app.js 992 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386
  1. define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product', 'service/Token', 'service/ProductUsers', 'service/File', 'service/PublicInquiry', 'service/Customer', 'service/PurcChange', 'angularTreeview'], function () {
  2. 'use strict';
  3. var app = angular.module('myApp', ['toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices', 'TokenService', 'ProductUserService', 'ui.tour', 'FileService', 'publicInquiryService', 'CustomerService', 'changeService', 'angularTreeview']);
  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. // window.location.href = window.location.origin + window.location.pathname + '/login';
  17. window.location.reload();
  18. return $q.reject(response);
  19. }
  20. return $q.reject(response);
  21. }
  22. }
  23. return httpInterceptor;
  24. }]);
  25. app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
  26. $stateProvider.state('index', {
  27. url: "/index",
  28. views: {
  29. "left-view": {
  30. templateUrl: "static/tpl/index/common/leftAll.html",
  31. controller: 'LeftCtrl'
  32. },
  33. "right-view": {
  34. templateUrl: "static/tpl/index/home/right.html",
  35. controller: 'RightCtrl'
  36. }
  37. }
  38. }).state('home', {
  39. url: "/",
  40. views: {
  41. "left-view": {
  42. templateUrl: "static/tpl/index/common/leftAll.html",
  43. controller: 'LeftCtrl'
  44. },
  45. "right-view": {
  46. templateUrl: "static/tpl/index/home/right.html",
  47. controller: 'RightCtrl'
  48. }
  49. }
  50. }).state('sale', {
  51. url: "/sale",
  52. views: {
  53. "left-view": {
  54. templateUrl: "static/tpl/index/common/leftAll.html",
  55. controller: 'LeftCtrl'
  56. },
  57. "right-view": {
  58. templateUrl: "static/tpl/index/sale/right.html"
  59. }
  60. },
  61. controller: function ($scope) {
  62. $scope.truck = [];
  63. $scope.dataChanged = false;
  64. }
  65. }).state('sale.index', {
  66. url: "",
  67. templateUrl: "static/tpl/index/sale/index.html"
  68. }).state('sale.home', {
  69. url: "/",
  70. templateUrl: "static/tpl/index/sale/index.html"
  71. }).state('purc', {
  72. url: "/purc",
  73. views: {
  74. "left-view": {
  75. templateUrl: "static/tpl/index/common/leftAll.html",
  76. controller: 'LeftCtrl'
  77. },
  78. "right-view": {
  79. templateUrl: "static/tpl/index/purc/right.html"
  80. }
  81. },
  82. controller: function ($scope) {
  83. $scope.truck = [];
  84. $scope.dataChanged = false;
  85. }
  86. }).state('purc.index', {
  87. url: "",
  88. templateUrl: "static/tpl/index/purc/index.html"
  89. }).state('purc.home', {
  90. url: "/",
  91. templateUrl: "static/tpl/index/purc/index.html"
  92. }).state('purc.introduce', {
  93. url: "/introduce",
  94. templateUrl: "static/tpl/index/purc/introduce.html"
  95. }).state('purc.order', {
  96. url: "/order",
  97. templateUrl: "static/tpl/index/purc/order.html",
  98. controller: 'PurcOrderCtrl'
  99. }).state('purc.order_detail', {
  100. url: "/order/:id",
  101. templateUrl: "static/tpl/index/purc/order_detail.html",
  102. controller: 'PurcOrderDetailCtrl'
  103. }).state('purc.newOrder', {
  104. url: "/addOrder",
  105. templateUrl: "static/tpl/index/purc/addOrder.html",
  106. controller: 'PurcNewOrderCtrl'
  107. }).state('purc.cart', {
  108. url: "/cart",
  109. templateUrl: "static/tpl/index/purc/cart.html",
  110. controller: 'CartController'
  111. }).state('purc.cartDetail', {
  112. url: "/cart/:id",
  113. templateUrl: "static/tpl/index/purc/cart_detail.html",
  114. controller: 'CartDetailController'
  115. }).state('purc.deputy', {
  116. url: "/deputy",
  117. templateUrl: "static/tpl/index/purc/deputyOrder.html",
  118. controller: 'DeputyOrderCtrl'
  119. }).state('purc.deputylog', {
  120. url: "/deputylog",
  121. templateUrl: "static/tpl/index/purc/deputyorders_log.html",
  122. controller: 'DeputyOrderLogCtrl'
  123. }).state('purc.newdeputy', {
  124. url: "/deputy/add",
  125. templateUrl: "static/tpl/index/purc/deputyOrder_new.html",
  126. controller: 'NewDeputyOrderCtrl'
  127. }).state('purc.deputydetail', {
  128. url: "/deputy/:id",
  129. templateUrl: "static/tpl/index/purc/deputyOrder_detail.html",
  130. controller: 'DeputyOrderDetailCtrl'
  131. }).state('purc.changeList', {// 新增采购变更单
  132. url: "/change",
  133. templateUrl: "static/tpl/index/purc/changeList.html",
  134. controller: 'PurcChangeListCtrl'
  135. /* 采购变更单详情 */
  136. }).state('purc.change_detail', {
  137. url: "/change/:id",
  138. templateUrl: "static/tpl/index/purc/change_detail.html",
  139. controller: 'PurcChangeDetailCtrl'
  140. }).state('purc.changeNew', {// 新增采购变更单
  141. url: "/change_new",
  142. templateUrl: "static/tpl/index/purc/change_new.html",
  143. controller: 'PurcChangeNewCtrl'
  144. /* 招标列表 */
  145. }).state('purc.tenderlist', {
  146. url: "/tender",
  147. templateUrl: "static/tpl/index/purc/tenderlist.html",
  148. controller: 'PurcTenderCtrl'
  149. /* 招标答疑列表 */
  150. }).state('purc.tenderanswerlist', {
  151. url: "/tender/answer",
  152. templateUrl: "static/tpl/index/purc/tender_answer_list.html",
  153. controller: 'PurcTenderAnswerListCtrl'
  154. /* 招标答疑详情 */
  155. }).state('purc.tenderanswerdetail', {
  156. url: "/tender/answer/:id",
  157. templateUrl: "static/tpl/index/purc/tender_answer_detail.html",
  158. controller: 'PurcTenderAnswerDetailCtrl'
  159. }).state('purc.waiting.tenderlist', {
  160. url: "/tender",
  161. templateUrl: "static/tpl/index/purc/tenderlist.html",
  162. controller: 'PurcTenderCtrl'
  163. }).state('purc.todo.tenderlist', {
  164. url: "/tender/todo",
  165. templateUrl: "static/tpl/index/purc/tenderlist.html",
  166. controller: 'PurcTenderCtrl'
  167. /* 招标 */
  168. }).state('purc.tender', {
  169. url: "/addTender",
  170. templateUrl: "static/tpl/index/purc/tender.html",
  171. controller: 'PurcNewTenderCtrl'
  172. }).state('purc.savedtender', {
  173. url: "/tender/:id",
  174. templateUrl: "static/tpl/index/purc/tender.html",
  175. controller: 'PurcNewTenderCtrl'
  176. /* 评标 */
  177. }).state('purc.evaluation', {
  178. url: "/evaluation/:id",
  179. templateUrl: "static/tpl/index/purc/tender_evaluation.html",
  180. controller: 'PurcEvaluationCtrl'
  181. /* 采购供应商资料 */
  182. }).state('purc.vendor', {
  183. url: "/vendor",
  184. templateUrl: "static/tpl/index/purc/vendor.html",
  185. controller: 'PurcVendorCtrl'
  186. /* 采购供应商资料 详情*/
  187. }).state('purc.vendorserve', {
  188. url: "/vendor/serve",
  189. templateUrl: "static/tpl/index/cs/right.html",
  190. controller: 'CustServeCtrl'
  191. }).state('purc.vendordetail', {
  192. url: "/vendor/:id",
  193. templateUrl: "static/tpl/index/purc/vendor_detail.html",
  194. controller: 'PurcVendorDetailCtrl'
  195. /* 客户指定招标列表 */
  196. }).state('purc.makeoutorder', {
  197. url: "/makeoutorder",
  198. templateUrl: "static/tpl/index/make/outorder.html",
  199. controller: 'MakeOutOrderCtrl'
  200. }).state('purc.outorder_detail', {
  201. url: "/makeoutorder/:id",
  202. templateUrl: "static/tpl/index/make/outorder_detail.html",
  203. controller: 'MakeOutOrderDetailCtrl'
  204. /*平台新增询价单*/
  205. }).state('purc.inquiry_new', {
  206. url: "/purcinquiry",
  207. templateUrl: "static/tpl/index/purc/inquiry_new.html",
  208. controller: 'PurcInquiryCtrl'
  209. /*新增公共询价*/
  210. }).state('purc.pubinquiry_new', {
  211. url: "/pubinquiry/new",
  212. templateUrl: "static/tpl/index/purc/pubInquiry_new.html",
  213. controller: 'PurcInquiryCtrl'
  214. }).state('purc.purcinquiry_new', {
  215. url: "/purcinquiry/:bussinessCode",
  216. templateUrl: "static/tpl/index/purc/purcinquiry_new.html",
  217. controller: 'PurcInquiryNewCtrl'
  218. }).state('purc.inquiry', {
  219. url: "/purchaseinquiry",
  220. templateUrl: "static/tpl/index/purc/inquiry.html",
  221. controller: 'PurchaseInquiryCtrl'
  222. }).state('purc.inquiry_detail', {
  223. url: "/purcinquirydetail",
  224. templateUrl: "static/tpl/index/purc/inquiry_detail.html",
  225. controller: 'PurcInquiryDetailCtrl'
  226. }).state('purc.inquiryInfo_detail', {
  227. url: "/purcinquirydetail/:id",
  228. templateUrl: "static/tpl/index/purc/inquiryInfo_detail.html",
  229. controller: 'PurcInquiryInfoDetailCtrl'
  230. }).state('purc.inquiry_unapply', {
  231. url: "/inquiry_unapply",
  232. templateUrl: "static/tpl/index/purc/inquiry_unapply.html",
  233. controller: 'UnapplyInquiryCtrl'
  234. }).state('purc.pubInquiry', {
  235. /**
  236. * 针对客户,查询已转报价的公共询价单列表
  237. */
  238. url: "/publicInquiry",
  239. templateUrl: "static/tpl/index/purc/pubInquiry.html",
  240. controller: 'PurcPubInquiryCtrl'
  241. }).state('purc.pubInquiry_detail', {
  242. /**
  243. * 针对客户,查询已转报价单的公共询价详情
  244. */
  245. url: "/publicInquiry/:id",
  246. templateUrl: "static/tpl/index/purc/pubInquiry_detail.html",
  247. controller: 'PurcPubInquiryDetailCtrl'
  248. }).state('purc.product', {
  249. url: "/product",
  250. templateUrl: "static/tpl/index/purc/prodList.html",
  251. controller: 'PurcProductCtrl'
  252. }).state('purc.newProduct', {
  253. url: "/newProduct",
  254. templateUrl: "static/tpl/index/purc/newProdInfo.html",
  255. controller: 'PurcNewProdInfoCtrl'
  256. }).state('purc.productDetail', {
  257. url: "/prodList/:id",
  258. templateUrl: "static/tpl/index/purc/productDetail.html",
  259. controller: 'PurcProdDetailCtrl'
  260. }).state('purc.productmatches', {
  261. url: "/productmatches",
  262. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  263. controller: 'ProductmatchesForPurcCtrl'
  264. }).state('purc.uploadProduct', {
  265. url: "/uploadProduct",
  266. templateUrl: "static/tpl/index/purc/uploadByBatch.html",
  267. controller: 'UploadProductCtrl'
  268. }).state('sale.tenderlist', {
  269. url: "/tender",
  270. templateUrl: "static/tpl/index/sale/tenderlist.html",
  271. controller: 'SaleTenderCtrl'
  272. /* 招标提问列表 */
  273. }).state('sale.tenderquestionlist', {
  274. url: "/tender/question",
  275. templateUrl: "static/tpl/index/sale/tender_question_list.html",
  276. controller: 'SaleTenderQuestionListCtrl'
  277. /* 招标提问详情 */
  278. }).state('sale.tenderquestiondetail', {
  279. url: "/tender/question/:id",
  280. templateUrl: "static/tpl/index/sale/tender_question_detail.html",
  281. controller: 'SaleTenderQuestionDetailCtrl'
  282. }).state('sale.todo.tenderlist', {
  283. url: "/tender",
  284. templateUrl: "static/tpl/index/sale/tenderlist.html",
  285. controller: 'SaleTenderCtrl'
  286. /* 平台公开招标列表 */
  287. }).state('baseInfo.openTenderList', {
  288. url: "/openTenderList",
  289. templateUrl: "static/tpl/index/sale/open_tender_list.html",
  290. controller: 'SaleOpenTenderCtrl'
  291. /* 查看公开招标详情 */
  292. }).state('baseInfo.open_tender_detail', {
  293. url: "/openTenderDetail/:id",
  294. templateUrl: "static/tpl/index/sale/open_tender_detail.html",
  295. controller: 'OpenSaleTenderDetailCtrl'
  296. /* 投标 */
  297. }).state('sale.tender', {
  298. url: "/tender/:id",
  299. templateUrl: "static/tpl/index/sale/tender.html",
  300. controller: 'SaleTenderDetailCtrl'
  301. /* 采购方查看供应商投标 */
  302. }).state('sale.vendortender', {
  303. url: "/tender/:vendUU/:id",
  304. templateUrl: "static/tpl/index/sale/vendor_tender.html",
  305. controller: 'SaleVendorTenderDetailCtrl'
  306. }).state('sale.todo', {
  307. url: "/todo",
  308. templateUrl: "static/tpl/index/sale/todo.html"
  309. }).state('sale.todo.inquiry', {
  310. url: "/inquiry",
  311. templateUrl: "static/tpl/index/sale/inquiry.html",
  312. controller: 'SaleInquiryCtrl'
  313. }).state('sale.todo.order', {
  314. url: "/order",
  315. templateUrl: "static/tpl/index/sale/order.html",
  316. controller: 'SaleOrderCtrl'
  317. }).state('sale.todo.change', {
  318. url: "/change",
  319. templateUrl: "static/tpl/index/sale/change.html",
  320. controller: 'SaleChangeCtrl'
  321. }).state('sale.todo.notice', {
  322. url: "/notice",
  323. templateUrl: "static/tpl/index/sale/notice.html",
  324. controller: 'SaleNoticeCtrl'
  325. }).state('sale.customer', {
  326. url: "/customer",
  327. templateUrl: "static/tpl/index/sale/customer.html",
  328. controller: 'CustomerCtrl'
  329. }).state('sale.customer_detail', {
  330. url: "/customer/:id",
  331. templateUrl: "static/tpl/index/sale/customer_detail.html",
  332. controller: 'CustomerDetailCtrl'
  333. }).state('sale.customerProduct', {
  334. url: "/customerProduct",
  335. templateUrl: "static/tpl/index/sale/customer.html",
  336. controller: 'CustomerCtrl'
  337. }).state('sale.inquiry', {
  338. url: "/inquiry",
  339. templateUrl: "static/tpl/index/sale/inquiry.html",
  340. controller: 'SaleInquiryCtrl'
  341. }).state('sale.pubinquiry', {
  342. /**
  343. * 针对卖家,展示已转询价报价的公共询价单列表
  344. */
  345. url: "/pubinquiry",
  346. templateUrl: "static/tpl/index/sale/pubinquiry.html",
  347. controller: 'SalePubInquiryCtrl',
  348. params: {
  349. 'saleInquiryActive': null
  350. }
  351. }).state('sale.pubinquiry_detail', {
  352. /**
  353. * 针对卖家,已转询价报价单的公共询价单详情
  354. */
  355. url: "/pubinquiry/:id",
  356. templateUrl: "static/tpl/index/sale/pubinquiry_detail.html",
  357. controller: 'SalePubInquiryDetailCtrl'
  358. }).state('sale.inquiryRemind', {
  359. /**
  360. * 针对卖家,查询推荐的询价列表
  361. */
  362. url: "/inquiryRemind",
  363. templateUrl: "static/tpl/index/sale/inquiryRemind.html",
  364. controller: 'SaleInquiryRemindCtrl'
  365. }).state('sale.inquirymould', {
  366. url: "/mould",
  367. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  368. controller: 'SaleInquiryMouldCtrl'
  369. }).state('sale.todo.inquirymould', {
  370. url: "/mould",
  371. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  372. controller: 'SaleInquiryMouldCtrl'
  373. }).state('sale.inquiry_mould_detail', {
  374. url: "/mould/:id",
  375. templateUrl: "static/tpl/index/sale/inquiry_mould_detail.html",
  376. controller: 'SaleInquiryMouldDetailCtrl'
  377. }).state('sale.inquiry_detail', {
  378. url: "/inquiry/:id",
  379. templateUrl: "static/tpl/index/sale/inquiry_detail.html",
  380. controller: 'SaleInquiryDetailCtrl'
  381. }).state('sale.quotation', {
  382. url: "/quotation",
  383. templateUrl: "static/tpl/index/sale/quotation.html"
  384. }).state('sale.quotation.new', {
  385. url: "/new",
  386. templateUrl: "static/tpl/index/sale/quotation_new.html",
  387. controller: 'SaleQuotationNewCtrl',
  388. params: {
  389. 'inquiryItem': null
  390. }
  391. }).state('sale.quotation.list', {
  392. url: "/list",
  393. templateUrl: "static/tpl/index/sale/quotation_list.html",
  394. controller: 'SaleQuotationListCtrl'
  395. }).state('sale.quotation.item', {
  396. url: "/:id",
  397. templateUrl: "static/tpl/index/sale/quotation_new.html",
  398. controller: 'SaleQuotationNewCtrl'
  399. }).state('sale.order', {
  400. url: "/order",
  401. templateUrl: "static/tpl/index/sale/order.html",
  402. controller: 'SaleOrderCtrl'
  403. }).state('sale.order_detail', {
  404. url: "/order/:id",
  405. templateUrl: "static/tpl/index/sale/order_detail.html",
  406. controller: 'SaleOrderDetailCtrl'
  407. }).state('sale.change', {
  408. url: "/change",
  409. templateUrl: "static/tpl/index/sale/change.html",
  410. controller: 'SaleChangeCtrl'
  411. }).state('sale.change_detail', {
  412. url: "/change/:id",
  413. templateUrl: "static/tpl/index/sale/change_detail.html",
  414. controller: 'SaleChangeDetailCtrl'
  415. }).state('sale.notice', {
  416. url: "/notice",
  417. templateUrl: "static/tpl/index/sale/notice.html",
  418. controller: 'SaleNoticeCtrl'
  419. }).state('sale.send', {
  420. url: "/send",
  421. templateUrl: "static/tpl/index/sale/send.html",
  422. controller: 'SaleSendCtrl'
  423. }).state('sale.send_detail', {
  424. url: "/send/:id",
  425. templateUrl: "static/tpl/index/sale/send_detail.html",
  426. controller: 'SaleSendDetailCtrl'
  427. }).state('sale.forecast', {
  428. url: "/forecast",
  429. templateUrl: "static/tpl/index/sale/forecast.html",
  430. controller: 'SaleForecastCtrl'
  431. }).state('sale.accept', {
  432. url: "/accept",
  433. templateUrl: "static/tpl/index/sale/accept.html",
  434. controller: 'SaleAcceptCtrl'
  435. }).state('sale.accept_detail', {
  436. url: "/accept/:id",
  437. templateUrl: "static/tpl/index/sale/accept_detail.html",
  438. controller: 'SaleAcceptDetailCtrl'
  439. }).state('sale.returns', {
  440. url: "/returns",
  441. templateUrl: "static/tpl/index/sale/returns.html",
  442. controller: 'SaleReturnsCtrl'
  443. }).state('sale.return_detail', {
  444. url: "/return/:id",
  445. templateUrl: "static/tpl/index/sale/return_detail.html",
  446. controller: 'SaleReturnsDetailCtrl'
  447. }).state('sale.sample', {
  448. url: "/sample",
  449. templateUrl: "static/tpl/index/sale/sample.html",
  450. controller: 'SaleSampleCtrl'
  451. }).state('sale.sample_detail', {
  452. url: "/sample/:id",
  453. templateUrl: "static/tpl/index/sale/sample_detail.html",
  454. controller: 'SaleSampleDetailCtrl'
  455. }).state('sale.approval', {
  456. url: "/approval",
  457. templateUrl: "static/tpl/index/sale/approval.html",
  458. controller: 'SaleApprovalCtrl'
  459. }).state('sale.prodList', {
  460. url: "/prodList",
  461. templateUrl: "static/tpl/index/baseInfo/prodList.html",
  462. controller: 'ProductListCtrl'
  463. }).state('sale.newProdInfo', {
  464. url: "/newProdInfo",
  465. templateUrl: "static/tpl/index/baseInfo/newProdInfo.html",
  466. controller: 'NewProdInfoCtrl'
  467. }).state('sale.uploadByBatch', {
  468. url: "/uploadByBatch",
  469. templateUrl: "static/tpl/index/baseInfo/uploadByBatch.html",
  470. controller: 'UploadByBatchCtrl'
  471. }).state('sale.productDetail', {
  472. url: "/prodList/:id",
  473. templateUrl: "static/tpl/index/baseInfo/productDetail.html",
  474. controller: 'ProductDetailCtrl'
  475. }).state('sale.productmatches', {
  476. url: "/productmatches",
  477. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  478. controller: 'ProductmatchesForSaleCtrl'
  479. }).state('sale.maketodo', {
  480. url: "/maketodo",
  481. templateUrl: "static/tpl/index/make/todo.html"
  482. }).state('sale.maketodo.order', {
  483. url: "/makeorder",
  484. templateUrl: "static/tpl/index/make/order.html",
  485. controller: 'MakeOrderCtrl'
  486. }).state('sale.makeorder', {
  487. url: "/makeorder",
  488. templateUrl: "static/tpl/index/make/order.html",
  489. controller: 'MakeOrderCtrl'
  490. }).state('sale.makeorder_detail', {
  491. url: "/makeorder/:id",
  492. templateUrl: "static/tpl/index/make/order_detail.html",
  493. controller: 'MakeOrderDetailCtrl'
  494. }).state('sale.badOut', {
  495. url: "/badOut",
  496. templateUrl: "static/tpl/index/qc/badOut.html",
  497. controller: 'SaleBadOutCtrl'
  498. }).state('sale.MRB', {
  499. url: "/MRB",
  500. templateUrl: "static/tpl/index/qc/MRB.html",
  501. controller: 'SaleMRBCtrl'
  502. }).state('sale.badIn', {
  503. url: "/badIn",
  504. templateUrl: "static/tpl/index/qc/badIn.html",
  505. controller: 'SaleBadInCtrl'
  506. }).state('sale.makeaccept', {
  507. url: "/makeaccept",
  508. templateUrl: "static/tpl/index/make/accept.html",
  509. controller: 'MakeAcceptCtrl'
  510. }).state('sale.makereturns', {
  511. url: "/makereturns",
  512. templateUrl: "static/tpl/index/make/returns.html",
  513. controller: 'MakeReturnCtrl'
  514. }).state('sale.makechange', {
  515. url: "/makechange",
  516. templateUrl: "static/tpl/index/make/change.html",
  517. controller: 'MakeChangeCtrl'
  518. }).state('sale.makechange_detail', {
  519. url: "/makechange/:id",
  520. templateUrl: "static/tpl/index/make/change_detail.html",
  521. controller: 'MakeChangeDetailCtrl'
  522. }).state('account', {
  523. url: "/account",
  524. views: {
  525. "left-view": {
  526. templateUrl: "static/tpl/index/account/left.html",
  527. controller: 'LeftCtrl'
  528. },
  529. "right-view": {
  530. templateUrl: "static/tpl/index/account/right.html"
  531. }
  532. }
  533. }).state('account.index', {
  534. url: "",
  535. templateUrl: "static/tpl/index/account/index.html",
  536. controller: 'RightCtrl'
  537. }).state('account.home', {
  538. url: "/",
  539. templateUrl: "static/tpl/index/account/index.html",
  540. controller: 'RightCtrl'
  541. }).state('baseInfo', {//基础资料
  542. url: "/baseInfo",
  543. views: {
  544. "left-view": {
  545. templateUrl: "static/tpl/index/common/leftAll.html"
  546. },
  547. "right-view": {
  548. templateUrl: "static/tpl/index/baseInfo/right.html"
  549. }
  550. }
  551. }).state('baseInfo.index', {
  552. url: "/enterpriseList",
  553. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  554. controller: 'EnterpriseListCtrl'
  555. }).state('baseInfo.home', {
  556. url: "/enterpriseList",
  557. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  558. controller: 'EnterpriseListCtrl'
  559. }).state('baseInfo.enterpriseList', {
  560. url: "/enterpriseList",
  561. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  562. controller: 'EnterpriseListCtrl'
  563. }).state('baseInfo.myClient', {
  564. url: "/myClient",
  565. templateUrl: "static/tpl/index/baseInfo/myClient.html",
  566. controller: 'MyClientCtrl'
  567. }).state('baseInfo.mySupplier', {
  568. url: "/mySupplier",
  569. templateUrl: "static/tpl/index/baseInfo/mySupplier.html",
  570. controller: 'MySupplierCtrl'
  571. }).state('baseInfo.myRequest', {
  572. url: "/myRequest",
  573. templateUrl: "static/tpl/index/baseInfo/myRequest.html",
  574. controller: 'AddPartnerRequestCtrl'
  575. }).state('baseInfo.newPartner', {
  576. url: "/newPartner",
  577. templateUrl: "static/tpl/index/baseInfo/newPartner.html",
  578. controller: 'NewPartnerCtrl'
  579. }).state('baseInfo.myMessage', {
  580. url: "/myMessage",
  581. templateUrl: "static/tpl/index/baseInfo/myMessage.html",
  582. controller: 'AddPartnerMessageCtrl'
  583. }).state('baseInfo.myPartners', {
  584. url: '/myPartners',
  585. templateUrl: "static/tpl/index/baseInfo/myPartners.html",
  586. controller: 'MyPartnersCtrl'
  587. }).state('baseInfo.businessGroups', {
  588. url: '/businessGroups',
  589. controller: 'BusinessGroupsCtrl'
  590. }).state('baseInfo.inquiryList', {
  591. url: '/inquiryList',
  592. templateUrl: "static/tpl/index/baseInfo/inquiry_list.html",
  593. controller: 'PublicInquiryListCtrl'
  594. }).state('baseInfo.inquiryListDetail', {
  595. url: '/inquiryList/:id',
  596. templateUrl: "static/tpl/index/baseInfo/inquiryItem_detail.html",
  597. controller: 'PublicInquiryListDetailCtrl'
  598. }).state('baseInfo.vendorInfo', {
  599. url: '/enume/vendorInfo',
  600. templateUrl: "static/tpl/index/baseInfo/vendorsInfo.html",
  601. controller: 'VendorsInfoCtrl'
  602. }).state('baseInfo.servicerInfo', {
  603. url: '/enume/servicerInfo',
  604. templateUrl: "static/tpl/index/baseInfo/servicerInfo.html",
  605. controller: 'ServicerInfoCtrl'
  606. }).state('baseInfo.customerInfo', {
  607. url: '/enume/customerInfo',
  608. templateUrl: "static/tpl/index/baseInfo/customersInfo.html",
  609. controller: 'CustomersInfoCtrl'
  610. }).state('baseInfo.enume', {
  611. url: '/enume',
  612. templateUrl: "static/tpl/index/baseInfo/vendorAndCustomer.html"
  613. }).state('baseInfo.partner', {
  614. url: '/partner',
  615. templateUrl: "static/tpl/index/baseInfo/addPartners.html",
  616. controller: 'AddPartnersCtrl'
  617. }).state('baseInfo.partner_searchresult', {
  618. url: '/search',
  619. templateUrl: "static/tpl/index/baseInfo/searchresult.html",
  620. controller: 'EnterpriseSearchCtrl'
  621. }).state('baseInfo.invitation', {
  622. url: '/invitation',
  623. templateUrl: "static/tpl/index/baseInfo/invitation.html",
  624. controller: 'InvitationCtrl'
  625. }).state('qc', {
  626. url: "/qc",
  627. views: {
  628. "left-view": {
  629. templateUrl: "static/tpl/index/qc/left.html"
  630. },
  631. "right-view": {
  632. templateUrl: "static/tpl/index/qc/right.html"
  633. }
  634. }
  635. }).state('qc.index', {
  636. url: "",
  637. templateUrl: "static/tpl/index/qc/index.html"
  638. }).state('qc.home', {
  639. url: "/",
  640. templateUrl: "static/tpl/index/qc/index.html"
  641. }).state('fa', {
  642. url: "/fa",
  643. views: {
  644. "left-view": {
  645. templateUrl: "static/tpl/index/common/leftAll.html"
  646. },
  647. "right-view": {
  648. templateUrl: "static/tpl/index/fa/right.html"
  649. }
  650. }
  651. }).state('fa.index', {
  652. url: "",
  653. templateUrl: "static/tpl/index/fa/index.html"
  654. }).state('fa.home', {
  655. url: "/",
  656. templateUrl: "static/tpl/index/fa/index.html"
  657. }).state('fa.apBill', {
  658. url: "/apBill",
  659. templateUrl: "static/tpl/index/fa/apBill.html",
  660. controller: 'SaleApBillCtrl'
  661. }).state('fa.apBill_detail', {
  662. url: "/apBill/:id",
  663. templateUrl: "static/tpl/index/fa/apBill_detail.html",
  664. controller: 'SaleApBillDetailCtrl'
  665. }).state('fa.arCheck', {
  666. url: "/arCheck",
  667. templateUrl: "static/tpl/index/fa/arCheck.html",
  668. controller: 'SaleArCheckCtrl'
  669. }).state('fa.arCheck_detail', {
  670. url: "/arCheck/:id",
  671. templateUrl: "static/tpl/index/fa/arCheck_detail.html",
  672. controller: 'SaleArCheckDetailCtrl'
  673. }).state('fa.apCheck', {
  674. url: "/apCheck",
  675. params: {
  676. 'id': null
  677. },
  678. templateUrl: "static/tpl/index/fa/apCheck.html",
  679. controller: 'PurchaseApCheckCtrl'
  680. }).state('fa.apCheck_detail', {
  681. url: "/apCheck/:id",
  682. templateUrl: "static/tpl/index/fa/apCheck_detail.html",
  683. controller: 'PurchaseApCheckDetailCtrl'
  684. }).state('fa.apCheckList', {
  685. url: "/apCheckList",
  686. templateUrl: "static/tpl/index/fa/apCheckList.html",
  687. controller: 'PurchaseApCheckListCtrl'
  688. }).state('fa.apBillOut', {
  689. url: "/apBillOut",
  690. params:{
  691. 'id':null
  692. },
  693. templateUrl: "static/tpl/index/fa/apBillOut.html",
  694. controller: 'PurchaseApBillOutCtrl'
  695. }).state('fa.apBillOut_detail', {
  696. url: "/apBillOut/:id",
  697. templateUrl: "static/tpl/index/fa/apBillOut_detail.html",
  698. controller: 'PurchaseApBillOutDetailCtrl'
  699. }).state('fa.apBillOutList', {
  700. url: "/apBillOutList",
  701. templateUrl: "static/tpl/index/fa/apBillOutList.html",
  702. controller: 'PurchaseApBillOutListCtrl'
  703. }).state('fa.adjustList', {
  704. url: "/adjustList",
  705. templateUrl: "static/tpl/index/fa/adjustList.html",
  706. controller: 'PurchaseAdjustListCtrl'
  707. }).state('make', {
  708. url: "/make",
  709. views: {
  710. "left-view": {
  711. templateUrl: "static/tpl/index/make/left.html"
  712. },
  713. "right-view": {
  714. templateUrl: "static/tpl/index/make/right.html"
  715. }
  716. }
  717. }).state('make.index', {
  718. url: "",
  719. templateUrl: "static/tpl/index/make/index.html"
  720. }).state('make.home', {
  721. url: "/",
  722. templateUrl: "static/tpl/index/make/index.html"
  723. }).state('cs', {// 客户服务
  724. url: "/cs",
  725. views: {
  726. "left-view": {
  727. templateUrl: "static/tpl/index/cs/left.html"
  728. },
  729. "right-view": {
  730. templateUrl: "static/tpl/index/cs/right.html"
  731. }
  732. }
  733. }).state('cs.index', {
  734. url: "",
  735. templateUrl: "static/tpl/index/cs/index.html"
  736. }).state('cs.home', {
  737. url: "/",
  738. templateUrl: "static/tpl/index/cs/index.html"
  739. }).state('search', { //顶部搜索
  740. url: "/search?keyword=",
  741. views: {
  742. "left-view": {
  743. templateUrl: "static/tpl/index/search/left.html"
  744. },
  745. "right-view": {
  746. templateUrl: "static/tpl/index/search/search_result.html",
  747. controller: 'TopSearchCtrl'
  748. }
  749. }
  750. }).state('approvalflow', { //审批流
  751. url: "/approvalFlow",
  752. views: {
  753. "left-view": {
  754. templateUrl: "static/tpl/index/common/leftAll.html"
  755. },
  756. "right-view": {
  757. templateUrl: "static/tpl/index/approvalFlow/right.html",
  758. }
  759. }
  760. }).state('approvalflow.flow', {
  761. url: "/flow",
  762. templateUrl: "static/tpl/index/approvalFlow/home.html",
  763. controller: 'approvalFlowCtrl'
  764. }).state('approvalflow.enterprise', {
  765. url: "/enterprise",
  766. templateUrl: "static/tpl/index/approvalFlow/enterprise.html",
  767. controller: 'EnterpriseCtrl'
  768. }).state('approvalflow.user', {
  769. url: "/user",
  770. templateUrl: "static/tpl/index/approvalFlow/user.html",
  771. controller: 'UserCtrl'
  772. }).state('approvalflow.log', {
  773. url: "/log",
  774. templateUrl: "static/tpl/index/approvalFlow/log.html",
  775. controller: 'LogCtrl'
  776. }).state('approvalflow.resource', {
  777. url: "/resource",
  778. templateUrl: "static/tpl/index/approvalFlow/resource.html",
  779. controller: 'ResourceCtrl'
  780. }).state('approvalflow.role', {
  781. url: "/role",
  782. templateUrl: "static/tpl/index/approvalFlow/role.html",
  783. controller: 'RoleCtrl'
  784. }).state('approvalflow.product', {
  785. url: "/product",
  786. templateUrl: "static/tpl/index/approvalFlow/prodList.html",
  787. controller: 'ProductAllCtrl'
  788. }).state('approvalflow.userProduct', {
  789. url: "/userProduct",
  790. templateUrl: "static/tpl/index/approvalFlow/userProduct.html",
  791. controller: 'UserProductCtrl'
  792. }).state('approvalflow.productmatches', {
  793. url: "/productmatches",
  794. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  795. controller: 'ProductmatchesCtrl'
  796. }).state('sale.vendorPerformanceAssess', {
  797. url: "/vendorPerformanceAssess",
  798. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess.html",
  799. controller: 'VendorPerformanceAssessCtrl'
  800. }).state('sale.vendorPerformanceAssess_detail', {
  801. url: "/vendorPerformanceAssess/:id",
  802. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess_detail.html",
  803. controller: 'VendorPerformanceAssessDetailCtrl'
  804. });
  805. $urlRouterProvider.otherwise('/index');
  806. }]);
  807. /**
  808. * 表示符号
  809. */
  810. app.factory('Symbol', function () {
  811. return {
  812. currency: function (cur) {
  813. if (cur == 'RMB') return '¥';
  814. else if (cur == 'USD') return '$';
  815. else if (cur == 'EUR') return '€';
  816. else if (cur == null || cur == '') return '¥';
  817. else return cur;
  818. }
  819. };
  820. }).factory('Lodop', function () {
  821. return {
  822. getLodop: function (oOBJECT, oEMBED) {
  823. var CreatedOKLodop7766 = null;
  824. /**************************
  825. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  826. IE系列、IE内核系列的浏览器采用oOBJECT,
  827. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  828. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  829. 64位浏览器指向64位的安装程序install_lodop64.exe。
  830. **************************/
  831. var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  832. var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  833. var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  834. var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  835. var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  836. var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  837. var LODOP;
  838. try {
  839. //=====判断浏览器类型:===============
  840. var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
  841. var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
  842. //=====如果页面有Lodop就直接使用,没有则新建:==========
  843. if (oOBJECT != undefined || oEMBED != undefined) {
  844. if (isIE)
  845. LODOP = oOBJECT;
  846. else
  847. LODOP = oEMBED;
  848. } else {
  849. if (CreatedOKLodop7766 == null) {
  850. LODOP = document.createElement("object");
  851. LODOP.setAttribute("width", 0);
  852. LODOP.setAttribute("height", 0);
  853. LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  854. if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  855. else LODOP.setAttribute("type", "application/x-print-lodop");
  856. document.documentElement.appendChild(LODOP);
  857. CreatedOKLodop7766 = LODOP;
  858. } else
  859. LODOP = CreatedOKLodop7766;
  860. }
  861. ;
  862. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  863. if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
  864. if (navigator.userAgent.indexOf('Chrome') >= 0)
  865. document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
  866. if (navigator.userAgent.indexOf('Firefox') >= 0)
  867. document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
  868. if (is64IE) document.write(strHtm64_Install); else if (isIE) document.write(strHtmInstall); else
  869. document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
  870. return LODOP;
  871. } else if (LODOP.VERSION < "6.1.9.8") {
  872. if (is64IE) document.write(strHtm64_Update); else if (isIE) document.write(strHtmUpdate); else
  873. document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
  874. return LODOP;
  875. }
  876. ;
  877. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  878. LODOP.SET_LICENSES("深圳市优软科技有限公司", "BBF53BD5AB0D522B3207D05CDE381F65", "", "");
  879. //============================================================
  880. return LODOP;
  881. } catch (err) {
  882. if (is64IE)
  883. document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML; else
  884. document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML;
  885. return LODOP;
  886. }
  887. ;
  888. }
  889. }
  890. });
  891. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', 'toaster', 'AccountEnterprise', function ($scope, $rootScope, $modal, toaster, AccountEnterprise) {
  892. $rootScope.$on('$locationChangeSuccess', function (evt, newUrl) {
  893. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  894. if (routeState.indexOf('/') > -1)
  895. routeState = routeState.substring(0, routeState.indexOf('/'));
  896. if (routeState.indexOf('.') > -1)
  897. routeState = routeState.substring(0, routeState.indexOf('.'));
  898. $scope.routeState = routeState || 'home';
  899. });
  900. $scope.search = function (keyword) {
  901. if (keyword != null && keyword != '') {
  902. $rootScope.searchKeyword = keyword;
  903. window.location.hash = '#/search?keyword=' + keyword;
  904. } else {
  905. $rootScope.searchKeyword = null;
  906. window.location.hash = '#/search';
  907. }
  908. };
  909. $scope.showMessage = function () {
  910. var modalInstance = $modal.open({
  911. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  912. controller: 'PagingReleaseCtrl'
  913. });
  914. };
  915. // 连接到询价
  916. $scope.linktoInquiry = function (active) {
  917. $rootScope.active = active;
  918. window.location.href = "#/sale/inquiry";
  919. }
  920. // 连接到招标
  921. $scope.linktoSaleTender = function (active) {
  922. $rootScope.active = active;
  923. window.location.href = "#/sale/tender";
  924. }
  925. // 链接到打样申请
  926. $scope.linktoSample = function (active) {
  927. $rootScope.active = active;
  928. window.location.href = "#/sale/sample";
  929. }
  930. // 链接到采购招标
  931. $scope.linktoPurcTender = function (active) {
  932. $rootScope.tenderActive = active;
  933. window.location.href = "#/purc/tender";
  934. }
  935. $scope.linktoPurcInquiry = function (active) {
  936. $rootScope.active = active;
  937. window.location.href = "#/purc/purchaseinquiry";
  938. }
  939. // 跳转到B2C
  940. $scope.b2cLink = function (url) {
  941. AccountEnterprise.getB2cUrl({}, function(data) {
  942. if (url == '/help/home') {
  943. window.open(data.url + url, '_target')
  944. } else {
  945. window.location.href = data.url + url;
  946. }
  947. });
  948. }
  949. }]);
  950. app.controller('AdController', ['$scope', '$modal', '$interval', function($scope, $modal, $interval) {
  951. // 广告操作
  952. $scope.count = 5;
  953. $scope.bannerShow = true;
  954. $scope.imgAnmiation = false;
  955. $scope.jingKongAnmiation = true;
  956. $scope.imgShow = true;
  957. $scope.Times = $interval(function () {
  958. $scope.count--;
  959. if ($scope.count <= 0) {
  960. $scope.count = 5;
  961. $scope.jingKongAnmiation = false;
  962. $interval.cancel($scope.Times);
  963. $scope.closeClick();
  964. }
  965. }, 1000);
  966. // 金控广告动画设置
  967. $scope.closeClick = function () {
  968. $scope.jingKongAnmiation = false;
  969. if ($scope.bannerShow === false) {
  970. $scope.imgAnmiation = false;
  971. $scope.imgShow = false;
  972. } else {
  973. $scope.bannerShow = false;
  974. $scope.imgAnmiation = true;
  975. }
  976. }
  977. }]);
  978. /**
  979. * 新消息提醒(调用公共服务接口) -2018-01-22 19:36:50
  980. * @author dongbw
  981. */
  982. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'PagingReleaseInfo',
  983. function ($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance, PagingReleaseInfo) {
  984. $scope.active = "todo";
  985. $scope.setActive = function (state) {
  986. if ($scope.active != state) {
  987. $scope.active = state;
  988. if ($scope.tableParams.page() == 1)
  989. $scope.tableParams.reload();
  990. else
  991. $scope.tableParams.page(1);
  992. }
  993. };
  994. /**
  995. * 页面状态按钮过滤
  996. */
  997. var getMessageState = function (active) {
  998. var fn = 'get';
  999. switch (active) {
  1000. case 'done':
  1001. fn = 'getDone';
  1002. break;
  1003. case 'todo':
  1004. fn = 'getTodo';
  1005. break;
  1006. }
  1007. return fn;
  1008. };
  1009. $scope.tableParams = new ngTableParams({
  1010. page: 1,
  1011. count: 5,
  1012. sorting: {
  1013. 'createTime': 'desc'
  1014. }
  1015. }, {
  1016. total: 0,
  1017. counts: [],
  1018. getData: function ($defer, params) {
  1019. $scope.loading = true;
  1020. var pageParams = params.url();
  1021. var realActive = {};
  1022. pageParams.searchFilter = { // 筛选条件
  1023. keyword: $scope.keyword
  1024. // fromDate: getDateTime($scope.condition.dateFrom),
  1025. // endDate: getDateTime($scope.condition.dateTo)
  1026. };
  1027. PagingRelease[getMessageState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1028. $scope.loading = false;
  1029. if (page) {
  1030. params.total(page.totalElements);
  1031. $defer.resolve(page.content);
  1032. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  1033. }
  1034. }, function (response) {
  1035. $scope.loading = false;
  1036. toaster.pop('error', '数据加载失败', response.data);
  1037. });
  1038. }
  1039. });
  1040. $scope.close = function () {
  1041. $modalInstance.close();
  1042. window.location.reload();
  1043. };
  1044. $scope.checks = {
  1045. checked: false
  1046. };// 全选框
  1047. $scope.checkAll = function () {
  1048. angular.forEach($scope.tableParams.data, function (message) {
  1049. message.checked = $scope.checks.checked;
  1050. });
  1051. };
  1052. // 单选
  1053. $scope.checkOne = function (vendor) {
  1054. vendor.checked = true;
  1055. var checked = true;
  1056. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  1057. if (!message.checked) {
  1058. checked = false;
  1059. }
  1060. });
  1061. $scope.checks.checked = checked;
  1062. };
  1063. // 单反选
  1064. $scope.unCheckOne = function (vendor) {
  1065. vendor.checked = false;
  1066. $scope.checks.checked = false;
  1067. };
  1068. /**
  1069. * 当前页标为已读
  1070. */
  1071. $scope.setRead = function () {
  1072. $scope.loading = true;
  1073. var messageIds = [];
  1074. angular.forEach($scope.tableParams.data, function(message) {
  1075. messageIds.push(message.id);
  1076. });
  1077. PagingRelease.setPageRead({}, messageIds, function (data) {
  1078. $scope.loading = false;
  1079. if (data.success) {
  1080. toaster.pop("success", "设置已读成功");
  1081. }
  1082. if (data.error) {
  1083. toaster.pop("error", "设置已读失败");
  1084. }
  1085. $scope.tableParams.page(1);
  1086. $scope.tableParams.reload();
  1087. });
  1088. };
  1089. // 点击内容连接之后,信息标为已读
  1090. $scope.setOneRead = function (id) {
  1091. $scope.loading = true;
  1092. $modalInstance.close();
  1093. PagingRelease.setMessageRead({id: id}, {}, function (data) {
  1094. $scope.loading = false;
  1095. }, function (response) {
  1096. $scope.loading = false;
  1097. toaster.pop('error', '提示', response.data);
  1098. });
  1099. };
  1100. // 搜索框回车
  1101. $scope.onSearch = function () {
  1102. $scope.tableParams.page(1);
  1103. $scope.tableParams.reload();
  1104. };
  1105. }]);
  1106. // 高亮显示关键词
  1107. app.filter('getkey', ['$sce', '$rootScope', function ($sce, $rootScope) {
  1108. var search = $rootScope.searchKeyword;
  1109. return function (content, search) {
  1110. content = encodeURI(content);
  1111. search = encodeURI(search);
  1112. var reg = new RegExp(search, 'gim');
  1113. var result = content.replace(reg, '<font color="red">$&</font>');
  1114. result = decodeURIComponent(result);
  1115. return $sce.trustAsHtml(result);
  1116. };
  1117. $rootScope.searchKeyword = null;// 清除缓存的关键字
  1118. }]);
  1119. /**
  1120. * 顶部搜索
  1121. */
  1122. 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) {
  1123. BaseService.scrollBackToTop();
  1124. $scope.active = 'all';
  1125. $scope.tip = $rootScope.searchKeyword;
  1126. // 企业搜索
  1127. var getService = function () {
  1128. return getAccountUserSpace;
  1129. };
  1130. $scope.tableParams = new ngTableParams({
  1131. page: 1,
  1132. count: 20,
  1133. sorting: {}
  1134. }, {
  1135. total: 0,
  1136. counts: [5, 10, 25, 50],
  1137. getData: function ($defer, params) {
  1138. $scope.loading = true;
  1139. var pageParams = params.url();
  1140. pageParams.keyword = $rootScope.searchKeyword;
  1141. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1142. $scope.loading = false;
  1143. if (page) {
  1144. $scope.total = page.totalElement;
  1145. params.total(page.totalElement);
  1146. $defer.resolve(page.content);
  1147. }
  1148. }, function (response) {
  1149. $scope.loading = false;
  1150. toaster.pop('error', '数据加载失败', response.data);
  1151. });
  1152. }
  1153. });
  1154. // 添加合作关系
  1155. $scope.addPartner = function (name, businessCode) {
  1156. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  1157. if (data.success) {
  1158. toaster.pop("success", '添加成功', data.success);
  1159. $scope.tableParams.reload();
  1160. }
  1161. if (data.error) {
  1162. toaster.pop("error", '添加失败', data.error);
  1163. }
  1164. }, function (response) {
  1165. toaster.pop('error', '失败', response.data);
  1166. });
  1167. }
  1168. // 物料搜索
  1169. var getProdService = function () {
  1170. return SearchProd;
  1171. };
  1172. $scope.prodTableParams = new ngTableParams({
  1173. page: 1,
  1174. count: 20,
  1175. sorting: {}
  1176. }, {
  1177. total: 0,
  1178. counts: [5, 10, 25, 50],
  1179. getData: function ($defer, params) {
  1180. $scope.loading = true;
  1181. var pageParams = params.url();
  1182. pageParams.keyword = $rootScope.searchKeyword;
  1183. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1184. $scope.loading = false;
  1185. if (page) {
  1186. $scope.prodtotal = page.totalElement;
  1187. params.total(page.totalElement);
  1188. $defer.resolve(page.content);
  1189. }
  1190. }, function (response) {
  1191. $scope.loading = false;
  1192. toaster.pop('error', '数据加载失败', response.data);
  1193. });
  1194. }
  1195. });
  1196. /**
  1197. * 向企业购买
  1198. */
  1199. $scope.PurcByEn = function (businessCode) {
  1200. $rootScope.businessCode = businessCode;
  1201. window.location.hash = "#/purc/addOrder";
  1202. }
  1203. /**
  1204. * 选中单个物料购买
  1205. * @param businessCode
  1206. * @param id
  1207. */
  1208. $scope.PurcByEnAndProd = function (businessCode, id) {
  1209. $rootScope.businessCode = businessCode;
  1210. $rootScope.prodId = id;
  1211. window.location.hash = "#/purc/addOrder";
  1212. }
  1213. /**
  1214. * 询价
  1215. */
  1216. $scope.PurcInquiry = function (businessCode, id) {
  1217. $rootScope.prodId = id;
  1218. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1219. }
  1220. /**
  1221. * 邀请注册商务平台
  1222. */
  1223. $scope.invite = function (name) {
  1224. var modalInstance = $modal.open({
  1225. animation: true,
  1226. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1227. controller: 'InviteCtrl',
  1228. resolve: {
  1229. enname: function () {
  1230. return name
  1231. }
  1232. }
  1233. });
  1234. modalInstance.result.then(function (data) {
  1235. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1236. if (data.success) {
  1237. toaster.pop('success', '提示', data.success);
  1238. }
  1239. if (data.error) {
  1240. toaster.pop('error', '提示', data.error);
  1241. }
  1242. }, function (response) {
  1243. toaster.pop('error', '提示', response.data);
  1244. });
  1245. });
  1246. }
  1247. /**
  1248. * 立即查看
  1249. */
  1250. $scope.view = function (name) {
  1251. $rootScope.vendName = name;
  1252. window.location.hash = "#/baseInfo/newPartner";
  1253. }
  1254. }]);
  1255. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', 'InvitationRecord', '$modal', function ($scope, toaster, $modalInstance, enname, InvitationRecord, $modal) {
  1256. $scope.enter = {
  1257. vendname: enname
  1258. };
  1259. $scope.save = function (enter) {
  1260. // 先检验是否已注册
  1261. InvitationRecord.enterpriseList({name: enter.vendname}, {}, function(data) {
  1262. $scope.existEn = data;
  1263. if ($scope.existEn.length == 0) {
  1264. $modalInstance.close(enter);
  1265. var modalInstance = $modal.open({
  1266. animation: true,
  1267. templateUrl: 'static/tpl/index/baseInfo/modal/QQshare_modal.html',
  1268. controller: 'QQShareCtrl',
  1269. });
  1270. } else {
  1271. $scope.enterprise = $scope.existEn[0];
  1272. }
  1273. });
  1274. }
  1275. $scope.viewDetail = function() {
  1276. $scope.exist = 1;
  1277. }
  1278. $scope.cancel = function () {
  1279. $modalInstance.dismiss();
  1280. }
  1281. $scope.closeDetail = function() {
  1282. $scope.exist = 0;
  1283. }
  1284. /**
  1285. * 添加合作伙伴
  1286. * @param enterprise
  1287. */
  1288. $scope.addPartner = function(en) {
  1289. InvitationRecord.addPart({inviteEnUU: $scope.enterprise.uu, inviteUserName: en.vendusername, inviteUserTel: en.vendusertel}, {}, function(data) {
  1290. if (data.success) {
  1291. toaster.pop('success', data.success);
  1292. $modalInstance.dismiss();
  1293. } else if (data.error) {
  1294. toaster.pop('error', data.error);
  1295. }
  1296. }, function(response) {
  1297. toaster.pop('error', response.data);
  1298. });
  1299. }
  1300. }]);
  1301. /**
  1302. * QQ分享
  1303. */
  1304. app.controller('QQShareCtrl', ['$scope', 'InvitationRecord', '$modalInstance', function($scope, InvitationRecord, $modalInstance) {
  1305. InvitationRecord.getInviteUrl({}, function(data) {
  1306. $scope.inviteUrl = data.url;
  1307. var p = {
  1308. url: $scope.inviteUrl, /*获取URL,可加上来自分享到QQ标识,方便统计*/
  1309. // desc: 'hejq', /*分享理由(风格应模拟用户对话),支持多分享语随机展现(使用|分隔)*/
  1310. // title: '', /*分享标题(可选)*/
  1311. // summary: '', /*分享摘要(可选)*/
  1312. // pics: '', /*分享图片(可选)*/
  1313. // flash: '', /*视频地址(可选)*/
  1314. // site: '', /*分享来源(可选) 如:QQ分享*/
  1315. // style: '201',
  1316. // width: 32,
  1317. // height: 32
  1318. };
  1319. var s = [];
  1320. for(var i in p){
  1321. s.push(i + '=' + encodeURIComponent(p[i]||''));
  1322. }
  1323. s.join('&');
  1324. $scope.QQshare = function() {
  1325. window.open("http://connect.qq.com/widget/shareqq/index.html?" + s)
  1326. }
  1327. });
  1328. $scope.close = function() {
  1329. $modalInstance.dismiss();
  1330. }
  1331. }]);
  1332. /**
  1333. * 再次邀请
  1334. */
  1335. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function ($scope, toaster, $modalInstance, id, InvitationRecord) {
  1336. var loadData = function (id) {
  1337. InvitationRecord.getRecordById({id: id}, {}, function (data) {
  1338. if (data.user !== null) {
  1339. data.user = {};
  1340. }
  1341. $scope.enter = data;
  1342. });
  1343. };
  1344. loadData(id);
  1345. $scope.save = function (enter) {
  1346. if (!enter.vendusertel && !enter.venduseremail) {
  1347. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1348. } else {
  1349. $modalInstance.close(enter);
  1350. }
  1351. };
  1352. $scope.cancel = function () {
  1353. $modalInstance.dismiss();
  1354. }
  1355. }]);
  1356. /**
  1357. * 邀请记录
  1358. */
  1359. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function ($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1360. BaseService.scrollBackToTop();
  1361. $scope.status = "invitation";
  1362. $scope.active = "invitation";
  1363. var getService = function () {
  1364. if ($scope.active === "invitation") {
  1365. return InvitationRecord.records;
  1366. } else if ($scope.active === "invitationTeam") {
  1367. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1368. }
  1369. };
  1370. $scope.setActive = function (state) {
  1371. if ($scope.active !== state) {
  1372. $scope.active = state;
  1373. if ($scope.tableParams.page() === 1)
  1374. $scope.tableParams.reload();
  1375. else
  1376. $scope.tableParams.page(1);
  1377. }
  1378. };
  1379. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1380. page: 1,
  1381. count: 20,
  1382. sorting: {}
  1383. }, {
  1384. total: 0,
  1385. counts: [],
  1386. getData: function ($defer, params) { // 获取数据的方法
  1387. $scope.loading = true;
  1388. var pageParams = params.url();
  1389. pageParams.keyword = $scope.keyword;
  1390. $scope.tip = $scope.keyword;
  1391. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  1392. $scope.loading = false;
  1393. if (page) {
  1394. params.total(page.totalElement);
  1395. $defer.resolve(page.content);
  1396. }
  1397. }, function (response) {
  1398. $scope.loading = false;
  1399. toaster.pop('error', '数据加载失败', response.data);
  1400. });
  1401. }
  1402. });
  1403. $scope.onSearch = function (keyword) {
  1404. $scope.tableParams.page(1);
  1405. $scope.tableParams.reload();
  1406. $scope.tip = keyword;
  1407. }
  1408. $scope.search = function (name) {
  1409. $modal.open({
  1410. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1411. controller: 'FuzzySearchCtrl',
  1412. resolve: {
  1413. name: function () {
  1414. return name
  1415. }
  1416. }
  1417. }).result.then(function (data) {
  1418. });
  1419. };
  1420. // 再次邀请
  1421. $scope.reInvite = function (id) {
  1422. var modalInstance = $modal.open({
  1423. animation: true,
  1424. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1425. controller: 'ReInviteCtrl',
  1426. resolve: {
  1427. id: function () {
  1428. return id
  1429. }
  1430. }
  1431. });
  1432. modalInstance.result.then(function (data) {
  1433. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1434. if (data.success) {
  1435. toaster.pop('success', '提示', data.success);
  1436. $scope.tableParams.reload();
  1437. }
  1438. if (data.error) {
  1439. toaster.pop('error', '提示', data.error);
  1440. }
  1441. }, function (response) {
  1442. toaster.pop('error', '提示', response.data);
  1443. });
  1444. });
  1445. }
  1446. }]);
  1447. /**
  1448. * 模糊查询相似的企业名称
  1449. */
  1450. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function ($scope, name, InvitationRecord, toaster, BaseService) {
  1451. $scope.name = name;
  1452. if ($scope.name != null) {
  1453. InvitationRecord.enterpriseList({name: $scope.name}, {}, function (data) {
  1454. $scope.enterprises = data;
  1455. }, function (response) {
  1456. toaster.pop('error', '提示', response.data);
  1457. });
  1458. }
  1459. }]);
  1460. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function ($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1461. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1462. AuthenticationService.getAuthentication().success(function (data) {
  1463. if (data.enterprises) {
  1464. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1465. if (data.enterprises.length > 1) {
  1466. var enSelect = [];
  1467. angular.forEach(data.enterprises, function (e) {
  1468. if (e.current)
  1469. data.enterprise = e;
  1470. else
  1471. enSelect.push(e);
  1472. });
  1473. data.enSelect = enSelect;
  1474. }
  1475. }
  1476. $scope.userInfo = data;
  1477. if (data == null || !data.userUU) {
  1478. $scope.isAuthed = false;
  1479. AuthenticationService.redirectSignin();
  1480. } else {
  1481. }
  1482. });
  1483. $scope.logout = function () {
  1484. $modal.open({
  1485. templateUrl: 'static/tpl/index/account/logout.html',
  1486. controller: 'LogOutCtrl'
  1487. }).result.then(function (s) {
  1488. if (s) {
  1489. AuthenticationService.logout();
  1490. }
  1491. });
  1492. };
  1493. // 打开登录模态框
  1494. $scope.signinModal = function() {
  1495. // 跳转账户中心
  1496. AuthenticationService.redirectSignin();
  1497. };
  1498. // 注册
  1499. $scope.registerModal = function() {
  1500. // 跳转账户中心
  1501. AuthenticationService.redirectRegister();
  1502. };
  1503. $scope.switchto = function (enUU) {// 切换企业
  1504. AuthenticationService.reSignin(enUU).success(function (response) {
  1505. console.log(response);
  1506. if (!response) $window.location.reload();
  1507. $.ajax({
  1508. url:response.url,
  1509. data:response.data,
  1510. type:"get",
  1511. cache:false,
  1512. dataType:"jsonp",
  1513. jsonp:"callback",
  1514. jsonpCallback:"successCallback",
  1515. success:function(data){
  1516. console.log(data);
  1517. $window.location.reload();
  1518. },
  1519. error:function(data){
  1520. console.log(data);
  1521. $window.location.reload();
  1522. }
  1523. });
  1524. });
  1525. };
  1526. $scope.addFavorite = function () {
  1527. var url = encodeURI(window.location.href);
  1528. try {
  1529. //ie浏览器收藏方式
  1530. window.external.addFavorite(url, "优软商务平台");
  1531. } catch (e) {
  1532. try {
  1533. //火狐浏览器收藏方式
  1534. window.sidebar.addPanel("优软商务平台", url);
  1535. } catch (e) {
  1536. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加," +
  1537. "或手动在浏览器里进行设置。");
  1538. }
  1539. }
  1540. };
  1541. }]);
  1542. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1543. $scope.close = function (confirm) {
  1544. $modalInstance.close(confirm);
  1545. };
  1546. }]);
  1547. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1548. $scope.image = {src: null};
  1549. // 图片上传成功之后
  1550. $scope.onUploadSuccess = function (data) {
  1551. var path = data.path;
  1552. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1553. $scope.$apply(function () {
  1554. $scope.image.src = data.path;
  1555. $scope.image.thumb = path;
  1556. });
  1557. };
  1558. $scope.close = function () {
  1559. $modalInstance.dismiss();
  1560. };
  1561. $scope.confirm = function () {
  1562. $modalInstance.close($scope.image);
  1563. $scope.imageUrl = null;
  1564. };
  1565. }]);
  1566. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', '$modal',
  1567. function ($scope, SnapshotService, BaseService, $rootScope, $modal) {
  1568. BaseService.scrollBackToTop();
  1569. SnapshotService.getTodo(function (data) {
  1570. $scope.todo = data;
  1571. });
  1572. var getUnread = function () {
  1573. SnapshotService.getUnread('all', function (data) {
  1574. $scope.unread = data;
  1575. });
  1576. };
  1577. getUnread();
  1578. //去除红点
  1579. $scope.setOrdersRead = function (type) {
  1580. switch (type){
  1581. case 'product':
  1582. $scope.unread.product = 0;
  1583. break;
  1584. case 'vendorPerformanceAssess':
  1585. $scope.unread.vendorPerformanceAssess = 0;
  1586. break;
  1587. case 'customer':
  1588. $scope.unread.customer = 0;
  1589. break;
  1590. case 'purcProduct':
  1591. $scope.unread.purcProduct = 0;
  1592. break;
  1593. case 'vendor':
  1594. $scope.unread.purcVendor = 0;
  1595. break;
  1596. }
  1597. };
  1598. $scope.setTenderActive = function (active) {
  1599. $rootScope.tenderActive = active;
  1600. window.location.hash = '#/purc/tender';
  1601. }
  1602. }]);
  1603. // header
  1604. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1605. SnapshotService.getMessage(function (data) {
  1606. $scope.message = data;
  1607. });
  1608. }]);
  1609. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function ($scope, $rootScope, $modal, SaleTruck) {
  1610. SaleTruck.query({}, function (data) {
  1611. $rootScope.truck = data;
  1612. $scope.truckCount = data ? data.length : 0;
  1613. });
  1614. $scope.$watch(function () {
  1615. return $rootScope.truck;
  1616. }, function (data) {
  1617. $scope.truckCount = data ? data.length : 0;
  1618. }, true);
  1619. $scope.clearAll = function () {
  1620. SaleTruck.remove({}, function () {
  1621. $rootScope.truck = [];
  1622. });
  1623. };
  1624. $scope.openTrack = function () {
  1625. $modal.open({
  1626. templateUrl: 'static/tpl/index/sale/track.html',
  1627. controller: 'TruckModalCtrl',
  1628. size: 'lg'
  1629. }).result.then(function (s) {
  1630. if (s) {
  1631. $scope.clearAll();
  1632. $rootScope.dataChanged = true;
  1633. }
  1634. });
  1635. };
  1636. }]);
  1637. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', 'token', function ($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout, token) {
  1638. $scope.loading = false;
  1639. $scope.saleSend = {sendItems: []};
  1640. SaleTruck.detail({}, function (data) {
  1641. // 按物料编号排序
  1642. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1643. });
  1644. $scope.remove = function (index, notice) {
  1645. SaleTruck.remove({noticeId: notice.id}, function (data) {
  1646. $rootScope.truck = data;
  1647. $scope.notices.splice(index, 1);
  1648. });
  1649. };
  1650. $scope.$watch(function () {
  1651. return $scope.notices;
  1652. }, function (data) {
  1653. var q = 0, t = 0;
  1654. if (data) {
  1655. angular.forEach(data, function (d) {
  1656. q += d.thisSendQty;
  1657. t += d.thisSendQty * d.orderItem.price;
  1658. });
  1659. }
  1660. $scope.totalQty = q;
  1661. $scope.total = t;
  1662. }, true);
  1663. $scope.cancel = function () {
  1664. $modalInstance.close();
  1665. };
  1666. $scope.lockstatus = false;
  1667. // 锁定时间按钮5秒
  1668. $scope.lockClick = function () {
  1669. $scope.lockstatus = true;
  1670. $timeout(function () {
  1671. $scope.lockstatus = false;
  1672. }, 5000);
  1673. }
  1674. var getToken = function() {
  1675. token.info({userType: 'salenotice'}, {}, function(data) {
  1676. $scope.token = data.token;
  1677. }, function(response) {
  1678. toaster.pop('error', '提示', response.data);
  1679. });
  1680. }
  1681. getToken();
  1682. $scope.send = function () {// 发货
  1683. $scope.loading = true;
  1684. if (!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1685. toaster.pop('error', '错误', '请输入送货单号');
  1686. $scope.loading = false;
  1687. return;
  1688. }
  1689. var currency = $scope.notices[0].orderItem.order.currency,
  1690. custUU = $scope.notices[0].enUU,
  1691. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1692. var num = 1;
  1693. for (var i in $scope.notices) {
  1694. var item = $scope.notices[i];
  1695. if (item.id) {
  1696. if (item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1697. valid = false;
  1698. break;
  1699. }
  1700. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++};
  1701. }
  1702. }
  1703. if (!valid) {
  1704. $scope.loading = false;
  1705. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  1706. } else {
  1707. var send = angular.extend(angular.copy($scope.saleSend), {
  1708. currency: currency,
  1709. custUU: custUU,
  1710. payments: payments,
  1711. sendItems: items
  1712. });
  1713. if($scope.token != null) {
  1714. PurcNotice.sendByBatch({token: $scope.token}, send, function (data) {
  1715. $scope.loading = false;
  1716. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1717. $modalInstance.close(true);
  1718. $state.go('sale.send_detail', {id: data.id});
  1719. }, function (response) {
  1720. $scope.loading = false;
  1721. toaster.pop('error', '错误', response.data);
  1722. });
  1723. }
  1724. }
  1725. $scope.setCheckedNoticeRead = function () {
  1726. var ids = [];
  1727. for (var i in $scope.notices) {
  1728. var item = $scope.notices[i];
  1729. if (item.id) {
  1730. ids.push(item.id);
  1731. }
  1732. }
  1733. PurcNotice.setRead({}, ids, function (message) {
  1734. });
  1735. }
  1736. };
  1737. }]);
  1738. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1739. SaleStat.cust({}, function (data) {
  1740. var p = [], q = [];
  1741. angular.forEach(data.month, function (d) {
  1742. p.push({
  1743. x: (d.enterprise.enShortname || d.enterprise.enName),
  1744. y: [(d.total || 0)],
  1745. tooltip: (d.total || 0)
  1746. });
  1747. });
  1748. angular.forEach(data.year, function (d) {
  1749. q.push({
  1750. x: (d.enterprise.enShortname || d.enterprise.enName),
  1751. y: [(d.total || 0)],
  1752. tooltip: (d.total || 0)
  1753. });
  1754. });
  1755. $scope.custCharts = {
  1756. month: {
  1757. chartType: 'pie',
  1758. datas: {
  1759. data: p
  1760. },
  1761. config: {
  1762. labels: false,
  1763. title: "客户月采购量排行榜",
  1764. legend: {
  1765. display: true,
  1766. position: 'right'
  1767. },
  1768. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1769. click: function (d) {
  1770. },
  1771. mouseover: function (d) {
  1772. },
  1773. mouseout: function (d) {
  1774. },
  1775. innerRadius: 0,
  1776. lineLegend: 'lineEnd'
  1777. }
  1778. },
  1779. year: {
  1780. chartType: 'pie',
  1781. datas: {
  1782. data: q
  1783. },
  1784. config: {
  1785. labels: false,
  1786. title: "客户年采购量排行榜",
  1787. legend: {
  1788. display: true,
  1789. position: 'right'
  1790. },
  1791. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1792. click: function (d) {
  1793. },
  1794. mouseover: function (d) {
  1795. },
  1796. mouseout: function (d) {
  1797. },
  1798. innerRadius: 0,
  1799. lineLegend: 'lineEnd'
  1800. }
  1801. }
  1802. };
  1803. });
  1804. SaleStat.seller({}, function (data) {
  1805. var p = [], q = [];
  1806. angular.forEach(data.month, function (d) {
  1807. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1808. });
  1809. angular.forEach(data.year, function (d) {
  1810. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1811. });
  1812. $scope.sellerCharts = {
  1813. month: {
  1814. chartType: 'pie',
  1815. datas: {
  1816. data: p
  1817. },
  1818. config: {
  1819. labels: false,
  1820. title: "业务员月销量排行榜",
  1821. legend: {
  1822. display: true,
  1823. position: 'right'
  1824. },
  1825. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1826. click: function (d) {
  1827. },
  1828. mouseover: function (d) {
  1829. },
  1830. mouseout: function (d) {
  1831. },
  1832. innerRadius: 0,
  1833. lineLegend: 'lineEnd'
  1834. }
  1835. },
  1836. year: {
  1837. chartType: 'pie',
  1838. datas: {
  1839. data: q
  1840. },
  1841. config: {
  1842. labels: false,
  1843. title: "业务员年销量排行榜",
  1844. legend: {
  1845. display: true,
  1846. position: 'right'
  1847. },
  1848. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1849. click: function (d) {
  1850. },
  1851. mouseover: function (d) {
  1852. },
  1853. mouseout: function (d) {
  1854. },
  1855. innerRadius: 0,
  1856. lineLegend: 'lineEnd'
  1857. }
  1858. }
  1859. };
  1860. });
  1861. }]);
  1862. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1863. SaleStat.get({}, function (data) {
  1864. var p = [], q = [], r = [];
  1865. angular.forEach(data.day, function (d) {
  1866. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1867. });
  1868. angular.forEach(data.month, function (d) {
  1869. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1870. });
  1871. angular.forEach(data.year, function (d) {
  1872. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1873. });
  1874. $scope.charts = {
  1875. day: {
  1876. chartType: "line",
  1877. datas: {
  1878. series: ['销售额'],
  1879. data: p
  1880. },
  1881. config: {
  1882. "labels": false,
  1883. "title": "销售额统计(近15日线)",
  1884. "legend": {
  1885. "display": true,
  1886. "position": "right"
  1887. },
  1888. colors: ['#4D9934'],
  1889. "innerRadius": 0,
  1890. "lineLegend": "lineEnd"
  1891. }
  1892. },
  1893. month: {
  1894. chartType: "line",
  1895. datas: {
  1896. series: ['销售额'],
  1897. data: q
  1898. },
  1899. config: {
  1900. "labels": false,
  1901. "title": "销售额统计(近12月线)",
  1902. "legend": {
  1903. "display": true,
  1904. "position": "right"
  1905. },
  1906. colors: ['#4D9934'],
  1907. "innerRadius": 0,
  1908. "lineLegend": "lineEnd"
  1909. }
  1910. },
  1911. year: {
  1912. chartType: "line",
  1913. datas: {
  1914. series: ['销售额'],
  1915. data: r
  1916. },
  1917. config: {
  1918. "labels": false,
  1919. "title": "销售额统计(近10年线)",
  1920. "legend": {
  1921. "display": true,
  1922. "position": "right"
  1923. },
  1924. colors: ['#4D9934'],
  1925. "innerRadius": 0,
  1926. "lineLegend": "lineEnd"
  1927. }
  1928. }
  1929. };
  1930. });
  1931. }]);
  1932. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', 'AuthenticationService', function ($scope, SnapshotService, AuthenticationService) {
  1933. AuthenticationService.getAuthentication().success(function (data) {
  1934. $scope.loading = false;
  1935. $scope.useruu = data.userUU;
  1936. SnapshotService.getNotice(7, $scope.useruu, function (data) { //5表示首页显示的公告条数
  1937. $scope.notices = data;
  1938. });
  1939. /**
  1940. * 设置单据阅读状态
  1941. * @param id
  1942. */
  1943. $scope.setReadStatus = function(id) {
  1944. SnapshotService.setNoticeStatusAfterRead(id, $scope.useruu);
  1945. }
  1946. /**
  1947. * 判断是否当天时间
  1948. * @param date
  1949. * @param time
  1950. * @returns {boolean}
  1951. */
  1952. $scope.isCurrentTime = function(date, time) {
  1953. var date1 = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
  1954. var date2 = new Date(time).getFullYear() + '-' + new Date(time).getMonth() + 1 + '-' + new Date(time).getDate();
  1955. return date1 == date2;
  1956. }
  1957. });
  1958. $scope.dateTime = new Date();
  1959. $scope.time = new Date().getTime();
  1960. /**
  1961. * 收起展开公告
  1962. */
  1963. $scope.show = false;
  1964. $scope.showGongGao = function () {
  1965. $scope.show = !$scope.show
  1966. }
  1967. }]);
  1968. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1969. SnapshotService.getOpenTender(5, function (data) {
  1970. $scope.openTenders = data;
  1971. var newDate = new Date();
  1972. newDate = newDate.getTime() - 3 * 24 * 60 * 60 * 1000;
  1973. angular.forEach($scope.openTenders, function (tender) {
  1974. if (tender.date - newDate > 0) {
  1975. tender.isNew = true;
  1976. } else {
  1977. tender.isNew = false;
  1978. }
  1979. });
  1980. });
  1981. $scope.dateTime = new Date();
  1982. }]);
  1983. app.controller('VendCountCtrl', ['$scope', 'VendorService', function ($scope, VendorService) {
  1984. VendorService.getCount(function (date) {
  1985. $scope.count = date;
  1986. });
  1987. }]);
  1988. // 客户
  1989. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  1990. BaseService.scrollBackToTop();
  1991. $scope.userInfoResult = true;
  1992. AuthenticationService.getAuthentication().success(function (data) {
  1993. $scope.loading = false;
  1994. $scope.thisUser = data;
  1995. });
  1996. // 获取当前用户分配客户的操作权限
  1997. CurrentRole.roles({}, function (data) {
  1998. // 存在权限或者user表sys字段为1时
  1999. $scope.enabled = data.count > 0 || $scope.thisUser.sys;
  2000. }, function (response) {
  2001. });
  2002. var getCustInfos = function (custuu) {
  2003. if (custuu) {
  2004. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  2005. $scope.custInfos = data;
  2006. var getPage = function (page, size) {
  2007. if ($scope.custInfos) {
  2008. var result = {};
  2009. result.totalCount = $scope.custInfos.length;
  2010. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  2011. if ($scope.custInfos.length % size == 0) {
  2012. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2013. } else {
  2014. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2015. }
  2016. result.first = page == 1;
  2017. result.last = page == result.totalPage;
  2018. result.page = page;
  2019. result.next = page - 0 + 1;
  2020. result.pre = page - 1;
  2021. return result;
  2022. }
  2023. }
  2024. $scope.userdata = getPage(1, 4);
  2025. $scope.first = function () {
  2026. $scope.userdata = getPage($scope.userdata.pre, 4);
  2027. }
  2028. $scope.last = function () {
  2029. $scope.userdata = getPage($scope.userdata.next, 4);
  2030. }
  2031. }, function (response) {
  2032. $scope.loading = false;
  2033. toaster.pop('error', '数据加载失败', response.data);
  2034. });
  2035. }
  2036. }
  2037. // 分配用户
  2038. $scope.addUserInfo = function (customer) {
  2039. if (!$scope.enabled) {
  2040. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  2041. return;
  2042. }
  2043. // 获取当前用户在当前企业是否被转移权限
  2044. AccountUser.getEnTransfer ({custUU: customer.myEnterprise.uu}, function(data) {
  2045. customer.enTransfer = data.result;
  2046. //是管理员,或者被转移了权限时
  2047. if ($scope.enabled || customer.enTransfer) {
  2048. var modalInstance = $modal.open({
  2049. animation: true,
  2050. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2051. controller: 'AddUserInfoCtrl',
  2052. resolve: {
  2053. customer: function () {
  2054. return customer;
  2055. }
  2056. }
  2057. });
  2058. modalInstance.result.then(function (changed, checked) {
  2059. if (changed) {
  2060. if (checked)
  2061. $scope.newUser.roles = checked;
  2062. else
  2063. loadUsers();
  2064. }
  2065. });
  2066. } else {
  2067. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  2068. }
  2069. });
  2070. };
  2071. // 转移权限
  2072. $scope.transferUserInfo = function (customer) {
  2073. customer.enDistribute = null;
  2074. if (!$scope.enabled) {
  2075. toaster.pop('error', '您没有转移当前客户权限的权限!');
  2076. return;
  2077. }
  2078. // 获取当前用户在当前企业是否被转移权限
  2079. AccountUser.getDistribute ({custUU: customer.myEnterprise.uu}, function(data) {
  2080. customer.enDistribute = data.result;
  2081. //是管理员,或者被分配时
  2082. if ($scope.enabled || customer.enDistribute) {
  2083. var modalInstance = $modal.open({
  2084. animation: true,
  2085. templateUrl: 'static/tpl/index/account/transfer_userInfo.html',
  2086. controller: 'TransferUserInfoCtrl',
  2087. resolve: {
  2088. customer: function () {
  2089. return customer;
  2090. }
  2091. }
  2092. });
  2093. modalInstance.result.then(function (changed, checked) {
  2094. if (changed) {
  2095. if (checked)
  2096. $scope.newUser.roles = checked;
  2097. else
  2098. loadUsers();
  2099. }
  2100. });
  2101. } else {
  2102. toaster.pop('error', '您没有转移当前客户权限的权限!');
  2103. }
  2104. });
  2105. };
  2106. $scope.showUserInfo = function (customer, boo) {
  2107. $scope.custInfo = customer;
  2108. if (boo) {
  2109. getCustInfos(customer.myEnterprise.uu);
  2110. $scope.userInfoResult = true;
  2111. }
  2112. };
  2113. var getService = function () {
  2114. return VendorService;
  2115. };
  2116. $scope.customerParams = new ngTableParams({
  2117. page: 1,
  2118. count: 20
  2119. }, {
  2120. total: 0,
  2121. counts: [5, 10, 25, 50],
  2122. getData: function ($defer, params) {
  2123. $scope.loading = true;
  2124. var pageParams = params.url();
  2125. pageParams.keyword = $scope.keyword;
  2126. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  2127. $scope.loading = false;
  2128. if (page) {
  2129. params.total(page.totalElement);
  2130. $defer.resolve(page.content);
  2131. $scope.keywordXls = pageParams.keyword;
  2132. }
  2133. $scope.totalCount = page.totalElement;
  2134. }, function (response) {
  2135. $scope.loading = false;
  2136. toaster.pop('error', '数据加载失败', response.data);
  2137. });
  2138. }
  2139. });
  2140. //设置消息已读
  2141. var setOrdersRead = function () {
  2142. var sourceId = [];
  2143. Vendor.setRead({}, sourceId, function (message) {
  2144. // $scope.getUnreadIds();
  2145. });
  2146. };
  2147. setOrdersRead();
  2148. // 搜索框回车
  2149. $scope.onSearch = function (keyword) {
  2150. $scope.customerParams.page(1);
  2151. $scope.customerParams.reload();
  2152. $scope.tip = keyword;
  2153. };
  2154. // 查看详情
  2155. $scope.viewDetail = function (id) {
  2156. window.location.hash = "#/sale/customer/" + id;
  2157. }
  2158. // 导出客户资料列表
  2159. $scope.exportXls = function () {
  2160. VendorService.exportXls.get({}, {}, function (data) {
  2161. if (data.success){
  2162. window.location.href = 'vendor/customer/xls?keyword='+ ($scope.keywordXls || '');
  2163. }
  2164. }, function (response) {
  2165. toaster.pop('error', '数据加载失败', response.data);
  2166. });
  2167. }
  2168. }]);
  2169. // 客户详情
  2170. 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) {
  2171. BaseService.scrollBackToTop();
  2172. $scope.userInfoResult = true;
  2173. AuthenticationService.getAuthentication().success(function (data) {
  2174. $scope.loading = false;
  2175. $scope.thisUser = data;
  2176. });
  2177. $scope.vendorContacts = [];
  2178. var loadData = function () {
  2179. Vendor.getCustomerDetail({id: $stateParams.id}, {}, function (data) {
  2180. $scope.customer = data.myEnterprise;
  2181. $scope.customerInfo = data;
  2182. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function (data) {
  2183. $scope.Contacts = data;
  2184. });
  2185. // 查看已分配人员
  2186. VendorService.userInfo.query({uu: $scope.customer.uu}, null, function (data) {
  2187. $scope.custInfos = data;
  2188. var getPage = function (page, size) {
  2189. if ($scope.custInfos) {
  2190. var result = {};
  2191. result.totalCount = $scope.custInfos.length;
  2192. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  2193. if ($scope.custInfos.length % size == 0) {
  2194. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2195. } else {
  2196. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2197. }
  2198. result.first = page == 1;
  2199. result.last = page == result.totalPage;
  2200. result.page = page;
  2201. result.next = page - 0 + 1;
  2202. result.pre = page - 1;
  2203. return result;
  2204. }
  2205. }
  2206. $scope.userdata = getPage(1, 4);
  2207. $scope.first = function () {
  2208. $scope.userdata = getPage($scope.userdata.pre, 4);
  2209. }
  2210. $scope.last = function () {
  2211. $scope.userdata = getPage($scope.userdata.next, 4);
  2212. }
  2213. }, function (response) {
  2214. $scope.loading = false;
  2215. toaster.pop('error', '数据加载失败', response.data);
  2216. });
  2217. }, function (response) {
  2218. $scope.loading = false;
  2219. toaster.pop('error', '数据加载失败', response.data);
  2220. });
  2221. };
  2222. loadData();
  2223. // 新增客户联系人
  2224. $scope.addContact = function (uu) {
  2225. var modalInstance = $modal.open({
  2226. animation: true,
  2227. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2228. controller: 'AddContacCtrl',
  2229. resolve: {}
  2230. });
  2231. modalInstance.result.then(function (data) {
  2232. $scope.contact = data;
  2233. $scope.contact.myenuu = uu;
  2234. Vendor.saveCustContact({}, $scope.contact, function (data) {
  2235. toaster.pop('success', '提示', '联系人保存成功');
  2236. $scope.Contacts.push(data);
  2237. }, function (response) {
  2238. toaster.pop('error', '失败', response.data);
  2239. });
  2240. });
  2241. }
  2242. // 编辑客户联系人
  2243. $scope.edit = function (contact) {
  2244. var modalInstance = $modal.open({
  2245. animation: true,
  2246. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2247. controller: 'EditContacCtrl',
  2248. resolve: {
  2249. contact: function () {
  2250. return contact;
  2251. }
  2252. }
  2253. });
  2254. modalInstance.result.then(function (data) {
  2255. Vendor.saveContact({}, data, function (data) {
  2256. loadData();
  2257. toaster.pop('success', '提示', '联系人修改成功');
  2258. }, function (response) {
  2259. toaster.pop('error', '失败', response.data);
  2260. });
  2261. });
  2262. }
  2263. // 删除客户联系人
  2264. $scope.deleteById = function (id, index) {
  2265. $scope.Contacts.splice(index, 1);
  2266. Vendor.deleteContact({id: id}, {}, function (data) {
  2267. toaster.pop('success', '提示', '客户联系人删除成功');
  2268. loadData();
  2269. }, function (response) {
  2270. toaster.pop('error', '提示', response.data);
  2271. });
  2272. }
  2273. // 供应商物料信息
  2274. $scope.viewProdList = function (uu) {
  2275. $scope.uu = uu;
  2276. $scope.tableParams.page(1);
  2277. $scope.tableParams.reload();
  2278. };
  2279. // 搜索框回车
  2280. $scope.onSearch = function (keyword) {
  2281. $scope.keyword = keyword;
  2282. $scope.tableParams.page(1);
  2283. $scope.tableParams.reload();
  2284. };
  2285. // 供应商物料信息
  2286. $scope.tableParams = new ngTableParams({
  2287. page: 1,
  2288. count: 20
  2289. }, {
  2290. total: 0,
  2291. counts: [5, 10, 25, 50],
  2292. getData: function ($defer, params) {
  2293. $scope.loading = true;
  2294. var pageParams = params.url();
  2295. pageParams.custUU = $scope.uu;
  2296. pageParams.keyword = $scope.keyword;
  2297. $scope.tip = $scope.keyword;
  2298. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  2299. $scope.loading = false;
  2300. if (page) {
  2301. params.total(page.totalElement);
  2302. $scope.total = page.totalElement;
  2303. $defer.resolve(page.content);
  2304. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2305. }
  2306. }, function (response) {
  2307. $scope.loading = false;
  2308. toaster.pop('error', '数据加载失败', response.data);
  2309. });
  2310. }
  2311. });
  2312. $scope.addUserInfo = function () {
  2313. //TODO
  2314. if ($scope.thisUser.sys) {
  2315. var modalInstance = $modal.open({
  2316. animation: true,
  2317. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2318. controller: 'AddUserInfoCtrl',
  2319. resolve: {
  2320. customer: function () {
  2321. return $scope.customerInfo;
  2322. }
  2323. }
  2324. });
  2325. modalInstance.result.then(function (changed, checked) {
  2326. loadData();
  2327. if (changed) {
  2328. if (checked) {
  2329. $scope.newUser.roles = checked;
  2330. } else {
  2331. loadUsers();
  2332. }
  2333. }
  2334. });
  2335. } else {
  2336. toaster.pop('error', '您不是管理员,无权限分配用户!');
  2337. }
  2338. }
  2339. $scope.Quotation = function (uu, id) {
  2340. $rootScope.custuu = uu;
  2341. $rootScope.prodId = id;
  2342. window.location.hash = "#/sale/quotation/new";
  2343. }
  2344. }]);
  2345. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function ($scope, $modalInstance, customer, AccountUser, toaster) {
  2346. $scope.checkboxes = {
  2347. checked: false
  2348. };
  2349. $scope.loading = true;
  2350. $scope.distribute = [];
  2351. AccountUser.findUsers({uu: customer.myEnterprise.uu}, null, function (data) {
  2352. $scope.userinfos = data;
  2353. var distribute = [];
  2354. angular.forEach($scope.userinfos, function (user, index) {
  2355. if (user.distribute) {
  2356. distribute.push({num: index});
  2357. }
  2358. });
  2359. $scope.distribute = distribute;
  2360. $scope.havedone = angular.copy($scope.distribute);
  2361. $scope.loading = false;
  2362. })
  2363. var checkStatus = function (userinfos) {
  2364. var distribute = [];
  2365. angular.forEach(userinfos, function (user, index) {
  2366. if (user.distribute) {
  2367. distribute.push({num: index});
  2368. }
  2369. });
  2370. $scope.distribute = distribute;
  2371. $scope.isChanged = !angular.equals($scope.havedone, $scope.distribute);
  2372. }
  2373. $scope.isChanged = false;
  2374. $scope.isChangedAll = false;
  2375. $scope.changes = [];
  2376. // 点击勾选全部的复选框
  2377. $scope.checkAll = function () {
  2378. angular.forEach($scope.userinfos, function (item, index) {
  2379. item.distribute = $scope.checkboxes.checked;
  2380. });
  2381. checkStatus($scope.userinfos);
  2382. };
  2383. // 点击其中一个明细的复选框
  2384. $scope.checkOne = function () {
  2385. var result = true;
  2386. angular.forEach($scope.userinfos, function (item) {
  2387. if (item.distribute != true) {
  2388. result = false;
  2389. return;
  2390. }
  2391. });
  2392. $scope.checkboxes.checked = result;
  2393. checkStatus($scope.userinfos);
  2394. };
  2395. $scope.close = function (save) {
  2396. var chooseResult = [];
  2397. if (save) {
  2398. if (customer.myEnterprise.uu) {
  2399. angular.forEach($scope.userinfos, function (item, i) {
  2400. chooseResult.push(item);
  2401. });
  2402. if (chooseResult.length > 0) {
  2403. $scope.loading = true;
  2404. AccountUser.addUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2405. $scope.loading = false;
  2406. toaster.pop('success', '提示', '保存成功');
  2407. $modalInstance.close(false);
  2408. }, function (response) {
  2409. $scope.loading = false;
  2410. toaster.pop('error', '保存失败', response.data);
  2411. $modalInstance.close(false);
  2412. })
  2413. } else {
  2414. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2415. }
  2416. } else {
  2417. $modalInstance.close(true, $scope.checkboxes.checked);
  2418. }
  2419. } else {
  2420. $modalInstance.close(false);
  2421. }
  2422. };
  2423. }]);
  2424. // 转移权限
  2425. app.controller('TransferUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', 'AuthenticationService', function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
  2426. AuthenticationService.getAuthentication().success(function (data) {
  2427. $scope.loading = false;
  2428. $scope.thisUser = data;
  2429. });
  2430. $scope.checkboxes = {
  2431. checked: false
  2432. };
  2433. $scope.loading = true;
  2434. $scope.transfer = [];
  2435. AccountUser.findUsers({uu: customer.myEnterprise.uu}, {}, function (data) {
  2436. $scope.userinfos = data;
  2437. var transfer = [];
  2438. angular.forEach($scope.userinfos, function (user, index) {
  2439. // 当前用户是被管理员转移权限时,转移的是被管理员转移的权限。
  2440. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2441. $scope.thisUser.transfer = true;
  2442. }
  2443. });
  2444. angular.forEach($scope.userinfos, function (user, index) {
  2445. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2446. if (user.transfer) {
  2447. transfer.push({num: index});
  2448. user.checked = true;
  2449. }
  2450. } else {
  2451. if (user.distribute) {
  2452. transfer.push({num: index});
  2453. user.checked = true;
  2454. }
  2455. }
  2456. });
  2457. $scope.transfer = transfer;
  2458. $scope.havedone = angular.copy($scope.transfer);
  2459. $scope.loading = false;
  2460. });
  2461. var checkStatus = function (userinfos) {
  2462. var transfer = [];
  2463. angular.forEach(userinfos, function (user, index) {
  2464. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2465. if (user.transfer) {
  2466. transfer.push({num: index});
  2467. }
  2468. } else {
  2469. if (user.distribute) {
  2470. transfer.push({num: index});
  2471. }
  2472. }
  2473. });
  2474. $scope.transfer = transfer;
  2475. $scope.isChanged = !angular.equals($scope.havedone, $scope.transfer);
  2476. };
  2477. $scope.isChanged = false;
  2478. $scope.isChangedAll = false;
  2479. $scope.changes = [];
  2480. // 点击其中一个明细的复选框
  2481. $scope.checkOne = function (user) {
  2482. $scope.changes = [];
  2483. if ($scope.thisUser.sys) { // 管理员操作
  2484. user.$checked = !user.$checked;
  2485. angular.forEach($scope.userinfos, function (userInfo) {
  2486. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2487. $scope.thisUser.transfer = true;
  2488. }
  2489. if (user.userUU !== userInfo.userUU) {
  2490. userInfo.transfer = false;
  2491. }
  2492. });
  2493. } else if ($scope.thisUser.transfer) { // 被管理员转移权限的非管理员操作
  2494. user.$checked = !user.$checked;
  2495. angular.forEach($scope.userinfos, function (userInfo) {
  2496. if (user.userUU !== userInfo.userUU) {
  2497. userInfo.transfer = false;
  2498. } else {
  2499. userInfo.transfer = true;
  2500. }
  2501. });
  2502. } else { // 被分配客户的用户
  2503. user.$checked = !user.$checked;
  2504. angular.forEach($scope.userinfos, function (userInfo) {
  2505. if (user.userUU !== userInfo.userUU) {
  2506. userInfo.distribute = false;
  2507. } else {
  2508. userInfo.distribute = true;
  2509. }
  2510. });
  2511. }
  2512. checkStatus($scope.userinfos);
  2513. };
  2514. $scope.close = function (save) {
  2515. var chooseResult = [];
  2516. if (save) {
  2517. if (customer.myEnterprise.uu) {
  2518. // 当前用户是管理员时
  2519. if ($scope.thisUser.sys) {
  2520. angular.forEach($scope.userinfos, function (item, i) {
  2521. chooseResult.push(item);
  2522. });
  2523. if (chooseResult.length > 0) {
  2524. $scope.loading = true;
  2525. AccountUser.transferUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2526. $scope.loading = false;
  2527. toaster.pop('success', '提示', '保存成功');
  2528. $modalInstance.close(false);
  2529. }, function (response) {
  2530. $scope.loading = false;
  2531. toaster.pop('error', '保存失败', response.data);
  2532. $modalInstance.close(false);
  2533. })
  2534. } else {
  2535. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2536. }
  2537. } else {
  2538. // 非管理员转移自己的权限时
  2539. angular.forEach($scope.userinfos, function (item, i) {
  2540. if (item.transfer && item.userUU !== $scope.thisUser.userUU) {
  2541. $scope.target = item;
  2542. }
  2543. });
  2544. if (!$scope.target) {
  2545. toaster.pop('error', '保存失败', "您未选择权限转移对象");
  2546. } else {
  2547. $scope.loading = true;
  2548. AccountUser.transferMyDistribute({custUU: customer.myEnterprise.uu, userUU: $scope.target.userUU}, {} ,function (data) {
  2549. $scope.loading = false;
  2550. toaster.pop('success', '提示', '保存成功');
  2551. $modalInstance.close(false);
  2552. }, function (response) {
  2553. $scope.loading = false;
  2554. toaster.pop('error', '保存失败', response.data);
  2555. $modalInstance.close(false);
  2556. });
  2557. }
  2558. }
  2559. } else {
  2560. $modalInstance.close(true, $scope.checkboxes.checked);
  2561. }
  2562. } else {
  2563. $modalInstance.close(false);
  2564. }
  2565. };
  2566. }]);
  2567. /**
  2568. * 页面状态按钮过滤
  2569. */
  2570. var getState = function (active) {
  2571. var fn = 'get';
  2572. switch (active) {
  2573. case 'done':
  2574. fn = 'getDone';
  2575. break;
  2576. case 'todo':
  2577. fn = 'getTodo';
  2578. break;
  2579. case 'end':
  2580. fn = 'getEnd';
  2581. break;
  2582. case 'waiting':
  2583. fn = 'getWaiting';
  2584. break;
  2585. case 'received':
  2586. fn = 'getReceived';
  2587. break;
  2588. case 'invalid':
  2589. fn = 'getInvalid';
  2590. break;
  2591. // 已采纳
  2592. case 'agreed':
  2593. fn = 'getAgreed';
  2594. break;
  2595. // 未采纳
  2596. case 'refused':
  2597. fn = 'getRefused';
  2598. break;
  2599. // 个人
  2600. case 'personal':
  2601. fn = 'getPersonal';
  2602. break;
  2603. // 集体
  2604. case 'teams':
  2605. fn = 'getTeams';
  2606. break;
  2607. // 非标准
  2608. case 'nonstandard':
  2609. fn = 'getNonstandard';
  2610. break;
  2611. // 标准
  2612. case 'standard':
  2613. fn = 'getStandard';
  2614. break;
  2615. // 变更单无需确认
  2616. case 'unread':
  2617. fn = 'getUnread';
  2618. break;
  2619. }
  2620. return fn;
  2621. };
  2622. /**
  2623. * 改变单据日期范围
  2624. */
  2625. var getDateCondition = function (zone, condition) {
  2626. var fromDate = new Date();
  2627. var toDate = new Date();
  2628. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  2629. fromDate.setHours(0, 0, 0, 0);
  2630. toDate.setHours(23, 59, 59, 999);
  2631. if (zone == -1) { // 自定义时间,什么都不做
  2632. } else if (zone == 1) {
  2633. fromDate.setMonth(fromDate.getMonth() - 1);
  2634. condition.dateFrom = fromDate;
  2635. condition.dateTo = toDate;
  2636. } else if (zone == 3) {
  2637. fromDate.setMonth(fromDate.getMonth() - 3);
  2638. condition.dateFrom = fromDate;
  2639. condition.dateTo = toDate;
  2640. } else if (zone == 6) {
  2641. fromDate.setMonth(fromDate.getMonth() - 6);
  2642. condition.dateFrom = fromDate;
  2643. condition.dateTo = toDate;
  2644. } else {
  2645. condition.dateFrom = null;
  2646. condition.dateTo = null;
  2647. }
  2648. };
  2649. /**
  2650. * 改变单据交货日期范围
  2651. */
  2652. var getDelveryCondition = function (zone, condition) {
  2653. var date = new Date();
  2654. if (zone == -1) {
  2655. condition.deliveryFrom = null;
  2656. condition.deliveryTo = null;
  2657. } else if (zone == 1) {
  2658. date.setMonth(date.getMonth() + 1);
  2659. condition.deliveryTo = date;
  2660. condition.deliveryFrom = new Date();
  2661. } else if (zone == 2) {
  2662. date.setMonth(date.getMonth() + 2);
  2663. condition.deliveryTo = date;
  2664. condition.deliveryFrom = new Date();
  2665. }
  2666. };
  2667. /**
  2668. * 将日期转化为整数日期
  2669. */
  2670. var getDateTime = function (date) {
  2671. if (angular.isDate(date)) {
  2672. return date.getTime();
  2673. } else {
  2674. return null;
  2675. }
  2676. };
  2677. /**
  2678. * 删除数组里某个特定的值
  2679. */
  2680. var removeByValue = function (arr, val) {
  2681. for(var i=0; i<arr.length; i++) {
  2682. if(arr[i] == val) {
  2683. arr.splice(i, 1);
  2684. break;
  2685. }
  2686. }
  2687. };
  2688. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrders', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope', 'PurchaseOrder', 'PurcOrdersInfo', 'PurcOrderItem', 'CurrentRole',
  2689. function ($scope, $filter, PurcOrders, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope, PurchaseOrder, PurcOrdersInfo, PurcOrderItem, CurrentRole) {
  2690. BaseService.scrollBackToTop();
  2691. // 获取当前用户是否为普通用户
  2692. CurrentRole.isUser({}, {}, function (data) {
  2693. $scope.isUser = data.isUser;
  2694. });
  2695. if ($rootScope.active) {
  2696. $scope.active = $rootScope.active;
  2697. $rootScope.active = null;
  2698. } else {
  2699. $scope.active = 'all';
  2700. }
  2701. $scope.dateZoneText = '不限';
  2702. $scope.deliveryZoneText = '不限';
  2703. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2704. /* 时间筛选初始化*/
  2705. var fromDate = new Date();
  2706. var toDate = new Date();
  2707. fromDate.setMonth(fromDate.getMonth() - 1);
  2708. fromDate.setHours(0, 0, 0, 0);
  2709. toDate.setHours(23, 59, 59, 999);
  2710. $scope.condition.dateFrom = fromDate;
  2711. $scope.condition.dateTo = toDate;
  2712. $scope.changeDateZone = function (zone) {
  2713. $scope.condition.dateZone = zone;
  2714. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2715. $scope.condition.$dateZoneOpen = false;
  2716. getDateCondition(zone, $scope.condition);
  2717. $scope.tableParams.page(1);
  2718. $scope.tableParams.reload();
  2719. };
  2720. $scope.changeDeliveryZone = function (zone) {
  2721. $scope.condition.deliveryZoneText = zone;
  2722. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2723. $scope.condition.$delievryZoneOpen = false;
  2724. getDelveryCondition(zone, $scope.condition);
  2725. $scope.tableParams.reload();
  2726. };
  2727. $scope.searchMethod = false;
  2728. var getService = function () {
  2729. return $scope.searchMethod ? PurcOrders : PurcOrdersInfo;
  2730. };
  2731. // 切换单据类型
  2732. $scope.setActive = function (state) {
  2733. if ($scope.active != state) {
  2734. $scope.active = state;
  2735. if ($scope.tableParams.page() == 1)
  2736. $scope.tableParams.reload();
  2737. else
  2738. $scope.tableParams.page(1);
  2739. }
  2740. };
  2741. var getPurcStatus = function (active) {
  2742. var fn = 'getPurcAll';
  2743. switch (active) {
  2744. case 'done':
  2745. fn = 'getPurcDone';
  2746. break;
  2747. case 'todo':
  2748. fn = 'getPurcTodo';
  2749. break;
  2750. case 'end':
  2751. fn = 'getPurcEnd';
  2752. break;
  2753. case 'waiting':
  2754. fn = 'getPurcWaiting';
  2755. break;
  2756. }
  2757. return fn;
  2758. };
  2759. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2760. page: 1,
  2761. count: 20,
  2762. sorting: {
  2763. display: 'desc',
  2764. date: 'desc'
  2765. }
  2766. }, {
  2767. total: 0,
  2768. counts: [5, 10, 15, 25, 50],
  2769. getData: function ($defer, params) {// 获取数据的方法
  2770. $scope.loading = true;
  2771. var pageParams = params.url();
  2772. pageParams.searchFilter = { // 筛选条件
  2773. keyword: $scope.keyword,
  2774. fromDate: getDateTime($scope.condition.dateFrom),
  2775. endDate: getDateTime($scope.condition.dateTo)
  2776. };
  2777. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2778. $scope.loading = false;
  2779. if (page) {
  2780. $defer.resolve(page.content);
  2781. $scope.total = page.totalElement;
  2782. params.total(page.totalElement);
  2783. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2784. }
  2785. }, function (response) {
  2786. $scope.loading = false;
  2787. toaster.pop('error', '数据加载失败', response.data);
  2788. });
  2789. }
  2790. });
  2791. //获得各分类未阅读数量
  2792. var getUnreadCount = function () {
  2793. PurcOrders.getUnreadCount(null, function (data) {
  2794. $scope.unread = data;
  2795. });
  2796. };
  2797. getUnreadCount();
  2798. //设置单据已读
  2799. $scope.setOrdersRead = function (id) {
  2800. // 如果单据本身已读,则不发送请求修改数据
  2801. if (!$scope.isUnread(id)){
  2802. return;
  2803. }
  2804. var sourceId = [];
  2805. sourceId.push(id);
  2806. PurcOrders.setRead({}, sourceId, function (message) {
  2807. // $scope.getUnreadIds();
  2808. getUnreadCount();
  2809. });
  2810. };
  2811. //获取未读单据id
  2812. var getUnreadIds = function () {
  2813. PurcOrders.getUnreadIds({}, "", function (message) {
  2814. $scope.unreadCode = message.content;
  2815. });
  2816. };
  2817. getUnreadIds();
  2818. //判断单据是否未读
  2819. $scope.isUnread = function (id) {
  2820. for (var i in $scope.unreadCode) {
  2821. if (id == $scope.unreadCode[i]) {
  2822. return true;
  2823. }
  2824. }
  2825. };
  2826. $scope.getReply = function (item) {
  2827. if (!item.replies) {
  2828. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2829. item.replies = replies;
  2830. });
  2831. }
  2832. };
  2833. $scope.getOrderTotal = function (items) {
  2834. var sum = 0;
  2835. angular.forEach(items, function (item) {
  2836. sum += item.qty * item.price;
  2837. });
  2838. return sum;
  2839. };
  2840. // 需方 打印 采购单
  2841. $scope.custPrint = function (order) {
  2842. var newPage = window.open("about:blank");
  2843. PurcOrder.printPermission({}, function () {
  2844. PurcOrder.custPrintCount({id: order.id}, {});//增加打印此次
  2845. ReportService.print(order.enUU, 'PURCLIST_CUST', "where purc$orders.pu_id=" + order.id, newPage);
  2846. }, function (response) {
  2847. newPage.close();
  2848. toaster.pop('error', '打印失败', response.data);
  2849. });
  2850. };
  2851. $scope.openDatePicker = function ($event, item, openParam) {
  2852. $event.preventDefault();
  2853. $event.stopPropagation();
  2854. item[openParam] = !item[openParam];
  2855. };
  2856. $scope.openFilterDatePicker = function ($event, item, openParam) {
  2857. $event.preventDefault();
  2858. $event.stopPropagation();
  2859. item[openParam] = !item[openParam];
  2860. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  2861. $scope.tableParams.reload();
  2862. }
  2863. };
  2864. $scope.parseDate = function (dateStr) {
  2865. if (dateStr)
  2866. return Date.parse(dateStr, 'yyyy-MM-dd');
  2867. return new Date();
  2868. };
  2869. $scope.checkboxes = {
  2870. checked: false
  2871. };
  2872. // 点击勾选全部的复选框
  2873. $scope.checkAll = function () {
  2874. angular.forEach($scope.tableParams.data, function (item) {
  2875. item.$selected = $scope.checkboxes.checked;
  2876. });
  2877. };
  2878. // 点击其中一个明细的复选框
  2879. $scope.checkOne = function (order) {
  2880. var result = true;
  2881. angular.forEach($scope.tableParams.data, function (item) {
  2882. if (item.$selected != true) {
  2883. result = false;
  2884. return;
  2885. }
  2886. });
  2887. $scope.checkboxes.checked = result;
  2888. };
  2889. // 搜索框回车
  2890. $scope.onSearch = function (keyword) {
  2891. // 每次搜索重置获取数据方法
  2892. $scope.searchMethod = false;
  2893. if(keyword != null && keyword != '') {
  2894. $scope.searchMethod = true;
  2895. }
  2896. $scope.tableParams.page(1);
  2897. $scope.tableParams.reload();
  2898. $scope.tip = keyword;
  2899. };
  2900. // 选择查找日期
  2901. $scope.onDateCondition = function () {
  2902. $scope.tableParams.page(1);
  2903. $scope.tableParams.reload();
  2904. };
  2905. // 复制订单
  2906. $scope.copyorder = function (id) {
  2907. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  2908. if (data.id) {
  2909. toaster.pop('success', '提示', '单据复制成功');
  2910. window.location.hash = "#purc/cart/" + data.id;
  2911. }
  2912. }, function (response) {
  2913. toaster.pop('error', '提示', response.data);
  2914. });
  2915. }
  2916. // 导出
  2917. $scope.exportXls = function () {
  2918. PurcOrders.exportXls({}, {}, function (data) {
  2919. if (data.success){
  2920. window.location.href = 'sale/orders/purc/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  2921. }
  2922. }, function (response) {
  2923. toaster.pop('error', '数据加载失败', response.data);
  2924. });
  2925. }
  2926. }]);
  2927. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'PurcOrdersInfo', 'CurrentRole', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, PurcOrdersInfo, CurrentRole) {
  2928. // 获取当前用户是否为普通用户
  2929. CurrentRole.isUser({}, {}, function (data) {
  2930. $scope.isUser = data.isUser;
  2931. });
  2932. var loadData = function () {
  2933. $scope.loading = true;
  2934. PurcOrdersInfo.getAll({id: $stateParams.id},{}, function (data) {
  2935. $scope.order = data;
  2936. var sum = 0;
  2937. angular.forEach($scope.order.orderItems, function (item) {
  2938. sum += item.qty * item.price;
  2939. });
  2940. $scope.order.total = sum;
  2941. // if($scope.order.display == 1) {//未查看的设为已查看
  2942. // $scope.setDisplay('setRead', $scope.order.id);
  2943. // }
  2944. //$scope.loading = false;
  2945. }, function (response) {
  2946. toaster.pop('error', '提示', response.data);
  2947. });
  2948. };
  2949. loadData();
  2950. $scope.getReply = function (item) {
  2951. if (!item.replies) {
  2952. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2953. item.replies = replies;
  2954. });
  2955. }
  2956. };
  2957. $scope.openDatePicker = function ($event, item, openParam) {
  2958. $event.preventDefault();
  2959. $event.stopPropagation();
  2960. item[openParam] = !item[openParam];
  2961. };
  2962. $scope.onReplyClick = function (item, inverse) {
  2963. if (item.reply) {
  2964. if (!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2965. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2966. return;
  2967. }
  2968. var reply = angular.copy(item.reply);
  2969. if (reply.delivery) {
  2970. if (typeof reply.delivery == 'object')
  2971. reply.delivery = reply.delivery.getTime();
  2972. } else {
  2973. reply.delivery = item.delivery;
  2974. }
  2975. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2976. $scope.loading = true;
  2977. PurcOrderItem.reply({orderItemId: item.id}, reply, function () {
  2978. $scope.loading = false;
  2979. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  2980. loadData();
  2981. }, function (response) {
  2982. $scope.loading = false;
  2983. toaster.pop('error', '回复失败', response.data);
  2984. });
  2985. }
  2986. };
  2987. //设置为已查看
  2988. $scope.setDisplay = function (state, orderId) {
  2989. if (orderId) {//设置单个
  2990. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  2991. // $scope.tableParams.reload();
  2992. }, function () {
  2993. toaster.pop('error', '错误', "设置失败");
  2994. });
  2995. } else {//设置已勾选的
  2996. var str = null;
  2997. angular.forEach($scope.tableParams.data, function (order) {
  2998. if (order.$selected == true) {
  2999. if (str != null && str != '') str += ',';
  3000. str += order.id;
  3001. }
  3002. });
  3003. if (str != null && str != '') {
  3004. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3005. $scope.tableParams.reload();
  3006. }, function () {
  3007. toaster.pop('error', '错误', "设置失败");
  3008. });
  3009. }
  3010. }
  3011. };
  3012. }]);
  3013. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PagingRelease', 'SnapshotService', 'PurcOrderItemInfo', 'token', 'CurrentRole', '$timeout', '$modal', function ($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PagingRelease, SnapshotService, PurcOrderItemInfo, token, CurrentRole, $timeout, $modal) {
  3014. BaseService.scrollBackToTop();
  3015. // 判断是否为普通用户
  3016. CurrentRole.isUser({}, {}, function (data) {
  3017. $scope.isUser = data.isUser;
  3018. });
  3019. $scope.active = 'todo';
  3020. $scope.dateZoneText = '不限';
  3021. $scope.deliveryZoneText = '不限';
  3022. $scope.condition = {dateZone: 1, deliveryZone: -1};
  3023. /* 时间筛选初始化*/
  3024. var fromDate = new Date();
  3025. var toDate = new Date();
  3026. fromDate.setMonth(fromDate.getMonth() - 1);
  3027. fromDate.setHours(0, 0, 0, 0);
  3028. toDate.setHours(23, 59, 59, 999);
  3029. $scope.condition.dateFrom = fromDate;
  3030. $scope.condition.dateTo = toDate;
  3031. $scope.changeDateZone = function (zone) {
  3032. $scope.condition.dateZone = zone;
  3033. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3034. $scope.condition.$dateZoneOpen = false;
  3035. getDateCondition(zone, $scope.condition);
  3036. $scope.tableParams.page(1);
  3037. $scope.tableParams.reload();
  3038. };
  3039. $scope.changeDeliveryZone = function (zone) {
  3040. $scope.condition.deliveryZoneText = zone;
  3041. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  3042. $scope.condition.$delievryZoneOpen = false;
  3043. getDelveryCondition(zone, $scope.condition);
  3044. $scope.tableParams.reload();
  3045. };
  3046. $scope.nowdate = new Date();
  3047. // 切换单据类型
  3048. $scope.setActive = function (state) {
  3049. if ($scope.active != state) {
  3050. $scope.active = state;
  3051. if ($scope.tableParams.page() == 1)
  3052. $scope.tableParams.reload();
  3053. else
  3054. $scope.tableParams.page(1);
  3055. }
  3056. };
  3057. $scope.searchMethod = false;
  3058. // 切换数据来源(正常数据 or 历史数据)
  3059. var getService = function () {
  3060. return $scope.searchMethod ? PurcOrderItem : PurcOrderItemInfo;
  3061. };
  3062. $scope.tableParams = new ngTableParams({ // ng-Table参数
  3063. page: 1,
  3064. count: 20,
  3065. sorting: {
  3066. date: 'desc',
  3067. id: 'desc'
  3068. }
  3069. }, {
  3070. total: 0,
  3071. counts: [5, 10, 15, 25, 50],
  3072. getData: function ($defer, params) { // 获取数据的方法
  3073. $scope.loading = true;
  3074. var pageParams = params.url();
  3075. pageParams.searchFilter = { // 筛选条件
  3076. keyword: $scope.keyword,
  3077. fromDate: getDateTime($scope.condition.dateFrom),
  3078. endDate: getDateTime($scope.condition.dateTo)
  3079. };
  3080. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3081. $scope.loading = false;
  3082. if (page) {
  3083. $defer.resolve(page.content);
  3084. params.total(page.totalElement);
  3085. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  3086. }
  3087. }, function (response) {
  3088. $scope.loading = false;
  3089. toaster.pop('error', '数据加载失败', response.data);
  3090. });
  3091. }
  3092. });
  3093. //获得各分类未阅读数量
  3094. var getUnreadCount = function () {
  3095. PurcOrderItem.getUnreadCount(null, function (data) {
  3096. $scope.unread = data;
  3097. });
  3098. };
  3099. getUnreadCount();
  3100. //设置单据已读
  3101. $scope.setOrdersRead = function (id) {
  3102. // 如果单据本身已读,则不发送请求修改数据
  3103. if (!$scope.isUnread(id)){
  3104. return;
  3105. }
  3106. var sourceId = [];
  3107. sourceId.push(id);
  3108. PurcOrderItem.setRead({}, sourceId, function (message) {
  3109. getUnreadCount();
  3110. });
  3111. };
  3112. //批量设置单据已读
  3113. $scope.setOrdersReadByBatch = function () {
  3114. var sourceId = [];
  3115. angular.forEach($scope.tableParams.data, function (order) {
  3116. if (order.$selected == true) {
  3117. sourceId.push(order.id);
  3118. }
  3119. });
  3120. PurcOrderItem.setRead({}, sourceId, function (message) {
  3121. getUnreadCount();
  3122. });
  3123. };
  3124. $scope.setOrdersReadByState = function () {
  3125. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3126. return;
  3127. }
  3128. PurcOrderItem.setReadByState({}, function () {
  3129. getUnreadIds();
  3130. getUnreadCount();
  3131. });
  3132. };
  3133. var getUnreadIds = function () {
  3134. PurcOrderItem.getUnreadIds({}, "", function (message) {
  3135. $scope.unreadCode = message.content;
  3136. });
  3137. };
  3138. getUnreadIds();
  3139. $scope.isUnread = function (id) {
  3140. for (var i in $scope.unreadCode) {
  3141. if (id == $scope.unreadCode[i]) {
  3142. return true;
  3143. }
  3144. }
  3145. };
  3146. $scope.getOrderTotal = function (items) {
  3147. var sum = 0;
  3148. angular.forEach(items, function (item) {
  3149. sum += item.qty * item.price;
  3150. });
  3151. return sum;
  3152. };
  3153. $scope.openDatePicker = function ($event, item, openParam) {
  3154. $event.preventDefault();
  3155. $event.stopPropagation();
  3156. item[openParam] = !item[openParam];
  3157. };
  3158. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3159. $event.preventDefault();
  3160. $event.stopPropagation();
  3161. item[openParam] = !item[openParam];
  3162. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3163. $scope.tableParams.reload();
  3164. }
  3165. };
  3166. $scope.parseDate = function (dateStr) {
  3167. if (dateStr)
  3168. return Date.parse(dateStr, 'yyyy-MM-dd');
  3169. return new Date();
  3170. };
  3171. // 获取token信息
  3172. $scope.getToken = function() {
  3173. token.info({userType: 'sale'}, {}, function(data) {
  3174. $scope.token = data.token;
  3175. }, function(response) {
  3176. toaster.pop('error', '提示', response.data);
  3177. });
  3178. }
  3179. $scope.onReplyClick = function (item, inverse) {
  3180. if (item.reply) {
  3181. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3182. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3183. return;
  3184. }
  3185. var reply = angular.copy(item.reply);
  3186. if (reply.delivery) {
  3187. if (typeof reply.delivery == 'object')
  3188. reply.delivery = reply.delivery.getTime();
  3189. } else {
  3190. reply.delivery = item.delivery;
  3191. }
  3192. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3193. $scope.loading = true;
  3194. if($scope.token != null) {
  3195. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3196. $scope.loading = false;
  3197. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3198. $scope.tableParams.reload();
  3199. }, function (response) {
  3200. $scope.loading = false;
  3201. toaster.pop('error', '回复失败', response.data);
  3202. });
  3203. }
  3204. }
  3205. };
  3206. //打印 采购单
  3207. $scope.print = function (order) {
  3208. var newPage = window.open("about:blank");
  3209. PurcOrder.printPermission({}, function () {
  3210. PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
  3211. if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  3212. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
  3213. $scope.tableParams.reload();
  3214. },function (response) {
  3215. newPage.close();
  3216. toaster.pop('error', '打印失败', response.data);
  3217. });
  3218. };
  3219. $scope.getReply = function (item) {
  3220. if (!item.replies) {
  3221. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3222. item.replies = replies;
  3223. });
  3224. }
  3225. };
  3226. $scope.checkboxes = {
  3227. checked: false
  3228. };
  3229. // 点击勾选全部的复选框
  3230. $scope.checkAll = function () {
  3231. angular.forEach($scope.tableParams.data, function (item) {
  3232. item.$selected = $scope.checkboxes.checked;
  3233. });
  3234. };
  3235. // 点击其中一个明细的复选框
  3236. $scope.checkOne = function (order) {
  3237. var result = true;
  3238. angular.forEach($scope.tableParams.data, function (item) {
  3239. if (item.$selected != true) {
  3240. result = false;
  3241. return;
  3242. }
  3243. });
  3244. $scope.checkboxes.checked = result;
  3245. };
  3246. //批量回复采购订单
  3247. $scope.replyByBatch = function () {
  3248. $scope.loading = true;
  3249. var str = '';
  3250. angular.forEach($scope.tableParams.data, function (order) {
  3251. if (order.$selected == true) {
  3252. str += order.id;
  3253. str += ',';
  3254. }
  3255. });
  3256. if (!(str == '')) {
  3257. $scope.loading = false;
  3258. str = str.substr(0, str.length - 1);
  3259. var modalInstance = $modal.open({
  3260. animation: true,
  3261. templateUrl: 'static/tpl/index/sale/modal/reply_bybatch.html',
  3262. controller: 'ReplyByBatchCtrl',
  3263. resolve: {}
  3264. });
  3265. modalInstance.result.then(function(data) {
  3266. $scope.loading = true;
  3267. var reply = data;
  3268. var date = null;
  3269. if (reply.date && reply.method == 1) {
  3270. date = reply.date.getTime();
  3271. }
  3272. PurcOrderItem.replyByBatch({date: date}, str, function () {
  3273. $scope.loading = false;
  3274. $scope.tableParams.reload();
  3275. toaster.pop('success', '提示', '批量回复成功');
  3276. }, function (response) {
  3277. $scope.loading = false;
  3278. toaster.pop('error', '提示', '批量回复失败');
  3279. });
  3280. });
  3281. } else {//没有勾选其中的明细
  3282. toaster.pop('error', '提示', '请先选择需要回复的单据');
  3283. $scope.loading = false;
  3284. }
  3285. };
  3286. // 搜索框回车
  3287. $scope.onSearch = function (keyword) {
  3288. // 每次搜索重置获取数据方法
  3289. $scope.searchMethod = false;
  3290. if(keyword != null && keyword != '') {
  3291. $scope.searchMethod = true;
  3292. }
  3293. $scope.tableParams.page(1);
  3294. $scope.tableParams.reload();
  3295. };
  3296. // 选择查找日期
  3297. $scope.onDateCondition = function () {
  3298. $scope.tableParams.page(1);
  3299. $scope.tableParams.reload();
  3300. };
  3301. //设置为已查看
  3302. $scope.setDisplay = function (state, orderId) {
  3303. if (orderId) {//设置单个
  3304. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3305. $scope.tableParams.reload();
  3306. }, function () {
  3307. toaster.pop('error', '错误', "设置失败");
  3308. });
  3309. } else {//设置已勾选的
  3310. var str = null;
  3311. angular.forEach($scope.tableParams.data, function (order) {
  3312. if (order.$selected == true) {
  3313. if (str != null && str != '') str += ',';
  3314. str += order.id;
  3315. }
  3316. });
  3317. if (str != null && str != '') {
  3318. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3319. $scope.tableParams.reload();
  3320. }, function () {
  3321. toaster.pop('error', '错误', "设置失败");
  3322. });
  3323. }
  3324. }
  3325. };
  3326. // 导出
  3327. $scope.exportXls = function () {
  3328. PurcOrderItem.exportXls({}, {}, function (data) {
  3329. if (data.success){
  3330. window.location.href = 'sale/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3331. }
  3332. }, function (response) {
  3333. toaster.pop('error', '数据加载失败', response.data);
  3334. });
  3335. }
  3336. }]);
  3337. /**
  3338. * 批量回复模态框
  3339. */
  3340. app.controller('ReplyByBatchCtrl', ['$scope', '$modalInstance', '$filter', 'toaster', function($scope, $modalInstance, $filter, toaster) {
  3341. $scope.activeTab = 'custom';
  3342. $scope.reply = {
  3343. method: 1
  3344. };
  3345. $scope.getMinDate = function () {
  3346. return $filter('date')(new Date, 'yyyy-MM-dd');
  3347. };
  3348. $scope.openDatePicker = function ($event, openParam) {
  3349. $event.preventDefault();
  3350. $event.stopPropagation();
  3351. $scope.$dateOpen = !openParam;
  3352. };
  3353. // 取消
  3354. $scope.cancel = function () {
  3355. $modalInstance.dismiss();
  3356. }
  3357. // 提交
  3358. $scope.submit = function () {
  3359. if ($scope.reply.method == 0) {
  3360. $modalInstance.close($scope.reply);
  3361. } else if ($scope.reply.method == 1) {
  3362. if (angular.isUndefined($scope.reply.date)) {
  3363. toaster.pop('error', '提示', '请先选择日期')
  3364. } else {
  3365. $modalInstance.close($scope.reply);
  3366. }
  3367. }
  3368. }
  3369. }]);
  3370. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token', 'file', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token, file) {
  3371. // 获取当前用户是否为普通用户
  3372. CurrentRole.isUser({}, {}, function (data) {
  3373. $scope.isUser = data.isUser;
  3374. });
  3375. var existFile = false;
  3376. var loadData = function () {
  3377. PurcOrder.get({id: $stateParams.id}, function (data) {
  3378. $scope.order = data;
  3379. var sum = 0;
  3380. angular.forEach($scope.order.orderItems, function (item) {
  3381. sum += item.qty * item.price;
  3382. if (item.attachs.length > 0) {
  3383. existFile = true;
  3384. }
  3385. });
  3386. $scope.order.total = sum;
  3387. if ($scope.order.display == 1) {//未查看的设为已查看
  3388. $scope.setDisplay('setRead', $scope.order.id);
  3389. }
  3390. $scope.loading = false;
  3391. }, function (response) {
  3392. toaster.pop('error', '', response.data);
  3393. });
  3394. };
  3395. loadData();
  3396. $scope.getReply = function (item) {
  3397. if (!item.replies) {
  3398. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3399. item.replies = replies;
  3400. });
  3401. }
  3402. };
  3403. $scope.openDatePicker = function ($event, item, openParam) {
  3404. $event.preventDefault();
  3405. $event.stopPropagation();
  3406. item[openParam] = !item[openParam];
  3407. };
  3408. // 获取token信息
  3409. var getToken = function() {
  3410. token.info({userType: 'sale'}, {}, function(data) {
  3411. $scope.token = data.token;
  3412. }, function(response) {
  3413. toaster.pop('error', '提示', response.data);
  3414. });
  3415. };
  3416. getToken();
  3417. $scope.onReplyClick = function (item, inverse) {
  3418. if (item.reply) {
  3419. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3420. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3421. return;
  3422. }
  3423. var reply = angular.copy(item.reply);
  3424. if (reply.delivery) {
  3425. if (typeof reply.delivery == 'object')
  3426. reply.delivery = reply.delivery.getTime();
  3427. } else {
  3428. reply.delivery = item.delivery;
  3429. }
  3430. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3431. $scope.loading = true;
  3432. if($scope.token != null) {
  3433. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3434. $scope.loading = false;
  3435. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3436. $scope.tableParams.reload();
  3437. }, function (response) {
  3438. $scope.loading = false;
  3439. toaster.pop('error', '回复失败', response.data);
  3440. });
  3441. }
  3442. }
  3443. };
  3444. // 采购单
  3445. $scope.print = function (order) {
  3446. var newPage = window.open("about:blank");
  3447. PurcOrder.printPermission({}, function () {
  3448. PurcOrder.printCount({id: order.id}, {});//增加打印此次
  3449. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id, newPage);
  3450. },function (response) {
  3451. newPage.close();
  3452. toaster.pop('error', '打印失败', response.data);
  3453. });
  3454. };
  3455. //设置为已查看
  3456. $scope.setDisplay = function (state, orderId) {
  3457. if (orderId) {//设置单个
  3458. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3459. $scope.tableParams.reload();
  3460. }, function () {
  3461. toaster.pop('error', '错误', "设置失败");
  3462. });
  3463. } else {//设置已勾选的
  3464. var str = null;
  3465. angular.forEach($scope.tableParams.data, function (order) {
  3466. if (order.$selected == true) {
  3467. if (str != null && str != '') str += ',';
  3468. str += order.id;
  3469. }
  3470. });
  3471. if (str != null && str != '') {
  3472. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3473. $scope.tableParams.reload();
  3474. }, function () {
  3475. toaster.pop('error', '错误', "设置失败");
  3476. });
  3477. }
  3478. }
  3479. };
  3480. // 下载附件
  3481. $scope.fileDownload = function (id) {
  3482. if (!existFile) {
  3483. toaster.pop('error', '提示', "当前采购单不存在附件信息");
  3484. } else {
  3485. window.open("file/batch/" + id);
  3486. }
  3487. }
  3488. }]);
  3489. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, CurrentRole) {
  3490. BaseService.scrollBackToTop();
  3491. // 获取当前用户是否为普通用户
  3492. CurrentRole.isUser({}, {}, function (data) {
  3493. $scope.isUser = data.isUser;
  3494. });
  3495. $scope.active = 'todo';
  3496. $scope.agreedText = '全部';
  3497. $scope.dateZoneText = '一个月内';
  3498. $scope.condition = {dateZone: 1};
  3499. /* 时间筛选初始化*/
  3500. var fromDate = new Date();
  3501. var toDate = new Date();
  3502. fromDate.setMonth(fromDate.getMonth() - 1);
  3503. fromDate.setHours(0, 0, 0, 0);
  3504. toDate.setHours(23, 59, 59, 999);
  3505. $scope.condition.dateFrom = fromDate;
  3506. $scope.condition.dateTo = toDate;
  3507. $scope.changeAgreed = function (agreed) {
  3508. $scope.condition.agreed = agreed;
  3509. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3510. $scope.condition.$agreedOpen = false;
  3511. };
  3512. $scope.changeDateZone = function (zone) {
  3513. $scope.condition.dateZone = zone;
  3514. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3515. $scope.condition.$dateZoneOpen = false;
  3516. getDateCondition(zone, $scope.condition);
  3517. $scope.tableParams.page(1);
  3518. $scope.tableParams.reload();
  3519. };
  3520. $scope.setActive = function (state) {
  3521. if ($scope.active != state) {
  3522. $scope.active = state;
  3523. if ($scope.tableParams.page() == 1)
  3524. $scope.tableParams.reload();
  3525. else
  3526. $scope.tableParams.page(1);
  3527. }
  3528. };
  3529. $scope.searchMethod = false;
  3530. var getService = function () {
  3531. return $scope.searchMethod ? PurcChange : PurcChanges;
  3532. };
  3533. $scope.tableParams = new ngTableParams({
  3534. page: 1,
  3535. count: 20,
  3536. sorting: {
  3537. date: 'desc'
  3538. }
  3539. }, {
  3540. total: 0,
  3541. counts: [5, 10, 25, 50],
  3542. getData: function ($defer, params) {
  3543. $scope.loading = true;
  3544. var pageParams = params.url();
  3545. pageParams.searchFilter = {
  3546. keyword: $scope.keyword,
  3547. fromDate: getDateTime($scope.condition.dateFrom),
  3548. endDate: getDateTime($scope.condition.dateTo)
  3549. };
  3550. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3551. $scope.loading = false;
  3552. if (page) {
  3553. params.total(page.totalElement);
  3554. $defer.resolve(page.content);
  3555. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3556. }
  3557. }, function (response) {
  3558. $scope.loading = false;
  3559. toaster.pop('error', '数据加载失败', response.data);
  3560. });
  3561. }
  3562. });
  3563. //获得各分类未阅读数量
  3564. var getUnreadCount = function () {
  3565. PurcChange.getUnreadCount(null, function(data){
  3566. $scope.unread = data;
  3567. });
  3568. };
  3569. getUnreadCount();
  3570. //设置单据已读
  3571. $scope.setOrdersRead = function (id) {
  3572. // 如果单据本身已读,则不发送请求修改数据
  3573. if (!$scope.isUnread(id)){
  3574. return;
  3575. }
  3576. var sourceId = [];
  3577. sourceId.push(id);
  3578. PurcChange.setRead({}, sourceId, function (message) {
  3579. // $scope.getUnreadIds();
  3580. getUnreadCount();
  3581. });
  3582. };
  3583. $scope.setOrdersReadByState = function () {
  3584. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3585. return;
  3586. }
  3587. PurcChange.setReadByState({}, function () {
  3588. getUnreadIds();
  3589. getUnreadCount();
  3590. });
  3591. };
  3592. //获取未读单据id
  3593. var getUnreadIds = function (){
  3594. PurcChange.getUnreadIds({}, "", function (message) {
  3595. $scope.unreadCode = message.content;
  3596. });
  3597. };
  3598. getUnreadIds();
  3599. //判断单据是否未读
  3600. $scope.isUnread = function (id){
  3601. for (var i in $scope.unreadCode) {
  3602. if (id == $scope.unreadCode[i]) {
  3603. return true;
  3604. }
  3605. }
  3606. };
  3607. $scope.openDatePicker = function ($event, item, openParam) {
  3608. $event.preventDefault();
  3609. $event.stopPropagation();
  3610. item[openParam] = !item[openParam];
  3611. };
  3612. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3613. $event.preventDefault();
  3614. $event.stopPropagation();
  3615. item[openParam] = !item[openParam];
  3616. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3617. $scope.tableParams.reload();
  3618. }
  3619. };
  3620. $scope.onReplyClick = function (change) {
  3621. if (change.$agreed) {
  3622. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3623. $scope.loading = true;
  3624. PurcChange.reply({changeId: change.id}, reply, function () {
  3625. $scope.loading = false;
  3626. toaster.pop('info', '提示', '回复成功');
  3627. $scope.tableParams.reload();
  3628. }, function (response) {
  3629. $scope.loading = false;
  3630. toaster.pop('error', '回复失败', response.data);
  3631. });
  3632. }
  3633. };
  3634. // 搜索框回车
  3635. $scope.onSearch = function (keyword) {
  3636. // 每次搜索重置获取数据方法
  3637. $scope.searchMethod = false;
  3638. if(keyword != null && keyword != '') {
  3639. $scope.searchMethod = true;
  3640. }
  3641. $scope.tableParams.page(1);
  3642. $scope.tableParams.reload();
  3643. };
  3644. // 导出
  3645. $scope.exportXls = function () {
  3646. PurcChange.exportXls({}, {}, function (data) {
  3647. if (data.success){
  3648. window.location.href = 'sale/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3649. }
  3650. }, function (response) {
  3651. toaster.pop('error', '数据加载失败', response.data);
  3652. });
  3653. }
  3654. }]);
  3655. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcChange, toaster, CurrentRole) {
  3656. // 获取当前用户是否为普通用户
  3657. CurrentRole.isUser({}, {}, function (data) {
  3658. $scope.isUser = data.isUser;
  3659. });
  3660. var loadData = function () {
  3661. PurcChange.getItem({id: $stateParams.id}, function (data) {
  3662. $scope.change = data;
  3663. }, function (response) {
  3664. toaster.pop('error', '', response.data);
  3665. });
  3666. };
  3667. loadData();
  3668. $scope.openDatePicker = function ($event, item, openParam) {
  3669. $event.preventDefault();
  3670. $event.stopPropagation();
  3671. item[openParam] = !item[openParam];
  3672. };
  3673. $scope.onReplyClick = function (change) {
  3674. if (change.$agreed) {
  3675. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3676. PurcChange.reply({changeId: change.id}, reply, function () {
  3677. toaster.pop('info', '提示', '回复成功');
  3678. loadData();
  3679. }, function (response) {
  3680. toaster.pop('error', '回复失败', response.data);
  3681. });
  3682. }
  3683. };
  3684. }]);
  3685. //客户采购询价
  3686. app.controller('SaleInquiryCtrl', ['$scope', '$filter', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', 'PurcInquiryInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', function ($scope, $filter, PurcInquiry, ngTableParams, toaster, BaseService, PurcInquiryInfo, $upload, $rootScope, token, $timeout, CurrentRole) {
  3687. BaseService.scrollBackToTop();
  3688. // 获取当前用户是否为普通用户
  3689. CurrentRole.isUser({}, {}, function (data) {
  3690. $scope.isUser = data.isUser;
  3691. });
  3692. if ($rootScope.active) {
  3693. $scope.active = $rootScope.active;
  3694. $rootScope.active = null;
  3695. } else {
  3696. $scope.active = 'todo';
  3697. }
  3698. $scope.agreedText = '全部';
  3699. $scope.dateZoneText = '最近一个月';
  3700. $scope.condition = {dateZone: 1};
  3701. /* 时间筛选初始化*/
  3702. var fromDate = new Date();
  3703. var toDate = new Date();
  3704. fromDate.setMonth(fromDate.getMonth() - 1);
  3705. fromDate.setHours(0, 0, 0, 0);
  3706. toDate.setHours(23, 59, 59, 999);
  3707. $scope.condition.dateFrom = fromDate;
  3708. $scope.condition.dateTo = toDate;
  3709. $scope.changeAgreed = function (agreed) {
  3710. $scope.condition.agreed = agreed;
  3711. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3712. $scope.condition.$agreedOpen = false;
  3713. };
  3714. $scope.changeDateZone = function (zone) {
  3715. $scope.condition.dateZone = zone;
  3716. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  3717. $scope.condition.$dateZoneOpen = false;
  3718. getDateCondition(zone, $scope.condition);
  3719. $scope.tableParams.page(1);
  3720. $scope.tableParams.reload();
  3721. };
  3722. $scope.setActive = function (state) {
  3723. if ($scope.active != state) {
  3724. $scope.active = state;
  3725. if ($scope.tableParams.page() == 1)
  3726. $scope.tableParams.reload();
  3727. else
  3728. $scope.tableParams.page(1);
  3729. }
  3730. };
  3731. // 设置阅读状态
  3732. $scope.setReadStatus = function(msg) {
  3733. if(!msg.read) {
  3734. PurcInquiry.setStatus({id: msg.inid}, {}, function(data) {
  3735. });
  3736. }
  3737. }
  3738. $scope.searchMethod = false;
  3739. var getService = function () {
  3740. return $scope.searchMethod ? PurcInquiry : PurcInquiryInfo;
  3741. };
  3742. $scope.tableParams = new ngTableParams({
  3743. page: 1,
  3744. count: 20,
  3745. sorting: {
  3746. 'inquiry.date': 'desc',
  3747. 'inquiry.enterprise.enName': 'asc',
  3748. 'inquiry.code': 'asc'
  3749. }
  3750. }, {
  3751. total: 0,
  3752. counts: [5, 10, 25, 50],
  3753. getData: function ($defer, params) {
  3754. $scope.loading = true;
  3755. var pageParams = params.url();
  3756. var realActive = {};
  3757. pageParams.searchFilter = { // 筛选条件
  3758. keyword: $scope.keyword,
  3759. fromDate: getDateTime($scope.condition.dateFrom),
  3760. endDate: getDateTime($scope.condition.dateTo)
  3761. };
  3762. if ($scope.active == 'overdue') {
  3763. $scope.active = 'end';
  3764. }
  3765. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3766. $scope.loading = false;
  3767. if (page) {
  3768. params.total(page.totalElement);
  3769. $defer.resolve(page.content);
  3770. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3771. }
  3772. }, function (response) {
  3773. $scope.loading = false;
  3774. toaster.pop('error', '数据加载失败', response.data);
  3775. });
  3776. }
  3777. });
  3778. //获得各分类未阅读数量
  3779. var getUnreadCount = function () {
  3780. PurcInquiry.getUnreadCount(null, function (data) {
  3781. $scope.unread = data;
  3782. });
  3783. };
  3784. getUnreadCount();
  3785. //设置单据已读
  3786. $scope.setOrdersRead = function (id) {
  3787. // 如果单据本身已读,则不发送请求修改数据
  3788. if (!$scope.isUnread(id)){
  3789. return;
  3790. }
  3791. var sourceId = [];
  3792. sourceId.push(id);
  3793. PurcInquiry.setRead({}, sourceId, function (message) {
  3794. getUnreadCount();
  3795. removeByValue($scope.unreadCode, id);
  3796. });
  3797. };
  3798. $scope.setOrdersReadByState = function () {
  3799. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3800. return;
  3801. }
  3802. PurcInquiry.setReadByState({}, function () {
  3803. getUnreadIds();
  3804. getUnreadCount();
  3805. });
  3806. };
  3807. var getUnreadIds = function () {
  3808. PurcInquiry.getUnreadIds({}, "", function (message) {
  3809. $scope.unreadCode = message.content;
  3810. });
  3811. };
  3812. getUnreadIds();
  3813. $scope.isUnread = function (id) {
  3814. for (var i in $scope.unreadCode) {
  3815. if (id == $scope.unreadCode[i]) {
  3816. return true;
  3817. }
  3818. }
  3819. };
  3820. $scope.getMinDate = function (item) {
  3821. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3822. };
  3823. $scope.replyPrices = [];
  3824. $scope.replylapQtys = [];
  3825. $scope.replyPrices.push(true);
  3826. $scope.replylapQtys.push(true);
  3827. $scope.addStep = function (inquiryItem) {
  3828. $scope.replyPrices.push(true);
  3829. if (inquiryItem.replies.length >= 10) {
  3830. toaster.pop('warning', '提示', '最多支持10个分段!');
  3831. } else {
  3832. inquiryItem.replies.push({});
  3833. if (inquiryItem.replies.length != 1) {
  3834. $scope.replyPrices.push(true);
  3835. $scope.replylapQtys.push(true);
  3836. }
  3837. }
  3838. };
  3839. $scope.removeStep = function (inquiryItem, stepIndex) {
  3840. inquiryItem.replies.splice(stepIndex, 1);
  3841. $scope.replyPrices.splice(stepIndex, 1);
  3842. $scope.replylapQtys.splice(stepIndex, 1);
  3843. };
  3844. $scope.openDatePicker = function ($event, item, openParam) {
  3845. $event.preventDefault();
  3846. $event.stopPropagation();
  3847. item[openParam] = !item[openParam];
  3848. };
  3849. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3850. $event.preventDefault();
  3851. $event.stopPropagation();
  3852. item[openParam] = !item[openParam];
  3853. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3854. $scope.tableParams.reload();
  3855. }
  3856. };
  3857. $scope.getHistory = function (item) {
  3858. if (!item.history) {
  3859. PurcInquiry.getHistory({itemId: item.id},function (data) {
  3860. $scope.historyShow = true;
  3861. item.history = data;
  3862. }, function (response) {
  3863. $scope.historyShow = false;
  3864. //toaster.pop('error', '数据加载失败', response.data);
  3865. });
  3866. }
  3867. };
  3868. // 获取token信息
  3869. $scope.getToken = function() {
  3870. token.info({userType: 'saleinquiry'}, {}, function(data) {
  3871. $scope.token = data.token;
  3872. }, function(response) {
  3873. toaster.pop('error', '提示', response.data);
  3874. });
  3875. };
  3876. $scope.deleteAttach = function (attaches, index) {
  3877. attaches.splice(index, 1);
  3878. };
  3879. $scope.onReplyClick = function (item, withSteps) {
  3880. if (item.vendFromDate instanceof Date) {
  3881. item.vendFromDate = item.vendFromDate.getTime();
  3882. }
  3883. if (item.vendToDate instanceof Date) {
  3884. item.vendToDate = item.vendToDate.getTime();
  3885. }
  3886. if (item.vendFromDate > item.vendToDate) {
  3887. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3888. return;
  3889. }
  3890. var replies = [];
  3891. // 判断分段数是否合法
  3892. var valid = true;
  3893. var validLapQty = 0;
  3894. angular.forEach(item.replies, function (r, i) {
  3895. if ((i > 0 ? r.lapQty : 1) || r.price) {
  3896. replies.push(r);
  3897. }
  3898. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  3899. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  3900. valid = false;
  3901. validLapQty = r.lapQty;
  3902. }
  3903. });
  3904. item.replies = replies;
  3905. $scope.loading = true;
  3906. if (!valid) {
  3907. if (validLapQty) {
  3908. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  3909. } else {
  3910. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  3911. }
  3912. $scope.loading = false;
  3913. } else {
  3914. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3915. if (withSteps) { // 保存并报价
  3916. if(null != file) {
  3917. $upload.upload({
  3918. url: 'sale/inquiry/addAttach',
  3919. file: file,
  3920. method: 'POST',
  3921. data: {
  3922. item: item,
  3923. method: 'reply'
  3924. }
  3925. }).success(function (data) {
  3926. if (data.item) {
  3927. item = data.item;
  3928. }
  3929. $scope.loading = false;
  3930. toaster.pop('info', '提示', '报价成功');
  3931. $scope.tableParams.reload();
  3932. }).error(function (data) {
  3933. $scope.loading = false;
  3934. toaster.pop('error', '附件上传失败');
  3935. });
  3936. } else {
  3937. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function (data) {
  3938. $scope.loading = false;
  3939. toaster.pop('info', '提示', '报价成功');
  3940. $scope.tableParams.reload();
  3941. }, function (response) {
  3942. $scope.loading = false;
  3943. toaster.pop('error', '询价失效', response.data);
  3944. });
  3945. }
  3946. } else { // 保存
  3947. if(null != file) {
  3948. $upload.upload({
  3949. url: 'sale/inquiry/addAttach',
  3950. file: file,
  3951. method: 'POST',
  3952. data: {
  3953. item: item,
  3954. method: 'save'
  3955. }
  3956. }).success(function (data) {
  3957. if (data.item) {
  3958. item = data.item;
  3959. }
  3960. $scope.loading = false;
  3961. toaster.pop('info', '提示', '保存成功');
  3962. $scope.tableParams.reload();
  3963. }).error(function (data) {
  3964. $scope.loading = false;
  3965. toaster.pop('error', '附件上传失败');
  3966. });
  3967. } else {
  3968. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function (data) {
  3969. $scope.loading = false;
  3970. toaster.pop('info', '提示', '保存成功');
  3971. $scope.tableParams.reload();
  3972. }, function (response) {
  3973. $scope.loading = false;
  3974. toaster.pop('error', '保存失败', response.data);
  3975. });
  3976. }
  3977. }
  3978. }
  3979. };
  3980. $scope.isValid = function (item, withSteps) {
  3981. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3982. if (!withSteps || !bool)
  3983. return bool;
  3984. angular.forEach(item.replies, function (r, i) {
  3985. $scope.verifylapQty(r.lapQty, i, item);
  3986. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  3987. });
  3988. return bool;
  3989. };
  3990. $scope.verifylapQty = function (value, index, inquiryItem) {
  3991. value = parseInt(value);
  3992. var regex = /^\d+(.\d{1,6})?$/;
  3993. var valid = true;
  3994. angular.forEach(inquiryItem.replies, function(reply, $index) {
  3995. if ($index < index && reply.lapQty >= value) {
  3996. valid = false;
  3997. }
  3998. });
  3999. $scope.replylapQtys[index] = regex.test(value) && valid;
  4000. };
  4001. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  4002. $scope.verify = function (value, type) {
  4003. var regex = /^\d+(.\d{1,6})?$/;//
  4004. switch (type) {
  4005. case 'minOrderQty':
  4006. $scope.minOrderQtyVerify = regex.test(value);
  4007. break;
  4008. case 'minPackQty':
  4009. $scope.minPackQtyVerify = regex.test(value);
  4010. break;
  4011. case 'leadtime':
  4012. $scope.leadtimeVerify = regex.test(value);
  4013. break;
  4014. default:
  4015. $scope.replyPrices[type] = regex.test(value);
  4016. break;
  4017. }
  4018. }
  4019. // 搜索框回车
  4020. $scope.onSearch = function (keyword) {
  4021. // 每次搜索重置获取数据方法
  4022. $scope.searchMethod = false;
  4023. if(keyword != null && keyword != '') {
  4024. $scope.searchMethod = true;
  4025. }
  4026. $scope.tableParams.page(1);
  4027. $scope.tableParams.reload();
  4028. };
  4029. // 取消
  4030. $scope.cancel = function () {
  4031. $scope.tableParams.reload();
  4032. }
  4033. // 导出
  4034. $scope.exportXls = function () {
  4035. PurcInquiry.exportXls({}, {}, function (data) {
  4036. if (data.success) {
  4037. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4038. }
  4039. }, function (response) {
  4040. toaster.pop('error', '数据加载失败', response.data);
  4041. })
  4042. }
  4043. }]);
  4044. // 询价单明细
  4045. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole) {
  4046. // 获取当前用户是否为普通用户
  4047. CurrentRole.isUser({}, {}, function (data) {
  4048. $scope.isUser = data.isUser;
  4049. });
  4050. var loadData = function () {
  4051. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  4052. $scope.newinquiryItems = data;
  4053. var inquiry = data[0].inquiry;
  4054. //inquiry.inquiryItems = data;
  4055. angular.forEach(inquiry.attachs, function (attach) {
  4056. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  4057. });
  4058. $scope.inquiry = inquiry;
  4059. }, function (response) {
  4060. $scope.loading = false;
  4061. toaster.pop('error', '', response.data);
  4062. });
  4063. };
  4064. loadData();
  4065. $scope.getMinDate = function (item) {
  4066. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4067. };
  4068. $scope.replyPrices = [];
  4069. $scope.replylapQtys = [];
  4070. $scope.replyPrices.push(true);
  4071. $scope.replylapQtys.push(true);
  4072. $scope.addStep = function (inquiryItem) {
  4073. if (inquiryItem.replies.length >= 10) {
  4074. toaster.pop('warning', '提示', '最多支持10个分段!');
  4075. } else
  4076. inquiryItem.replies.push({});
  4077. };
  4078. $scope.removeStep = function (inquiryItem, stepIndex) {
  4079. inquiryItem.replies.splice(stepIndex, 1);
  4080. };
  4081. $scope.openDatePicker = function ($event, item, openParam) {
  4082. $event.preventDefault();
  4083. $event.stopPropagation();
  4084. item[openParam] = !item[openParam];
  4085. };
  4086. $scope.getHistory = function (item) {
  4087. if (!item.history) {
  4088. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  4089. item.history = data;
  4090. });
  4091. }
  4092. };
  4093. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  4094. $scope.verify = function (value, type) {
  4095. var regex = /^\d+(.\d{1,6})?$/;//
  4096. switch (type) {
  4097. case 'minOrderQty':
  4098. $scope.minOrderQtyVerify = regex.test(value);
  4099. break;
  4100. case 'minPackQty':
  4101. $scope.minPackQtyVerify = regex.test(value);
  4102. break;
  4103. case 'leadtime':
  4104. $scope.leadtimeVerify = regex.test(value);
  4105. break;
  4106. default:
  4107. $scope.replyPrices[type] = regex.test(value);
  4108. break;
  4109. }
  4110. }
  4111. $scope.verifylapQty = function (value, index, inquiryItem) {
  4112. value = parseInt(value);
  4113. var regex = /^\d+(.\d{1,6})?$/;
  4114. var valid = true;
  4115. angular.forEach(inquiryItem.replies, function(reply, $index) {
  4116. if ($index < index && reply.lapQty >= value) {
  4117. valid = false;
  4118. }
  4119. });
  4120. $scope.replylapQtys[index] = regex.test(value) && valid;
  4121. };
  4122. $scope.isValid = function (item, withSteps) {
  4123. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4124. if (!withSteps || !bool)
  4125. return bool;
  4126. angular.forEach(item.replies, function (r, i) {
  4127. $scope.verifylapQty(r.lapQty, i, item);
  4128. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  4129. });
  4130. return bool;
  4131. };
  4132. // 获取token信息
  4133. $scope.getToken = function() {
  4134. token.info({userType: 'saleinquiry'}, {}, function(data) {
  4135. $scope.token = data.token;
  4136. }, function(response) {
  4137. toaster.pop('error', '提示', response.data);
  4138. });
  4139. };
  4140. $scope.deleteAttach = function (attaches, index) {
  4141. attaches.splice(index, 1);
  4142. };
  4143. $scope.onReplyClick = function (item, withSteps) {
  4144. if (item.vendFromDate instanceof Date) {
  4145. item.vendFromDate = item.vendFromDate.getTime();
  4146. }
  4147. if (item.vendToDate instanceof Date) {
  4148. item.vendToDate = item.vendToDate.getTime();
  4149. }
  4150. if (item.vendFromDate > item.vendToDate) {
  4151. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4152. return;
  4153. }
  4154. var replies = [];
  4155. var valid = true;
  4156. var validLapQty = 0;
  4157. angular.forEach(item.replies, function (r, i) {
  4158. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  4159. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  4160. valid = false;
  4161. validLapQty = r.lapQty;
  4162. }
  4163. if ((i > 0 ? r.lapQty : 1) || r.price)
  4164. replies.push(r);
  4165. });
  4166. item.replies = replies;
  4167. $scope.loading = true;
  4168. if (!valid) { // 不合法时给出提示
  4169. if (validLapQty) {
  4170. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  4171. } else {
  4172. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  4173. }
  4174. $scope.loading = false;
  4175. } else {
  4176. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  4177. if (withSteps) {
  4178. if(null != file) {
  4179. $upload.upload({
  4180. url: 'sale/inquiry/addAttach',
  4181. file: file,
  4182. method: 'POST',
  4183. data: {
  4184. item: item,
  4185. method: 'reply'
  4186. }
  4187. }).success(function (data) {
  4188. if (data.item) {
  4189. item = data.item;
  4190. }
  4191. window.location.reload();
  4192. });
  4193. } else {
  4194. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  4195. $scope.loading = false;
  4196. toaster.pop('info', '提示', '报价成功');
  4197. // loadData();
  4198. window.location.reload();
  4199. }, function (response) {
  4200. $scope.loading = false;
  4201. toaster.pop('error', '询价失效', response.data);
  4202. });
  4203. }
  4204. } else {
  4205. if(null != file) {
  4206. $upload.upload({
  4207. url: 'sale/inquiry/addAttach',
  4208. file: file,
  4209. method: 'POST',
  4210. data: {
  4211. item: item,
  4212. method: 'save'
  4213. }
  4214. }).success(function (data) {
  4215. if (data.item) {
  4216. item = data.item;
  4217. }
  4218. window.location.reload();
  4219. });
  4220. } else {
  4221. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  4222. $scope.loading = false;
  4223. toaster.pop('info', '提示', '保存成功');
  4224. // loadData();
  4225. window.location.reload();
  4226. }, function (response) {
  4227. $scope.loading = false;
  4228. toaster.pop('error', '保存失败', response.data);
  4229. });
  4230. }
  4231. }
  4232. }
  4233. };
  4234. // 取消
  4235. $scope.cancel = function () {
  4236. $scope.tableParams.reload();
  4237. }
  4238. }]);
  4239. // 平台新增的询价单
  4240. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'PurcProduct', 'PurcProductNewest', '$timeout', '$http', 'ShipAddress', 'Search', 'ComponentActiveAPI', '$state',
  4241. function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, PurcProduct, PurcProductNewest, $timeout, $http, ShipAddress, Search, ComponentActiveAPI, $state) {
  4242. $scope.status = 'InquiryNew';
  4243. $scope.active = 'all';
  4244. $rootScope.tenderVendor = null;// 清除掉已选择的
  4245. $scope.searchMethod = false;
  4246. var getService = function () {
  4247. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  4248. };
  4249. $scope.inquiry = {
  4250. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  4251. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  4252. priceType: '采购',
  4253. isOpen: 1,
  4254. invoice: 0,
  4255. ifTax: 1,
  4256. currency: 'RMB',
  4257. inquirytype: '询价'
  4258. };
  4259. $scope.changeCurrency = function (inquiry) {
  4260. if (inquiry.currency !== 'RMB') {
  4261. $scope.notRMB = true;
  4262. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  4263. inquiry.invoice = 0;
  4264. } else {
  4265. $scope.notRMB = false;
  4266. }
  4267. };
  4268. // 获取收货地址列表
  4269. var loadShipAddress = function () {
  4270. ShipAddress.shipAddList({}, function (data) {
  4271. $scope.ships = data;
  4272. if (angular.isDefined($scope.ships)) {
  4273. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  4274. }
  4275. });
  4276. };
  4277. loadShipAddress();
  4278. // 获取地址信息
  4279. $http.get('resources/citydata/city.json', {
  4280. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  4281. }).then(function (response) {
  4282. $scope.provinces = response.data;
  4283. });
  4284. // 新增收货地址保存
  4285. $scope.saveShipAddress = function (ship) {
  4286. ship.address = ship.province + ship.city + ship.district;
  4287. ShipAddress.saveAddress({}, ship, function (data) {
  4288. if (data.success) {
  4289. // 获取收货地址列表
  4290. loadShipAddress();
  4291. toaster.pop('success', '提示', data.success);
  4292. }
  4293. if (data.error) {
  4294. toaster.pop('error', '提示', data.error);
  4295. }
  4296. });
  4297. };
  4298. $scope.currentDay = function () {
  4299. return $filter('date')(new Date(), 'yyyy-MM-dd');
  4300. };
  4301. $scope.vendors = [];
  4302. // 查找供应商
  4303. $scope.dbfindVendor = function () {
  4304. var modalInstance = $modal.open({
  4305. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  4306. controller: 'DbfindVendorCtrl',
  4307. size: 'lg',
  4308. resolve: {}
  4309. });
  4310. modalInstance.result.then(function (data) {
  4311. var ifPush = true;
  4312. modalInstance.result.then(function (data) {
  4313. angular.forEach(data, function (vendor) {
  4314. if (!$scope.vendors) {// 不存在就先创建
  4315. $scope.vendors = [{}];
  4316. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  4317. } else {
  4318. for (var i = 0; i < $scope.vendors.length; i++) {
  4319. ifPush = true;
  4320. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  4321. ifPush = false;
  4322. break; // 判定到已存在供应商,就终止循环。
  4323. }
  4324. }
  4325. if (ifPush) {
  4326. $scope.vendors.push({
  4327. enName: vendor.vendorEnterprise.enName,
  4328. enuu: vendor.vendorEnterprise.uu
  4329. });
  4330. }
  4331. }
  4332. });
  4333. $rootScope.tenderVendor = $scope.vendors;
  4334. }, function () {
  4335. });
  4336. }, function () {
  4337. });
  4338. };
  4339. // 删除一个供应商
  4340. $scope.removeVendor = function (index) {
  4341. $scope.vendors.splice(index, 1);
  4342. };
  4343. $scope.removeChecked = function () {
  4344. if ($scope.vendors.length > 0) {
  4345. $scope.vendors = [];
  4346. $rootScope.tenderVendor = '';
  4347. }
  4348. }
  4349. // 物料信息
  4350. $scope.tableParams = new ngTableParams({
  4351. page: 1,
  4352. count: 20,
  4353. sorting: {
  4354. id: 'desc'
  4355. }
  4356. }, {
  4357. total: 0,
  4358. counts: [5, 10, 25, 50],
  4359. getData: function ($defer, params) {
  4360. $scope.loading = true;
  4361. var pageParams = params.url();
  4362. pageParams.keyword = $scope.keyword;
  4363. $scope.tip = $scope.keyword;
  4364. pageParams.searchFilter = $scope.searchFilter;
  4365. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4366. $scope.loading = false;
  4367. if (page) {
  4368. params.total(page.totalElement);
  4369. $scope.total = page.totalElement;
  4370. $defer.resolve(page.content);
  4371. }
  4372. }, function (response) {
  4373. $scope.loading = false;
  4374. toaster.pop('error', '数据加载失败', response.data);
  4375. });
  4376. }
  4377. });
  4378. // 搜索框回车
  4379. $scope.onSearch = function (keyword) {
  4380. // 每次搜索重置获取数据方法
  4381. $scope.searchMethod = false;
  4382. if(keyword != null && keyword != '') {
  4383. $scope.searchMethod = true;
  4384. }
  4385. $scope.tableParams.page(1);
  4386. $scope.tableParams.reload();
  4387. };
  4388. $scope.inquiry.inquiryItems = [];
  4389. var prod = {
  4390. cmpCode: null,
  4391. prodTitle: null,
  4392. inbrand: null,
  4393. toDate: null,
  4394. unit: 'PCS',
  4395. needquantity: null
  4396. };
  4397. $scope.inquiry.inquiryItems.push(prod);
  4398. // 联想词start
  4399. // 获取品牌联想词
  4400. $scope.getSimilarBrands = function (value) {
  4401. if (value) {
  4402. // 获取品牌联想词
  4403. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  4404. return data.map(function (item) {
  4405. return item;
  4406. });
  4407. });
  4408. }
  4409. };
  4410. // 获取产品型号联想词
  4411. $scope.getSimilarCodes = function (value) {
  4412. if (value) {
  4413. // 获取产品型号联想词
  4414. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  4415. return data.map(function (item) {
  4416. return item;
  4417. })
  4418. });
  4419. }
  4420. };
  4421. $scope.selectKind = function (prod) {
  4422. var submit = [];
  4423. $modal.open({
  4424. animation: true,
  4425. size: 'lg',
  4426. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  4427. controller: 'ProdKindChooseCtrl',
  4428. resolve: {
  4429. actives: function () {
  4430. return $scope.actives;
  4431. }
  4432. }
  4433. }).result.then(function (data) {
  4434. $scope.actives = data.actives;
  4435. var size = data.actives.length;
  4436. submit.gradeOneKiName = '';
  4437. submit.gradeTwoKiName = '';
  4438. submit.gradeThreeKiName = '';
  4439. if (size > 0) {
  4440. submit.gradeOneKiName = $scope.actives[0].nameCn;
  4441. prod.prodTitle = submit.gradeOneKiName;
  4442. if (size > 1) {
  4443. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  4444. prod.prodTitle = submit.gradeTwoKiName;
  4445. if (size > 2) {
  4446. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  4447. prod.prodTitle = submit.gradeThreeKiName;
  4448. }
  4449. }
  4450. }
  4451. }, function () {
  4452. });
  4453. };
  4454. // 点击联想词获取品牌信息
  4455. $scope.onAssociateBrandClick = function (brand, prod) {
  4456. if (brand instanceof String) {
  4457. prod.inbrand = brand;
  4458. } else if (brand instanceof Object) {
  4459. prod.inbrand = brand.brandCn;
  4460. }
  4461. };
  4462. // 打开品牌选择的模态框
  4463. $scope.selectBrand = function (prod) { //打开模态
  4464. var modalInstance = $modal.open({
  4465. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  4466. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  4467. });
  4468. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  4469. });
  4470. modalInstance.result.then(function (brand) {
  4471. prod.inbrand = brand.nameCn;
  4472. }, function (reason) {
  4473. });
  4474. };
  4475. // 点击联想词获取器件信息 带入产品分类和品牌
  4476. $scope.onAssociateCmpClick = function (cmp, prod) {
  4477. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  4478. $scope.component = data;
  4479. prod.cmpCode = data.code;
  4480. prod.prodTitle = data.kind.nameCn;
  4481. prod.inbrand = data.brand.nameCn;
  4482. }, function (res) {
  4483. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  4484. })
  4485. };
  4486. //联想词end
  4487. // 导入商品信息
  4488. $scope.uplodaByBatch = function () {
  4489. var modalInstance = $modal.open({
  4490. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  4491. controller: 'PurcInquiryUploadCtrl',
  4492. size: 'lg',
  4493. resolve: {}
  4494. });
  4495. modalInstance.result.then(function (data) {
  4496. angular.forEach(data, function (prod) {
  4497. $scope.inquiry.inquiryItems.push(prod);
  4498. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4499. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4500. $scope.inquiry.inquiryItems.splice(i, 1);
  4501. }
  4502. }
  4503. })
  4504. }, function () {
  4505. });
  4506. }
  4507. //增加商品
  4508. $scope.add = function () {
  4509. $scope.inquiry.inquiryItems.push(
  4510. {
  4511. cmpCode: null,
  4512. prodTitle: null,
  4513. unit: 'PCS',
  4514. ibrand: null,
  4515. toDate: null,
  4516. needquantity: null
  4517. });
  4518. };
  4519. //删除商品
  4520. $scope.del = function (index) {
  4521. $scope.inquiry.inquiryItems.splice(index, 1);
  4522. };
  4523. $scope.check = function (product) {
  4524. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4525. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4526. $scope.inquiry.inquiryItems.splice(i, 1);
  4527. }
  4528. }
  4529. $scope.inquiry.inquiryItems.push({
  4530. cmpCode: product.cmpCode, prodTitle: product.title, spec: product.spec, unit: product.unit,
  4531. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand
  4532. });
  4533. }
  4534. $scope.getMinDate = function (item) {
  4535. return $filter('date')(new Date, 'yyyy-MM-dd');
  4536. };
  4537. $scope.openDatePicker = function ($event, openParam, index) {
  4538. $event.preventDefault();
  4539. $event.stopPropagation();
  4540. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  4541. };
  4542. $scope.openEndDatePicker = function ($event, item, openParam) {
  4543. $event.preventDefault();
  4544. $event.stopPropagation();
  4545. item[openParam] = !item[openParam];
  4546. };
  4547. $scope.ifrepeat = false;
  4548. // 保存
  4549. $scope.save = function () {
  4550. $scope.loading = true;
  4551. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4552. $scope.item = $scope.inquiry.inquiryItems[i];
  4553. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4554. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4555. if (i != j) {
  4556. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4557. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4558. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4559. $scope.ifrepeat = true;
  4560. }
  4561. }
  4562. }
  4563. }
  4564. if (!$scope.ifrepeat) {
  4565. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4566. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4567. if ($scope.vendors.length > 0) {
  4568. $upload.upload({
  4569. url: 'purc/inquiry/save/withVendor',
  4570. file: file,
  4571. method: 'POST',
  4572. data: {
  4573. inquiry: $scope.inquiry,
  4574. contacts: $scope.vendors
  4575. },
  4576. }).success(function (data) {
  4577. $scope.loading = false;
  4578. if (data.success) {
  4579. toaster.pop('success', '提示', data.success);
  4580. $timeout(function () {
  4581. $rootScope.active = 'todo';
  4582. window.location.hash = "#/purc/inquiry_unapply";
  4583. }, 500);
  4584. }
  4585. if (data.error) {
  4586. toaster.pop('error', '提示', data.error);
  4587. }
  4588. }).error(function (data, status, headers, config) {
  4589. $scope.loadingShow = false;
  4590. if (status == 403) { // 抛异常专用
  4591. toaster.pop('error', '操作失败', data);
  4592. } else {
  4593. toaster.pop('error', '操作失败', data.error);
  4594. }
  4595. });
  4596. } else {
  4597. toaster.pop('info', '提示', '请先选择供应商');
  4598. }
  4599. } else {
  4600. $upload.upload({
  4601. url: 'purc/inquiry/save/withoutVendor',
  4602. file: file,
  4603. method: 'POST',
  4604. data: {
  4605. inquiry: $scope.inquiry,
  4606. },
  4607. }).success(function (data) {
  4608. $scope.loading = false;
  4609. if (data.success) {
  4610. toaster.pop('success', '提示', data.success);
  4611. }
  4612. if (data.error) {
  4613. toaster.pop('error', '提示', data.error);
  4614. }
  4615. }).error(function (data, status, headers, config) {
  4616. $scope.loadingShow = false;
  4617. if (status == 403) { // 抛异常专用
  4618. toaster.pop('error', '操作失败', data);
  4619. } else {
  4620. toaster.pop('error', '操作失败', data.error);
  4621. }
  4622. });
  4623. }
  4624. } else {
  4625. $scope.loading = false;
  4626. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4627. }
  4628. }
  4629. // 保存并提交
  4630. $scope.submit = function () {
  4631. $scope.loading = true;
  4632. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4633. $scope.item = $scope.inquiry.inquiryItems[i];
  4634. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4635. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4636. if (i != j) {
  4637. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4638. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4639. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4640. $scope.ifrepeat = true;
  4641. }
  4642. }
  4643. }
  4644. }
  4645. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4646. if (!$scope.ifrepeat) {
  4647. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4648. if ($scope.vendors.length > 0) {
  4649. $upload.upload({
  4650. url: 'purc/inquiry/submit/withVendor',
  4651. file: file,
  4652. method: 'POST',
  4653. data: {
  4654. inquiry: $scope.inquiry,
  4655. contacts: $scope.vendors
  4656. },
  4657. }).success(function (data) {
  4658. $scope.loading = false;
  4659. if (data.success) {
  4660. toaster.pop('success', '提示', data.success);
  4661. $timeout(function () {
  4662. window.location.hash = "#/purc/purchaseinquiry";
  4663. }, 500);
  4664. }
  4665. if (data.error) {
  4666. toaster.pop('error', '提示', data.error);
  4667. }
  4668. }).error(function (data, status, headers, config) {
  4669. $scope.loadingShow = false;
  4670. if (status == 403) { // 抛异常专用
  4671. toaster.pop('error', '操作失败', data);
  4672. } else {
  4673. toaster.pop('error', '操作失败', data.error);
  4674. }
  4675. });
  4676. } else {
  4677. toaster.pop('info', '提示', '请先选择供应商');
  4678. }
  4679. } else {
  4680. $upload.upload({
  4681. url: 'purc/inquiry/submit/withoutVendor',
  4682. file: file,
  4683. method: 'POST',
  4684. data: {
  4685. inquiry: $scope.inquiry,
  4686. },
  4687. }).success(function (data) {
  4688. $scope.loading = false;
  4689. if (data.success) {
  4690. toaster.pop('success', '提示', data.success);
  4691. }
  4692. if (data.error) {
  4693. toaster.pop('error', '提示', data.error);
  4694. }
  4695. }).error(function (data, status, headers, config) {
  4696. $scope.loadingShow = false;
  4697. if (status == 403) { // 抛异常专用
  4698. toaster.pop('error', '操作失败', data);
  4699. } else {
  4700. toaster.pop('error', '操作失败', data.error);
  4701. }
  4702. });
  4703. }
  4704. } else {
  4705. $scope.loading = false;
  4706. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4707. }
  4708. }
  4709. $scope.previewShow = false;
  4710. $scope.pdfShow = false;
  4711. $scope.noneFileShow = true;
  4712. $scope.$watch('myFiles', function () {
  4713. if ($scope.myFiles) {
  4714. $scope.noneFileShow = false;
  4715. var file = $scope.myFiles[0];
  4716. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  4717. $scope.pdfShow = true;
  4718. $scope.previewShow = false;
  4719. $scope.imgPreviewName = file.name;
  4720. } else {
  4721. if (typeof(Worker) !== "undefined") {//支持HTML5
  4722. $scope.imgPreview = getObjectURL(file);
  4723. $scope.imgPreviewName = file.name;
  4724. } else {//不支持HTML5
  4725. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  4726. $scope.imgPreviewName = file.name;
  4727. }
  4728. $scope.previewShow = true;
  4729. $scope.pdfShow = false;
  4730. }
  4731. } else {
  4732. $scope.noneFileShow = true;
  4733. $scope.previewShow = false;
  4734. $scope.pdfShow = false;
  4735. }
  4736. });
  4737. //建立一个可存取到该file的url
  4738. var getObjectURL = function (file) {
  4739. var url = null;
  4740. if (window.createObjectURL != undefined) { // basic
  4741. url = window.createObjectURL(file);
  4742. } else if (window.URL != undefined) { // mozilla(firefox)
  4743. url = window.URL.createObjectURL(file);
  4744. } else if (window.webkitURL != undefined) { // webkit or chrome
  4745. url = window.webkitURL.createObjectURL(file);
  4746. }
  4747. return url;
  4748. };
  4749. }]);
  4750. /**
  4751. * 代采订单批量导入
  4752. */
  4753. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  4754. // 通过excel批量上传物料
  4755. $scope.result = null;
  4756. $scope.upload = function () {
  4757. var file = $scope.myFiles[0];
  4758. $upload.upload({
  4759. url: 'purc/inquiry/release/excel',
  4760. file: file,
  4761. method: 'POST'
  4762. }).success(function (data) {
  4763. $scope.result = data;
  4764. $scope.success = $scope.result.success;
  4765. $scope.total = $scope.result.total;
  4766. $scope.alters = $scope.result.alters;
  4767. }).error(function (response) {
  4768. toaster.pop('error', response.data || response);
  4769. });
  4770. };
  4771. // 查看范例
  4772. $scope.showImg = function () {
  4773. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  4774. box.show();
  4775. box.find('img').attr('src', src);
  4776. box.find('a').click(function () {
  4777. box.hide();
  4778. });
  4779. box.dblclick(function () {
  4780. box.hide();
  4781. });
  4782. };
  4783. // 下载模板
  4784. $scope.download = function () {
  4785. window.location.href = 'purc/inquiry/upload/template';
  4786. };
  4787. $scope.enSure = function () {
  4788. $modalInstance.close($scope.result.items);
  4789. }
  4790. $scope.cancel = function () {
  4791. $modalInstance.dismiss();
  4792. }
  4793. }]);
  4794. // 平台询价单(已提交)
  4795. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', 'CurrentRole', function ($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope, CurrentRole) {
  4796. $scope.status = 'InquirySubmit';
  4797. BaseService.scrollBackToTop();
  4798. // 获取当前用户是否为普通用户
  4799. CurrentRole.isUser({}, {}, function (data) {
  4800. $scope.isUser = data.isUser;
  4801. });
  4802. if ($rootScope.active) {
  4803. $scope.active = $rootScope.active;
  4804. $rootScope.active = null;
  4805. } else {
  4806. $scope.active = 'todo';
  4807. }
  4808. $scope.agreedText = '全部';
  4809. $scope.dateZoneText = '一个月内';
  4810. $scope.condition = {dateZone: 1};
  4811. /* 时间筛选初始化*/
  4812. var fromDate = new Date();
  4813. var toDate = new Date();
  4814. fromDate.setMonth(fromDate.getMonth() - 1);
  4815. fromDate.setHours(0, 0, 0, 0);
  4816. toDate.setHours(23, 59, 59, 999);
  4817. $scope.condition.dateFrom = fromDate;
  4818. $scope.condition.dateTo = toDate;
  4819. $scope.changeAgreed = function (agreed) {
  4820. $scope.condition.agreed = agreed;
  4821. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4822. $scope.condition.$agreedOpen = false;
  4823. };
  4824. $scope.changeDateZone = function (zone) {
  4825. $scope.condition.dateZone = zone;
  4826. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4827. $scope.condition.$dateZoneOpen = false;
  4828. getDateCondition(zone, $scope.condition);
  4829. $scope.tableParams.page(1);
  4830. $scope.tableParams.reload();
  4831. };
  4832. $scope.setActive = function (state) {
  4833. if ($scope.active != state) {
  4834. $scope.active = state;
  4835. if ($scope.tableParams.page() == 1) {
  4836. $scope.tableParams.reload();
  4837. } else {
  4838. $scope.tableParams.page(1);
  4839. }
  4840. }
  4841. }
  4842. var getService = function () {
  4843. return PurchaseInquiry;
  4844. };
  4845. $scope.tableParams = new ngTableParams({
  4846. page: 1,
  4847. count: 20,
  4848. sorting: {
  4849. 'inquiry.date': 'desc',
  4850. 'inquiry.enterprise.enName': 'asc',
  4851. 'inquiry.code': 'asc'
  4852. }
  4853. }, {
  4854. total: 0,
  4855. counts: [5, 10, 25, 50],
  4856. getData: function ($defer, params) {
  4857. $scope.loading = true;
  4858. var pageParams = params.url();
  4859. var realActive = {};
  4860. pageParams.searchFilter = {
  4861. keyword: $scope.keyword,
  4862. fromDate: getDateTime($scope.condition.dateFrom),
  4863. endDate: getDateTime($scope.condition.dateTo)
  4864. };
  4865. if ($scope.active == 'overdue') {
  4866. $scope.active = 'end';
  4867. }
  4868. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4869. $scope.loading = false;
  4870. if (page) {
  4871. params.total(page.totalElement);
  4872. $defer.resolve(page.content);
  4873. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4874. }
  4875. }, function (response) {
  4876. $scope.loading = false;
  4877. toaster.pop('error', '数据加载失败', response.data);
  4878. });
  4879. }
  4880. });
  4881. //获得各分类未阅读数量
  4882. var getUnreadCount = function () {
  4883. PurchaseInquiry.getUnreadCount(null, function(data){
  4884. $scope.unread = data;
  4885. });
  4886. };
  4887. getUnreadCount();
  4888. //设置单据已读
  4889. $scope.setOrdersRead = function (id) {
  4890. // 如果单据本身已读,则不发送请求修改数据
  4891. if (!$scope.isUnread(id)){
  4892. return;
  4893. }
  4894. var sourceId = [];
  4895. sourceId.push(id);
  4896. PurchaseInquiry.setRead({}, sourceId, function (message) {
  4897. getUnreadIds();
  4898. getUnreadCount();
  4899. });
  4900. };
  4901. //获得未读单据id
  4902. var getUnreadIds = function (){
  4903. PurchaseInquiry.getUnreadIds({}, "", function (message) {
  4904. $scope.unreadCode = message.content;
  4905. });
  4906. };
  4907. getUnreadIds();
  4908. //判断单据是否未读
  4909. $scope.isUnread = function (id){
  4910. for (var i in $scope.unreadCode) {
  4911. if (id == $scope.unreadCode[i]) {
  4912. return true;
  4913. }
  4914. }
  4915. };
  4916. $scope.openDatePicker = function ($event, item, openParam) {
  4917. $event.preventDefault();
  4918. $event.stopPropagation();
  4919. item[openParam] = !item[openParam];
  4920. };
  4921. $scope.openFilterDatePicker = function ($event, item, openParam) {
  4922. $event.preventDefault();
  4923. $event.stopPropagation();
  4924. item[openParam] = !item[openParam];
  4925. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  4926. $scope.tableParams.reload();
  4927. }
  4928. };
  4929. // 搜索框回车
  4930. $scope.onSearch = function () {
  4931. $scope.tableParams.page(1);
  4932. $scope.tableParams.reload();
  4933. };
  4934. // 采纳
  4935. $scope.accept = function (id) {
  4936. PurchaseInquiry.accept({id: id}, {}, function (data) {
  4937. if (data.success) {
  4938. toaster.pop('success', '提示', data.success);
  4939. $scope.tableParams.reload();
  4940. }
  4941. if (data.error) {
  4942. toaster.pop('error', '提示', data.error);
  4943. }
  4944. }, function (response) {
  4945. toaster.pop('error', '提示', response.data);
  4946. })
  4947. };
  4948. // 拒绝
  4949. $scope.refuse = function (id) {
  4950. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  4951. if (data.success) {
  4952. toaster.pop('success', '提示', data.success);
  4953. $scope.tableParams.reload();
  4954. }
  4955. if (data.error) {
  4956. toaster.pop('error', '提示', data.error);
  4957. }
  4958. }, function (response) {
  4959. toaster.pop('error', '提示', response.data);
  4960. })
  4961. }
  4962. // 导出
  4963. $scope.exportXls = function () {
  4964. PurchaseInquiry.exportXls({}, {}, function (data) {
  4965. if (data.success){
  4966. window.location.href = 'purc/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4967. }
  4968. }, function (response) {
  4969. toaster.pop('error', '数据加载失败', response.data);
  4970. });
  4971. }
  4972. }]);
  4973. // 平台询价单(未提交)
  4974. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function ($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  4975. BaseService.scrollBackToTop();
  4976. if ($rootScope.active = 'done') {
  4977. $scope.active = 'done';
  4978. $rootScope.active = '';
  4979. }
  4980. if ($rootScope.active = 'todo') {
  4981. $scope.active = 'todo';
  4982. $rootScope.active = '';
  4983. }
  4984. var getService = function () {
  4985. if ($scope.active == 'todo') {
  4986. return PurchaseInquiry.getUnapply;
  4987. }
  4988. if ($scope.active == 'done') {
  4989. return PurchaseInquiry.getSubmit;
  4990. }
  4991. }
  4992. $scope.setActive = function (state) {
  4993. if ($scope.active != state) {
  4994. $scope.active = state;
  4995. if ($scope.tableParams.page() == 1) {
  4996. $scope.tableParams.reload();
  4997. } else {
  4998. $scope.tableParams.page(1);
  4999. }
  5000. }
  5001. }
  5002. $scope.tableParams = new ngTableParams({
  5003. page: 1,
  5004. count: 20,
  5005. sorting: {
  5006. 'date': 'desc',
  5007. 'enterprise.enName': 'asc',
  5008. 'code': 'asc'
  5009. }
  5010. }, {
  5011. total: 0,
  5012. counts: [5, 10, 25, 50],
  5013. getData: function ($defer, params) {
  5014. $scope.loading = true;
  5015. var pageParams = params.url();
  5016. var realActive = {};
  5017. if ($scope.active == 'overdue') {
  5018. $scope.active = 'end';
  5019. }
  5020. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  5021. $scope.loading = false;
  5022. if (page) {
  5023. params.total(page.totalElements);
  5024. $defer.resolve(page.content);
  5025. }
  5026. }, function (response) {
  5027. $scope.loading = false;
  5028. toaster.pop('error', '数据加载失败', response.data);
  5029. });
  5030. }
  5031. });
  5032. // 删除明细
  5033. $scope.deleteById = function (id) {
  5034. PurchaseInquiry.deleteById({id: id}, {}, function (data) {
  5035. toaster.pop('success', '提示', '删除成功');
  5036. $scope.tableParams.reload();
  5037. }, function (response) {
  5038. toaster.pop('error', '提示', response.data);
  5039. });
  5040. }
  5041. // 删除主表
  5042. $scope.clearOrder = function (id) {
  5043. PurchaseInquiry.clearOrder({id: id}, {}, function (data) {
  5044. toaster.pop('success', '提示', '删除成功');
  5045. $scope.tableParams.reload();
  5046. }, function (response) {
  5047. toaster.pop('error', '提示', response.data);
  5048. });
  5049. }
  5050. // 提交
  5051. $scope.submit = function (id) {
  5052. PurchaseInquiry.submitUnapply({id: id}, {}, function (data) {
  5053. toaster.pop('success', '提示', '单据提交成功');
  5054. $scope.active = 'done';
  5055. $scope.tableParams.reload();
  5056. }, function (response) {
  5057. toaster.pop('error', '提示', response.data);
  5058. })
  5059. }
  5060. // 发布公共询价
  5061. $scope.publish = function (id) {
  5062. PurchaseInquiry.publishInquiry({id: id}, {}, function (data) {
  5063. toaster.pop('success', '提示', data.success);
  5064. $scope.active = 'done';
  5065. $scope.tableParams.reload();
  5066. }, function (response) {
  5067. toaster.pop('error', '提示', response.data);
  5068. })
  5069. }
  5070. }]);
  5071. // 公共询价列表
  5072. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'PurcInquiry', 'publicInquiry', 'publicInquiryList', '$modal', '$http', 'AccountEnterprise', 'customer', 'AuthenticationService', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, PurcInquiry, publicInquiry, publicInquiryList, $modal, $http, AccountEnterprise, customer, AuthenticationService) {
  5073. BaseService.scrollBackToTop();
  5074. }]);
  5075. /**
  5076. * 报价操作
  5077. */
  5078. app.controller('QuoteCtrl', ['$scope', 'inquiryItem', 'toaster', 'publicInquiry', '$modalInstance', '$upload', function($scope, inquiryItem, toaster, publicInquiry, $modalInstance, $upload) {
  5079. $scope.inquiryItem = inquiryItem;
  5080. if ($scope.inquiryItem.replies == null || $scope.inquiryItem.replies.length == 0) {
  5081. $scope.inquiryItem.replies = [];
  5082. var reply = {
  5083. lapQty: 0,
  5084. price: null
  5085. };
  5086. $scope.inquiryItem.replies.push(reply);
  5087. }
  5088. $scope.replyPrices = [];
  5089. $scope.replylapQtys = [];
  5090. $scope.replyPrices.push(true);
  5091. $scope.replylapQtys.push(true);
  5092. // 获取默认币别
  5093. publicInquiry.getCurrency({}, function(data) {
  5094. $scope.currencies = data;
  5095. });
  5096. // 增加一列分段报价
  5097. $scope.addStep = function (inquiryItem) {
  5098. var check = true;
  5099. angular.forEach(inquiryItem.replies, function(reply) {
  5100. if (reply.lapQty == null) {
  5101. toaster.pop('error', '提示', '存在未填写分段数量的分段,请先填写分段数量');
  5102. check = false;
  5103. }
  5104. if (check && reply.price == null) {
  5105. toaster.pop('error', '提示', '存在未填写价格的分段,请先填写价格');
  5106. check = false;
  5107. }
  5108. });
  5109. if (check) {
  5110. $scope.replyPrices.push(true);
  5111. if (inquiryItem.replies.length >= 5) {
  5112. toaster.pop('warning', '提示', '最多支持5个分段!');
  5113. } else {
  5114. inquiryItem.replies.push({});
  5115. if (inquiryItem.replies.length != 1) {
  5116. $scope.replyPrices.push(true);
  5117. $scope.replylapQtys.push(true);
  5118. }
  5119. }
  5120. }
  5121. };
  5122. // 删除一列分段报价
  5123. $scope.removeStep = function (inquiryItem, stepIndex) {
  5124. inquiryItem.replies.splice(stepIndex, 1);
  5125. $scope.replyPrices.splice(stepIndex, 1);
  5126. $scope.replylapQtys.splice(stepIndex, 1);
  5127. };
  5128. // 取消,关闭弹出框
  5129. $scope.cancel = function() {
  5130. $modalInstance.dismiss();
  5131. }
  5132. // 保存报价信息
  5133. $scope.save = function(inquiryItem, method) {
  5134. var replies = [];
  5135. // 判断分段数是否合法
  5136. var valid = true;
  5137. var validLapQty = 0;
  5138. angular.forEach(inquiryItem.replies, function (r, i) {
  5139. if ((i > 0 ? r.lapQty : 1) || r.price) {
  5140. replies.push(r);
  5141. }
  5142. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  5143. if (i > 0 && parseInt(r.lapQty) <= parseInt(inquiryItem.replies[i - 1].lapQty) || r.lapQty == null) {
  5144. valid = false;
  5145. validLapQty = r.lapQty;
  5146. }
  5147. });
  5148. inquiryItem.replies = replies;
  5149. $scope.loading = true;
  5150. if (!valid) {
  5151. if (validLapQty) {
  5152. toaster.pop('error', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  5153. } else {
  5154. toaster.pop('error', '提示', '分段数量不合法,不能报价!');
  5155. }
  5156. } else {
  5157. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  5158. $upload.upload({
  5159. url: 'pubInquiry/turnToQuotation',
  5160. file: file,
  5161. method: 'POST',
  5162. data: {
  5163. item: inquiryItem,
  5164. method: method
  5165. }
  5166. }).success(function (data) {
  5167. if (data.item) {
  5168. item = data.item;
  5169. }
  5170. $scope.loading = false;
  5171. toaster.pop('info', '提示', '报价成功');
  5172. $modalInstance.close();
  5173. }).error(function (data) {
  5174. $scope.loading = false;
  5175. toaster.pop('error', '报价失败');
  5176. });
  5177. }
  5178. }
  5179. $scope.previewShow = false;
  5180. $scope.pdfShow = false;
  5181. $scope.noneFileShow = true;
  5182. $scope.$watch('myFiles', function () {
  5183. if ($scope.myFiles) {
  5184. $scope.noneFileShow = false;
  5185. var file = $scope.myFiles[0];
  5186. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  5187. $scope.pdfShow = true;
  5188. $scope.previewShow = false;
  5189. $scope.imgPreviewName = file.name;
  5190. } else {
  5191. if (typeof(Worker) !== "undefined") {//支持HTML5
  5192. $scope.imgPreview = getObjectURL(file);
  5193. $scope.imgPreviewName = file.name;
  5194. } else {//不支持HTML5
  5195. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  5196. $scope.imgPreviewName = file.name;
  5197. }
  5198. $scope.previewShow = true;
  5199. $scope.pdfShow = false;
  5200. }
  5201. } else {
  5202. $scope.noneFileShow = true;
  5203. $scope.previewShow = false;
  5204. $scope.pdfShow = false;
  5205. }
  5206. });
  5207. //建立一个可存取到该file的url
  5208. var imgurl = null;
  5209. var getObjectURL = function (file) {
  5210. var url = null;
  5211. if (window.createObjectURL != undefined) { // basic
  5212. url = window.createObjectURL(file);
  5213. } else if (window.URL != undefined) { // mozilla(firefox)
  5214. url = window.URL.createObjectURL(file);
  5215. } else if (window.webkitURL != undefined) { // webkit or chrome
  5216. url = window.webkitURL.createObjectURL(file);
  5217. }
  5218. imgurl = url;
  5219. return url;
  5220. };
  5221. }]);
  5222. /**
  5223. * 公共询价详情
  5224. */
  5225. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', 'publicInquiry', 'publicInquiryList', '$modal', '$http', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise, publicInquiry, publicInquiryList, $modal, $http) {
  5226. BaseService.scrollBackToTop();
  5227. $scope.currentHasBid = false;
  5228. var loadData = function () {
  5229. // 当前企业
  5230. AccountEnterprise.get({}, function (data) {
  5231. $scope.enterprise = data
  5232. publicInquiry.getUrl({}, function(data) {
  5233. var url = data.url;
  5234. $http({
  5235. method: 'get',
  5236. dataType: 'json',
  5237. url: url + '/inquiry/sale/publicInquiry/detail',
  5238. params: {id: $stateParams.id, enuu: $scope.enterprise.uu}
  5239. }).success(function (response) {
  5240. if (response) {
  5241. $scope.inquiryItem = response.inquiryItem;
  5242. }
  5243. }).error(function (err) {
  5244. toaster.pop('error', '数据加载失败', err);
  5245. });
  5246. });
  5247. });
  5248. };
  5249. loadData();
  5250. // 当前时间
  5251. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  5252. // 当前企业
  5253. AccountEnterprise.get({}, function (data) {
  5254. $scope.enterprise = data;
  5255. });
  5256. $scope.isOverDue = function (date) {
  5257. if (date) {
  5258. var ndate = new Date();
  5259. ndate.setHours(23, 59, 59 ,999);
  5260. ndate.setDate(ndate.getDate());
  5261. var timestamp = Date.parse(ndate);
  5262. if (date > timestamp) {
  5263. return true;
  5264. } else {
  5265. return false;
  5266. }
  5267. } else {
  5268. return true;
  5269. }
  5270. }
  5271. // 转客户询价
  5272. $scope.transtoInquiry = function (inquiryItem) {
  5273. publicInquiry.quotationInfo({id: inquiryItem.id}, function(data) {
  5274. if (data.inquiryItem) { //存在已报价的就不进行报价操作
  5275. toaster.pop('error', '该询价单已已经报价');
  5276. } else {
  5277. var modalInstance = $modal.open({
  5278. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5279. controller: 'QuoteCtrl',
  5280. size: 'lg',
  5281. resolve: {
  5282. inquiryItem: function () {
  5283. return inquiryItem
  5284. }
  5285. }
  5286. });
  5287. modalInstance.result.then(function (data) {
  5288. $scope.tableParams.reload();
  5289. }, function () {
  5290. });
  5291. }
  5292. });
  5293. }
  5294. }]);
  5295. // 询价单明细
  5296. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, CurrentRole) {
  5297. // 获取当前用户是否为普通用户
  5298. CurrentRole.isUser({}, {}, function (data) {
  5299. $scope.isUser = !data.isUser;
  5300. });
  5301. var loadData = function () {
  5302. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  5303. $scope.newinquiryItems = data;
  5304. var inquiry = data[0].inquiry;
  5305. //inquiry.inquiryItems = data;
  5306. angular.forEach(inquiry.attachs, function (attach) {
  5307. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5308. });
  5309. $scope.inquiry = inquiry;
  5310. });
  5311. };
  5312. loadData();
  5313. $scope.getMinDate = function (item) {
  5314. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5315. };
  5316. $scope.addStep = function (inquiryItem) {
  5317. if (inquiryItem.replies.length >= 10) {
  5318. toaster.pop('warning', '提示', '最多支持10个分段!');
  5319. } else
  5320. inquiryItem.replies.push({});
  5321. };
  5322. $scope.removeStep = function (inquiryItem, stepIndex) {
  5323. inquiryItem.replies.splice(stepIndex, 1);
  5324. };
  5325. $scope.openDatePicker = function ($event, item, openParam) {
  5326. $event.preventDefault();
  5327. $event.stopPropagation();
  5328. item[openParam] = !item[openParam];
  5329. };
  5330. $scope.getHistory = function (item) {
  5331. if (!item.history) {
  5332. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5333. item.history = data;
  5334. });
  5335. }
  5336. };
  5337. $scope.isValid = function (item, withSteps) {
  5338. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5339. if (!withSteps || !bool)
  5340. return bool;
  5341. angular.forEach(item.replies, function (r, i) {
  5342. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5343. });
  5344. return bool;
  5345. };
  5346. $scope.onReplyClick = function (item, withSteps) {
  5347. if (item.vendFromDate instanceof Date) {
  5348. item.vendFromDate = item.vendFromDate.getTime();
  5349. }
  5350. if (item.vendToDate instanceof Date) {
  5351. item.vendToDate = item.vendToDate.getTime();
  5352. }
  5353. if (item.vendFromDate > item.vendToDate) {
  5354. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5355. return;
  5356. }
  5357. var replies = [];
  5358. angular.forEach(item.replies, function (r, i) {
  5359. if ((i > 0 ? r.lapQty : 1) || r.price)
  5360. replies.push(r);
  5361. });
  5362. item.replies = replies;
  5363. if (withSteps) {
  5364. PurcInquiry.reply({itemId: item.id}, item, function () {
  5365. toaster.pop('info', '提示', '报价成功');
  5366. loadData();
  5367. }, function (response) {
  5368. toaster.pop('error', '报价失败', response.data);
  5369. });
  5370. }
  5371. };
  5372. }]);
  5373. // 询价单明细(发出)
  5374. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, CurrentRole) {
  5375. // 获取当前用户是否为普通用户
  5376. CurrentRole.isUser({}, {}, function (data) {
  5377. $scope.isUser = data.isUser;
  5378. });
  5379. var loadData = function () {
  5380. PurchaseInquiry.detail({id: $stateParams.id}, {},function (data) {
  5381. $scope.inquiry = data;
  5382. },function (response) {
  5383. toaster.pop('error', '提示', response.data);
  5384. });
  5385. };
  5386. loadData();
  5387. $scope.getMinDate = function (item) {
  5388. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5389. };
  5390. $scope.nowDate = new Date().getTime();
  5391. $scope.addStep = function (inquiryItem) {
  5392. if (inquiryItem.replies.length >= 10) {
  5393. toaster.pop('warning', '提示', '最多支持10个分段!');
  5394. } else
  5395. inquiryItem.replies.push({});
  5396. };
  5397. $scope.removeStep = function (inquiryItem, stepIndex) {
  5398. inquiryItem.replies.splice(stepIndex, 1);
  5399. };
  5400. $scope.openDatePicker = function ($event, item, openParam) {
  5401. $event.preventDefault();
  5402. $event.stopPropagation();
  5403. item[openParam] = !item[openParam];
  5404. };
  5405. $scope.getHistory = function (item) {
  5406. if (!item.history) {
  5407. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5408. item.history = data;
  5409. });
  5410. }
  5411. };
  5412. $scope.isValid = function (item, withSteps) {
  5413. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5414. if (!withSteps || !bool)
  5415. return bool;
  5416. angular.forEach(item.replies, function (r, i) {
  5417. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5418. });
  5419. return bool;
  5420. };
  5421. $scope.onReplyClick = function (item, withSteps) {
  5422. if (item.vendFromDate instanceof Date) {
  5423. item.vendFromDate = item.vendFromDate.getTime();
  5424. }
  5425. if (item.vendToDate instanceof Date) {
  5426. item.vendToDate = item.vendToDate.getTime();
  5427. }
  5428. if (item.vendFromDate > item.vendToDate) {
  5429. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5430. return;
  5431. }
  5432. var replies = [];
  5433. angular.forEach(item.replies, function (r, i) {
  5434. if ((i > 0 ? r.lapQty : 1) || r.price)
  5435. replies.push(r);
  5436. });
  5437. item.replies = replies;
  5438. if (withSteps) {
  5439. PurcInquiry.reply({itemId: item.id}, item, function () {
  5440. toaster.pop('info', '提示', '报价成功');
  5441. loadData();
  5442. }, function (response) {
  5443. toaster.pop('error', '报价失败', response.data);
  5444. });
  5445. }
  5446. };
  5447. // 采纳
  5448. $scope.accept = function (id) {
  5449. PurchaseInquiry.accept({id: id}, {}, function (data) {
  5450. if (data.success) {
  5451. toaster.pop('success', '提示', data.success);
  5452. loadData();
  5453. }
  5454. if (data.error) {
  5455. toaster.pop('error', '提示', data.error);
  5456. }
  5457. }, function (response) {
  5458. toaster.pop('error', '提示', response.data);
  5459. })
  5460. };
  5461. // 拒绝
  5462. $scope.refuse = function (id) {
  5463. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  5464. if (data.success) {
  5465. toaster.pop('success', '提示', data.success);
  5466. loadData();
  5467. }
  5468. if (data.error) {
  5469. toaster.pop('error', '提示', data.error);
  5470. }
  5471. }, function (response) {
  5472. toaster.pop('error', '提示', response.data);
  5473. })
  5474. }
  5475. }]);
  5476. // 模具询价管理
  5477. app.controller('SaleInquiryMouldCtrl', ['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', 'PurcInquiryMouldSql', 'CurrentRole', function ($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload, PurcInquiryMouldSql, CurrentRole) {
  5478. BaseService.scrollBackToTop();
  5479. // 获取当前用户是否为普通用户
  5480. CurrentRole.isUser({}, {}, function (data) {
  5481. $scope.isUser = data.isUser;
  5482. });
  5483. $scope.active = 'todo';
  5484. $scope.agreedText = '全部';
  5485. $scope.dateZoneText = '不限';
  5486. $scope.condition = {dateZone: 1};
  5487. /* 时间筛选初始化*/
  5488. var fromDate = new Date();
  5489. var toDate = new Date();
  5490. fromDate.setMonth(fromDate.getMonth() - 1);
  5491. fromDate.setHours(0, 0, 0, 0);
  5492. toDate.setHours(23, 59, 59, 999);
  5493. $scope.condition.dateFrom = fromDate;
  5494. $scope.condition.dateTo = toDate;
  5495. var inquiryMould_copy = {};
  5496. $scope.changeAgreed = function (agreed) {
  5497. $scope.condition.agreed = agreed;
  5498. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  5499. $scope.condition.$agreedOpen = false;
  5500. };
  5501. $scope.changeDateZone = function (zone) {
  5502. $scope.condition.dateZone = zone;
  5503. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5504. $scope.condition.$dateZoneOpen = false;
  5505. getDateCondition(zone, $scope.condition);
  5506. $scope.tableParams.page(1);
  5507. $scope.tableParams.reload();
  5508. };
  5509. $scope.setActive = function (state) {
  5510. if ($scope.active != state) {
  5511. $scope.active = state;
  5512. if ($scope.tableParams.page() == 1) {
  5513. $scope.tableParams.reload();
  5514. } else {
  5515. $scope.tableParams.page(1);
  5516. }
  5517. }
  5518. };
  5519. var getService = function () {
  5520. if ($scope.keyword) {
  5521. return PurcInquiryMould;
  5522. } else {
  5523. return PurcInquiryMouldSql;
  5524. }
  5525. };
  5526. $scope.tableParams = new ngTableParams({
  5527. page: 1,
  5528. count: 5
  5529. }, {
  5530. total: 0,
  5531. counts: [5, 10, 25, 50],
  5532. getData: function ($defer, params) {
  5533. $scope.loading = true;
  5534. var pageParams = params.url();
  5535. var realActive = {};
  5536. pageParams.searchFilter = {
  5537. keyword: $scope.keyword,
  5538. fromDate: getDateTime($scope.condition.dateFrom),
  5539. endDate: getDateTime($scope.condition.dateTo)
  5540. };
  5541. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  5542. $scope.loading = false;
  5543. // 用来验证价格修改
  5544. var mould = page.content;
  5545. inquiryMould_copy = angular.copy(mould);
  5546. if (page) {
  5547. params.total(page.totalElement);
  5548. $defer.resolve(page.content);
  5549. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词 $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5550. }
  5551. }, function (response) {
  5552. $scope.loading = false;
  5553. toaster.pop('error', '数据加载失败', response.data);
  5554. });
  5555. }
  5556. });
  5557. //获得各分类未阅读数量
  5558. var getUnreadCount = function () {
  5559. PurcInquiryMould.getUnreadCount(null, function(data){
  5560. $scope.unread = data;
  5561. });
  5562. };
  5563. getUnreadCount();
  5564. //设置单据已读
  5565. $scope.setOrdersRead = function (id) {
  5566. // 如果单据本身已读,则不发送请求修改数据
  5567. if (!$scope.isUnread(id)){
  5568. return;
  5569. }
  5570. var sourceId = [];
  5571. sourceId.push(id);
  5572. PurcInquiryMould.setRead({}, sourceId, function (message) {
  5573. // $scope.getUnreadIds();
  5574. getUnreadCount();
  5575. });
  5576. };
  5577. $scope.setOrdersReadByState = function () {
  5578. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  5579. return;
  5580. }
  5581. PurcInquiryMould.setReadByState({}, function () {
  5582. getUnreadIds();
  5583. getUnreadCount();
  5584. });
  5585. };
  5586. //获取未读单据id
  5587. var getUnreadIds = function (){
  5588. PurcInquiryMould.getUnreadIds({}, "", function (message) {
  5589. $scope.unreadCode = message.content;
  5590. });
  5591. };
  5592. getUnreadIds();
  5593. //判断单据是否未读
  5594. $scope.isUnread = function (id){
  5595. for (var i in $scope.unreadCode) {
  5596. if (id == $scope.unreadCode[i]) {
  5597. return true;
  5598. }
  5599. }
  5600. };
  5601. $scope.getMinDate = function (item) {
  5602. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  5603. };
  5604. $scope.replyPrices = [];
  5605. $scope.replyPrices.push(true);
  5606. // 取消
  5607. $scope.reload = function () {
  5608. $scope.tableParams.reload();
  5609. $scope.canSave = false;
  5610. }
  5611. // 能否保存设置
  5612. $scope.canSave = false;
  5613. // items价格验证
  5614. $scope.verifyItems = function (price, reply) {
  5615. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  5616. if (regex.test(price) && price != 0) {
  5617. if (price != reply) {
  5618. $scope.canSave = true;
  5619. } else {
  5620. $scope.canSave = false;
  5621. }
  5622. } else {
  5623. $scope.canSave = false;
  5624. }
  5625. }
  5626. // prod下prods价格验证
  5627. $scope.verifyProds = function (price, reply) {
  5628. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5629. if (regex.test(price) && price != 0) {
  5630. if (price != reply) {
  5631. $scope.canSave = true;
  5632. } else {
  5633. $scope.canSave = false;
  5634. }
  5635. } else {
  5636. $scope.canSave = false;
  5637. }
  5638. }
  5639. //有价格为0或者不符合正则式,则不能报价
  5640. $scope.notZero = function (mould) {
  5641. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5642. angular.forEach(mould.inquiryMouldItems, function (item) {
  5643. if (item.price == 0 || !regex.test(item.price)) {
  5644. $scope.canSave = false;
  5645. }
  5646. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5647. if (detail.price == 0 || !regex.test(detail.price)) {
  5648. $scope.canSave = false;
  5649. }
  5650. })
  5651. });
  5652. }
  5653. $scope.blurPrice = function (price) {
  5654. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5655. if (!regex.test(price)) {
  5656. toaster.pop('warning', '格式错误', '请输入有效价格');
  5657. }
  5658. }
  5659. // 获取历史报价
  5660. $scope.getHistory = function (mould) {
  5661. if (!mould.history) {
  5662. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  5663. $scope.historyShow = true;
  5664. mould.history = data;
  5665. },function (response) {
  5666. $scope.historyShow = false;
  5667. });
  5668. }
  5669. };
  5670. var uploadAttach = function (mould, file) {
  5671. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5672. $scope.mould = mould;
  5673. $upload.upload({
  5674. url: 'sale/mould/' + mould.id + '/send',
  5675. method: 'POST',
  5676. file: file,
  5677. data: {
  5678. json: $scope.mould
  5679. }
  5680. }).success(function (res) {
  5681. $scope.mould.sellAttachs.push(res);
  5682. }).error(function (res) {
  5683. });
  5684. }
  5685. $scope.pushFile = function(mould, file) {
  5686. // var file = $scope.myFiles;
  5687. if (file.length > 0) {
  5688. for (var i = 0; i < file.length; i++) {
  5689. console.log(file[i].name);
  5690. var flag = true;
  5691. if (mould.sellAttachs.length > 0) {
  5692. for (var j = 0; j < mould.sellAttachs.length; j++) {
  5693. if (mould.sellAttachs[j].name == file[i].name
  5694. && mould.sellAttachs[j].size == file[i].size) {
  5695. flag = false;
  5696. break;
  5697. }
  5698. }
  5699. }
  5700. if (flag) {
  5701. uploadAttach(mould, file[i]);
  5702. $scope.canSave = true;
  5703. }
  5704. }
  5705. }
  5706. document.getElementById("inquiryMould.sellAttachs").value = "";
  5707. };
  5708. $scope.removeFile = function(mould, file) {
  5709. $scope.inquiryMould = mould;
  5710. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5711. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5712. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5713. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5714. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5715. }
  5716. }
  5717. }
  5718. };
  5719. // 保存并确认报价
  5720. $scope.onReplyClick = function (mould, withSteps) {
  5721. $scope.loading = true;
  5722. if (withSteps) {
  5723. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5724. $scope.loading = false;
  5725. toaster.pop('info', '提示', '报价成功');
  5726. $scope.tableParams.reload();
  5727. $scope.canSave = false;
  5728. }, function (response) {
  5729. $scope.loading = false;
  5730. toaster.pop('error', '报价失败', response.data);
  5731. });
  5732. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5733. }, function (response) {
  5734. });
  5735. } else {
  5736. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5737. $scope.loading = false;
  5738. toaster.pop('info', '提示', '保存成功');
  5739. $scope.tableParams.reload();
  5740. }, function (response) {
  5741. $scope.loading = false;
  5742. toaster.pop('error', '保存失败', response.data);
  5743. });
  5744. }
  5745. };
  5746. // 搜索框回车
  5747. $scope.onSearch = function () {
  5748. $scope.tableParams.page(1);
  5749. $scope.tableParams.reload();
  5750. };
  5751. $scope.openDatePicker = function ($event, item, openParam) {
  5752. $event.preventDefault();
  5753. $event.stopPropagation();
  5754. item[openParam] = !item[openParam];
  5755. };
  5756. $scope.openFilterDatePicker = function ($event, item, openParam) {
  5757. $event.preventDefault();
  5758. $event.stopPropagation();
  5759. item[openParam] = !item[openParam];
  5760. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  5761. $scope.tableParams.reload();
  5762. }
  5763. };
  5764. $scope.parseDate = function (dateStr) {
  5765. if (dateStr)
  5766. return Date.parse(dateStr, 'yyyy-MM-dd');
  5767. return new Date();
  5768. };
  5769. // 导出客户资料列表
  5770. $scope.exportXls = function () {
  5771. PurcInquiryMould.exportXls({}, {}, function (data) {
  5772. if (data.success){
  5773. window.location.href = 'sale/mould/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  5774. }
  5775. }, function (response) {
  5776. toaster.pop('error', '数据加载失败', response.data);
  5777. });
  5778. }
  5779. }]);
  5780. // 模具询价单明细
  5781. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould', '$filter', 'toaster', '$upload', 'CurrentRole', function ($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload, CurrentRole) {
  5782. // 获取当前用户是否为普通用户
  5783. CurrentRole.isUser({}, {}, function (data) {
  5784. $scope.isUser = data.isUser;
  5785. });
  5786. var inquiryMould_copy = {};
  5787. var loadData = function () {
  5788. PurcInquiryMould.getAll({id: $stateParams.id}, function (data) {
  5789. // 用来验证价格修改
  5790. inquiryMould_copy = angular.copy(data);
  5791. $scope.inquiryMould_copy = inquiryMould_copy;
  5792. $scope.newinquirymould = data;
  5793. var mould = data;
  5794. angular.forEach(mould.attachs, function (attach) {
  5795. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5796. });
  5797. $scope.inquiryMould = mould;
  5798. }, function (response) {
  5799. toaster.pop('error', '数据加载失败', response.data);
  5800. });
  5801. };
  5802. loadData();
  5803. $scope.getMinDate = function (item) {
  5804. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5805. };
  5806. // 取消
  5807. $scope.reload = function () {
  5808. loadData();
  5809. $scope.canSave = false;
  5810. }
  5811. //有价格为0,则不能报价
  5812. $scope.notZero = function (mould) {
  5813. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5814. angular.forEach(mould.inquiryMouldItems, function (item) {
  5815. if (item.price == 0 || !regex.test(item.price)) {
  5816. $scope.canSave = false;
  5817. }
  5818. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5819. if (detail.price == 0 || !regex.test(detail.price)) {
  5820. $scope.canSave = false;
  5821. }
  5822. })
  5823. });
  5824. }
  5825. $scope.blurPrice = function (price) {
  5826. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5827. if (!regex.test(price)) {
  5828. toaster.pop('warning', '格式错误', '请输入有效价格');
  5829. }
  5830. }
  5831. // 获取历史报价
  5832. $scope.getHistory = function (mould) {
  5833. if (!mould.history) {
  5834. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  5835. $scope.historyShow = true;
  5836. mould.history = data;
  5837. },function (response) {
  5838. $scope.historyShow = false;
  5839. //toaster.pop('error', '提示', response.data);
  5840. });
  5841. }
  5842. };
  5843. $scope.canSave = false;
  5844. // items价格验证
  5845. $scope.verifyItems = function (price, index) {
  5846. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5847. if (regex.test(price) && price != 0) {
  5848. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  5849. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  5850. $scope.canSave = true;
  5851. } else {
  5852. $scope.canSave = false;
  5853. }
  5854. } else {
  5855. $scope.canSave = false;
  5856. }
  5857. }
  5858. // prod下prods价格验证
  5859. $scope.verifyProds = function (price, index, parentIndex) {
  5860. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5861. if (regex.test(price) && price != 0) {
  5862. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  5863. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  5864. $scope.canSave = true;
  5865. } else {
  5866. $scope.canSave = false;
  5867. }
  5868. } else {
  5869. $scope.canSave = false;
  5870. }
  5871. }
  5872. // 上传附件
  5873. var uploadAttach = function(file) {
  5874. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5875. $scope.mould = $scope.inquiryMould;
  5876. $upload.upload({
  5877. url: 'sale/mould/' + $scope.mould.id + '/send',
  5878. method: 'POST',
  5879. file: file,
  5880. data: {
  5881. json: $scope.mould
  5882. }
  5883. }).success(function(attach){
  5884. if (attach){
  5885. $scope.inquiryMould.sellAttachs.push(attach);
  5886. }
  5887. }).error(function(res){
  5888. console.log("failure");
  5889. console.log(res);
  5890. });
  5891. }
  5892. $scope.pushFile = function(file) {
  5893. // var file = $scope.myFiles;
  5894. if (file.length > 0) {
  5895. for (var i = 0; i < file.length; i++) {
  5896. console.log(file[i].name);
  5897. var flag = true;
  5898. if ($scope.inquiryMould.sellAttachs.length > 0) {
  5899. for (var j = 0; j < $scope.inquiryMould.sellAttachs.length; j++) {
  5900. if ($scope.inquiryMould.sellAttachs[j].name == file[i].name
  5901. && $scope.inquiryMould.sellAttachs[j].size == file[i].size) {
  5902. flag = false;
  5903. break;
  5904. }
  5905. }
  5906. }
  5907. if (flag) {
  5908. uploadAttach(file[i]);
  5909. }
  5910. }
  5911. }
  5912. };
  5913. $scope.removeFile = function(file) {
  5914. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5915. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5916. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5917. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5918. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5919. document.getElementById("file").value = "";
  5920. }
  5921. }
  5922. }
  5923. };
  5924. $scope.onReplyClick = function (mould, withSteps) {
  5925. $scope.loading = true;
  5926. if (withSteps) {
  5927. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5928. $scope.loading = false;
  5929. toaster.pop('info', '提示', '报价成功');
  5930. loadData();
  5931. $scope.canSave = false;
  5932. }, function (response) {
  5933. $scope.loading = false;
  5934. toaster.pop('error', '报价失败', response.data);
  5935. });
  5936. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5937. }, function (response) {
  5938. });
  5939. } else {
  5940. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5941. $scope.loading = false;
  5942. toaster.pop('info', '提示', '保存成功');
  5943. loadData();
  5944. }, function (response) {
  5945. $scope.loading = false;
  5946. toaster.pop('error', '保存失败', response.data);
  5947. });
  5948. }
  5949. };
  5950. }]);
  5951. // 主动报价 - 列表
  5952. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', 'QuotationInfo', 'CurrentRole', function ($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope, QuotationInfo, CurrentRole) {
  5953. BaseService.scrollBackToTop();
  5954. // 获取当前用户是否为普通用户
  5955. CurrentRole.isUser({}, {}, function (data) {
  5956. $scope.isUser = data.isUser;
  5957. });
  5958. $rootScope.enteryStatus = false;
  5959. $scope.active = 'todo';
  5960. $scope.agreedText = '全部';
  5961. $scope.dateZoneText = '一个月内';
  5962. $scope.condition = {dateZone: 1};
  5963. /* 时间筛选初始化*/
  5964. var fromDate = new Date();
  5965. var toDate = new Date();
  5966. fromDate.setMonth(fromDate.getMonth() - 1);
  5967. fromDate.setHours(0, 0, 0, 0);
  5968. toDate.setHours(23, 59, 59, 999);
  5969. $scope.condition.dateFrom = fromDate;
  5970. $scope.condition.dateTo = toDate;
  5971. $scope.changeDateZone = function (zone) {
  5972. $scope.condition.dateZone = zone;
  5973. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5974. $scope.condition.$dateZoneOpen = false;
  5975. getDateCondition(zone, $scope.condition);
  5976. $scope.tableParams.page(1);
  5977. $scope.tableParams.reload();
  5978. };
  5979. $scope.setActive = function (state) {
  5980. if ($scope.active != state) {
  5981. $scope.active = state;
  5982. if ($scope.tableParams.page() == 1)
  5983. $scope.tableParams.reload();
  5984. else
  5985. $scope.tableParams.page(1);
  5986. }
  5987. };
  5988. $scope.searchMethod = false;
  5989. var getService = function () {
  5990. return $scope.searchMethod ? Quotation : QuotationInfo;
  5991. };
  5992. $scope.tableParams = new ngTableParams({
  5993. page: 1,
  5994. count: 20,
  5995. sorting: {
  5996. 'date': 'desc'
  5997. }
  5998. }, {
  5999. total: 0,
  6000. counts: [5, 10, 25, 50],
  6001. getData: function ($defer, params) {
  6002. $scope.loading = true;
  6003. var pageParams = params.url();
  6004. pageParams.searchFilter = {
  6005. keyword: $scope.keyword,
  6006. fromDate: getDateTime($scope.condition.dateFrom),
  6007. endDate: getDateTime($scope.condition.dateTo)
  6008. };
  6009. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6010. $scope.loading = false;
  6011. if (page) {
  6012. params.total(page.totalElement);
  6013. $defer.resolve(page.content);
  6014. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6015. }
  6016. }, function (response) {
  6017. $scope.loading = false;
  6018. toaster.pop('error', '数据加载失败', response.data);
  6019. });
  6020. }
  6021. });
  6022. $scope.openDatePicker = function ($event, item, openParam) {
  6023. $event.preventDefault();
  6024. $event.stopPropagation();
  6025. item[openParam] = !item[openParam];
  6026. };
  6027. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6028. $event.preventDefault();
  6029. $event.stopPropagation();
  6030. item[openParam] = !item[openParam];
  6031. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6032. $scope.tableParams.reload();
  6033. }
  6034. };
  6035. $scope.getHistory = function (item) {
  6036. if (!item.history) {
  6037. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  6038. item.history = data;
  6039. });
  6040. }
  6041. };
  6042. $scope.isValid = function (item, withSteps) {
  6043. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  6044. if (!withSteps || !bool)
  6045. return bool;
  6046. angular.forEach(item.replies, function (r, i) {
  6047. bool = (i > 0 ? r.lapQty : 1) && r.price;
  6048. });
  6049. return bool;
  6050. };
  6051. // 搜索框回车
  6052. $scope.onSearch = function (keyword) {
  6053. // 每次搜索重置获取数据方法
  6054. $scope.searchMethod = false;
  6055. if(keyword != null && keyword != '') {
  6056. $scope.searchMethod = true;
  6057. }
  6058. $scope.tableParams.page(1);
  6059. $scope.tableParams.reload();
  6060. };
  6061. // 导出
  6062. $scope.exportXls = function () {
  6063. Quotation.exportXls({}, {}, function (data) {
  6064. if (data.success){
  6065. window.location.href = 'sale/quotation/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  6066. }
  6067. }, function (response) {
  6068. toaster.pop('error', '数据加载失败', response.data);
  6069. });
  6070. }
  6071. }]);
  6072. // Controller 主动报价 - 新增
  6073. app.controller('SaleQuotationNewCtrl', ['$scope', '$stateParams', '$filter', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'Quotation', 'VendorInfo', '$rootScope', 'CurrentRole', function ($scope, $stateParams, $filter, ngTableParams, toaster, BaseService, $modal, Quotation, VendorInfo, $rootScope, CurrentRole) {
  6074. BaseService.scrollBackToTop();
  6075. // 获取当前用户是否为普通用户
  6076. CurrentRole.isUser({}, {}, function (data) {
  6077. $scope.isUser = data.isUser;
  6078. });
  6079. var staticItem = null;
  6080. if (!angular.isUndefined($stateParams.id)) {// 查看模式
  6081. $scope.loading = true;
  6082. $rootScope.enteryStatus = true;
  6083. Quotation.getItem({id: $stateParams.id}, function (data) {
  6084. // data.$editing = false;
  6085. $scope.item = data;
  6086. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  6087. staticItem = angular.copy(data);
  6088. $scope.loading = false;
  6089. }, function (response) {
  6090. $scope.loading = false;
  6091. toaster.pop('error', '数据加载失败', response.data);
  6092. });
  6093. } else {// 新增模式
  6094. $rootScope.enteryStatus = false;
  6095. $scope.item = {
  6096. quotation: {
  6097. currency: 'RMB',
  6098. taxrate: 17,
  6099. },
  6100. product: {},
  6101. prices: [{lapQty: 0}],
  6102. minOrderQty: 1,
  6103. minPackQty: 1,
  6104. $endDateOpen: false,
  6105. $editing: true
  6106. };
  6107. }
  6108. $scope.getMinDate = function (item) {
  6109. return $filter('date')(new Date, 'yyyy-MM-dd');
  6110. };
  6111. //是否不能被点击
  6112. $scope.isDisabled = function () {
  6113. return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
  6114. }
  6115. $scope.openDatePicker = function ($event, openParam) {
  6116. $event.preventDefault();
  6117. $event.stopPropagation();
  6118. $scope.item.$endDateOpen = !openParam;
  6119. };
  6120. // 增加一个分段
  6121. $scope.addPrice = function () {
  6122. if ($scope.item.prices.length >= 10) {
  6123. toaster.pop('warning', '提示', '最多支持10个分段!');
  6124. } else
  6125. $scope.item.prices.push({});
  6126. };
  6127. // 删除一个分段
  6128. $scope.removePrice = function (index) {
  6129. $scope.item.prices.splice(index, 1);
  6130. };
  6131. // 查找客户
  6132. $scope.dbfindCust = function () {
  6133. if ($scope.item.$editing) {
  6134. var modalInstance = $modal.open({
  6135. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  6136. controller: 'DbfindCustCtrl',
  6137. size: 'lg',
  6138. resolve: {}
  6139. });
  6140. modalInstance.result.then(function (data) {
  6141. $scope.item.quotation.cust = data.myEnterprise;
  6142. $scope.item.quotation.custUser = data.myUser;
  6143. $scope.item.product = null;
  6144. }, function () {
  6145. });
  6146. }
  6147. };
  6148. // 赋值客户信息
  6149. if ($rootScope.custuu) {
  6150. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function (data) {
  6151. $scope.item.quotation.cust = data.myEnterprise;
  6152. $scope.item.quotation.custUser = data.myUser;
  6153. })
  6154. }
  6155. // 赋值物料信息
  6156. if ($rootScope.prodId) {
  6157. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  6158. $scope.item.product.code = data.code;
  6159. $scope.item.product.title = data.title;
  6160. $scope.item.product.spec = data.spec;
  6161. $scope.item.product.unit = data.unit;
  6162. $scope.item.product.id = data.id;
  6163. }, function (response) {
  6164. });
  6165. }
  6166. // 查找客户物料
  6167. $scope.dbfindCustProd = function () {
  6168. if ($scope.item.$editing) {
  6169. if ($scope.item.quotation.cust) {
  6170. var modalInstance = $modal.open({
  6171. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  6172. controller: 'DbfindCustProdCtrl',
  6173. size: 'lg',
  6174. resolve: {
  6175. custUU: function () {
  6176. return $scope.item.quotation.cust.uu
  6177. }
  6178. }
  6179. });
  6180. modalInstance.result.then(function (data) {
  6181. $scope.item.product = data;
  6182. }, function () {
  6183. });
  6184. } else {
  6185. toaster.pop('error', '错误', '请先选择客户');
  6186. }
  6187. }
  6188. };
  6189. // 根据传入的询价相关的信息封装成报价需要的信息
  6190. if ($stateParams.inquiryItem != null) {
  6191. var item = $stateParams.inquiryItem;
  6192. $scope.item.quotation.cust = item.inquiry.enterprise;
  6193. $scope.item.quotation.custUser = item.inquiry.recorderUser;
  6194. $scope.item.quotation.custUserUU = item.inquiry.recorderUU;
  6195. if (item.product == null || item.product.id == null) {
  6196. toaster.pop('info', '暂未匹配到物料信息,请手动选择');
  6197. } else {
  6198. $scope.item.product = item.product;
  6199. if (item.replies.length > 0) {
  6200. $scope.item.prices = item.replies;
  6201. angular.forEach($scope.item.prices, function(price) {
  6202. price.id = null;
  6203. });
  6204. }
  6205. $scope.item.quotation.taxrate = item.taxrate;
  6206. $scope.item.minPackQty = item.minPackQty;
  6207. $scope.item.minOrderQty = item.minOrderQty;
  6208. $scope.item.leadtime = item.leadtime;
  6209. $scope.item.quotation.currency = item.currency;
  6210. }
  6211. }
  6212. // 保存
  6213. $scope.save = function () {
  6214. var valid = true;
  6215. angular.forEach($scope.item.prices, function(price, $index) {
  6216. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6217. valid = false;
  6218. }
  6219. });
  6220. if (!valid) {
  6221. toaster.pop('info', '提示', '分段数量请保持递增!');
  6222. } else {
  6223. $scope.loading = true;
  6224. if (!$scope.item.quotation.code) //新增,设单号
  6225. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6226. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6227. if ($scope.item.quotation.custUserUU == null) {
  6228. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6229. }
  6230. $scope.item.productId = $scope.item.product.id;
  6231. Quotation.save({}, $scope.item, function (data) {
  6232. $scope.loading = false;
  6233. $scope.item = data;
  6234. toaster.pop('success', '成功', '保存成功');
  6235. if ($stateParams.id)
  6236. window.location.reload();
  6237. else
  6238. window.location.hash = '#/sale/quotation/list';
  6239. }, function (response) {
  6240. $scope.loading = false;
  6241. toaster.pop('error', '保存失败', response.data);
  6242. });
  6243. }
  6244. };
  6245. // 更新
  6246. $scope.update = function () {
  6247. $scope.item.$editing = true;
  6248. };
  6249. // 取消
  6250. $scope.cancel = function () {
  6251. $scope.item.$editing = false;
  6252. $scope.item = angular.copy(staticItem);
  6253. };
  6254. // 提交
  6255. $scope.submit = function () {
  6256. var valid = true;
  6257. angular.forEach($scope.item.prices, function(price, $index) {
  6258. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6259. valid = false;
  6260. }
  6261. });
  6262. if (!valid) {
  6263. toaster.pop('info', '提示', '分段数量请保持递增!');
  6264. } else {
  6265. $scope.loading = true;
  6266. if (!$scope.item.quotation.code) //新增,设单号
  6267. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6268. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6269. if ($scope.item.quotation.custUserUU == null) {
  6270. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6271. }
  6272. $scope.item.productId = $scope.item.product.id;
  6273. // $scope.item.quotation.status = 101;//已提交
  6274. if ($scope.item.quotation.date instanceof Date) {
  6275. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  6276. }
  6277. if ($scope.item.quotation.endDate instanceof Date) {
  6278. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  6279. }
  6280. Quotation.submit({}, $scope.item, function (data) {
  6281. $scope.loading = false;
  6282. $scope.item = data;
  6283. toaster.pop('success', '成功', '提交成功');
  6284. // window.location.hash = '#/sale/quotation/' + data.id;
  6285. window.location.hash = '#/sale/quotation/list';
  6286. }, function (response) {
  6287. $scope.loading = false;
  6288. toaster.pop('error', '保存失败', response.data);
  6289. });
  6290. }
  6291. };
  6292. $scope.deleteById = function (id) {
  6293. Quotation.deleteById({id: id}, {}, function (data) {
  6294. window.location.href = "#/sale/quotation/list";
  6295. }, function (response) {
  6296. toaster.pop('error', '提示', response.data);
  6297. })
  6298. }
  6299. }]);
  6300. // 查找客户
  6301. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function ($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance) {
  6302. BaseService.scrollBackToTop();
  6303. $scope.tableParams = new ngTableParams({
  6304. page: 1,
  6305. count: 20
  6306. }, {
  6307. total: 0,
  6308. counts: [5, 10, 25, 50],
  6309. getData: function ($defer, params) {
  6310. $scope.loading = true;
  6311. var pageParams = params.url();
  6312. pageParams.keyword = $scope.keyword;
  6313. Customer.get(BaseService.parseParams(pageParams), function (page) {
  6314. $scope.loading = false;
  6315. if (page) {
  6316. params.total(page.totalElement);
  6317. $defer.resolve(page.content);
  6318. }
  6319. $scope.totalCount = page.totalElement;
  6320. }, function (response) {
  6321. $scope.loading = false;
  6322. toaster.pop('error', '数据加载失败', response.data);
  6323. });
  6324. }
  6325. });
  6326. $scope.onSearch = function () {
  6327. $scope.tableParams.page(1);
  6328. $scope.tableParams.reload();
  6329. };
  6330. $scope.cancel = function () {
  6331. $modalInstance.dismiss();
  6332. };
  6333. $scope.check = function (cust) {
  6334. $modalInstance.close(cust);
  6335. };
  6336. }]);
  6337. // 查找客户物料
  6338. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function ($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU) {
  6339. BaseService.scrollBackToTop();
  6340. $scope.tableParams = new ngTableParams({
  6341. page: 1,
  6342. count: 20
  6343. }, {
  6344. total: 0,
  6345. counts: [5, 10, 25, 50],
  6346. getData: function ($defer, params) {
  6347. $scope.loading = true;
  6348. var pageParams = params.url();
  6349. pageParams.keyword = $scope.keyword;
  6350. pageParams.custUU = custUU;
  6351. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  6352. $scope.loading = false;
  6353. if (page) {
  6354. params.total(page.totalElement);
  6355. $defer.resolve(page.content);
  6356. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6357. }
  6358. }, function (response) {
  6359. $scope.loading = false;
  6360. toaster.pop('error', '数据加载失败', response.data);
  6361. });
  6362. }
  6363. });
  6364. // 取消
  6365. $scope.cancel = function () {
  6366. $modalInstance.dismiss();
  6367. };
  6368. // 选择
  6369. $scope.check = function (cust) {
  6370. $modalInstance.close(cust);
  6371. };
  6372. // 搜索框回车
  6373. $scope.onSearch = function () {
  6374. $scope.tableParams.page(1);
  6375. $scope.tableParams.reload();
  6376. };
  6377. }]);
  6378. // 查找供应商
  6379. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', '$rootScope', function ($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope) {
  6380. BaseService.scrollBackToTop();
  6381. // 搜索框回车
  6382. $scope.onSearch = function (keyword) {
  6383. $scope.keyword = keyword;
  6384. $scope.tableParams.page(1);
  6385. $scope.tableParams.reload();
  6386. };
  6387. $scope.tableParams = new ngTableParams({
  6388. page: 1,
  6389. count: 20
  6390. }, {
  6391. total: 0,
  6392. counts: [10, 25, 50, 100],
  6393. getData: function ($defer, params) {
  6394. $scope.loading = true;
  6395. var pageParams = params.url();
  6396. pageParams.keyword = $scope.keyword;
  6397. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  6398. $scope.loading = false;
  6399. if (page) {
  6400. params.total(page.totalElement);
  6401. $defer.resolve(page.content);
  6402. // 添加供应商时,将已存在的选中
  6403. if ($rootScope.tenderVendor) {
  6404. angular.forEach(page.content, function (vendor) {
  6405. for (var i = 0; i < $rootScope.tenderVendor.length; i++) {
  6406. vendor.checked = false;
  6407. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  6408. vendor.checked = true;
  6409. break;
  6410. }
  6411. }
  6412. });
  6413. }
  6414. }
  6415. $scope.totalCount = page.totalElement;
  6416. }, function (response) {
  6417. $scope.loading = false;
  6418. toaster.pop('error', '数据加载失败', response.data);
  6419. });
  6420. }
  6421. });
  6422. $scope.cancel = function () {
  6423. $modalInstance.dismiss();
  6424. };
  6425. $scope.checks = {
  6426. checked: false
  6427. };// 全选框
  6428. $scope.checkAll = function () {
  6429. angular.forEach($scope.tableParams.data, function (vendor) {
  6430. vendor.checked = $scope.checks.checked;
  6431. });
  6432. };
  6433. // 单选
  6434. $scope.checkOne = function (vendor) {
  6435. vendor.checked = true;
  6436. var checked = true;
  6437. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  6438. if (!message.checked) {
  6439. checked = false;
  6440. }
  6441. });
  6442. $scope.checks.checked = checked;
  6443. };
  6444. // 单反选
  6445. $scope.unCheckOne = function (vendor) {
  6446. vendor.checked = false;
  6447. $scope.checks.checked = false;
  6448. };
  6449. $scope.close = function () {
  6450. var vendors = [];
  6451. angular.forEach($scope.tableParams.data, function (vendor) {
  6452. if (vendor.checked) {
  6453. vendors.push(vendor);
  6454. $modalInstance.close(vendors);
  6455. }
  6456. });
  6457. };
  6458. }]);
  6459. // 发货提醒
  6460. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'SaleTruck', 'Symbol', '$state', '$timeout', 'PurcNoticeInfo', 'token', 'CurrentRole', function ($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, $modal, SaleTruck, Symbol, $state, $timeout, PurcNoticeInfo, token, CurrentRole) {
  6461. BaseService.scrollBackToTop();
  6462. // 获取当前用户是否为普通用户
  6463. CurrentRole.isUser({}, {}, function (data) {
  6464. $scope.isUser = data.isUser;
  6465. });
  6466. // 用来记录已经选择的id
  6467. $rootScope.ids = [];
  6468. $scope.active = 'todo';
  6469. $scope.currency = Symbol.currency;
  6470. $scope.dateZoneText = '不限';
  6471. $scope.condition = {dateZone: 6};
  6472. $scope.searchStatus = false;
  6473. /* 时间筛选初始化*/
  6474. var fromDate = new Date();
  6475. var toDate = new Date();
  6476. fromDate.setMonth(fromDate.getMonth() - 6);
  6477. fromDate.setHours(0, 0, 0, 0);
  6478. toDate.setHours(23, 59, 59, 999);
  6479. $scope.condition.dateFrom = fromDate;
  6480. $scope.condition.dateTo = toDate;
  6481. $scope.changeDateZone = function (zone) {
  6482. $scope.condition.dateZone = zone;
  6483. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6484. $scope.condition.$dateZoneOpen = false;
  6485. getDateCondition(zone, $scope.condition);
  6486. $scope.tableParams.page(1);
  6487. $scope.tableParams.reload();
  6488. };
  6489. $scope.setActive = function (state) {
  6490. if ($scope.active != state) {
  6491. $scope.active = state;
  6492. if ($scope.tableParams.page() == 1)
  6493. $scope.tableParams.reload();
  6494. else
  6495. $scope.tableParams.page(1);
  6496. }
  6497. };
  6498. var getService = function () {
  6499. if ($scope.searchStatus) {
  6500. return PurcNotice;
  6501. }
  6502. return PurcNoticeInfo;
  6503. };
  6504. $scope.tableParams = new ngTableParams({
  6505. page: 1,
  6506. count: 20,
  6507. sorting: {
  6508. 'id': 'desc'
  6509. }
  6510. }, {
  6511. total: 0,
  6512. counts: [5, 10, 25, 50],
  6513. getData: function ($defer, params) {
  6514. $scope.loading = true;
  6515. var pageParams = params.url();
  6516. pageParams.keyword = $scope.keyword;
  6517. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6518. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6519. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6520. $scope.loading = false;
  6521. if (page) {
  6522. params.total(page.totalElement);
  6523. $defer.resolve(page.content);
  6524. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6525. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6526. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6527. $scope.checkall = true;
  6528. angular.forEach(page.content, function (notice) {
  6529. if ($rootScope.ids.indexOf(notice.id) > -1) {
  6530. notice.$selected = true;
  6531. } else {
  6532. $scope.checkall = false;
  6533. }
  6534. });
  6535. $scope.checkboxes = {
  6536. checked: $scope.checkall
  6537. };
  6538. }
  6539. }, function (response) {
  6540. $scope.loading = false;
  6541. toaster.pop('error', '数据加载失败', response.data);
  6542. });
  6543. }
  6544. });
  6545. //获得各分类未阅读数量
  6546. var getUnreadCount = function () {
  6547. PurcNotice.getUnreadCount(null, function (data) {
  6548. $scope.unread = data;
  6549. });
  6550. };
  6551. getUnreadCount();
  6552. //设置单据已读
  6553. $scope.setOrdersRead = function (id) {
  6554. // 如果单据本身已读,则不发送请求修改数据
  6555. if (!$scope.isUnread(id)){
  6556. return;
  6557. }
  6558. var sourceId = [];
  6559. sourceId.push(id);
  6560. PurcNotice.setRead({}, sourceId, function (message) {
  6561. // $scope.getUnreadIds();
  6562. getUnreadCount();
  6563. });
  6564. };
  6565. $scope.setOrdersReadByState = function () {
  6566. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  6567. return;
  6568. }
  6569. PurcNotice.setReadByState({}, function () {
  6570. getUnreadIds();
  6571. getUnreadCount();
  6572. });
  6573. };
  6574. var getUnreadIds = function () {
  6575. PurcNotice.getUnreadIds({}, "", function (message) {
  6576. $scope.unreadCode = message.content;
  6577. });
  6578. };
  6579. getUnreadIds();
  6580. $scope.isUnread = function (id) {
  6581. for (var i in $scope.unreadCode) {
  6582. if (id == $scope.unreadCode[i]) {
  6583. return true;
  6584. }
  6585. }
  6586. };
  6587. $scope.openDatePicker = function ($event, item, openParam) {
  6588. $event.preventDefault();
  6589. $event.stopPropagation();
  6590. item[openParam] = !item[openParam];
  6591. };
  6592. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6593. $event.preventDefault();
  6594. $event.stopPropagation();
  6595. item[openParam] = !item[openParam];
  6596. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6597. $scope.tableParams.reload();
  6598. }
  6599. };
  6600. //生成随机单号
  6601. $scope.autoCode = function (notice) {
  6602. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  6603. };
  6604. // 获取token信息 并打开询价模态框
  6605. $scope.getToken = function() {
  6606. token.info({userType: 'salenotice'}, {}, function(data) {
  6607. $scope.token = data.token;
  6608. }, function(response) {
  6609. toaster.pop('error', '提示', response.data);
  6610. });
  6611. }
  6612. //可送货日期
  6613. $scope.sendDate = function (notice) {
  6614. var stock = notice.orderItem.product.ltinstock || 0;
  6615. var de = new Date(notice.delivery);
  6616. if (stock == -1) {
  6617. de.setMonth(de.getMonth() - 1);
  6618. de.setDate(26);
  6619. } else if (stock >= 0) {
  6620. de.setDate(de.getDate() - stock - 1);
  6621. }
  6622. return de;
  6623. };
  6624. $scope.lockstatus = false;
  6625. // 锁定时间按钮5秒
  6626. $scope.lockClick = function (notice) {
  6627. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6628. } else if (!notice.send.code) {
  6629. } else {
  6630. $scope.lockstatus = true;
  6631. $timeout(function () {
  6632. $scope.lockstatus = false;
  6633. }, 5000);
  6634. }
  6635. };
  6636. var isSumbit = false;
  6637. $scope.onReplyClick = function (notice) {
  6638. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6639. toaster.pop('warning', '警告', '数量填写错误!');
  6640. } else if (!notice.send.code) {
  6641. toaster.pop('warning', '警告', '请填写发货单号!');
  6642. } else {
  6643. if (!isSumbit) {
  6644. var send = {
  6645. code: notice.send.code,
  6646. remark: notice.send.remark,
  6647. sendItems: [{qty: notice.send.qty}]
  6648. };
  6649. $scope.loading = true;
  6650. PurcNotice.save({id: notice.id, token: $scope.token}, send, function (data) {
  6651. $scope.loading = false;
  6652. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  6653. $state.go('sale.send_detail', {id: data.id});
  6654. }, function (response) {
  6655. $scope.loading = false;
  6656. toaster.pop('error', '发货失败', response.data);
  6657. });
  6658. isSumbit = true;
  6659. return true;
  6660. } else {
  6661. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6662. return false;
  6663. }
  6664. }
  6665. }
  6666. $scope.checkboxes = {
  6667. checked: false
  6668. };
  6669. angular.forEach($scope.tableParams.data, function (item) {
  6670. $scope.checkboxes.checked = false;
  6671. if($rootScope.ids.in_array(item.id)) {
  6672. $rootScope.ids.remove(item.id);
  6673. $scope.checkboxes.checked = true;
  6674. }
  6675. });
  6676. // 点击勾选全部的复选框
  6677. $scope.checkAll = function () {
  6678. angular.forEach($scope.tableParams.data, function (item) {
  6679. if (!item.waiting) {
  6680. item.$selected = $scope.checkboxes.checked;
  6681. if(item.$selected) {
  6682. if(!$rootScope.ids.in_array(item.id)) {
  6683. $rootScope.ids.push(item.id);
  6684. }
  6685. } else {
  6686. if($rootScope.ids.in_array(item.id)) {
  6687. $rootScope.ids.remove(item.id);
  6688. }
  6689. }
  6690. }
  6691. });
  6692. };
  6693. // 判断数组中是否存在某个对象
  6694. Array.prototype.S = String.fromCharCode(2);
  6695. Array.prototype.in_array = function(e) {
  6696. var r = new RegExp(this.S + e + this.S);
  6697. return (r.test(this.S + this.join(this.S) + this.S));
  6698. }
  6699. // 从数组中移除某个对象
  6700. Array.prototype.remove = function(val) {
  6701. var index = this.indexOf(val);
  6702. if (index > -1) {
  6703. this.splice(index, 1);
  6704. }
  6705. };
  6706. // 点击其中一个明细的复选框
  6707. $scope.checkOne = function (order) {
  6708. var result = true;
  6709. angular.forEach($scope.tableParams.data, function (item) {
  6710. if (item.$selected != true) {
  6711. result = false;
  6712. return;
  6713. }
  6714. });
  6715. if(order.$selected) {
  6716. if(!$rootScope.ids.in_array(order.id)) {
  6717. $rootScope.ids.push(order.id);
  6718. }
  6719. } else {
  6720. if($rootScope.ids.in_array(order.id)) {
  6721. $rootScope.ids.remove(order.id);
  6722. }
  6723. }
  6724. $scope.checkboxes = {
  6725. checked: result
  6726. };
  6727. };
  6728. // 打开批量发货模态框
  6729. var sendByBatch = function() {
  6730. var modalInstance = $modal.open({
  6731. animation: true,
  6732. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  6733. controller: 'SaleNoticeSendByBatchCtrl',
  6734. size: 'lg',
  6735. resolve: {
  6736. selectedNotices: function () {
  6737. return $scope.tableParams.data;
  6738. },
  6739. token: function() {
  6740. return $scope.token;
  6741. },
  6742. ids: function() {
  6743. return $rootScope.ids;
  6744. }
  6745. }
  6746. });
  6747. modalInstance.result.then(function () {
  6748. $scope.tableParams.reload();
  6749. }, function () {
  6750. });
  6751. }
  6752. $scope.sendByBatch = function () {
  6753. if($scope.token == null) {
  6754. token.info({userType: 'salenotice'}, {}, function(data) {
  6755. $scope.token = data.token;
  6756. sendByBatch();
  6757. }, function(response) {
  6758. toaster.pop('error', '提示', response.data);
  6759. });
  6760. } else {
  6761. sendByBatch();
  6762. }
  6763. };
  6764. $scope.getSends = function (notice) {
  6765. if (!notice.sends && notice.endQty > 0) {
  6766. notice.getSendsing = true;
  6767. notice.getSendsError = false;
  6768. PurcNotice.getSends({id: notice.id}, function (data) {
  6769. notice.getSendsing = false;
  6770. notice.getSendsError = false;
  6771. notice.sends = data;
  6772. }, function (response) {
  6773. notice.getSendsing = false;
  6774. notice.getSendsError = true;
  6775. notice.getErrorMessage = response.data;
  6776. });
  6777. }
  6778. };
  6779. // 搜索框回车
  6780. $scope.onSearch = function () {
  6781. $scope.searchStatus = true;
  6782. $scope.tableParams.page(1);
  6783. $scope.tableParams.reload();
  6784. };
  6785. // 选择查找日期
  6786. $scope.onDateCondition = function () {
  6787. $scope.tableParams.page(1);
  6788. $scope.tableParams.reload();
  6789. };
  6790. //货车功能
  6791. var truck = $rootScope.truck;
  6792. if (!truck) {
  6793. SaleTruck.query({}, function (data) {
  6794. $rootScope.truck = data;
  6795. });
  6796. }
  6797. $scope.isInTruck = function (noticeId) {
  6798. return truck.indexOf(noticeId) > -1;
  6799. };
  6800. $scope.addtoTruck = function (notice) {
  6801. SaleTruck.save({noticeId: notice.id}, {}, function (data) {
  6802. $rootScope.truck = data;
  6803. });
  6804. };
  6805. $scope.delFromTruck = function (notice) {
  6806. SaleTruck.remove({noticeId: notice.id}, {}, function (data) {
  6807. $rootScope.truck = data;
  6808. });
  6809. };
  6810. $scope.$watch(function () {
  6811. return $rootScope.truck;
  6812. }, function (data) {
  6813. truck = $rootScope.truck;
  6814. }, true);
  6815. $scope.$watch(function () {
  6816. return $rootScope.dataChanged;
  6817. }, function (data) {
  6818. data && ($scope.tableParams.reload());
  6819. }, true);
  6820. // 导出
  6821. $scope.exportXls = function () {
  6822. PurcNotice.exportXls({}, {}, function (data) {
  6823. if (data.success){
  6824. window.location.href = 'sale/notice/xls?_state='+$scope.active+
  6825. '&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  6826. }
  6827. }, function (response) {
  6828. toaster.pop('error', '数据加载失败', response.data);
  6829. });
  6830. }
  6831. }]);
  6832. app.controller('SaleNoticeSendByBatchCtrl', ['$scope', '$modalInstance', 'Symbol', 'selectedNotices', 'PurcNotice', 'toaster', '$state', '$timeout', 'token', 'ids', '$rootScope', function ($scope, $modalInstance, Symbol, selectedNotices, PurcNotice, toaster, $state, $timeout, token, ids, $rootScope) {
  6833. // $scope.notices = angular.copy(selectedNotices);
  6834. PurcNotice.findByIds({ids : angular.toJson(ids)}, function(data) {
  6835. $scope.notices = angular.copy(data);
  6836. }, function(res) {
  6837. toaster.pop('error', '提示', '发货提醒查询失败');
  6838. });
  6839. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6840. $scope.saleSend = {
  6841. code: '',
  6842. payments: '',
  6843. currency: '',
  6844. custUU: null,
  6845. custUserUU: null,
  6846. remark: '批量发货',
  6847. sendItems: []
  6848. };
  6849. // 计算总数、总额
  6850. $scope.$watch(function () {
  6851. return $scope.notices;
  6852. }, function (data) {
  6853. var q = 0, t = 0;
  6854. if (data) {
  6855. angular.forEach(data, function (d) {
  6856. q += (d.thisSendQty || 0);
  6857. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  6858. });
  6859. }
  6860. $scope.totalQty = q;
  6861. $scope.total = t;
  6862. }, true);
  6863. /**
  6864. * 删除一个已选中的送货提醒
  6865. */
  6866. $scope.removeOne = function (index) {
  6867. $scope.notices.splice(index, 1);
  6868. };
  6869. $scope.lockstatus = false;
  6870. // 锁定时间按钮5秒
  6871. $scope.lockClick = function () {
  6872. $scope.lockstatus = true;
  6873. $timeout(function () {
  6874. $scope.lockstatus = false;
  6875. }, 5000);
  6876. }
  6877. $scope.lockstatus = false;
  6878. // 锁定时间按钮5秒
  6879. $scope.lockClick = function (notice) {
  6880. if ($scope.saleSend.code == '') {//送货单号为空
  6881. return;
  6882. } else {
  6883. $scope.lockstatus = true;
  6884. $timeout(function () {
  6885. $scope.lockstatus = false;
  6886. }, 5000);
  6887. }
  6888. };
  6889. var isSumbit = false;
  6890. //确认送货
  6891. $scope.sendByBatch = function () {
  6892. $scope.saleSend.sendItems = [];
  6893. if ($scope.saleSend.code == '') {//送货单号为空
  6894. toaster.pop('error', '错误', '请输入送货单号');
  6895. return;
  6896. }
  6897. var a = 0;
  6898. var num = 1;
  6899. var valid = true;
  6900. angular.forEach($scope.notices, function (item, key) {
  6901. if (a == 0) {//第一次
  6902. $scope.saleSend.currency = item.orderItem.order.currency;
  6903. $scope.saleSend.custUU = item.enUU;
  6904. $scope.saleSend.payments = item.orderItem.order.payments;
  6905. a = 1;
  6906. } else {//其他
  6907. if ($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  6908. if ($scope.saleSend.custUU != item.enUU) valid = false;
  6909. if ($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  6910. }
  6911. $scope.saleSend.sendItems.push({
  6912. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++
  6913. });
  6914. });
  6915. if (!valid) {
  6916. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  6917. } else {
  6918. if (!isSumbit) {
  6919. PurcNotice.sendByBatch({token: token}, $scope.saleSend, function (data) {
  6920. if(data.id) {
  6921. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  6922. $modalInstance.close('success');
  6923. $state.go('sale.send_detail', {id: data.id});
  6924. } else {
  6925. toaster.pop('error', '提示', '发货失败,请刷新页面重试');
  6926. }
  6927. }, function (response) {
  6928. toaster.pop('error', '错误', response.data);
  6929. });
  6930. isSumbit = true;
  6931. return true;
  6932. } else {
  6933. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6934. return false;
  6935. }
  6936. }
  6937. };
  6938. $scope.cancel = function () {
  6939. $modalInstance.dismiss();
  6940. };
  6941. }]);
  6942. /**
  6943. * 发货单
  6944. */
  6945. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'ReportService', function ($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService) {
  6946. BaseService.scrollBackToTop();
  6947. $scope.active = 'all';
  6948. $scope.currency = Symbol.currency;
  6949. $scope.dateZoneText = '不限';
  6950. $scope.condition = {dateZone: 1};
  6951. /* 时间筛选初始化*/
  6952. var fromDate = new Date();
  6953. var toDate = new Date();
  6954. fromDate.setMonth(fromDate.getMonth() - 1);
  6955. fromDate.setHours(0, 0, 0, 0);
  6956. toDate.setHours(23, 59, 59, 999);
  6957. $scope.condition.dateFrom = fromDate;
  6958. $scope.condition.dateTo = toDate;
  6959. $scope.changeDateZone = function (zone) {
  6960. $scope.condition.dateZone = zone;
  6961. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6962. $scope.condition.$dateZoneOpen = false;
  6963. getDateCondition(zone, $scope.condition);
  6964. $scope.tableParams.page(1);
  6965. $scope.tableParams.reload();
  6966. };
  6967. $scope.setActive = function (state) {
  6968. if ($scope.active != state) {
  6969. $scope.active = state;
  6970. if ($scope.tableParams.page() == 1)
  6971. $scope.tableParams.reload();
  6972. else
  6973. $scope.tableParams.page(1);
  6974. }
  6975. };
  6976. var getService = function () {
  6977. return SaleSend;
  6978. };
  6979. $scope.tableParams = new ngTableParams({
  6980. page: 1,
  6981. count: 20,
  6982. sorting: {
  6983. date: 'desc'
  6984. }
  6985. }, {
  6986. total: 0,
  6987. counts: [5, 10, 25, 50],
  6988. getData: function ($defer, params) {
  6989. $scope.loading = true;
  6990. var pageParams = params.url();
  6991. pageParams.keyword = $scope.keyword;
  6992. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6993. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6994. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6995. $scope.loading = false;
  6996. if (page) {
  6997. params.total(page.totalElement);
  6998. $defer.resolve(page.content);
  6999. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7000. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7001. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7002. }
  7003. }, function (response) {
  7004. $scope.loading = false;
  7005. toaster.pop('error', '数据加载失败', response.data);
  7006. });
  7007. }
  7008. });
  7009. //打印 发货单
  7010. $scope.print = function (send) {
  7011. var newPage = window.open("about:blank");
  7012. SaleSend.printPermission({}, function () {
  7013. SaleSend.printCount({id: send.id}, {}); //增加打印此次
  7014. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id, newPage);
  7015. $scope.tableParams.reload();
  7016. }, function (response) {
  7017. newPage.close();
  7018. toaster.pop('error', '打印失败', response.data);
  7019. });
  7020. };
  7021. $scope.openDatePicker = function ($event, item, openParam) {
  7022. $event.preventDefault();
  7023. $event.stopPropagation();
  7024. item[openParam] = !item[openParam];
  7025. };
  7026. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7027. $event.preventDefault();
  7028. $event.stopPropagation();
  7029. item[openParam] = !item[openParam];
  7030. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7031. $scope.tableParams.reload();
  7032. }
  7033. };
  7034. // 搜索框回车
  7035. $scope.onSearch = function () {
  7036. $scope.tableParams.page(1);
  7037. $scope.tableParams.reload();
  7038. };
  7039. // 选择查找日期
  7040. $scope.onDateCondition = function () {
  7041. $scope.tableParams.page(1);
  7042. $scope.tableParams.reload();
  7043. };
  7044. $scope.exportXls = function () {
  7045. SaleSend.exportXls({}, {}, function (data) {
  7046. if (data.success){
  7047. window.location.href = 'sale/notice/sends/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7048. }
  7049. }, function (response) {
  7050. toaster.pop('error', '数据加载失败', response.data);
  7051. });
  7052. }
  7053. }]);
  7054. /**
  7055. * 发货单(包括发货条码维护)
  7056. */
  7057. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService', 'ngTableParams', 'Lodop', '$modal', 'CurrentRole', function ($scope, $stateParams, SaleSend, toaster, ReportService, ngTableParams, Lodop, $modal, CurrentRole) {
  7058. // 获取当前用户是否为普通用户
  7059. CurrentRole.isUser({}, {}, function (data) {
  7060. $scope.isUser = data.isUser;
  7061. });
  7062. var loading = true;
  7063. $scope.checkBarCode = [];
  7064. $scope.checkBoxCode = [];
  7065. var vm = $scope.vm = {};
  7066. $scope.getCheckedItems = {};
  7067. vm.editBar = false;
  7068. vm.showBarCode = [];
  7069. $scope.barCode = function () {
  7070. vm.editBar = !vm.editBar;
  7071. }
  7072. $scope.checkboxes = {
  7073. checked: false
  7074. };
  7075. $scope.checkbars = {
  7076. checked: false
  7077. };
  7078. // 点击勾选barCode全部的复选框
  7079. $scope.checkBarAll = function () {
  7080. angular.forEach($scope.checkBarCode, function (item, key) {
  7081. $scope.checkBarCode[key] = $scope.checkbars.checked;
  7082. });
  7083. };
  7084. //点击barCode单选
  7085. $scope.checkBarOne = function () {
  7086. var result = true;
  7087. angular.forEach($scope.checkBarCode, function (item, key) {
  7088. if (item != true) {
  7089. result = false;
  7090. return;
  7091. }
  7092. });
  7093. $scope.checkbars.checked = result;
  7094. }
  7095. // 点击boxCode全部的复选框
  7096. $scope.checkBoxAll = function () {
  7097. angular.forEach($scope.checkBoxCode, function (item, key) {
  7098. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  7099. });
  7100. };
  7101. //点击boxCode单选
  7102. $scope.checkBoxOne = function () {
  7103. var result = true;
  7104. angular.forEach($scope.checkBoxCode, function (item) {
  7105. if (item != true) {
  7106. result = false;
  7107. return;
  7108. }
  7109. });
  7110. $scope.checkboxes.checked = result;
  7111. }
  7112. /**
  7113. * 生成条码和箱号
  7114. */
  7115. $scope.generateBarCode = function (item) {
  7116. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  7117. $scope.getCheckedItems = [];
  7118. var warningdata = '';
  7119. angular.forEach($scope.checkBarCode, function (item, key) {
  7120. $scope.getCheckedItem = {};
  7121. if (item == true) {
  7122. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7123. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  7124. $scope.getCheckedItems.push($scope.getCheckedItem);
  7125. //判断是否生成过条码
  7126. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7127. warningdata += $scope.order.sendItems[key].number + ","
  7128. }
  7129. }
  7130. });
  7131. if ($scope.getCheckedItems.length == 0) {
  7132. toaster.pop('warning', '提示', '请勾选需要生成条码的明细行!');
  7133. return;
  7134. }
  7135. if (warningdata != '') {
  7136. if (!confirm('明细行序号:' + warningdata + "已经生成了条码,继续生成将清空原有条码?")) {
  7137. return;
  7138. }
  7139. }
  7140. SaleSend.generateBarcodes({id: $scope.order.id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7141. toaster.pop('success', '提示', '生成成功!');
  7142. loadData();
  7143. }, function (response) {
  7144. $scope.loading = false;
  7145. toaster.pop('error', '生成失败', response.data);
  7146. });
  7147. }
  7148. /**
  7149. * 打印条码和箱号
  7150. */
  7151. $scope.printCode = function (type) {
  7152. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7153. //勾选需要打印的行
  7154. $scope.getCheckedItems = [];
  7155. var warningdata = ''
  7156. angular.forEach($scope.checkBarCode, function (item, key) {
  7157. $scope.getCheckedItem = {};
  7158. if (item == true) {
  7159. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7160. $scope.getCheckedItems.push($scope.getCheckedItem);
  7161. //判断是否生成过条码
  7162. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7163. warningdata += $scope.order.sendItems[key].number + ","
  7164. }
  7165. }
  7166. });
  7167. if ($scope.getCheckedItems.length == 0) {
  7168. toaster.pop('warning', '提示', '请勾选需要打印的明细行!');
  7169. return;
  7170. }
  7171. if (warningdata == '') {
  7172. toaster.pop('warning', '提示', '明细行序号:' + warningdata + '未生成条码无法打印');
  7173. return;
  7174. }
  7175. //选择打印模板
  7176. var modalInstance = $modal.open({
  7177. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7178. controller: 'BarPrintModalCtrl',
  7179. resolve: {
  7180. typeItem: function () {
  7181. return {'type': type, 'id': $scope.order.id};
  7182. }
  7183. }
  7184. });
  7185. modalInstance.result.then(function (s) {
  7186. if (s) {
  7187. //获取打印数据
  7188. SaleSend.getPrintBarcodes({lpsId: s.tp_id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7189. if (s.type == 'print') {//判断选择是打印还是打印预览
  7190. lodopPrint(data.message, LODOP, type);
  7191. } else if (s.type == 'printPreview') {
  7192. lodopPrintPreview(data.message, LODOP, type);
  7193. }
  7194. }, function (response) {
  7195. toaster.pop('error', '获取打印数据失败', response.data);
  7196. });
  7197. }
  7198. });
  7199. };
  7200. //打印单个条码
  7201. $scope.printSingleCode = function (id) {
  7202. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7203. //选择打印模板
  7204. var modalInstance = $modal.open({
  7205. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7206. controller: 'BarPrintModalCtrl',
  7207. resolve: {
  7208. typeItem: function () {
  7209. return {'type': 'Bar', 'id': $scope.order.id};
  7210. }
  7211. }
  7212. });
  7213. modalInstance.result.then(function (s) {
  7214. if (s) {
  7215. //获取打印数据
  7216. SaleSend.getSPrintBarcode({lpsId: s.tp_id, bsnId: id}, function (data) {
  7217. if (s.type == 'print') {//判断选择是打印还是打印预览
  7218. lodopSPrint(data.message, LODOP);
  7219. } else if (s.type == 'printPreview') {
  7220. lodopSPrintPreview(data.message, LODOP);
  7221. }
  7222. }, function (response) {
  7223. toaster.pop('error', '获取打印数据失败', response.data);
  7224. });
  7225. }
  7226. });
  7227. }
  7228. var lodopSPrint = function (printStore, LODOP) {//单个条码打印
  7229. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7230. if (selectOrNot != -1) {
  7231. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7232. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7233. var strs = pagesize.split("*"); //字符分割
  7234. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7235. angular.forEach(printStore, function (data, index) {
  7236. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7237. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7238. if (data['LP_VALUETYPE'] == 'barcode') {
  7239. 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']);
  7240. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7241. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7242. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7243. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7244. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7245. } else if (data['LP_VALUETYPE'] == 'text') {
  7246. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7247. }
  7248. });
  7249. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7250. LODOP.PRINT();
  7251. }
  7252. };
  7253. var lodopSPrintPreview = function (printStore, LODOP) {//单个条码打印预览
  7254. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7255. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7256. var strs = pagesize.split("*"); //字符分割
  7257. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7258. angular.forEach(printStore, function (data, index) {
  7259. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7260. if (data['LP_VALUETYPE'] == 'barcode') {
  7261. 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']);
  7262. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7263. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7264. } else if (data['LP_VALUETYPE'] == 'text') {
  7265. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7266. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7267. }
  7268. });
  7269. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7270. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7271. LODOP.PREVIEW();//打印预览
  7272. };
  7273. var lodopPrint = function (printStore, LODOP, type) {//勾选发货单明细进行打印
  7274. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7275. if (selectOrNot != -1) {
  7276. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7277. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  7278. var strs = new Array(); //定义一数组
  7279. strs = pagesize.split("*"); //字符分割
  7280. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7281. var ids = new Array();
  7282. angular.forEach(printStore, function (value, key) {
  7283. //LODOP.NewPage();
  7284. angular.forEach(value['data'], function (record, key) {
  7285. angular.forEach(record['store'], function (data, index) {
  7286. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7287. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7288. if (data['LP_VALUETYPE'] == 'barcode') {
  7289. 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']);
  7290. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7291. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7292. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7293. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7294. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7295. } else if (data['LP_VALUETYPE'] == 'text') {
  7296. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7297. }
  7298. });
  7299. });
  7300. var o = new Object();
  7301. o['id'] = record['si_id']
  7302. ids.push(o);
  7303. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7304. LODOP.PRINT();
  7305. });
  7306. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7307. if (type == 'Bar') {
  7308. //更新打印状态
  7309. SaleSend.updatePrintStatus({}, ids, function (data) {
  7310. }, function (res) {
  7311. });
  7312. }
  7313. }
  7314. };
  7315. var lodopPrintPreview = function (printData, LODOP, type) {//打印预览
  7316. var ids = new Array();
  7317. angular.forEach(printData, function (record, index) {
  7318. angular.forEach(record['data'], function (value, index) {
  7319. LODOP.NewPage();
  7320. angular.forEach(value['store'], function (data, index) {
  7321. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7322. if (data['LP_VALUETYPE'] == 'barcode') {
  7323. 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']);
  7324. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7325. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7326. } else if (data['LP_VALUETYPE'] == 'text') {
  7327. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7328. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7329. }
  7330. });
  7331. });
  7332. var o = new Object();
  7333. o['id'] = record['si_id']
  7334. ids.push(o);
  7335. });
  7336. var pagesize = printData[0]['pagesize'];//获取标签的大小
  7337. var strs = new Array(); //定义一数组
  7338. strs = pagesize.split("*"); //字符分割
  7339. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7340. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7341. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7342. var times = LODOP.PREVIEW();//打印预览
  7343. if (times > 0) {//点击了打印预览内的打印按钮
  7344. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7345. if (type == 'Bar') {
  7346. //更新打印状态
  7347. SaleSend.updatePrintStatus({}, ids, function (data) {
  7348. loadData();
  7349. }, function (res) {
  7350. });
  7351. }
  7352. }
  7353. };
  7354. /**
  7355. * 查看条码按钮
  7356. */
  7357. $scope.showBarCode = function (number) {
  7358. $scope.keys = number;
  7359. for (var i = 0; i < vm.showBarCode.length; i++) {
  7360. if (i != number) {
  7361. vm.showBarCode[i] = false;
  7362. }
  7363. }
  7364. vm.showBarCode[number] = !vm.showBarCode[number];
  7365. $scope.barcodes = [];
  7366. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  7367. var getPage = function (page, size) {
  7368. if ($scope.barcodes) {
  7369. var result = {};
  7370. result.totalCount = $scope.barcodes.length;
  7371. result.content = $scope.barcodes.slice((page - 1) * size, page * size);
  7372. if ($scope.barcodes.length % size == 0) {
  7373. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  7374. } else {
  7375. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  7376. }
  7377. result.first = page == 1;
  7378. result.last = page == result.totalPage;
  7379. result.page = page;
  7380. result.next = page - 0 + 1;
  7381. result.pre = page - 1;
  7382. return result;
  7383. }
  7384. }
  7385. $scope.barData = getPage(1, 5);
  7386. $scope.first = function () {
  7387. $scope.barData = getPage($scope.barData.pre, 5);
  7388. }
  7389. $scope.last = function () {
  7390. $scope.barData = getPage($scope.barData.next, 5);
  7391. }
  7392. };
  7393. /**
  7394. * 更新外箱号
  7395. */
  7396. $scope.updateOutBox = function (item, number) {
  7397. if ($scope.oldoutBoxQty[number] == item.outBoxQty) {
  7398. } else {
  7399. if (item.outBoxQty > 0) {
  7400. if (!(item.outBoxQty % item.packageQty)) {
  7401. SaleSend.update({id: item.id}, item, function () {
  7402. toaster.pop('success', '提示', '保存成功!');
  7403. loadData();
  7404. }, function (response) {
  7405. $scope.loading = false;
  7406. toaster.pop('error', '回复失败', response.data);
  7407. })
  7408. } else {
  7409. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  7410. }
  7411. } else {
  7412. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7413. }
  7414. }
  7415. loadData();
  7416. };
  7417. /**
  7418. * 更新最小包数
  7419. */
  7420. $scope.updatePackage = function (item, number) {
  7421. if (item.packageQty == $scope.oldpackageQty[number]) {
  7422. } else {
  7423. if (item.orderItem.product.minPack != 0) {
  7424. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7425. if (!(item.packageQty % item.orderItem.product.minPack)) {
  7426. SaleSend.update({id: item.id}, item, function () {
  7427. toaster.pop('success', '提示', '保存成功!');
  7428. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7429. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7430. }
  7431. loadData();
  7432. }, function (response) {
  7433. $scope.loading = false;
  7434. toaster.pop('error', '回复失败', response.data);
  7435. })
  7436. } else {
  7437. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  7438. }
  7439. } else {
  7440. toaster.pop('warning', '提示', '请填写有效的数量!');
  7441. }
  7442. } else {
  7443. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7444. SaleSend.update({id: item.id}, item, function () {
  7445. toaster.pop('success', '提示', '保存成功!');
  7446. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7447. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7448. }
  7449. loadData();
  7450. }, function (response) {
  7451. $scope.loading = false;
  7452. toaster.pop('error', '回复失败', response.data);
  7453. })
  7454. } else {
  7455. toaster.pop('warning', '提示', '请填写有效的数量!');
  7456. }
  7457. }
  7458. }
  7459. loadData();
  7460. };
  7461. var loadData = function () {
  7462. SaleSend.getItem({id: $stateParams.id}, function (data) {
  7463. $scope.order = data;
  7464. var orderCount = $scope.order.sendItems.length;
  7465. $scope.oldpackageQty = [];
  7466. $scope.oldoutBoxQty = [];
  7467. var sum = 0;
  7468. vm.oldpackageQty = [];
  7469. angular.forEach(data.sendItems, function (value, key) {
  7470. //给showBarCode数组赋初值
  7471. if (vm.showBarCode.length < orderCount) {
  7472. vm.showBarCode.push(false);
  7473. }
  7474. if ($scope.checkBarCode.length < orderCount) {
  7475. $scope.checkBarCode.push(false);
  7476. }
  7477. if ($scope.checkBoxCode.length < orderCount) {
  7478. $scope.checkBoxCode.push(false);
  7479. }
  7480. //给个初值
  7481. if (!value.packageQty) {
  7482. value.packageQty = value.orderItem.product.minPack;
  7483. }
  7484. $scope.oldpackageQty.push(value.packageQty);
  7485. if (value.outBoxQty) {
  7486. $scope.oldoutBoxQty.push(value.outBoxQty);
  7487. }
  7488. sum += value.price * value.qty;
  7489. });
  7490. data.total = sum;
  7491. $scope.loading = false;
  7492. }, function (response) {
  7493. loading = false;
  7494. toaster.pop('error', '获取数据失败', response.data);
  7495. });
  7496. };
  7497. loadData();
  7498. }]);
  7499. app.controller('BarPrintModalCtrl', ['$scope', 'typeItem', 'SaleSend', 'toaster', '$modalInstance', function ($scope, typeItem, SaleSend, toaster, $modalInstance) {
  7500. $scope.typeItem = typeItem;
  7501. $scope.template = [];
  7502. $scope.choose = {};
  7503. //获取打印模板
  7504. SaleSend.getPrintTemplate({id: $scope.typeItem.id, type: $scope.typeItem.type}, function (data) {
  7505. if (data.message) {
  7506. $scope.template = data.message;
  7507. $scope.choose.tp_id = $scope.template[0].id;
  7508. }
  7509. }, function (res) {
  7510. toaster.pop('error', '获取模板错误', res.data);
  7511. });
  7512. $scope.print = function () {
  7513. $scope.choose.type = 'print';
  7514. $modalInstance.close($scope.choose);
  7515. };
  7516. $scope.printPreview = function () {
  7517. $scope.choose.type = 'printPreview';
  7518. $modalInstance.close($scope.choose);
  7519. }
  7520. $scope.cancel = function () {
  7521. $modalInstance.close();
  7522. }
  7523. }]);
  7524. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', 'CurrentRole', function ($scope, $stateParams, PurcSample, toaster, $modal, BaseService, CurrentRole) {
  7525. BaseService.scrollBackToTop();
  7526. // 获取当前用户是否为普通用户
  7527. CurrentRole.isUser({}, {}, function (data) {
  7528. $scope.isUser = data.isUser;
  7529. });
  7530. var loading = true;
  7531. var loadData = function () {
  7532. PurcSample.getItem({id: $stateParams.id}, function (data) {
  7533. $scope.sample = data;
  7534. if (!$scope.sample.sends) {
  7535. $scope.sample.getSendInfo = '加载中...';
  7536. PurcSample.getSend({id: $stateParams.id}, function (sendData) {
  7537. if (sendData) {
  7538. $scope.sample.getSendInfo = null;
  7539. $scope.sample.sends = sendData;
  7540. } else {
  7541. $scope.sample.getSendInfo = '无送样信息';
  7542. $scope.sample.sends = '无送样信息';
  7543. }
  7544. }, function (response) {
  7545. $scope.sample.getSendInfo = '加载失败!';
  7546. toaster.pop('error', '', response.data);
  7547. });
  7548. }
  7549. $scope.loading = false;
  7550. }, function (response) {
  7551. loading = false;
  7552. toaster.pop('error', '获取数据失败', response.data);
  7553. });
  7554. };
  7555. loadData();
  7556. $scope.openSend = function (index, sample) {
  7557. var modalInstance = $modal.open({
  7558. animation: true,
  7559. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7560. controller: 'SampleSendCtrl',
  7561. resolve: {
  7562. sampleItem: function () {
  7563. return sample;
  7564. }
  7565. }
  7566. });
  7567. modalInstance.result.then(function () {
  7568. toaster.pop('info', '提示', '送样成功');
  7569. $scope.tableParams.reload();
  7570. }, function () {
  7571. });
  7572. };
  7573. }]);
  7574. /**
  7575. * 客户打样申请
  7576. */
  7577. app.controller('SaleSampleCtrl', ['$scope', '$filter', 'PurcSample', 'ngTableParams', 'toaster', '$modal', 'BaseService', 'ReportService', 'Symbol', '$rootScope', 'PurcSampleInfo', 'CurrentRole', function ($scope, $filter, PurcSample, ngTableParams, toaster, $modal, BaseService, ReportService, Symbol, $rootScope, PurcSampleInfo, CurrentRole) {
  7578. BaseService.scrollBackToTop();
  7579. // 获取当前用户是否为普通用户
  7580. CurrentRole.isUser({}, {}, function (data) {
  7581. $scope.isUser = data.isUser;
  7582. });
  7583. if ($rootScope.active) {
  7584. $scope.active = $rootScope.active;
  7585. $rootScope.active = null;
  7586. } else {
  7587. $scope.active = 'todo';
  7588. }
  7589. $scope.agreedText = '全部';
  7590. $scope.dateZoneText = '一个月内';
  7591. $scope.condition = {dateZone: 1};
  7592. /*初始化筛选时间*/
  7593. var fromDate = new Date();
  7594. var toDate = new Date();
  7595. fromDate.setMonth(fromDate.getMonth() - 1);
  7596. fromDate.setHours(0, 0, 0, 0);
  7597. toDate.setHours(23, 59, 59, 999);
  7598. $scope.condition.dateFrom = fromDate;
  7599. $scope.condition.dateTo = toDate;
  7600. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7601. $scope.changeAgreed = function (agreed) {
  7602. $scope.condition.agreed = agreed;
  7603. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7604. $scope.condition.$agreedOpen = false;
  7605. };
  7606. $scope.changeDateZone = function (zone) {
  7607. $scope.condition.dateZone = zone;
  7608. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7609. $scope.condition.$dateZoneOpen = false;
  7610. getDateCondition(zone, $scope.condition);
  7611. $scope.tableParams.page(1);
  7612. $scope.tableParams.reload();
  7613. };
  7614. $scope.setActive = function (state) {
  7615. if ($scope.active != state) {
  7616. $scope.active = state;
  7617. if ($scope.tableParams.page() == 1)
  7618. $scope.tableParams.reload();
  7619. else
  7620. $scope.tableParams.page(1);
  7621. }
  7622. };
  7623. $scope.searchMethod = false;
  7624. var getService = function () {
  7625. return $scope.searchMethod ? PurcSample : PurcSampleInfo;
  7626. };
  7627. $scope.tableParams = new ngTableParams({
  7628. page: 1,
  7629. count: 20,
  7630. sorting: {
  7631. proofingDate: 'desc'
  7632. }
  7633. }, {
  7634. total: 0,
  7635. counts: [5, 10, 25, 50],
  7636. getData: function ($defer, params) {
  7637. $scope.loading = true;
  7638. var pageParams = params.url();
  7639. pageParams.searchFilter = {
  7640. keyword: $scope.keyword,
  7641. fromDate: getDateTime($scope.condition.dateFrom),
  7642. endDate: getDateTime($scope.condition.dateTo)
  7643. };
  7644. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7645. $scope.loading = false;
  7646. if (page) {
  7647. params.total(page.totalElement);
  7648. $defer.resolve(page.content);
  7649. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7650. }
  7651. getUnreadCount();
  7652. }, function (response) {
  7653. $scope.loading = false;
  7654. toaster.pop('error', '数据加载失败', response.data);
  7655. });
  7656. }
  7657. });
  7658. //获得各分类未阅读数量
  7659. var getUnreadCount = function () {
  7660. PurcSample.getUnreadCount(null, function(data){
  7661. $scope.unread = data;
  7662. });
  7663. };
  7664. getUnreadCount();
  7665. //设置单个单据已读
  7666. $scope.setOrdersRead = function (id) {
  7667. if (!$scope.isUnread(id)) {
  7668. return;
  7669. }
  7670. var sourceId = [];
  7671. sourceId.push(id);
  7672. PurcSample.setRead({}, sourceId, function (message) {
  7673. getUnreadIds();
  7674. getUnreadCount();
  7675. });
  7676. };
  7677. //获取未读单据id
  7678. var getUnreadIds = function (){
  7679. PurcSample.getUnreadIds({}, "", function (message) {
  7680. $scope.unreadCode = message.content;
  7681. });
  7682. };
  7683. getUnreadIds();
  7684. //判断单据是否未读
  7685. $scope.isUnread = function (id){
  7686. for (var i in $scope.unreadCode) {
  7687. if (id == $scope.unreadCode[i]) {
  7688. return true;
  7689. }
  7690. }
  7691. };
  7692. $scope.openDatePicker = function ($event, item, openParam) {
  7693. $event.preventDefault();
  7694. $event.stopPropagation();
  7695. item[openParam] = !item[openParam];
  7696. };
  7697. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7698. $event.preventDefault();
  7699. $event.stopPropagation();
  7700. item[openParam] = !item[openParam];
  7701. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7702. $scope.tableParams.reload();
  7703. }
  7704. };
  7705. $scope.openSend = function (index, sample) {
  7706. var modalInstance = $modal.open({
  7707. animation: true,
  7708. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7709. controller: 'SampleSendCtrl',
  7710. resolve: {
  7711. sampleItem: function () {
  7712. return sample;
  7713. }
  7714. }
  7715. });
  7716. modalInstance.result.then(function () {
  7717. toaster.pop('info', '提示', '送样成功');
  7718. $scope.tableParams.reload();
  7719. }, function () {
  7720. });
  7721. };
  7722. //打印 样品采购单
  7723. $scope.print = function (sample) {
  7724. var newPage = window.open("about:blank");
  7725. PurcSample.printPermission({}, function () {
  7726. PurcSample.printCount({id: sample.id}, {});//增加打印此次
  7727. ReportService.print(sample.proofing.enUU, 'PURCPROOFING', "where purc$proofingitems.ppi_id =" + sample.id, newPage);
  7728. }, function (response) {
  7729. newPage.close();
  7730. toaster.pop('error', '打印失败', response.data);
  7731. });
  7732. };
  7733. $scope.getSend = function (proofing) {
  7734. if (!proofing.sends) {
  7735. proofing.getSendInfo = '加载中...';
  7736. PurcSample.getSend({id: proofing.id}, function (data) {
  7737. if (data) {
  7738. proofing.getSendInfo = null;
  7739. proofing.sends = data;
  7740. } else {
  7741. proofing.getSendInfo = '无送样信息';
  7742. proofing.sends = '无送样信息';
  7743. }
  7744. }, function (response) {
  7745. proofing.getSendInfo = '加载失败!';
  7746. });
  7747. }
  7748. };
  7749. // 搜索框回车
  7750. $scope.onSearch = function (keyword) {
  7751. // 每次搜索重置获取数据方法
  7752. $scope.searchMethod = false;
  7753. if(keyword != null && keyword != '') {
  7754. $scope.searchMethod = true;
  7755. }
  7756. $scope.tableParams.page(1);
  7757. $scope.tableParams.reload();
  7758. };
  7759. // 导出
  7760. $scope.exportXls = function () {
  7761. PurcSample.exportXls({}, {}, function (data) {
  7762. if (data.success){
  7763. window.location.href = 'sale/sample/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  7764. }
  7765. }, function (response) {
  7766. toaster.pop('error', '数据加载失败', response.data);
  7767. });
  7768. }
  7769. }]);
  7770. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function ($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster) {
  7771. if (!sampleItem.sends) {
  7772. PurcSample.getSend({id: sampleItem.id}, function (data) {
  7773. if (data) {
  7774. sampleItem.sends = data; // 获取送样信息
  7775. angular.forEach(data, function (send) {
  7776. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  7777. });
  7778. }
  7779. }, function (response) {
  7780. });
  7781. }
  7782. $scope.sampleItem = sampleItem;
  7783. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  7784. //确认送样
  7785. $scope.ok = function (form) {
  7786. $scope.loading = true;
  7787. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  7788. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  7789. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  7790. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  7791. $upload.upload({
  7792. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  7793. method: 'POST',
  7794. file: file,
  7795. data: {
  7796. json: $scope.sampleItem.sampleSend
  7797. }
  7798. }).success(function (data) {
  7799. $scope.loading = false;
  7800. $modalInstance.close('success');
  7801. }).error(function (data) {
  7802. $scope.loading = false;
  7803. toaster.pop('error', '错误', data);
  7804. });
  7805. };
  7806. $scope.cancel = function () {
  7807. $modalInstance.dismiss(sampleItem);
  7808. };
  7809. //设置单个单据已读
  7810. $scope.setOrdersRead = function (id) {
  7811. var sourceId = [];
  7812. sourceId.push(id);
  7813. PurcSample.setRead({}, sourceId, function (message) {
  7814. // $scope.getUnreadIds();
  7815. });
  7816. };
  7817. }]);
  7818. /**
  7819. * 客户认定单
  7820. */
  7821. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol) {
  7822. BaseService.scrollBackToTop();
  7823. $scope.active = 'all';
  7824. $scope.agreedText = '全部';
  7825. $scope.dateZoneText = '一个月内';
  7826. $scope.condition = {dateZone: 1};
  7827. /* 时间筛选初始化*/
  7828. var fromDate = new Date();
  7829. var toDate = new Date();
  7830. fromDate.setMonth(fromDate.getMonth() - 1);
  7831. fromDate.setHours(0, 0, 0, 0);
  7832. toDate.setHours(23, 59, 59, 999);
  7833. $scope.condition.dateFrom = fromDate;
  7834. $scope.condition.dateTo = toDate;
  7835. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7836. $scope.changeDateZone = function (zone) {
  7837. $scope.condition.dateZone = zone;
  7838. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7839. $scope.condition.$dateZoneOpen = false;
  7840. getDateCondition(zone, $scope.condition);
  7841. $scope.tableParams.page(1);
  7842. $scope.tableParams.reload();
  7843. };
  7844. $scope.setActive = function (state) {
  7845. if ($scope.active != state) {
  7846. $scope.active = state;
  7847. if ($scope.tableParams.page() == 1)
  7848. $scope.tableParams.reload();
  7849. else
  7850. $scope.tableParams.page(1);
  7851. }
  7852. };
  7853. var getService = function () {
  7854. return PurcApproval;
  7855. };
  7856. $scope.tableParams = new ngTableParams({
  7857. page: 1,
  7858. count: 20,
  7859. sorting: {
  7860. inDate: 'desc'
  7861. }
  7862. }, {
  7863. total: 0,
  7864. counts: [5, 10, 25, 50],
  7865. getData: function ($defer, params) {
  7866. $scope.loading = true;
  7867. var pageParams = params.url();
  7868. pageParams.keyword = $scope.keyword;
  7869. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7870. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7871. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7872. $scope.loading = false;
  7873. if (page) {
  7874. params.total(page.totalElement);
  7875. $defer.resolve(page.content);
  7876. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7877. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7878. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7879. }
  7880. }, function (response) {
  7881. $scope.loading = false;
  7882. toaster.pop('error', '数据加载失败', response.data);
  7883. });
  7884. }
  7885. });
  7886. $scope.openDatePicker = function ($event, item, openParam) {
  7887. $event.preventDefault();
  7888. $event.stopPropagation();
  7889. item[openParam] = !item[openParam];
  7890. };
  7891. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7892. $event.preventDefault();
  7893. $event.stopPropagation();
  7894. item[openParam] = !item[openParam];
  7895. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7896. $scope.tableParams.reload();
  7897. }
  7898. };
  7899. $scope.parseDate = function (dateStr) {
  7900. if (dateStr)
  7901. return Date.parse(dateStr, 'yyyy-MM-dd');
  7902. return new Date();
  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. $scope.exportXls = function () {
  7916. PurcApproval.exportXls({}, {}, function (data) {
  7917. if (data.success){
  7918. window.location.href = 'sale/sample/approval/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7919. }
  7920. }, function (response) {
  7921. toaster.pop('error', '数据加载失败', response.data);
  7922. });
  7923. }
  7924. }]);
  7925. /**
  7926. * 客户采购预测
  7927. */
  7928. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol) {
  7929. BaseService.scrollBackToTop();
  7930. $scope.active = 'all';
  7931. $scope.agreedText = '全部';
  7932. $scope.dateZoneText = '一个月内';
  7933. $scope.condition = {dateZone: 1};
  7934. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7935. $scope.changeAgreed = function (agreed) {
  7936. $scope.condition.agreed = agreed;
  7937. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7938. $scope.condition.$agreedOpen = false;
  7939. };
  7940. $scope.changeDateZone = function (zone) {
  7941. $scope.condition.dateZone = zone;
  7942. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7943. $scope.condition.$dateZoneOpen = false;
  7944. };
  7945. $scope.setActive = function (state) {
  7946. if ($scope.active != state) {
  7947. $scope.active = state;
  7948. if ($scope.tableParams.page() == 1)
  7949. $scope.tableParams.reload();
  7950. else
  7951. $scope.tableParams.page(1);
  7952. }
  7953. };
  7954. var getService = function () {
  7955. return PurcForecast;
  7956. };
  7957. $scope.tableParams = new ngTableParams({
  7958. page: 1,
  7959. count: 20,
  7960. sorting: {
  7961. orderDate: 'desc'
  7962. }
  7963. }, {
  7964. total: 0,
  7965. counts: [5, 10, 25, 50],
  7966. getData: function ($defer, params) {
  7967. $scope.loading = true;
  7968. var pageParams = params.url();
  7969. pageParams.keyword = $scope.keyword;
  7970. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7971. $scope.loading = false;
  7972. if (page) {
  7973. params.total(page.totalElement);
  7974. $defer.resolve(page.content);
  7975. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7976. }
  7977. }, function (response) {
  7978. $scope.loading = false;
  7979. toaster.pop('error', '数据加载失败', response.data);
  7980. });
  7981. }
  7982. });
  7983. $scope.openDatePicker = function ($event, item, openParam) {
  7984. $event.preventDefault();
  7985. $event.stopPropagation();
  7986. item[openParam] = !item[openParam];
  7987. };
  7988. // 搜索框回车
  7989. $scope.onSearch = function () {
  7990. $scope.tableParams.page(1);
  7991. $scope.tableParams.reload();
  7992. };
  7993. }]);
  7994. /**
  7995. * 客户采购验收
  7996. */
  7997. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  7998. BaseService.scrollBackToTop();
  7999. // 获取当前用户是否为普通用户
  8000. CurrentRole.isUser({}, {}, function (data) {
  8001. $scope.isUser = data.isUser;
  8002. });
  8003. $scope.active = 'all';
  8004. $scope.dateZoneText = '不限';
  8005. $scope.deliveryZoneText = '不限';
  8006. $scope.condition = {dateZone: 1, deliveryZone: -1};
  8007. /* 时间筛选初始化*/
  8008. var fromDate = new Date();
  8009. var toDate = new Date();
  8010. fromDate.setMonth(fromDate.getMonth() - 1);
  8011. fromDate.setHours(0, 0, 0, 0);
  8012. toDate.setHours(23, 59, 59, 999);
  8013. $scope.condition.dateFrom = fromDate;
  8014. $scope.condition.dateTo = toDate;
  8015. $scope.changeDateZone = function (zone) {
  8016. $scope.condition.dateZone = zone;
  8017. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8018. $scope.condition.$dateZoneOpen = false;
  8019. getDateCondition(zone, $scope.condition);
  8020. $scope.tableParams.page(1);
  8021. $scope.tableParams.reload();
  8022. };
  8023. $scope.changeDeliveryZone = function (zone) {
  8024. $scope.condition.deliveryZoneText = zone;
  8025. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  8026. $scope.condition.$delievryZoneOpen = false;
  8027. getDelveryCondition(zone, $scope.condition);
  8028. $scope.tableParams.reload();
  8029. };
  8030. $scope.setActive = function (state) {
  8031. if ($scope.active != state) {
  8032. $scope.active = state;
  8033. if ($scope.tableParams.page() == 1)
  8034. $scope.tableParams.reload();
  8035. else
  8036. $scope.tableParams.page(1);
  8037. }
  8038. };
  8039. var getService = function () {
  8040. return PurcAccept;
  8041. };
  8042. $scope.tableParams = new ngTableParams({
  8043. page: 1,
  8044. count: 20,
  8045. sorting: {
  8046. date: 'desc'
  8047. }
  8048. }, {
  8049. total: 0,
  8050. counts: [5, 10, 25, 50],
  8051. getData: function ($defer, params) {
  8052. $scope.loading = true;
  8053. var pageParams = params.url();
  8054. pageParams.searchFilter = { // 筛选条件
  8055. keyword: $scope.keyword,
  8056. fromDate: getDateTime($scope.condition.dateFrom),
  8057. endDate: getDateTime($scope.condition.dateTo)
  8058. };
  8059. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8060. $scope.loading = false;
  8061. if (page) {
  8062. params.total(page.totalElement);
  8063. $defer.resolve(page.content);
  8064. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8065. }
  8066. }, function (response) {
  8067. $scope.loading = false;
  8068. toaster.pop('error', '数据加载失败', response.data);
  8069. });
  8070. }
  8071. });
  8072. $scope.openDatePicker = function ($event, item, openParam) {
  8073. $event.preventDefault();
  8074. $event.stopPropagation();
  8075. item[openParam] = !item[openParam];
  8076. };
  8077. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8078. $event.preventDefault();
  8079. $event.stopPropagation();
  8080. item[openParam] = !item[openParam];
  8081. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8082. $scope.tableParams.reload();
  8083. }
  8084. };
  8085. $scope.parseDate = function (dateStr) {
  8086. if (dateStr)
  8087. return Date.parse(dateStr, 'yyyy-MM-dd');
  8088. return new Date();
  8089. };
  8090. // 选择查找日期
  8091. $scope.onDateCondition = function () {
  8092. $scope.tableParams.page(1);
  8093. $scope.tableParams.reload();
  8094. };
  8095. // 搜索框回车
  8096. $scope.onSearch = function () {
  8097. $scope.tableParams.page(1);
  8098. $scope.tableParams.reload();
  8099. };
  8100. // 导出
  8101. $scope.exportXls = function () {
  8102. PurcAccept.exportXls({}, {}, function (data) {
  8103. if (data.success){
  8104. window.location.href = 'sale/accept/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8105. }
  8106. }, function (response) {
  8107. toaster.pop('error', '数据加载失败', response.data);
  8108. });
  8109. }
  8110. }]);
  8111. /**
  8112. * 客户采购验收详情
  8113. */
  8114. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcAccept, toaster, BaseService, $stateParams, CurrentRole) {
  8115. BaseService.scrollBackToTop();
  8116. // 获取当前用户是否为普通用户
  8117. CurrentRole.isUser({}, {}, function (data) {
  8118. $scope.isUser = data.isUser;
  8119. });
  8120. if ($stateParams.id) {
  8121. PurcAccept.getDetail({id: $stateParams.id}, {}, function (data) {
  8122. $scope.accept = data;
  8123. if ($scope.accept.acceptItems != null) {
  8124. var sum = 0;
  8125. angular.forEach($scope.accept.acceptItems, function (item) {
  8126. if (item.orderPrice == null) {
  8127. item.orderPrice = 0;
  8128. }
  8129. sum += item.orderPrice * item.qty;
  8130. });
  8131. $scope.totalPrice = sum;
  8132. }
  8133. }, function (response) {
  8134. toaster.pop('error', '提示', response.data);
  8135. });
  8136. }
  8137. }]);
  8138. /**
  8139. * 客户采购验退
  8140. */
  8141. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8142. BaseService.scrollBackToTop();
  8143. // 获取当前用户是否为普通用户
  8144. CurrentRole.isUser({}, {}, function (data) {
  8145. $scope.isUser = data.isUser;
  8146. });
  8147. $scope.active = 'all';
  8148. $scope.agreedText = '全部';
  8149. $scope.dateZoneText = '一个月内';
  8150. $scope.condition = {dateZone: 1};
  8151. /* 时间筛选初始化*/
  8152. var fromDate = new Date();
  8153. var toDate = new Date();
  8154. fromDate.setMonth(fromDate.getMonth() - 1);
  8155. fromDate.setHours(0, 0, 0, 0);
  8156. toDate.setHours(23, 59, 59, 999);
  8157. $scope.condition.dateFrom = fromDate;
  8158. $scope.condition.dateTo = toDate;
  8159. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8160. $scope.changeAgreed = function (agreed) {
  8161. $scope.condition.agreed = agreed;
  8162. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8163. $scope.condition.$agreedOpen = false;
  8164. };
  8165. $scope.changeDateZone = function (zone) {
  8166. $scope.condition.dateZone = zone;
  8167. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8168. $scope.condition.$dateZoneOpen = false;
  8169. getDateCondition(zone, $scope.condition);
  8170. $scope.tableParams.page(1);
  8171. $scope.tableParams.reload();
  8172. };
  8173. $scope.setActive = function (state) {
  8174. if ($scope.active != state) {
  8175. $scope.active = state;
  8176. if ($scope.tableParams.page() == 1)
  8177. $scope.tableParams.reload();
  8178. else
  8179. $scope.tableParams.page(1);
  8180. }
  8181. };
  8182. var getService = function () {
  8183. return PurcReturn;
  8184. };
  8185. $scope.tableParams = new ngTableParams({
  8186. page: 1,
  8187. count: 20,
  8188. sorting: {
  8189. date: 'desc'
  8190. }
  8191. }, {
  8192. total: 0,
  8193. counts: [5, 10, 25, 50],
  8194. getData: function ($defer, params) {
  8195. $scope.loading = true;
  8196. var pageParams = params.url();
  8197. pageParams.searchFilter = {
  8198. keyword: $scope.keyword,
  8199. fromDate: getDateTime($scope.condition.dateFrom),
  8200. endDate: getDateTime($scope.condition.dateTo)
  8201. };
  8202. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8203. $scope.loading = false;
  8204. if (page) {
  8205. params.total(page.totalElement);
  8206. $defer.resolve(page.content);
  8207. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8208. angular.forEach(page.content, function (data) {
  8209. if (!data.returnItems[0].orderItem) {
  8210. PurcReturn.getEnterpriseName({id: data.id, enuu: data.enUU}, function (enterprise) {
  8211. data.enName = enterprise.enName;
  8212. });
  8213. }
  8214. });
  8215. }
  8216. }, function (response) {
  8217. $scope.loading = false;
  8218. toaster.pop('error', '数据加载失败', response.data);
  8219. });
  8220. }
  8221. });
  8222. $scope.openDatePicker = function ($event, item, openParam) {
  8223. $event.preventDefault();
  8224. $event.stopPropagation();
  8225. item[openParam] = !item[openParam];
  8226. };
  8227. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8228. $event.preventDefault();
  8229. $event.stopPropagation();
  8230. item[openParam] = !item[openParam];
  8231. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8232. $scope.tableParams.reload();
  8233. }
  8234. };
  8235. // 搜索框回车
  8236. $scope.onSearch = function () {
  8237. $scope.tableParams.page(1);
  8238. $scope.tableParams.reload();
  8239. };
  8240. // 导出
  8241. $scope.exportXls = function () {
  8242. PurcReturn.exportXls({}, {}, function (data) {
  8243. if (data.success){
  8244. window.location.href = 'sale/return/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8245. }
  8246. }, function (response) {
  8247. toaster.pop('error', '数据加载失败', response.data);
  8248. });
  8249. }
  8250. }]);
  8251. /**
  8252. * 客户采购验退详情
  8253. */
  8254. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcReturn, toaster, BaseService, $stateParams, CurrentRole) {
  8255. BaseService.scrollBackToTop();'' +
  8256. // 获取当前用户是否为普通用户
  8257. CurrentRole.isUser({}, {}, function (data) {
  8258. $scope.isUser = data.isUser;
  8259. });
  8260. if ($stateParams.id != null) {
  8261. PurcReturn.getDetail({id: $stateParams.id}, {}, function (data) {
  8262. $scope.returns = data;
  8263. if ($scope.returns.returnItems != null) {
  8264. var sum = 0;
  8265. angular.forEach($scope.returns.returnItems, function (item) {
  8266. if (null != item.orderPrice) {
  8267. sum += item.orderPrice * item.qty;
  8268. }
  8269. });
  8270. $scope.totalPrice = sum;
  8271. }
  8272. }, function (response) {
  8273. toaster.pop('error', '提示', response.data);
  8274. });
  8275. }
  8276. }]);
  8277. /**
  8278. * 客户不良品入库
  8279. */
  8280. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8281. BaseService.scrollBackToTop();
  8282. // 获取当前用户是否为普通用户
  8283. CurrentRole.isUser({}, {}, function (data) {
  8284. $scope.isUser = data.isUser;
  8285. });
  8286. $scope.active = 'all';
  8287. $scope.agreedText = '全部';
  8288. $scope.dateZoneText = '一个月内';
  8289. $scope.condition = {dateZone: 1};
  8290. /* 时间筛选初始化*/
  8291. var fromDate = new Date();
  8292. var toDate = new Date();
  8293. fromDate.setMonth(fromDate.getMonth() - 1);
  8294. fromDate.setHours(0, 0, 0, 0);
  8295. toDate.setHours(23, 59, 59, 999);
  8296. $scope.condition.dateFrom = fromDate;
  8297. $scope.condition.dateTo = toDate;
  8298. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8299. $scope.changeAgreed = function (agreed) {
  8300. $scope.condition.agreed = agreed;
  8301. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8302. $scope.condition.$agreedOpen = false;
  8303. };
  8304. $scope.changeDateZone = function (zone) {
  8305. $scope.condition.dateZone = zone;
  8306. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8307. $scope.condition.$dateZoneOpen = false;
  8308. getDateCondition(zone, $scope.condition);
  8309. $scope.tableParams.page(1);
  8310. $scope.tableParams.reload();
  8311. };
  8312. $scope.setActive = function (state) {
  8313. if ($scope.active != state) {
  8314. $scope.active = state;
  8315. if ($scope.tableParams.page() == 1)
  8316. $scope.tableParams.reload();
  8317. else
  8318. $scope.tableParams.page(1);
  8319. }
  8320. };
  8321. var getService = function () {
  8322. return PurcBadIn;
  8323. };
  8324. $scope.tableParams = new ngTableParams({
  8325. page: 1,
  8326. count: 20,
  8327. sorting: {
  8328. date: 'desc'
  8329. }
  8330. }, {
  8331. total: 0,
  8332. counts: [5, 10, 25, 50],
  8333. getData: function ($defer, params) {
  8334. $scope.loading = true;
  8335. var pageParams = params.url();
  8336. pageParams.searchFilter = {
  8337. keyword: $scope.keyword,
  8338. fromDate: getDateTime($scope.condition.dateFrom),
  8339. endDate: getDateTime($scope.condition.dateTo)
  8340. };
  8341. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8342. $scope.loading = false;
  8343. if (page) {
  8344. params.total(page.totalElement);
  8345. $defer.resolve(page.content);
  8346. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8347. }
  8348. }, function (response) {
  8349. $scope.loading = false;
  8350. toaster.pop('error', '数据加载失败', response.data);
  8351. });
  8352. }
  8353. });
  8354. $scope.openDatePicker = function ($event, item, openParam) {
  8355. $event.preventDefault();
  8356. $event.stopPropagation();
  8357. item[openParam] = !item[openParam];
  8358. };
  8359. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8360. $event.preventDefault();
  8361. $event.stopPropagation();
  8362. item[openParam] = !item[openParam];
  8363. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8364. $scope.tableParams.reload();
  8365. }
  8366. };
  8367. // 搜索框回车
  8368. $scope.onSearch = function (keyword) {
  8369. $scope.keyword = keyword;
  8370. $scope.tableParams.page(1);
  8371. $scope.tableParams.reload();
  8372. };
  8373. // 导出
  8374. $scope.exportXls = function () {
  8375. PurcBadIn.exportXls({}, {}, function (data) {
  8376. if (data.success){
  8377. window.location.href = 'sale/badIn/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8378. }
  8379. }, function (response) {
  8380. toaster.pop('error', '数据加载失败', response.data);
  8381. });
  8382. }
  8383. }]);
  8384. /**
  8385. * 客户不良品出库
  8386. */
  8387. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8388. BaseService.scrollBackToTop();
  8389. // 获取当前用户是否为普通用户
  8390. CurrentRole.isUser({}, {}, function (data) {
  8391. $scope.isUser = data.isUser;
  8392. });
  8393. $scope.active = 'all';
  8394. $scope.agreedText = '全部';
  8395. $scope.dateZoneText = '一个月内';
  8396. $scope.condition = {dateZone: 1};
  8397. /* 时间筛选初始化*/
  8398. var fromDate = new Date();
  8399. var toDate = new Date();
  8400. fromDate.setMonth(fromDate.getMonth() - 1);
  8401. fromDate.setHours(0, 0, 0, 0);
  8402. toDate.setHours(23, 59, 59, 999);
  8403. $scope.condition.dateFrom = fromDate;
  8404. $scope.condition.dateTo = toDate;
  8405. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8406. $scope.changeAgreed = function (agreed) {
  8407. $scope.condition.agreed = agreed;
  8408. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8409. $scope.condition.$agreedOpen = false;
  8410. };
  8411. $scope.changeDateZone = function (zone) {
  8412. $scope.condition.dateZone = zone;
  8413. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8414. $scope.condition.$dateZoneOpen = false;
  8415. getDateCondition(zone, $scope.condition);
  8416. $scope.tableParams.page(1);
  8417. $scope.tableParams.reload();
  8418. };
  8419. $scope.setActive = function (state) {
  8420. if ($scope.active != state) {
  8421. $scope.active = state;
  8422. if ($scope.tableParams.page() == 1)
  8423. $scope.tableParams.reload();
  8424. else
  8425. $scope.tableParams.page(1);
  8426. }
  8427. };
  8428. var getService = function () {
  8429. return PurcBadOut;
  8430. };
  8431. $scope.tableParams = new ngTableParams({
  8432. page: 1,
  8433. count: 20,
  8434. sorting: {
  8435. date: 'desc'
  8436. }
  8437. }, {
  8438. total: 0,
  8439. counts: [5, 10, 25, 50],
  8440. getData: function ($defer, params) {
  8441. $scope.loading = true;
  8442. var pageParams = params.url();
  8443. pageParams.searchFilter = {
  8444. keyword: $scope.keyword,
  8445. fromDate: getDateTime($scope.condition.dateFrom),
  8446. endDate: getDateTime($scope.condition.dateTo)
  8447. };
  8448. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8449. $scope.loading = false;
  8450. if (page) {
  8451. params.total(page.totalElement);
  8452. $defer.resolve(page.content);
  8453. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8454. }
  8455. }, function (response) {
  8456. $scope.loading = false;
  8457. toaster.pop('error', '数据加载失败', response.data);
  8458. });
  8459. }
  8460. });
  8461. $scope.openDatePicker = function ($event, item, openParam) {
  8462. $event.preventDefault();
  8463. $event.stopPropagation();
  8464. item[openParam] = !item[openParam];
  8465. };
  8466. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8467. $event.preventDefault();
  8468. $event.stopPropagation();
  8469. item[openParam] = !item[openParam];
  8470. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8471. $scope.tableParams.reload();
  8472. }
  8473. };
  8474. // 搜索框回车
  8475. $scope.onSearch = function () {
  8476. $scope.tableParams.page(1);
  8477. $scope.tableParams.reload();
  8478. };
  8479. // 导出
  8480. $scope.exportXls = function () {
  8481. PurcBadOut.exportXls({}, {}, function (data) {
  8482. if (data.success){
  8483. window.location.href = 'sale/badOut/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8484. }
  8485. }, function (response) {
  8486. toaster.pop('error', '数据加载失败', response.data);
  8487. });
  8488. }
  8489. }]);
  8490. /**
  8491. * 客户MRB
  8492. */
  8493. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol) {
  8494. BaseService.scrollBackToTop();
  8495. $scope.active = 'all';
  8496. $scope.agreedText = '全部';
  8497. $scope.dateZoneText = '一个月内';
  8498. $scope.condition = {dateZone: 1};
  8499. /* 时间筛选初始化*/
  8500. var fromDate = new Date();
  8501. var toDate = new Date();
  8502. fromDate.setMonth(fromDate.getMonth() - 1);
  8503. fromDate.setHours(0, 0, 0, 0);
  8504. toDate.setHours(23, 59, 59, 999);
  8505. $scope.condition.dateFrom = fromDate;
  8506. $scope.condition.dateTo = toDate;
  8507. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8508. $scope.changeAgreed = function (agreed) {
  8509. $scope.condition.agreed = agreed;
  8510. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8511. $scope.condition.$agreedOpen = false;
  8512. };
  8513. $scope.changeDateZone = function (zone) {
  8514. $scope.condition.dateZone = zone;
  8515. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8516. $scope.condition.$dateZoneOpen = false;
  8517. getDateCondition(zone, $scope.condition);
  8518. $scope.tableParams.page(1);
  8519. $scope.tableParams.reload();
  8520. };
  8521. $scope.setActive = function (state) {
  8522. if ($scope.active != state) {
  8523. $scope.active = state;
  8524. if ($scope.tableParams.page() == 1)
  8525. $scope.tableParams.reload();
  8526. else
  8527. $scope.tableParams.page(1);
  8528. }
  8529. };
  8530. var getService = function () {
  8531. return PurcMRB;
  8532. };
  8533. $scope.tableParams = new ngTableParams({
  8534. page: 1,
  8535. count: 20,
  8536. sorting: {
  8537. date: 'desc'
  8538. }
  8539. }, {
  8540. total: 0,
  8541. counts: [5, 10, 25, 50],
  8542. getData: function ($defer, params) {
  8543. $scope.loading = true;
  8544. var pageParams = params.url();
  8545. pageParams.searchFilter = {
  8546. keyword: $scope.keyword,
  8547. fromDate: getDateTime($scope.condition.dateFrom),
  8548. endDate: getDateTime($scope.condition.dateTo)
  8549. };
  8550. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8551. $scope.loading = false;
  8552. if (page) {
  8553. params.total(page.totalElement);
  8554. $defer.resolve(page.content);
  8555. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8556. }
  8557. }, function (response) {
  8558. $scope.loading = false;
  8559. toaster.pop('error', '数据加载失败', response.data);
  8560. });
  8561. }
  8562. });
  8563. $scope.openDatePicker = function ($event, item, openParam) {
  8564. $event.preventDefault();
  8565. $event.stopPropagation();
  8566. item[openParam] = !item[openParam];
  8567. };
  8568. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8569. $event.preventDefault();
  8570. $event.stopPropagation();
  8571. item[openParam] = !item[openParam];
  8572. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8573. $scope.tableParams.reload();
  8574. }
  8575. };
  8576. // 搜索框回车
  8577. $scope.onSearch = function () {
  8578. $scope.tableParams.page(1);
  8579. $scope.tableParams.reload();
  8580. };
  8581. // 导出
  8582. $scope.exportXls = function () {
  8583. PurcMRB.exportXls({}, {}, function (data) {
  8584. if (data.success){
  8585. window.location.href = 'sale/MRB/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8586. }
  8587. }, function (response) {
  8588. toaster.pop('error', '数据加载失败', response.data);
  8589. });
  8590. }
  8591. }]);
  8592. //客户航天开票
  8593. app.controller('PurchaseApBillOutCtrl',['$scope', 'FaApBillOut', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function ($scope, FaApBillOut, BaseService, ngTableParams, toaster, ReportService , Symbol) {
  8594. BaseService.scrollBackToTop();
  8595. $scope.dateZoneText = '不限';
  8596. $scope.condition = {dateZone: 1};
  8597. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8598. $scope.active = 'all';
  8599. /* 时间筛选初始化*/
  8600. var fromDate = new Date();
  8601. var toDate = new Date();
  8602. fromDate.setMonth(fromDate.getMonth() - 1);
  8603. fromDate.setHours(0,0,0,0);
  8604. toDate.setHours(23,59,59,999);
  8605. $scope.condition.dateFrom = fromDate;
  8606. $scope.condition.dateTo = toDate;
  8607. //打印 开票单
  8608. $scope.print = function (billOut) {
  8609. FaApBillOut.printCount({id: billOut.id},function (data) {
  8610. if(!data.error) {
  8611. toaster.pop('success', '提示', '打印成功');
  8612. //$scope.tableParams.reload();
  8613. }else{
  8614. toaster.pop('error', '提示', '打印失败');
  8615. }
  8616. });
  8617. //ReportService.print(billOut.custUu, 'PURCBILLOUT', 'where purc$apbillout.pabo_id =' + billOut.id);
  8618. };
  8619. //状态
  8620. $scope.setActive = function (state) {
  8621. if($scope.active != state) {
  8622. $scope.active = state;
  8623. if($scope.tableParams.page() == 1)
  8624. $scope.tableParams.reload();
  8625. else
  8626. $scope.tableParams.page(1);
  8627. }
  8628. };
  8629. $scope.changeDateZone = function (zone) {
  8630. $scope.condition.dateZone = zone;
  8631. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8632. $scope.condition.$dateZoneOpen = false;
  8633. getDateCondition(zone, $scope.condition);
  8634. $scope.tableParams.page(1);
  8635. $scope.tableParams.reload();
  8636. };
  8637. //获取全部已确定应收对账单
  8638. $scope.tableParams = new ngTableParams({
  8639. page: 1,
  8640. count: 20,
  8641. sorting: {
  8642. recordDate: 'desc'
  8643. }
  8644. }, {
  8645. total: 0,
  8646. counts: [5, 10, 25, 50],
  8647. getData: function ($defer, params) {
  8648. $scope.loading = true;
  8649. var pageParams = params.url();
  8650. pageParams.searchFilter = { // 筛选条件
  8651. keyword: $scope.keyword,
  8652. fromDate: getDateTime($scope.condition.dateFrom),
  8653. endDate: getDateTime($scope.condition.dateTo)
  8654. };
  8655. FaApBillOut[getState($scope.active )](BaseService.parseParams(pageParams), function (page) {
  8656. $scope.loading = false;
  8657. if(page) {
  8658. params.total(page.totalElement);
  8659. $scope.data = $defer.resolve(page.content);
  8660. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  8661. }
  8662. }, function (response) {
  8663. $scope.loading = false;
  8664. toaster.pop('error', '数据加载失败', response.data);
  8665. });
  8666. }
  8667. });
  8668. $scope.openDatePicker = function ($event, item, openParam) {
  8669. $event.preventDefault();
  8670. $event.stopPropagation();
  8671. item[openParam] = !item[openParam];
  8672. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  8673. $scope.tableParams.reload();
  8674. }
  8675. };
  8676. // 计算开票数量
  8677. $scope.getTotalProd = function (billOut) {
  8678. var total = 0;
  8679. if(billOut.items) {
  8680. angular.forEach(billOut.items, function (value) {
  8681. total += value.NowQty;
  8682. });
  8683. }
  8684. return total;
  8685. };
  8686. // 搜索框回车
  8687. $scope.onSearch = function () {
  8688. $scope.tableParams.page(1);
  8689. $scope.tableParams.reload();
  8690. };
  8691. // 选择查找日期
  8692. $scope.onDateCondition = function () {
  8693. $scope.tableParams.page(1);
  8694. $scope.tableParams.reload();
  8695. };
  8696. }]);
  8697. //开票单详情
  8698. app.controller('PurchaseApBillOutDetailCtrl',['$scope', 'toaster', 'FaApBillOut', 'FaApCheck', '$stateParams', 'BaseService', function ($scope, toaster, FaApBillOut, FaApCheck, $stateParams, BaseService) {
  8699. BaseService.scrollBackToTop();
  8700. $scope.haveSelected = true;
  8701. $scope.data = {};
  8702. //控制提交和删除按钮的显示
  8703. $scope.ifShow = true;
  8704. var loadData = function () {
  8705. FaApBillOut.get({id:$stateParams.id},function (data) {
  8706. $scope.data = data;
  8707. if($scope.data.status){
  8708. }else{
  8709. $scope.ifShow = true;
  8710. }
  8711. })
  8712. };
  8713. if($stateParams.id){
  8714. loadData();
  8715. }
  8716. $scope.haveSource = false;
  8717. //TODO 提交开票单
  8718. $scope.invoiceIssued = function (apBillOut) {
  8719. $scope.loading = true;
  8720. FaApBillOut.invoiceIssued({id:apBillOut.id},function (data) {
  8721. $scope.loading = false;
  8722. if(data.apBillOut) {
  8723. $scope.haveSelected = false;
  8724. window.location.href = '#/fa/apBillOut';
  8725. toaster.pop('success', '提示', '提交成功');
  8726. } else {
  8727. $scope.loading = false;
  8728. toaster.pop('error', '提示', data.error);
  8729. }
  8730. })
  8731. }
  8732. //删除开票单(后台同时更新对账单明细表已开票数)
  8733. $scope.deleteApBillOut = function () {
  8734. FaApBillOut.deleteApBillOut({id:$stateParams.id},function (data) {
  8735. window.location.href = '#/fa/apBillOut';
  8736. toaster.pop('success','提示','删除成功');
  8737. },function () {
  8738. toaster.pop('error','提示','删除失败');
  8739. });
  8740. $scope.haveSelected = false;
  8741. }
  8742. //TODO 作废开票单
  8743. $scope.InvoiceCancel = function () {
  8744. $scope.loading = true;
  8745. FaApBillOut.InvoiceCancel({id:$stateParams.id},function (data) {
  8746. $scope.loading = false;
  8747. if(!data.error) {
  8748. toaster.pop('success', '提示', '作废成功');
  8749. window.location.href = '#/fa/apBillOut';
  8750. $scope.tableParams.reload();
  8751. }else{
  8752. toaster.pop('error', '提示', data.error);
  8753. }
  8754. },function (response) {
  8755. $scope.loading = false;
  8756. toaster.pop('error', '提示', response.data);
  8757. });
  8758. }
  8759. }]);
  8760. //航天开票单据列表
  8761. app.controller('PurchaseApBillOutListCtrl',['$scope', 'FaApCheck', 'FaApBillOut', 'toaster', '$state','$filter', '$modal', function ($scope, FaApCheck, FaApBillOut, toaster, $state, $filter, $modal) {
  8762. $scope.data = [];// 列表数据
  8763. $scope.condition = {
  8764. $fromOpened: false
  8765. }
  8766. $scope.openDatePicker = function ($event, item, openParam) {
  8767. $event.preventDefault();
  8768. $event.stopPropagation();
  8769. item[openParam] = !item[openParam];
  8770. }
  8771. //查找客户
  8772. $scope.searchCust = function (suuorname) {
  8773. var modalInstance = $modal.open({
  8774. animation: true,
  8775. templateUrl: 'static/tpl/index/fa/custInfo.html',
  8776. controller: 'SearchCustInfoCtrl',
  8777. resolve: {
  8778. suuorname: function () {
  8779. return suuorname;
  8780. }
  8781. }
  8782. });
  8783. modalInstance.result.then(function (suuorname) {
  8784. $scope.suuorname = suuorname;
  8785. });
  8786. }
  8787. // 点击筛选根据条件选择数据
  8788. $scope.suuorname = '';
  8789. // 默认本月
  8790. $scope.sdateTo = new Date();
  8791. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  8792. $scope.vuuorname = '';
  8793. $scope.factory = '';
  8794. $scope.prodTitle = '';
  8795. $scope.prodSpec = '';
  8796. $scope.condition.uuorname = '';
  8797. $scope.condition.dateFrom = '';
  8798. $scope.condition.dateTo = '';
  8799. $scope.condition.venduuorname = '';
  8800. $scope.condition.factory = '';
  8801. $scope.condition.prodTitle = '';
  8802. $scope.condition.prodSpec = '';
  8803. $scope.searchOrder = function (check) {
  8804. $scope.data = [];
  8805. $scope.checkboxes.checked = false;
  8806. $scope.totalMoney = 0;
  8807. $scope.condition.uuorname = $scope.suuorname;
  8808. $scope.condition.factory = $scope.factory;
  8809. $scope.condition.prodTitle = $scope.prodTitle;
  8810. $scope.condition.prodSpec = $scope.prodSpec;
  8811. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  8812. $scope.thisdatato = ($scope.sdateTo || 0);
  8813. if($scope.thisdatato != 0) {
  8814. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  8815. } else {
  8816. $scope.condition.dateTo = ($scope.sdateTo || 0);
  8817. }
  8818. $scope.condition.venduuorname = $scope.vuuorname;
  8819. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  8820. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8821. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8822. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  8823. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  8824. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  8825. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  8826. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  8827. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8828. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  8829. if(!$scope.suuorname) {
  8830. toaster.pop('warning','提示', '请先选择客户');
  8831. document.getElementById('suuorname').focus();//光标默认在客户
  8832. } else {
  8833. $scope.loading = true;
  8834. FaApBillOut.getDoneApCheckByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  8835. if(data.length > 0) {
  8836. angular.forEach(data, function (checkItem) {
  8837. checkItem.$selected = true;
  8838. if(checkItem.billed) {
  8839. checkItem.thisBilledQty = checkItem.checkQty - checkItem.billed;
  8840. //$filter('number')(checkItem.thisBilledQty, 2);
  8841. } else {
  8842. checkItem.billed = 0;
  8843. checkItem.thisBilledQty = checkItem.checkQty;
  8844. }
  8845. //最大最小开票数
  8846. checkItem.maxThisBilledQty = checkItem.thisBilledQty;
  8847. checkItem.minThisBilledQty = 0;
  8848. });
  8849. $scope.data = data;
  8850. $scope.checkboxes.checked = true;
  8851. $scope.getTotalMoney();
  8852. } else {
  8853. toaster.pop('info', '提示', '当前没有需要对账记录');
  8854. }
  8855. $scope.loading = false;
  8856. }, function (response) {
  8857. $scope.loading = false;
  8858. toaster.pop('error', '提示', response.data);
  8859. });
  8860. }
  8861. }
  8862. }
  8863. /**
  8864. * 点击勾选框,选中要转应收对账单的订单
  8865. * */
  8866. $scope.totalMoney = 0;
  8867. $scope.checkboxes = {
  8868. checked: false
  8869. };
  8870. // 点击勾选全部的复选框
  8871. $scope.checkAll = function () {
  8872. $scope.totalMoney = 0;
  8873. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  8874. var uuorname = $scope.suuorname;
  8875. var venduuorname = $scope.venduuorname;
  8876. var dateFrom = $scope.condition.dateFrom;
  8877. var dateTo = $scope.condition.dateTo;
  8878. var prodTitle = $scope.condition.prodTitle;
  8879. var prodSpec = $scope.condition.prodSpec;
  8880. var factory = $scope.condition.factory;
  8881. angular.forEach($scope.filteredData, function (item) {
  8882. if((item.apCheck.apDate >= dateFrom || dateFrom == '') && (item.apCheck.apDate < dateTo || dateTo == '')){
  8883. item.$selected = $scope.checkboxes.checked;
  8884. }
  8885. });
  8886. $scope.getTotalMoney();
  8887. };
  8888. //获取已选单据总金额
  8889. var total = true;
  8890. $scope.getTotalMoney = function () {
  8891. $scope.totalMoney = 0;
  8892. angular.forEach($scope.data, function (check) {
  8893. if(check.$selected){
  8894. $scope.totalMoney += (check.CheckQty || 0)*(check.orderPrice || 0);
  8895. }else{
  8896. $scope.totalMoney += 0;
  8897. }
  8898. });
  8899. }
  8900. // 点击其中一个明细的复选框
  8901. $scope.checkOne = function (check) {
  8902. var result = true;
  8903. angular.forEach($scope.data, function (item) {
  8904. if(item.$selected != true){
  8905. result = false;
  8906. return;
  8907. }
  8908. });
  8909. $scope.checkboxes.checked = result;
  8910. };
  8911. $scope.haveSelected = false;
  8912. //生成开票单
  8913. $scope.createApBillOut = function () {
  8914. //保存应收对账单主记录字段
  8915. $scope.apBillOut = {
  8916. custUu: '',
  8917. custName: '',
  8918. beginDate: '',
  8919. endDate: '',
  8920. enUu: '',
  8921. recordDate: '',
  8922. checkStatus: '未开票',
  8923. currency: '',
  8924. rate: '',
  8925. //billed:'',
  8926. //apBillOutItemId:'',
  8927. items: [],
  8928. sourceInfos: []
  8929. };
  8930. //保存来源单据相关信息
  8931. //var sourceInfos = [];
  8932. //所允许的本次对账最大最小数量
  8933. //$scope.data.maxThisCheckQty = 0;
  8934. //$scope.data.minThisCheckQty = 0;
  8935. $scope.sameCust = true;
  8936. $scope.validQty = true;
  8937. $scope.loading = true;
  8938. angular.forEach($scope.data, function (checkItem) {
  8939. //保存开票单明细行数据
  8940. $scope.item = {
  8941. inoutno: '',
  8942. inoutnodetno: '',
  8943. orderCode: '',
  8944. orderClass: '',
  8945. orderDetno: '',
  8946. price: '',
  8947. NowQty: '',
  8948. //amount: '',
  8949. sourceId:'',
  8950. sourceTable:'',
  8951. //oldYCheckQty:'',
  8952. status: 0,
  8953. //receiveCode:'',
  8954. //receiveName:'',
  8955. prodCode:'',
  8956. //prodSpec:'',
  8957. taxrate: '',
  8958. //sendcode: '',
  8959. //whname: '',
  8960. };
  8961. //开票单明细行来源表信息(新的已开票数)
  8962. $scope.sourceInfo = {
  8963. sourceId: '',
  8964. sourceTable: '',
  8965. newBilledQty: 0
  8966. };
  8967. //本次开票新的开票数
  8968. //$scope.thisBilledQty = 0;
  8969. if(checkItem.$selected == true) {
  8970. $scope.apBillOut.custName = checkItem.apCheck.custName;
  8971. $scope.apBillOut.enUu = checkItem.apCheck.enUu;
  8972. $scope.item.inoutno = checkItem.inoutno;
  8973. $scope.item.inoutnodetno = checkItem.inoutnodetno;
  8974. $scope.item.orderCode = checkItem.orderCode;
  8975. $scope.item.orderClass = checkItem.orderClass;
  8976. $scope.item.orderDetno = checkItem.orderDetno;
  8977. $scope.item.NowQty = checkItem.thisBilledQty;
  8978. if (typeof(checkItem.billed) == "undefined") {
  8979. checkItem.billed = 0;
  8980. $scope.sourceInfo.newBilledQty =checkItem.thisBilledQty;
  8981. } else {
  8982. //TODO 变成了字符串相加?
  8983. $scope.sourceInfo.newBilledQty = checkItem.thisBilledQty + checkItem.billed;
  8984. }
  8985. //$scope.apBillOut.apBillOutItemId = check.id;
  8986. $scope.apBillOut.recordDate = checkItem.recordDate;
  8987. $scope.apBillOut.rate = checkItem.apCheck.rate;
  8988. //必须是同一家客户才能生成对账单,否则提示错误
  8989. if($scope.apBillOut.custUu == ''){
  8990. $scope.apBillOut.custUu = checkItem.apCheck.custUu;
  8991. }else if($scope.apBillOut.custUu !== checkItem.apCheck.custUu){
  8992. $scope.sameCust = false;
  8993. $scope.loading = false;
  8994. toaster.pop('error', '请选择同一家客户');
  8995. }
  8996. //必须是相同币别才能生成对账单,否则提示错误
  8997. if ($scope.apBillOut.currency == '') {
  8998. $scope.apBillOut.currency = checkItem.apCheck.currency;
  8999. } else if ($scope.apBillOut.currency !== checkItem.apCheck.currency) {
  9000. $scope.sameCust = false;
  9001. $scope.loading = false;
  9002. toaster.pop('error', '请选择同一种币别');
  9003. }
  9004. //本次对账数量必须小于总对账数量
  9005. if (checkItem.checkQty > 0) {
  9006. if (checkItem.minThisBilledQty >checkItem.thisBilledQty || checkItem.maxThisBilledQty <checkItem.thisBilledQty) {
  9007. $scope.validQty = false;
  9008. $scope.loading = false;
  9009. toaster.pop('error','本次开票数量,填写有误!');
  9010. }
  9011. } else if (check.qty < 0) {
  9012. $scope.data.maxCheckQty = 0;
  9013. $scope.data.minCheckQty = check.qty;
  9014. if(((-check.qty)-(-check.yCheckQty) < (-check.CheckQty)) || check.CheckQty > 0 || check.CheckQty == 0){
  9015. $scope.validQty = false;
  9016. $scope.loading = false;
  9017. toaster.pop('error','本次开票数量,填写有误!');
  9018. }
  9019. }
  9020. //TODO
  9021. //获取最小时间作为对账区间的起始时间
  9022. if($scope.apBillOut.beginDate == ''){
  9023. $scope.apBillOut.beginDate = checkItem.apCheck.apDate;
  9024. }else{
  9025. $scope.apBillOut.beginDate = $scope.apBillOut.beginDate>checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.beginDate;
  9026. }
  9027. //获取最大时间作为对账区间的截止时间
  9028. if($scope.apBillOut.endDate == ''){
  9029. $scope.apBillOut.endDate = checkItem.apCheck.apDate;
  9030. }else{
  9031. $scope.apBillOut.endDate = $scope.apBillOut.endDate<checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.endDate;
  9032. }
  9033. //应收开票单明细行数据
  9034. $scope.item.price = checkItem.price;
  9035. $scope.item.sourceId = checkItem.id;
  9036. $scope.item.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  9037. $scope.item.NowQty = checkItem.thisBilledQty;
  9038. $scope.item.prodCode = checkItem.prodCode;
  9039. $scope.item.taxrate = checkItem.taxrate;
  9040. //来源表相关信息
  9041. $scope.sourceInfo.sourceId = checkItem.id;
  9042. $scope.sourceInfo.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  9043. $scope.sourceInfo.newBilledQty = ((checkItem.billed || 0) + checkItem.thisBilledQty);
  9044. //sourceInfos.push($scope.sourceInfo);
  9045. $scope.apBillOut.items.push($scope.item);
  9046. $scope.apBillOut.sourceInfos.push($scope.sourceInfo);
  9047. $scope.haveSelected = true;
  9048. }
  9049. });
  9050. //保存生成的开票单,后台同时更新对账单明细表中已开票数
  9051. $scope.saveApBillOut = function () {
  9052. FaApBillOut.saveApBillOut({}, $scope.apBillOut, function (data) {
  9053. $scope.loading = false;
  9054. toaster.pop('success', '成功', '生成开票单成功');
  9055. $state.go('fa.apBillOut_detail', {id: data.id}, {reload:true});
  9056. }, function (response) {
  9057. toaster.pop('error', '生成开票单失败', response.data);
  9058. });
  9059. };
  9060. //如果是同一家客户,生成对账单的同时,关闭模态框
  9061. if($scope.sameCust && $scope.validQty) {
  9062. $scope.saveApBillOut();
  9063. }
  9064. }
  9065. }]);
  9066. /**
  9067. * 客户应付发票
  9068. */
  9069. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  9070. BaseService.scrollBackToTop();
  9071. // 获取当前用户是否为普通用户
  9072. CurrentRole.isUser({}, {}, function (data) {
  9073. $scope.isUser = data.isUser;
  9074. });
  9075. $scope.active = 'all';
  9076. $scope.dateZoneText = '不限';
  9077. $scope.condition = {dateZone: 1};
  9078. /* 时间筛选初始化*/
  9079. var fromDate = new Date();
  9080. var toDate = new Date();
  9081. fromDate.setMonth(fromDate.getMonth() - 1);
  9082. fromDate.setHours(0, 0, 0, 0);
  9083. toDate.setHours(23, 59, 59, 999);
  9084. $scope.condition.dateFrom = fromDate;
  9085. $scope.condition.dateTo = toDate;
  9086. $scope.changeDateZone = function (zone) {
  9087. $scope.condition.dateZone = zone;
  9088. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9089. $scope.condition.$dateZoneOpen = false;
  9090. getDateCondition(zone, $scope.condition);
  9091. $scope.tableParams.page(1);
  9092. $scope.tableParams.reload();
  9093. };
  9094. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9095. $scope.setActive = function (state) {
  9096. if ($scope.active != state) {
  9097. $scope.active = state;
  9098. if ($scope.tableParams.page() == 1)
  9099. $scope.tableParams.reload();
  9100. else
  9101. $scope.tableParams.page(1);
  9102. }
  9103. };
  9104. var getService = function () {
  9105. return FaApBill;
  9106. };
  9107. $scope.tableParams = new ngTableParams({
  9108. page: 1,
  9109. count: 20,
  9110. sorting: {
  9111. date: 'desc'
  9112. }
  9113. }, {
  9114. total: 0,
  9115. counts: [5, 10, 25, 50],
  9116. getData: function ($defer, params) {
  9117. $scope.loading = true;
  9118. var pageParams = params.url();
  9119. pageParams.searchFilter = { // 筛选条件
  9120. keyword: $scope.keyword,
  9121. fromDate: getDateTime($scope.condition.dateFrom),
  9122. endDate: getDateTime($scope.condition.dateTo)
  9123. };
  9124. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  9125. $scope.loading = false;
  9126. if (page) {
  9127. params.total(page.totalElement);
  9128. $defer.resolve(page.content);
  9129. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  9130. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9131. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9132. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  9133. }
  9134. }, function (response) {
  9135. $scope.loading = false;
  9136. toaster.pop('error', '数据加载失败', response.data);
  9137. });
  9138. }
  9139. });
  9140. $scope.openDatePicker = function ($event, item, openParam) {
  9141. $event.preventDefault();
  9142. $event.stopPropagation();
  9143. item[openParam] = !item[openParam];
  9144. };
  9145. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9146. $event.preventDefault();
  9147. $event.stopPropagation();
  9148. item[openParam] = !item[openParam];
  9149. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9150. $scope.tableParams.reload();
  9151. }
  9152. };
  9153. $scope.parseDate = function (dateStr) {
  9154. if (dateStr)
  9155. return Date.parse(dateStr, 'yyyy-MM-dd');
  9156. return new Date();
  9157. };
  9158. // 搜索框回车
  9159. $scope.onSearch = function () {
  9160. $scope.tableParams.page(1);
  9161. $scope.tableParams.reload();
  9162. };
  9163. // 选择查找日期
  9164. $scope.onDateCondition = function () {
  9165. $scope.tableParams.page(1);
  9166. $scope.tableParams.reload();
  9167. };
  9168. // 导出
  9169. $scope.exportXls = function () {
  9170. FaApBill.exportXls({}, {}, function (data) {
  9171. if (data.success){
  9172. window.location.href = 'sale/apBill/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  9173. }
  9174. }, function (response) {
  9175. toaster.pop('error', '数据加载失败', response.data);
  9176. });
  9177. }
  9178. }]);
  9179. /**
  9180. * 客户应付发票详情
  9181. */
  9182. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, $filter, FaApBill, toaster, $stateParams, BaseService, CurrentRole) {
  9183. BaseService.scrollBackToTop();
  9184. // 获取当前用户是否为普通用户
  9185. CurrentRole.isUser({}, {}, function (data) {
  9186. $scope.isUser = data.isUser;
  9187. });
  9188. var loadData = function () {
  9189. FaApBill.getAll({id: $stateParams.id}, function (data) {
  9190. $scope.bill = data;
  9191. $scope.loading = false;
  9192. }, function (response) {
  9193. toaster.pop('error', '', response.data);
  9194. });
  9195. };
  9196. loadData(); // 初始获取单据数据
  9197. }]);
  9198. /**
  9199. * 应付对账单
  9200. */
  9201. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol) {
  9202. BaseService.scrollBackToTop();
  9203. $scope.active = 'all';
  9204. $scope.dateZoneText = '不限';
  9205. $scope.condition = {dateZone: 1};
  9206. /* 时间筛选初始化*/
  9207. var fromDate = new Date();
  9208. var toDate = new Date();
  9209. fromDate.setMonth(fromDate.getMonth() - 1);
  9210. fromDate.setHours(0, 0, 0, 0);
  9211. toDate.setHours(23, 59, 59, 999);
  9212. $scope.condition.dateFrom = fromDate;
  9213. $scope.condition.dateTo = toDate;
  9214. $scope.changeDateZone = function (zone) {
  9215. $scope.condition.dateZone = zone;
  9216. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9217. $scope.condition.$dateZoneOpen = false;
  9218. getDateCondition(zone, $scope.condition);
  9219. $scope.tableParams.page(1);
  9220. $scope.tableParams.reload();
  9221. };
  9222. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9223. $scope.setActive = function (state) {
  9224. if ($scope.active != state) {
  9225. $scope.active = state;
  9226. if ($scope.tableParams.page() == 1)
  9227. $scope.tableParams.reload();
  9228. else
  9229. $scope.tableParams.page(1);
  9230. }
  9231. };
  9232. var getService = function () {
  9233. return FaArCheck;
  9234. };
  9235. $scope.tableParams = new ngTableParams({
  9236. page: 1,
  9237. count: 20,
  9238. sorting: {
  9239. date: 'desc'
  9240. }
  9241. }, {
  9242. total: 0,
  9243. counts: [5, 10, 25, 50],
  9244. getData: function ($defer, params) {
  9245. $scope.loading = true;
  9246. var pageParams = params.url();
  9247. pageParams.searchFilter = {};
  9248. pageParams.searchFilter.keyword = $scope.keyword;
  9249. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9250. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9251. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  9252. $scope.loading = false;
  9253. if (page) {
  9254. params.total(page.totalElement);
  9255. $defer.resolve(page.content);
  9256. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9257. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9258. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9259. }
  9260. }, function (response) {
  9261. $scope.loading = false;
  9262. toaster.pop('error', '数据加载失败', response.data);
  9263. });
  9264. }
  9265. });
  9266. $scope.openDatePicker = function ($event, item, openParam) {
  9267. $event.preventDefault();
  9268. $event.stopPropagation();
  9269. item[openParam] = !item[openParam];
  9270. };
  9271. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9272. $event.preventDefault();
  9273. $event.stopPropagation();
  9274. item[openParam] = !item[openParam];
  9275. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9276. $scope.tableParams.reload();
  9277. }
  9278. };
  9279. // 计算单据的商品总数
  9280. $scope.getTotalProd = function (check) {
  9281. var total = 0;
  9282. if (check.items) {
  9283. angular.forEach(check.items, function (value) {
  9284. total += value.qty;
  9285. });
  9286. }
  9287. return total;
  9288. };
  9289. // 搜索框回车
  9290. $scope.onSearch = function () {
  9291. $scope.tableParams.page(1);
  9292. $scope.tableParams.reload();
  9293. };
  9294. // 选择查找日期
  9295. $scope.onDateCondition = function () {
  9296. $scope.tableParams.page(1);
  9297. $scope.tableParams.reload();
  9298. };
  9299. }]);
  9300. // 应付对账单详情页
  9301. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function ($scope, $stateParams, FaArCheck, toaster, $state, BaseService) {
  9302. BaseService.scrollBackToTop();
  9303. var loadData = function () {
  9304. FaArCheck.get({id: $stateParams.id}, function (data) {
  9305. $scope.order = data;
  9306. $scope.loading = false;
  9307. });
  9308. };
  9309. loadData(); // 初始获取单据数据
  9310. $scope.onReplyClick = function (item, isAgreed) {
  9311. if (isAgreed) {// 同意确认
  9312. FaArCheck.agree({itemId: item.id}, {}, function (data) {
  9313. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  9314. }, function (response) {
  9315. toaster.pop('danger', '确认失败', response.data);
  9316. });
  9317. } else {// 不同意回复
  9318. FaArCheck.disagree({itemId: item.id}, {
  9319. qty: item.$replyQty,
  9320. remark: item.$replyRemark
  9321. }, function (data) {
  9322. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  9323. }, function (response) {
  9324. toaster.pop('danger', '确认失败', response.data);
  9325. });
  9326. }
  9327. };
  9328. // 获取明细的回复记录
  9329. $scope.getReplies = function (item) {
  9330. if (!item.replies) {
  9331. FaArCheck.getReplies({itemId: item.id}, function (data) {
  9332. item.replies = data;
  9333. }, function (response) {
  9334. toaster.pop('danger', '获取对账记录失败', response.data);
  9335. });
  9336. }
  9337. };
  9338. }]);
  9339. //应收对账单列表
  9340. app.controller('PurchaseApCheckCtrl', ['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster', 'ReportService', 'Symbol', 'CurrentRole', function ($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService, Symbol, CurrentRole) {
  9341. BaseService.scrollBackToTop();
  9342. // 获取当前用户是否为普通用户
  9343. CurrentRole.isUser({}, {}, function (data) {
  9344. $scope.isUser = data.isUser;
  9345. });
  9346. $scope.dateZoneText = '不限';
  9347. $scope.condition = {dateZone: 1};
  9348. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9349. $scope.active = 'todo';
  9350. /* 时间筛选初始化*/
  9351. var fromDate = new Date();
  9352. var toDate = new Date();
  9353. fromDate.setMonth(fromDate.getMonth() - 1);
  9354. fromDate.setHours(0, 0, 0, 0);
  9355. toDate.setHours(23, 59, 59, 999);
  9356. $scope.condition.dateFrom = fromDate;
  9357. $scope.condition.dateTo = toDate;
  9358. //打印 对账单
  9359. $scope.print = function (check) {
  9360. var newPage = window.open("about:blank");
  9361. FaApCheck.printPermission({}, function () {
  9362. FaApCheck.printCount({id: check.id}, {});//增加打印此次
  9363. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id, newPage);
  9364. }, function (response) {
  9365. newPage.close();
  9366. toaster.pop('error', '打印失败', response.data);
  9367. });
  9368. };
  9369. //状态
  9370. $scope.setActive = function (state) {
  9371. if ($scope.active != state) {
  9372. $scope.active = state;
  9373. if ($scope.tableParams.page() == 1)
  9374. $scope.tableParams.reload();
  9375. else
  9376. $scope.tableParams.page(1);
  9377. }
  9378. };
  9379. $scope.changeDateZone = function (zone) {
  9380. $scope.condition.dateZone = zone;
  9381. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9382. $scope.condition.$dateZoneOpen = false;
  9383. getDateCondition(zone, $scope.condition);
  9384. $scope.tableParams.page(1);
  9385. $scope.tableParams.reload();
  9386. };
  9387. //获取应收对账单全部
  9388. $scope.tableParams = new ngTableParams({
  9389. page: 1,
  9390. count: 20,
  9391. sorting: {
  9392. recordDate: 'desc'
  9393. }
  9394. }, {
  9395. total: 0,
  9396. counts: [5, 10, 25, 50],
  9397. getData: function ($defer, params) {
  9398. $scope.loading = true;
  9399. var pageParams = params.url();
  9400. pageParams.searchFilter = { // 筛选条件
  9401. keyword: $scope.keyword,
  9402. fromDate: getDateTime($scope.condition.dateFrom),
  9403. endDate: getDateTime($scope.condition.dateTo)
  9404. };
  9405. FaApCheck[getState($scope.active)](BaseService.parseParams(pageParams), function (page) {
  9406. $scope.loading = false;
  9407. if (page) {
  9408. params.total(page.totalElement);
  9409. $scope.data = $defer.resolve(page.content);
  9410. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  9411. }
  9412. }, function (response) {
  9413. $scope.loading = false;
  9414. toaster.pop('error', '数据加载失败', response.data);
  9415. });
  9416. }
  9417. });
  9418. //获得各分类未阅读数量
  9419. var getUnreadCount = function () {
  9420. FaApCheck.getUnreadCount(null, function(data){
  9421. $scope.unread = data;
  9422. });
  9423. };
  9424. getUnreadCount();
  9425. //设置单据已读
  9426. $scope.setOrdersRead = function (id) {
  9427. // 如果单据本身已读,则不发送请求修改数据
  9428. if (!$scope.isUnread(id)){
  9429. return;
  9430. }
  9431. var sourceId = [];
  9432. sourceId.push(id);
  9433. FaApCheck.setRead({}, sourceId, function (message) {
  9434. getUnreadCount();
  9435. });
  9436. };
  9437. //获取未读单据id
  9438. var getUnreadIds = function (){
  9439. FaApCheck.getUnreadIds({}, "", function (message) {
  9440. $scope.unreadCode = message.content;
  9441. });
  9442. };
  9443. getUnreadIds();
  9444. //判断单据是否未读
  9445. $scope.isUnread = function (id){
  9446. for (var i in $scope.unreadCode) {
  9447. if (id == $scope.unreadCode[i]) {
  9448. return true;
  9449. }
  9450. }
  9451. };
  9452. $scope.openDatePicker = function ($event, item, openParam) {
  9453. $event.preventDefault();
  9454. $event.stopPropagation();
  9455. item[openParam] = !item[openParam];
  9456. };
  9457. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9458. $event.preventDefault();
  9459. $event.stopPropagation();
  9460. item[openParam] = !item[openParam];
  9461. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9462. $scope.tableParams.reload();
  9463. }
  9464. };
  9465. // 计算单据的商品总数
  9466. $scope.getTotalProd = function (check) {
  9467. var total = 0;
  9468. if (check.items) {
  9469. angular.forEach(check.items, function (value) {
  9470. total += value.checkQty;
  9471. });
  9472. }
  9473. return total;
  9474. };
  9475. // 搜索框回车
  9476. $scope.onSearch = function () {
  9477. $scope.tableParams.page(1);
  9478. $scope.tableParams.reload();
  9479. };
  9480. // 选择查找日期
  9481. $scope.onDateCondition = function () {
  9482. $scope.tableParams.page(1);
  9483. $scope.tableParams.reload();
  9484. };
  9485. // 导出
  9486. $scope.exportXls = function () {
  9487. FaApCheck.exportXls({}, {}, function (data) {
  9488. if (data.success){
  9489. window.location.href = 'sale/apCheck/xls/list?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  9490. }
  9491. }, function (response) {
  9492. toaster.pop('error', '数据加载失败', response.data);
  9493. });
  9494. }
  9495. }]);
  9496. //应收对账单详情
  9497. app.controller('PurchaseApCheckDetailCtrl', ['$scope', 'toaster', 'FaApCheck', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, toaster, FaApCheck, $stateParams, BaseService, CurrentRole) {
  9498. BaseService.scrollBackToTop();
  9499. // 获取当前用户是否为普通用户
  9500. CurrentRole.isUser({}, {}, function (data) {
  9501. $scope.isUser = data.isUser;
  9502. });
  9503. $scope.haveSelected = true;
  9504. $scope.data = {};
  9505. //控制提交和删除按钮的显示
  9506. $scope.ifShow = true;
  9507. var loadData = function () {
  9508. FaApCheck.getItem({id: $stateParams.id}, function (data) {
  9509. $scope.data = data;
  9510. if ($scope.data.status) {
  9511. } else {
  9512. $scope.ifShow = true;
  9513. }
  9514. }, function (response) {
  9515. toaster.pop('error', '', response.data);
  9516. })
  9517. };
  9518. if ($stateParams.id) {
  9519. loadData();
  9520. }
  9521. $scope.haveSource = false;
  9522. //提交应收对账单
  9523. $scope.submitApCheck = function () {
  9524. FaApCheck.updateStatus({id: $stateParams.id}, {}, function (data) {
  9525. if (data.result) {
  9526. toaster.pop('success', '提示', '提交成功');
  9527. $scope.haveSelected = false;
  9528. window.location.href = '#/fa/apCheck';
  9529. } else {
  9530. $scope.haveSource = true;
  9531. loadData();
  9532. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  9533. $scope.haveSelected = true;
  9534. }
  9535. }, function (response) {
  9536. $scope.loading = false;
  9537. toaster.pop('error', '更新已转数失败', response.data);
  9538. });
  9539. }
  9540. //删除应收对账单的同时更新来源表已转数
  9541. var updateYCheckQty = function () {
  9542. var sourceInfos = [];
  9543. angular.forEach($scope.data.items, function (item) {
  9544. $scope.sourceInfo = {
  9545. sourceId: '',
  9546. sourceTable: '',
  9547. newYCheckQty: ''
  9548. };
  9549. $scope.sourceInfo.sourceId = item.sourceId;
  9550. $scope.sourceInfo.sourceTable = item.sourceTable;
  9551. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  9552. sourceInfos.push($scope.sourceInfo);
  9553. });
  9554. FaApCheck.update({}, sourceInfos, function () {
  9555. }, function (response) {
  9556. $scope.loading = false;
  9557. toaster.pop('error', '更新已转数失败', response.data);
  9558. });
  9559. }
  9560. //删除应收对账单
  9561. $scope.deleteApCheck = function () {
  9562. FaApCheck.deleteApCheck({id: $stateParams.id}, {}, function (data) {
  9563. updateYCheckQty();
  9564. toaster.pop('success', '提示', '删除成功');
  9565. }, function (response) {
  9566. toaster.pop('error', '删除失败', response.data);
  9567. });
  9568. $scope.haveSelected = false;
  9569. }
  9570. //作废应收对账单
  9571. $scope.cancelApCheck = function (check) {
  9572. FaApCheck.cancel({id: check.id}, {}, function (data) {
  9573. $scope.checkResult = false;
  9574. if (data.result) {
  9575. $scope.checkResult = true;
  9576. toaster.pop('success', '提示', '作废成功');
  9577. $scope.tableParams.reload();
  9578. } else {
  9579. toaster.pop('error', '提示', '作废失败');
  9580. }
  9581. }, function (response) {
  9582. $scope.loading = false;
  9583. toaster.pop('error', '作废失败', response.data);
  9584. });
  9585. }
  9586. }]);
  9587. //未对账单据列表
  9588. app.controller('PurchaseApCheckListCtrl', ['$scope', 'FaApCheck', 'toaster', '$state', '$filter', '$modal', 'Vendor', 'DecimalNumber', function ($scope, FaApCheck, toaster, $state, $filter, $modal, Vendor, DecimalNumber) {
  9589. $scope.data = [];// 列表数据
  9590. $scope.condition = {
  9591. $fromOpened: false
  9592. }
  9593. $scope.openDatePicker = function ($event, item, openParam) {
  9594. $event.preventDefault();
  9595. $event.stopPropagation();
  9596. item[openParam] = !item[openParam];
  9597. }
  9598. // 客户联想词
  9599. $scope.getSimilarCustomers = function (value) {
  9600. if (value) {
  9601. return Vendor.getSimilarCustomers({keyword: value}).$promise.then(function (data) {
  9602. return data.map(function (item) {
  9603. return item;
  9604. });
  9605. });
  9606. }
  9607. };
  9608. $scope.onAssociateCustomerClick = function (vendor) {
  9609. if (vendor.apcheck == 0) {
  9610. toaster.pop('info', '提示', '该客户暂未启用平台对账功能');
  9611. $scope.suuorname = '';
  9612. } else {
  9613. $scope.suuorname = vendor.custName;
  9614. }
  9615. }
  9616. //查找客户
  9617. $scope.searchCust = function (suuorname) {
  9618. var modalInstance = $modal.open({
  9619. animation: true,
  9620. templateUrl: 'static/tpl/index/fa/apcheck_customer.html',
  9621. controller: 'SearchCustInfoCtrl',
  9622. size: 'lg',
  9623. resolve: {
  9624. suuorname: function () {
  9625. return suuorname;
  9626. }
  9627. }
  9628. });
  9629. modalInstance.result.then(function (customer) {
  9630. $scope.suuorname = customer.myEnterprise.enName;
  9631. });
  9632. }
  9633. // 点击筛选根据条件选择数据
  9634. // 默认本月
  9635. $scope.sdateTo = new Date();
  9636. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  9637. $scope.condition.uuorname = '';
  9638. $scope.condition.dateFrom = '';
  9639. $scope.condition.dateTo = '';
  9640. $scope.condition.venduuorname = '';
  9641. $scope.condition.factory = '';
  9642. $scope.condition.prodtitle = '';
  9643. $scope.condition.prodspec = '';
  9644. $scope.searchOrder = function (check) {
  9645. $scope.data = [];
  9646. $scope.checkboxes.checked = false;
  9647. $scope.totalMoney = 0;
  9648. $scope.condition.uuorname = $scope.suuorname;
  9649. $scope.condition.factory = $scope.factory
  9650. $scope.condition.prodtitle = $scope.prodtitle;
  9651. $scope.condition.prodspec = $scope.prodspec;
  9652. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9653. $scope.thisdatato = ($scope.sdateTo || 0);
  9654. if ($scope.thisdatato != 0) {
  9655. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9656. } else {
  9657. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9658. }
  9659. $scope.condition.venduuorname = $scope.vuuorname;
  9660. if ($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9661. $scope.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9662. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9663. $scope.searchKeyWord = {
  9664. receiveName: $scope.receiveName,
  9665. factory: $scope.factory,
  9666. prodTitle: $scope.prodTitle,
  9667. prodSpec: $scope.prodSpec,
  9668. taxRate: $scope.taxRate,
  9669. suuorname: $scope.suuorname
  9670. }
  9671. $scope.exportKeywords = encodeURIComponent($scope.searchKeyWord);
  9672. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9673. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9674. if (!$scope.suuorname) {
  9675. toaster.pop('warning', '提示', '请先选择客户');
  9676. document.getElementById('suuorname').focus();//光标默认在客户
  9677. } else {
  9678. $scope.loading = true;
  9679. FaApCheck.getAllByKeywords({
  9680. fromDate: $scope.fromDate,
  9681. endDate: $scope.endDate,
  9682. receiveName: $scope.receiveName,
  9683. factory: $scope.factory,
  9684. prodTitle: $scope.prodTitle,
  9685. prodSpec: $scope.prodSpec,
  9686. taxRate: $scope.taxRate,
  9687. suuorname: $scope.suuorname
  9688. }, function (data) {
  9689. if (data.length > 0) {
  9690. angular.forEach(data, function (item) {
  9691. item.$selected = true;
  9692. });
  9693. $scope.data = data;
  9694. $scope.checkboxes.checked = true;
  9695. $scope.getTotalMoney();
  9696. } else {
  9697. toaster.pop('info', '提示', '当前没有需要对账记录');
  9698. }
  9699. $scope.loading = false;
  9700. }, function (response) {
  9701. $scope.loading = false;
  9702. toaster.pop('error', '提示', response.data);
  9703. });
  9704. }
  9705. }
  9706. }
  9707. $scope.exportApcheckList = function() {
  9708. var url = 'sale/apCheck/xls?fromDate=' + $scope.fromDate + '&endDate=' + $scope.endDate;
  9709. if (angular.isDefined($scope.receiveName)) {
  9710. url = url + '&receiveName=' + $scope.receiveName;
  9711. }
  9712. if (angular.isDefined($scope.factory)) {
  9713. url = url + '&factory=' + $scope.factory;
  9714. }
  9715. if (angular.isDefined($scope.prodTitle)) {
  9716. url = url + '&prodTitle=' + $scope.prodTitle;
  9717. }
  9718. if (angular.isDefined($scope.prodSpec)) {
  9719. url = url + '&prodSpec=' + $scope.prodSpec;
  9720. }
  9721. if (angular.isDefined($scope.suuorname)) {
  9722. url = url + '&suuorname=' + $scope.suuorname;
  9723. }
  9724. if (angular.isDefined($scope.taxRate)) {
  9725. url = url + '&receiveName=' + $scope.taxRate;
  9726. }
  9727. window.location.href = url;
  9728. }
  9729. /**
  9730. * 点击勾选框,选中要转应收对账单的订单
  9731. * */
  9732. $scope.totalMoney = 0;
  9733. $scope.checkboxes = {
  9734. checked: false
  9735. };
  9736. // 点击勾选全部的复选框
  9737. $scope.checkAll = function () {
  9738. $scope.totalMoney = 0;
  9739. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodtitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodspec || $scope.condition.factory);
  9740. var dateFrom = $scope.condition.dateFrom;
  9741. var dateTo = $scope.condition.dateTo;
  9742. angular.forEach($scope.filteredData, function (item) {
  9743. if ((item.pidate >= dateFrom || dateFrom == '') && (item.pidate < dateTo || dateTo == '')) {
  9744. item.$selected = $scope.checkboxes.checked;
  9745. }
  9746. });
  9747. $scope.getTotalMoney();
  9748. };
  9749. //获取已选单据总金额
  9750. $scope.getTotalMoney = function () {
  9751. $scope.totalMoney = 0;
  9752. angular.forEach($scope.data, function (check) {
  9753. if (check.$selected) {
  9754. var price = DecimalNumber.accMul((check.thischeckqty || 0), (check.orderprice || 0));
  9755. $scope.totalMoney += Math.round(price * 100) / 100;
  9756. } else {
  9757. $scope.totalMoney += 0;
  9758. }
  9759. });
  9760. }
  9761. // 点击其中一个明细的复选框
  9762. $scope.checkOne = function (check) {
  9763. var result = true;
  9764. angular.forEach($scope.data, function (item) {
  9765. if (item.$selected != true) {
  9766. result = false;
  9767. return;
  9768. }
  9769. });
  9770. $scope.checkboxes.checked = result;
  9771. };
  9772. $scope.haveSelected = false;
  9773. //生成应收对账单
  9774. $scope.createApCheck = function () {
  9775. //保存应收对账单主记录字段
  9776. $scope.apCheck = {
  9777. custUu: '',
  9778. custName: '',
  9779. enUu: '',
  9780. apDate: '',
  9781. beginDate: '',
  9782. endDate: '',
  9783. checkStatus: '未对账',
  9784. checkAmount: 0,
  9785. currency: '',
  9786. rate: '',
  9787. items: [],
  9788. taxrate: ''
  9789. };
  9790. //保存来源单据相关信息
  9791. var sourceInfos = [];
  9792. //所允许的本次对账最大最小数量
  9793. $scope.data.maxThisCheckQty = 0;
  9794. $scope.data.minThisCheckQty = 0;
  9795. $scope.sameCust = true;
  9796. $scope.validQty = true;
  9797. $scope.loading = true;
  9798. angular.forEach($scope.data, function (check) {
  9799. //保存应收对账单明细行数据
  9800. $scope.item = {
  9801. inoutno: '',
  9802. inoutnodetno: '',
  9803. orderCode: '',
  9804. orderClass: '',
  9805. orderDetno: '',
  9806. price: '',
  9807. checkQty: '',
  9808. amount: '',
  9809. sourceId: '',
  9810. sourceTable: '',
  9811. oldYCheckQty: '',
  9812. status: 0,
  9813. receiveCode: '',
  9814. receiveName: '',
  9815. prodCode: '',
  9816. prodTitle: '',
  9817. prodUnit: '',
  9818. prodSpec: '',
  9819. taxrate: '',
  9820. sendcode: '',
  9821. whname: '',
  9822. };
  9823. //应收对账单明细行来源表信息
  9824. $scope.sourceInfo = {
  9825. sourceId: '',
  9826. sourceTable: '',
  9827. newYCheckQty: ''
  9828. };
  9829. //此次对账后新的已转数
  9830. $scope.newYCheckQty = 0;
  9831. if (check.$selected == true) {
  9832. $scope.apCheck.custName = check.custname;
  9833. $scope.apCheck.enUu = check.enuu;
  9834. $scope.apCheck.checkAmount += (check.thischeckqty || 0) * (check.orderprice || 0);
  9835. $scope.apCheck.apDate = check.pidate;
  9836. $scope.apCheck.rate = check.rate;
  9837. //必须是同一家客户才能生成对账单,否则提示错误
  9838. if ($scope.apCheck.custUu == '') {
  9839. $scope.apCheck.custUu = check.custuu;
  9840. } else if ($scope.apCheck.custUu !== check.custuu) {
  9841. $scope.sameCust = false;
  9842. $scope.loading = false;
  9843. toaster.pop('error', '请选择同一家客户');
  9844. }
  9845. //必须是相同币别才能生成对账单,否则提示错误
  9846. if ($scope.apCheck.currency == '') {
  9847. $scope.apCheck.currency = check.currency;
  9848. } else if ($scope.apCheck.currency !== check.currency) {
  9849. $scope.sameCust = false;
  9850. $scope.loading = false;
  9851. toaster.pop('error', '请选择同一种币别');
  9852. }
  9853. //必须是相同税率才能生成对账单,否则提示错误
  9854. if (!angular.isNumber($scope.apCheck.taxrate)) {
  9855. $scope.apCheck.taxrate = check.taxrate;
  9856. } else if ($scope.apCheck.taxrate != check.taxrate) {
  9857. $scope.sameCust = false;
  9858. $scope.loading = false;
  9859. toaster.pop('error', '请选择相同的税率');
  9860. }
  9861. //本次对账数量必须小于总对账数量
  9862. if (check.qty > 0) {
  9863. $scope.data.maxThisCheckQty = check.qty;
  9864. $scope.data.minThisCheckQty = 0;
  9865. if (check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0) {
  9866. $scope.validQty = false;
  9867. $scope.loading = false;
  9868. toaster.pop('error', '本次对账数量,填写有误!');
  9869. }
  9870. } else if (check.qty < 0) {
  9871. $scope.data.maxThisCheckQty = 0;
  9872. $scope.data.minThisCheckQty = check.qty;
  9873. if (((-check.qty) - (-check.ycheckqty) < (-check.thischeckqty)) || check.thischeckqty > 0 || check.thischeckqty == 0) {
  9874. $scope.validQty = false;
  9875. $scope.loading = false;
  9876. toaster.pop('error', '本次对账数量,填写有误!');
  9877. }
  9878. }
  9879. //获取最小时间作为对账区间的起始时间
  9880. if ($scope.apCheck.beginDate == '') {
  9881. $scope.apCheck.beginDate = check.pidate;
  9882. } else {
  9883. $scope.apCheck.beginDate = $scope.apCheck.beginDate > check.pidate ? check.pidate : $scope.apCheck.beginDate;
  9884. }
  9885. //获取最大时间作为对账区间的截止时间
  9886. if ($scope.apCheck.endDate == '') {
  9887. $scope.apCheck.endDate = check.pidate;
  9888. } else {
  9889. $scope.apCheck.endDate = $scope.apCheck.endDate < check.pidate ? check.pidate : $scope.apCheck.endDate;
  9890. }
  9891. //应收对账单明细行数据
  9892. $scope.item.orderCode = check.ordercode;
  9893. $scope.item.orderClass = check.piclass;
  9894. $scope.item.orderDetno = check.orderdetno;
  9895. $scope.item.price = check.orderprice;
  9896. $scope.item.checkQty = check.thischeckqty;
  9897. $scope.item.amount = (check.thischeckqty || 0) * (check.orderprice || 0);
  9898. $scope.item.sourceId = check.sourceid;
  9899. $scope.item.sourceTable = check.sourcetable;
  9900. $scope.item.oldYCheckQty = check.ycheckqty;
  9901. $scope.item.prodCode = check.prodcode;
  9902. $scope.item.prodTitle = check.prodtitle;
  9903. $scope.item.prodSpec = check.prodspec;
  9904. $scope.item.prodUnit = check.produnit;
  9905. $scope.item.inoutno = check.inoutno;
  9906. $scope.item.inoutnodetno = check.detno;
  9907. $scope.item.taxrate = check.taxrate;
  9908. $scope.item.receiveCode = check.receivecode;
  9909. $scope.item.receiveName = check.receivename;
  9910. $scope.item.sendcode = check.sendcode;
  9911. $scope.item.whname = check.whname;
  9912. //来源表相关信息
  9913. $scope.sourceInfo.sourceid = check.sourceid;
  9914. $scope.sourceInfo.sourcetable = check.sourcetable;
  9915. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  9916. sourceInfos.push($scope.sourceInfo);
  9917. $scope.apCheck.items.push($scope.item);
  9918. $scope.haveSelected = true;
  9919. }
  9920. });
  9921. //保存生成的应收对账单
  9922. $scope.saveApCheck = function () {
  9923. FaApCheck.saveApCheck({}, $scope.apCheck, function (data) {
  9924. $scope.loading = false;
  9925. toaster.pop('success', '成功', '生成应收对账成功');
  9926. $state.go('fa.apCheck_detail', {id: data.id}, {reload: true});
  9927. }, function (response) {
  9928. $scope.loading = false;
  9929. toaster.pop('error', '生成对账单失败', response.data);
  9930. })
  9931. };
  9932. //如果是同一家客户,生成对账单的同时,关闭模态框
  9933. if ($scope.sameCust && $scope.validQty) {
  9934. $scope.saveApCheck();
  9935. }
  9936. }
  9937. }]);
  9938. // 企业信息设置
  9939. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function ($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder) {
  9940. BaseService.scrollBackToTop();
  9941. $scope.loading = true;
  9942. AccountEnterprise.get({}, function (data) {
  9943. $scope.loading = false;
  9944. $scope.enterprise = data;
  9945. if (data.tags) {
  9946. $scope.tags = data.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  9947. } else {
  9948. $scope.tags = [];
  9949. }
  9950. // 获取付款企业信息
  9951. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  9952. $scope.pays = data;
  9953. }, function (response) {
  9954. toaster.pop('error', '提示', response.data);
  9955. });
  9956. });
  9957. // 更新企业信息
  9958. $scope.updateDetailInfo = function () {
  9959. $scope.loading = true;
  9960. $scope.enterprise = $scope.copyEnterprise;
  9961. $scope.enterprise.tags = $scope.tags.join(','); // 将标签数组转换成逗号分隔的字符串,便于储存
  9962. AccountEnterprise.save($scope.enterprise, function () {
  9963. $scope.loading = false;
  9964. $scope.connectionEditing = false;
  9965. toaster.pop('success', '提示', '修改企业信息成功');
  9966. $state.reload();
  9967. }, function (response) {
  9968. $scope.loading = false;
  9969. toaster.pop('error', '修改信息失败', response.data);
  9970. });
  9971. };
  9972. // 申请Saas
  9973. $scope.applySaas = function () {
  9974. if ($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  9975. var modalInstance = $modal.open({
  9976. animation: true,
  9977. templateUrl: 'static/tpl/index/account/applySaas.html',
  9978. controller: 'ApplySaasCtrl',
  9979. resolve: {
  9980. enterprise: function () {
  9981. return angular.copy($scope.enterprise);
  9982. }
  9983. }
  9984. });
  9985. modalInstance.result.then(function () {
  9986. $state.reload();
  9987. }, function () {
  9988. });
  9989. } else {
  9990. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  9991. }
  9992. };
  9993. // 获取收货地址列表
  9994. ShipAddress.shipAddList({}, function (data) {
  9995. $scope.ships = data;
  9996. });
  9997. // 判断是否是代采企业
  9998. DeputyOrder.isDeputyEnterprise({}, function (data) {
  9999. $scope.deputyEnter = data;
  10000. });
  10001. // 获取地址信息
  10002. $http.get('resources/citydata/city.json', {
  10003. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10004. }).then(function (response) {
  10005. $scope.provinces = response.data;
  10006. });
  10007. // 新增收货地址保存
  10008. $scope.saveShipAddress = function (ship) {
  10009. ship.address = ship.province + ship.city + ship.district;
  10010. ShipAddress.saveAddress({}, ship, function (data) {
  10011. if (data.success) {
  10012. ShipAddress.shipAddList({}, function (data) {
  10013. $scope.ships = data;
  10014. });
  10015. toaster.pop('success', '提示', data.success);
  10016. $scope.ship = {receiver: null, usertel: null, phone: null, email: null, province: null, city: null, district: null, addressdet: null, addalias: null, address: null};
  10017. }
  10018. if (data.error) {
  10019. toaster.pop('error', '提示', data.error);
  10020. }
  10021. });
  10022. }
  10023. // 删除收货地址
  10024. $scope.removeShip = function (id, index) {
  10025. ShipAddress.removeShipAddress({id: id}, {}, function (data) {
  10026. $scope.ships.splice(index, 1);
  10027. toaster.pop('success', '提示', '收货地址删除成功');
  10028. }, function (response) {
  10029. toaster.pop('error', '提示', response.data);
  10030. });
  10031. };
  10032. // 编辑收货地址
  10033. $scope.editShip = function (ship) {
  10034. var modalInstance = $modal.open({
  10035. animation: true,
  10036. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  10037. controller: 'ShipAddressCtrl',
  10038. resolve: {
  10039. ship: function () {
  10040. return ship;
  10041. }
  10042. }
  10043. });
  10044. modalInstance.result.then(function () {
  10045. ShipAddress.shipAddList({}, function (data) {
  10046. $scope.ships = data;
  10047. });
  10048. }, function () {
  10049. });
  10050. };
  10051. // 新增付款企业
  10052. $scope.addPayCompany = function () {
  10053. var modalInstance = $modal.open({
  10054. animation: true,
  10055. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  10056. controller: 'PayCompanyCtrl',
  10057. resolve: {
  10058. pay: function () {
  10059. return null;
  10060. }
  10061. }
  10062. });
  10063. modalInstance.result.then(function () {
  10064. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  10065. $scope.pays = data;
  10066. // 获取付款企业信息
  10067. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  10068. $scope.pays = data;
  10069. }, function (response) {
  10070. toaster.pop('error', '提示', response.data);
  10071. });
  10072. }, function (response) {
  10073. toaster.pop('error', '提示', response.data);
  10074. });
  10075. }, function () {
  10076. });
  10077. }
  10078. // 删除付款企业
  10079. $scope.removePay = function (id, index) {
  10080. DeputyOrder.removePayCompany({id: id}, {}, function (data) {
  10081. $scope.pays.splice(index, 1);
  10082. toaster.pop('success', '提示', '付款企业信息删除成功');
  10083. }, function (response) {
  10084. toaster.pop('error', '提示', response.data);
  10085. });
  10086. };
  10087. // 编辑付款企业
  10088. $scope.editPay = function (pay, uu) {
  10089. var modalInstance = $modal.open({
  10090. animation: true,
  10091. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  10092. controller: 'PayCompanyCtrl',
  10093. resolve: {
  10094. pay: function () {
  10095. return pay;
  10096. }
  10097. }
  10098. });
  10099. modalInstance.result.then(function () {
  10100. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  10101. $scope.pays = data;
  10102. }, function (response) {
  10103. toaster.pop('error', '提示', response.data);
  10104. });
  10105. }, function () {
  10106. });
  10107. };
  10108. // 设置logo
  10109. $scope.showImageDialog = function (modal) {
  10110. require(['jquery-uploadify'], function () {
  10111. $modal.open({
  10112. templateUrl: 'static/tpl/index/home/insert.html',
  10113. controller: 'ImageInsertCtrl',
  10114. backdrop: 'static'
  10115. }).result.then(function (image) {
  10116. $scope.imageUrl = image.thumb;
  10117. User.postImageUrl(null, angular.toJson($scope.imageUrl), function (data) {
  10118. $scope.user = data;
  10119. }, function (response) {
  10120. toaster.pop('error', '设置图像失败,' + response.data);
  10121. });
  10122. });
  10123. });
  10124. }
  10125. // 添加经营范围标签
  10126. $scope.addTag = function () {
  10127. if ($scope.tags.indexOf($scope.tag) == -1){
  10128. if (null != $scope.tag && '' != $scope.tag) {
  10129. $scope.tags.push($scope.tag);
  10130. }
  10131. }
  10132. $scope.tag = '';
  10133. }
  10134. // 移除经营范围标签
  10135. $scope.removeTag = function (tag) {
  10136. removeByValue($scope.tags, tag);
  10137. }
  10138. // 获取行业信息
  10139. $http.get('static/data/profession.json').success(function (data) {
  10140. $scope.list = data;
  10141. });
  10142. // 选择行业
  10143. $scope.profession = new Array();
  10144. $scope.showProfession = false;
  10145. $scope.selectProfession = function () {
  10146. $scope.professionArray = [];
  10147. $scope.active = [];
  10148. $scope.showProfession = !$scope.showProfession;
  10149. $scope.profession[0] = $scope.list;
  10150. }
  10151. $scope.isInList = false;
  10152. $scope.isInInput = false;
  10153. $scope.hideList = function () {
  10154. if (!$scope.isInList && !$scope.isInInput && $scope.showProfession) {
  10155. $scope.showProfession = false;
  10156. }
  10157. }
  10158. // 行业子菜单点击
  10159. $scope.onItemClick = function (key, index, value) {
  10160. $scope.active[index] = key;
  10161. if (angular.isString(value)){ // 值为字符串说明点击的是最后一级
  10162. $scope.copyEnterprise.profession = value;
  10163. $scope.showProfession = false;
  10164. return;
  10165. }
  10166. $scope.professionArray = [];
  10167. $scope.profession.splice(index+1);
  10168. if (angular.isArray(value)){ // 值为数组说明下一级是最后一级
  10169. $scope.professionArray = value;
  10170. } else if (angular.isObject(value)) {
  10171. $scope.profession[index+1] = value;
  10172. }
  10173. }
  10174. // 判断值是否为字符串
  10175. $scope.isString = function (value) {
  10176. return angular.isString(value);
  10177. }
  10178. // 拷贝企业数据,在编辑企业数据是使用拷贝数据
  10179. $scope.copyData = function () {
  10180. $scope.copyEnterprise = angular.copy($scope.enterprise);
  10181. if ($scope.enterprise.tags) {
  10182. $scope.tags = $scope.enterprise.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  10183. } else {
  10184. $scope.tags = [];
  10185. }
  10186. }
  10187. }]);
  10188. // 编辑收货地址
  10189. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function ($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  10190. $scope.ship = ship;
  10191. // 获取地址信息
  10192. $http.get('resources/citydata/city.json', {
  10193. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10194. }).then(function (response) {
  10195. $scope.provinces = response.data;
  10196. });
  10197. // 新增收货地址保存
  10198. $scope.saveShipAddress = function (ship) {
  10199. ship.address = ship.province + ship.city + ship.district;
  10200. ShipAddress.saveAddress({}, ship, function (data) {
  10201. if (data.success) {
  10202. toaster.pop('success', '提示', data.success);
  10203. $modalInstance.close();
  10204. }
  10205. if (data.error) {
  10206. toaster.pop('error', '提示', data.error);
  10207. }
  10208. });
  10209. }
  10210. $scope.cancel = function () {
  10211. $modalInstance.dismiss();
  10212. }
  10213. }]);
  10214. // 编辑付款企业信息
  10215. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function ($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  10216. $scope.pay = pay;
  10217. // 获取地址信息
  10218. $http.get('resources/citydata/city.json', {
  10219. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10220. }).then(function (response) {
  10221. $scope.provinces = response.data;
  10222. });
  10223. // 新增收货地址保存
  10224. $scope.savePayCompany = function (pay) {
  10225. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  10226. DeputyOrder.savePaycompany({}, pay, function (data) {
  10227. toaster.pop('success', '提示', '保存成功');
  10228. $modalInstance.dismiss();
  10229. }, function (response) {
  10230. toaster.pop('error', '提示', response.data);
  10231. });
  10232. }
  10233. $scope.cancel = function () {
  10234. $modalInstance.dismiss();
  10235. }
  10236. }]);
  10237. // 申请Saas Controller
  10238. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function ($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http) {
  10239. $scope.enterprise = enterprise;
  10240. $scope.checking = false;
  10241. $scope.$watch('enterprise.enSaasUrl', function () {
  10242. if ($scope.enterprise.enSaasUrl) {
  10243. $http.get('signup/saasUrlEnable', {
  10244. params: {
  10245. enSaasUrl: $scope.enterprise.enSaasUrl
  10246. }
  10247. }).success(function (data) {
  10248. if (data && data == 'true') {
  10249. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  10250. } else {
  10251. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10252. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  10253. }
  10254. }).error(function () {
  10255. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10256. $scope.enSaasUrlErrorInfo = '验证出错';
  10257. });
  10258. } else {
  10259. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10260. }
  10261. });
  10262. var setSaasUrl = function (url) {
  10263. var index = url.indexOf('www.');
  10264. if (index != -1) {//包含www.
  10265. var substr = url.substring(index + 4, url.length);
  10266. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  10267. } else {
  10268. $scope.enterprise.enSaasUrl = getHost(url);
  10269. }
  10270. };
  10271. // 解析获取网址的一级域名
  10272. var getHost = function (host) {
  10273. var newhost;
  10274. var domain;
  10275. var ArrDomain = new Array('.com.cn', '.net.cn', '.org.cn', '.gov.cn', '.com', '.cn', '.tel', '.mobi', '.net', '.org', '.asia', '.me', '.cc', '.name', '.info');//枚举所有后缀
  10276. for (var k in ArrDomain) {
  10277. var re = eval('/\\' + ArrDomain[k] + '$/g');
  10278. newhost = host.replace(re, '');
  10279. if (newhost != host) {
  10280. domain = ArrDomain[k];
  10281. break;
  10282. }
  10283. }
  10284. var hostar = newhost.split('.');
  10285. var s = hostar[hostar.length - 1];
  10286. return s;
  10287. };
  10288. // 设置优企云服域名为官网网址一级域名
  10289. if ($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  10290. $scope.apply = function () {
  10291. $scope.loading = true;
  10292. AccountEnterprise.applySaas({
  10293. enUU: $scope.enterprise.uu,
  10294. enSaasUrl: $scope.enterprise.enSaasUrl,
  10295. enAdminPassword: $scope.enterprise.enAdminPassword
  10296. }, {}, function () {
  10297. $scope.loading = false;
  10298. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  10299. $modalInstance.close();
  10300. }, function (response) {
  10301. $scope.loading = false;
  10302. toaster.pop('error', '申请失败', response.data);
  10303. });
  10304. };
  10305. $scope.cancel = function () {
  10306. $modalInstance.dismiss();
  10307. };
  10308. }]);
  10309. app.controller('UserCtrl', ['$scope', '$filter', 'AuthenticationService', 'AccountUser', 'BaseService', 'ngTableParams', 'toaster', '$modal', '$http', 'ngAlert', 'AccountEnterprise', 'CurrentRole', function ($scope, $filter, AuthenticationService, AccountUser, BaseService, ngTableParams, toaster, $modal, $http, ngAlert, AccountEnterprise, CurrentRole) {
  10310. BaseService.scrollBackToTop();
  10311. $scope.editing = false;
  10312. $scope.loading = true;
  10313. $scope.enterprise = null;
  10314. $scope.searchMthod = false;
  10315. $scope.keyword = null;
  10316. AccountUser.findDistribute({}, function (data) {
  10317. $scope.distributes = data;
  10318. }, function (response) {
  10319. toaster.pop('error', '系统错误', response.data);
  10320. });
  10321. AuthenticationService.getAuthentication().success(function (data) {
  10322. $scope.loading = false;
  10323. $scope.user = data;
  10324. });
  10325. var users = [];
  10326. var getMangagerInfo = function() {
  10327. CurrentRole.isManager({}, function(data) {
  10328. $scope.isManager = data.isManager || $scope.user.sys;
  10329. });
  10330. CurrentRole.roles({}, function(data) {
  10331. $scope.roles = data.count || $scope.user.sys;
  10332. });
  10333. };
  10334. getMangagerInfo();
  10335. $scope.tableParams = new ngTableParams({
  10336. page: 1,
  10337. count: 20,
  10338. sorting: {
  10339. userName: 'asc'
  10340. }
  10341. }, {
  10342. total: 0,
  10343. counts: [15, 25, 50, 100],
  10344. getData: function ($defer, params) {
  10345. $scope.loading = true;
  10346. var pageParams = params.url();
  10347. pageParams.keyword = $scope.keyword;
  10348. $scope.tip = $scope.keyword;
  10349. AccountUser.getAll.call(null, BaseService.parseParams(pageParams), function (page) {
  10350. $scope.loading = false;
  10351. if (page) {
  10352. params.total(page.totalElement);
  10353. $defer.resolve(page.content);
  10354. users = page.content;
  10355. if(users.length > 0) {
  10356. if(users.length > 0) {
  10357. angular.forEach(users, function (user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  10358. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  10359. $scope.user.userIdcode = user.userIdcode;
  10360. }
  10361. });
  10362. }
  10363. }
  10364. }
  10365. }, function (response) {
  10366. $scope.loading = false;
  10367. toaster.pop('error', '数据加载失败', response.data);
  10368. });
  10369. }
  10370. });
  10371. $scope.onSearch = function(keyword) {
  10372. $scope.keyword = keyword;
  10373. $scope.tableParams.reload();
  10374. $scope.tableParams.page(1);
  10375. }
  10376. $scope.saveUser = function () {
  10377. $scope.loading = true;
  10378. AccountUser.update({}, $scope.user, function (data) {
  10379. $scope.loading = false;
  10380. toaster.pop('success', '提示', '修改用户信息成功');
  10381. AuthenticationService.getAuthentication().success(function (data) {
  10382. $scope.user = data;
  10383. });
  10384. loadUsers();
  10385. $scope.editing = false;
  10386. }, function (reponse) {
  10387. $scope.loading = false;
  10388. toaster.pop('error', '失败', reponse.data);
  10389. });
  10390. };
  10391. $scope.updatePassword = function () {
  10392. var newPage = window.open("about:black");
  10393. AccountUser.getUpdatePasswordUrl({returnUrl: window.location.href}, function (data) {
  10394. newPage.location.href = data.url;
  10395. });
  10396. };
  10397. $scope.updateDetail = function () {
  10398. var newPage = window.open("about:black");
  10399. AccountUser.getCloudCenterUrl({}, function (data) {
  10400. newPage.location.href = data.url;
  10401. });
  10402. }
  10403. $scope.newUser = {};
  10404. //弹出添加用户模态框
  10405. $scope.addExistUser = function () {
  10406. var modalInstance = $modal.open({
  10407. animation: true,
  10408. templateUrl: 'static/tpl/index/account/addExistUser.html',
  10409. controller: 'AddExistUserCtrl'
  10410. });
  10411. modalInstance.result.then(function () {
  10412. $scope.userTelSuccess = false;
  10413. $scope.userTelError = false;
  10414. $scope.tableParams.reload();
  10415. }, function () {
  10416. });
  10417. };
  10418. /**
  10419. * 添加未注册用户
  10420. */
  10421. $scope.submit = false;
  10422. $scope.addUser = function () {
  10423. $scope.submit = true;
  10424. $scope.adding = true;
  10425. $scope.loading = true;
  10426. AccountUser.save({}, $scope.newUser, function (data) {
  10427. $scope.loading = false;
  10428. $scope.submit = false;
  10429. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  10430. $scope.newUser = {userSex: 'M'};
  10431. $scope.tableParams.reload();
  10432. $scope.adding = false;
  10433. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10434. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10435. $scope.userTelSuccess = false;
  10436. $scope.userTelError = false;
  10437. $scope.userEmailSuccess = false;
  10438. $scope.userEmailError = false;
  10439. }, function (response) {
  10440. $scope.submit = false;
  10441. $scope.loading = false;
  10442. toaster.pop('error', '错误', response.data);
  10443. });
  10444. };
  10445. /**
  10446. * 验证手机号是否可用
  10447. */
  10448. $scope.telValid = function (tel) {
  10449. if (tel) {
  10450. $http.get('account/user/telEnable', {
  10451. params: {
  10452. tel: tel
  10453. }
  10454. }).success(function (data) {
  10455. data = eval(data);
  10456. if (data == true) {
  10457. $scope.newUserForm.newUserTel.$setValidity('available', true);
  10458. $scope.userTelSuccess = true;
  10459. $scope.userTelError = false;
  10460. } else {
  10461. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10462. $scope.userTelError = true;
  10463. $scope.userTelSuccess = false;
  10464. if (tel.length == 11)
  10465. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  10466. }
  10467. }).error(function () {
  10468. $scope.userTelSuccess = false;
  10469. $scope.userTelError = true;
  10470. });
  10471. } else {
  10472. $scope.userTelSuccess = false;
  10473. $scope.userTelError = false;
  10474. }
  10475. };
  10476. /**
  10477. * 验证邮箱是否可用
  10478. */
  10479. $scope.emailValid = function (email) {
  10480. if (email) {
  10481. $http.get('account/user/emailEnable', {
  10482. params: {
  10483. email: email
  10484. }
  10485. }).success(function (data) {
  10486. data = eval(data);
  10487. if (data == true) {
  10488. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  10489. $scope.userEmailSuccess = true;
  10490. $scope.userEmailError = false;
  10491. } else {
  10492. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10493. $scope.userEmailError = true;
  10494. $scope.userEmailSuccess = false;
  10495. }
  10496. }).error(function () {
  10497. $scope.userEmailError = true;
  10498. $scope.userEmailSuccess = false;
  10499. });
  10500. } else {
  10501. $scope.userEmailError = false;
  10502. $scope.userEmailSuccess = false;
  10503. }
  10504. };
  10505. /**
  10506. * 删除用户
  10507. */
  10508. $scope.removeUser = function (user) {
  10509. new ngAlert({
  10510. title: '提示',
  10511. content: '确定删除用户(' + user.userName + ')吗?'
  10512. }, function () {
  10513. AccountUser.remove({uu: user.userUU}, function () {
  10514. toaster.pop('success', '提示', '用户删除成功。');
  10515. loadUsers();
  10516. }, function (response) {
  10517. toaster.pop('error', '删除失败', response.data);
  10518. });
  10519. });
  10520. };
  10521. // 编辑用户的角色
  10522. $scope.editUserRole = function (user) {
  10523. var modalInstance = $modal.open({
  10524. animation: true,
  10525. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  10526. controller: 'UserRoleCtrl',
  10527. resolve: {
  10528. user: function () {
  10529. return user;
  10530. }
  10531. }
  10532. });
  10533. modalInstance.result.then(function (changed, checked) {
  10534. if (changed) {
  10535. if (checked)
  10536. $scope.newUser.roles = checked;
  10537. else
  10538. loadUsers();
  10539. }
  10540. });
  10541. };
  10542. // 为用户分配角色(删除企业)
  10543. $scope.removeVendor = function (user) {
  10544. var resultRole = true;
  10545. angular.forEach(user.roles, function (role) {
  10546. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10547. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10548. resultRole = false;
  10549. return;
  10550. }
  10551. });
  10552. if (resultRole) {
  10553. var modalInstance = $modal.open({
  10554. animation: true,
  10555. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  10556. controller: 'RemoveVendorCtrl',
  10557. resolve: {
  10558. user: function () {
  10559. return user;
  10560. }
  10561. }
  10562. });
  10563. }
  10564. };
  10565. // 为用户分配角色(添加企业)
  10566. $scope.addVendor = function (user, isIssy) {
  10567. if (!$scope.roles) {
  10568. toaster.pop('error', '提示', '你不是管理员或销售经理,无权限分配!请立即联系管理员');
  10569. return;
  10570. }
  10571. var resultRole = true;
  10572. angular.forEach(user.roles, function (role) {
  10573. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10574. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10575. resultRole = false;
  10576. return;
  10577. }
  10578. })
  10579. if (resultRole) {
  10580. var modalInstance = $modal.open({
  10581. animation: true,
  10582. templateUrl: 'static/tpl/index/account/add_vendor.html',
  10583. controller: 'AddVendorCtrl',
  10584. resolve: {
  10585. user: function () {
  10586. return user;
  10587. }
  10588. }
  10589. });
  10590. modalInstance.result.then(function (changed, checked) {
  10591. if (changed) {
  10592. if (checked)
  10593. $scope.newUser.roles = checked;
  10594. else
  10595. loadUsers();
  10596. }
  10597. });
  10598. }
  10599. };
  10600. }]);
  10601. // 登录手机号码验证
  10602. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function ($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout) {
  10603. $scope.user = user;
  10604. $scope.cancel = function () {
  10605. $modalInstance.close();
  10606. }
  10607. }]);
  10608. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10609. $scope.checkboxes = {
  10610. checked: false
  10611. };
  10612. $scope.loading = true;
  10613. AccountUser.findChooseVendor({uu: user.userUU}, function (data) {
  10614. $scope.enters = data;
  10615. $scope.loading = false;
  10616. angular.forEach($scope.enters, function (item) {
  10617. item:{
  10618. $selected:true;
  10619. }
  10620. });
  10621. })
  10622. // 点击勾选全部的复选框
  10623. $scope.checkAll = function () {
  10624. angular.forEach($scope.enters, function (item) {
  10625. item.$selected = $scope.checkboxes.checked;
  10626. });
  10627. };
  10628. // 点击其中一个明细的复选框
  10629. $scope.checkOne = function (vendor) {
  10630. var result = true;
  10631. angular.forEach($scope.enters, function (item) {
  10632. if (item.$selected != true) {
  10633. result = false;
  10634. return;
  10635. }
  10636. });
  10637. $scope.checkboxes.checked = result;
  10638. };
  10639. $scope.close = function (save) {
  10640. var chooseResult = [];
  10641. if (save) {
  10642. if (user.userUU) {
  10643. angular.forEach($scope.enters, function (item, i) {
  10644. if (item.$selected) {
  10645. chooseResult.push(item.id);
  10646. }
  10647. });
  10648. if (chooseResult.length > 0) {
  10649. $scope.loading = true;
  10650. AccountUser.removeChooseVendor({uu: user.userUU}, chooseResult, function (data) {
  10651. $scope.loading = false;
  10652. toaster.pop('success', '提示', '删除成功');
  10653. $modalInstance.close(false);
  10654. }, function (response) {
  10655. $scope.loading = false;
  10656. toaster.pop('error', '删除失败', response.data);
  10657. $modalInstance.close(false);
  10658. })
  10659. } else {
  10660. toaster.pop('error', '删除失败', "您未勾选任何记录");
  10661. }
  10662. } else {
  10663. $modalInstance.close(true, $scope.checkboxes.checked);
  10664. }
  10665. } else {
  10666. $modalInstance.close(false);
  10667. }
  10668. };
  10669. }]);
  10670. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10671. $scope.checkboxes = {
  10672. checked: false
  10673. };
  10674. $scope.loading = true;
  10675. AccountUser.findVendor({uu: user.userUU}, function (data) {
  10676. $scope.enters = data;
  10677. $scope.loading = false;
  10678. })
  10679. // 点击勾选全部的复选框
  10680. $scope.checkAll = function () {
  10681. angular.forEach($scope.enters, function (item) {
  10682. item.distribute = $scope.checkboxes.checked;
  10683. });
  10684. };
  10685. // 点击其中一个明细的复选框
  10686. $scope.checkOne = function (vendor) {
  10687. var result = true;
  10688. angular.forEach($scope.enters, function (item) {
  10689. if (item.distribute != true) {
  10690. result = false;
  10691. return;
  10692. }
  10693. });
  10694. $scope.checkboxes.checked = result;
  10695. };
  10696. $scope.close = function (save) {
  10697. var chooseResult = [];
  10698. if (save) {
  10699. if (user.userUU) {
  10700. angular.forEach($scope.enters, function (item, i) {
  10701. chooseResult.push(item);
  10702. });
  10703. if (chooseResult.length > 0) {
  10704. $scope.loading = true;
  10705. AccountUser.addVendor({uu: user.userUU}, chooseResult, function (data) {
  10706. $scope.loading = false;
  10707. toaster.pop('success', '提示', '保存成功');
  10708. $modalInstance.close(false);
  10709. }, function (response) {
  10710. $scope.loading = false;
  10711. toaster.pop('error', '保存失败', response.data);
  10712. $modalInstance.close(false);
  10713. })
  10714. } else {
  10715. toaster.pop('error', '保存失败', "您未勾选任何记录");
  10716. }
  10717. } else {
  10718. $modalInstance.close(true, $scope.checkboxes.checked);
  10719. }
  10720. } else {
  10721. $modalInstance.close(false);
  10722. }
  10723. };
  10724. }]);
  10725. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountRole, AccountUser, toaster) {
  10726. $scope.checked = [];
  10727. $scope.master = [];
  10728. AccountRole.query({}, function (data) {
  10729. if (user && data) {
  10730. var rs = [], checked = [];
  10731. angular.forEach(user.roles, function (r) {
  10732. rs.push(r.id);
  10733. });
  10734. angular.forEach(data, function (d) {
  10735. if (rs.indexOf(d.id) > -1) {
  10736. d.$checked = true;
  10737. checked.push(d);
  10738. }
  10739. });
  10740. }
  10741. $scope.roles = data;
  10742. $scope.checked = checked;
  10743. $scope.master = angular.copy($scope.checked);
  10744. });
  10745. $scope.select = function (role) {
  10746. role.$checked = !role.$checked;
  10747. if (role.$checked) {
  10748. if (role.desc === '管理员' || role.desc === '普通用户') {
  10749. $scope.checked = [];
  10750. angular.forEach($scope.roles, function (r) {
  10751. r.$checked = false;
  10752. });
  10753. role.$checked = true;
  10754. $scope.checked.push(role);
  10755. } else {
  10756. angular.forEach( $scope.checked, function (r, i) {
  10757. if (r.desc === '管理员' || r.desc === '普通用户') {
  10758. $scope.checked.splice(i, 1);
  10759. }
  10760. });
  10761. angular.forEach($scope.roles, function (r) {
  10762. if (r.desc === '管理员' || r.desc === '普通用户') {
  10763. r.$checked = false;
  10764. }
  10765. });
  10766. $scope.checked.push(role);
  10767. }
  10768. } else {
  10769. angular.forEach($scope.checked, function (c, i) {
  10770. if (c.id == role.id)
  10771. $scope.checked.splice(i, 1);
  10772. });
  10773. }
  10774. };
  10775. $scope.isChanged = function () {
  10776. return !angular.equals($scope.master, $scope.checked);
  10777. };
  10778. $scope.close = function (save) {
  10779. if (save) {
  10780. if (user.userUU) {
  10781. user.roles = $scope.checked;
  10782. AccountUser.updateRole({}, user, function () {
  10783. toaster.pop('success', '提示', '保存成功');
  10784. $modalInstance.close(true);
  10785. }, function (response) {
  10786. toaster.pop('error', '保存失败', response.data);
  10787. });
  10788. } else {
  10789. $modalInstance.close(true, $scope.checked);
  10790. }
  10791. } else {
  10792. $modalInstance.close(false);
  10793. }
  10794. };
  10795. }]);
  10796. // 修改密码Controller
  10797. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10798. $scope.user = user;
  10799. $scope.checking = false;
  10800. //输入原密码后验证原密码是否正确
  10801. $scope.checkPassword = function (password) {
  10802. $scope.checking = true;
  10803. $scope.checkSuccess = false;
  10804. $scope.checkFailed = false;
  10805. AccountUser.checkPassword({password: password}, function (data) {
  10806. $scope.checkSuccess = true;
  10807. $scope.checking = false;
  10808. $scope.checkFailed = false;
  10809. }, function (response) {
  10810. $scope.checkFailed = true;
  10811. $scope.checking = false;
  10812. $scope.checkSuccess = false;
  10813. });
  10814. };
  10815. //修改密码
  10816. $scope.ok = function () {
  10817. if ($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  10818. AccountUser.updatePassword({
  10819. password: $scope.user.password,
  10820. newPassword: $scope.user.newPassword
  10821. }, {}, function (data) {
  10822. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  10823. toaster.pop('success', '成功', tip);
  10824. $scope.user.password = null;
  10825. $scope.user.newPassword = null;
  10826. $scope.user.newPassword1 = null;
  10827. $scope.checking = false;
  10828. $scope.checkSuccess = false;
  10829. $scope.checkFailed = false;
  10830. $modalInstance.close();
  10831. }, function (response) {
  10832. toaster.pop('error', '错误', response.data);
  10833. });
  10834. } else {
  10835. toaster.pop('error', '错误', '重复密码不一致');
  10836. }
  10837. };
  10838. $scope.cancel = function () {
  10839. $modalInstance.dismiss();
  10840. };
  10841. }]);
  10842. /*
  10843. * 绑定用户到企业
  10844. */
  10845. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function ($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster) {
  10846. $scope.searching = false;
  10847. //根据输入的内容查找用户
  10848. $scope.searchUser = function (keyWord) {
  10849. $scope.searching = true;
  10850. $scope.searchSuccess = false;
  10851. $scope.searchFailed = false;
  10852. $scope.illegalError = false;
  10853. $scope.reBindError = false;
  10854. $scope.okDisabled = false;
  10855. FuzzySearch.searchUser({keyWord: keyWord}, function (data) {
  10856. $scope.searchSuccess = true;
  10857. $scope.searchFailed = false;
  10858. $scope.user = data; //查询到的用户
  10859. }, function (response) {
  10860. $scope.searchSuccess = false;
  10861. $scope.searchFailed = true;
  10862. });
  10863. };
  10864. //确认绑定
  10865. $scope.ok = function (keyWord) {
  10866. AuthenticationService.getAuthentication().success(function (data) {
  10867. $scope.currentUser = data; //当前登录的用户(管理员)
  10868. //不可自己绑定自己
  10869. if ($scope.currentUser.userUU == $scope.user.userUU) {
  10870. $scope.illegalError = true;
  10871. $scope.okDisabled = true;
  10872. return false;
  10873. }
  10874. //用户未绑定到任何企业时
  10875. if (!$scope.user.enterprises) {
  10876. //正常绑定
  10877. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  10878. $scope.okDisabled = true;
  10879. toaster.pop("success", "提示", "用户绑定成功");
  10880. $modalInstance.close(true);
  10881. }, function (response) {
  10882. });
  10883. return true;
  10884. }
  10885. //用户已绑定到某些企业时
  10886. for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
  10887. if ($scope.currentUser.enterprises[i].current) {
  10888. for (var j = 0; j < $scope.user.enterprises.length; j++) {
  10889. //该用户已绑定到当前企业,不可重复绑定
  10890. if ($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu) {
  10891. $scope.reBindError = true;
  10892. $scope.okDisabled = true;
  10893. return false;
  10894. }
  10895. }
  10896. //该用户未绑定到当前企业,可以进行绑定
  10897. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  10898. $scope.okDisabled = true;
  10899. toaster.pop("success", "提示", "用户绑定成功");
  10900. $modalInstance.close(true);
  10901. }, function (response) {
  10902. console.log("绑定失败!");
  10903. });
  10904. }
  10905. }
  10906. });
  10907. };
  10908. $scope.cancel = function () {
  10909. $modalInstance.dismiss();
  10910. };
  10911. }]);
  10912. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function ($scope, BaseService, ngTableParams, ErpLog, UsageLog) {
  10913. $scope.erpParams = new ngTableParams({
  10914. page: 1,
  10915. count: 20,
  10916. sorting: {
  10917. time: 'desc'
  10918. }
  10919. }, {
  10920. total: 0,
  10921. counts: [5, 10, 25, 50],
  10922. getData: function ($defer, params) {
  10923. $scope.loading = true;
  10924. ErpLog.get(BaseService.parseParams(params.url()), function (page) {
  10925. $scope.loading = false;
  10926. if (page) {
  10927. params.total(page.totalElements);
  10928. $defer.resolve(page.content);
  10929. }
  10930. }, function (response) {
  10931. $scope.loading = false;
  10932. toaster.pop('error', '数据加载失败', response.data);
  10933. });
  10934. }
  10935. });
  10936. $scope.usageParams = new ngTableParams({
  10937. page: 1,
  10938. count: 20,
  10939. sorting: {
  10940. time: 'desc'
  10941. }
  10942. }, {
  10943. total: 0,
  10944. counts: [5, 10, 25, 50],
  10945. getData: function ($defer, params) {
  10946. $scope.loading = true;
  10947. UsageLog.get(BaseService.parseParams(params.url()), function (page) {
  10948. $scope.loading = false;
  10949. if (page) {
  10950. params.total(page.totalElements);
  10951. $defer.resolve(page.content);
  10952. }
  10953. }, function (response) {
  10954. $scope.loading = false;
  10955. toaster.pop('error', '数据加载失败', response.data);
  10956. });
  10957. }
  10958. });
  10959. }]);
  10960. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function ($scope, AccountResource) {
  10961. AccountResource.query({}, function (data) {
  10962. if (data && data.length > 0) {
  10963. data[0].$open = true;
  10964. }
  10965. $scope.resources = data;
  10966. });
  10967. }]);
  10968. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function ($scope, $modal, AccountRole) {
  10969. $scope.roles = {};
  10970. var getData = function () {
  10971. AccountRole.query({}, function (data) {
  10972. var defaults = [], custom = [];
  10973. angular.forEach(data, function (d) {
  10974. if (d.isdefault == 1)
  10975. defaults.push(d);
  10976. else
  10977. custom.push(d);
  10978. });
  10979. $scope.roles = {defaults: defaults, custom: custom};
  10980. });
  10981. };
  10982. getData();
  10983. $scope.editRole = function (role) {
  10984. var modalInstance = $modal.open({
  10985. animation: true,
  10986. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  10987. controller: 'RoleEditCtrl',
  10988. resolve: {
  10989. role: function () {
  10990. return role;
  10991. }
  10992. }
  10993. });
  10994. modalInstance.result.then(function (added) {
  10995. added && (getData());
  10996. });
  10997. };
  10998. }]);
  10999. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', 'CurrentRole', 'AuthenticationService', function ($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService, CurrentRole, AuthenticationService) {
  11000. BaseService.scrollBackToTop();
  11001. // 获取当前用户是否为管理员
  11002. AuthenticationService.getAuthentication().success(function (data) {
  11003. $scope.loading = false;
  11004. $scope.user = data;
  11005. });
  11006. CurrentRole.isManager({}, {}, function (data) {
  11007. $scope.isManager = data.isManager || $scope.user.sys;
  11008. });
  11009. $scope.role = role;
  11010. $scope.master = angular.copy($scope.role);
  11011. var isNew = role == null;
  11012. $scope.cancel = function () {
  11013. $modalInstance.close(false);
  11014. };
  11015. AccountResource.query({}, function (data) {
  11016. if (data && data.length > 0) {
  11017. if (role && role.resourceItems) {
  11018. var rs = [];// 已分配的资源的id
  11019. angular.forEach(role.resourceItems, function (item) {
  11020. rs.push(item.id);
  11021. });
  11022. angular.forEach(data, function (resource) {
  11023. var c = 0;
  11024. angular.forEach(resource.items, function (item) {
  11025. if (rs.indexOf(item.id) > -1) {
  11026. item.$checked = true;
  11027. c += 1;
  11028. }
  11029. });
  11030. resource.$checked = c == resource.items.length;
  11031. });
  11032. }
  11033. $scope.resourceItems = data[0].items;
  11034. data[0].$active = true;
  11035. }
  11036. $scope.resources = data;
  11037. $timeout(function () {
  11038. angular.forEach($scope.resources, function (resource) {
  11039. var c = 0;
  11040. angular.forEach(resource.items, function (item) {
  11041. item.$checked && (c += 1);
  11042. });
  11043. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  11044. });
  11045. }, 100);
  11046. });
  11047. $scope.onItemClick = function (resource) {
  11048. $scope.resourceItems = resource.items;
  11049. angular.forEach($scope.resources, function (r) {
  11050. r.$active = false;
  11051. });
  11052. resource.$active = true;
  11053. };
  11054. var getChecked = function () {
  11055. var items = [];
  11056. angular.forEach($scope.resources, function (resource) {
  11057. angular.forEach(resource.items, function (item) {
  11058. item.$checked && (items.push(item));
  11059. });
  11060. });
  11061. $scope.role.resourceItems = items;
  11062. };
  11063. $scope.onResourceChange = function (resource) {
  11064. angular.forEach(resource.items, function (item) {
  11065. item.$checked = resource.$checked;
  11066. });
  11067. getChecked();
  11068. };
  11069. $scope.onItemChange = function () {
  11070. angular.forEach($scope.resources, function (resource) {
  11071. if (resource.$active) {
  11072. var c = 0;
  11073. angular.forEach(resource.items, function (item) {
  11074. item.$checked && (c += 1);
  11075. });
  11076. resource.$checked = (c == resource.items.length);
  11077. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  11078. }
  11079. });
  11080. getChecked();
  11081. };
  11082. $scope.isChanged = function (formData) {
  11083. if (!$scope.master)
  11084. return true;
  11085. return !angular.equals(formData, $scope.master);
  11086. };
  11087. $scope.save = function () {
  11088. $scope.master = angular.copy($scope.role);
  11089. AccountRole.save($scope.master, function () {
  11090. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
  11091. $modalInstance.close(true);
  11092. }, function (response) {
  11093. toaster.pop('error', '错误', response.data);
  11094. });
  11095. };
  11096. $scope.del = function () {
  11097. new ngAlert({
  11098. title: '提示',
  11099. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  11100. }, function () {
  11101. AccountRole.remove({id: role.id}, {}, function () {
  11102. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  11103. $modalInstance.close(true);
  11104. }, function (response) {
  11105. toaster.pop('error', '错误', response.data);
  11106. });
  11107. })
  11108. };
  11109. $scope.updateDefault = function () {
  11110. new ngAlert({
  11111. title: '提示',
  11112. content: '确定把(' + $scope.role.desc + ')信息更新到标准库吗?'
  11113. }, function () {
  11114. AccountRole.updateDefault({desc: $scope.role.desc}, $scope.role.resourceItems, function () {
  11115. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 更新成功');
  11116. $modalInstance.close(true);
  11117. }, function (response) {
  11118. toaster.pop('error', '错误', response.data);
  11119. });
  11120. })
  11121. }
  11122. $scope.recover = function () {
  11123. new ngAlert({
  11124. title: '提示',
  11125. content: '确定将“' + $scope.role.desc + '”恢复默认权限吗?'
  11126. }, function () {
  11127. AccountRole.recover({roleId: role.id}, {}, function () {
  11128. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 恢复默认权限成功');
  11129. $modalInstance.close(true);
  11130. }, function (response) {
  11131. toaster.pop('error', '错误', response.data);
  11132. });
  11133. })
  11134. };
  11135. }]);
  11136. /**
  11137. * 委外订单
  11138. */
  11139. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole',
  11140. function ($scope, $filter, MakeOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  11141. BaseService.scrollBackToTop();
  11142. // 获取当前用户是否为普通用户
  11143. CurrentRole.isUser({}, {}, function (data) {
  11144. $scope.isUser = data.isUser;
  11145. });
  11146. $scope.active = 'todo';
  11147. $scope.dateZoneText = '不限';
  11148. $scope.condition = {dateZone: 1};
  11149. /* 时间筛选初始化*/
  11150. var fromDate = new Date();
  11151. var toDate = new Date();
  11152. fromDate.setMonth(fromDate.getMonth() - 1);
  11153. fromDate.setHours(0, 0, 0, 0);
  11154. toDate.setHours(23, 59, 59, 999);
  11155. $scope.condition.dateFrom = fromDate;
  11156. $scope.condition.dateTo = toDate;
  11157. $scope.changeDateZone = function (zone) {
  11158. $scope.condition.dateZone = zone;
  11159. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11160. $scope.condition.$dateZoneOpen = false;
  11161. getDateCondition(zone, $scope.condition);
  11162. $scope.tableParams.page(1);
  11163. $scope.tableParams.reload();
  11164. };
  11165. $scope.setActive = function (state) {
  11166. if ($scope.active != state) {
  11167. $scope.active = state;
  11168. if ($scope.tableParams.page() == 1)
  11169. $scope.tableParams.reload();
  11170. else
  11171. $scope.tableParams.page(1);
  11172. }
  11173. };
  11174. var getService = function () {
  11175. return MakeOrder;
  11176. };
  11177. $scope.tableParams = new ngTableParams({
  11178. page: 1,
  11179. count: 20,
  11180. sorting: {
  11181. date: 'desc'
  11182. }
  11183. }, {
  11184. total: 0,
  11185. counts: [5, 10, 25, 50],
  11186. getData: function ($defer, params) {
  11187. $scope.loading = true;
  11188. var pageParams = params.url();
  11189. pageParams.searchFilter = {
  11190. keyword: $scope.keyword,
  11191. fromDate: getDateTime($scope.condition.dateFrom),
  11192. endDate: getDateTime($scope.condition.dateTo)
  11193. };
  11194. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11195. $scope.loading = false;
  11196. if (page) {
  11197. params.total(page.totalElement);
  11198. $defer.resolve(page.content);
  11199. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11200. }
  11201. }, function (response) {
  11202. $scope.loading = false;
  11203. toaster.pop('error', '数据加载失败', response.data);
  11204. });
  11205. }
  11206. });
  11207. //获得各分类未阅读数量
  11208. var getUnreadCount = function () {
  11209. MakeOrder.getUnreadCount(null, function (data) {
  11210. $scope.unread = data;
  11211. });
  11212. };
  11213. getUnreadCount();
  11214. //设置单据已读
  11215. $scope.setOrdersRead = function (id) {
  11216. // 如果单据本身已读,则不发送请求修改数据
  11217. if (!$scope.isUnread(id)){
  11218. return;
  11219. }
  11220. var sourceId = [];
  11221. sourceId.push(id);
  11222. MakeOrder.setRead({}, sourceId, function (message) {
  11223. // $scope.getUnreadIds();
  11224. getUnreadCount();
  11225. });
  11226. };
  11227. $scope.setOrdersReadByState = function () {
  11228. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  11229. return;
  11230. }
  11231. MakeOrder.setReadByState({}, function () {
  11232. getUnreadIds();
  11233. getUnreadCount();
  11234. });
  11235. };
  11236. var getUnreadIds = function () {
  11237. MakeOrder.getUnreadIds({}, "", function (message) {
  11238. $scope.unreadCode = message.content;
  11239. });
  11240. };
  11241. getUnreadIds();
  11242. $scope.isUnread = function (id) {
  11243. for (var i in $scope.unreadCode) {
  11244. if (id == $scope.unreadCode[i]) {
  11245. return true;
  11246. }
  11247. }
  11248. };
  11249. $scope.getOrderTotal = function (items) {
  11250. var sum = 0;
  11251. angular.forEach(items, function (item) {
  11252. sum += item.qty * item.price;
  11253. });
  11254. return sum;
  11255. };
  11256. $scope.openDatePicker = function ($event, item, openParam) {
  11257. $event.preventDefault();
  11258. $event.stopPropagation();
  11259. item[openParam] = !item[openParam];
  11260. };
  11261. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11262. $event.preventDefault();
  11263. $event.stopPropagation();
  11264. item[openParam] = !item[openParam];
  11265. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11266. $scope.tableParams.reload();
  11267. }
  11268. };
  11269. $scope.parseDate = function (dateStr) {
  11270. if (dateStr)
  11271. return Date.parse(dateStr, 'yyyy-MM-dd');
  11272. return new Date();
  11273. };
  11274. // 打开回复
  11275. $scope.openReply = function (order) {
  11276. if (!order.reply) {
  11277. order.reply = {
  11278. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11279. delivery: order.delivery
  11280. }
  11281. }
  11282. order.$editing = true;
  11283. };
  11284. // 关闭回复
  11285. $scope.closeReply = function (order) {
  11286. order.$editing = false;
  11287. }
  11288. // 搜索框回车
  11289. $scope.onSearch = function () {
  11290. $scope.tableParams.page(1);
  11291. $scope.tableParams.reload();
  11292. };
  11293. // 选择查找日期
  11294. $scope.onDateCondition = function () {
  11295. $scope.tableParams.page(1);
  11296. $scope.tableParams.reload();
  11297. };
  11298. // 点击回复
  11299. $scope.onReplyClick = function (order, inverse) {
  11300. if (order.reply) {
  11301. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11302. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11303. return;
  11304. }
  11305. var reply = angular.copy(order.reply);
  11306. if (reply.delivery) {
  11307. if (typeof reply.delivery == 'object')
  11308. reply.delivery = reply.delivery.getTime();
  11309. } else {
  11310. reply.delivery = order.delivery;
  11311. }
  11312. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11313. $scope.loading = true;
  11314. MakeOrder.reply({orderId: order.id}, reply, function () {
  11315. $scope.loading = false;
  11316. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11317. $scope.tableParams.reload();
  11318. }, function (response) {
  11319. $scope.loading = false;
  11320. toaster.pop('error', '回复失败', response.data);
  11321. });
  11322. }
  11323. };
  11324. //委外加工单
  11325. $scope.print = function (order) {
  11326. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11327. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  11328. };
  11329. // 获取回复记录
  11330. $scope.getReply = function (order) {
  11331. if (!order.replies) {
  11332. MakeOrder.getReply({orderId: order.id}, function (replies) {
  11333. order.replies = replies;
  11334. });
  11335. }
  11336. };
  11337. // 导出
  11338. $scope.exportXls = function () {
  11339. MakeOrder.exportXls({}, {}, function (data) {
  11340. if (data.success){
  11341. window.location.href = 'make/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11342. }
  11343. }, function (response) {
  11344. toaster.pop('error', '数据加载失败', response.data);
  11345. });
  11346. }
  11347. }]);
  11348. /**
  11349. * 委外加工单详细
  11350. */
  11351. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService, CurrentRole) {
  11352. BaseService.scrollBackToTop();
  11353. // 获取当前用户是否为普通用户
  11354. CurrentRole.isUser({}, {}, function (data) {
  11355. $scope.isUser = data.isUser;
  11356. });
  11357. var loadData = function () {
  11358. MakeOrder.getItem({id: $stateParams.id}, function (data) {
  11359. $scope.order = data;
  11360. var sum = $scope.order.qty * $scope.order.price;
  11361. $scope.order.total = sum;
  11362. $scope.loading = false;
  11363. }, function (response) {
  11364. toaster.pop('error', '', response.data);
  11365. });
  11366. };
  11367. loadData();
  11368. // 获取回复记录
  11369. $scope.getReply = function (item) {
  11370. if (!item.replies) {
  11371. MakeOrder.getReply({orderId: item.id}, function (replies) {
  11372. item.replies = replies;
  11373. });
  11374. }
  11375. };
  11376. $scope.openDatePicker = function ($event, item, openParam) {
  11377. $event.preventDefault();
  11378. $event.stopPropagation();
  11379. item[openParam] = !item[openParam];
  11380. };
  11381. // 点击回复
  11382. $scope.onReplyClick = function (order, inverse) {
  11383. if (order.reply) {
  11384. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11385. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11386. return;
  11387. }
  11388. var reply = angular.copy(order.reply);
  11389. if (reply.delivery) {
  11390. if (typeof reply.delivery == 'object')
  11391. reply.delivery = reply.delivery.getTime();
  11392. } else {
  11393. reply.delivery = order.delivery;
  11394. }
  11395. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11396. $scope.loading = true;
  11397. MakeOrder.reply({orderId: order.id}, reply, function () {
  11398. $scope.loading = false;
  11399. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11400. loadData();
  11401. }, function (response) {
  11402. $scope.loading = false;
  11403. toaster.pop('error', '回复失败', response.data);
  11404. });
  11405. }
  11406. };
  11407. // 打开回复
  11408. $scope.openReply = function (order) {
  11409. if (!order.reply) {
  11410. order.reply = {
  11411. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11412. delivery: order.delivery
  11413. }
  11414. }
  11415. order.$editing = true;
  11416. };
  11417. // 关闭回复
  11418. $scope.closeReply = function (order) {
  11419. order.$editing = false;
  11420. }
  11421. // 委外订单
  11422. $scope.print = function (order) {
  11423. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11424. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  11425. };
  11426. }]);
  11427. /**
  11428. * 客户委外验收
  11429. */
  11430. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11431. BaseService.scrollBackToTop();
  11432. // 获取当前用户是否为普通用户
  11433. CurrentRole.isUser({}, {}, function (data) {
  11434. $scope.isUser = data.isUser;
  11435. });
  11436. $scope.active = 'all';
  11437. $scope.agreedText = '全部';
  11438. $scope.dateZoneText = '一个月内';
  11439. $scope.condition = {dateZone: 1};
  11440. /* 时间筛选初始化*/
  11441. var fromDate = new Date();
  11442. var toDate = new Date();
  11443. fromDate.setMonth(fromDate.getMonth() - 1);
  11444. fromDate.setHours(0, 0, 0, 0);
  11445. toDate.setHours(23, 59, 59, 999);
  11446. $scope.condition.dateFrom = fromDate;
  11447. $scope.condition.dateTo = toDate;
  11448. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11449. $scope.changeAgreed = function (agreed) {
  11450. $scope.condition.agreed = agreed;
  11451. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11452. $scope.condition.$agreedOpen = false;
  11453. };
  11454. $scope.changeDateZone = function (zone) {
  11455. $scope.condition.dateZone = zone;
  11456. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11457. $scope.condition.$dateZoneOpen = false;
  11458. getDateCondition(zone, $scope.condition);
  11459. $scope.tableParams.page(1);
  11460. $scope.tableParams.reload();
  11461. };
  11462. $scope.setActive = function (state) {
  11463. if ($scope.active != state) {
  11464. $scope.active = state;
  11465. if ($scope.tableParams.page() == 1)
  11466. $scope.tableParams.reload();
  11467. else
  11468. $scope.tableParams.page(1);
  11469. }
  11470. };
  11471. var getService = function () {
  11472. return MakeAccept;
  11473. };
  11474. $scope.tableParams = new ngTableParams({
  11475. page: 1,
  11476. count: 20,
  11477. sorting: {
  11478. date: 'desc'
  11479. }
  11480. }, {
  11481. total: 0,
  11482. counts: [5, 10, 25, 50],
  11483. getData: function ($defer, params) {
  11484. $scope.loading = true;
  11485. var pageParams = params.url();
  11486. pageParams.searchFilter = {};
  11487. pageParams.searchFilter.keyword = $scope.keyword;
  11488. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11489. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11490. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11491. $scope.loading = false;
  11492. if (page) {
  11493. params.total(page.totalElement);
  11494. $defer.resolve(page.content);
  11495. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11496. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11497. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11498. }
  11499. }, function (response) {
  11500. $scope.loading = false;
  11501. toaster.pop('error', '数据加载失败', response.data);
  11502. });
  11503. }
  11504. });
  11505. $scope.openDatePicker = function ($event, item, openParam) {
  11506. $event.preventDefault();
  11507. $event.stopPropagation();
  11508. item[openParam] = !item[openParam];
  11509. };
  11510. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11511. $event.preventDefault();
  11512. $event.stopPropagation();
  11513. item[openParam] = !item[openParam];
  11514. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11515. $scope.tableParams.reload();
  11516. }
  11517. };
  11518. // 搜索框回车
  11519. $scope.onSearch = function () {
  11520. $scope.tableParams.page(1);
  11521. $scope.tableParams.reload();
  11522. };
  11523. // 选择查找日期
  11524. $scope.onDateCondition = function () {
  11525. $scope.tableParams.page(1);
  11526. $scope.tableParams.reload();
  11527. };
  11528. // 导出
  11529. $scope.exportXls = function () {
  11530. MakeAccept.exportXls({}, {}, function (data) {
  11531. if (data.success){
  11532. window.location.href = 'make/accept/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11533. }
  11534. }, function (response) {
  11535. toaster.pop('error', '数据加载失败', response.data);
  11536. });
  11537. }
  11538. }]);
  11539. /**
  11540. * 客户委外验退
  11541. */
  11542. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11543. BaseService.scrollBackToTop();
  11544. // 获取当前用户是否为普通用户
  11545. CurrentRole.isUser({}, {}, function (data) {
  11546. $scope.isUser = data.isUser;
  11547. });
  11548. $scope.active = 'all';
  11549. $scope.agreedText = '全部';
  11550. $scope.dateZoneText = '一个月内';
  11551. $scope.condition = {dateZone: 1};
  11552. /* 时间筛选初始化*/
  11553. var fromDate = new Date();
  11554. var toDate = new Date();
  11555. fromDate.setMonth(fromDate.getMonth() - 1);
  11556. fromDate.setHours(0, 0, 0, 0);
  11557. toDate.setHours(23, 59, 59, 999);
  11558. $scope.condition.dateFrom = fromDate;
  11559. $scope.condition.dateTo = toDate;
  11560. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11561. $scope.changeAgreed = function (agreed) {
  11562. $scope.condition.agreed = agreed;
  11563. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11564. $scope.condition.$agreedOpen = false;
  11565. };
  11566. $scope.changeDateZone = function (zone) {
  11567. $scope.condition.dateZone = zone;
  11568. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11569. $scope.condition.$dateZoneOpen = false;
  11570. getDateCondition(zone, $scope.condition);
  11571. $scope.tableParams.page(1);
  11572. $scope.tableParams.reload();
  11573. };
  11574. $scope.setActive = function (state) {
  11575. if ($scope.active != state) {
  11576. $scope.active = state;
  11577. if ($scope.tableParams.page() == 1)
  11578. $scope.tableParams.reload();
  11579. else
  11580. $scope.tableParams.page(1);
  11581. }
  11582. };
  11583. var getService = function () {
  11584. return MakeReturn;
  11585. };
  11586. $scope.tableParams = new ngTableParams({
  11587. page: 1,
  11588. count: 20,
  11589. sorting: {
  11590. date: 'desc'
  11591. }
  11592. }, {
  11593. total: 0,
  11594. counts: [5, 10, 25, 50],
  11595. getData: function ($defer, params) {
  11596. $scope.loading = true;
  11597. var pageParams = params.url();
  11598. pageParams.searchFilter = {};
  11599. pageParams.searchFilter.keyword = $scope.keyword;
  11600. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11601. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11602. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11603. $scope.loading = false;
  11604. if (page) {
  11605. params.total(page.totalElement);
  11606. $defer.resolve(page.content);
  11607. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11608. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11609. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11610. }
  11611. }, function (response) {
  11612. $scope.loading = false;
  11613. toaster.pop('error', '数据加载失败', response.data);
  11614. });
  11615. }
  11616. });
  11617. $scope.openDatePicker = function ($event, item, openParam) {
  11618. $event.preventDefault();
  11619. $event.stopPropagation();
  11620. item[openParam] = !item[openParam];
  11621. };
  11622. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11623. $event.preventDefault();
  11624. $event.stopPropagation();
  11625. item[openParam] = !item[openParam];
  11626. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11627. $scope.tableParams.reload();
  11628. }
  11629. };
  11630. // 搜索框回车
  11631. $scope.onSearch = function () {
  11632. $scope.tableParams.page(1);
  11633. $scope.tableParams.reload();
  11634. };
  11635. // 选择查找日期
  11636. $scope.onDateCondition = function () {
  11637. $scope.tableParams.page(1);
  11638. $scope.tableParams.reload();
  11639. };
  11640. // 导出
  11641. $scope.exportXls = function () {
  11642. MakeReturn.exportXls({}, {}, function (data) {
  11643. if (data.success){
  11644. window.location.href = 'make/return/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11645. }
  11646. }, function (response) {
  11647. toaster.pop('error', '数据加载失败', response.data);
  11648. });
  11649. }
  11650. }]);
  11651. /**
  11652. * 委外加工变更
  11653. */
  11654. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeChange, ngTableParams, toaster, BaseService, CurrentRole) {
  11655. BaseService.scrollBackToTop();
  11656. // 获取当前用户是否为普通用户
  11657. CurrentRole.isUser({}, {}, function (data) {
  11658. $scope.isUser = data.isUser;
  11659. });
  11660. $scope.active = 'all';
  11661. $scope.agreedText = '全部';
  11662. $scope.dateZoneText = '一个月内';
  11663. $scope.condition = {dateZone: 1};
  11664. /* 时间筛选初始化*/
  11665. var fromDate = new Date();
  11666. var toDate = new Date();
  11667. fromDate.setMonth(fromDate.getMonth() - 1);
  11668. fromDate.setHours(0, 0, 0, 0);
  11669. toDate.setHours(23, 59, 59, 999);
  11670. $scope.condition.dateFrom = fromDate;
  11671. $scope.condition.dateTo = toDate;
  11672. $scope.changeAgreed = function (agreed) {
  11673. $scope.condition.agreed = agreed;
  11674. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11675. $scope.condition.$agreedOpen = false;
  11676. };
  11677. $scope.changeDateZone = function (zone) {
  11678. $scope.condition.dateZone = zone;
  11679. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11680. $scope.condition.$dateZoneOpen = false;
  11681. getDateCondition(zone, $scope.condition);
  11682. $scope.tableParams.page(1);
  11683. $scope.tableParams.reload();
  11684. };
  11685. $scope.setActive = function (state) {
  11686. if ($scope.active != state) {
  11687. $scope.active = state;
  11688. if ($scope.tableParams.page() == 1)
  11689. $scope.tableParams.reload();
  11690. else
  11691. $scope.tableParams.page(1);
  11692. }
  11693. };
  11694. var getService = function () {
  11695. return MakeChange;
  11696. };
  11697. $scope.tableParams = new ngTableParams({
  11698. page: 1,
  11699. count: 20,
  11700. sorting: {
  11701. orderChangeDate: 'desc'
  11702. }
  11703. }, {
  11704. total: 0,
  11705. counts: [5, 10, 25, 50],
  11706. getData: function ($defer, params) {
  11707. $scope.loading = true;
  11708. var pageParams = params.url();
  11709. pageParams.searchFilter = {
  11710. keyword: $scope.keyword,
  11711. fromDate: getDateTime($scope.condition.dateFrom),
  11712. endDate: getDateTime($scope.condition.dateTo)
  11713. };
  11714. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11715. $scope.loading = false;
  11716. if (page) {
  11717. params.total(page.totalElement);
  11718. $defer.resolve(page.content);
  11719. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11720. }
  11721. }, function (response) {
  11722. $scope.loading = false;
  11723. toaster.pop('error', '数据加载失败', response.data);
  11724. });
  11725. }
  11726. });
  11727. $scope.openDatePicker = function ($event, item, openParam) {
  11728. $event.preventDefault();
  11729. $event.stopPropagation();
  11730. item[openParam] = !item[openParam];
  11731. };
  11732. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11733. $event.preventDefault();
  11734. $event.stopPropagation();
  11735. item[openParam] = !item[openParam];
  11736. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11737. $scope.tableParams.reload();
  11738. }
  11739. };
  11740. // 打开回复
  11741. $scope.openReply = function (change) {
  11742. change.$editing = true;
  11743. };
  11744. // 关闭回复
  11745. $scope.closeReply = function (change) {
  11746. change.$editing = false;
  11747. }
  11748. // 确定回复
  11749. $scope.onReplyClick = function (change) {
  11750. if (change.$agreed) {
  11751. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11752. $scope.loading = true;
  11753. MakeChange.reply({itemId: change.id}, reply, function () {
  11754. $scope.loading = false;
  11755. toaster.pop('info', '提示', '回复成功');
  11756. $scope.tableParams.reload();
  11757. }, function (response) {
  11758. $scope.loading = false;
  11759. toaster.pop('error', '回复失败', response.data);
  11760. });
  11761. }
  11762. };
  11763. // 搜索框回车
  11764. $scope.onSearch = function () {
  11765. $scope.tableParams.page(1);
  11766. $scope.tableParams.reload();
  11767. };
  11768. // 选择查找日期
  11769. $scope.onDateCondition = function () {
  11770. $scope.tableParams.page(1);
  11771. $scope.tableParams.reload();
  11772. };
  11773. // 导出
  11774. $scope.exportXls = function () {
  11775. MakeChange.exportXls({}, {}, function (data) {
  11776. if (data.success){
  11777. window.location.href = 'make/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11778. }
  11779. }, function (response) {
  11780. toaster.pop('error', '数据加载失败', response.data);
  11781. });
  11782. }
  11783. }]);
  11784. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeChange, toaster, BaseService, CurrentRole) {
  11785. BaseService.scrollBackToTop();
  11786. CurrentRole.isUser({}, {}, function (data) {
  11787. $scope.isUser = data.isUser;
  11788. });
  11789. var loadData = function () {
  11790. MakeChange.getItem({id: $stateParams.id}, function (data) {
  11791. $scope.change = data;
  11792. }, function (response) {
  11793. toaster.pop('error', '数据加载失败', response.data);
  11794. });
  11795. };
  11796. loadData();
  11797. $scope.openDatePicker = function ($event, item, openParam) {
  11798. $event.preventDefault();
  11799. $event.stopPropagation();
  11800. item[openParam] = !item[openParam];
  11801. };
  11802. $scope.onReplyClick = function (change) {
  11803. if (change.$agreed) {
  11804. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11805. MakeChange.reply({itemId: change.id}, reply, function () {
  11806. toaster.pop('info', '提示', '回复成功');
  11807. loadData();
  11808. }, function (response) {
  11809. toaster.pop('error', '回复失败', response.data);
  11810. });
  11811. }
  11812. };
  11813. }]);
  11814. /**
  11815. * 委外加工
  11816. */
  11817. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeOutOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  11818. BaseService.scrollBackToTop();
  11819. // 获取当前用户是否为普通用户
  11820. CurrentRole.isUser({}, {}, function (data) {
  11821. $scope.isUser = data.isUser;
  11822. });
  11823. $scope.active = 'all';
  11824. $scope.agreedText = '全部';
  11825. $scope.dateZoneText = '一个月内';
  11826. $scope.condition = {dateZone: 1};
  11827. /* 时间筛选初始化*/
  11828. var fromDate = new Date();
  11829. var toDate = new Date();
  11830. fromDate.setMonth(fromDate.getMonth() - 1);
  11831. fromDate.setHours(0, 0, 0, 0);
  11832. toDate.setHours(23, 59, 59, 999);
  11833. $scope.condition.dateFrom = fromDate;
  11834. $scope.condition.dateTo = toDate;
  11835. $scope.changeAgreed = function (agreed) {
  11836. $scope.condition.agreed = agreed;
  11837. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11838. $scope.condition.$agreedOpen = false;
  11839. };
  11840. $scope.changeDateZone = function (zone) {
  11841. $scope.condition.dateZone = zone;
  11842. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11843. $scope.condition.$dateZoneOpen = false;
  11844. getDateCondition(zone, $scope.condition);
  11845. $scope.tableParams.page(1);
  11846. $scope.tableParams.reload();
  11847. };
  11848. $scope.setActive = function (state) {
  11849. if ($scope.active != state) {
  11850. $scope.active = state;
  11851. if ($scope.tableParams.page() == 1)
  11852. $scope.tableParams.reload();
  11853. else
  11854. $scope.tableParams.page(1);
  11855. }
  11856. };
  11857. var getService = function () {
  11858. return MakeOutOrder;
  11859. };
  11860. $scope.tableParams = new ngTableParams({
  11861. page: 1,
  11862. count: 20,
  11863. sorting: {
  11864. date: 'desc'
  11865. }
  11866. }, {
  11867. total: 0,
  11868. counts: [5, 10, 25, 50],
  11869. getData: function ($defer, params) {
  11870. $scope.loading = true;
  11871. var pageParams = params.url();
  11872. pageParams.searchFilter = {};
  11873. pageParams.searchFilter.keyword = $scope.keyword;
  11874. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11875. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11876. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11877. $scope.loading = false;
  11878. if (page) {
  11879. params.total(page.totalElement);
  11880. $defer.resolve(page.content);
  11881. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11882. }
  11883. }, function (response) {
  11884. $scope.loading = false;
  11885. toaster.pop('error', '数据加载失败', response.data);
  11886. });
  11887. }
  11888. });
  11889. $scope.openDatePicker = function ($event, item, openParam) {
  11890. $event.preventDefault();
  11891. $event.stopPropagation();
  11892. item[openParam] = !item[openParam];
  11893. };
  11894. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11895. $event.preventDefault();
  11896. $event.stopPropagation();
  11897. item[openParam] = !item[openParam];
  11898. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11899. $scope.tableParams.reload();
  11900. }
  11901. };
  11902. // 获取回复记录
  11903. $scope.getReply = function (item) {
  11904. if (!item.replies) {
  11905. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  11906. item.replies = replies;
  11907. });
  11908. }
  11909. };
  11910. // 打开回复
  11911. $scope.openReply = function (change) {
  11912. change.$editing = true;
  11913. };
  11914. // 关闭回复
  11915. $scope.closeReply = function (change) {
  11916. change.$editing = false;
  11917. }
  11918. // 确定回复
  11919. $scope.onReplyClick = function (change) {
  11920. if (change.$agreed) {
  11921. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11922. $scope.loading = true;
  11923. MakeOutOrder.reply({itemId: change.id}, reply, function () {
  11924. $scope.loading = false;
  11925. toaster.pop('info', '提示', '回复成功');
  11926. $scope.tableParams.reload();
  11927. }, function (response) {
  11928. $scope.loading = false;
  11929. toaster.pop('error', '回复失败', response.data);
  11930. });
  11931. }
  11932. };
  11933. // 搜索框回车
  11934. $scope.onSearch = function () {
  11935. $scope.tableParams.page(1);
  11936. $scope.tableParams.reload();
  11937. };
  11938. // 选择查找日期
  11939. $scope.onDateCondition = function () {
  11940. $scope.tableParams.page(1);
  11941. $scope.tableParams.reload();
  11942. };
  11943. // 导出
  11944. $scope.exportXls = function () {
  11945. MakeOutOrder.exportXls({}, {}, function (data) {
  11946. if (data.success){
  11947. window.location.href = 'make/outorders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11948. }
  11949. }, function (response) {
  11950. toaster.pop('error', '数据加载失败', response.data);
  11951. });
  11952. }
  11953. }]);
  11954. /**
  11955. * 委外加工详细
  11956. */
  11957. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService, CurrentRole) {
  11958. BaseService.scrollBackToTop();
  11959. // 获取当前用户是否为普通用户
  11960. CurrentRole.isUser({}, {}, function (data) {
  11961. $scope.isUser = data.isUser;
  11962. });
  11963. var loadData = function () {
  11964. MakeOutOrder.getItem({id: $stateParams.id},{}, function (data) {
  11965. $scope.order = data;
  11966. var sum = $scope.order.qty * $scope.order.price;
  11967. $scope.order.total = sum;
  11968. $scope.loading = false;
  11969. }, function (response) {
  11970. toaster.pop('error', '提示', response.data);
  11971. });
  11972. };
  11973. loadData();
  11974. // 获取回复记录
  11975. $scope.getReply = function (item) {
  11976. if (!item.replies) {
  11977. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  11978. item.replies = replies;
  11979. });
  11980. }
  11981. };
  11982. $scope.openDatePicker = function ($event, item, openParam) {
  11983. $event.preventDefault();
  11984. $event.stopPropagation();
  11985. item[openParam] = !item[openParam];
  11986. };
  11987. // 点击回复
  11988. $scope.onReplyClick = function (order, inverse) {
  11989. if (order.reply) {
  11990. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11991. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11992. return;
  11993. }
  11994. var reply = angular.copy(order.reply);
  11995. if (reply.delivery) {
  11996. if (typeof reply.delivery == 'object')
  11997. reply.delivery = reply.delivery.getTime();
  11998. } else {
  11999. reply.delivery = order.delivery;
  12000. }
  12001. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  12002. $scope.loading = true;
  12003. MakeOutOrder.reply({orderId: order.id}, reply, function () {
  12004. $scope.loading = false;
  12005. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  12006. loadData();
  12007. }, function (response) {
  12008. $scope.loading = false;
  12009. toaster.pop('error', '回复失败', response.data);
  12010. });
  12011. }
  12012. };
  12013. // 打开回复
  12014. $scope.openReply = function (order) {
  12015. if (!order.reply) {
  12016. order.reply = {
  12017. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  12018. delivery: order.delivery
  12019. }
  12020. }
  12021. order.$editing = true;
  12022. };
  12023. // 关闭回复
  12024. $scope.closeReply = function (order) {
  12025. order.$editing = false;
  12026. }
  12027. // 自己委外加工订单
  12028. $scope.print = function (order) {
  12029. MakeOutOrder.printCount({id: order.id}, {});//增加打印此次
  12030. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  12031. };
  12032. }]);
  12033. /**
  12034. * 计算时间差
  12035. */
  12036. app.filter('timespan', function () {
  12037. return function (time) {
  12038. if (time == null)
  12039. return '9999年';
  12040. var now = new Date().getTime(), span = time - now,
  12041. d = Math.ceil(span / 86400000), h = Math.ceil(span / 3600000),
  12042. m = Math.ceil(span / 60000);
  12043. if (span < 0)
  12044. return '1天';
  12045. if (d > 0)
  12046. return d + 1 + '天';
  12047. if (h > 0)
  12048. return h + '小时';
  12049. if (m > 0)
  12050. return m + '分钟';
  12051. return '0天';
  12052. };
  12053. });
  12054. /**
  12055. * 公共询价计算时间差
  12056. */
  12057. app.filter('datespan', function () {
  12058. return function (time) {
  12059. if (time == null) {
  12060. return '剩余9999年';
  12061. }
  12062. var now = new Date().getTime(), span = time - now,
  12063. d = Math.floor(span / 86400000), h = Math.floor(span / 3600000),
  12064. m = Math.floor(span / 60000);
  12065. if (d > 0) {
  12066. var day = d + 1;
  12067. return '剩余' + day + '天';
  12068. }
  12069. if (h > 0) {
  12070. return '<span class="text-inverse">剩余' + h + '小时</span>';
  12071. }
  12072. if (m > 0) {
  12073. return '<span class="text-inverse">剩余' + m + '分钟</span>';
  12074. }
  12075. return '已结束';
  12076. };
  12077. });
  12078. app.filter('firstchar', function () {
  12079. return function (str) {
  12080. if (str == null)
  12081. return null;
  12082. return str.substring(0, 1);
  12083. };
  12084. });
  12085. app.filter('summary', function () {
  12086. return function (data, field) {
  12087. var sum = 0;
  12088. if (data) {
  12089. angular.forEach(data, function (d) {
  12090. sum += d[field];
  12091. });
  12092. }
  12093. return sum;
  12094. };
  12095. });
  12096. /**
  12097. * 搜索框,回车触发
  12098. */
  12099. app.directive('ngSearch', ['$parse', function ($parse) {
  12100. return {
  12101. require: '?ngModel',
  12102. restrict: 'A',
  12103. link: function (scope, element, attrs, ngModel) {
  12104. var searchFn = $parse(attrs.ngSearch);
  12105. element.bind('keypress', function (event) {
  12106. if (event.keyCode == '13') {
  12107. event.preventDefault();
  12108. event.stopPropagation();
  12109. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  12110. }
  12111. });
  12112. }
  12113. };
  12114. }]);
  12115. /**
  12116. * 状态码 -> 描述
  12117. */
  12118. app.filter('status', function () {
  12119. return function (data) {
  12120. var statusConfig = {
  12121. '101': '已提交',
  12122. '102': '已审核',
  12123. '103': '未通过',
  12124. '200': '未回复',
  12125. '201': '已回复',
  12126. '313': '已激活',
  12127. '316': '已过账',
  12128. '311': '申请中',
  12129. '312': '未激活'
  12130. };
  12131. return statusConfig[data];
  12132. }
  12133. });
  12134. //弹出问题反馈模态框
  12135. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function ($scope, $modal, AuthenticationService) {
  12136. //获取当前用户
  12137. AuthenticationService.getAuthentication().success(function (data) {
  12138. $scope.user = data;
  12139. });
  12140. $scope.showModal = function () {
  12141. var modalInstance = $modal.open({
  12142. animation: true,
  12143. templateUrl: 'static/tpl/serve/feedback.html',
  12144. controller: 'FeedbackCtrl',
  12145. resolve: {
  12146. user: function () {
  12147. return $scope.user;
  12148. } //传递当前用户到模态框Controller
  12149. }
  12150. });
  12151. modalInstance.result.then(function () {
  12152. }, function () {
  12153. });
  12154. }
  12155. }]);
  12156. /*
  12157. * 提交我的反馈
  12158. */
  12159. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function ($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user) {
  12160. $scope.isPublic = 1; //默认公开
  12161. $scope.classId = 1; //默认类别
  12162. $scope.user = user;
  12163. $scope.ok = function () {
  12164. if (!$scope.user) { //用户未登录
  12165. $scope.uu = null;
  12166. } else { //用户已登录
  12167. $scope.uu = $scope.user.userUU;
  12168. }
  12169. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  12170. FeedBackService.feedBackQuestion({
  12171. classId: $scope.classId,
  12172. isPublic: $scope.isPublic,
  12173. title: $scope.title,
  12174. userUU: $scope.uu
  12175. }, {},
  12176. function (data) {
  12177. toaster.pop('success', '成功', '您的问题反馈成功!');
  12178. $scope.cancel();
  12179. }, function (response) {
  12180. toaster.pop('error', '错误', response.data);
  12181. });
  12182. }
  12183. $scope.cancel = function () {
  12184. $modalInstance.dismiss();
  12185. };
  12186. }]);
  12187. //“我的问题反馈”跳转控制
  12188. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function ($scope, AuthenticationService, toaster, $rootScope) {
  12189. $scope.myFeedback = function () {
  12190. AuthenticationService.getAuthentication().success(function (data) {
  12191. $scope.user = data;
  12192. if (!$scope.user) {
  12193. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  12194. return false;
  12195. } else {
  12196. window.location.href = "./serve#/question/myFeedback";
  12197. }
  12198. });
  12199. };
  12200. $scope.getSaleOrderCount = function (unread) {
  12201. if (unread != undefined) {
  12202. return unread.order + unread.change + unread.makeOrder;
  12203. }
  12204. };
  12205. $scope.getSaleInquiryCount = function (unread) {
  12206. if (unread != undefined) {
  12207. return unread.inquiry + unread.mould;
  12208. }
  12209. };
  12210. $scope.setActive = function (active) {
  12211. $rootScope.active = active;
  12212. }
  12213. }]);
  12214. //客户服务
  12215. app.controller('CustServeCtrl', ['$scope', 'Vendor', function ($scope, Vendor) {
  12216. Vendor.getServe(function (datas) {
  12217. $scope.vendors = datas;
  12218. // 自动跳转
  12219. if (datas && datas.length == 1)
  12220. $scope.redirect(datas[0]);
  12221. });
  12222. $scope.redirect = function (vendor) {
  12223. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  12224. };
  12225. }]);
  12226. /**
  12227. * 物料资料
  12228. */
  12229. app.controller('ProductListCtrl', ['$scope', 'GetProductInfo', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$rootScope', '$modal', 'Products', 'GetProductInfoNewest', 'AccountEnterprise', function ($scope, GetProductInfo, ngTableParams, $filter, BaseService, toaster, $timeout, $rootScope, $modal, Products, GetProductInfoNewest, AccountEnterprise) {
  12230. BaseService.scrollBackToTop();
  12231. var loadAccount = function () {
  12232. AccountEnterprise.get({}, function (data) {
  12233. $scope.enterprise = data;
  12234. $scope.saleStatus = $scope.enterprise.prodsale;
  12235. });
  12236. }
  12237. loadAccount();
  12238. $scope.active = 'all';
  12239. $scope.agreedText = '全部';
  12240. $scope.dateZoneText = '一个月内';
  12241. $scope.condition = {dateZone: 1};
  12242. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12243. $scope.changeAgreed = function (agreed) {
  12244. $scope.condition.agreed = agreed;
  12245. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12246. $scope.condition.$agreedOpen = false;
  12247. };
  12248. $scope.changeDateZone = function (zone) {
  12249. $scope.condition.dateZone = zone;
  12250. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12251. $scope.condition.$dateZoneOpen = false;
  12252. getDateCondition(zone, $scope.condition);
  12253. $scope.tableParams.reload();
  12254. };
  12255. $scope.setActive = function (state) {
  12256. if ($scope.active != state) {
  12257. $scope.active = state;
  12258. if ($scope.tableParams.page() == 1)
  12259. $scope.tableParams.reload();
  12260. else
  12261. $scope.tableParams.page(1);
  12262. }
  12263. };
  12264. $scope.searchMethod = false;
  12265. var getService = function () {
  12266. return $scope.searchMethod ? GetProductInfo : GetProductInfoNewest;
  12267. };
  12268. $scope.tableParams = new ngTableParams({
  12269. page: 1,
  12270. count: 20,
  12271. sorting: {
  12272. id: 'desc',
  12273. }
  12274. }, {
  12275. total: 0,
  12276. counts: [5, 10, 25, 50],
  12277. getData: function ($defer, params) {
  12278. $scope.loading = true;
  12279. var pageParams = params.url();
  12280. pageParams.keyword = $scope.keyword;
  12281. pageParams.searchFilter = $scope.searchFilter;
  12282. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12283. $scope.loading = false;
  12284. if (page) {
  12285. params.total(page.totalElement);
  12286. $defer.resolve(page.content);
  12287. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12288. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  12289. }
  12290. }, function (response) {
  12291. $scope.loading = false;
  12292. toaster.pop('error', '数据加载失败', response.data);
  12293. });
  12294. }
  12295. });
  12296. // 搜索框回车
  12297. $scope.onSearch = function (keyword) {
  12298. // 每次搜索重置获取数据方法
  12299. $scope.searchMethod = false;
  12300. if(keyword != null && keyword != '') {
  12301. $scope.searchMethod = true;
  12302. }
  12303. $scope.tableParams.page(1);
  12304. $scope.tableParams.reload();
  12305. };
  12306. //删除
  12307. $scope.deleteById = function (id) {
  12308. $scope.loading = true;
  12309. GetProductInfo.deleteById({}, id, function (data) {
  12310. if (data.error) {
  12311. toaster.pop("error", "提示", data.error);
  12312. } else {
  12313. toaster.pop("success", "提示", "删除成功");
  12314. $timeout(function () {
  12315. $scope.tableParams.reload();
  12316. }, 500);
  12317. }
  12318. $scope.loading = false;
  12319. }, function (response) {
  12320. $scope.loading = false;
  12321. toaster.pop("error", "删除失败", response.data);
  12322. });
  12323. };
  12324. $rootScope.isProductEdit = false;
  12325. // 编辑
  12326. $scope.isProductEdit = function () {
  12327. $rootScope.isProductEdit = true;
  12328. };
  12329. // 一键开启关闭
  12330. $scope.toggle = function (status) {
  12331. if ($scope.saleStatus == 0) {
  12332. $scope.saleStatus = 1;
  12333. } else {
  12334. $scope.saleStatus = 0;
  12335. }
  12336. $scope.loading = true;
  12337. GetProductInfo.toggle({status: status}, {}, function (data) {
  12338. $scope.loading = false;
  12339. toaster.pop('success', '提示', '操作成功');
  12340. loadAccount();
  12341. $scope.tableParams.reload();
  12342. }, function (response) {
  12343. $scope.loading = false;
  12344. toaster.pop('error', '提示', response.data);
  12345. })
  12346. }
  12347. var products = [];
  12348. $scope.checks = {
  12349. checked: false
  12350. };
  12351. // 全选框
  12352. $scope.checkAll = function () {
  12353. products = [];// 每次选择时先清空,防止重复
  12354. angular.forEach($scope.tableParams.data, function (product) {
  12355. if (product.cmpUuId == null) {
  12356. product.checked = $scope.checks.checked;
  12357. }
  12358. });
  12359. };
  12360. // 单选
  12361. $scope.checkOne = function (product) {
  12362. products = [];// 每次选择时先清空,防止重复
  12363. var result = true;
  12364. angular.forEach($scope.tableParams.data, function (item) {
  12365. if (item.$selected != true) {
  12366. result = false;
  12367. return;
  12368. }
  12369. });
  12370. $scope.checks.checked = result;
  12371. var checked = true;
  12372. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  12373. if (!message.checked) {
  12374. checked = false;
  12375. }
  12376. });
  12377. $scope.checks.checked = checked;
  12378. };
  12379. $scope.updateByBatch = function (updatetype) {
  12380. var modalInstance = $modal.open({
  12381. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  12382. controller: 'UpdateByBatchCtrl',
  12383. size: 'md',
  12384. resolve: {
  12385. updatetype: function () {
  12386. return updatetype;
  12387. },
  12388. active: function () {
  12389. return $scope.active;
  12390. },
  12391. type: function () {
  12392. return 'sale';
  12393. }
  12394. }
  12395. });
  12396. modalInstance.result.then(function (data) {
  12397. toaster.pop('success', '提示', data.success);
  12398. $scope.tableParams.reload();
  12399. }, function () {
  12400. });
  12401. }
  12402. // 一键匹配
  12403. $scope.matchall = function () {
  12404. $scope.loading = true;
  12405. $scope.type = "sale";
  12406. GetProductInfo.matchbytype({type: $scope.type}, {}, function (data) {
  12407. if (data.error) {
  12408. $scope.loading = false;
  12409. toaster.pop('error', '提示', data.error);
  12410. } else {
  12411. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  12412. window.location.href = "#/sale/productmatches";
  12413. }
  12414. }, function (response) {
  12415. $scope.loading = false;
  12416. toaster.pop('error', '提示', response.data);
  12417. });
  12418. }
  12419. $scope.exportXls = function () {
  12420. GetProductInfo.exportXls({},{}, function (data) {
  12421. if (data.success) {
  12422. window.location.href = 'product/baseInfo/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  12423. }
  12424. }, function (response) {
  12425. toaster.pop('error', '数据加载失败', response.data);
  12426. })
  12427. }
  12428. }]);
  12429. /**
  12430. * 批量修改
  12431. */
  12432. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function ($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  12433. $scope.updatetype = updatetype;
  12434. $scope.changed = false;
  12435. $scope.parameter = {
  12436. updatetype: updatetype,
  12437. standard: active,
  12438. type: type,
  12439. oldvalue: null,
  12440. newvalue: null
  12441. };
  12442. $scope.cancel = function () {
  12443. $modalInstance.dismiss();
  12444. }
  12445. if (updatetype === '品牌')
  12446. var loadData = function () {
  12447. Products.getBrands({parameter: $scope.parameter}, {}, function (data) {
  12448. $scope.products = data;
  12449. }, function (response) {
  12450. toaster.pop('error', '提示', response.data);
  12451. })
  12452. }
  12453. if (updatetype === '名称(类目)')
  12454. var loadData = function () {
  12455. Products.getTitles({parameter: $scope.parameter}, {}, function (data) {
  12456. $scope.products = data;
  12457. }, function (response) {
  12458. toaster.pop('error', '提示', response.data);
  12459. })
  12460. }
  12461. loadData();
  12462. $scope.okay = function (newvalue) {
  12463. if (newvalue == '' || newvalue == null) {
  12464. toaster.pop('error', '提示', '修改的值不能为空');
  12465. } else {
  12466. $scope.loading = true;
  12467. Products.alterByBatch({parameter: $scope.parameter}, {}, function (data) {
  12468. $scope.loading = false;
  12469. $modalInstance.close(data);
  12470. }, function (response) {
  12471. $scope.loading = false;
  12472. toaster.pop('error', '提示', response.data);
  12473. });
  12474. }
  12475. }
  12476. }]);
  12477. /**
  12478. * 物料批量上传
  12479. */
  12480. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  12481. BaseService.scrollBackToTop();
  12482. $scope.$watch('myFiles', function () {
  12483. if ($scope.myFiles) {
  12484. var file = $scope.myFiles[0];
  12485. $scope.fileName = file.name;
  12486. }
  12487. })
  12488. // 通过excel批量上传物料
  12489. $scope.upload = function () {
  12490. $scope.loading = true;
  12491. if ($scope.myFiles) {
  12492. var file = $scope.myFiles[0];
  12493. if (file.name) {
  12494. $upload.upload({
  12495. url: 'product/baseInfo/edit/release/excel',
  12496. file: file,
  12497. method: 'POST'
  12498. }).success(function (data) {
  12499. $scope.loading = false;
  12500. if (data.error) {
  12501. toaster.pop('error', '提示', data.error);
  12502. }
  12503. $scope.result = data;
  12504. // $scope.products = $scope.result.products;
  12505. $scope.success = $scope.result.success;
  12506. $scope.total = $scope.result.total;
  12507. $scope.alters = $scope.result.alters;
  12508. $scope.infos = $scope.result.infos;
  12509. $scope.myFiles[0] = "";
  12510. $scope.fileName = "";
  12511. }).error(function (response) {
  12512. $scope.loading = false;
  12513. toaster.pop('error', response.data || response);
  12514. });
  12515. } else {
  12516. $scope.loading = false;
  12517. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  12518. }
  12519. } else {
  12520. $scope.loading = false;
  12521. }
  12522. };
  12523. // 查看范例
  12524. $scope.showImg = function () {
  12525. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  12526. box.show();
  12527. box.find('img').attr('src', src);
  12528. box.find('a').click(function () {
  12529. box.hide();
  12530. });
  12531. box.dblclick(function () {
  12532. box.hide();
  12533. });
  12534. };
  12535. // 下载模板
  12536. $scope.download = function () {
  12537. window.location.href = 'product/baseInfo/upload/template';
  12538. };
  12539. }]);
  12540. /**
  12541. * 物料详情
  12542. */
  12543. app.controller('ProductDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$rootScope', '$modal', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $rootScope, $modal, Products) {
  12544. BaseService.scrollBackToTop();
  12545. // 录入人
  12546. AuthenticationService.getAuthentication().success(function (data) {
  12547. $scope.loading = false;
  12548. $scope.user = data;
  12549. });
  12550. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12551. $scope.editstatus = false;
  12552. var loadData = function () {
  12553. GetProductInfo.getSaleProduct({id: $stateParams.id}, function (data) {
  12554. if (data.attachment) {
  12555. $scope.imgPreview = data.attachment;
  12556. $scope.previewShow = true;
  12557. }
  12558. $scope.prodInfo = data;
  12559. if ($scope.prodInfo.isbusiness == 0) {
  12560. $scope.editstatus = true;
  12561. }
  12562. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  12563. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  12564. $scope.matchresults = data;
  12565. }, function (response) {
  12566. toaster.pop('error', '提示', response.data);
  12567. });
  12568. }
  12569. $scope.loading = false;
  12570. }, function (response) {
  12571. $scope.loading = false;
  12572. toaster.pop('error', '数据加载失败', response.data);
  12573. });
  12574. };
  12575. loadData();
  12576. // 联想词 start
  12577. // 获取类目
  12578. $scope.getSimilarKinds = function (value) {
  12579. if (value) {
  12580. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12581. return data.map(function (item) {
  12582. return item;
  12583. });
  12584. });
  12585. }
  12586. };
  12587. // 设置类目
  12588. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12589. $scope.prodInfo.kind = kind.kindName;
  12590. }
  12591. // 设置名称
  12592. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  12593. $scope.prodInfo.title = kind.kindName;
  12594. }
  12595. $scope.getSimilarBrands = function (value) {
  12596. if (value) {
  12597. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12598. return data.map(function (item) {
  12599. return item;
  12600. });
  12601. });
  12602. }
  12603. }
  12604. // 设置导入品牌
  12605. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12606. $scope.prodInfo.brand = brand.brandName;
  12607. }
  12608. // 设置标准品牌
  12609. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  12610. $scope.prodInfo.pbranden = brand.brandName;
  12611. }
  12612. $scope.getSimilarComponents = function (value) {
  12613. if (value) {
  12614. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12615. return data.map(function (item) {
  12616. return item;
  12617. });
  12618. });
  12619. }
  12620. }
  12621. // 设置标准型号
  12622. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12623. $scope.prodInfo.pcmpcode = cmp.code;
  12624. }
  12625. // 设置导入的型号
  12626. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  12627. $scope.prodInfo.cmpCode = cmp.code;
  12628. }
  12629. // 联想词 end
  12630. // 选择类目
  12631. $scope.selectKind = function (cmpcode) {
  12632. if (cmpcode == null) {
  12633. $modal.open({
  12634. animation: true,
  12635. size: 'lg',
  12636. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12637. controller: 'KindChooseCtrl',
  12638. }).result.then(function (data) {
  12639. $scope.kindId = data;
  12640. var modalInstance = $modal.open({
  12641. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12642. controller: 'FindComponentCtrl',
  12643. size: 'lg',
  12644. resolve: {
  12645. KindId: function () {
  12646. return $scope.kindId;
  12647. }
  12648. }
  12649. });
  12650. modalInstance.result.then(function (data) {
  12651. $scope.prodInfo.cmpUuId = data.uuid;
  12652. $scope.prodInfo.pcmpcode = data.code;
  12653. $scope.prodInfo.pbranden = data.brand.nameEn;
  12654. $scope.prodInfo.pbrand = data.brand.nameCn;
  12655. }, function () {
  12656. });
  12657. }, function () {
  12658. });
  12659. }
  12660. };
  12661. $scope.isShow = true;
  12662. // 更新
  12663. $scope.update = function () {
  12664. $scope.prodInfo.$editing = true;
  12665. $scope.isShow = true;
  12666. };
  12667. // 取消
  12668. $scope.cancel = function () {
  12669. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  12670. $scope.prodInfo = data;
  12671. $scope.prodInfo.$editing = false;
  12672. $scope.isShow = false;
  12673. $scope.loading = false;
  12674. });
  12675. };
  12676. // 删除
  12677. $scope.clearfile = function () {
  12678. $scope.prodInfo.attachment = null;
  12679. $scope.myFiles = null;
  12680. $scope.previewShow = false;
  12681. }
  12682. //删除
  12683. $scope.deleteById = function (id) {
  12684. $scope.loading = true;
  12685. GetProductInfo.deleteById({}, id, function (data) {
  12686. $scope.loading = false;
  12687. if (data.error) {
  12688. toaster.pop("error", "提示", data.error);
  12689. } else {
  12690. toaster.pop("success", "提示", "删除成功");
  12691. window.location.href = "#/sale/prodList";
  12692. }
  12693. }, function (response) {
  12694. $scope.loading = false;
  12695. toaster.pop("error", "删除失败", response.data);
  12696. });
  12697. };
  12698. $scope.submit = function (prodInfo) {
  12699. $scope.prodInfo.isSale = 1;
  12700. $scope.loading = true;
  12701. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12702. $upload.upload({
  12703. url: 'product/baseInfo/edit/updateProdInfo',
  12704. file: file,
  12705. method: 'POST',
  12706. data: {
  12707. prodInfo: $scope.prodInfo
  12708. },
  12709. }).success(function (data) {
  12710. $scope.loading = false;
  12711. if (data.success) {
  12712. toaster.pop('success', '提示', data.success);
  12713. $rootScope.isProductEdit = false;
  12714. loadData();
  12715. // window.location.href="#/sale/prodList";
  12716. }
  12717. if (data.error) {
  12718. toaster.pop('error', '提示', data.error);
  12719. }
  12720. }).error(function (data, status) {
  12721. $scope.loading = false;
  12722. $scope.loadingShow = false;
  12723. if (status == 403){
  12724. toaster.pop('error', '操作失败', data);
  12725. } else {
  12726. toaster.pop('error', '操作失败', data.error);
  12727. }
  12728. });
  12729. }
  12730. $scope.previewShow = false;
  12731. $scope.pdfShow = false;
  12732. $scope.noneFileShow = true;
  12733. $scope.$watch('myFiles', function () {
  12734. if ($scope.myFiles) {
  12735. $scope.noneFileShow = false;
  12736. var file = $scope.myFiles[0];
  12737. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12738. $scope.pdfShow = true;
  12739. $scope.previewShow = false;
  12740. $scope.imgPreviewName = file.name;
  12741. } else {
  12742. if (typeof(Worker) !== "undefined") {//支持HTML5
  12743. $scope.imgPreview = getObjectURL(file);
  12744. $scope.imgPreviewName = file.name;
  12745. } else {//不支持HTML5
  12746. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12747. $scope.imgPreviewName = file.name;
  12748. }
  12749. $scope.previewShow = true;
  12750. $scope.pdfShow = false;
  12751. }
  12752. } else {
  12753. $scope.noneFileShow = true;
  12754. $scope.previewShow = false;
  12755. $scope.pdfShow = false;
  12756. }
  12757. });
  12758. //建立一个可存取到该file的url
  12759. var imgurl = null;
  12760. var getObjectURL = function (file) {
  12761. var url = null;
  12762. if (window.createObjectURL != undefined) { // basic
  12763. url = window.createObjectURL(file);
  12764. } else if (window.URL != undefined) { // mozilla(firefox)
  12765. url = window.URL.createObjectURL(file);
  12766. } else if (window.webkitURL != undefined) { // webkit or chrome
  12767. url = window.webkitURL.createObjectURL(file);
  12768. }
  12769. imgurl = url;
  12770. return url;
  12771. };
  12772. // 查看范例
  12773. $scope.showImg = function () {
  12774. if ($scope.prodInfo.attachment) {
  12775. $scope.imgPreview = $scope.prodInfo.attachment;
  12776. var src = $scope.prodInfo.attachment, box = $('#image-box');
  12777. box.show();
  12778. box.find('img').attr('src', src);
  12779. box.find('a').click(function () {
  12780. box.hide();
  12781. });
  12782. box.dblclick(function () {
  12783. box.hide();
  12784. });
  12785. $scope.previewShow = true;
  12786. } else if (imgurl != null) {
  12787. var src = imgurl, box = $('#image-box');
  12788. box.show();
  12789. box.find('img').attr('src', src);
  12790. box.find('a').click(function () {
  12791. box.hide();
  12792. });
  12793. box.dblclick(function () {
  12794. box.hide();
  12795. });
  12796. }
  12797. };
  12798. }]);
  12799. /**
  12800. * 新增物料(销售)
  12801. */
  12802. app.controller('NewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService, Products) {
  12803. BaseService.scrollBackToTop();
  12804. // 录入人
  12805. AuthenticationService.getAuthentication().success(function (data) {
  12806. $scope.loading = false;
  12807. $scope.user = data;
  12808. });
  12809. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12810. $scope.prodInfo = {};
  12811. // 选择类目
  12812. $scope.selectKind = function () {
  12813. $modal.open({
  12814. animation: true,
  12815. size: 'lg',
  12816. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12817. controller: 'KindChooseCtrl',
  12818. }).result.then(function (data) {
  12819. $scope.kindId = data;
  12820. var modalInstance = $modal.open({
  12821. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12822. controller: 'FindComponentCtrl',
  12823. size: 'lg',
  12824. resolve: {
  12825. KindId: function () {
  12826. return $scope.kindId;
  12827. }
  12828. }
  12829. });
  12830. modalInstance.result.then(function (data) {
  12831. $scope.prodInfo.cmpUuId = data.uuid;
  12832. $scope.prodInfo.pcmpcode = data.code;
  12833. $scope.prodInfo.pbranden = data.brand.nameEn;
  12834. $scope.prodInfo.pbrand = data.brand.nameCn;
  12835. }, function () {
  12836. });
  12837. }, function () {
  12838. });
  12839. };
  12840. // 联想词 start
  12841. // 获取类目
  12842. $scope.getSimilarKinds = function (value) {
  12843. if (value) {
  12844. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12845. return data.map(function (item) {
  12846. return item;
  12847. });
  12848. });
  12849. }
  12850. };
  12851. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12852. $scope.prodInfo.title = kind.kindName;
  12853. }
  12854. $scope.getSimilarBrands = function (value) {
  12855. if (value) {
  12856. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12857. return data.map(function (item) {
  12858. return item;
  12859. });
  12860. });
  12861. }
  12862. }
  12863. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12864. $scope.prodInfo.brand = brand.brandName;
  12865. }
  12866. $scope.getSimilarComponents = function (value) {
  12867. if (value) {
  12868. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12869. return data.map(function (item) {
  12870. return item;
  12871. });
  12872. });
  12873. }
  12874. }
  12875. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12876. $scope.prodInfo.cmpCode = cmp.code;
  12877. }
  12878. // 联想词 end
  12879. // 删除
  12880. $scope.clearfile = function () {
  12881. $scope.myFiles = null;
  12882. $scope.previewShow = false;
  12883. }
  12884. //提交
  12885. $scope.submit = function (prodInfo) {
  12886. $scope.loading = true;
  12887. $scope.prodInfo.isSale = 1;
  12888. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12889. $upload.upload({
  12890. url: 'product/baseInfo/edit/addNewProduct',
  12891. file: file,
  12892. method: 'POST',
  12893. data: {
  12894. prodInfo: prodInfo
  12895. },
  12896. }).success(function (data) {
  12897. $scope.loading = false;
  12898. if (data.success) {
  12899. toaster.pop('success', '提示', '产品添加成功');
  12900. $timeout(function () {
  12901. //提交后跳转到详情页面,防止重复提交
  12902. window.location.href = "#/sale/prodList/" + data.id;
  12903. // window.location.href="#/sale/prodList";
  12904. }, 500);
  12905. }
  12906. if (data.error) {
  12907. toaster.pop('error', '提示', data.error);
  12908. $timeout(function () {
  12909. //提交后跳转到详情页面,防止重复提交
  12910. window.location.href = "#/sale/prodList/" + data.id;
  12911. // window.location.href="#/sale/prodList";
  12912. }, 500);
  12913. }
  12914. }).error(function (data, status) {
  12915. $scope.loading = false;
  12916. $scope.loadingShow = false;
  12917. if (status == 403) {
  12918. toaster.pop('error', '操作失败', data);
  12919. } else {
  12920. toaster.pop('error', '操作失败', data.error);
  12921. }
  12922. });
  12923. };
  12924. $scope.previewShow = false;
  12925. $scope.pdfShow = false;
  12926. $scope.noneFileShow = true;
  12927. $scope.$watch('myFiles', function () {
  12928. if ($scope.myFiles) {
  12929. $scope.noneFileShow = false;
  12930. var file = $scope.myFiles[0];
  12931. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12932. $scope.pdfShow = true;
  12933. $scope.previewShow = false;
  12934. $scope.imgPreviewName = file.name;
  12935. } else {
  12936. if (typeof(Worker) !== "undefined") {//支持HTML5
  12937. $scope.imgPreview = getObjectURL(file);
  12938. $scope.imgPreviewName = file.name;
  12939. } else {//不支持HTML5
  12940. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12941. $scope.imgPreviewName = file.name;
  12942. }
  12943. $scope.previewShow = true;
  12944. $scope.pdfShow = false;
  12945. }
  12946. } else {
  12947. $scope.noneFileShow = true;
  12948. $scope.previewShow = false;
  12949. $scope.pdfShow = false;
  12950. }
  12951. });
  12952. //建立一个可存取到该file的url
  12953. var imgUrl = null
  12954. var getObjectURL = function (file) {
  12955. var url = null;
  12956. if (window.createObjectURL != undefined) { // basic
  12957. url = window.createObjectURL(file);
  12958. } else if (window.URL != undefined) { // mozilla(firefox)
  12959. url = window.URL.createObjectURL(file);
  12960. } else if (window.webkitURL != undefined) { // webkit or chrome
  12961. url = window.webkitURL.createObjectURL(file);
  12962. }
  12963. imgUrl = url;
  12964. return url;
  12965. };
  12966. // 查看范例
  12967. $scope.showImg = function () {
  12968. var src = imgUrl, box = $('#image-box');
  12969. box.show();
  12970. box.find('img').attr('src', src);
  12971. box.find('a').click(function () {
  12972. box.hide();
  12973. });
  12974. box.dblclick(function () {
  12975. box.hide();
  12976. });
  12977. };
  12978. // 取消
  12979. $scope.cancel = function () {
  12980. $scope.prodInfo = angular.copy($scope.prodInfo);
  12981. };
  12982. }]);
  12983. /**
  12984. * 类目选择模态框
  12985. */
  12986. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function ($scope, KindAPI, toaster, $modalInstance, $modal) {
  12987. $scope.kindId = null;
  12988. $scope.kinds = [[], [], [], []];
  12989. // 获取子类目
  12990. var getChildren = function (pid, deep) {
  12991. KindAPI.getChildren({parentId: pid}, function (data) {
  12992. $scope.kinds[deep] = data;
  12993. }, function (response) {
  12994. toaster.pop('error', '获取子类目失败', response.data);
  12995. });
  12996. };
  12997. // 改变节点选中状态
  12998. var changeStatus = function (item, deep) {
  12999. var kindId = null, level = 0;
  13000. angular.forEach($scope.kinds, function (ks, i) {
  13001. if (i > deep) {
  13002. $scope.kinds[i] = [];
  13003. } else {
  13004. angular.forEach(ks, function (k, j) {
  13005. if (i == deep) {
  13006. if (k.id == item.id) {
  13007. $scope.kinds[i][j].$active = true;
  13008. kindId = k.id;
  13009. } else {
  13010. k.$active = null;
  13011. }
  13012. }
  13013. });
  13014. }
  13015. });
  13016. // 选择的节点
  13017. $scope.kindId = kindId;
  13018. $scope.active = item;
  13019. // 当前可操作的层级
  13020. if (deep < 3) {
  13021. $scope.activeDeep = deep + 1;
  13022. }
  13023. };
  13024. // 节点点击后获取子类目,节点被选中
  13025. $scope.onItemClick = function (item, deep) {
  13026. changeStatus(item, deep);
  13027. if (!item.isLeaf) {
  13028. getChildren(item.id, deep + 1);
  13029. }
  13030. };
  13031. // 重新加载数据
  13032. function reload(deep) {
  13033. var pid;
  13034. if (deep) {
  13035. pid = $scope.actives[deep - 1].id;
  13036. } else {
  13037. pid = 0;
  13038. deep = 0;
  13039. }
  13040. getChildren(pid, deep);
  13041. }
  13042. // 初始加载数据,获取第一层的类目
  13043. if ($scope.actives) {
  13044. angular.forEach($scope.actives, function (v, k) {
  13045. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  13046. $scope.kinds[k] = data;
  13047. angular.forEach($scope.kinds[k], function (kind, i) {
  13048. if (kind.id == v.id) {
  13049. $scope.kinds[k][i].$active = true;
  13050. $scope.actives[k] = $scope.kinds[k][i];
  13051. }
  13052. })
  13053. }, function (response) {
  13054. toaster.pop('error', '获取子类目失败', response.data);
  13055. });
  13056. });
  13057. } else {
  13058. reload();
  13059. }
  13060. // 取消
  13061. $scope.cancel = function () {
  13062. $modalInstance.dismiss();
  13063. };
  13064. // 确认选择
  13065. $scope.check = function () {
  13066. $modalInstance.close($scope.kindId);
  13067. };
  13068. }]);
  13069. /**
  13070. * 器件筛选
  13071. */
  13072. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  13073. //状态
  13074. $scope.setActive = function (state) {
  13075. if ($scope.active != state) {
  13076. $scope.active = state;
  13077. if ($scope.tableParams.page() == 1)
  13078. $scope.tableParams.reload();
  13079. else
  13080. $scope.tableParams.page(1);
  13081. }
  13082. };
  13083. $scope.tableParams = new ngTableParams({
  13084. page: 1,
  13085. count: 20
  13086. }, {
  13087. total: 0,
  13088. counts: [5, 10, 25, 50],
  13089. getData: function ($defer, params) {
  13090. $scope.loading = true;
  13091. var pageParams = params.url();
  13092. pageParams.keyword = $scope.keyword;
  13093. pageParams.kindId = KindId;
  13094. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function (page) {
  13095. $scope.loading = false;
  13096. if (page) {
  13097. params.total(page.totalElement);
  13098. $defer.resolve(page.content);
  13099. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13100. }
  13101. }, function (response) {
  13102. $scope.loading = false;
  13103. toaster.pop('error', '数据加载失败', response.data);
  13104. });
  13105. }
  13106. });
  13107. // 取消
  13108. $scope.cancel = function () {
  13109. $modalInstance.dismiss();
  13110. };
  13111. // 选择
  13112. $scope.check = function (data) {
  13113. $modalInstance.close(data);
  13114. };
  13115. // 搜索框回车
  13116. $scope.onSearch = function () {
  13117. $scope.tableParams.page(1);
  13118. $scope.tableParams.reload();
  13119. };
  13120. }]);
  13121. /**
  13122. * 企业列表
  13123. */
  13124. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  13125. BaseService.scrollBackToTop();
  13126. $scope.active = 'all';
  13127. $scope.agreedText = '全部';
  13128. $scope.dateZoneText = '一个月内';
  13129. $scope.condition = {dateZone: 1};
  13130. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13131. $scope.changeAgreed = function (agreed) {
  13132. $scope.condition.agreed = agreed;
  13133. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13134. $scope.condition.$agreedOpen = false;
  13135. };
  13136. $scope.changeDateZone = function (zone) {
  13137. $scope.condition.dateZone = zone;
  13138. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13139. $scope.condition.$dateZoneOpen = false;
  13140. getDateCondition(zone, $scope.condition);
  13141. $scope.tableParams.reload();
  13142. };
  13143. $scope.setActive = function (state) {
  13144. if ($scope.active != state) {
  13145. $scope.active = state;
  13146. if ($scope.tableParams.page() == 1)
  13147. $scope.tableParams.reload();
  13148. else
  13149. $scope.tableParams.page(1);
  13150. }
  13151. };
  13152. var getService = function () {
  13153. return getAccountUserSpace;
  13154. };
  13155. $scope.tableParams = new ngTableParams({
  13156. page: 1,
  13157. count: 20,
  13158. sorting: {}
  13159. }, {
  13160. total: 0,
  13161. counts: [5, 10, 25, 50],
  13162. getData: function ($defer, params) {
  13163. $scope.loading = true;
  13164. var pageParams = params.url();
  13165. pageParams.keyword = $scope.keyword;
  13166. $scope.tip = $scope.keyword;
  13167. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  13168. $scope.loading = false;
  13169. if (page) {
  13170. params.total(page.totalElement);
  13171. $defer.resolve(page.content);
  13172. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13173. }
  13174. }, function (response) {
  13175. $scope.loading = false;
  13176. toaster.pop('error', '数据加载失败', response.data);
  13177. });
  13178. }
  13179. });
  13180. // 搜索框回车
  13181. $scope.onSearch = function () {
  13182. $scope.tableParams.page(1);
  13183. $scope.tableParams.reload();
  13184. };
  13185. // 添加合作关系
  13186. $scope.addPartner = function (name, businessCode) {
  13187. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  13188. if (data.success) {
  13189. toaster.pop("success", '添加成功', data.success);
  13190. $scope.tableParams.reload();
  13191. }
  13192. if (data.error) {
  13193. toaster.pop("error", '添加失败', data.error);
  13194. }
  13195. }, function (response) {
  13196. toaster.pop('error', '失败', response.data);
  13197. });
  13198. }
  13199. $scope.status = 'enList';
  13200. }]);
  13201. /**
  13202. * 新增采购单
  13203. */
  13204. app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', 'recentPrice',
  13205. function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token, recentPrice) {
  13206. BaseService.scrollBackToTop();
  13207. // 每次进入时先清除掉rootScope下的venduu
  13208. $rootScope.venduu = null;
  13209. // 获取收货地址列表
  13210. ShipAddress.shipAddList({}, function (data) {
  13211. $scope.ships = data;
  13212. $scope.order.shipadd = $scope.ships[0];
  13213. });
  13214. // 获取地址信息
  13215. $http.get('resources/citydata/city.json', {
  13216. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  13217. }).then(function (response) {
  13218. $scope.provinces = response.data;
  13219. });
  13220. var getToken = function() {
  13221. if($scope.token == null) {
  13222. token.info({userType: 'purcorder'}, {}, function(data) {
  13223. $scope.token = data.token;
  13224. }, function(response) {
  13225. toaster.pop('error', '提示', response.data);
  13226. });
  13227. }
  13228. }
  13229. getToken();
  13230. $scope.order = {
  13231. date: new Date(),
  13232. vend: {
  13233. uu: '',
  13234. },
  13235. vendUser: {},
  13236. code: $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  13237. orderItems: {
  13238. product: {},
  13239. },
  13240. rate: 17
  13241. };
  13242. //商品信息
  13243. $scope.order.orderItems = [];
  13244. var item = {
  13245. code: null,
  13246. title: null,
  13247. spec: null,
  13248. unit: null,
  13249. qty: null,
  13250. price: null,
  13251. remark: null,
  13252. delivery: null,
  13253. prid: null,
  13254. taxrate: null
  13255. };
  13256. if ($rootScope.businessCode) {
  13257. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function (data) {
  13258. $scope.id = data.id;
  13259. $scope.order.vend.enName = data.vendorEnterprise.enName;
  13260. $scope.order.vend.enAddress = data.vendorEnterprise.enAddress;
  13261. $scope.order.vend.uu = data.vendorEnterprise.uu;
  13262. $scope.order.paymethods = data.paymethod;
  13263. $rootScope.venduu = data.vendorEnterprise.uu;
  13264. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13265. $scope.contacts = data;
  13266. $scope.order.vendor = $scope.contacts[0];
  13267. });
  13268. }, function (response) {
  13269. });
  13270. }
  13271. ;
  13272. // 查找供应商
  13273. $scope.dbfindVend = function () {
  13274. var modalInstance = $modal.open({
  13275. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  13276. controller: 'DbfindVendorInfoCtrl',
  13277. size: 'lg',
  13278. resolve: {
  13279. orderItems: function () {
  13280. return $scope.order.orderItems;
  13281. }
  13282. }
  13283. });
  13284. modalInstance.result.then(function (data) {
  13285. $rootScope.venduu = data.vendorEnterprise.uu;
  13286. $scope.id = data.id;
  13287. $scope.order.vend = data.vendorEnterprise;
  13288. $scope.order.vend.enName = data.vendorEnterprise.enName;
  13289. $scope.order.vendUser = data.vendorUser;
  13290. $scope.order.payments = data.paymethod;
  13291. $scope.order.orderItems = [];
  13292. var item = {
  13293. code: null,
  13294. title: null,
  13295. spec: null,
  13296. unit: null,
  13297. qty: null,
  13298. price: null,
  13299. remark: null,
  13300. delivery: null,
  13301. taxrate: null
  13302. };
  13303. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13304. $scope.contacts = data;
  13305. $scope.order.vendor = $scope.contacts[0];
  13306. });
  13307. }, function () {
  13308. });
  13309. };
  13310. // 联想词 start
  13311. // 获取供应商
  13312. $scope.getSimilarVendors = function (value) {
  13313. if (value) {
  13314. return Vendor.getSimilarVendors({keyword: value}).$promise.then(function (data) {
  13315. return data.map(function (item) {
  13316. return item;
  13317. });
  13318. });
  13319. }
  13320. };
  13321. $scope.onAssociateCmpClick = function (vendor, order) {
  13322. $scope.order.vend.uu = vendor.venduu;
  13323. $scope.id = vendor.id;
  13324. $scope.order.payments = vendor.paymethod;
  13325. $rootScope.venduu = $scope.order.vend.uu;
  13326. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13327. $scope.contacts = data;
  13328. $scope.order.vendor = $scope.contacts[0];
  13329. });
  13330. }
  13331. // 联想词 end
  13332. // $scope.order.orderItems.push(item);
  13333. if ($rootScope.prodId) {
  13334. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  13335. item.code = data.code;
  13336. item.title = data.title;
  13337. item.spec = data.spec;
  13338. item.unit = data.unit;
  13339. item.id = data.id;
  13340. $scope.order.orderItems.push(item);
  13341. $rootScope.prodId = null;// 清除掉prodId
  13342. }, function (response) {
  13343. });
  13344. }
  13345. //增加商品
  13346. $scope.addProduct = function (index) {
  13347. if ($scope.order.orderItems[index].code == null) {
  13348. toaster.pop('info', '提示', '请先选择商品');
  13349. } else {
  13350. $scope.order.orderItems.push({
  13351. code: null,
  13352. title: null,
  13353. spec: null,
  13354. unit: null,
  13355. qty: null,
  13356. price: null,
  13357. remark: null,
  13358. delivery: null,
  13359. $endDateOpen: false,
  13360. taxrate: $scope.order.rate,
  13361. prodsource: 'seller'
  13362. });
  13363. }
  13364. };
  13365. //删除商品
  13366. $scope.deleteProduct = function (index) {
  13367. $scope.order.orderItems.splice(index, 1);
  13368. };
  13369. // 搜索框回车
  13370. $scope.onSearch = function (keyword) {
  13371. $scope.keyword = keyword;
  13372. $scope.tableParams.page(1);
  13373. $scope.tableParams.reload();
  13374. };
  13375. $scope.tableParams = new ngTableParams({
  13376. page: 1,
  13377. count: 20
  13378. }, {
  13379. total: 0,
  13380. counts: [5, 10, 25, 50],
  13381. getData: function ($defer, params) {
  13382. $scope.loading = true;
  13383. var pageParams = params.url();
  13384. pageParams.keyword = $scope.keyword;
  13385. $scope.tip = $scope.keyword;
  13386. pageParams.vendUU = $scope.order.vend.uu;
  13387. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  13388. $scope.loading = false;
  13389. if (page) {
  13390. params.total(page.totalElement);
  13391. $scope.total = page.totalElement;
  13392. $defer.resolve(page.content);
  13393. }
  13394. }, function (response) {
  13395. $scope.loading = false;
  13396. toaster.pop('error', '数据加载失败', response.data);
  13397. });
  13398. }
  13399. });
  13400. // 选择
  13401. $scope.check = function (data) {
  13402. var price = null;
  13403. var qty = null;
  13404. var taxRate = null;
  13405. if (data.id) {
  13406. recentPrice.agreed({prId: data.id}, {}, function(response) {
  13407. price = response.price;
  13408. qty = response.qty;
  13409. taxRate = response.taxRate;
  13410. $scope.order.orderItems.push({
  13411. code: data.code,
  13412. title: data.title,
  13413. spec: data.spec,
  13414. unit: data.unit,
  13415. qty: qty,
  13416. price: price,
  13417. remark: null,
  13418. delivery: null,
  13419. prid: data.id,
  13420. taxrate: taxRate,
  13421. prodsource: 'seller',
  13422. });
  13423. });
  13424. }
  13425. };
  13426. // 导入商品信息
  13427. $scope.uplodaByBatch = function () {
  13428. var modalInstance = $modal.open({
  13429. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  13430. controller: 'PurcUploadByBatchCtrl',
  13431. size: 'lg',
  13432. resolve: {}
  13433. });
  13434. modalInstance.result.then(function (data) {
  13435. angular.forEach(data, function (prod) {
  13436. $scope.order.orderItems.push({
  13437. code: prod.code,
  13438. title: prod.title,
  13439. unit: 'PCS',
  13440. spec: prod.spec,
  13441. qty: prod.amount,
  13442. price: prod.price,
  13443. remark: prod.remark,
  13444. delivery: prod.date,
  13445. prid: prod.id,
  13446. taxrate: prod.rate,
  13447. prodsource: 'purchaser'
  13448. });
  13449. })
  13450. }, function () {
  13451. });
  13452. };
  13453. // 监听venduu发生变化,重新加载物料信息
  13454. $scope.$watch('order.vend.uu', function (n, o) {
  13455. if (n == o) {
  13456. return;
  13457. } else {
  13458. $scope.tableParams.page(1);
  13459. $scope.tableParams.reload();
  13460. }
  13461. }, true);
  13462. $scope.getMinDate = function (item) {
  13463. return $filter('date')(new Date, 'yyyy-MM-dd');
  13464. };
  13465. $scope.openDatePicker = function ($event, openParam, index) {
  13466. $event.preventDefault();
  13467. $event.stopPropagation();
  13468. $scope.order.orderItems[index].$endDateOpen = !openParam;
  13469. };
  13470. // 添加到购物车
  13471. $scope.addToCart = function (order) {
  13472. $scope.loading = true;
  13473. $scope.order.status = 311;
  13474. $scope.order.vendusertel = order.vendor.tel;
  13475. $scope.order.venduser = order.vendor.venduser;
  13476. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13477. $scope.order.vendUU = $scope.order.vend.uu;
  13478. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13479. if ($scope.order.date instanceof Date) {
  13480. $scope.order.date = $scope.order.date.getTime();
  13481. }
  13482. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13483. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13484. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13485. }
  13486. if ($scope.order.currency != 'RMB') {
  13487. $scope.order.orderItems[i].rate = 0;
  13488. }
  13489. }
  13490. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13491. $scope.loading = false;
  13492. toaster.pop('success', '成功', '保存成功');
  13493. window.location.hash = '#/purc/cart/' + data.id;
  13494. $window.location.reload();
  13495. }, function (response) {
  13496. $scope.loading = false;
  13497. toaster.pop('error', '保存失败', response.data);
  13498. });
  13499. };
  13500. // 立即购买
  13501. $scope.addToOrder = function (order) {
  13502. $scope.loading = true;
  13503. $scope.order.status = 200;
  13504. $scope.order.vendusertel = order.vendor.tel;
  13505. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  13506. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13507. $scope.order.vendUU = $scope.order.vend.uu;
  13508. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13509. if ($scope.order.date instanceof Date) {
  13510. $scope.order.date = $scope.order.date.getTime();
  13511. }
  13512. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13513. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13514. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13515. }
  13516. if ($scope.order.currency != 'RMB') {
  13517. $scope.order.orderItems[i].rate = 0;
  13518. }
  13519. }
  13520. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13521. $scope.loading = false;
  13522. toaster.pop('success', '成功', '保存成功');
  13523. window.location.hash = '#/purc/order/' + data.id;
  13524. }, function (response) {
  13525. $scope.loading = false;
  13526. toaster.pop('error', '保存失败', response.data);
  13527. });
  13528. };
  13529. // 新增收货地址保存
  13530. $scope.saveShipAddress = function (ship) {
  13531. ship.address = ship.province + ship.city + ship.district;
  13532. ShipAddress.saveAddress({}, ship, function (data) {
  13533. if (data.success) {
  13534. ShipAddress.shipAddList({}, function (data) {
  13535. $scope.ships = data;
  13536. $scope.order.shipadd = $scope.ships[0];
  13537. });
  13538. toaster.pop('success', '提示', data.success);
  13539. }
  13540. if (data.error) {
  13541. toaster.pop('error', '提示', data.error);
  13542. }
  13543. });
  13544. }
  13545. // 新增供应商联系人
  13546. $scope.addContact = function (uu) {
  13547. var modalInstance = $modal.open({
  13548. animation: true,
  13549. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13550. controller: 'AddContacCtrl',
  13551. resolve: {}
  13552. });
  13553. modalInstance.result.then(function (data) {
  13554. $scope.contact = data;
  13555. $scope.contact.venduu = uu;
  13556. Vendor.saveContact({}, $scope.contact, function (data) {
  13557. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13558. $scope.contacts = data;
  13559. $scope.order.vendor = $scope.contacts[0];
  13560. });
  13561. toaster.pop('success', '提示', '联系人保存成功');
  13562. }, function (response) {
  13563. toaster.pop('error', '失败', response.data);
  13564. });
  13565. });
  13566. }
  13567. }]);
  13568. /**
  13569. * 采购批量导入
  13570. */
  13571. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  13572. // 通过excel批量上传物料
  13573. $scope.result = null;
  13574. $scope.loading = false;
  13575. $scope.upload = function () {
  13576. $scope.loading = true;
  13577. var file = $scope.myFiles[0];
  13578. $upload.upload({
  13579. url: 'purchase/release/excel',
  13580. file: file,
  13581. method: 'POST'
  13582. }).success(function (data) {
  13583. $scope.loading = false;
  13584. $scope.result = data;
  13585. $scope.success = $scope.result.success;
  13586. $scope.total = $scope.result.total;
  13587. $scope.alters = $scope.result.alters;
  13588. }).error(function (response) {
  13589. $scope.loading = false;
  13590. toaster.pop('error', response.data || response);
  13591. });
  13592. };
  13593. // 下载模板
  13594. $scope.download = function () {
  13595. window.location.href = 'purchase/upload/template';
  13596. };
  13597. $scope.enSure = function () {
  13598. $modalInstance.close($scope.result.products);
  13599. }
  13600. // 点击确定时增加加载标志
  13601. $scope.addClass = function() {
  13602. $scope.loading = true;
  13603. }
  13604. $scope.cancel = function () {
  13605. $modalInstance.dismiss();
  13606. }
  13607. }]);
  13608. // 查找供应商
  13609. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems) {
  13610. $scope.prod = false;
  13611. if (orderItems.length != 0) {
  13612. $scope.prod = true;
  13613. }
  13614. BaseService.scrollBackToTop();
  13615. if ($rootScope.venduu != null) {
  13616. $scope.venduu = $rootScope.venduu;
  13617. }
  13618. // 搜索框回车
  13619. $scope.onSearch = function (keyword) {
  13620. $scope.keyword = keyword;
  13621. $scope.customerParams.page(1);
  13622. $scope.customerParams.reload();
  13623. };
  13624. $scope.customerParams = new ngTableParams({
  13625. page: 1,
  13626. count: 20
  13627. }, {
  13628. total: 0,
  13629. counts: [5, 10, 25, 50],
  13630. getData: function ($defer, params) {
  13631. $scope.loading = true;
  13632. var pageParams = params.url();
  13633. pageParams.keyword = $scope.keyword;
  13634. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13635. $scope.loading = false;
  13636. if (page) {
  13637. params.total(page.totalElement);
  13638. $defer.resolve(page.content);
  13639. }
  13640. $scope.totalCount = page.totalElement;
  13641. }, function (response) {
  13642. $scope.loading = false;
  13643. toaster.pop('error', '数据加载失败', response.data);
  13644. });
  13645. }
  13646. });
  13647. $scope.cancel = function () {
  13648. $modalInstance.dismiss();
  13649. };
  13650. $scope.ensure = false;
  13651. $scope.check = function (vendor) { // 需要进行判断的选择
  13652. $scope.vendorInfo = vendor;
  13653. $scope.ensure = true;
  13654. };
  13655. $scope.checkVendor = function (vendor) { // 直接选择
  13656. $modalInstance.close(vendor);
  13657. }
  13658. }]);
  13659. /**
  13660. * 我的客户
  13661. */
  13662. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster) {
  13663. $scope.userInfoResult = true;
  13664. AuthenticationService.getAuthentication().success(function (data) {
  13665. $scope.loading = false;
  13666. $scope.thisUser = data;
  13667. });
  13668. var getCustInfos = function (custuu) {
  13669. if (custuu) {
  13670. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  13671. $scope.custInfos = data;
  13672. var getPage = function (page, size) {
  13673. if ($scope.custInfos) {
  13674. var result = {};
  13675. result.totalCount = $scope.custInfos.length;
  13676. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  13677. if ($scope.custInfos.length % size == 0) {
  13678. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  13679. } else {
  13680. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  13681. }
  13682. result.first = page == 1;
  13683. result.last = page == result.totalPage;
  13684. result.page = page;
  13685. result.next = page - 0 + 1;
  13686. result.pre = page - 1;
  13687. return result;
  13688. }
  13689. }
  13690. $scope.userdata = getPage(1, 4);
  13691. $scope.first = function () {
  13692. $scope.userdata = getPage($scope.userdata.pre, 4);
  13693. }
  13694. $scope.last = function () {
  13695. $scope.userdata = getPage($scope.userdata.next, 4);
  13696. }
  13697. }, function (response) {
  13698. $scope.loading = false;
  13699. toaster.pop('error', '数据加载失败', response.data);
  13700. });
  13701. }
  13702. }
  13703. // 分配权限
  13704. $scope.addUserInfo = function (customer) {
  13705. //TODO
  13706. if ($scope.thisUser.sys) {
  13707. var modalInstance = $modal.open({
  13708. animation: true,
  13709. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  13710. controller: 'AddUserInfoCtrl',
  13711. resolve: {
  13712. customer: function () {
  13713. return customer;
  13714. }
  13715. }
  13716. });
  13717. modalInstance.result.then(function (changed, checked) {
  13718. if (changed) {
  13719. if (checked)
  13720. $scope.newUser.roles = checked;
  13721. else
  13722. loadUsers();
  13723. }
  13724. });
  13725. } else {
  13726. toaster.pop('error', '您没有分配用户的权限!');
  13727. }
  13728. };
  13729. $scope.showUserInfo = function (customer, boo) {
  13730. $scope.custInfo = customer;
  13731. if (boo) {
  13732. getCustInfos(customer.myEnterprise.uu);
  13733. $scope.userInfoResult = true;
  13734. }
  13735. }
  13736. $scope.customerParams = new ngTableParams({
  13737. page: 1,
  13738. count: 20
  13739. }, {
  13740. total: 0,
  13741. counts: [5, 10, 25, 50],
  13742. getData: function ($defer, params) {
  13743. $scope.loading = true;
  13744. VendorService.customer.get(BaseService.parseParams(params.url()), function (page) {
  13745. $scope.loading = false;
  13746. if (page) {
  13747. params.total(page.totalElement);
  13748. $defer.resolve(page.content);
  13749. }
  13750. $scope.totalCount = page.totalElement;
  13751. }, function (response) {
  13752. $scope.loading = false;
  13753. toaster.pop('error', '数据加载失败', response.data);
  13754. });
  13755. }
  13756. });
  13757. }]);
  13758. /**
  13759. * 我的供应商
  13760. */
  13761. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  13762. BaseService.scrollBackToTop();
  13763. // 搜索框回车
  13764. $scope.onSearch = function (keyword) {
  13765. $scope.keyword = keyword;
  13766. $scope.customerParams.page(1);
  13767. $scope.customerParams.reload();
  13768. };
  13769. $scope.customerParams = new ngTableParams({
  13770. page: 1,
  13771. count: 20
  13772. }, {
  13773. total: 0,
  13774. counts: [5, 10, 25, 50],
  13775. getData: function ($defer, params) {
  13776. $scope.loading = true;
  13777. var pageParams = params.url();
  13778. pageParams.keyword = $scope.keyword;
  13779. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13780. $scope.loading = false;
  13781. if (page) {
  13782. params.total(page.totalElement);
  13783. $scope.total = page.totalElement;
  13784. $defer.resolve(page.content);
  13785. }
  13786. $scope.totalCount = page.totalElement;
  13787. }, function (response) {
  13788. $scope.loading = false;
  13789. toaster.pop('error', '数据加载失败', response.data);
  13790. });
  13791. }
  13792. });
  13793. //设置消息已读
  13794. var setOrdersRead = function () {
  13795. var ids=[];
  13796. Vendor.setVendorRead({}, ids, function (message) {
  13797. });
  13798. };
  13799. setOrdersRead();
  13800. // 查看供应商详情
  13801. $scope.VendorDetail = function (id, uu) {
  13802. $rootScope.vendorId = id;
  13803. $rootScope.vendoruu = uu;
  13804. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  13805. }
  13806. // 向企业购买
  13807. $scope.purcByEn = function (businessCode) {
  13808. $rootScope.businessCode = businessCode;
  13809. window.location.hash = "#/purc/addOrder";
  13810. }
  13811. }]);
  13812. /**
  13813. * 供应商详情
  13814. */
  13815. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  13816. BaseService.scrollBackToTop();
  13817. $scope.vendorContacts = [];
  13818. var loadData = function () {
  13819. Vendor.getVendorDetail({id: $stateParams.id}, {}, function (data) {
  13820. $scope.vendor = data.vendorEnterprise;
  13821. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  13822. $scope.vendorContacts = data;
  13823. });
  13824. }, function (response) {
  13825. toaster.pop('error', '提示', response.data);
  13826. });
  13827. };
  13828. loadData();
  13829. // 新增供应商联系人
  13830. $scope.addContact = function (uu) {
  13831. var modalInstance = $modal.open({
  13832. animation: true,
  13833. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13834. controller: 'AddContacCtrl',
  13835. resolve: {}
  13836. });
  13837. modalInstance.result.then(function (data) {
  13838. $scope.contact = data;
  13839. $scope.contact.venduu = uu;
  13840. Vendor.saveContact({}, $scope.contact, function (data) {
  13841. toaster.pop('success', '提示', '联系人保存成功');
  13842. $scope.vendorContacts.push(data);
  13843. }, function (response) {
  13844. toaster.pop('error', '失败', response.data);
  13845. });
  13846. });
  13847. };
  13848. // 编辑供应商联系人
  13849. $scope.edit = function (contact) {
  13850. var modalInstance = $modal.open({
  13851. animation: true,
  13852. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13853. controller: 'EditContacCtrl',
  13854. resolve: {
  13855. contact: function () {
  13856. return contact;
  13857. }
  13858. }
  13859. });
  13860. modalInstance.result.then(function (data) {
  13861. Vendor.saveContact({}, data, function (data) {
  13862. loadData();
  13863. toaster.pop('success', '提示', '联系人修改成功');
  13864. }, function (response) {
  13865. toaster.pop('error', '失败', response.data);
  13866. });
  13867. });
  13868. }
  13869. // 删除供应商联系人
  13870. $scope.deleteById = function (id, index) {
  13871. $scope.vendorContacts.splice(index, 1);
  13872. Vendor.deleteContact({id: id}, {}, function (data) {
  13873. toaster.pop('success', '提示', '供应商联系人删除成功');
  13874. loadData();
  13875. }, function (response) {
  13876. toaster.pop('error', '提示', response.data);
  13877. });
  13878. }
  13879. // 供应商物料信息
  13880. $scope.viewProdList = function (uu) {
  13881. $scope.uu = uu;
  13882. $scope.tableParams.page(1);
  13883. $scope.tableParams.reload();
  13884. };
  13885. // 搜索框回车
  13886. $scope.onSearch = function (keyword) {
  13887. $scope.keyword = keyword;
  13888. $scope.tableParams.page(1);
  13889. $scope.tableParams.reload();
  13890. };
  13891. // 供应商物料信息
  13892. $scope.tableParams = new ngTableParams({
  13893. page: 1,
  13894. count: 20
  13895. }, {
  13896. total: 0,
  13897. counts: [5, 10, 25, 50],
  13898. getData: function ($defer, params) {
  13899. $scope.loading = true;
  13900. var pageParams = params.url();
  13901. pageParams.custUU = $scope.uu;
  13902. pageParams.keyword = $scope.keyword;
  13903. $scope.tip = $scope.keyword;
  13904. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  13905. $scope.loading = false;
  13906. if (page) {
  13907. params.total(page.totalElement);
  13908. $scope.total = page.totalElement;
  13909. $defer.resolve(page.content);
  13910. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13911. }
  13912. }, function (response) {
  13913. $scope.loading = false;
  13914. toaster.pop('error', '数据加载失败', response.data);
  13915. });
  13916. }
  13917. });
  13918. /**
  13919. * 选中单个物料购买
  13920. * @param businessCode
  13921. * @param id
  13922. */
  13923. $scope.PurcByEnAndProd = function (businessCode, id) {
  13924. $rootScope.businessCode = businessCode;
  13925. $rootScope.prodId = id;
  13926. window.location.hash = "#/purc/addOrder";
  13927. }
  13928. /**
  13929. * 询价
  13930. */
  13931. $scope.PurcInquiry = function (businessCode, id) {
  13932. $rootScope.prodId = id;
  13933. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  13934. }
  13935. }]);
  13936. /**
  13937. * 编辑供应商联系人
  13938. */
  13939. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function ($scope, toaster, $modalInstance, contact) {
  13940. $scope.contact = angular.copy(contact);
  13941. $scope.save = function (contact) {
  13942. $modalInstance.close(contact);
  13943. };
  13944. $scope.cancel = function () {
  13945. $modalInstance.dismiss();
  13946. }
  13947. }]);
  13948. /**
  13949. * 新增供应商联系人
  13950. */
  13951. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function ($scope, toaster, $modalInstance) {
  13952. $scope.save = function (contact) {
  13953. $modalInstance.close(contact);
  13954. };
  13955. $scope.cancel = function () {
  13956. $modalInstance.dismiss();
  13957. }
  13958. }]);
  13959. /**
  13960. * 建立合作关系申请 (我的合作伙伴)
  13961. */
  13962. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  13963. BaseService.scrollBackToTop();
  13964. $scope.status = "partner";
  13965. $scope.active = 'done';
  13966. var getRequestStatus = function (active) {
  13967. var fn = 'getAllRequest';
  13968. switch (active) {
  13969. case 'done':
  13970. fn = 'getRequestDone';
  13971. break;
  13972. case 'todo':
  13973. fn = 'getRequestTodo';
  13974. break;
  13975. case 'end':
  13976. fn = 'getRequestEnd';
  13977. break;
  13978. }
  13979. return fn;
  13980. }
  13981. // 切换单据类型
  13982. $scope.setActive = function (state) {
  13983. if ($scope.active != state) {
  13984. $scope.active = state;
  13985. if ($scope.tableParams.page() == 1)
  13986. $scope.tableParams.reload();
  13987. else
  13988. $scope.tableParams.page(1);
  13989. }
  13990. };
  13991. // 切换数据来源(正常数据 or 历史数据)
  13992. var getService = function () {
  13993. return AddPartnerMyRequest;
  13994. };
  13995. $scope.tableParams = new ngTableParams({ // ng-Table参数
  13996. page: 1,
  13997. count: 20,
  13998. sorting: {}
  13999. }, {
  14000. total: 0,
  14001. counts: [],
  14002. getData: function ($defer, params) { // 获取数据的方法
  14003. $scope.loading = true;
  14004. var pageParams = params.url();
  14005. pageParams.keyword = $scope.keyword;
  14006. if ($rootScope.vendName) {
  14007. pageParams.keyword = $rootScope.vendName;
  14008. $scope.keyword = $rootScope.vendName;
  14009. $rootScope.vendName = null;
  14010. }
  14011. $scope.tip = $scope.keyword;
  14012. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14013. $scope.loading = false;
  14014. if (page) {
  14015. params.total(page.totalElement);
  14016. $defer.resolve(page.content);
  14017. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14018. }
  14019. }, function (response) {
  14020. $scope.loading = false;
  14021. toaster.pop('error', '数据加载失败', response.data);
  14022. });
  14023. }
  14024. });
  14025. // 再次申请
  14026. $scope.addAgain = function (name, businessCode) {
  14027. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14028. if (data.success) {
  14029. toaster.pop("success", '添加成功', data.success);
  14030. $scope.tableParams.reload();
  14031. }
  14032. if (data.error) {
  14033. toaster.pop("error", '添加失败', data.error);
  14034. }
  14035. }, function (response) {
  14036. toaster.pop('error', '失败', response.data);
  14037. });
  14038. }
  14039. // 添加为供应商
  14040. $scope.addSupplier = function (vendUID) {
  14041. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14042. if (data.success) {
  14043. toaster.pop('success', '提示', data.success);
  14044. $scope.tableParams.reload();
  14045. }
  14046. if (data.error) {
  14047. toaster.pop('error', '提示', data.error);
  14048. }
  14049. }, function (response) {
  14050. toaster.pop('error', '失败', response.data);
  14051. })
  14052. };
  14053. // 添加为供应商
  14054. $scope.addServicer = function (vendUID) {
  14055. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14056. if (data.success) {
  14057. toaster.pop('success', '提示', data.success);
  14058. $scope.tableParams.reload();
  14059. }
  14060. if (data.error) {
  14061. toaster.pop('error', '提示', data.error);
  14062. }
  14063. }, function (response) {
  14064. toaster.pop('error', '失败', response.data);
  14065. })
  14066. };
  14067. // 添加客户
  14068. $scope.addCust = function (vendUID) {
  14069. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14070. if (data.success) {
  14071. toaster.pop('success', '提示', data.success);
  14072. $scope.tableParams.reload();
  14073. }
  14074. if (data.error) {
  14075. toaster.pop('error', '提示', data.error);
  14076. }
  14077. }, function (response) {
  14078. toaster.pop('error', '失败', response.data);
  14079. })
  14080. };
  14081. // 搜索框回车
  14082. $scope.onSearch = function () {
  14083. $scope.tableParams.page(1);
  14084. $scope.tableParams.reload();
  14085. };
  14086. // 同意申请
  14087. $scope.agree = function (id) {
  14088. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14089. if (data.success) {
  14090. toaster.pop('success', '提示', '操作成功');
  14091. }
  14092. if (data.error) {
  14093. toaster.pop('error', '提示', '操作失败');
  14094. }
  14095. // $scope.tableParams.reload();
  14096. $window.location.reload();
  14097. }, function (response) {
  14098. toaster.pop('error', '提示', response.data);
  14099. });
  14100. };
  14101. // 拒绝申请
  14102. $scope.refuse = function (id, reason) {
  14103. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14104. if (data.success) {
  14105. toaster.pop('success', '提示', '操作成功');
  14106. }
  14107. if (data.error) {
  14108. toaster.pop('error', '提示', '操作失败');
  14109. }
  14110. // $scope.tableParams.reload();
  14111. $window.location.reload();
  14112. }, function (response) {
  14113. toaster.pop('error', '提示', response.data);
  14114. });
  14115. };
  14116. // 取消供应商关系
  14117. $scope.relieve = function (id) {
  14118. VendorInfo.relieve({id: id}, {}, function (data) {
  14119. if (data.success) {
  14120. toaster.pop('success', '提示', data.success);
  14121. }
  14122. // $scope.tableParams.page(1);
  14123. $scope.tableParams.reload();
  14124. }, function (response) {
  14125. toaster.pop('error', '提示', response.data);
  14126. });
  14127. };
  14128. // 建立供应商关系
  14129. $scope.activeVend = function (id) {
  14130. VendorInfo.activeVend({id: id}, {}, function (data) {
  14131. if (data.success) {
  14132. toaster.pop('success', '提示', data.success);
  14133. }
  14134. // $scope.tableParams.page(1);
  14135. $scope.tableParams.reload();
  14136. }, function (response) {
  14137. toaster.pop('error', '提示', response.data);
  14138. });
  14139. };
  14140. // 取消服务商
  14141. $scope.relieveServicer = function (id) {
  14142. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14143. if (data.success) {
  14144. toaster.pop('success', '提示', data.success);
  14145. }
  14146. $scope.tableParams.reload();
  14147. }, function (response) {
  14148. toaster.pop('error', '提示', response.data);
  14149. });
  14150. };
  14151. // 启用服务商
  14152. $scope.activeServicer = function (id) {
  14153. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14154. if (data.success) {
  14155. toaster.pop('success', '提示', data.success);
  14156. }
  14157. $scope.tableParams.reload();
  14158. }, function (response) {
  14159. toaster.pop('error', '提示', response.data);
  14160. });
  14161. };
  14162. // 取消客户关系
  14163. $scope.disableCust = function (id) {
  14164. VendorInfo.disableCust({id: id}, {}, function (data) {
  14165. if (data.success) {
  14166. toaster.pop('success', '提示', data.success);
  14167. }
  14168. $scope.tableParams.page(1);
  14169. $scope.tableParams.reload();
  14170. }, function (response) {
  14171. toaster.pop('error', '提示', response.data);
  14172. });
  14173. };
  14174. // 激活客户关系
  14175. $scope.activeCust = function (id) {
  14176. VendorInfo.activeCust({id: id}, {}, function (data) {
  14177. if (data.success) {
  14178. toaster.pop('success', '提示', data.success);
  14179. }
  14180. $scope.tableParams.page(1);
  14181. $scope.tableParams.reload();
  14182. }, function (response) {
  14183. toaster.pop('error', '提示', response.data);
  14184. });
  14185. }
  14186. }]);
  14187. /**
  14188. * 建立合作关系申请 (新的合作伙伴)
  14189. */
  14190. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', '$modal',
  14191. function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window, $modal) {
  14192. BaseService.scrollBackToTop();
  14193. $scope.status = "partner";
  14194. $scope.active = 'all'; // 所有申请记录
  14195. var getRequestStatus = function (active) {
  14196. var fn = 'getAllRequest';
  14197. switch (active) {
  14198. case 'done':
  14199. fn = 'getRequestDone';
  14200. break;
  14201. case 'todo':
  14202. fn = 'getRequestTodo';
  14203. break;
  14204. case 'end':
  14205. fn = 'getRequestEnd';
  14206. break;
  14207. }
  14208. return fn;
  14209. }
  14210. // 切换单据类型
  14211. $scope.setActive = function (state) {
  14212. if ($scope.active != state) {
  14213. $scope.active = state;
  14214. if ($scope.tableParams.page() == 1)
  14215. $scope.tableParams.reload();
  14216. else
  14217. $scope.tableParams.page(1);
  14218. }
  14219. };
  14220. // 切换数据来源(正常数据 or 历史数据)
  14221. var getService = function () {
  14222. return AddPartnerMyRequest;
  14223. };
  14224. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14225. page: 1,
  14226. count: 20,
  14227. sorting: {}
  14228. }, {
  14229. total: 0,
  14230. counts: [],
  14231. getData: function ($defer, params) { // 获取数据的方法
  14232. $scope.loading = true;
  14233. var pageParams = params.url();
  14234. pageParams.keyword = $scope.keyword;
  14235. if ($rootScope.vendName) {
  14236. pageParams.keyword = $rootScope.vendName;
  14237. $scope.keyword = $rootScope.vendName;
  14238. $rootScope.vendName = null;
  14239. }
  14240. $scope.tip = $scope.keyword;
  14241. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14242. $scope.loading = false;
  14243. if (page) {
  14244. params.total(page.totalElement);
  14245. $defer.resolve(page.content);
  14246. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14247. }
  14248. }, function (response) {
  14249. $scope.loading = false;
  14250. toaster.pop('error', '数据加载失败', response.data);
  14251. });
  14252. }
  14253. });
  14254. // 再次申请
  14255. $scope.addAgain = function (name, businessCode) {
  14256. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14257. if (data.success) {
  14258. toaster.pop("success", '添加成功', data.success);
  14259. $scope.tableParams.reload();
  14260. }
  14261. if (data.error) {
  14262. toaster.pop("error", '添加失败', data.error);
  14263. }
  14264. }, function (response) {
  14265. toaster.pop('error', '失败', response.data);
  14266. });
  14267. }
  14268. // 添加为供应商
  14269. $scope.addSupplier = function (vendUID) {
  14270. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14271. if (data.success) {
  14272. toaster.pop('success', '提示', data.success);
  14273. $scope.tableParams.reload();
  14274. }
  14275. if (data.error) {
  14276. toaster.pop('error', '提示', data.error);
  14277. }
  14278. }, function (response) {
  14279. toaster.pop('error', '失败', response.data);
  14280. })
  14281. };
  14282. // 添加为供应商
  14283. $scope.addServicer = function (vendUID) {
  14284. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14285. if (data.success) {
  14286. toaster.pop('success', '提示', data.success);
  14287. $scope.tableParams.reload();
  14288. }
  14289. if (data.error) {
  14290. toaster.pop('error', '提示', data.error);
  14291. }
  14292. }, function (response) {
  14293. toaster.pop('error', '失败', response.data);
  14294. })
  14295. };
  14296. // 添加客户
  14297. $scope.addCust = function (vendUID) {
  14298. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14299. if (data.success) {
  14300. toaster.pop('success', '提示', data.success);
  14301. $scope.tableParams.reload();
  14302. }
  14303. if (data.error) {
  14304. toaster.pop('error', '提示', data.error);
  14305. }
  14306. }, function (response) {
  14307. toaster.pop('error', '失败', response.data);
  14308. })
  14309. };
  14310. // 搜索框回车
  14311. $scope.onSearch = function () {
  14312. $scope.tableParams.page(1);
  14313. $scope.tableParams.reload();
  14314. };
  14315. // 同意申请
  14316. $scope.agree = function (id) {
  14317. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14318. if (data.success) {
  14319. toaster.pop('success', '提示', '操作成功');
  14320. if (data.result) {
  14321. //选择打印模板
  14322. var modalInstance = $modal.open({
  14323. templateUrl: 'static/tpl/index/baseInfo/modal/partnership_modal.html',
  14324. controller: 'PartnerShipCtrl',
  14325. resolve: {
  14326. PartnerShipInfo: function () {
  14327. return data.result;
  14328. }
  14329. }
  14330. });
  14331. modalInstance.result.then(function () {
  14332. window.location.reload();
  14333. });
  14334. }
  14335. }
  14336. if (data.error) {
  14337. toaster.pop('error', '提示', '操作失败');
  14338. }
  14339. }, function (response) {
  14340. toaster.pop('error', '提示', response.data);
  14341. });
  14342. };
  14343. AddPartnerMyRequest.requestAmount({}, function (data) {
  14344. $scope.requestTodo = data;
  14345. });
  14346. // 拒绝申请
  14347. $scope.refuse = function (id, reason) {
  14348. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14349. if (data.success) {
  14350. toaster.pop('success', '提示', '操作成功');
  14351. }
  14352. if (data.error) {
  14353. toaster.pop('error', '提示', '操作失败');
  14354. }
  14355. // $scope.tableParams.reload();
  14356. $window.location.reload();
  14357. }, function (response) {
  14358. toaster.pop('error', '提示', response.data);
  14359. });
  14360. };
  14361. // 取消供应商关系
  14362. $scope.relieve = function (id) {
  14363. VendorInfo.relieve({id: id}, {}, function (data) {
  14364. if (data.success) {
  14365. toaster.pop('success', '提示', data.success);
  14366. }
  14367. // $scope.tableParams.page(1);
  14368. $scope.tableParams.reload();
  14369. }, function (response) {
  14370. toaster.pop('error', '提示', response.data);
  14371. });
  14372. }
  14373. // 建立供应商关系
  14374. $scope.activeVend = function (id) {
  14375. VendorInfo.activeVend({id: id}, {}, function (data) {
  14376. if (data.success) {
  14377. toaster.pop('success', '提示', data.success);
  14378. }
  14379. // $scope.tableParams.page(1);
  14380. $scope.tableParams.reload();
  14381. }, function (response) {
  14382. toaster.pop('error', '提示', response.data);
  14383. });
  14384. }
  14385. // 取消服务商
  14386. $scope.relieveServicer = function (id) {
  14387. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14388. if (data.success) {
  14389. toaster.pop('success', '提示', data.success);
  14390. }
  14391. $scope.tableParams.reload();
  14392. }, function (response) {
  14393. toaster.pop('error', '提示', response.data);
  14394. });
  14395. }
  14396. // 启用服务商
  14397. $scope.activeServicer = function (id) {
  14398. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14399. if (data.success) {
  14400. toaster.pop('success', '提示', data.success);
  14401. }
  14402. $scope.tableParams.reload();
  14403. }, function (response) {
  14404. toaster.pop('error', '提示', response.data);
  14405. });
  14406. }
  14407. // 取消客户关系
  14408. $scope.disableCust = function (id) {
  14409. VendorInfo.disableCust({id: id}, {}, function (data) {
  14410. if (data.success) {
  14411. toaster.pop('success', '提示', data.success);
  14412. }
  14413. // $scope.tableParams.page(1);
  14414. $scope.tableParams.reload();
  14415. }, function (response) {
  14416. toaster.pop('error', '提示', response.data);
  14417. });
  14418. }
  14419. // 激活客户关系
  14420. $scope.activeCust = function (id) {
  14421. VendorInfo.activeCust({id: id}, {}, function (data) {
  14422. if (data.success) {
  14423. toaster.pop('success', '提示', data.success);
  14424. }
  14425. $scope.tableParams.reload();
  14426. }, function (response) {
  14427. toaster.pop('error', '提示', response.data);
  14428. });
  14429. }
  14430. }]);
  14431. /**
  14432. * 同意申请后续操作
  14433. */
  14434. app.controller('PartnerShipCtrl', ['$scope', 'PartnerShipInfo', '$modalInstance', 'AddPartner', 'toaster',
  14435. function($scope, PartnerShipInfo, $modalInstance, AddPartner, toaster) {
  14436. $scope.partInfo = PartnerShipInfo;
  14437. // 添加为服务商
  14438. $scope.addServicer = function (vendUID) {
  14439. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14440. if (data.success) {
  14441. toaster.pop('success', '提示', data.success);
  14442. $scope.tableParams.reload();
  14443. }
  14444. if (data.error) {
  14445. toaster.pop('error', '提示', data.error);
  14446. }
  14447. }, function (response) {
  14448. toaster.pop('error', '失败', response.data);
  14449. })
  14450. };
  14451. // 添加客户
  14452. $scope.addCust = function (vendUID) {
  14453. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14454. if (data.success) {
  14455. toaster.pop('success', '提示', data.success);
  14456. $scope.tableParams.reload();
  14457. }
  14458. if (data.error) {
  14459. toaster.pop('error', '提示', data.error);
  14460. }
  14461. }, function (response) {
  14462. toaster.pop('error', '失败', response.data);
  14463. })
  14464. };
  14465. // 添加为供应商
  14466. $scope.addSupplier = function (vendUID) {
  14467. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14468. if (data.success) {
  14469. toaster.pop('success', '提示', data.success);
  14470. $scope.tableParams.reload();
  14471. }
  14472. if (data.error) {
  14473. toaster.pop('error', '提示', data.error);
  14474. }
  14475. }, function (response) {
  14476. toaster.pop('error', '失败', response.data);
  14477. })
  14478. };
  14479. // 关闭
  14480. $scope.close = function() {
  14481. $modalInstance.close();
  14482. }
  14483. }]);
  14484. /**
  14485. * 建立合作关系处理申请
  14486. */
  14487. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', '$window', function ($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest, $window) {
  14488. BaseService.scrollBackToTop();
  14489. $scope.active = 'todo';
  14490. var getMessagetStatus = function (active) {
  14491. var fn = 'getAllMessage';
  14492. switch (active) {
  14493. case 'done':
  14494. fn = 'getMessageDone';
  14495. break;
  14496. case 'todo':
  14497. fn = 'getMessageTodo';
  14498. break;
  14499. case 'end':
  14500. fn = 'getMessageEnd';
  14501. break;
  14502. }
  14503. return fn;
  14504. }
  14505. // 切换单据类型
  14506. $scope.setActive = function (state) {
  14507. if ($scope.active != state) {
  14508. $scope.active = state;
  14509. if ($scope.tableParams.page() == 1)
  14510. $scope.tableParams.reload();
  14511. else
  14512. $scope.tableParams.page(1);
  14513. }
  14514. };
  14515. var getService = function () {
  14516. return AddPartnerMyMessage;
  14517. };
  14518. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14519. page: 1,
  14520. count: 20,
  14521. sorting: {}
  14522. }, {
  14523. total: 0,
  14524. counts: [5, 10, 15, 25, 50],
  14525. getData: function ($defer, params) { // 获取数据的方法
  14526. $scope.loading = true;
  14527. var pageParams = params.url();
  14528. pageParams.searchFilter = { // 筛选条件
  14529. keyword: $scope.keyword,
  14530. };
  14531. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14532. $scope.loading = false;
  14533. if (page) {
  14534. params.total(page.totalElement);
  14535. $defer.resolve(page.content);
  14536. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14537. }
  14538. }, function (response) {
  14539. $scope.loading = false;
  14540. toaster.pop('error', '数据加载失败', response.data);
  14541. });
  14542. }
  14543. });
  14544. // 同意申请
  14545. $scope.agree = function (id) {
  14546. AddPartner.agreeReq
  14547. uest({id: id}, {}, function (data) {
  14548. if (data.success) {
  14549. toaster.pop('success', '提示', '操作成功');
  14550. }
  14551. if (data.error) {
  14552. toaster.pop('error', '提示', '操作失败');
  14553. }
  14554. // $scope.tableParams.reload();
  14555. $window.location.reload();
  14556. }, function (response) {
  14557. toaster.pop('error', '提示', response.data);
  14558. });
  14559. };
  14560. // 拒绝申请
  14561. $scope.refuse = function (id, reason) {
  14562. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14563. if (data.success) {
  14564. toaster.pop('success', '提示', '操作成功');
  14565. }
  14566. if (data.error) {
  14567. toaster.pop('error', '提示', '操作失败');
  14568. }
  14569. // $scope.tableParams.reload();
  14570. $window.location.reload();
  14571. }, function (response) {
  14572. toaster.pop('error', '提示', response.data);
  14573. });
  14574. };
  14575. $scope.status = 'get';
  14576. }]);
  14577. /**
  14578. * 我的合作伙伴
  14579. */
  14580. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function ($scope, toaster, GetProductInfo, BaseService) {
  14581. BaseService.scrollBackToTop();
  14582. // 默认显示合作伙伴
  14583. $scope.status = 'news';
  14584. // 获取所有的合作伙伴
  14585. GetProductInfo.getAllPartners({}, function (data) {
  14586. $scope.partners = data;
  14587. }, function (res) {
  14588. toaster.pop('error', '获取列表失败', res.data);
  14589. });
  14590. // 添加为客户
  14591. $scope.addCust = function (partner) {
  14592. GetProductInfo.addCust({}, partner, function (data) {
  14593. toaster.pop('success', '提示', '添加客户成功');
  14594. $scope.tableParams.reload();
  14595. }, function (response) {
  14596. toaster.pop('error', '添加客户失败', response.data);
  14597. });
  14598. }
  14599. // 添加为供应商
  14600. $scope.addSupplier = function (partner) {
  14601. GetProductInfo.addSupplier({}, partner, function (data) {
  14602. toaster.pop('success', '提示', '添加供应商成功');
  14603. $scope.tableParams.reload();
  14604. }, function (response) {
  14605. toaster.pop('error', '添加供应商失败', response.data);
  14606. });
  14607. }
  14608. }]);
  14609. /**
  14610. * 财务对账时,企业进行筛选操作
  14611. */
  14612. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', 'VendorService', 'ngTableParams', 'BaseService', function ($scope, $modalInstance, suuorname, FaApCheck, VendorService, ngTableParams, BaseService) {
  14613. var getData = function () {
  14614. $scope.loading = true;
  14615. FaApCheck.getAllCustomers(function (data) {
  14616. $scope.custs = data;
  14617. $scope.loading = false;
  14618. });
  14619. };
  14620. getData();
  14621. $scope.customerParams = new ngTableParams({
  14622. page: 1,
  14623. count: 20
  14624. }, {
  14625. total: 0,
  14626. counts: [5, 10, 25, 50],
  14627. getData: function ($defer, params) {
  14628. $scope.loading = true;
  14629. var pageParams = params.url();
  14630. pageParams.keyword = $scope.keyword;
  14631. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  14632. $scope.loading = false;
  14633. if (page) {
  14634. params.total(page.totalElement);
  14635. $defer.resolve(page.content);
  14636. }
  14637. $scope.totalCount = page.totalElement;
  14638. }, function (response) {
  14639. $scope.loading = false;
  14640. toaster.pop('error', '数据加载失败', response.data);
  14641. });
  14642. }
  14643. });
  14644. // 搜索框回车
  14645. $scope.onSearch = function (keyword) {
  14646. $scope.customerParams.page(1);
  14647. $scope.customerParams.reload();
  14648. $scope.tip = keyword;
  14649. };
  14650. $scope.select = function (customer) {
  14651. if (customer.apcheck != 0) {
  14652. $modalInstance.close(customer);
  14653. }
  14654. }
  14655. $scope.close = function () {
  14656. $modalInstance.dismiss();
  14657. }
  14658. }]);
  14659. /**
  14660. * 跳转到企业圈
  14661. */
  14662. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function ($scope, GetProductInfo, toaster) {
  14663. GetProductInfo.businessGroups({}, function (data) {
  14664. window.open(data.url);
  14665. }, function (response) {
  14666. toaster.pop('error', '提示', response.data);
  14667. });
  14668. }]);
  14669. /**
  14670. * 购物车
  14671. */
  14672. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', 'cartList', 'PurchaseOrder', function ($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout, cartList, PurchaseOrder) {
  14673. BaseService.scrollBackToTop();
  14674. $scope.active = 'all';
  14675. $scope.agreedText = '全部';
  14676. $scope.dateZoneText = '一个月内';
  14677. $scope.condition = {dateZone: 1};
  14678. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14679. $scope.hasClick = false;
  14680. /* 时间筛选初始化*/
  14681. var fromDate = new Date();
  14682. var toDate = new Date();
  14683. fromDate.setMonth(fromDate.getMonth() - 1);
  14684. fromDate.setHours(0, 0, 0, 0);
  14685. toDate.setHours(23, 59, 59, 999);
  14686. $scope.condition.dateFrom = fromDate;
  14687. $scope.condition.dateTo = toDate;
  14688. $scope.changeDateZone = function (zone) {
  14689. $scope.condition.dateZone = zone;
  14690. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14691. $scope.condition.$dateZoneOpen = false;
  14692. getDateCondition(zone, $scope.condition);
  14693. $scope.tableParams.page(1);
  14694. $scope.tableParams.reload();
  14695. };
  14696. $scope.changeDeliveryZone = function (zone) {
  14697. $scope.condition.deliveryZoneText = zone;
  14698. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  14699. $scope.condition.$delievryZoneOpen = false;
  14700. getDelveryCondition(zone, $scope.condition);
  14701. $scope.tableParams.reload();
  14702. };
  14703. $scope.openDatePicker = function ($event, item, openParam) {
  14704. $event.preventDefault();
  14705. $event.stopPropagation();
  14706. item[openParam] = !item[openParam];
  14707. };
  14708. $scope.openFilterDatePicker = function ($event, item, openParam) {
  14709. $event.preventDefault();
  14710. $event.stopPropagation();
  14711. item[openParam] = !item[openParam];
  14712. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  14713. $scope.tableParams.reload();
  14714. }
  14715. };
  14716. $scope.parseDate = function (dateStr) {
  14717. if (dateStr)
  14718. return Date.parse(dateStr, 'yyyy-MM-dd');
  14719. return new Date();
  14720. };
  14721. $scope.setActive = function (state) {
  14722. if ($scope.active != state) {
  14723. $scope.active = state;
  14724. if ($scope.tableParams.page() == 1)
  14725. $scope.tableParams.reload();
  14726. else
  14727. $scope.tableParams.page(1);
  14728. }
  14729. };
  14730. $scope.searchMethod = false;
  14731. var getService = function () {
  14732. return $scope.searchMethod ? cartList : getCartList;
  14733. };
  14734. var getTodoCartCount = function () {
  14735. cartOperation.getTodoCartCount({}, function (data) {
  14736. $scope.countTodo = data.cartTodo;
  14737. });
  14738. };
  14739. getTodoCartCount();
  14740. $scope.tableParams = new ngTableParams({
  14741. page: 1,
  14742. count: 20,
  14743. sorting: {
  14744. date: 'desc'
  14745. }
  14746. }, {
  14747. total: 0,
  14748. counts: [5, 10, 25, 50],
  14749. getData: function ($defer, params) {
  14750. $scope.loading = true;
  14751. var pageParams = params.url();
  14752. pageParams.searchFilter = { // 筛选条件
  14753. keyword: $scope.keyword,
  14754. fromDate: getDateTime($scope.condition.dateFrom),
  14755. endDate: getDateTime($scope.condition.dateTo)
  14756. };
  14757. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14758. $scope.loading = false;
  14759. if (page) {
  14760. params.total(page.totalElement);
  14761. $defer.resolve(page.content);
  14762. }
  14763. }, function (response) {
  14764. $scope.loading = false;
  14765. toaster.pop('error', '数据加载失败', response.data);
  14766. });
  14767. }
  14768. });
  14769. $scope.getCartTotal = function (items) {
  14770. var sum = 0;
  14771. angular.forEach(items, function (item) {
  14772. sum += item.qty * item.price;
  14773. });
  14774. return sum;
  14775. };
  14776. // 搜索框回车
  14777. $scope.onSearch = function (keyword) {
  14778. // 每次搜索重置获取数据方法
  14779. $scope.searchMethod = false;
  14780. if(keyword != null && keyword != '') {
  14781. $scope.searchMethod = true;
  14782. }
  14783. $scope.tableParams.page(1);
  14784. $scope.tableParams.reload();
  14785. };
  14786. var changeClickStatus = function () {
  14787. $scope.hasClick = true;
  14788. $timeout(function () {
  14789. $scope.hasClick = false;
  14790. }, 500);
  14791. }
  14792. // 提交
  14793. $scope.addtoOrder = function (id) {
  14794. cartOperation.addToOrder({id: id}, {}, function (data) {
  14795. if (data.success) {
  14796. toaster.pop('success', '提示', data.success);
  14797. getTodoCartCount();
  14798. $timeout(function () {
  14799. window.location.hash = '#/purc/order/' + data.id;
  14800. window.location.reload();
  14801. }, 500);
  14802. }
  14803. if (data.error) {
  14804. toaster.pop('error', '提示', data.error);
  14805. }
  14806. }, function (response) {
  14807. toaster.pop('erroer', '提示', response.data);
  14808. });
  14809. };
  14810. // 删除一条主记录
  14811. $scope.deleteCart = function (id) {
  14812. changeClickStatus();
  14813. $scope.loading = true;
  14814. cartOperation.deleteCart({id: id}, {}, function (data) {
  14815. if (data.success) {
  14816. toaster.pop('success', '提示', data.success);
  14817. getTodoCartCount();
  14818. getTodoCartCount();
  14819. $timeout(function () {
  14820. $scope.tableParams.page(1);
  14821. $scope.tableParams.reload();
  14822. }, 500);
  14823. }
  14824. if (data.error) {
  14825. toaster.pop('error', '提示', data.error);
  14826. }
  14827. $scope.loading = false;
  14828. }, function (response) {
  14829. $scope.loading = false;
  14830. toaster.pop('erroer', '提示', response.data);
  14831. });
  14832. };
  14833. // 删除一条明细
  14834. $scope.deleteDetail = function (id) {
  14835. changeClickStatus();
  14836. $scope.loading = true;
  14837. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14838. if (data.success) {
  14839. toaster.pop('success', '提示', data.success);
  14840. $timeout(function () {
  14841. $scope.tableParams.reload();
  14842. }, 500);
  14843. }
  14844. if (data.error) {
  14845. toaster.pop('error', '提示', data.error);
  14846. }
  14847. $scope.loading = false;
  14848. }, function (response) {
  14849. toaster.pop('erroer', '提示', response.data);
  14850. $scope.loading = false;
  14851. });
  14852. };
  14853. // 清空购物车
  14854. $scope.clearCart = function () {
  14855. changeClickStatus();
  14856. $scope.loading = true;
  14857. cartOperation.deleteCarts({}, function (data) {
  14858. if (data.success) {
  14859. toaster.pop('success', '提示', data.success);
  14860. getTodoCartCount();
  14861. $timeout(function () {
  14862. $scope.tableParams.reload();
  14863. }, 500);
  14864. }
  14865. if (data.error) {
  14866. toaster.pop('error', '提示', data.error);
  14867. }
  14868. $scope.loading = false;
  14869. }, function (response) {
  14870. toaster.pop('erroer', '提示', response.data);
  14871. $scope.loading = false;
  14872. });
  14873. }
  14874. // 复制订单
  14875. $scope.copyorder = function (id) {
  14876. changeClickStatus();
  14877. $scope.loading = true;
  14878. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  14879. if (data.id) {
  14880. toaster.pop('success', '提示', '单据复制成功');
  14881. getTodoCartCount();
  14882. $scope.loading = false;
  14883. window.location.hash = "#purc/cart/" + data.id;
  14884. }
  14885. }, function (response) {
  14886. toaster.pop('error', '提示', response.data);
  14887. $scope.loading = false;
  14888. });
  14889. }
  14890. }]);
  14891. /**
  14892. * 购物车详情
  14893. */
  14894. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', 'recentPrice',
  14895. function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token, recentPrice) {
  14896. BaseService.scrollBackToTop();
  14897. $scope.loading = true;
  14898. var loadData = function () {
  14899. cartOperation.getCartDetail({id: $stateParams.id}, function (data) {
  14900. if (data.code) {
  14901. $scope.order = data;
  14902. var sum = 0;
  14903. angular.forEach($scope.order.orderItems, function (item) {
  14904. sum += item.qty * item.price;
  14905. });
  14906. $scope.order.total = sum;
  14907. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  14908. $scope.contacts = data;
  14909. $scope.order.vendor = $scope.order.venduser;
  14910. });
  14911. $scope.loading = false;
  14912. } else {
  14913. window.location.hash = '#/purc/cart';
  14914. }
  14915. });
  14916. };
  14917. loadData();
  14918. var getToken = function() {
  14919. token.info({userType: 'cart'}, {}, function(data) {
  14920. $scope.token = data.token;
  14921. }, function(response) {
  14922. toaster.pop('error', '提示', response.data);
  14923. });
  14924. }
  14925. getToken();
  14926. // 获取地址信息
  14927. $http.get('resources/citydata/city.json', {
  14928. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  14929. }).then(function (response) {
  14930. $scope.provinces = response.data;
  14931. });
  14932. // 获取收货地址列表
  14933. ShipAddress.shipAddList({}, function (data) {
  14934. $scope.ships = data;
  14935. $scope.order.shipadd = $scope.ships[0];
  14936. });
  14937. //增加商品
  14938. $scope.addProduct = function (index) {
  14939. if ($scope.order.orderItems[index].code == null) {
  14940. toaster.pop('info', '提示', '请先选择商品');
  14941. } else {
  14942. $scope.order.orderItems.push({
  14943. code: null,
  14944. title: null,
  14945. spec: null,
  14946. unit: null,
  14947. qty: null,
  14948. price: null,
  14949. remark: null,
  14950. delivery: null,
  14951. $endDateOpen: false,
  14952. taxrate: $scope.order.rate
  14953. });
  14954. }
  14955. };
  14956. //删除商品
  14957. $scope.deleteProduct = function (index, id) {
  14958. $scope.order.orderItems.splice(index, 1);
  14959. if (id != null) {
  14960. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14961. if (data.success) {
  14962. loadData();
  14963. }
  14964. if (data.error) {
  14965. toaster.pop('error', '提示', data.error);
  14966. }
  14967. }, function (response) {
  14968. toaster.pop('erroer', '提示', response.data);
  14969. });
  14970. }
  14971. };
  14972. // 搜索框回车
  14973. $scope.onSearch = function (keyword) {
  14974. $scope.keyword = keyword;
  14975. $scope.tableParams.page(1);
  14976. $scope.tableParams.reload();
  14977. };
  14978. $scope.tableParams = new ngTableParams({
  14979. page: 1,
  14980. count: 20
  14981. }, {
  14982. total: 0,
  14983. counts: [5, 10, 25, 50],
  14984. getData: function ($defer, params) {
  14985. $scope.loading = true;
  14986. var pageParams = params.url();
  14987. pageParams.keyword = $scope.keyword;
  14988. $scope.tip = $scope.keyword;
  14989. pageParams.vendUU = $scope.order.receiveCode;
  14990. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  14991. $scope.loading = false;
  14992. if (page) {
  14993. params.total(page.totalElement);
  14994. $scope.total = page.totalElement;
  14995. $defer.resolve(page.content);
  14996. }
  14997. }, function (response) {
  14998. $scope.loading = false;
  14999. toaster.pop('error', '数据加载失败', response.data);
  15000. });
  15001. }
  15002. });
  15003. // 选择
  15004. $scope.check = function (data) {
  15005. var price = null;
  15006. var qty = null;
  15007. var taxRate = null;
  15008. if (data.id) {
  15009. recentPrice.agreed({prId: data.id}, {}, function(response) {
  15010. price = response.price;
  15011. qty = response.qty;
  15012. taxRate = response.taxRate;
  15013. $scope.order.orderItems.push({
  15014. code: data.code,
  15015. title: data.title,
  15016. spec: data.spec,
  15017. unit: data.unit,
  15018. qty: qty,
  15019. price: price,
  15020. remark: null,
  15021. delivery: null,
  15022. prid: data.id,
  15023. taxrate: taxRate,
  15024. prodsource: 'seller',
  15025. });
  15026. });
  15027. }
  15028. };
  15029. // 导入商品信息
  15030. $scope.uplodaByBatch = function () {
  15031. var modalInstance = $modal.open({
  15032. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  15033. controller: 'PurcUploadByBatchCtrl',
  15034. size: 'lg',
  15035. resolve: {}
  15036. });
  15037. modalInstance.result.then(function (data) {
  15038. angular.forEach(data, function (prod) {
  15039. $scope.order.orderItems.push({
  15040. code: prod.code,
  15041. title: data.title,
  15042. unit: 'PCS',
  15043. spec: prod.spec,
  15044. qty: prod.amount,
  15045. price: prod.price,
  15046. remark: prod.remark,
  15047. delivery: prod.date,
  15048. prid: prod.id,
  15049. taxrate: prod.rate
  15050. });
  15051. })
  15052. }, function () {
  15053. });
  15054. }
  15055. // 删除一条主记录
  15056. $scope.deleteCart = function (id) {
  15057. cartOperation.deleteCart({id: id}, {}, function (data) {
  15058. if (data.success) {
  15059. toaster.pop('success', '提示', data.success);
  15060. $timeout(function () {
  15061. window.location.reload();
  15062. }, 500);
  15063. }
  15064. if (data.error) {
  15065. toaster.pop('error', '提示', data.error);
  15066. }
  15067. }, function (response) {
  15068. toaster.pop('erroer', '提示', response.data);
  15069. });
  15070. };
  15071. $scope.getMinDate = function (item) {
  15072. return $filter('date')(new Date, 'yyyy-MM-dd');
  15073. };
  15074. $scope.openDatePicker = function ($event, openParam, index) {
  15075. $event.preventDefault();
  15076. $event.stopPropagation();
  15077. $scope.order.orderItems[index].$endDateOpen = !openParam;
  15078. };
  15079. // 添加到购物车
  15080. $scope.addToCart = function (order) {
  15081. $scope.loading = true;
  15082. if (order.vendor.tel != null) {
  15083. $scope.order.vendusertel = order.vendor.tel;
  15084. }
  15085. if (order.vendor.venduser != null && order.vendor.tel != null) {
  15086. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  15087. }
  15088. if (order.shipadd != null) {
  15089. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  15090. }
  15091. if ($scope.order.date instanceof Date) {
  15092. $scope.order.date = $scope.order.date.getTime();
  15093. }
  15094. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  15095. if ($scope.order.orderItems[i].delivery instanceof Date) {
  15096. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  15097. }
  15098. if ($scope.order.currency != 'RMB') {
  15099. $scope.order.orderItems[i].rate = 0;
  15100. }
  15101. }
  15102. $scope.order.status = 311;
  15103. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  15104. $scope.loading = false;
  15105. toaster.pop('success', '成功', '保存成功');
  15106. loadData();
  15107. }, function (response) {
  15108. $scope.loading = false;
  15109. toaster.pop('error', '保存失败', response.data);
  15110. });
  15111. };
  15112. // 立即购买
  15113. $scope.addToOrder = function (order) {
  15114. $scope.loading = true;
  15115. if (order.vendor.tel != null) {
  15116. $scope.order.vendusertel = order.vendor.tel;
  15117. }
  15118. if (order.vendor.venduser != null && order.vendor.tel != null) {
  15119. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  15120. }
  15121. if (order.shipadd != null) {
  15122. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  15123. }
  15124. if ($scope.order.date instanceof Date) {
  15125. $scope.order.date = $scope.order.date.getTime();
  15126. }
  15127. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  15128. if ($scope.order.orderItems[i].delivery instanceof Date) {
  15129. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  15130. }
  15131. if ($scope.order.currency != 'RMB') {
  15132. $scope.order.orderItems[i].rate = 0;
  15133. }
  15134. }
  15135. $scope.order.status = 200;
  15136. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  15137. $scope.loading = false;
  15138. toaster.pop('success', '成功', '保存成功');
  15139. window.location.hash = '#/purc/order/' + data.id;
  15140. }, function (response) {
  15141. $scope.loading = false;
  15142. toaster.pop('error', '保存失败', response.data);
  15143. });
  15144. };
  15145. // 新增收货地址保存
  15146. $scope.saveShipAddress = function (ship) {
  15147. ship.address = ship.province + ship.city + ship.district;
  15148. ShipAddress.saveAddress({}, ship, function (data) {
  15149. if (data.success) {
  15150. ShipAddress.shipAddList({}, function (data) {
  15151. $scope.ships = data;
  15152. $scope.order.shipadd = $scope.ships[0];
  15153. });
  15154. toaster.pop('success', '提示', data.success);
  15155. }
  15156. if (data.error) {
  15157. toaster.pop('error', '提示', data.error);
  15158. }
  15159. });
  15160. }
  15161. // 新增供应商联系人
  15162. $scope.addContact = function (uu) {
  15163. var modalInstance = $modal.open({
  15164. animation: true,
  15165. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  15166. controller: 'AddContacCtrl',
  15167. resolve: {}
  15168. });
  15169. modalInstance.result.then(function (data) {
  15170. $scope.contact = data;
  15171. $scope.contact.venduu = $scope.order.receiveCode;
  15172. Vendor.saveContact({}, $scope.contact, function (data) {
  15173. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  15174. $scope.contacts = data;
  15175. });
  15176. toaster.pop('success', '提示', '联系人保存成功');
  15177. }, function (response) {
  15178. toaster.pop('error', '失败', response.data);
  15179. });
  15180. });
  15181. }
  15182. }]);
  15183. /**
  15184. * 审批流
  15185. */
  15186. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function ($scope, toaster, $modal, appFlow, BaseService) {
  15187. BaseService.scrollBackToTop();
  15188. $scope.vacation = false;
  15189. $scope.workovertime = false;
  15190. $scope.workdaily = false;
  15191. $scope.feeplease = false;
  15192. $scope.signapp = false;
  15193. appFlow.viewAppFlow({}, function (data) {// 获取已设置的列表
  15194. $scope.nodes = data;
  15195. angular.forEach($scope.nodes, function (node) {
  15196. if (node.appname = '请假单') {
  15197. $scope.vacation = true;
  15198. }
  15199. if (node.appname = '加班单') {
  15200. $scope.workovertime = true;
  15201. }
  15202. if (node.appname = '工作日报') {
  15203. $scope.workdaily = true;
  15204. }
  15205. if (node.appname = '出差单') {
  15206. $scope.feeplease = true;
  15207. }
  15208. if (node.appname = '申诉单') {
  15209. $scope.signapp = true;
  15210. }
  15211. });
  15212. }, function (response) {
  15213. });
  15214. $scope.NoteSet = function () {
  15215. var modalInstance = $modal.open({
  15216. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15217. controller: 'NoteStep1Ctrl',
  15218. size: 'lg',
  15219. resolve: {
  15220. AppName: function () {
  15221. return '请假单';
  15222. }
  15223. }
  15224. });
  15225. modalInstance.result.then(function (data) {
  15226. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15227. if (data.error) {
  15228. toaster.pop('error', '提示', data.error);
  15229. }
  15230. if (data.success) {
  15231. toaster.pop('success', '提示', data.success);
  15232. }
  15233. }, function (response) {
  15234. });
  15235. }, function () {
  15236. });
  15237. }
  15238. $scope.overTimeSet = function () {
  15239. var modalInstance = $modal.open({
  15240. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15241. controller: 'NoteStep1Ctrl',
  15242. size: 'lg',
  15243. resolve: {
  15244. AppName: function () {
  15245. return '加班单';
  15246. }
  15247. }
  15248. });
  15249. modalInstance.result.then(function (data) {
  15250. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15251. if (data.error) {
  15252. toaster.pop('error', '提示', data.error);
  15253. }
  15254. if (data.success) {
  15255. toaster.pop('success', '提示', data.success);
  15256. }
  15257. }, function (response) {
  15258. });
  15259. }, function () {
  15260. });
  15261. }
  15262. $scope.feePleaseSet = function () {
  15263. var modalInstance = $modal.open({
  15264. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15265. controller: 'NoteStep1Ctrl',
  15266. size: 'lg',
  15267. resolve: {
  15268. AppName: function () {
  15269. return '出差单';
  15270. }
  15271. }
  15272. });
  15273. modalInstance.result.then(function (data) {
  15274. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15275. if (data.error) {
  15276. toaster.pop('error', '提示', data.error);
  15277. }
  15278. if (data.success) {
  15279. toaster.pop('success', '提示', data.success);
  15280. }
  15281. }, function (response) {
  15282. });
  15283. }, function () {
  15284. });
  15285. }
  15286. $scope.workDailySet = function () {
  15287. var modalInstance = $modal.open({
  15288. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15289. controller: 'NoteStep1Ctrl',
  15290. size: 'lg',
  15291. resolve: {
  15292. AppName: function () {
  15293. return '工作日报';
  15294. }
  15295. }
  15296. });
  15297. modalInstance.result.then(function (data) {
  15298. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15299. if (data.error) {
  15300. toaster.pop('error', '提示', data.error);
  15301. }
  15302. if (data.success) {
  15303. toaster.pop('success', '提示', data.success);
  15304. }
  15305. }, function (response) {
  15306. });
  15307. }, function () {
  15308. });
  15309. }
  15310. $scope.signAppSet = function () {
  15311. var modalInstance = $modal.open({
  15312. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15313. controller: 'NoteStep1Ctrl',
  15314. size: 'lg',
  15315. resolve: {
  15316. AppName: function () {
  15317. return '申诉单';
  15318. }
  15319. }
  15320. });
  15321. modalInstance.result.then(function (data) {
  15322. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15323. if (data.error) {
  15324. toaster.pop('error', '提示', data.error);
  15325. }
  15326. if (data.success) {
  15327. toaster.pop('success', '提示', data.success);
  15328. }
  15329. }, function (response) {
  15330. });
  15331. }, function () {
  15332. });
  15333. }
  15334. }]);
  15335. /**
  15336. * 审核条件设置
  15337. */
  15338. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function ($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  15339. $scope.appName = AppName;// 标题名称
  15340. $scope.AppFlow = {
  15341. appName: $scope.appName,
  15342. appNodes: {}
  15343. };
  15344. $scope.AppFlow.appNodes = [];
  15345. appFlow.getNodeByName({name: AppName}, {}, function (data) {// 通过单据名称查询单个审批流
  15346. if (data.appNodes.length != 0) {
  15347. $scope.node = data;
  15348. $scope.AppFlow = data;
  15349. }
  15350. }, function () {
  15351. });
  15352. $scope.copy = function () {//复制
  15353. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  15354. toaster.pop('info', '提示', '复制成功');
  15355. $modalInstance.dismiss();
  15356. }
  15357. $scope.paste = function () {
  15358. $scope.AppFlow = {appName: $scope.appName, appNodes: {}};
  15359. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  15360. }
  15361. $scope.clear = function () {// 清空
  15362. $scope.AppFlow = {
  15363. appName: $scope.appName,
  15364. appNodes: {}
  15365. };
  15366. $scope.AppFlow.appNodes = [];
  15367. }
  15368. appFlow.getPositions({}, function (data) {// 获取人员信息
  15369. $scope.users = data;
  15370. }, function (response) {
  15371. });
  15372. appFlow.getPositionInfo({}, function (data) { // 获取职位信息
  15373. $scope.roles = data;
  15374. }, function (response) {
  15375. });
  15376. $scope.SelectUser = function (data) { // 添加人员
  15377. var item = {
  15378. useruu: null,
  15379. username: null,
  15380. level: null
  15381. };
  15382. item.useruu = data.useruu;
  15383. item.username = data.username;
  15384. $scope.AppFlow.appNodes.push(item);
  15385. }
  15386. $scope.SelectRole = function (data) {// 添加职位
  15387. var item = {
  15388. position: null,
  15389. level: null
  15390. };
  15391. item.position = data;
  15392. $scope.AppFlow.appNodes.push(item);
  15393. }
  15394. $scope.deleteNode = function (index) {// 删除节点
  15395. $scope.AppFlow.appNodes.splice(index, 1);
  15396. };
  15397. $scope.saveNode = function () { // 保存
  15398. angular.forEach($scope.AppFlow.appNodes, function (value, key) {
  15399. $scope.AppFlow.appNodes[key].level = key;
  15400. });
  15401. if ($scope.AppFlow.appNodes.length == 0) {
  15402. toaster.pop('info', '提示', '您还未设置审批人');
  15403. } else {
  15404. $modalInstance.close($scope.AppFlow);
  15405. }
  15406. ;
  15407. };
  15408. $scope.cancel = function () {// 取消
  15409. $modalInstance.dismiss();
  15410. }
  15411. }]);
  15412. /***
  15413. * 代采定单
  15414. */
  15415. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', 'getOrderInfo', '$modal', 'CurrentRole', function ($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService, getOrderInfo, $modal, CurrentRole) {
  15416. BaseService.scrollBackToTop();
  15417. // 获取当前用户是否为普通用户
  15418. CurrentRole.isUser({}, {}, function (data) {
  15419. $scope.isUser = data.isUser;
  15420. });
  15421. $scope.active = 'all';
  15422. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15423. $scope.total = null;
  15424. $scope.setActive = function (state) {
  15425. if ($scope.active != state) {
  15426. $scope.active = state;
  15427. if ($scope.tableParams.page() == 1)
  15428. $scope.tableParams.reload();
  15429. else
  15430. $scope.tableParams.page(1);
  15431. }
  15432. };
  15433. $scope.agreedText = '全部';
  15434. $scope.dateZoneText = '不限';
  15435. $scope.condition = {dateZone: 1};
  15436. /* 时间筛选初始化*/
  15437. var fromDate = new Date();
  15438. var toDate = new Date();
  15439. fromDate.setMonth(fromDate.getMonth() - 1);
  15440. fromDate.setHours(0, 0, 0, 0);
  15441. toDate.setHours(23, 59, 59, 999);
  15442. $scope.condition.dateFrom = fromDate;
  15443. $scope.condition.dateTo = toDate;
  15444. $scope.changeDateZone = function (zone) {
  15445. $scope.condition.dateZone = zone;
  15446. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  15447. $scope.condition.$dateZoneOpen = false;
  15448. getDateCondition(zone, $scope.condition);
  15449. $scope.tableParams.page(1);
  15450. $scope.tableParams.reload();
  15451. };
  15452. $scope.openDatePicker = function ($event, item, openParam) {
  15453. $event.preventDefault();
  15454. $event.stopPropagation();
  15455. item[openParam] = !item[openParam];
  15456. };
  15457. $scope.openFilterDatePicker = function ($event, item, openParam) {
  15458. $event.preventDefault();
  15459. $event.stopPropagation();
  15460. item[openParam] = !item[openParam];
  15461. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  15462. $scope.tableParams.reload();
  15463. }
  15464. };
  15465. $scope.searchMethod = false;
  15466. var getSerivce = function() {
  15467. return $scope.searchMethod ? getDeOrder : getOrderInfo;
  15468. }
  15469. getSerivce();
  15470. // 获取订单总金额
  15471. var getOrdersAmount = function() {
  15472. DeputyOrder.odersAmount({}, function(data) {
  15473. $scope.odersAmount = data.amount;
  15474. });
  15475. }
  15476. getOrdersAmount();
  15477. $scope.tableParams = new ngTableParams({
  15478. page: 1,
  15479. count: 20,
  15480. sorting: {'date': 'desc', 'id': 'desc'}
  15481. }, {
  15482. total: 0,
  15483. counts: [5, 10, 25, 50],
  15484. getData: function ($defer, params) {
  15485. $scope.loading = true;
  15486. var pageParams = params.url();
  15487. pageParams.searchFilter = {
  15488. keyword: $scope.keyword,
  15489. fromDate: getDateTime($scope.condition.dateFrom),
  15490. endDate: getDateTime($scope.condition.dateTo)
  15491. };
  15492. getSerivce()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  15493. $scope.loading = false;
  15494. if (page) {
  15495. params.total(page.totalElement);
  15496. $scope.total = page.totalElement;
  15497. $defer.resolve(page.content);
  15498. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  15499. }
  15500. }, function (response) {
  15501. $scope.loading = false;
  15502. toaster.pop('error', '数据加载失败', response.data);
  15503. });
  15504. }
  15505. });
  15506. //打印
  15507. $scope.print = function (deputyOrder) {
  15508. DeputyOrder.printCount({id: deputyOrder.id}, {});//增加打印此次
  15509. $scope.tableParams.reload();
  15510. ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  15511. ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  15512. ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  15513. ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  15514. };
  15515. // 搜索框回车
  15516. $scope.onSearch = function (keyword) {
  15517. // 每次搜索重置获取数据方法
  15518. $scope.searchMethod = false;
  15519. if(keyword != null && keyword != '') {
  15520. $scope.searchMethod = true;
  15521. }
  15522. $scope.tableParams.page(1);
  15523. $scope.tableParams.reload();
  15524. };
  15525. // 复制采购单
  15526. $scope.copyorder = function (id) {
  15527. $scope.loading = true;
  15528. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  15529. $scope.loading = false;
  15530. if (data.id) {
  15531. toaster.pop('success', '提示', '复制生成单据成功');
  15532. window.location.hash = "#/purc/deputy/" + data.id;
  15533. }
  15534. if (data.error) {
  15535. toaster.pop('error', '提示', '保存失败');
  15536. }
  15537. }, function (response) {
  15538. $scope.loading = false;
  15539. toaster.pop('error', '提示', response.data);
  15540. });
  15541. }
  15542. // 删除代采订单
  15543. $scope.clear = function (id) {
  15544. $scope.loading = true;
  15545. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  15546. if (data.success) {
  15547. toaster.pop('success', '提示', data.success);
  15548. $scope.tableParams.reload();
  15549. }
  15550. $scope.loading = false;
  15551. }, function (response) {
  15552. $scope.loading = false;
  15553. toaster.pop('error', '提示', response.data);
  15554. });
  15555. }
  15556. $scope.viewApprove = function(salecode, uu) {
  15557. var modalInstance = $modal.open({
  15558. templateUrl: 'static/tpl/index/purc/modal/approval_detail.html',
  15559. controller: 'ViewApprovalDetailCtrl',
  15560. resolve: {
  15561. uu: function () {
  15562. return uu
  15563. },
  15564. salecode: function () {
  15565. return salecode
  15566. }
  15567. }
  15568. });
  15569. }
  15570. }]);
  15571. // 查询代采定单在信扬中的审批情况
  15572. app.controller('ViewApprovalDetailCtrl', ['$scope', 'toaster', '$modalInstance', 'DeputyOrder', 'BaseService', 'ngTableParams', 'uu', 'salecode', function ($scope, toaster, $modalInstance, DeputyOrder, BaseService, ngTableParams, uu, salecode) {
  15573. DeputyOrder.approve({uu: uu, code: salecode}, {}, function (data) {
  15574. $scope.nodes = data.nodes;
  15575. $scope.process = data.process;
  15576. if(data.error) {
  15577. toaster.pop('error', '提示', data.error);
  15578. }
  15579. }, function (response) {
  15580. toaster.pop('error', '提示', '暂未获取到相关单据的信息');
  15581. });
  15582. $scope.cancel = function () {
  15583. $modalInstance.dismiss();
  15584. };
  15585. $scope.select = function (company) { // 直接选择
  15586. $modalInstance.close(company);
  15587. }
  15588. }]);
  15589. /**
  15590. * 新增代采订单
  15591. */
  15592. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', 'DecimalNumber', 'DekeyValue', function ($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService, DecimalNumber, DekeyValue) {
  15593. BaseService.scrollBackToTop();
  15594. //默认采购单号不重复
  15595. $scope.orderCodeEnable = true;
  15596. $scope.deOrder = {
  15597. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  15598. entrydate: new Date(),
  15599. status: '在录入',
  15600. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  15601. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  15602. riskmethod: '甲方承担',
  15603. taxpaymentmethod: '甲方承担',
  15604. totalamount: 0,
  15605. totalpayament: 0,
  15606. orderamount: 0,
  15607. usdpayment: 0
  15608. };
  15609. $scope.deOrder.deputyOrderItems = [];
  15610. var item = {
  15611. prodname: null,
  15612. prodcode: null,
  15613. prodspec: null,
  15614. amount: null,
  15615. unitprice: null,
  15616. purcprice: null,
  15617. remark: null,
  15618. orderprice: null,
  15619. };
  15620. $scope.deOrder.deputyOrderItems.push(item);
  15621. // 代采企业列表
  15622. DeputyOrder.deputyEnterprise({}, function (data) {
  15623. $scope.deputyEnterprises = data;
  15624. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15625. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15626. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  15627. });
  15628. var getPayMethod = function(enuu, key) {
  15629. // 获取我方付款支付方式默认值
  15630. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  15631. $scope.methods = data.content;
  15632. });
  15633. }
  15634. // 更新名称时后台更改uu号
  15635. $scope.change = function (deputyname) {
  15636. DeputyOrder.deputyEnterprise({}, function (data) {
  15637. $scope.deputyEn = data;
  15638. angular.forEach($scope.deputyEn, function (en) {
  15639. if (deputyname == en.deputyenname) {
  15640. $scope.deputyuu = en.deputyenuu;
  15641. getPayMethod($scope.deputyuu, 'paymentmethod');
  15642. }
  15643. });
  15644. });
  15645. }
  15646. // 查找付款企业
  15647. $scope.dbfindPayCompany = function (deputyuu) {
  15648. var modalInstance = $modal.open({
  15649. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15650. controller: 'DbfindDeputyPayCompanyCtrl',
  15651. resolve: {
  15652. deputyuu: function () {
  15653. return deputyuu
  15654. }
  15655. }
  15656. });
  15657. modalInstance.result.then(function (data) {
  15658. $scope.deOrder.paycomname = data.enname;
  15659. $scope.deOrder.paycomaddress = data.address;
  15660. })
  15661. }
  15662. // 查询上次的关键词记录
  15663. $scope.getHisKeyword = function (tervendor) {
  15664. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function (data) {
  15665. $scope.deOrder.vendtel = data.vendtel;
  15666. $scope.deOrder.venduser = data.venduser;
  15667. $scope.deOrder.otherdata = data.otherdata;
  15668. $scope.deOrder.companyname = data.companyname;
  15669. $scope.deOrder.bankaccount = data.bankaccount;
  15670. $scope.deOrder.bankaddress = data.bankaddress;
  15671. $scope.deOrder.bankcode = data.bankcode;
  15672. $scope.deOrder.bankname = data.bankname;
  15673. $scope.deOrder.legalrepresent = data.legalrepresent;
  15674. $scope.deOrder.tervendaddress = data.tervendaddress;
  15675. $scope.deOrder.enfax = data.enfax;
  15676. $scope.deOrder.deliverymethod = data.deliverymethod;
  15677. }, function (response) {
  15678. toaster.pop('error', '提示', response.data);
  15679. });
  15680. }
  15681. // 查询历史供应商
  15682. DeputyOrder.hisvendors({}, function (data) {
  15683. $scope.hisvendors = data;
  15684. }, function (response) {
  15685. toaster.pop('error', '提示', response.data);
  15686. });
  15687. // 上次填写记录(不关联供应商)
  15688. DeputyOrder.lastKeywords({}, function (data) {
  15689. $scope.lastkeyowrds = data;
  15690. $scope.deOrder.madealdate = $scope.lastkeyowrds.madealdate;
  15691. $scope.deOrder.madealcode = $scope.lastkeyowrds.madealcode;
  15692. }, function (response) {
  15693. toaster.pop('error', '提示', response.data);
  15694. });
  15695. //增加商品
  15696. $scope.add = function (index) {
  15697. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15698. toaster.pop('info', '提示', '请先填写商品信息');
  15699. } else {
  15700. $scope.deOrder.deputyOrderItems.push(
  15701. {
  15702. prodname: null,
  15703. prodcode: null,
  15704. prodspec: null,
  15705. prodbrand: null,
  15706. amount: null,
  15707. unitprice: null,
  15708. purcprice: null,
  15709. remark: null,
  15710. orderprice: null
  15711. });
  15712. }
  15713. };
  15714. //删除商品
  15715. $scope.del = function (index) {
  15716. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15717. };
  15718. // 导入商品信息
  15719. $scope.uplodaByBatch = function () {
  15720. var modalInstance = $modal.open({
  15721. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15722. controller: 'DeputyOrderUploadCtrl',
  15723. size: 'lg',
  15724. resolve: {}
  15725. });
  15726. modalInstance.result.then(function (data) {
  15727. angular.forEach(data, function (data) {
  15728. $scope.deOrder.deputyOrderItems.push(data);
  15729. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15730. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15731. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15732. }
  15733. }
  15734. })
  15735. $scope.deOrder.totalamount = 0;
  15736. $scope.deOrder.usdpayment = 0;
  15737. $scope.deOrder.orderamount = 0;
  15738. $scope.deOrder.totalpayament = 0;
  15739. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15740. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15741. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15742. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15743. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15744. });
  15745. }, function () {
  15746. });
  15747. }
  15748. // 查找供应商
  15749. $scope.dbfindVendor = function (deputyuu) {
  15750. var modalInstance = $modal.open({
  15751. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  15752. controller: 'DbfindDeputyVendorInfoCtrl',
  15753. size: 'lg',
  15754. resolve: {
  15755. deputyuu: function () {
  15756. return deputyuu
  15757. }
  15758. }
  15759. });
  15760. modalInstance.result.then(function (data) {
  15761. $scope.deOrder.customer = data.vendorEnterprise.enName;
  15762. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  15763. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  15764. $scope.deOrder.usertel = data.vendorUser.userTel;
  15765. })
  15766. }
  15767. // 检验订单编号是否存在
  15768. $scope.checkOrder = function (salecode, deputyuu) {
  15769. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  15770. $scope.orderCodeEnable = true;
  15771. if (data.info) {
  15772. toaster.pop('error', '提示', data.info);
  15773. $scope.orderCodeEnable = false;
  15774. }
  15775. }, function (response) {
  15776. toaster.pop('error', '提示', response.data);
  15777. })
  15778. }
  15779. //计算采购单价
  15780. $scope.checkPrice = function (rate) {
  15781. $scope.deOrder.totalamount = 0;
  15782. $scope.deOrder.usdpayment = 0;
  15783. $scope.deOrder.orderamount = 0;
  15784. $scope.deOrder.totalpayament = 0;
  15785. if (rate == null) {
  15786. toaster.pop('info', '提示', '请先填入税率');
  15787. } else {
  15788. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15789. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  15790. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15791. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15792. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15793. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15794. });
  15795. }
  15796. }
  15797. // 获取订单总价
  15798. $scope.totalPrice = function () {
  15799. $scope.deOrder.totalamount = 0;
  15800. $scope.deOrder.usdpayment = 0;
  15801. $scope.deOrder.orderamount = 0;
  15802. $scope.deOrder.totalpayament = 0;
  15803. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15804. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  15805. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15806. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15807. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15808. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15809. }
  15810. });
  15811. }
  15812. $scope.checkresult = false;
  15813. var checkKeyword = function () {
  15814. if ($scope.deOrder.madealdate == null) {
  15815. toaster.pop('info', '提示', '主协议签订日期未选择');
  15816. } else if ($scope.deOrder.madealcode == null) {
  15817. toaster.pop('info', '提示', '主协议签订编号未填写');
  15818. } else if ($scope.deOrder.tervendor == null) {
  15819. toaster.pop('info', '提示', '终端供应商名称未填写');
  15820. } else if ($scope.deOrder.vendtel == null) {
  15821. toaster.pop('info', '提示', '电话号码未填写');
  15822. } else if ($scope.deOrder.venduser == null) {
  15823. toaster.pop('info', '提示', '联系人未填写');
  15824. } else if ($scope.deOrder.shipdate == null) {
  15825. toaster.pop('info', '提示', '供应商发货时间未选择');
  15826. } else if ($scope.deOrder.goodspacking == null) {
  15827. toaster.pop('info', '提示', '货物包装要求未填写');
  15828. } else if ($scope.deOrder.deliverymethod == null) {
  15829. toaster.pop('info', '提示', '供应商交货方式未填写');
  15830. } else if ($scope.deOrder.pickupmethod == null) {
  15831. toaster.pop('info', '提示', '我方提货方式未填写');
  15832. } else if ($scope.deOrder.paymentmethod == null) {
  15833. toaster.pop('info', '提示', '我方付款方式未填写');
  15834. } else if ($scope.deOrder.pickupdate == null) {
  15835. toaster.pop('info', '提示', '我方提货时间未选择');
  15836. } else if ($scope.deOrder.currency == null) {
  15837. toaster.pop('info', '提示', '交易币别未选择');
  15838. } else if ($scope.deOrder.deputyuu == null) {
  15839. toaster.pop('info', '提示', '代采企业未选择');
  15840. } else if ($scope.deOrder.salecode == null) {
  15841. toaster.pop('info', '提示', '订单编号未填写');
  15842. } else if ($scope.deOrder.paydeldate == null) {
  15843. toaster.pop('info', '提示', '我方付款提货时间未选择');
  15844. } else if ($scope.deOrder.riskmethod == null) {
  15845. toaster.pop('info', '提示', '风险承担方式未填写');
  15846. } else if ($scope.deOrder.taxpaymentmethod == null) {
  15847. toaster.pop('info', '提示', '运、税费承担方式');
  15848. } else if ($scope.deOrder.tervendaddress == null) {
  15849. toaster.pop('info', '提示', '终端供应商地址未填写');
  15850. } else if ($scope.deOrder.companyname == null) {
  15851. toaster.pop('info', '提示', '公司全称(英文)未填写');
  15852. } else if ($scope.deOrder.requirepaydate == null) {
  15853. toaster.pop('info', '提示', '要求付汇日期未选择');
  15854. } else if ($scope.deOrder.bankname == null) {
  15855. toaster.pop('info', '提示', '银行名称(英文)未填写');
  15856. } else if ($scope.deOrder.bankaccount == null) {
  15857. toaster.pop('info', '提示', '银行账号未填写');
  15858. } else if ($scope.deOrder.bankaddress == null) {
  15859. toaster.pop('info', '提示', '银行地址未填写');
  15860. } else if ($scope.deOrder.bankcode == null) {
  15861. toaster.pop('info', '提示', '银行代码未填写');
  15862. } else if ($scope.deOrder.salepocode == null) {
  15863. toaster.pop('info', '提示', '合同编号未填写');
  15864. } else if ($scope.deOrder.legalrepresent == null) {
  15865. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  15866. } else if ($scope.deOrder.paycomname == null) {
  15867. toaster.pop('info', '提示', '付款公司未填写');
  15868. } else if ($scope.deOrder.paycomaddress == null) {
  15869. toaster.pop('info', '提示', '付款公司地址未填写');
  15870. } else if ($scope.deOrder.enfax == null) {
  15871. toaster.pop('info', '提示', '供应商方法人电话未填写');
  15872. } else if ($scope.deOrder.paydate == null) {
  15873. toaster.pop('info', '提示', '货款支付时间未选择');
  15874. } else if ($scope.deOrder.paymethod == null) {
  15875. toaster.pop('info', '提示', '货款支付方式未填写');
  15876. } else if ($scope.deOrder.deliverydate == null) {
  15877. toaster.pop('info', '提示', '交货时间未选择');
  15878. } else if (!$scope.orderCodeEnable) {
  15879. toaster.pop('info', '提示', '采购单号重复');
  15880. } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
  15881. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
  15882. } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
  15883. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
  15884. } else {
  15885. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  15886. if (orderitem.prodname == null) {
  15887. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  15888. } else if (orderitem.prodcode == null) {
  15889. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  15890. } else if (orderitem.prodspec == null) {
  15891. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  15892. } else if (orderitem.prodbrand == null) {
  15893. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  15894. } else if (orderitem.amount == null) {
  15895. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  15896. } else if (orderitem.unitprice == null) {
  15897. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  15898. } else if (orderitem.purcprice == null) {
  15899. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  15900. } else {
  15901. $scope.checkresult = true;
  15902. $scope.isSave = true;
  15903. }
  15904. })
  15905. };
  15906. }
  15907. // 保存
  15908. $scope.isSave = false;
  15909. $scope.save = function (status) {
  15910. $scope.deOrder.entrystatus = status;
  15911. checkKeyword();
  15912. if ($scope.checkresult) {
  15913. $scope.deOrder.totalamount = 0;
  15914. $scope.deOrder.usdpayment = 0;
  15915. $scope.deOrder.orderamount = 0;
  15916. $scope.deOrder.totalpayament = 0;
  15917. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15918. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15919. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15920. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15921. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15922. });
  15923. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  15924. toaster.pop('info', '提示', '您还未填写任何商品信息');
  15925. } else {
  15926. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  15927. if (data.id) {
  15928. toaster.pop('success', '提示', status + '成功');
  15929. window.location.hash = "#/purc/deputy/" + data.id;
  15930. }
  15931. if (data.error) {
  15932. toaster.pop('error', '提示', status + '失败');
  15933. }
  15934. }, function (response) {
  15935. });
  15936. }
  15937. }
  15938. }
  15939. $scope.openDatePicker = function ($event, deOrder, openParam) {
  15940. $event.preventDefault();
  15941. $event.stopPropagation();
  15942. deOrder[openParam] = !deOrder[openParam];
  15943. };
  15944. }]);
  15945. // 代采企业供应商
  15946. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  15947. $scope.prod = false;
  15948. BaseService.scrollBackToTop();
  15949. // 搜索框回车
  15950. $scope.onSearch = function (keyword) {
  15951. $scope.keyword = keyword;
  15952. $scope.customerParams.page(1);
  15953. $scope.customerParams.reload();
  15954. };
  15955. $scope.customerParams = new ngTableParams({
  15956. page: 1,
  15957. count: 20
  15958. }, {
  15959. total: 0,
  15960. counts: [5, 10, 25, 50],
  15961. getData: function ($defer, params) {
  15962. $scope.loading = true;
  15963. var pageParams = params.url();
  15964. pageParams.keyword = $scope.keyword;
  15965. pageParams.enuu = deputyuu;
  15966. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function (page) {
  15967. $scope.loading = false;
  15968. if (page) {
  15969. params.total(page.totalElement);
  15970. $defer.resolve(page.content);
  15971. }
  15972. $scope.totalCount = page.totalElement;
  15973. }, function (response) {
  15974. $scope.loading = false;
  15975. toaster.pop('error', '数据加载失败', response.data);
  15976. });
  15977. }
  15978. });
  15979. $scope.cancel = function () {
  15980. $modalInstance.dismiss();
  15981. };
  15982. $scope.checkVendor = function (vendor) { // 直接选择
  15983. $modalInstance.close(vendor);
  15984. }
  15985. }]);
  15986. // 代采企业付款企业
  15987. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  15988. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function (data) {
  15989. $scope.paycompanies = data;
  15990. }, function (response) {
  15991. toaster.pop('error', '提示', response.data);
  15992. });
  15993. $scope.cancel = function () {
  15994. $modalInstance.dismiss();
  15995. };
  15996. $scope.select = function (company) { // 直接选择
  15997. $modalInstance.close(company);
  15998. }
  15999. }]);
  16000. /**
  16001. * 代采订单批量导入
  16002. */
  16003. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  16004. // 通过excel批量上传物料
  16005. $scope.result = null;
  16006. $scope.upload = function () {
  16007. var file = $scope.myFiles[0];
  16008. $upload.upload({
  16009. url: 'deputyOrder/release/excel',
  16010. file: file,
  16011. method: 'POST'
  16012. }).success(function (data) {
  16013. $scope.result = data;
  16014. $scope.success = $scope.result.success;
  16015. $scope.total = $scope.result.total;
  16016. $scope.alters = $scope.result.alters;
  16017. }).error(function (response) {
  16018. toaster.pop('error', response.data || response);
  16019. });
  16020. };
  16021. // 查看范例
  16022. $scope.showImg = function () {
  16023. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  16024. box.show();
  16025. box.find('img').attr('src', src);
  16026. box.find('a').click(function () {
  16027. box.hide();
  16028. });
  16029. box.dblclick(function () {
  16030. box.hide();
  16031. });
  16032. };
  16033. // 下载模板
  16034. $scope.download = function () {
  16035. window.location.href = 'deputyOrder/upload/template';
  16036. };
  16037. $scope.enSure = function () {
  16038. $modalInstance.close($scope.result.items);
  16039. }
  16040. $scope.cancel = function () {
  16041. $modalInstance.dismiss();
  16042. }
  16043. }]);
  16044. /**
  16045. * 代采详情
  16046. */
  16047. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', 'DecimalNumber', 'CurrentRole', 'DekeyValue', function ($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal, DecimalNumber, CurrentRole, DekeyValue) {
  16048. BaseService.scrollBackToTop();
  16049. // 获取当前用户是否为普通用户
  16050. CurrentRole.isUser({}, {}, function (data) {
  16051. $scope.isUser = data.isUser;
  16052. });
  16053. var loadData = function () {
  16054. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function (data) {
  16055. $scope.deOrder = data;
  16056. $scope.deOrder.$editing = true;
  16057. }, function (response) {
  16058. toaster.pop('error', '提示', response.data);
  16059. });
  16060. };
  16061. loadData();
  16062. //默认采购单号不重复
  16063. $scope.orderCodeEnable = true;
  16064. // 查询历史供应商
  16065. DeputyOrder.hisvendors({}, function (data) {
  16066. $scope.hisvendors = data;
  16067. }, function (response) {
  16068. toaster.pop('error', '提示', response.data);
  16069. });
  16070. // 代采企业列表
  16071. DeputyOrder.deputyEnterprise({}, function (data) {
  16072. $scope.deputyEnterprises = data;
  16073. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  16074. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  16075. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  16076. });
  16077. var getPayMethod = function(enuu, key) {
  16078. // 获取我方付款支付方式默认值
  16079. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  16080. $scope.methods = data.content;
  16081. });
  16082. }
  16083. // 更新代采企业时更新费率
  16084. $scope.change = function (deputyname) {
  16085. DeputyOrder.deputyEnterprise({}, function (data) {
  16086. $scope.deputyEn = data;
  16087. angular.forEach($scope.deputyEn, function (en) {
  16088. if (deputyname == en.deputyenname) {
  16089. $scope.deputyuu = en.deputyenuu;
  16090. getPayMethod($scope.deputyuu, 'paymentmethod');
  16091. }
  16092. });
  16093. });
  16094. }
  16095. // 查找付款企业
  16096. $scope.dbfindPayCompany = function (deputyuu) {
  16097. var modalInstance = $modal.open({
  16098. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  16099. controller: 'DbfindDeputyPayCompanyCtrl',
  16100. resolve: {
  16101. deputyuu: function () {
  16102. return deputyuu
  16103. }
  16104. }
  16105. });
  16106. modalInstance.result.then(function (data) {
  16107. $scope.deOrder.paycomname = data.enname;
  16108. $scope.deOrder.paycomaddress = data.address;
  16109. })
  16110. }
  16111. // 删除明细
  16112. $scope.del = function (index, id) {
  16113. DeputyOrder.deleteProdById({id: id}, {}, function (data) {
  16114. if (data.success) {
  16115. toaster.pop('success', '提示', data.success);
  16116. $scope.deOrder.deputyOrderItems.splice(index, 1)
  16117. }
  16118. if (data.error) {
  16119. toaster.pop('error', '提示', data.error);
  16120. }
  16121. $scope.deOrder.totalamount = 0;
  16122. $scope.deOrder.usdpayment = 0;
  16123. $scope.deOrder.orderamount = 0;
  16124. $scope.deOrder.totalpayament = 0;
  16125. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16126. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16127. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16128. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16129. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16130. });
  16131. }, function (response) {
  16132. toaster.pop('error', '提示', response.data);
  16133. });
  16134. }
  16135. //增加商品
  16136. $scope.add = function (index) {
  16137. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  16138. toaster.pop('info', '提示', '请先填写商品信息');
  16139. } else {
  16140. $scope.deOrder.deputyOrderItems.push(
  16141. {
  16142. prodname: null,
  16143. prodcode: null,
  16144. prodspec: null,
  16145. prodbrand: null,
  16146. amount: null,
  16147. unitprice: null,
  16148. remark: null,
  16149. orderprice: null
  16150. });
  16151. }
  16152. };
  16153. // 导入商品信息
  16154. $scope.uplodaByBatch = function () {
  16155. var modalInstance = $modal.open({
  16156. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  16157. controller: 'DeputyOrderUploadCtrl',
  16158. size: 'lg',
  16159. resolve: {}
  16160. });
  16161. modalInstance.result.then(function (data) {
  16162. angular.forEach(data, function (data) {
  16163. $scope.deOrder.deputyOrderItems.push(data);
  16164. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  16165. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  16166. $scope.deOrder.deputyOrderItems.splice(i, 1);
  16167. }
  16168. }
  16169. })
  16170. $scope.deOrder.totalamount = 0;
  16171. $scope.deOrder.usdpayment = 0;
  16172. $scope.deOrder.orderamount = 0;
  16173. $scope.deOrder.totalpayament = 0;
  16174. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16175. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16176. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16177. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16178. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16179. });
  16180. }, function () {
  16181. });
  16182. }
  16183. //删除商品
  16184. $scope.delItem = function (index) {
  16185. $scope.deOrder.deputyOrderItems.splice(index, 1);
  16186. };
  16187. var getService = function () {
  16188. return DeputyOrder.getProdList;
  16189. };
  16190. $scope.update = function () {
  16191. $scope.deOrder.$editing = true;
  16192. }
  16193. $scope.cancel = function () {
  16194. $scope.deOrder.$editing = false;
  16195. }
  16196. // 检验订单编号是否存在
  16197. $scope.checkOrder = function (salecode, deputyuu) {
  16198. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  16199. $scope.orderCodeEnable = true;
  16200. if (data.info) {
  16201. toaster.pop('error', '提示', data.info);
  16202. $scope.orderCodeEnable = false;
  16203. }
  16204. }, function (response) {
  16205. toaster.pop('error', '提示', response.data);
  16206. })
  16207. }
  16208. //计算采购单价
  16209. $scope.checkPrice = function (rate) {
  16210. $scope.deOrder.totalamount = 0;
  16211. $scope.deOrder.usdpayment = 0;
  16212. $scope.deOrder.orderamount = 0;
  16213. $scope.deOrder.totalpayament = 0;
  16214. if (rate == null) {
  16215. toaster.pop('info', '提示', '请先填入税率');
  16216. } else {
  16217. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16218. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  16219. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16220. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16221. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16222. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16223. });
  16224. }
  16225. }
  16226. // 获取订单总价
  16227. $scope.totalPrice = function () {
  16228. $scope.deOrder.totalamount = 0;
  16229. $scope.deOrder.usdpayment = 0;
  16230. $scope.deOrder.orderamount = 0;
  16231. $scope.deOrder.totalpayament = 0;
  16232. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16233. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  16234. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16235. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16236. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16237. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16238. }
  16239. });
  16240. }
  16241. $scope.checkresult = false;
  16242. var checkKeyword = function () {
  16243. if ($scope.deOrder.madealdate == null) {
  16244. toaster.pop('info', '提示', '主协议签订日期未选择');
  16245. } else if ($scope.deOrder.madealcode == null) {
  16246. toaster.pop('info', '提示', '主协议签订编号未填写');
  16247. } else if ($scope.deOrder.tervendor == null) {
  16248. toaster.pop('info', '提示', '终端供应商名称未填写');
  16249. } else if ($scope.deOrder.vendtel == null) {
  16250. toaster.pop('info', '提示', '电话号码未填写');
  16251. } else if ($scope.deOrder.venduser == null) {
  16252. toaster.pop('info', '提示', '联系人未填写');
  16253. } else if ($scope.deOrder.shipdate == null) {
  16254. toaster.pop('info', '提示', '供应商发货时间未选择');
  16255. } else if ($scope.deOrder.goodspacking == null) {
  16256. toaster.pop('info', '提示', '货物包装要求未填写');
  16257. } else if ($scope.deOrder.deliverymethod == null) {
  16258. toaster.pop('info', '提示', '供应商交货方式未填写');
  16259. } else if ($scope.deOrder.pickupmethod == null) {
  16260. toaster.pop('info', '提示', '我方提货方式未填写');
  16261. } else if ($scope.deOrder.paymentmethod == null) {
  16262. toaster.pop('info', '提示', '我方付款方式未填写');
  16263. } else if ($scope.deOrder.pickupdate == null) {
  16264. toaster.pop('info', '提示', '我方提货时间未选择');
  16265. } else if ($scope.deOrder.currency == null) {
  16266. toaster.pop('info', '提示', '交易币别未选择');
  16267. } else if ($scope.deOrder.deputyuu == null) {
  16268. toaster.pop('info', '提示', '代采企业未选择');
  16269. } else if ($scope.deOrder.salecode == null) {
  16270. toaster.pop('info', '提示', '订单编号未填写');
  16271. } else if ($scope.deOrder.paydeldate == null) {
  16272. toaster.pop('info', '提示', '我方付款提货时间未选择');
  16273. } else if ($scope.deOrder.riskmethod == null) {
  16274. toaster.pop('info', '提示', '风险承担方式未填写');
  16275. } else if ($scope.deOrder.taxpaymentmethod == null) {
  16276. toaster.pop('info', '提示', '运、税费承担方式');
  16277. } else if ($scope.deOrder.tervendaddress == null) {
  16278. toaster.pop('info', '提示', '终端供应商地址未填写');
  16279. } else if ($scope.deOrder.companyname == null) {
  16280. toaster.pop('info', '提示', '公司全称(英文)未填写');
  16281. } else if ($scope.deOrder.requirepaydate == null) {
  16282. toaster.pop('info', '提示', '要求付汇日期未选择');
  16283. } else if ($scope.deOrder.bankname == null) {
  16284. toaster.pop('info', '提示', '银行名称(英文)未填写');
  16285. } else if ($scope.deOrder.bankaccount == null) {
  16286. toaster.pop('info', '提示', '银行账号未填写');
  16287. } else if ($scope.deOrder.bankaddress == null) {
  16288. toaster.pop('info', '提示', '银行地址未填写');
  16289. } else if ($scope.deOrder.bankcode == null) {
  16290. toaster.pop('info', '提示', '银行代码未填写');
  16291. } else if ($scope.deOrder.salepocode == null) {
  16292. toaster.pop('info', '提示', '合同编号未填写');
  16293. } else if ($scope.deOrder.legalrepresent == null) {
  16294. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  16295. } else if ($scope.deOrder.paycomname == null) {
  16296. toaster.pop('info', '提示', '付款公司未填写');
  16297. } else if ($scope.deOrder.paycomaddress == null) {
  16298. toaster.pop('info', '提示', '付款公司地址未填写');
  16299. } else if ($scope.deOrder.enfax == null) {
  16300. toaster.pop('info', '提示', '供应商方法人电话未填写');
  16301. } else if ($scope.deOrder.paydate == null) {
  16302. toaster.pop('info', '提示', '货款支付时间未选择');
  16303. } else if ($scope.deOrder.paymethod == null) {
  16304. toaster.pop('info', '提示', '货款支付方式未填写');
  16305. } else if ($scope.deOrder.deliverydate == null) {
  16306. toaster.pop('info', '提示', '交货时间未选择');
  16307. } else if (!$scope.orderCodeEnable) {
  16308. toaster.pop('info', '提示', '采购单号重复');
  16309. } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
  16310. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
  16311. } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
  16312. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
  16313. } else {
  16314. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  16315. if (orderitem.prodname == null) {
  16316. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  16317. } else if (orderitem.prodcode == null) {
  16318. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  16319. } else if (orderitem.prodspec == null) {
  16320. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  16321. } else if (orderitem.prodbrand == null) {
  16322. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  16323. } else if (orderitem.amount == null) {
  16324. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  16325. } else if (orderitem.unitprice == null) {
  16326. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  16327. } else if (orderitem.purcprice == null) {
  16328. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  16329. } else {
  16330. $scope.checkresult = true;
  16331. $scope.isSave = true;
  16332. }
  16333. });
  16334. }
  16335. }
  16336. // 保存
  16337. $scope.isSave = false;
  16338. $scope.save = function (status) {
  16339. checkKeyword();
  16340. if ($scope.checkresult) {
  16341. $scope.deOrder.totalamount = 0;
  16342. $scope.deOrder.usdpayment = 0;
  16343. $scope.deOrder.orderamount = 0;
  16344. $scope.deOrder.totalpayament = 0;
  16345. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16346. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16347. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16348. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16349. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16350. });
  16351. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  16352. toaster.pop('info', '提示', '您还未填写任何商品信息');
  16353. } else {
  16354. $scope.deOrder.entrystatus = status;
  16355. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  16356. if (data.id) {
  16357. toaster.pop('success', '提示', '保存成功');
  16358. loadData();
  16359. window.location.reload();
  16360. }
  16361. if (data.error) {
  16362. toaster.pop('error', '提示', '保存失败');
  16363. }
  16364. }, function (response) {
  16365. toaster.pop('error', '保存失败', response.data);
  16366. });
  16367. }
  16368. }
  16369. }
  16370. $scope.openDatePicker = function ($event, deOrder, openParam) {
  16371. $event.preventDefault();
  16372. $event.stopPropagation();
  16373. deOrder[openParam] = !deOrder[openParam];
  16374. };
  16375. //复制采购单
  16376. $scope.copyorder = function (id) {
  16377. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  16378. if (data.id) {
  16379. toaster.pop('success', '提示', '复制生成单据成功');
  16380. window.location.hash = "#/purc/deputy/" + data.id;
  16381. }
  16382. if (data.error) {
  16383. toaster.pop('error', '提示', '保存失败');
  16384. }
  16385. }, function (response) {
  16386. toaster.pop('error', '提示', response.data);
  16387. });
  16388. }
  16389. // 删除代采订单
  16390. $scope.clear = function (id) {
  16391. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  16392. if (data.success) {
  16393. toaster.pop('success', '提示', data.success);
  16394. window.location.hash = "#/purc/deputy";
  16395. }
  16396. }, function (response) {
  16397. toaster.pop('error', '提示', response.data);
  16398. });
  16399. }
  16400. }]);
  16401. /**
  16402. * 代采错误日志
  16403. */
  16404. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function ($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  16405. BaseService.scrollBackToTop();
  16406. var getService = function () {
  16407. return DeputyOrder.getRepetitions;
  16408. };
  16409. $scope.tableParams = new ngTableParams({
  16410. page: 1,
  16411. count: 20,
  16412. sorting: {}
  16413. }, {
  16414. total: 0,
  16415. counts: [5, 10, 25, 50],
  16416. getData: function ($defer, params) {
  16417. $scope.loading = true;
  16418. var pageParams = params.url();
  16419. pageParams.keyword = $scope.keyword;
  16420. pageParams.searchFilter = $scope.searchFilter;
  16421. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  16422. $scope.loading = false;
  16423. if (page) {
  16424. params.total(page.totalElement);
  16425. $defer.resolve(page.content);
  16426. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  16427. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  16428. }
  16429. }, function (response) {
  16430. $scope.loading = false;
  16431. toaster.pop('error', '数据加载失败', response.data);
  16432. });
  16433. }
  16434. });
  16435. // 搜索框回车
  16436. $scope.onSearch = function () {
  16437. $scope.tableParams.page(1);
  16438. $scope.tableParams.reload();
  16439. };
  16440. //删除
  16441. $scope.deleteById = function (id) {
  16442. GetProductInfo.deleteById({id: id}, function (data) {
  16443. if (data.error) {
  16444. toaster.pop("error", "提示", data.error);
  16445. } else {
  16446. toaster.pop("success", "提示", "删除成功");
  16447. $timeout(function () {
  16448. $scope.tableParams.reload();
  16449. }, 500);
  16450. }
  16451. }), function (response) {
  16452. toaster.pop("error", "删除失败", response.data);
  16453. };
  16454. }
  16455. }]);
  16456. /**
  16457. * 招标单
  16458. */
  16459. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams',
  16460. '$modal', '$rootScope', 'PurcTenderInfo', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, PurcTenderInfo) {
  16461. BaseService.scrollBackToTop();
  16462. $scope.searchStatus = false;
  16463. if ($rootScope.tenderActive) {
  16464. $scope.active = $rootScope.tenderActive;
  16465. $rootScope.tenderActive = null;
  16466. } else {
  16467. $scope.active = 'todo';
  16468. }
  16469. $scope.dateZoneText = '不限';
  16470. $scope.deliveryZoneText = '不限';
  16471. $scope.condition = {dateZone: 1, deliveryZone: -1};
  16472. /* 时间筛选初始化*/
  16473. var fromDate = new Date();
  16474. var toDate = new Date();
  16475. fromDate.setMonth(fromDate.getMonth() - 1);
  16476. fromDate.setHours(0, 0, 0, 0);
  16477. toDate.setHours(23, 59, 59, 999);
  16478. $scope.condition.dateFrom = fromDate;
  16479. $scope.condition.dateTo = toDate;
  16480. $scope.changeDateZone = function (zone) {
  16481. $scope.condition.dateZone = zone;
  16482. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  16483. $scope.condition.$dateZoneOpen = false;
  16484. getDateCondition(zone, $scope.condition);
  16485. $scope.tableParams.reload();
  16486. };
  16487. $scope.changeDeliveryZone = function (zone) {
  16488. $scope.condition.deliveryZoneText = zone;
  16489. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  16490. $scope.condition.$delievryZoneOpen = false;
  16491. getDelveryCondition(zone, $scope.condition);
  16492. $scope.tableParams.page(1);
  16493. $scope.tableParams.reload();
  16494. };
  16495. $scope.setActive = function (state) {
  16496. if ($scope.active != state) {
  16497. $scope.active = state;
  16498. if ($scope.tableParams.page() == 1)
  16499. $scope.tableParams.reload();
  16500. else
  16501. $scope.tableParams.page(1);
  16502. }
  16503. };
  16504. var getTenderStatus = function (active) {
  16505. var fn = 'getMyAll';
  16506. switch (active) {
  16507. case 'done':
  16508. fn = 'getMyDone';
  16509. break;
  16510. case 'todo':
  16511. fn = 'getMyTodo';
  16512. break;
  16513. // case 'end':
  16514. // fn = 'getMyEnd';break;
  16515. case 'waiting':
  16516. fn = 'getMyWaiting';
  16517. break;
  16518. }
  16519. return fn;
  16520. };
  16521. var getService = function () {
  16522. if ($scope.searchStatus) {
  16523. return PurcTender;
  16524. }
  16525. return PurcTenderInfo;
  16526. };
  16527. $scope.tableParams = new ngTableParams({
  16528. page: 1,
  16529. count: 20,
  16530. sorting: {
  16531. 'id': 'desc'
  16532. }
  16533. }, {
  16534. total: 0,
  16535. counts: [5, 10, 25, 50],
  16536. getData: function ($defer, params) {
  16537. $scope.loading = true;
  16538. var pageParams = params.url();
  16539. var realActive = {};
  16540. pageParams.searchFilter = { // 筛选条件
  16541. keyword: $scope.keyword,
  16542. fromDate: getDateTime($scope.condition.dateFrom),
  16543. endDate: getDateTime($scope.condition.dateTo)
  16544. };
  16545. getService()[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16546. $scope.loading = false;
  16547. if (page) {
  16548. params.total(page.totalElement);
  16549. $defer.resolve(page.content);
  16550. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  16551. }
  16552. }, function (response) {
  16553. $scope.loading = false;
  16554. toaster.pop('error', '数据加载失败', response.data);
  16555. });
  16556. }
  16557. });
  16558. //获得各分类未阅读数量
  16559. var getUnreadCount = function () {
  16560. PurcTender.getPurcUnreadCount(null, function(data){
  16561. $scope.unread = data;
  16562. });
  16563. };
  16564. getUnreadCount();
  16565. //设置单据已读
  16566. $scope.setOrdersRead = function (id) {
  16567. // 如果单据本身已读,则不发送请求修改数据
  16568. if (!$scope.isUnread(id)){
  16569. return;
  16570. }
  16571. var sourceId = [];
  16572. sourceId.push(id);
  16573. PurcTender.setPurcRead({}, sourceId, function (message) {
  16574. // $scope.getUnreadIds();
  16575. getUnreadCount();
  16576. });
  16577. };
  16578. //获取未读单据id
  16579. var getUnreadIds = function (){
  16580. PurcTender.getPurcUnreadIds({}, "", function (message) {
  16581. $scope.unreadCode = message.content;
  16582. });
  16583. };
  16584. getUnreadIds();
  16585. //判断单据是否未读
  16586. $scope.isUnread = function (tender){
  16587. for (var i in $scope.unreadCode) {
  16588. if (tender.id == $scope.unreadCode[i]) {
  16589. var flag = tender.status == '待评标' && tender.overdue == 1 && tender.result != 1;
  16590. if (!flag) {
  16591. $scope.unreadCode.splice(i,1);
  16592. return false;
  16593. }
  16594. return true;
  16595. }
  16596. }
  16597. };
  16598. $scope.openDatePicker = function ($event, item, openParam) {
  16599. $event.preventDefault();
  16600. $event.stopPropagation();
  16601. item[openParam] = !item[openParam];
  16602. };
  16603. $scope.openFilterDatePicker = function ($event, item, openParam) {
  16604. $event.preventDefault();
  16605. $event.stopPropagation();
  16606. item[openParam] = !item[openParam];
  16607. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  16608. $scope.tableParams.reload();
  16609. }
  16610. };
  16611. $scope.parseDate = function (dateStr) {
  16612. if (dateStr)
  16613. return Date.parse(dateStr, 'yyyy-MM-dd');
  16614. return new Date();
  16615. };
  16616. // 选择查找日期
  16617. $scope.onDateCondition = function () {
  16618. $scope.tableParams.page(1);
  16619. $scope.tableParams.reload();
  16620. };
  16621. // 搜索框回车
  16622. $scope.onSearch = function () {
  16623. $scope.searchStatus = true;
  16624. $scope.tableParams.page(1);
  16625. $scope.tableParams.reload();
  16626. };
  16627. }]);
  16628. /**
  16629. * 新增招标单
  16630. */
  16631. app.controller('PurcNewTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'ShipAddress', '$http', 'AuthenticationService', 'KindAPI', 'BrandActiveAPI', 'Search', 'ComponentActiveAPI', 'GetProductInfo', 'Vendor', 'PurcProduct', 'PurcProductNewest', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, ShipAddress, $http, AuthenticationService, KindAPI, BrandActiveAPI, Search, ComponentActiveAPI, GetProductInfo, Vendor, PurcProduct, PurcProductNewest) {
  16632. // 录入人
  16633. AuthenticationService.getAuthentication().success(function (data) {
  16634. $scope.user = data;
  16635. });
  16636. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16637. $scope.searchMethod = false;
  16638. var getService = function () {
  16639. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  16640. };
  16641. // 物料信息
  16642. $scope.tableParams = new ngTableParams({
  16643. page: 1,
  16644. count: 20,
  16645. sorting: {}
  16646. }, {
  16647. total: 0,
  16648. counts: [5, 10, 25, 50],
  16649. getData: function ($defer, params) {
  16650. $scope.loading = true;
  16651. var pageParams = params.url();
  16652. pageParams.keyword = $scope.keyword;
  16653. $scope.tip = $scope.keyword;
  16654. pageParams.searchFilter = $scope.searchFilter;
  16655. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16656. $scope.loading = false;
  16657. if (page) {
  16658. params.total(page.totalElement);
  16659. $scope.total = page.totalElement;
  16660. $defer.resolve(page.content);
  16661. }
  16662. }, function (response) {
  16663. $scope.loading = false;
  16664. toaster.pop('error', '数据加载失败', response.data);
  16665. });
  16666. }
  16667. });
  16668. // 搜索框回车
  16669. $scope.onSearch = function (keyword) {
  16670. // 每次搜索重置获取数据方法
  16671. $scope.searchMethod = false;
  16672. if(keyword != null && keyword != '') {
  16673. $scope.searchMethod = true;
  16674. }
  16675. $scope.tableParams.page(1);
  16676. $scope.tableParams.reload();
  16677. };
  16678. //在产品列表添加商品
  16679. $scope.check = function (product) {
  16680. $scope.tenderProd.push({
  16681. prodTitle: product.title,
  16682. prodCode: product.code,
  16683. brand: product.brand,
  16684. unit: product.unit,
  16685. qty: null
  16686. // 供应商企业信息
  16687. // enterpriseBaseInfo: [{}]
  16688. });
  16689. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16690. if ($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  16691. $scope.tenderProd.splice(i, 1);
  16692. }
  16693. }
  16694. };
  16695. $scope.loading = false;
  16696. // 获取收货地址列表
  16697. var loadShipAddress = function () {
  16698. ShipAddress.shipAddList({}, function (data) {
  16699. $scope.ships = data;
  16700. $scope.tender.shipadd = $scope.ships[0];
  16701. });
  16702. };
  16703. loadShipAddress();
  16704. // 获取地址信息
  16705. $http.get('resources/citydata/city.json', {
  16706. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  16707. }).then(function (response) {
  16708. $scope.provinces = response.data;
  16709. });
  16710. // 新增收货地址保存
  16711. $scope.saveShipAddress = function (ship) {
  16712. ship.address = ship.province + ship.city + ship.district;
  16713. ShipAddress.saveAddress({}, ship, function (data) {
  16714. if (data.success) {
  16715. // 获取收货地址列表
  16716. loadShipAddress();
  16717. toaster.pop('success', '提示', data.success);
  16718. }
  16719. if (data.error) {
  16720. toaster.pop('error', '提示', data.error);
  16721. }
  16722. });
  16723. };
  16724. // 可选的证照要求
  16725. $scope.certificates = [{name: '三/五证合一'}, {name: '营业执照'}, {name: '组织机构代码证'}, {name: '一般纳税人证明材料'}, {name: '统计登记证'}, {name: '社会保险登记证'}];
  16726. // 处理证照要求
  16727. var parseCertificate = function (a) {
  16728. if (a) {
  16729. var arr = a.split(',');
  16730. angular.forEach(arr, function (app) {
  16731. var contained = false;
  16732. angular.forEach($scope.certificates, function ($app) {
  16733. if ($app.name == app) {
  16734. $app.checked = true;
  16735. contained = true;
  16736. }
  16737. });
  16738. if (!contained) {
  16739. $scope.certificates.push({name: app, checked: true});
  16740. }
  16741. });
  16742. }
  16743. };
  16744. // 联想词start
  16745. // 获取品牌联想词
  16746. $scope.getSimilarBrands = function (value) {
  16747. if (value) {
  16748. // 获取品牌联想词
  16749. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  16750. return data.map(function (item) {
  16751. return item;
  16752. });
  16753. });
  16754. }
  16755. };
  16756. // 获取产品型号联想词
  16757. $scope.getSimilarCodes = function (value) {
  16758. if (value) {
  16759. // 获取产品型号联想词
  16760. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  16761. return data.map(function (item) {
  16762. return item;
  16763. })
  16764. });
  16765. }
  16766. };
  16767. // 选择类目
  16768. $scope.selectKind = function (prod) {
  16769. var submit = [];
  16770. $modal.open({
  16771. animation: true,
  16772. size: 'lg',
  16773. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  16774. controller: 'ProdKindChooseCtrl',
  16775. resolve: {
  16776. actives: function () {
  16777. return $scope.actives;
  16778. }
  16779. }
  16780. }).result.then(function (data) {
  16781. $scope.actives = data.actives;
  16782. var size = data.actives.length;
  16783. submit.gradeOneKiName = '';
  16784. submit.gradeTwoKiName = '';
  16785. submit.gradeThreeKiName = '';
  16786. if (size > 0) {
  16787. submit.gradeOneKiName = $scope.actives[0].nameCn;
  16788. prod.prodTitle = submit.gradeOneKiName;
  16789. if (size > 1) {
  16790. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  16791. prod.prodTitle = submit.gradeTwoKiName;
  16792. if (size > 2) {
  16793. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  16794. prod.prodTitle = submit.gradeThreeKiName;
  16795. }
  16796. }
  16797. }
  16798. }, function () {
  16799. });
  16800. };
  16801. // 点击联想词获取品牌信息
  16802. $scope.onAssociateBrandClick = function (brand, prod) {
  16803. if (brand instanceof String) {
  16804. prod.brand = brand;
  16805. } else if (brand instanceof Object) {
  16806. prod.brand = brand.brandCn;
  16807. }
  16808. };
  16809. // 打开品牌选择的模态框
  16810. $scope.selectBrand = function (prod) { //打开模态
  16811. var modalInstance = $modal.open({
  16812. size: 'lg',
  16813. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  16814. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  16815. });
  16816. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  16817. });
  16818. modalInstance.result.then(function (brand) {
  16819. prod.brand = brand.nameCn;
  16820. }, function (reason) {
  16821. });
  16822. };
  16823. // 点击联想词获取器件信息 带入产品分类和品牌
  16824. $scope.onAssociateCmpClick = function (cmp, prod) {
  16825. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  16826. $scope.component = data;
  16827. prod.prodCode = data.code;
  16828. prod.prodTitle = data.kind.nameCn;
  16829. prod.brand = data.brand.nameCn;
  16830. }, function (res) {
  16831. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  16832. })
  16833. };
  16834. //联想词end
  16835. $scope.condition = {dateZone: 1};
  16836. $scope.tenderProd = [];
  16837. var prod = {
  16838. prodTitle: null,
  16839. prodCode: null,
  16840. brand: null,
  16841. unit: 'PCS',
  16842. qty: null
  16843. // 供应商企业信息
  16844. // enterpriseBaseInfo: [{}]
  16845. };
  16846. $scope.tender = {
  16847. date: new Date(),
  16848. unit: 'PCS',
  16849. currency: 'RMB',
  16850. ifOpen: 1,
  16851. ifTax: 1,
  16852. invoiceType: 2,
  16853. tenderAttachs: [{}]
  16854. };
  16855. //
  16856. $scope.tenderProd.push(prod);
  16857. //增加商品
  16858. $scope.add = function (index) {
  16859. $scope.tenderProd.push({
  16860. prodTitle: null,
  16861. prodCode: null,
  16862. brand: null,
  16863. unit: 'PCS',
  16864. qty: null
  16865. // 供应商企业信息
  16866. // enterpriseBaseInfo: [{}]
  16867. });
  16868. };
  16869. //删除商品
  16870. $scope.del = function (index) {
  16871. $scope.tenderProd.splice(index, 1);
  16872. };
  16873. // 批量导入
  16874. $scope.uplodaByBatch = function () {
  16875. var modalInstance = $modal.open({
  16876. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  16877. controller: 'PurcTenderUploadCtrl',
  16878. size: 'lg',
  16879. resolve: {}
  16880. });
  16881. modalInstance.result.then(function (data) {
  16882. // 获取上传的产品明细,前台展示
  16883. angular.forEach(data, function (data) {
  16884. $scope.tenderProd.push(data);
  16885. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16886. if ($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  16887. $scope.tenderProd.splice(i, 1);
  16888. }
  16889. }
  16890. });
  16891. }, function () {
  16892. });
  16893. };
  16894. $scope.isSave = false;
  16895. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  16896. if (!angular.isUndefined($stateParams.id)) {
  16897. $scope.isSave = true; // 用于判断是新增还是已保存
  16898. $scope.loading = true;
  16899. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  16900. data.$editing = false;
  16901. $scope.tender = data;
  16902. $scope.tenderProd = data.purchaseTenderProds;
  16903. parseCertificate($scope.tender.certificate);
  16904. $scope.firstProd = data.purchaseTenderProds[0];
  16905. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  16906. // 获取供应商联系人
  16907. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function (data) {
  16908. item.saleTender.enterpriseBaseInfo.contacts = data;
  16909. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  16910. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function (contact) {
  16911. if (item.saleTender.userTel === contact.tel) {
  16912. item.saleTender.enterpriseBaseInfo.contact = contact;
  16913. }
  16914. });
  16915. });
  16916. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  16917. $scope.tenderProd.enterpriseBaseInfo = [{}];
  16918. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  16919. } else {
  16920. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  16921. }
  16922. });
  16923. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  16924. $scope.loading = false;
  16925. $scope.attaches = $scope.tender.tenderAttaches;
  16926. }, function (response) {
  16927. $scope.loading = false;
  16928. toaster.pop('error', '数据加载失败', response.data);
  16929. });
  16930. }
  16931. if (angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  16932. $rootScope.tenderVendor = [{}];
  16933. }
  16934. $scope.changeShipAddress = false;
  16935. $scope.changeAddress = function () {
  16936. if ($scope.changeShipAddress) {
  16937. $scope.changeShipAddress = false;
  16938. } else {
  16939. $scope.changeShipAddress = true;
  16940. }
  16941. };
  16942. $scope.changeContactInfo = function (en) {
  16943. if (en.changeContact) {
  16944. en.changeContact = false;
  16945. } else {
  16946. en.changeContact = true;
  16947. }
  16948. };
  16949. $scope.changeCurrency = function (tender) {
  16950. if (tender.currency !== 'RMB') {
  16951. $scope.notRMB = true;
  16952. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  16953. tender.invoiceType = 0;
  16954. } else {
  16955. $scope.notRMB = false;
  16956. }
  16957. };
  16958. // 查找供应商
  16959. $scope.dbfindVendor = function () {
  16960. var modalInstance = $modal.open({
  16961. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  16962. controller: 'DbfindVendorCtrl',
  16963. size: 'lg',
  16964. resolve: {}
  16965. });
  16966. var ifPush = true;
  16967. modalInstance.result.then(function (data) {
  16968. angular.forEach(data, function (vendor) {
  16969. // 获取供应商联系人
  16970. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function (data) {
  16971. vendor.vendorEnterprise.contacts = data;
  16972. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  16973. });
  16974. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  16975. $scope.tenderProd.enterpriseBaseInfo = [{}];
  16976. // 获取供应商联系人
  16977. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  16978. } else {
  16979. for (var i = 0; i < $scope.tenderProd.enterpriseBaseInfo.length; i++) {
  16980. ifPush = true;
  16981. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  16982. ifPush = false;
  16983. break; // 判定到已存在供应商,就终止循环。
  16984. }
  16985. }
  16986. if (ifPush) {
  16987. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  16988. }
  16989. }
  16990. });
  16991. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  16992. }, function () {
  16993. });
  16994. };
  16995. // 新增供应商联系人
  16996. $scope.addContact = function (en) {
  16997. var modalInstance = $modal.open({
  16998. animation: true,
  16999. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  17000. controller: 'AddContacCtrl',
  17001. resolve: {}
  17002. });
  17003. modalInstance.result.then(function (data) {
  17004. en.contact = data;
  17005. en.contact.venduu = en.uu;
  17006. Vendor.saveContact({}, en.contact, function (data) {
  17007. Vendor.contacts({venduu: en.uu}, {}, function (data) {
  17008. en.contacts = data;
  17009. en.contact = data[0]; // 新增的作为联系人
  17010. });
  17011. toaster.pop('success', '提示', '联系人保存成功');
  17012. }, function (response) {
  17013. toaster.pop('error', '失败', response.data);
  17014. });
  17015. });
  17016. };
  17017. // 删除一个供应商
  17018. $scope.removeVendor = function (index) {
  17019. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  17020. };
  17021. // 删除供应商时,后台删除投标单
  17022. $scope.removeSaleTender = function (id, vendUU) {
  17023. var hasSaved = false;
  17024. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function (saleTenderItem) {
  17025. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  17026. hasSaved = true;
  17027. }
  17028. });
  17029. if (hasSaved) {
  17030. PurcTender.removeSaleTender({id: id, vendUU: vendUU}, {}, function (data) {
  17031. }, function (response) {
  17032. toaster.pop('error', '提示', response.data);
  17033. });
  17034. }
  17035. };
  17036. // 删除产品明细时,后台删除产品明细
  17037. $scope.deleteProd = function (tenderProd) {
  17038. if (tenderProd.id) {
  17039. PurcTender.deleteProd({tenderProdId: tenderProd.id}, {}, function (data) {
  17040. }, function (response) {
  17041. toaster.pop('error', '提示', response.data);
  17042. });
  17043. }
  17044. };
  17045. if (!$scope.attaches) {
  17046. $scope.attaches = []; // 存放上传了的附件
  17047. }
  17048. $scope.upload = function (myFile) { // 上传附件
  17049. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  17050. $upload.upload({
  17051. url: 'tender/addTenderAttach',
  17052. file: file,
  17053. method: 'POST'
  17054. }).success(function (attach) {
  17055. $scope.attaches.push(attach);
  17056. });
  17057. };
  17058. $scope.removeAttach = function (id, index) {
  17059. $scope.attaches.splice(index, 1);
  17060. };
  17061. var sleep = function (d) {
  17062. for (var t = Date.now(); Date.now() - t <= d;);
  17063. };
  17064. // 保存和发布招标单
  17065. $scope.save = function (isPublish) {
  17066. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  17067. toaster.pop('info', '提示', '请先指定供应商');
  17068. } else {
  17069. $scope.loading = true;
  17070. // --组装证照要求
  17071. var myCertificate = [];
  17072. angular.forEach($scope.certificates, function (certificate) {
  17073. if (certificate.checked) {
  17074. myCertificate.push(certificate.name);
  17075. }
  17076. });
  17077. $scope.tender.certificate = myCertificate.join(',');
  17078. if (!$scope.tender.code) { //新增,设单号
  17079. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  17080. }
  17081. if ($scope.tender.date instanceof Date) {
  17082. $scope.tender.date = $scope.tender.date.getTime();
  17083. }
  17084. if ($scope.tender.endDate instanceof Date) {
  17085. $scope.tender.endDate = $scope.tender.endDate.getTime();
  17086. }
  17087. if ($scope.tender.publishDate instanceof Date) {
  17088. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  17089. }
  17090. if ($scope.tender.questionEndDate instanceof Date) {
  17091. $scope.tender.questionEndDate = $scope.tender.questionEndDate.getTime();
  17092. }
  17093. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  17094. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  17095. $scope.tender.purchaseTenderProds[i].index = i + 1;
  17096. }
  17097. $scope.tender.tenderAttaches = $scope.attaches;
  17098. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  17099. var enInfos = [];
  17100. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  17101. var enInfo = {
  17102. uu: null,
  17103. contact: null,
  17104. contactTel: null
  17105. };
  17106. enInfo.uu = enterpriseBaseInfo.uu;
  17107. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17108. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17109. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17110. }
  17111. enInfos.push(enInfo);
  17112. });
  17113. if (isPublish) { // 发布
  17114. toaster.pop('info', '提示', '正在发布,请稍候');
  17115. $scope.tender.isPublish = 1;
  17116. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17117. // sleep(1500); //当前方法暂停1.5秒
  17118. $scope.loading = false;
  17119. toaster.pop('success', '成功', '发布成功');
  17120. window.location.hash = '#/purc/tender';
  17121. }, function (response) {
  17122. $scope.loading = false;
  17123. toaster.pop('error', '发布失败', response.data);
  17124. });
  17125. } else { // 保存
  17126. toaster.pop('info', '提示', '正在保存,请稍候');
  17127. $scope.tender.isPublish = 0;
  17128. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17129. $scope.loading = false;
  17130. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  17131. toaster.pop('success', '成功', '保存成功');
  17132. window.location.hash = '#/purc/tender';
  17133. }, function (response) {
  17134. $scope.loading = false;
  17135. toaster.pop('error', '保存失败', response.data);
  17136. });
  17137. }
  17138. }
  17139. };
  17140. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  17141. $scope.removeChecked = function () {
  17142. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  17143. $scope.tenderProd.enterpriseBaseInfo = [];
  17144. }
  17145. };
  17146. // 删除(在录入状态)
  17147. $scope.deleteThis = function (id) {
  17148. PurcTender.deleteOne({id: id}, {}, function (data) {
  17149. toaster.pop('info', '提示', '删除成功');
  17150. window.location.hash = '#/purc/tender';
  17151. });
  17152. };
  17153. // 更新和发布(在录入状态)
  17154. $scope.updateSaved = function (isPublish) {
  17155. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  17156. toaster.pop('info', '提示', '请先指定供应商');
  17157. } else {
  17158. $scope.loading = true;
  17159. // --组装证照要求
  17160. var myCertificate = [];
  17161. angular.forEach($scope.certificates, function (certificate) {
  17162. if (certificate.checked) {
  17163. myCertificate.push(certificate.name);
  17164. }
  17165. });
  17166. $scope.tender.certificate = myCertificate.join(',');
  17167. if ($scope.tender.endDate instanceof Date) {
  17168. $scope.tender.endDate = $scope.tender.endDate.getTime();
  17169. }
  17170. if ($scope.tender.publishDate instanceof Date) {
  17171. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  17172. }
  17173. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  17174. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  17175. $scope.tender.purchaseTenderProds[i].index = i + 1;
  17176. }
  17177. $scope.tender.tenderAttaches = $scope.attaches;
  17178. if ($scope.tender.shipadd) {
  17179. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  17180. }
  17181. angular.forEach($scope.tender.purchaseTenderProds, function (tenderProd) {
  17182. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  17183. });
  17184. var enInfos = [];
  17185. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  17186. var enInfo = {
  17187. uu: null,
  17188. contact: null,
  17189. contactTel: null
  17190. };
  17191. enInfo.uu = enterpriseBaseInfo.uu;
  17192. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17193. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17194. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17195. }
  17196. enInfos.push(enInfo);
  17197. });
  17198. if (isPublish) { // 发布
  17199. toaster.pop('info', '提示', '正在发布,请稍候');
  17200. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17201. $scope.loading = false;
  17202. toaster.pop('success', '成功', '发布成功');
  17203. window.location.hash = '#/purc/tender';
  17204. }, function (response) {
  17205. $scope.loading = false;
  17206. toaster.pop('error', '发布失败', response.data);
  17207. });
  17208. } else { // 保存
  17209. toaster.pop('info', '提示', '正在保存,请稍候');
  17210. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17211. $scope.loading = false;
  17212. toaster.pop('success', '成功', '保存成功');
  17213. window.location.reload();
  17214. }, function (response) {
  17215. $scope.loading = false;
  17216. toaster.pop('error', '保存失败', response.data);
  17217. });
  17218. }
  17219. }
  17220. };
  17221. $scope.currentDay = function () {
  17222. return $filter('date')(new Date(), 'yyyy-MM-dd');
  17223. };
  17224. $scope.getMinDate = function () {
  17225. if ($scope.tender.endDate instanceof Date) {
  17226. var minDate = new Date($scope.tender.endDate.getTime() + 2 * 24 * 60 * 60 * 1000 + 1); // 公布结果日期与截止报价日期至少隔一天
  17227. }
  17228. return $scope.tender.endDate ? $filter('date')(minDate, 'yyyy-MM-dd') : $filter('date')(new Date(new Date().getTime() + 24 * 60 * 60 * 1000 + 1), 'yyyy-MM-dd');
  17229. };
  17230. $scope.getMaxDate = function () {
  17231. // var maxDate = angular.copy($scope.tender.publishDate);
  17232. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  17233. if ($scope.tender.publishDate instanceof Date) {
  17234. var maxDate = new Date($scope.tender.publishDate.getTime() - 24 * 60 * 60 * 1000 - 1); // 至少提前两天
  17235. }
  17236. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd') : "";
  17237. };
  17238. $scope.openDatePicker = function ($event, item, openParam) {
  17239. $event.preventDefault();
  17240. $event.stopPropagation();
  17241. item[openParam] = !item[openParam];
  17242. };
  17243. }]);
  17244. //类目选择模态框(招标产品明细)
  17245. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function ($scope, KindAPI, actives, toaster, $modalInstance) {
  17246. $scope.actives = actives;
  17247. $scope.kinds = [[], [], [], []];
  17248. // 获取子类目
  17249. var getChildren = function (pid, deep) {
  17250. KindAPI.getChildren({parentId: pid}, function (data) {
  17251. $scope.kinds[deep] = data;
  17252. }, function (response) {
  17253. toaster.pop('error', '获取子类目失败', response.data);
  17254. });
  17255. };
  17256. // 改变节点选中状态
  17257. var changeStatus = function (item, deep) {
  17258. var actives = [], level = 0;
  17259. angular.forEach($scope.kinds, function (ks, i) {
  17260. if (i > deep) {
  17261. $scope.kinds[i] = [];
  17262. } else {
  17263. angular.forEach(ks, function (k, j) {
  17264. if (i == deep) {
  17265. if (k.id == item.id) {
  17266. $scope.kinds[i][j].$active = true;
  17267. actives.push(k);
  17268. } else {
  17269. k.$active = null;
  17270. }
  17271. } else {
  17272. if (k.$active) {
  17273. actives.push(k);
  17274. }
  17275. }
  17276. });
  17277. }
  17278. });
  17279. // 选择的节点
  17280. $scope.actives = actives;
  17281. $scope.active = item;
  17282. // 当前可操作的层级
  17283. if (deep < 3) {
  17284. $scope.activeDeep = deep + 1;
  17285. }
  17286. };
  17287. // 节点点击后获取子类目,节点被选中
  17288. $scope.onItemClick = function (item, deep) {
  17289. changeStatus(item, deep);
  17290. if (!item.isLeaf) {
  17291. getChildren(item.id, deep + 1);
  17292. }
  17293. };
  17294. // 重新加载数据
  17295. function reload(deep) {
  17296. var pid;
  17297. if (deep) {
  17298. pid = $scope.actives[deep - 1].id;
  17299. } else {
  17300. pid = 0;
  17301. deep = 0;
  17302. }
  17303. getChildren(pid, deep);
  17304. }
  17305. // 初始加载数据,获取第一层的类目
  17306. if ($scope.actives) {
  17307. angular.forEach($scope.actives, function (v, k) {
  17308. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  17309. $scope.kinds[k] = data;
  17310. angular.forEach($scope.kinds[k], function (kind, i) {
  17311. if (kind.id == v.id) {
  17312. $scope.kinds[k][i].$active = true;
  17313. $scope.actives[k] = $scope.kinds[k][i];
  17314. }
  17315. })
  17316. }, function (response) {
  17317. toaster.pop('error', '获取子类目失败', response.data);
  17318. });
  17319. });
  17320. } else {
  17321. reload();
  17322. }
  17323. // 取消
  17324. $scope.cancel = function () {
  17325. $modalInstance.dismiss();
  17326. };
  17327. // 确认选择
  17328. $scope.check = function () {
  17329. var a = {
  17330. active: $scope.active,
  17331. actives: $scope.actives
  17332. };
  17333. $modalInstance.close(a);
  17334. };
  17335. }]);
  17336. //品牌选择模态框的controller
  17337. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function ($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  17338. $scope.filter = {};
  17339. $scope.brandsTableParams = new ngTableParams({
  17340. page: 1,
  17341. count: 6,
  17342. sorting: {
  17343. nameCn: 'asc'
  17344. }
  17345. }, {
  17346. total: 0,
  17347. counts: [],
  17348. getData: function ($defer, params) {
  17349. var param = BaseService.parseParams(params.url());
  17350. param.keyword = $scope.filter.keyword;
  17351. var keyword = $scope.filter.keyword;
  17352. // param.keyword = $scope.filter.keyword;
  17353. BrandActiveAPI.getSimpleInfoPage(param, {}, function (page) {
  17354. if (page) {
  17355. params.total(page.totalElements);
  17356. $defer.resolve(page.content);
  17357. }
  17358. }, function () {
  17359. });
  17360. }
  17361. });
  17362. // 搜索
  17363. $scope.search = function () {
  17364. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  17365. $scope.brandsTableParams.page(1);
  17366. $scope.brandsTableParams.reload();
  17367. };
  17368. // 选择
  17369. $scope.select = function (brand) {
  17370. $modalInstance.close(brand);
  17371. };
  17372. // 关闭
  17373. $scope.cancel = function () {
  17374. $modalInstance.dismiss();
  17375. };
  17376. }]);
  17377. /**
  17378. * 招标单批量导入
  17379. */
  17380. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  17381. // 通过excel批量上传物料
  17382. $scope.result = null;
  17383. $scope.upload = function () {
  17384. var file = $scope.myFiles[0];
  17385. $upload.upload({
  17386. url: 'tender/release/excel',
  17387. file: file,
  17388. method: 'POST'
  17389. }).success(function (data) {
  17390. $scope.result = data;
  17391. $scope.success = $scope.result.success;
  17392. $scope.total = $scope.result.total;
  17393. $scope.alters = $scope.result.alters;
  17394. }).error(function (response) {
  17395. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  17396. });
  17397. };
  17398. // 查看范例
  17399. $scope.showImg = function () {
  17400. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  17401. box.show();
  17402. box.find('img').attr('src', src);
  17403. box.find('a').click(function () {
  17404. box.hide();
  17405. });
  17406. box.dblclick(function () {
  17407. box.hide();
  17408. });
  17409. };
  17410. // 下载模板
  17411. $scope.download = function () {
  17412. window.location.href = 'tender/upload/template';
  17413. };
  17414. $scope.enSure = function () {
  17415. $modalInstance.close($scope.result.items);
  17416. }
  17417. $scope.cancel = function () {
  17418. $modalInstance.dismiss();
  17419. }
  17420. }]);
  17421. /**
  17422. * 评标
  17423. */
  17424. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, CurrentRole) {
  17425. BaseService.scrollBackToTop();
  17426. // 获取当前用户是否为普通用户
  17427. CurrentRole.isUser({}, {}, function (data) {
  17428. $scope.isUser = data.isUser;
  17429. });
  17430. $scope.tenderItems = [];
  17431. // 采购方获取评标单
  17432. var evaluation = function () {
  17433. $scope.loading = true;
  17434. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17435. data.$editing = false;
  17436. $scope.tender = data;
  17437. $scope.tableParams = new ngTableParams({}, {dataset: data});
  17438. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  17439. $scope.loading = false;
  17440. }, function (response) {
  17441. $scope.loading = false;
  17442. toaster.pop('error', '数据加载失败', response.data);
  17443. });
  17444. };
  17445. evaluation();
  17446. $scope.orderType = '';
  17447. // $scope.dir = '-';
  17448. // 改变排序顺序
  17449. $scope.changeOrder = function (type) {
  17450. $scope.orderType = type;
  17451. };
  17452. $scope.submit = function (tender) {
  17453. var canSubmit = false;
  17454. var hasDecide = false;
  17455. angular.forEach(tender.purchaseTenderProds, function (tenderProd) {
  17456. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17457. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  17458. hasDecide = true;
  17459. }
  17460. });
  17461. if (hasDecide) {
  17462. canSubmit = true;
  17463. }
  17464. });
  17465. if (!canSubmit) {
  17466. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  17467. } else {
  17468. PurcTender.decide(tender, function () {
  17469. toaster.pop('success', '确认成功');
  17470. window.location.hash = '#/purc/tender';
  17471. }, function (response) {
  17472. toaster.pop('error', '确认失败', response.data);
  17473. });
  17474. }
  17475. }
  17476. }]);
  17477. /**
  17478. * 客户招标
  17479. *
  17480. */
  17481. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', 'PurcTenderInfo',
  17482. function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise, PurcTenderInfo) {
  17483. BaseService.scrollBackToTop();
  17484. if ($rootScope.active) {
  17485. $scope.active = $rootScope.active;
  17486. $rootScope.active = null;
  17487. } else {
  17488. $scope.active = 'todo';
  17489. }
  17490. $scope.searchStatus = false;
  17491. /**
  17492. * 改变类型
  17493. */
  17494. var getTypeCondition = function (zone, condition) {
  17495. if (zone == -1) {
  17496. condition.ifOpen = null;
  17497. } else if (zone == 1) {
  17498. condition.ifOpen = 1;
  17499. } else {
  17500. condition.ifOpen = 0;
  17501. }
  17502. };
  17503. $scope.dateZoneText = '不限';
  17504. $scope.typeText = '全部';
  17505. $scope.deliveryZoneText = '不限';
  17506. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17507. /* 时间筛选初始化*/
  17508. var fromDate = new Date();
  17509. var toDate = new Date();
  17510. fromDate.setMonth(fromDate.getMonth() - 1);
  17511. fromDate.setHours(0, 0, 0, 0);
  17512. toDate.setHours(23, 59, 59, 999);
  17513. $scope.condition.dateFrom = fromDate;
  17514. $scope.condition.dateTo = toDate;
  17515. $scope.changeDateZone = function (zone) {
  17516. $scope.condition.dateZone = zone;
  17517. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17518. $scope.condition.$dateZoneOpen = false;
  17519. getDateCondition(zone, $scope.condition);
  17520. $scope.tableParams.page(1);
  17521. $scope.tableParams.reload();
  17522. };
  17523. $scope.changeDeliveryZone = function (zone) {
  17524. $scope.condition.deliveryZoneText = zone;
  17525. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17526. $scope.condition.$delievryZoneOpen = false;
  17527. getDelveryCondition(zone, $scope.condition);
  17528. $scope.tableParams.page(1);
  17529. $scope.tableParams.reload();
  17530. };
  17531. $scope.changeType = function (type) {
  17532. $scope.condition.type = type;
  17533. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17534. getTypeCondition(type, $scope.condition);
  17535. $scope.tableParams.reload();
  17536. };
  17537. $scope.setActive = function (state) {
  17538. if ($scope.active != state) {
  17539. $scope.active = state;
  17540. if ($scope.tableParams.page() == 1)
  17541. $scope.tableParams.reload();
  17542. else
  17543. $scope.tableParams.page(1);
  17544. }
  17545. };
  17546. var getService = function () {
  17547. if ($scope.searchStatus) {
  17548. return PurcTender;
  17549. }
  17550. return PurcTenderInfo;
  17551. };
  17552. $scope.tableParams = new ngTableParams({
  17553. page: 1,
  17554. count: 20,
  17555. sorting: {
  17556. 'id': 'desc'
  17557. }
  17558. }, {
  17559. total: 0,
  17560. counts: [5, 10, 25, 50],
  17561. getData: function ($defer, params) {
  17562. $scope.loading = true;
  17563. var pageParams = params.url();
  17564. var realActive = {};
  17565. pageParams.searchFilter = { // 筛选条件
  17566. keyword: $scope.keyword,
  17567. pt_ifopen: $scope.condition.ifOpen,
  17568. fromDate: getDateTime($scope.condition.dateFrom),
  17569. endDate: getDateTime($scope.condition.dateTo)
  17570. };
  17571. AccountEnterprise.get({}, function (data) {
  17572. $scope.currentEn = data;
  17573. });
  17574. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17575. $scope.loading = false;
  17576. if (page) {
  17577. params.total(page.totalElement);
  17578. $defer.resolve(page.content);
  17579. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17580. angular.forEach(page.content, function (purcTender) {
  17581. purcTender.vendorHasBid = false;
  17582. angular.forEach(purcTender.purchaseTenderProds, function (tenderProd) {
  17583. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17584. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  17585. tenderProd.currentItem = saleTenderItem;
  17586. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  17587. purcTender.vendorHasBid = true;
  17588. }
  17589. }
  17590. });
  17591. });
  17592. });
  17593. }
  17594. }, function (response) {
  17595. $scope.loading = false;
  17596. toaster.pop('error', '数据加载失败', response.data);
  17597. });
  17598. }
  17599. });
  17600. //获得各分类未阅读数量
  17601. var getUnreadCount = function () {
  17602. PurcTender.getUnreadCount(null, function (data) {
  17603. $scope.unread = data;
  17604. });
  17605. };
  17606. getUnreadCount();
  17607. //设置单据已读
  17608. $scope.setOrdersRead = function (id) {
  17609. // 如果单据本身已读,则不发送请求修改数据
  17610. if (!$scope.isUnread(id)){
  17611. return;
  17612. }
  17613. var sourceId = [];
  17614. sourceId.push(id);
  17615. PurcTender.setRead({}, sourceId, function (message) {
  17616. // $scope.getUnreadIds();
  17617. getUnreadCount();
  17618. });
  17619. };
  17620. var getUnreadIds = function () {
  17621. PurcTender.getUnreadIds({}, "", function (message) {
  17622. $scope.unreadCode = message.content;
  17623. });
  17624. };
  17625. getUnreadIds();
  17626. $scope.isUnread = function (id) {
  17627. for (var i in $scope.unreadCode) {
  17628. if (id == $scope.unreadCode[i]) {
  17629. return true;
  17630. }
  17631. }
  17632. };
  17633. $scope.openDatePicker = function ($event, item, openParam) {
  17634. $event.preventDefault();
  17635. $event.stopPropagation();
  17636. item[openParam] = !item[openParam];
  17637. };
  17638. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17639. $event.preventDefault();
  17640. $event.stopPropagation();
  17641. item[openParam] = !item[openParam];
  17642. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17643. $scope.tableParams.reload();
  17644. }
  17645. };
  17646. $scope.parseDate = function (dateStr) {
  17647. if (dateStr)
  17648. return Date.parse(dateStr, 'yyyy-MM-dd');
  17649. return new Date();
  17650. };
  17651. // 选择查找日期
  17652. $scope.onDateCondition = function () {
  17653. $scope.tableParams.page(1);
  17654. $scope.tableParams.reload();
  17655. };
  17656. // 搜索框回车
  17657. $scope.onSearch = function () {
  17658. $scope.searchStatus = true;
  17659. $scope.tableParams.page(1);
  17660. $scope.tableParams.reload();
  17661. };
  17662. }]);
  17663. /**
  17664. * 招标提问列表
  17665. *
  17666. */
  17667. app.controller('SaleTenderQuestionListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17668. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17669. BaseService.scrollBackToTop();
  17670. if ($rootScope.active) {
  17671. $scope.active = $rootScope.active;
  17672. $rootScope.active = null;
  17673. } else {
  17674. $scope.active = 'todo';
  17675. }
  17676. $scope.searchStatus = false;
  17677. /**
  17678. * 改变类型
  17679. */
  17680. var getTypeCondition = function (zone, condition) {
  17681. if (zone == -1) {
  17682. condition.ifOpen = null;
  17683. } else if (zone == 1) {
  17684. condition.ifOpen = 1;
  17685. } else {
  17686. condition.ifOpen = 0;
  17687. }
  17688. };
  17689. $scope.dateZoneText = '不限';
  17690. $scope.typeText = '全部';
  17691. $scope.deliveryZoneText = '不限';
  17692. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17693. /* 时间筛选初始化*/
  17694. var fromDate = new Date();
  17695. var toDate = new Date();
  17696. fromDate.setMonth(fromDate.getMonth() - 1);
  17697. fromDate.setHours(0, 0, 0, 0);
  17698. toDate.setHours(23, 59, 59, 999);
  17699. $scope.condition.dateFrom = fromDate;
  17700. $scope.condition.dateTo = toDate;
  17701. $scope.changeDateZone = function (zone) {
  17702. $scope.condition.dateZone = zone;
  17703. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17704. $scope.condition.$dateZoneOpen = false;
  17705. getDateCondition(zone, $scope.condition);
  17706. $scope.tableParams.page(1);
  17707. $scope.tableParams.reload();
  17708. };
  17709. $scope.changeDeliveryZone = function (zone) {
  17710. $scope.condition.deliveryZoneText = zone;
  17711. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17712. $scope.condition.$delievryZoneOpen = false;
  17713. getDelveryCondition(zone, $scope.condition);
  17714. $scope.tableParams.page(1);
  17715. $scope.tableParams.reload();
  17716. };
  17717. $scope.changeType = function (type) {
  17718. $scope.condition.type = type;
  17719. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17720. getTypeCondition(type, $scope.condition);
  17721. $scope.tableParams.reload();
  17722. };
  17723. $scope.setActive = function (state) {
  17724. if ($scope.active != state) {
  17725. $scope.active = state;
  17726. if ($scope.tableParams.page() == 1)
  17727. $scope.tableParams.reload();
  17728. else
  17729. $scope.tableParams.page(1);
  17730. }
  17731. };
  17732. //TODO 增加直接从数据库取方法之后修改
  17733. var getService = function () {
  17734. if ($scope.searchStatus) {
  17735. return SaleTenderQuestion;
  17736. }
  17737. return SaleTenderQuestion;
  17738. };
  17739. $scope.tableParams = new ngTableParams({
  17740. page: 1,
  17741. count: 20,
  17742. sorting: {
  17743. 'id': 'desc'
  17744. }
  17745. }, {
  17746. total: 0,
  17747. counts: [5, 10, 25, 50],
  17748. getData: function ($defer, params) {
  17749. $scope.loading = true;
  17750. var pageParams = params.url();
  17751. var realActive = {};
  17752. pageParams.searchFilter = { // 筛选条件
  17753. keyword: $scope.keyword,
  17754. fromDate: getDateTime($scope.condition.dateFrom),
  17755. endDate: getDateTime($scope.condition.dateTo)
  17756. };
  17757. AccountEnterprise.get({}, function (data) {
  17758. $scope.currentEn = data;
  17759. });
  17760. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17761. $scope.loading = false;
  17762. params.total(page.totalElement);
  17763. $defer.resolve(page.content);
  17764. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17765. }, function (response) {
  17766. $scope.loading = false;
  17767. toaster.pop('error', '数据加载失败', response.data);
  17768. });
  17769. }
  17770. });
  17771. //TODO 获得各分类未阅读数量
  17772. //TODO 设置单据已读
  17773. $scope.openDatePicker = function ($event, item, openParam) {
  17774. $event.preventDefault();
  17775. $event.stopPropagation();
  17776. item[openParam] = !item[openParam];
  17777. };
  17778. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17779. $event.preventDefault();
  17780. $event.stopPropagation();
  17781. item[openParam] = !item[openParam];
  17782. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17783. $scope.tableParams.reload();
  17784. }
  17785. };
  17786. $scope.parseDate = function (dateStr) {
  17787. if (dateStr)
  17788. return Date.parse(dateStr, 'yyyy-MM-dd');
  17789. return new Date();
  17790. };
  17791. // 选择查找日期
  17792. $scope.onDateCondition = function () {
  17793. $scope.tableParams.page(1);
  17794. $scope.tableParams.reload();
  17795. };
  17796. // 搜索框回车
  17797. $scope.onSearch = function (keyword) {
  17798. // 每次搜索重置获取数据方法
  17799. $scope.searchMethod = false;
  17800. if(keyword != null && keyword != '') {
  17801. $scope.searchMethod = true;
  17802. }
  17803. $scope.tableParams.page(1);
  17804. $scope.tableParams.reload();
  17805. };
  17806. }]);
  17807. /**
  17808. * 投标单提问单详情
  17809. */
  17810. app.controller('SaleTenderQuestionDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams'
  17811. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams){
  17812. BaseService.scrollBackToTop();
  17813. $scope.loading = true;
  17814. var loadData = function () {
  17815. SaleTenderQuestion.getDetail({id: $stateParams.id}, function(data){
  17816. $scope.loading = false;
  17817. $scope.question = data;
  17818. } , function (response) {
  17819. $scope.loading = false;
  17820. toaster.pop('error', '数据加载失败');
  17821. });
  17822. };
  17823. loadData();
  17824. }]);
  17825. /**
  17826. * 招标答疑列表
  17827. *
  17828. */
  17829. app.controller('PurcTenderAnswerListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17830. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17831. BaseService.scrollBackToTop();
  17832. if ($rootScope.active) {
  17833. $scope.active = $rootScope.active;
  17834. $rootScope.active = null;
  17835. } else {
  17836. $scope.active = 'todo';
  17837. }
  17838. $scope.searchStatus = false;
  17839. /**
  17840. * 改变类型
  17841. */
  17842. var getTypeCondition = function (zone, condition) {
  17843. if (zone == -1) {
  17844. condition.ifOpen = null;
  17845. } else if (zone == 1) {
  17846. condition.ifOpen = 1;
  17847. } else {
  17848. condition.ifOpen = 0;
  17849. }
  17850. };
  17851. /**
  17852. * 当前页面状态按钮过滤
  17853. */
  17854. var getAnswer = function (active) {
  17855. var fn = 'getAllAnswer';
  17856. switch (active) {
  17857. case 'done':
  17858. fn = 'getDoneAnswer';
  17859. break;
  17860. case 'todo':
  17861. fn = 'getTodoAnswer';
  17862. break;
  17863. }
  17864. return fn;
  17865. };
  17866. $scope.dateZoneText = '不限';
  17867. $scope.typeText = '全部';
  17868. $scope.deliveryZoneText = '不限';
  17869. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17870. /* 时间筛选初始化*/
  17871. var fromDate = new Date();
  17872. var toDate = new Date();
  17873. fromDate.setMonth(fromDate.getMonth() - 1);
  17874. fromDate.setHours(0, 0, 0, 0);
  17875. toDate.setHours(23, 59, 59, 999);
  17876. $scope.condition.dateFrom = fromDate;
  17877. $scope.condition.dateTo = toDate;
  17878. $scope.changeDateZone = function (zone) {
  17879. $scope.condition.dateZone = zone;
  17880. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17881. $scope.condition.$dateZoneOpen = false;
  17882. getDateCondition(zone, $scope.condition);
  17883. $scope.tableParams.page(1);
  17884. $scope.tableParams.reload();
  17885. };
  17886. $scope.changeDeliveryZone = function (zone) {
  17887. $scope.condition.deliveryZoneText = zone;
  17888. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17889. $scope.condition.$delievryZoneOpen = false;
  17890. getDelveryCondition(zone, $scope.condition);
  17891. $scope.tableParams.page(1);
  17892. $scope.tableParams.reload();
  17893. };
  17894. $scope.changeType = function (type) {
  17895. $scope.condition.type = type;
  17896. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17897. getTypeCondition(type, $scope.condition);
  17898. $scope.tableParams.reload();
  17899. };
  17900. $scope.setActive = function (state) {
  17901. if ($scope.active != state) {
  17902. $scope.active = state;
  17903. if ($scope.tableParams.page() == 1)
  17904. $scope.tableParams.reload();
  17905. else
  17906. $scope.tableParams.page(1);
  17907. }
  17908. };
  17909. //TODO 增加直接从数据库取方法之后修改
  17910. var getService = function () {
  17911. if ($scope.searchStatus) {
  17912. return SaleTenderQuestion;
  17913. }
  17914. return SaleTenderQuestion;
  17915. };
  17916. $scope.tableParams = new ngTableParams({
  17917. page: 1,
  17918. count: 20,
  17919. sorting: {
  17920. 'id': 'desc'
  17921. }
  17922. }, {
  17923. total: 0,
  17924. counts: [5, 10, 25, 50],
  17925. getData: function ($defer, params) {
  17926. $scope.loading = true;
  17927. var pageParams = params.url();
  17928. var realActive = {};
  17929. pageParams.searchFilter = { // 筛选条件
  17930. keyword: $scope.keyword,
  17931. fromDate: getDateTime($scope.condition.dateFrom),
  17932. endDate: getDateTime($scope.condition.dateTo)
  17933. };
  17934. AccountEnterprise.get({}, function (data) {
  17935. $scope.currentEn = data;
  17936. });
  17937. getService()[getAnswer($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17938. $scope.loading = false;
  17939. params.total(page.totalElement);
  17940. $defer.resolve(page.content);
  17941. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17942. }, function (response) {
  17943. $scope.loading = false;
  17944. toaster.pop('error', '数据加载失败', response.data);
  17945. });
  17946. }
  17947. });
  17948. //TODO 获得各分类未阅读数量
  17949. //TODO 设置单据已读
  17950. $scope.openDatePicker = function ($event, item, openParam) {
  17951. $event.preventDefault();
  17952. $event.stopPropagation();
  17953. item[openParam] = !item[openParam];
  17954. };
  17955. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17956. $event.preventDefault();
  17957. $event.stopPropagation();
  17958. item[openParam] = !item[openParam];
  17959. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17960. $scope.tableParams.reload();
  17961. }
  17962. };
  17963. $scope.parseDate = function (dateStr) {
  17964. if (dateStr)
  17965. return Date.parse(dateStr, 'yyyy-MM-dd');
  17966. return new Date();
  17967. };
  17968. // 选择查找日期
  17969. $scope.onDateCondition = function () {
  17970. $scope.tableParams.page(1);
  17971. $scope.tableParams.reload();
  17972. };
  17973. // 搜索框回车
  17974. $scope.onSearch = function (keyword) {
  17975. // 每次搜索重置获取数据方法
  17976. $scope.searchMethod = false;
  17977. if(keyword != null && keyword != '') {
  17978. $scope.searchMethod = true;
  17979. }
  17980. $scope.tableParams.page(1);
  17981. $scope.tableParams.reload();
  17982. };
  17983. }]);
  17984. /**
  17985. * 招标答疑单详情
  17986. */
  17987. app.controller('PurcTenderAnswerDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams', '$modal'
  17988. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams, $modal){
  17989. BaseService.scrollBackToTop();
  17990. $scope.loading = true;
  17991. var loadData = function () {
  17992. SaleTenderQuestion.getAnswerDetail({id: $stateParams.id}, function(data){
  17993. $scope.loading = false;
  17994. $scope.answer = data;
  17995. var now = new Date();
  17996. if ($scope.answer.questionEndDate < now.getTime()) {
  17997. $scope.answer.questionEnd = 1;
  17998. } else {
  17999. $scope.answer.questionEnd = 0;
  18000. }
  18001. } , function (response) {
  18002. $scope.loading = false;
  18003. toaster.pop('error', '数据加载失败');
  18004. });
  18005. };
  18006. loadData();
  18007. // 回答
  18008. $scope.sendAnswer = function (){
  18009. var modalInstance = $modal.open({
  18010. animation: true,
  18011. templateUrl: 'static/tpl/index/purc/tender_answer.html',
  18012. controller: 'PurcTenderAnswerCtrl',
  18013. size: 'lg',
  18014. resolve: {
  18015. answer: function () {
  18016. return $scope.answer;
  18017. } //传递当前答疑单到模态框Controller
  18018. }
  18019. });
  18020. modalInstance.result.then(function () {
  18021. toaster.pop('success', '答疑成功');
  18022. }, function () {
  18023. });
  18024. };
  18025. }]);
  18026. /**
  18027. * 招标单答疑
  18028. */
  18029. app.controller('PurcTenderAnswerCtrl', ['$scope', 'answer','$modalInstance', '$upload', 'toaster', function($scope, answer, $modalInstance, $upload ,toaster){
  18030. $scope.answer = answer;
  18031. $scope.cancel = function() {
  18032. $modalInstance.dismiss();
  18033. };
  18034. //确认回答
  18035. $scope.ok = function (form) {
  18036. $scope.loading = true;
  18037. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18038. $upload.upload({
  18039. url: 'tender/question/answer/send',
  18040. method: 'POST',
  18041. file: file,
  18042. data: {
  18043. json: $scope.answer
  18044. }
  18045. }).success(function (data) {
  18046. $scope.loading = false;
  18047. $modalInstance.close('success');
  18048. }).error(function (data) {
  18049. $scope.loading = false;
  18050. toaster.pop('error', '错误', '出现异常,答疑失败');
  18051. });
  18052. };
  18053. }]);
  18054. /**
  18055. * 平台公开招标
  18056. *
  18057. */
  18058. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  18059. BaseService.scrollBackToTop();
  18060. /**
  18061. * 改变单据日期范围
  18062. */
  18063. var getTenderDateCondition = function (zone, condition) {
  18064. var date = new Date();
  18065. if (zone == -1) {
  18066. condition.dateFrom = null;
  18067. condition.dateTo = null;
  18068. } else if (zone == 7) { // 一星期内
  18069. date.setDate(date.getDate() - 7);
  18070. condition.dateFrom = date;
  18071. condition.dateTo = new Date();
  18072. } else if (zone == 1) { // 一个月内
  18073. date.setMonth(date.getMonth() - 1);
  18074. condition.dateFrom = date;
  18075. condition.dateTo = new Date();
  18076. } else if (zone == 3) { // 三个月内
  18077. date.setMonth(date.getMonth() - 3);
  18078. condition.dateFrom = date;
  18079. condition.dateTo = new Date();
  18080. } else if (zone == 6) { // 半年内
  18081. date.setMonth(date.getMonth() - 6);
  18082. condition.dateFrom = date;
  18083. condition.dateTo = new Date();
  18084. } else { // 一年内
  18085. date.setYear(date.getYear() - 1);
  18086. condition.dateFrom = date;
  18087. condition.dateTo = new Date();
  18088. }
  18089. };
  18090. $scope.active = 'all';
  18091. $scope.dateZoneText = '不限';
  18092. $scope.deliveryZoneText = '不限';
  18093. $scope.condition = {dateZone: -1};
  18094. $scope.changeDateZone = function (zone) {
  18095. $scope.condition.dateZone = zone;
  18096. $scope.condition.$dateZoneOpen = false;
  18097. getTenderDateCondition(zone, $scope.condition);
  18098. $scope.tableParams.page(1);
  18099. $scope.tableParams.reload();
  18100. };
  18101. $scope.openDatePicker = function ($event, item, openParam) {
  18102. $event.preventDefault();
  18103. $event.stopPropagation();
  18104. item[openParam] = !item[openParam];
  18105. };
  18106. $scope.parseDate = function (dateStr) {
  18107. if (dateStr)
  18108. return Date.parse(dateStr, 'yyyy-MM-dd');
  18109. return new Date();
  18110. };
  18111. // 选择查找日期
  18112. $scope.onDateCondition = function () {
  18113. $scope.tableParams.page(1);
  18114. $scope.tableParams.reload();
  18115. };
  18116. var getOpenState = function (active) {
  18117. var fn = 'getOpenAll';
  18118. switch (active) {
  18119. case 'all':
  18120. fn = 'getOpenAll';
  18121. break;
  18122. // case 'done':
  18123. // fn = 'getOpenDone';break;
  18124. case 'todo':
  18125. fn = 'getOpenTodo';
  18126. break;
  18127. case 'end':
  18128. fn = 'getOpenEnd';
  18129. break;
  18130. // case 'waiting':
  18131. // fn = 'getOpenWaiting';break;
  18132. }
  18133. return fn;
  18134. };
  18135. $scope.tableParams = new ngTableParams({
  18136. page: 1,
  18137. count: 20,
  18138. sorting: {
  18139. 'tender.endDate': 'desc',
  18140. 'tender.enterprise.enName': 'asc',
  18141. 'tender.code': 'asc'
  18142. }
  18143. }, {
  18144. total: 0,
  18145. counts: [],
  18146. getData: function ($defer, params) {
  18147. $scope.loading = true;
  18148. var pageParams = params.url();
  18149. var realActive = {};
  18150. pageParams.searchFilter = { // 筛选条件
  18151. keyword: $scope.keyword,
  18152. fromDate: getDateTime($scope.condition.dateFrom),
  18153. endDate: getDateTime($scope.condition.dateTo)
  18154. };
  18155. AccountEnterprise.get({}, function (data) {
  18156. $scope.currentEn = data;
  18157. });
  18158. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18159. $scope.loading = false;
  18160. if (page) {
  18161. params.total(page.totalElement);
  18162. $defer.resolve(page.content);
  18163. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  18164. }
  18165. }, function (response) {
  18166. $scope.loading = false;
  18167. toaster.pop('error', '数据加载失败', response.data);
  18168. });
  18169. }
  18170. });
  18171. $scope.toDetail = function (id) {
  18172. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  18173. };
  18174. // 搜索框回车
  18175. $scope.onSearch = function () {
  18176. $scope.tableParams.page(1);
  18177. $scope.tableParams.reload();
  18178. };
  18179. }]);
  18180. /**
  18181. * 采购方查看供应商投标单
  18182. */
  18183. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  18184. $scope.loading = true;
  18185. PurcTender.getVendorSaleTenderDetail({tenderId: $stateParams.id, vendUU:$stateParams.vendUU}, function (data) {
  18186. $scope.saleTender = data.saleTender;
  18187. $scope.tender = data.tender;
  18188. $scope.loading = false;
  18189. }, function (response) {
  18190. $scope.loading = false;
  18191. toaster.pop('error', '数据加载失败', response.data);
  18192. });
  18193. }]);
  18194. /**
  18195. * 查看投标单详情
  18196. */
  18197. app.controller('SaleTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', '$upload', 'AccountEnterprise', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, $upload, AccountEnterprise, CurrentRole) {
  18198. BaseService.scrollBackToTop();
  18199. if (!$scope.attaches) {
  18200. $scope.attaches = []; // 存放上传了的附件
  18201. }
  18202. AccountEnterprise.get({}, function (data) {
  18203. $scope.currentEn = data;
  18204. });
  18205. // 获取当前用户是否为普通用户
  18206. CurrentRole.isUser({}, {}, function (data) {
  18207. $scope.isUser = data.isUser;
  18208. });
  18209. $scope.loading = true;
  18210. PurcTender.getSaleTenderDetail({tenderId: $stateParams.id}, function (data) {
  18211. $scope.saleTender = data.saleTender;
  18212. $scope.tender = data.tender;
  18213. $scope.loading = false;
  18214. }, function (response) {
  18215. $scope.loading = false;
  18216. toaster.pop('error', '数据加载失败', response.data);
  18217. });
  18218. // 提问
  18219. $scope.sendQuestion = function (){
  18220. var modalInstance = $modal.open({
  18221. animation: true,
  18222. templateUrl: 'static/tpl/index/sale/tender_question.html',
  18223. controller: 'SaleTenderQuestionCtrl',
  18224. size: 'lg',
  18225. resolve: {
  18226. saleTender: function () {
  18227. return $scope.saleTender;
  18228. } //传递当前投标单到模态框Controller
  18229. }
  18230. });
  18231. modalInstance.result.then(function () {
  18232. toaster.pop('success', '提问成功');
  18233. }, function () {
  18234. });
  18235. };
  18236. $scope.upload = function (myFile) { // 上传附件
  18237. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  18238. $upload.upload({
  18239. url: 'tender/addTenderItemAttach',
  18240. file: file,
  18241. method: 'POST'
  18242. }).success(function (attach) {
  18243. $scope.attaches.push(attach);
  18244. });
  18245. };
  18246. $scope.removeAttach = function (attachId, index) {
  18247. $scope.attaches.splice(index, 1);
  18248. };
  18249. var taxrateYes = false;
  18250. var cycleYes = false;
  18251. var priceYes = false;
  18252. $scope.canSave = false;
  18253. $scope.validateThis = function (value, type) {
  18254. if ("" != value) {
  18255. switch (type) {
  18256. case 'taxrate':
  18257. var regex = /^\+?[0-9][0-9]{0,1}$/;
  18258. if (regex.test(value)) {
  18259. taxrateYes = true;
  18260. } else {
  18261. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  18262. }
  18263. break;
  18264. case 'cycle':
  18265. regex = /^\+?[1-9][0-9]*$/;
  18266. if (regex.test(value)) {
  18267. cycleYes = true;
  18268. } else {
  18269. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  18270. }
  18271. break;
  18272. case 'price':
  18273. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18274. if (regex.test(value) && value !== 0) {
  18275. priceYes = true;
  18276. } else {
  18277. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  18278. }
  18279. break;
  18280. }
  18281. }
  18282. };
  18283. $scope.emNumYes = true;
  18284. $scope.validEmNum = function (value) {
  18285. var regex = /^\+?[1-9][0-9]*$/;
  18286. if (!regex.test(value) || value === 0 || value !== null) {
  18287. $scope.emNumYes = false;
  18288. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  18289. }
  18290. };
  18291. $scope.validateProds = function (saleTender) {
  18292. $scope.canSave = true;
  18293. var cycleRegex = /^\+?[1-9][0-9]*$/;
  18294. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  18295. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  18296. if ($scope.tender.ifAll == 1) { // 全包时需要所有信息都填写并合法才可以投标
  18297. // 全包全部需要填写,且需要符合正则式
  18298. angular.forEach(saleTender.saleTenderItems, function(item) {
  18299. if ((!item.cycle || !item.price) || (!cycleRegex.test(item.cycle) || !priceRegex.test(item.price))) {
  18300. $scope.canSave = false;
  18301. }
  18302. });
  18303. if (!saleTender.cycle || !saleTender.taxrate || !cycleRegex.test(saleTender.cycle) || !taxrateRegex.test(saleTender.taxrate)) {
  18304. $scope.canSave = false;
  18305. }
  18306. } else { // 非全包模式
  18307. angular.forEach(saleTender.saleTenderItems, function(item) {
  18308. if (item.cycle || item.taxrate || item.price) {
  18309. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18310. // 判断填写过的有为0或不符合正则式的,设置不能保存
  18311. if (!cycleRegex.test(item.cycle) || !taxrateRegex.test(item.taxrate) || !priceRegex.test(item.price)) {
  18312. $scope.canSave = false;
  18313. } else {
  18314. $scope.canSave = true;
  18315. }
  18316. }
  18317. });
  18318. }
  18319. };
  18320. // 投标
  18321. $scope.bidIt = function (saleTender) {
  18322. $scope.loading = true;
  18323. if (saleTender.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  18324. saleTender.enterpriseBaseInfo.enEstablishDate = saleTender.enterpriseBaseInfo.enEstablishDate.getTime();
  18325. }
  18326. saleTender.bidAttaches.push.apply(saleTender.bidAttaches, $scope.attaches);
  18327. angular.forEach(saleTender.saleTenderItems, function (item) {
  18328. item.tenderProd = {};
  18329. if ("" == item.price && "" == item.taxrate && "" == item.cycle) {
  18330. item.price = 0;
  18331. item.cycle = 0;
  18332. item.taxrate = 0;
  18333. }
  18334. });
  18335. PurcTender.reply({}, saleTender, function (data) {
  18336. $scope.loading = false;
  18337. toaster.pop('info', '成功', '投标成功');
  18338. window.location.hash = '#/sale/tender';
  18339. }, function (response) {
  18340. $scope.loading = false;
  18341. toaster.pop('error', '投标失败', response.data);
  18342. });
  18343. };
  18344. $scope.condition = {
  18345. $fromOpened: false
  18346. };
  18347. $scope.getMaxDate = function () {
  18348. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18349. };
  18350. $scope.openDatePicker = function ($event, item, openParam) {
  18351. $event.preventDefault();
  18352. $event.stopPropagation();
  18353. item[openParam] = !item[openParam];
  18354. };
  18355. }]);
  18356. /**
  18357. * 投标单提问
  18358. */
  18359. app.controller('SaleTenderQuestionCtrl', ['$scope', 'saleTender','$modalInstance', '$upload', 'toaster', function($scope, saleTender, $modalInstance, $upload ,toaster){
  18360. $scope.saleTender = saleTender;
  18361. // 当前日期,用作新增提问
  18362. $scope.currentDay = new Date();
  18363. $scope.question = {
  18364. inDate : null,
  18365. replyDate : null,
  18366. topic : null,
  18367. status : null,
  18368. content : null,
  18369. questionAttaches : []
  18370. };
  18371. $scope.cancel = function() {
  18372. $modalInstance.dismiss();
  18373. };
  18374. //确认提问
  18375. $scope.ok = function (form) {
  18376. $scope.loading = true;
  18377. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18378. $upload.upload({
  18379. url: 'tender/question/send/' + $scope.saleTender.id,
  18380. method: 'POST',
  18381. file: file,
  18382. data: {
  18383. json: $scope.question
  18384. }
  18385. }).success(function (data) {
  18386. $scope.loading = false;
  18387. $modalInstance.close('success');
  18388. }).error(function (data) {
  18389. $scope.loading = false;
  18390. toaster.pop('error', '错误', '出现异常,提问失败');
  18391. });
  18392. };
  18393. }]);
  18394. /**
  18395. * 公开招标转投标单
  18396. */
  18397. 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) {
  18398. BaseService.scrollBackToTop();
  18399. $scope.attaches = []; // 存放上传了的附件
  18400. var sleep = function (d) {
  18401. for (var t = Date.now(); Date.now() - t <= d;);
  18402. }
  18403. var getCurrentEn = function () {
  18404. AccountEnterprise.get({}, function (data) {
  18405. $scope.currentEn = data;
  18406. });
  18407. }
  18408. if (!angular.isUndefined($stateParams.id)) { // 获取招标单详情
  18409. $scope.loading = true;
  18410. getCurrentEn();
  18411. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  18412. data.$editing = false;
  18413. $scope.tender = data;
  18414. $scope.tenderProd = data.purchaseTenderProds;
  18415. $scope.currentHasBid = false; // 默认当前企业未转投标单
  18416. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  18417. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  18418. $scope.currentHasBid = true;
  18419. }
  18420. });
  18421. $scope.loading = false;
  18422. $scope.attaches = $scope.tender.tenderAttaches;
  18423. }, function (response) {
  18424. $scope.loading = false;
  18425. toaster.pop('error', '数据加载失败', response.data);
  18426. });
  18427. }
  18428. $scope.hasClick = false;
  18429. $scope.iWantToBid = function (id) {
  18430. $scope.hasClick = true;
  18431. PurcTender.addItems({id: id}, {}, function (data) { // 添加明细
  18432. toaster.pop('success', '成功', '转投标单成功');
  18433. window.location.hash = "#/sale/tender/" + id;
  18434. }, function (response) {
  18435. toaster.pop('error', '操作失败', response.data);
  18436. });
  18437. };
  18438. }]);
  18439. // 基础资料客户详情
  18440. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'VendorInfo', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, VendorInfo) {
  18441. BaseService.scrollBackToTop();
  18442. $scope.status = 'customer';
  18443. $scope.userInfoResult = true;
  18444. AuthenticationService.getAuthentication().success(function (data) {
  18445. $scope.loading = false;
  18446. $scope.thisUser = data;
  18447. });
  18448. $scope.customerParams = new ngTableParams({
  18449. page: 1,
  18450. count: 20
  18451. }, {
  18452. total: 0,
  18453. counts: [],
  18454. getData: function ($defer, params) {
  18455. $scope.loading = true;
  18456. var pageParams = params.url();
  18457. pageParams.keyword = $scope.keyword;
  18458. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18459. $scope.loading = false;
  18460. if (page) {
  18461. params.total(page.totalElement);
  18462. $scope.total = page.totalElement;
  18463. $defer.resolve(page.content);
  18464. }
  18465. $scope.totalCount = page.totalElement;
  18466. }, function (response) {
  18467. $scope.loading = false;
  18468. toaster.pop('error', '数据加载失败', response.data);
  18469. });
  18470. }
  18471. });
  18472. // 搜索框回车
  18473. $scope.onSearch = function (keyword) {
  18474. $scope.customerParams.page(1);
  18475. $scope.customerParams.reload();
  18476. $scope.tip = keyword;
  18477. };
  18478. // 查看详情
  18479. $scope.viewDetail = function (id) {
  18480. window.location.hash = "#/sale/customer/" + id;
  18481. }
  18482. // 取消合作关系
  18483. $scope.disableCust = function (id) {
  18484. VendorInfo.disableCust({id: id}, {}, function (data) {
  18485. if (data.success) {
  18486. toaster.pop('success', '提示', data.success);
  18487. }
  18488. // $scope.customerParams.page(1);
  18489. $scope.customerParams.reload();
  18490. }, function (response) {
  18491. toaster.pop('error', '提示', response.data);
  18492. });
  18493. }
  18494. // 解除禁用
  18495. $scope.activeCust = function (id) {
  18496. VendorInfo.activeCust({id: id}, {}, function (data) {
  18497. if (data.success) {
  18498. toaster.pop('success', '提示', data.success);
  18499. }
  18500. // $scope.customerParams.page(1);
  18501. $scope.customerParams.reload();
  18502. }, function (response) {
  18503. toaster.pop('error', '提示', response.data);
  18504. });
  18505. }
  18506. }]);
  18507. // 基础资料供应商
  18508. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18509. BaseService.scrollBackToTop();
  18510. $scope.status = 'vendor';
  18511. // 搜索框回车
  18512. $scope.onSearch = function () {
  18513. $scope.customerParams.page(1);
  18514. $scope.customerParams.reload();
  18515. };
  18516. $scope.customerParams = new ngTableParams({
  18517. page: 1,
  18518. count: 20
  18519. }, {
  18520. total: 0,
  18521. counts: [],
  18522. getData: function ($defer, params) {
  18523. $scope.loading = true;
  18524. var pageParams = params.url();
  18525. pageParams.keyword = $scope.keyword;
  18526. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  18527. $scope.loading = false;
  18528. if (page) {
  18529. params.total(page.totalElement);
  18530. $scope.total = page.totalElement;
  18531. $defer.resolve(page.content);
  18532. }
  18533. $scope.totalCount = page.totalElement;
  18534. }, function (response) {
  18535. $scope.loading = false;
  18536. toaster.pop('error', '数据加载失败', response.data);
  18537. });
  18538. }
  18539. });
  18540. // 查看供应商详情
  18541. $scope.VendorDetail = function (id, uu) {
  18542. $rootScope.vendorId = id;
  18543. $rootScope.vendoruu = uu;
  18544. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18545. }
  18546. // 向企业购买
  18547. $scope.purcByEn = function (businessCode) {
  18548. $rootScope.businessCode = businessCode;
  18549. window.location.hash = "#/purc/addOrder";
  18550. }
  18551. // 取消合作关系
  18552. $scope.relieve = function (id) {
  18553. VendorInfo.relieve({id: id}, {}, function (data) {
  18554. if (data.success) {
  18555. toaster.pop('success', '提示', data.success);
  18556. }
  18557. // $scope.customerParams.page(1);
  18558. $scope.customerParams.reload();
  18559. }, function (response) {
  18560. toaster.pop('error', '提示', response.data);
  18561. });
  18562. }
  18563. // 建立合作关系
  18564. $scope.activeVend = function (id) {
  18565. VendorInfo.activeVend({id: id}, {}, function (data) {
  18566. if (data.success) {
  18567. toaster.pop('success', '提示', data.success);
  18568. }
  18569. // $scope.customerParams.page(1);
  18570. $scope.customerParams.reload();
  18571. }, function (response) {
  18572. toaster.pop('error', '提示', response.data);
  18573. });
  18574. }
  18575. }]);
  18576. // 基础资料服务商
  18577. app.controller('ServicerInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18578. BaseService.scrollBackToTop();
  18579. $scope.status = 'servicer';
  18580. // 搜索框回车
  18581. $scope.onSearch = function () {
  18582. $scope.customerParams.page(1);
  18583. $scope.customerParams.reload();
  18584. };
  18585. $scope.customerParams = new ngTableParams({
  18586. page: 1,
  18587. count: 20
  18588. }, {
  18589. total: 0,
  18590. counts: [],
  18591. getData: function ($defer, params) {
  18592. $scope.loading = true;
  18593. var pageParams = params.url();
  18594. pageParams.keyword = $scope.keyword;
  18595. Vendor.getServicer.call(null, BaseService.parseParams(pageParams), function (page) {
  18596. $scope.loading = false;
  18597. if (page) {
  18598. params.total(page.totalElement);
  18599. $scope.total = page.totalElement;
  18600. $defer.resolve(page.content);
  18601. }
  18602. $scope.totalCount = page.totalElement;
  18603. }, function (response) {
  18604. $scope.loading = false;
  18605. toaster.pop('error', '数据加载失败', response.data);
  18606. });
  18607. }
  18608. });
  18609. // 查看服务商详情
  18610. $scope.VendorDetail = function (id, uu) {
  18611. $rootScope.vendorId = id;
  18612. $rootScope.vendoruu = uu;
  18613. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18614. };
  18615. // 取消合作关系
  18616. $scope.relieveServicer = function (id) {
  18617. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  18618. if (data.success) {
  18619. toaster.pop('success', '提示', data.success);
  18620. }
  18621. // $scope.customerParams.page(1);
  18622. $scope.customerParams.reload();
  18623. }, function (response) {
  18624. toaster.pop('error', '提示', response.data);
  18625. });
  18626. }
  18627. // 建立合作关系
  18628. $scope.activeServicer = function (id) {
  18629. VendorInfo.activeServicer({id: id}, {}, function (data) {
  18630. if (data.success) {
  18631. toaster.pop('success', '提示', data.success);
  18632. }
  18633. // $scope.customerParams.page(1);
  18634. $scope.customerParams.reload();
  18635. }, function (response) {
  18636. toaster.pop('error', '提示', response.data);
  18637. });
  18638. }
  18639. }]);
  18640. // 企业圈搜索界面
  18641. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
  18642. $scope.onSearch = function (keyword) {
  18643. $rootScope.enterpriseKeyword = keyword;
  18644. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  18645. }
  18646. }]);
  18647. // 企业圈搜索结果
  18648. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  18649. $scope.status = 'add';
  18650. BaseService.scrollBackToTop();
  18651. $scope.active = 'all';
  18652. $scope.agreedText = '全部';
  18653. $scope.dateZoneText = '一个月内';
  18654. $scope.condition = {dateZone: 1};
  18655. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18656. $scope.changeAgreed = function (agreed) {
  18657. $scope.condition.agreed = agreed;
  18658. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18659. $scope.condition.$agreedOpen = false;
  18660. };
  18661. $scope.changeDateZone = function (zone) {
  18662. $scope.condition.dateZone = zone;
  18663. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18664. $scope.condition.$dateZoneOpen = false;
  18665. getDateCondition(zone, $scope.condition);
  18666. $scope.tableParams.reload();
  18667. };
  18668. $scope.setActive = function (state) {
  18669. if ($scope.active != state) {
  18670. $scope.active = state;
  18671. if ($scope.tableParams.page() == 1)
  18672. $scope.tableParams.reload();
  18673. else
  18674. $scope.tableParams.page(1);
  18675. }
  18676. };
  18677. var getService = function () {
  18678. return getAccountUserSpace;
  18679. };
  18680. $scope.tableParams = new ngTableParams({
  18681. page: 1,
  18682. count: 20,
  18683. sorting: {}
  18684. }, {
  18685. total: 0,
  18686. counts: [],
  18687. getData: function ($defer, params) {
  18688. $scope.loading = true;
  18689. var pageParams = params.url();
  18690. pageParams.keyword = $scope.keyword;
  18691. $scope.tip = $scope.keyword;
  18692. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18693. $scope.loading = false;
  18694. if (page) {
  18695. params.total(page.totalElement);
  18696. $defer.resolve(page.content);
  18697. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18698. }
  18699. }, function (response) {
  18700. $scope.loading = false;
  18701. toaster.pop('error', '数据加载失败', response.data);
  18702. });
  18703. }
  18704. });
  18705. // 搜索框回车
  18706. $scope.onSearch = function (keyword) {
  18707. if (keyword === '') {
  18708. keyword = null;
  18709. $rootScope.searchKeyword = keyword;
  18710. $scope.keyword = keyword;
  18711. $scope.tableParams.page(1);
  18712. $scope.tableParams.reload();
  18713. } else {
  18714. $rootScope.searchKeyword = keyword;
  18715. $scope.keyword = keyword;
  18716. $scope.tableParams.page(1);
  18717. $scope.tableParams.reload();
  18718. }
  18719. };
  18720. // 添加合作关系
  18721. $scope.addPartner = function (name, businessCode) {
  18722. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  18723. if (data.success) {
  18724. toaster.pop("success", '添加成功', data.success);
  18725. $scope.tableParams.reload();
  18726. }
  18727. if (data.error) {
  18728. toaster.pop("error", '添加失败', data.error);
  18729. }
  18730. }, function (response) {
  18731. toaster.pop('error', '失败', response.data);
  18732. });
  18733. }
  18734. /**
  18735. * 邀请注册商务平台
  18736. */
  18737. $scope.invite = function (name) {
  18738. var modalInstance = $modal.open({
  18739. animation: true,
  18740. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  18741. controller: 'InviteCtrl',
  18742. resolve: {
  18743. enname: function () {
  18744. return name
  18745. }
  18746. }
  18747. });
  18748. modalInstance.result.then(function (data) {
  18749. InvitationRecord.invite({formStore: data}, {}, function (data) {
  18750. if (data.success) {
  18751. toaster.pop('success', '提示', data.success);
  18752. $scope.tableParams.reload();
  18753. }
  18754. if (data.error) {
  18755. toaster.pop('error', '提示', data.error);
  18756. }
  18757. }, function (response) {
  18758. toaster.pop('error', '提示', response.data);
  18759. });
  18760. });
  18761. }
  18762. /**
  18763. * 立即查看
  18764. */
  18765. $scope.view = function (name) {
  18766. $rootScope.vendName = name;
  18767. window.location.hash = "#/baseInfo/newPartner";
  18768. }
  18769. }]);
  18770. // 平台新增的询价单(指定一个供应商)
  18771. app.controller('PurcInquiryNewCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'GetProductInfo', '$timeout', '$http', 'ShipAddress', '$stateParams', 'Vendor', 'Product', 'Search', 'ComponentActiveAPI', 'VendorInfo', function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, GetProductInfo, $timeout, $http, ShipAddress, $stateParams, Vendor, Product, Search, ComponentActiveAPI, VendorInfo) {
  18772. $scope.active = 'all';
  18773. // 供应商信息
  18774. var loadData = function () {
  18775. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function (data) {
  18776. $scope.vendor = data;
  18777. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  18778. $scope.vendorContacts = data;
  18779. });
  18780. // 物料信息
  18781. $scope.tableParams = new ngTableParams({
  18782. page: 1,
  18783. count: 20
  18784. }, {
  18785. total: 0,
  18786. counts: [5, 10, 25, 50],
  18787. getData: function ($defer, params) {
  18788. $scope.loading = true;
  18789. var pageParams = params.url();
  18790. pageParams.keyword = $scope.keyword;
  18791. $scope.tip = $scope.keyword;
  18792. pageParams.custUU = $scope.vendor.uu;
  18793. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18794. $scope.loading = false;
  18795. if (page) {
  18796. params.total(page.totalElement);
  18797. $scope.total = page.totalElement;
  18798. $defer.resolve(page.content);
  18799. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  18800. }
  18801. }, function (response) {
  18802. $scope.loading = false;
  18803. toaster.pop('error', '数据加载失败', response.data);
  18804. });
  18805. }
  18806. });
  18807. });
  18808. };
  18809. loadData();
  18810. $rootScope.tenderVendor = null;// 清除掉已选择的
  18811. var getService = function () {
  18812. return GetProductInfo;
  18813. };
  18814. $scope.inquiry = {
  18815. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  18816. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  18817. priceType: '采购',
  18818. isOpen: 0,
  18819. invoice: 0,
  18820. ifTax: 1,
  18821. currency: 'RMB'
  18822. };
  18823. $scope.changeCurrency = function (inquiry) {
  18824. if (inquiry.currency !== 'RMB') {
  18825. $scope.notRMB = true;
  18826. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  18827. inquiry.invoice = 0;
  18828. } else {
  18829. $scope.notRMB = false;
  18830. }
  18831. };
  18832. // 获取收货地址列表
  18833. var loadShipAddress = function () {
  18834. ShipAddress.shipAddList({}, function (data) {
  18835. $scope.ships = data;
  18836. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  18837. });
  18838. };
  18839. loadShipAddress();
  18840. // 获取地址信息
  18841. $http.get('resources/citydata/city.json', {
  18842. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  18843. }).then(function (response) {
  18844. $scope.provinces = response.data;
  18845. });
  18846. // 新增收货地址保存
  18847. $scope.saveShipAddress = function (ship) {
  18848. ship.address = ship.province + ship.city + ship.district;
  18849. ShipAddress.saveAddress({}, ship, function (data) {
  18850. if (data.success) {
  18851. // 获取收货地址列表
  18852. loadShipAddress();
  18853. toaster.pop('success', '提示', data.success);
  18854. }
  18855. if (data.error) {
  18856. toaster.pop('error', '提示', data.error);
  18857. }
  18858. });
  18859. };
  18860. $scope.currentDay = function () {
  18861. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18862. };
  18863. // 搜索框回车
  18864. $scope.onSearch = function (keyword) {
  18865. $scope.tableParams.page(1);
  18866. $scope.tableParams.reload();
  18867. };
  18868. $scope.inquiry.inquiryItems = [];
  18869. var prod = {
  18870. prodCode: null,
  18871. prodTitle: null,
  18872. inbrand: null,
  18873. currency: 'RMB',
  18874. toDate: null,
  18875. unit: 'PCS'
  18876. };
  18877. $scope.inquiry.inquiryItems.push(prod);
  18878. // 联想词start
  18879. // 获取品牌联想词
  18880. $scope.getSimilarBrands = function (value) {
  18881. if (value) {
  18882. // 获取品牌联想词
  18883. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  18884. return data.map(function (item) {
  18885. return item;
  18886. });
  18887. });
  18888. }
  18889. };
  18890. // 获取产品型号联想词
  18891. $scope.getSimilarCodes = function (value) {
  18892. if (value) {
  18893. // 获取产品型号联想词
  18894. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  18895. return data.map(function (item) {
  18896. return item;
  18897. })
  18898. });
  18899. }
  18900. };
  18901. $scope.selectKind = function (prod) {
  18902. var submit = [];
  18903. $modal.open({
  18904. animation: true,
  18905. size: 'lg',
  18906. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  18907. controller: 'ProdKindChooseCtrl',
  18908. resolve: {
  18909. actives: function () {
  18910. return $scope.actives;
  18911. }
  18912. }
  18913. }).result.then(function (data) {
  18914. $scope.actives = data.actives;
  18915. var size = data.actives.length;
  18916. submit.gradeOneKiName = '';
  18917. submit.gradeTwoKiName = '';
  18918. submit.gradeThreeKiName = '';
  18919. if (size > 0) {
  18920. submit.gradeOneKiName = $scope.actives[0].nameCn;
  18921. prod.prodTitle = submit.gradeOneKiName;
  18922. if (size > 1) {
  18923. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  18924. prod.prodTitle = submit.gradeTwoKiName;
  18925. if (size > 2) {
  18926. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  18927. prod.prodTitle = submit.gradeThreeKiName;
  18928. }
  18929. }
  18930. }
  18931. }, function () {
  18932. });
  18933. };
  18934. // 点击联想词获取品牌信息
  18935. $scope.onAssociateBrandClick = function (brand, prod) {
  18936. if (brand instanceof String) {
  18937. prod.inbrand = brand;
  18938. } else if (brand instanceof Object) {
  18939. prod.inbrand = brand.brandCn;
  18940. }
  18941. };
  18942. // 打开品牌选择的模态框
  18943. $scope.selectBrand = function (prod) { //打开模态
  18944. var modalInstance = $modal.open({
  18945. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  18946. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  18947. });
  18948. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  18949. });
  18950. modalInstance.result.then(function (brand) {
  18951. prod.inbrand = brand.nameCn;
  18952. }, function (reason) {
  18953. });
  18954. };
  18955. // 点击联想词获取器件信息 带入产品分类和品牌
  18956. $scope.onAssociateCmpClick = function (cmp, prod) {
  18957. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  18958. $scope.component = data;
  18959. prod.prodCode = data.code;
  18960. prod.prodTitle = data.kind.nameCn;
  18961. prod.inbrand = data.brand.nameCn;
  18962. }, function (res) {
  18963. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  18964. })
  18965. };
  18966. //联想词end
  18967. // 导入商品信息
  18968. $scope.uplodaByBatch = function () {
  18969. var modalInstance = $modal.open({
  18970. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  18971. controller: 'PurcInquiryUploadCtrl',
  18972. size: 'lg',
  18973. resolve: {}
  18974. });
  18975. modalInstance.result.then(function (data) {
  18976. angular.forEach(data, function (prod) {
  18977. $scope.inquiry.inquiryItems.push(prod);
  18978. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  18979. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  18980. $scope.inquiry.inquiryItems.splice(i, 1);
  18981. }
  18982. }
  18983. })
  18984. }, function () {
  18985. });
  18986. }
  18987. //增加商品
  18988. $scope.add = function () {
  18989. $scope.inquiry.inquiryItems.push(
  18990. {
  18991. prodCode: null,
  18992. prodTitle: null,
  18993. unit: 'PCS',
  18994. ibrand: null,
  18995. currency: 'RMB',
  18996. toDate: null
  18997. });
  18998. };
  18999. //删除商品
  19000. $scope.del = function (index) {
  19001. $scope.inquiry.inquiryItems.splice(index, 1);
  19002. };
  19003. // 搜索结果询价
  19004. if ($rootScope.prodId) {
  19005. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  19006. prod.prodCode = data.code;
  19007. prod.prodTitle = data.title;
  19008. prod.spec = data.spec;
  19009. prod.unit = data.unit;
  19010. prod.productId = data.id;
  19011. prod.inbrand = data.brand;
  19012. $scope.inquiry.inquiryItems.push(prod);
  19013. $rootScope.prodId = null;// 清除掉prodId
  19014. }, function (response) {
  19015. });
  19016. }
  19017. $scope.check = function (product) {
  19018. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19019. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19020. $scope.inquiry.inquiryItems.splice(i, 1);
  19021. }
  19022. }
  19023. $scope.inquiry.inquiryItems.push({
  19024. prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  19025. currency: null, toDate: null, productId: product.id, inbrand: product.brand
  19026. });
  19027. }
  19028. $scope.getMinDate = function (item) {
  19029. return $filter('date')(new Date, 'yyyy-MM-dd');
  19030. };
  19031. $scope.openDatePicker = function ($event, openParam, index) {
  19032. $event.preventDefault();
  19033. $event.stopPropagation();
  19034. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  19035. };
  19036. $scope.openEndDatePicker = function ($event, item, openParam) {
  19037. $event.preventDefault();
  19038. $event.stopPropagation();
  19039. item[openParam] = !item[openParam];
  19040. };
  19041. $scope.ifrepeat = false;
  19042. // 保存并提交
  19043. $scope.submit = function () {
  19044. $scope.loading = true;
  19045. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19046. $scope.item = $scope.inquiry.inquiryItems[i];
  19047. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  19048. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  19049. if (i != j) {
  19050. if ($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  19051. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  19052. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  19053. $scope.ifrepeat = true;
  19054. }
  19055. }
  19056. }
  19057. }
  19058. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  19059. $scope.vendors = [];
  19060. $scope.vendors.push({
  19061. enName: $scope.vendor.enName,
  19062. enuu: $scope.vendor.uu,
  19063. currency: $scope.vendor.currency,
  19064. rate: $scope.vendor.rate
  19065. });
  19066. if (!$scope.ifrepeat) {
  19067. $upload.upload({
  19068. url: 'purc/inquiry/submit/withVendor',
  19069. file: file,
  19070. method: 'POST',
  19071. data: {
  19072. inquiry: $scope.inquiry,
  19073. contacts: $scope.vendors
  19074. },
  19075. }).success(function (data) {
  19076. if (data.success) {
  19077. $scope.loading = false;
  19078. toaster.pop('success', '提示', data.success);
  19079. $timeout(function () {
  19080. window.location.hash = "#/purc/purchaseinquiry";
  19081. }, 500);
  19082. }
  19083. if (data.error) {
  19084. $scope.loading = false;
  19085. toaster.pop('error', '提示', data.error);
  19086. }
  19087. }).error(function (data) {
  19088. $scope.loadingShow = false;
  19089. toaster.pop('error', '操作失败', data.error);
  19090. });
  19091. } else {
  19092. $scope.loading = false;
  19093. toaster.pop('error', '提示', '存在条件相同的物料');
  19094. }
  19095. }
  19096. }]);
  19097. // 企业圈查询收到待处理的数目
  19098. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', '$modal', 'InvitationRecord', 'toaster', function ($scope, AddPartnerMyRequest, $modal, InvitationRecord, toaster) {
  19099. AddPartnerMyRequest.requestAmount({}, function (data) {
  19100. $scope.requestTodo = data;
  19101. });
  19102. /**
  19103. * 邀请注册商务平台
  19104. */
  19105. $scope.invite = function () {
  19106. var modalInstance = $modal.open({
  19107. animation: true,
  19108. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  19109. controller: 'InviteCtrl',
  19110. resolve: {
  19111. enname: function () {
  19112. return null
  19113. }
  19114. }
  19115. });
  19116. modalInstance.result.then(function (data) {
  19117. InvitationRecord.invite({formStore: data}, {}, function (data) {
  19118. if (data.success) {
  19119. toaster.pop('success', '提示', data.success);
  19120. $scope.tableParams.reload();
  19121. }
  19122. if (data.error) {
  19123. toaster.pop('error', '提示', data.error);
  19124. }
  19125. }, function (response) {
  19126. toaster.pop('error', '提示', response.data);
  19127. });
  19128. });
  19129. }
  19130. }]);
  19131. // 当前企业所有的物料信息
  19132. app.controller('ProductAllCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', 'ProductAllNewest', '$rootScope', 'prodUser', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, ProductAllNewest, $rootScope, prodUser) {
  19133. BaseService.scrollBackToTop();
  19134. $rootScope.ids = [];// 用来记录已经选择的物料
  19135. $scope.active = 'all';
  19136. $scope.agreedText = '全部';
  19137. $scope.dateZoneText = '一个月内';
  19138. $scope.condition = {dateZone: 1};
  19139. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19140. $scope.changeAgreed = function (agreed) {
  19141. $scope.condition.agreed = agreed;
  19142. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19143. $scope.condition.$agreedOpen = false;
  19144. };
  19145. $scope.changeDateZone = function (zone) {
  19146. $scope.condition.dateZone = zone;
  19147. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19148. $scope.condition.$dateZoneOpen = false;
  19149. getDateCondition(zone, $scope.condition);
  19150. $scope.tableParams.reload();
  19151. };
  19152. $scope.setActive = function (state) {
  19153. if ($scope.active != state) {
  19154. $scope.active = state;
  19155. if ($scope.tableParams.page() == 1)
  19156. $scope.tableParams.reload();
  19157. else
  19158. $scope.tableParams.page(1);
  19159. }
  19160. };
  19161. $scope.searchMethod = false;
  19162. var getService = function () {
  19163. return $scope.searchMethod ? ProductAll : ProductAllNewest;
  19164. };
  19165. $scope.tableParams = new ngTableParams({
  19166. page: 1,
  19167. count: 20,
  19168. sorting: {
  19169. standard: 'desc',
  19170. id: 'desc',
  19171. }
  19172. }, {
  19173. total: 0,
  19174. counts: [5, 10, 25, 50],
  19175. getData: function ($defer, params) {
  19176. $scope.loading = true;
  19177. var pageParams = params.url();
  19178. pageParams.keyword = $scope.keyword;
  19179. pageParams.searchFilter = $scope.searchFilter;
  19180. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19181. $scope.loading = false;
  19182. if (page) {
  19183. params.total(page.totalElement);
  19184. $defer.resolve(page.content);
  19185. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19186. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19187. $scope.checkall = true;
  19188. if(page.content.length <= 2) {
  19189. $scope.checkall = false;
  19190. } else {
  19191. angular.forEach(page.content, function (prod) {
  19192. if ($rootScope.ids.indexOf(prod.id) > -1) {
  19193. prod.$selected = true;
  19194. } else {
  19195. $scope.checkall = false;
  19196. }
  19197. });
  19198. }
  19199. $scope.checkboxes = {
  19200. checked: $scope.checkall
  19201. };
  19202. }
  19203. }, function (response) {
  19204. $scope.loading = false;
  19205. toaster.pop('error', '数据加载失败', response.data);
  19206. });
  19207. }
  19208. });
  19209. // 搜索框回车
  19210. $scope.onSearch = function (keyword) {
  19211. // 每次搜索重置获取数据方法
  19212. $scope.searchMethod = false;
  19213. if(keyword != null && keyword != '') {
  19214. $scope.searchMethod = true;
  19215. }
  19216. $scope.tableParams.page(1);
  19217. $scope.tableParams.reload();
  19218. };
  19219. // 开启销售
  19220. $scope.unlock = function (id) {
  19221. $scope.loading = true;
  19222. Products.unlock({id: id}, {}, function (data) {
  19223. $scope.loading = false;
  19224. toaster.pop('success', '提示', '操作成功');
  19225. $scope.tableParams.reload();
  19226. }, function (response) {
  19227. toaster.pop('error', '提示', response.data);
  19228. })
  19229. }
  19230. // 关闭销售
  19231. $scope.lock = function (id) {
  19232. $scope.loading = true;
  19233. Products.lock({id: id}, {}, function (data) {
  19234. $scope.loading = false;
  19235. toaster.pop('success', '提示', '操作成功');
  19236. $scope.tableParams.reload();
  19237. }, function (response) {
  19238. toaster.pop('error', '提示', response.data);
  19239. })
  19240. }
  19241. // 开启购买
  19242. $scope.unlockPurc = function (id) {
  19243. $scope.loading = true;
  19244. Products.unlockPurc({id: id}, {}, function (data) {
  19245. $scope.loading = false;
  19246. toaster.pop('success', '提示', '操作成功');
  19247. $scope.tableParams.reload();
  19248. }, function (response) {
  19249. toaster.pop('error', '提示', response.data);
  19250. })
  19251. }
  19252. // 关闭购买
  19253. $scope.lockPurc = function (id) {
  19254. $scope.loading = true;
  19255. Products.lockPurc({id: id}, {}, function (data) {
  19256. $scope.loading = false;
  19257. toaster.pop('success', '提示', '操作成功');
  19258. $scope.tableParams.reload();
  19259. }, function (response) {
  19260. toaster.pop('error', '提示', response.data);
  19261. })
  19262. }
  19263. // 一键匹配
  19264. $scope.matchall = function () {
  19265. $scope.type = "all";
  19266. $scope.loading = true;
  19267. Products.matchbytype({type: $scope.type}, {}, function (data) {
  19268. if (data.error) {
  19269. $scope.loading = false;
  19270. toaster.pop('error', '提示', data.error);
  19271. } else {
  19272. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  19273. window.location.href = "#/approvalFlow/productmatches";
  19274. }
  19275. }, function (response) {
  19276. toaster.pop('error', '提示', response.data);
  19277. });
  19278. }
  19279. $scope.checkboxes = {
  19280. checked: false
  19281. };
  19282. angular.forEach($scope.tableParams.data, function (item) {
  19283. $scope.checkboxes.checked = false;
  19284. if($rootScope.ids.in_array(item.id)) {
  19285. $rootScope.ids.remove(item.id);
  19286. $scope.checkboxes.checked = true;
  19287. }
  19288. });
  19289. // 点击勾选全部的复选框
  19290. $scope.checkAll = function () {
  19291. angular.forEach($scope.tableParams.data, function (item) {
  19292. if (!item.waiting) {
  19293. item.$selected = $scope.checkboxes.checked;
  19294. if(item.$selected) {
  19295. if(!$rootScope.ids.in_array(item.id)) {
  19296. $rootScope.ids.push(item.id);
  19297. }
  19298. } else {
  19299. if($rootScope.ids.in_array(item.id)) {
  19300. $rootScope.ids.remove(item.id);
  19301. }
  19302. }
  19303. }
  19304. });
  19305. };
  19306. // 判断数组中是否存在某个对象
  19307. Array.prototype.S = String.fromCharCode(2);
  19308. Array.prototype.in_array = function(e) {
  19309. var r = new RegExp(this.S + e + this.S);
  19310. return (r.test(this.S + this.join(this.S) + this.S));
  19311. }
  19312. // 从数组中移除某个对象
  19313. Array.prototype.remove = function(val) {
  19314. var index = this.indexOf(val);
  19315. if (index > -1) {
  19316. this.splice(index, 1);
  19317. }
  19318. };
  19319. // 点击其中一个明细的复选框
  19320. $scope.checkOne = function (product) {
  19321. var result = true;
  19322. angular.forEach($scope.tableParams.data, function (item) {
  19323. if (item.$selected != true) {
  19324. result = false;
  19325. return;
  19326. }
  19327. });
  19328. if(product.$selected) {
  19329. if(!$rootScope.ids.in_array(product.id)) {
  19330. $rootScope.ids.push(product.id);
  19331. }
  19332. } else {
  19333. if($rootScope.ids.in_array(product.id)) {
  19334. $rootScope.ids.remove(product.id);
  19335. }
  19336. }
  19337. $scope.checkboxes = {
  19338. checked: result
  19339. };
  19340. };
  19341. // 批量转入我的产品库
  19342. $scope.addtoUserByCheck = function() {
  19343. var ids = angular.copy($rootScope.ids);
  19344. if($rootScope.ids.length == 0) {
  19345. toaster.pop('error', '提示', '请先选择产品');
  19346. } else {
  19347. prodUser.coverToUserByIds({}, ids, function(data) {
  19348. toaster.pop('success', '提示', '选择' + $rootScope.ids.length + '个产品,成功转入' + data.count + '个产品');
  19349. $rootScope.ids = [];
  19350. $scope.tableParams.page(1);
  19351. $scope.tableParams.reload();
  19352. }, function(res) {
  19353. toaster.pop('error', '提示', '转入失败');
  19354. });
  19355. }
  19356. }
  19357. // 转入我的产品库
  19358. $scope.addtoUser = function(id) {
  19359. $scope.loading = true;
  19360. prodUser.coverToUser({id: id}, {}, function(data) {
  19361. $scope.loading = false;
  19362. toaster.pop('success', '提示', '转入成功');
  19363. }, function(res) {
  19364. $scope.loading = false;
  19365. toaster.pop('error', '提示', '转入失败');
  19366. });
  19367. }
  19368. }]);
  19369. // 当前企业匹配的标准物料信息
  19370. app.controller('ProductmatchesCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  19371. BaseService.scrollBackToTop();
  19372. $scope.active = 'all';
  19373. $scope.agreedText = '全部';
  19374. $scope.dateZoneText = '一个月内';
  19375. $scope.condition = {dateZone: 1};
  19376. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19377. $scope.changeAgreed = function (agreed) {
  19378. $scope.condition.agreed = agreed;
  19379. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19380. $scope.condition.$agreedOpen = false;
  19381. };
  19382. $scope.changeDateZone = function (zone) {
  19383. $scope.condition.dateZone = zone;
  19384. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19385. $scope.condition.$dateZoneOpen = false;
  19386. getDateCondition(zone, $scope.condition);
  19387. $scope.tableParams.reload();
  19388. };
  19389. $scope.setActive = function (state) {
  19390. if ($scope.active != state) {
  19391. $scope.active = state;
  19392. if ($scope.tableParams.page() == 1)
  19393. $scope.tableParams.reload();
  19394. else
  19395. $scope.tableParams.page(1);
  19396. }
  19397. };
  19398. $scope.searchMethod = false;
  19399. var getService = function () {
  19400. if ($rootScope.productMatchStatus === 'sale') {
  19401. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19402. } else if ($rootScope.productMatchStatus === 'purc') {
  19403. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19404. } else {
  19405. return $scope.searchMethod ? Products.matchResult : Products.newestMatchResult;
  19406. }
  19407. };
  19408. $scope.tableParams = new ngTableParams({
  19409. page: 1,
  19410. count: 20,
  19411. sorting: {
  19412. matchsize: 'asc',
  19413. id: 'desc'
  19414. }
  19415. }, {
  19416. total: 0,
  19417. counts: [5, 10, 25, 50],
  19418. getData: function ($defer, params) {
  19419. $scope.loading = true;
  19420. var pageParams = params.url();
  19421. pageParams.keyword = $scope.keyword;
  19422. pageParams.searchFilter = $scope.searchFilter;
  19423. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19424. if (page) {
  19425. $scope.loading = false;
  19426. params.total(page.totalElement);
  19427. $defer.resolve(page.content);
  19428. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19429. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19430. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19431. ids = [];
  19432. if (product.matchresults.length == 1) {
  19433. product.checked = $scope.checks.checked;
  19434. }
  19435. });
  19436. }
  19437. }, function (response) {
  19438. $scope.loading = false;
  19439. toaster.pop('error', '数据加载失败', response.data);
  19440. });
  19441. }
  19442. });
  19443. // 搜索框回车
  19444. $scope.onSearch = function (keyword) {
  19445. $scope.searchMethod = false;
  19446. if(keyword != null && keyword != '') {
  19447. $scope.searchMethod = true;
  19448. }
  19449. $scope.tableParams.page(1);
  19450. $scope.tableParams.reload();
  19451. };
  19452. var ids = [];
  19453. $scope.checks = {
  19454. checked: false
  19455. };
  19456. // 全选框
  19457. $scope.checkAll = function () {
  19458. ids = [];// 每次选择时先清空,防止重复
  19459. angular.forEach($scope.tableParams.data, function (product) {
  19460. if (product.matchresults.length == 1) {
  19461. product.checked = $scope.checks.checked;
  19462. }
  19463. });
  19464. };
  19465. // 单选
  19466. $scope.checkOne = function (product) {
  19467. ids = [];// 每次选择时先清空,防止重复
  19468. product.checked = !product.checked;
  19469. var result = true;
  19470. angular.forEach($scope.tableParams.data, function (item) {
  19471. if (item.$selected != true) {
  19472. result = false;
  19473. return;
  19474. }
  19475. });
  19476. $scope.checks.checked = result;
  19477. var checked = true;
  19478. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19479. if (!message.checked) {
  19480. checked = false;
  19481. }
  19482. });
  19483. $scope.checks.checked = checked;
  19484. };
  19485. $scope.product = {
  19486. checked: false
  19487. };
  19488. var checkResults = function (result) {
  19489. angular.forEach($scope.tableParams.data, function (product) {
  19490. if (product.id == result.prid) {
  19491. product.checked = false;
  19492. angular.forEach(product.matchresults, function (item) {
  19493. if (result.id == item.id) {
  19494. if (item.checked) {
  19495. product.checked = true;
  19496. return;
  19497. }
  19498. } else {
  19499. item.checked = false;
  19500. }
  19501. });
  19502. }
  19503. });
  19504. // checkProductCheck();
  19505. };
  19506. var checkProductCheck = function () {
  19507. var checked = true;
  19508. angular.forEach($scope.tableParams.data, function (product) {
  19509. if (!product.checked) {
  19510. checked = false;
  19511. }
  19512. });
  19513. $scope.product.checked = checked;
  19514. }
  19515. // 单选明细
  19516. $scope.checkItem = function (result) {
  19517. ids = [];
  19518. result.checked = !result.checked;
  19519. checkResults(result);
  19520. }
  19521. // 一键更新
  19522. $scope.updateAll = function () {
  19523. $scope.loading = true;
  19524. angular.forEach($scope.tableParams.data, function (product) {
  19525. if (product.checked) {
  19526. if (product.matchresults.length == 1) {
  19527. ids.push(product.matchresults[0].id);
  19528. }
  19529. if (product.matchresults.length > 1) {
  19530. angular.forEach(product.matchresults, function (item) {
  19531. if (item.checked) {
  19532. ids.push(item.id);
  19533. }
  19534. });
  19535. }
  19536. }
  19537. });
  19538. Products.updateall({status: $scope.checks.checked, type: 'all'}, ids, function (data) {
  19539. if (data.success) {
  19540. toaster.pop('success', '提示', data.success);
  19541. $timeout(function () {
  19542. $scope.tableParams.page(1);
  19543. $scope.tableParams.reload();
  19544. $scope.loading = false;
  19545. }, 500);
  19546. }
  19547. ids = []; // 清空ids,防止重复点击出现多余的数据
  19548. }, function (response) {
  19549. $scope.loading = false;
  19550. toaster.pop('error', '提示', response.data);
  19551. });
  19552. }
  19553. }]);
  19554. // 当前企业匹配的标准物料信息(销售)
  19555. app.controller('ProductmatchesForSaleCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  19556. BaseService.scrollBackToTop();
  19557. $scope.active = 'all';
  19558. $scope.agreedText = '全部';
  19559. $scope.dateZoneText = '一个月内';
  19560. $scope.condition = {dateZone: 1};
  19561. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19562. $scope.changeAgreed = function (agreed) {
  19563. $scope.condition.agreed = agreed;
  19564. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19565. $scope.condition.$agreedOpen = false;
  19566. };
  19567. $scope.changeDateZone = function (zone) {
  19568. $scope.condition.dateZone = zone;
  19569. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19570. $scope.condition.$dateZoneOpen = false;
  19571. getDateCondition(zone, $scope.condition);
  19572. $scope.tableParams.reload();
  19573. };
  19574. $scope.setActive = function (state) {
  19575. if ($scope.active != state) {
  19576. $scope.active = state;
  19577. if ($scope.tableParams.page() == 1)
  19578. $scope.tableParams.reload();
  19579. else
  19580. $scope.tableParams.page(1);
  19581. }
  19582. };
  19583. $scope.searchMethod = false;
  19584. var getService = function () {
  19585. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19586. };
  19587. $scope.tableParams = new ngTableParams({
  19588. page: 1,
  19589. count: 20,
  19590. sorting: {
  19591. matchsize: 'asc',
  19592. id: 'desc'
  19593. }
  19594. }, {
  19595. total: 0,
  19596. counts: [5, 10, 25, 50],
  19597. getData: function ($defer, params) {
  19598. $scope.loading = true;
  19599. var pageParams = params.url();
  19600. pageParams.keyword = $scope.keyword;
  19601. pageParams.searchFilter = $scope.searchFilter;
  19602. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19603. if (page) {
  19604. $scope.loading = false;
  19605. params.total(page.totalElement);
  19606. $defer.resolve(page.content);
  19607. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19608. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19609. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19610. ids = [];
  19611. if (product.matchresults.length == 1) {
  19612. product.checked = $scope.checks.checked;
  19613. }
  19614. });
  19615. }
  19616. }, function (response) {
  19617. $scope.loading = false;
  19618. toaster.pop('error', '数据加载失败', response.data);
  19619. });
  19620. }
  19621. });
  19622. // 搜索框回车
  19623. $scope.onSearch = function (keyword) {
  19624. $scope.searchMethod = false;
  19625. if(keyword != null && keyword != '') {
  19626. $scope.searchMethod = true;
  19627. }
  19628. $scope.tableParams.page(1);
  19629. $scope.tableParams.reload();
  19630. };
  19631. var ids = [];
  19632. $scope.checks = {
  19633. checked: false
  19634. };
  19635. // 全选框
  19636. $scope.checkAll = function () {
  19637. ids = [];// 每次选择时先清空,防止重复
  19638. angular.forEach($scope.tableParams.data, function (product) {
  19639. if (product.matchresults.length == 1) {
  19640. product.checked = $scope.checks.checked;
  19641. }
  19642. });
  19643. };
  19644. // 单选
  19645. $scope.checkOne = function (product) {
  19646. ids = [];// 每次选择时先清空,防止重复
  19647. product.checked = !product.checked;
  19648. var result = true;
  19649. angular.forEach($scope.tableParams.data, function (item) {
  19650. if (item.$selected != true) {
  19651. result = false;
  19652. return;
  19653. }
  19654. });
  19655. $scope.checks.checked = result;
  19656. var checked = true;
  19657. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19658. if (!message.checked) {
  19659. checked = false;
  19660. }
  19661. });
  19662. $scope.checks.checked = checked;
  19663. };
  19664. $scope.product = {
  19665. checked: false
  19666. };
  19667. var checkResults = function (result) {
  19668. angular.forEach($scope.tableParams.data, function (product) {
  19669. if (product.id == result.prid) {
  19670. product.checked = false;
  19671. angular.forEach(product.matchresults, function (item) {
  19672. if (result.id == item.id) {
  19673. if (item.checked) {
  19674. product.checked = true;
  19675. return;
  19676. }
  19677. } else {
  19678. item.checked = false;
  19679. }
  19680. });
  19681. }
  19682. });
  19683. // checkProductCheck();
  19684. };
  19685. var checkProductCheck = function () {
  19686. var checked = true;
  19687. angular.forEach($scope.tableParams.data, function (product) {
  19688. if (!product.checked) {
  19689. checked = false;
  19690. }
  19691. });
  19692. $scope.product.checked = checked;
  19693. }
  19694. // 单选明细
  19695. $scope.checkItem = function (result) {
  19696. ids = [];
  19697. result.checked = !result.checked;
  19698. checkResults(result);
  19699. }
  19700. // 一键更新
  19701. $scope.updateAll = function () {
  19702. $scope.loading = true;
  19703. angular.forEach($scope.tableParams.data, function (product) {
  19704. if (product.checked) {
  19705. if (product.matchresults.length == 1) {
  19706. ids.push(product.matchresults[0].id);
  19707. }
  19708. if (product.matchresults.length > 1) {
  19709. angular.forEach(product.matchresults, function (item) {
  19710. if (item.checked) {
  19711. ids.push(item.id);
  19712. }
  19713. });
  19714. }
  19715. }
  19716. });
  19717. Products.updateall({status: $scope.checks.checked, type: 'sale'}, ids, function (data) {
  19718. if (data.success) {
  19719. toaster.pop('success', '提示', data.success);
  19720. $timeout(function () {
  19721. $scope.tableParams.page(1);
  19722. $scope.tableParams.reload();
  19723. $scope.loading = false;
  19724. }, 500);
  19725. }
  19726. ids = []; // 清空ids,防止重复点击出现多余的数据
  19727. }, function (response) {
  19728. $scope.loading = true;
  19729. toaster.pop('error', '提示', response.data);
  19730. });
  19731. }
  19732. }]);
  19733. // 当前企业匹配的标准物料信息(采购)
  19734. app.controller('ProductmatchesForPurcCtrl', ['$scope', 'ProductAll', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$rootScope', 'PurcProduct', 'GetProductInfo', function ($scope, ProductAll, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $rootScope, PurcProduct, GetProductInfo) {
  19735. BaseService.scrollBackToTop();
  19736. $scope.active = 'all';
  19737. $scope.agreedText = '全部';
  19738. $scope.dateZoneText = '一个月内';
  19739. $scope.condition = {dateZone: 1};
  19740. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19741. $scope.changeAgreed = function (agreed) {
  19742. $scope.condition.agreed = agreed;
  19743. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19744. $scope.condition.$agreedOpen = false;
  19745. };
  19746. $scope.changeDateZone = function (zone) {
  19747. $scope.condition.dateZone = zone;
  19748. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19749. $scope.condition.$dateZoneOpen = false;
  19750. getDateCondition(zone, $scope.condition);
  19751. $scope.tableParams.reload();
  19752. };
  19753. $scope.setActive = function (state) {
  19754. if ($scope.active != state) {
  19755. $scope.active = state;
  19756. if ($scope.tableParams.page() == 1)
  19757. $scope.tableParams.reload();
  19758. else
  19759. $scope.tableParams.page(1);
  19760. }
  19761. };
  19762. $scope.searchMethod = false;
  19763. var getService = function () {
  19764. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19765. };
  19766. $scope.tableParams = new ngTableParams({
  19767. page: 1,
  19768. count: 20,
  19769. sorting: {
  19770. matchsize: 'asc',
  19771. id: 'desc'
  19772. }
  19773. }, {
  19774. total: 0,
  19775. counts: [5, 10, 25, 50],
  19776. getData: function ($defer, params) {
  19777. $scope.loading = true;
  19778. var pageParams = params.url();
  19779. pageParams.keyword = $scope.keyword;
  19780. pageParams.searchFilter = $scope.searchFilter;
  19781. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19782. if (page) {
  19783. $scope.loading = false;
  19784. params.total(page.totalElement);
  19785. $defer.resolve(page.content);
  19786. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19787. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19788. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19789. ids = [];
  19790. if (product.matchresults.length == 1) {
  19791. product.checked = $scope.checks.checked;
  19792. }
  19793. });
  19794. $scope.total = page.totalElement;
  19795. }
  19796. }, function (response) {
  19797. $scope.loading = false;
  19798. toaster.pop('error', '数据加载失败', response.data);
  19799. });
  19800. }
  19801. });
  19802. // 搜索框回车
  19803. $scope.onSearch = function (keyword) {
  19804. $scope.searchMethod = false;
  19805. if(keyword != null && keyword != '') {
  19806. $scope.searchMethod = true;
  19807. }
  19808. $scope.tableParams.page(1);
  19809. $scope.tableParams.reload();
  19810. };
  19811. var ids = [];
  19812. $scope.checks = {
  19813. checked: false
  19814. };
  19815. // 全选框
  19816. $scope.checkAll = function () {
  19817. ids = [];// 每次选择时先清空,防止重复
  19818. angular.forEach($scope.tableParams.data, function (product) {
  19819. if (product.matchresults.length == 1) {
  19820. product.checked = $scope.checks.checked;
  19821. }
  19822. });
  19823. };
  19824. // 单选
  19825. $scope.checkOne = function (product) {
  19826. ids = [];// 每次选择时先清空,防止重复
  19827. product.checked = !product.checked;
  19828. var result = true;
  19829. angular.forEach($scope.tableParams.data, function (item) {
  19830. if (item.$selected != true) {
  19831. result = false;
  19832. return;
  19833. }
  19834. });
  19835. $scope.checks.checked = result;
  19836. var checked = true;
  19837. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19838. if (!message.checked) {
  19839. checked = false;
  19840. }
  19841. });
  19842. $scope.checks.checked = checked;
  19843. };
  19844. $scope.product = {
  19845. checked: false
  19846. };
  19847. var checkResults = function (result) {
  19848. angular.forEach($scope.tableParams.data, function (product) {
  19849. if (product.id == result.prid) {
  19850. product.checked = false;
  19851. angular.forEach(product.matchresults, function (item) {
  19852. if (result.id == item.id) {
  19853. if (item.checked) {
  19854. product.checked = true;
  19855. return;
  19856. }
  19857. } else {
  19858. item.checked = false;
  19859. }
  19860. });
  19861. }
  19862. });
  19863. // checkProductCheck();
  19864. };
  19865. var checkProductCheck = function () {
  19866. var checked = true;
  19867. angular.forEach($scope.tableParams.data, function (product) {
  19868. if (!product.checked) {
  19869. checked = false;
  19870. }
  19871. });
  19872. $scope.product.checked = checked;
  19873. }
  19874. // 单选明细
  19875. $scope.checkItem = function (result) {
  19876. ids = [];
  19877. result.checked = !result.checked;
  19878. checkResults(result);
  19879. }
  19880. // 一键更新
  19881. $scope.updateAll = function () {
  19882. $scope.loading = true;
  19883. angular.forEach($scope.tableParams.data, function (product) {
  19884. if (product.checked) {
  19885. if (product.matchresults.length == 1) {
  19886. ids.push(product.matchresults[0].id);
  19887. }
  19888. if (product.matchresults.length > 1) {
  19889. angular.forEach(product.matchresults, function (item) {
  19890. if (item.checked) {
  19891. ids.push(item.id);
  19892. }
  19893. });
  19894. }
  19895. }
  19896. });
  19897. Products.updateall({status: $scope.checks.checked, type: 'purc'}, ids, function (data) {
  19898. if (data.success) {
  19899. toaster.pop('success', '提示', data.success);
  19900. $timeout(function () {
  19901. $scope.tableParams.page(1);
  19902. $scope.tableParams.reload();
  19903. $scope.loading = false;
  19904. }, 500);
  19905. }
  19906. ids = []; // 清空ids,防止重复点击出现多余的数据
  19907. }, function (response) {
  19908. $scope.loading = false;
  19909. toaster.pop('error', '提示', response.data);
  19910. });
  19911. }
  19912. }]);
  19913. /**
  19914. * 采购物料资料
  19915. */
  19916. app.controller('PurcProductCtrl', ['$scope', 'PurcProduct', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', 'Products', '$modal', 'GetProductInfo', '$rootScope', 'PurcProductNewest', 'AccountEnterprise', function ($scope, PurcProduct, ngTableParams, $filter, BaseService, toaster, $timeout, Products, $modal, GetProductInfo, $rootScope, PurcProductNewest, AccountEnterprise) {
  19917. BaseService.scrollBackToTop();
  19918. // 用来记录已经选择的id
  19919. $rootScope.ids = [];
  19920. var loadAccount = function () {
  19921. AccountEnterprise.get({}, function (data) {
  19922. $scope.enterprise = data;
  19923. $scope.purcStatus = $scope.enterprise.prodpurc;
  19924. });
  19925. }
  19926. loadAccount();
  19927. $scope.active = 'all';
  19928. $scope.agreedText = '全部';
  19929. $scope.dateZoneText = '一个月内';
  19930. $scope.condition = {dateZone: 1};
  19931. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19932. $scope.changeAgreed = function (agreed) {
  19933. $scope.condition.agreed = agreed;
  19934. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19935. $scope.condition.$agreedOpen = false;
  19936. };
  19937. $scope.changeDateZone = function (zone) {
  19938. $scope.condition.dateZone = zone;
  19939. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19940. $scope.condition.$dateZoneOpen = false;
  19941. getDateCondition(zone, $scope.condition);
  19942. $scope.tableParams.reload();
  19943. };
  19944. $scope.setActive = function (state) {
  19945. if ($scope.active != state) {
  19946. $scope.active = state;
  19947. if ($scope.tableParams.page() == 1)
  19948. $scope.tableParams.reload();
  19949. else
  19950. $scope.tableParams.page(1);
  19951. }
  19952. };
  19953. $scope.searchMethod = false;
  19954. var getService = function () {
  19955. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  19956. };
  19957. $scope.tableParams = new ngTableParams({
  19958. page: 1,
  19959. count: 20,
  19960. sorting: {
  19961. id: 'desc'
  19962. }
  19963. }, {
  19964. total: 0,
  19965. counts: [5, 10, 25, 50],
  19966. getData: function ($defer, params) {
  19967. $scope.loading = true;
  19968. var pageParams = params.url();
  19969. pageParams.keyword = $scope.keyword;
  19970. pageParams.searchFilter = $scope.searchFilter;
  19971. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19972. $scope.loading = false;
  19973. if (page) {
  19974. params.total(page.totalElement);
  19975. $defer.resolve(page.content);
  19976. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19977. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19978. }
  19979. }, function (response) {
  19980. $scope.loading = false;
  19981. toaster.pop('error', '数据加载失败', response.data);
  19982. });
  19983. }
  19984. });
  19985. // //设置单据已读
  19986. // var setOrdersRead = function () {
  19987. // var ids = [];
  19988. // PurcProduct.setRead({}, ids, function (message) {
  19989. // // $scope.getUnreadIds();
  19990. // });
  19991. // };
  19992. // setOrdersRead();
  19993. // 搜索框回车
  19994. $scope.onSearch = function (keyword) {
  19995. $scope.searchMethod = false;
  19996. if(keyword != null && keyword != '') {
  19997. $scope.searchMethod = true;
  19998. }
  19999. $scope.tableParams.page(1);
  20000. $scope.tableParams.reload();
  20001. };
  20002. //删除
  20003. $scope.deleteById = function (id) {
  20004. GetProductInfo.deletePurcById({}, id, function (data) {
  20005. if (data.error) {
  20006. toaster.pop("error", "提示", data.error);
  20007. } else {
  20008. toaster.pop("success", "提示", "删除成功");
  20009. $timeout(function () {
  20010. $scope.tableParams.reload();
  20011. }, 500);
  20012. }
  20013. }), function (response) {
  20014. toaster.pop("error", "删除失败", response.data);
  20015. };
  20016. }
  20017. // 一键开启关闭
  20018. $scope.toggle = function (status) {
  20019. $scope.loading = true;
  20020. Products.toggle({status: status}, {}, function (data) {
  20021. $scope.loading = false;
  20022. toaster.pop('success', '提示', '操作成功');
  20023. loadAccount();
  20024. $scope.tableParams.reload();
  20025. if ($scope.purcStatus == 0) {
  20026. $scope.purcStatus = 1;
  20027. } else {
  20028. $scope.purcStatus = 0;
  20029. }
  20030. }, function (response) {
  20031. $scope.loading = false;
  20032. toaster.pop('error', '提示', response.data);
  20033. })
  20034. }
  20035. var products = [];
  20036. $scope.checks = {
  20037. checked: false
  20038. };
  20039. // 全选框
  20040. $scope.checkAll = function () {
  20041. products = [];// 每次选择时先清空,防止重复
  20042. angular.forEach($scope.tableParams.data, function (product) {
  20043. if (product.cmpUuId == null) {
  20044. product.checked = $scope.checks.checked;
  20045. }
  20046. });
  20047. };
  20048. // 单选
  20049. $scope.checkOne = function (product) {
  20050. products = [];// 每次选择时先清空,防止重复
  20051. var result = true;
  20052. angular.forEach($scope.tableParams.data, function (item) {
  20053. if (item.$selected != true) {
  20054. result = false;
  20055. return;
  20056. }
  20057. });
  20058. $scope.checks.checked = result;
  20059. var checked = true;
  20060. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  20061. if (!message.checked) {
  20062. checked = false;
  20063. }
  20064. });
  20065. $scope.checks.checked = checked;
  20066. };
  20067. $scope.updateByBatch = function (updatetype) {
  20068. var modalInstance = $modal.open({
  20069. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  20070. controller: 'UpdateByBatchCtrl',
  20071. size: 'md',
  20072. resolve: {
  20073. updatetype: function () {
  20074. return updatetype;
  20075. },
  20076. active: function () {
  20077. return $scope.active;
  20078. },
  20079. type: function () {
  20080. return 'purchase';
  20081. }
  20082. }
  20083. });
  20084. modalInstance.result.then(function (data) {
  20085. toaster.pop('success', '提示', data.success);
  20086. $scope.tableParams.reload();
  20087. }, function () {
  20088. });
  20089. }
  20090. // 一键匹配
  20091. $scope.matchall = function () {
  20092. $scope.type = "purc";
  20093. $scope.loading = true;
  20094. PurcProduct.matchbytype({type: $scope.type}, {}, function (data) {
  20095. if (data.error) {
  20096. $scope.loading = false;
  20097. toaster.pop('error', '提示', data.error);
  20098. } else {
  20099. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  20100. window.location.href = "#/purc/productmatches";
  20101. }
  20102. }, function (response) {
  20103. $scope.loading = false;
  20104. toaster.pop('error', '提示', response.data);
  20105. });
  20106. }
  20107. // 导出
  20108. $scope.exportXls = function () {
  20109. PurcProduct.exportXls({}, {}, function (data) {
  20110. if (data.success){
  20111. window.location.href = 'purcProduct/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  20112. }
  20113. }, function (response) {
  20114. toaster.pop('error', '数据加载失败', response.data);
  20115. });
  20116. }
  20117. }]);
  20118. /**
  20119. * 采购物料批量上传
  20120. */
  20121. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  20122. BaseService.scrollBackToTop();
  20123. $scope.$watch('myFiles', function () {
  20124. if ($scope.myFiles) {
  20125. var file = $scope.myFiles[0];
  20126. $scope.fileName = file.name;
  20127. }
  20128. })
  20129. // 通过excel批量上传物料
  20130. $scope.upload = function () {
  20131. $scope.loading = true;
  20132. if ($scope.myFiles) {
  20133. var file = $scope.myFiles[0];
  20134. if (file.name) {
  20135. $scope.loading = true;
  20136. $upload.upload({
  20137. url: 'purcProduct/edit/release/excel',
  20138. file: file,
  20139. method: 'POST'
  20140. }).success(function (data) {
  20141. $scope.loading = false;
  20142. if (data.error) {
  20143. toaster.pop('error', '提示', data.error);
  20144. }
  20145. $scope.result = data;
  20146. // $scope.products = $scope.result.products;
  20147. $scope.success = $scope.result.success;
  20148. $scope.total = $scope.result.total;
  20149. $scope.alters = $scope.result.alters;
  20150. $scope.infos = $scope.result.infos;
  20151. $scope.myFiles[0] = "";
  20152. $scope.fileName = "";
  20153. }).error(function (response) {
  20154. $scope.loading = false;
  20155. toaster.pop('error', response.data || response);
  20156. });
  20157. } else {
  20158. $scope.loading = false;
  20159. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20160. }
  20161. } else {
  20162. $scope.loading = false;
  20163. }
  20164. };
  20165. // 查看范例
  20166. $scope.showImg = function () {
  20167. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  20168. box.show();
  20169. box.find('img').attr('src', src);
  20170. box.find('a').click(function () {
  20171. box.hide();
  20172. });
  20173. box.dblclick(function () {
  20174. box.hide();
  20175. });
  20176. };
  20177. // 下载模板
  20178. $scope.download = function () {
  20179. window.location.href = 'product/baseInfo/upload/template';
  20180. };
  20181. }]);
  20182. /**
  20183. * 新增物料(采购)
  20184. */
  20185. app.controller('PurcNewProdInfoCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', '$modal', 'ComponentActive', 'KindAPI', '$timeout', '$filter', 'AuthenticationService', 'BaseService', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, $modal, ComponentActive, KindAPI, $timeout, $filter, AuthenticationService, BaseService, Products) {
  20186. BaseService.scrollBackToTop();
  20187. // 录入人
  20188. AuthenticationService.getAuthentication().success(function (data) {
  20189. $scope.loading = false;
  20190. $scope.user = data;
  20191. });
  20192. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20193. $scope.prodInfo = {};
  20194. // 选择类目
  20195. $scope.selectKind = function () {
  20196. $modal.open({
  20197. animation: true,
  20198. size: 'lg',
  20199. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20200. controller: 'KindChooseCtrl',
  20201. }).result.then(function (data) {
  20202. $scope.kindId = data;
  20203. var modalInstance = $modal.open({
  20204. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20205. controller: 'FindComponentCtrl',
  20206. size: 'lg',
  20207. resolve: {
  20208. KindId: function () {
  20209. return $scope.kindId;
  20210. }
  20211. }
  20212. });
  20213. modalInstance.result.then(function (data) {
  20214. $scope.prodInfo.cmpUuId = data.uuid;
  20215. $scope.prodInfo.pcmpcode = data.code;
  20216. $scope.prodInfo.pbranden = data.brand.nameEn;
  20217. $scope.prodInfo.pbrand = data.brand.nameCn;
  20218. }, function () {
  20219. });
  20220. }, function () {
  20221. });
  20222. };
  20223. // 联想词 start
  20224. // 获取类目
  20225. $scope.getSimilarKinds = function (value) {
  20226. if (value) {
  20227. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20228. return data.map(function (item) {
  20229. return item;
  20230. });
  20231. });
  20232. }
  20233. };
  20234. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20235. $scope.prodInfo.title = kind.kindName;
  20236. }
  20237. $scope.getSimilarBrands = function (value) {
  20238. if (value) {
  20239. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20240. return data.map(function (item) {
  20241. return item;
  20242. });
  20243. });
  20244. }
  20245. }
  20246. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20247. $scope.prodInfo.brand = brand.brandName;
  20248. }
  20249. $scope.getSimilarComponents = function (value) {
  20250. if (value) {
  20251. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20252. return data.map(function (item) {
  20253. return item;
  20254. });
  20255. });
  20256. }
  20257. }
  20258. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20259. $scope.prodInfo.cmpCode = cmp.code;
  20260. }
  20261. // 联想词 end
  20262. // 删除
  20263. $scope.clearfile = function () {
  20264. $scope.myFiles = null;
  20265. $scope.previewShow = false;
  20266. }
  20267. //提交
  20268. $scope.submit = function (prodInfo) {
  20269. $scope.loading = true;
  20270. $scope.prodInfo.isPurchase = 1;
  20271. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20272. $upload.upload({
  20273. url: 'purcProduct/edit/addNewProduct',
  20274. file: file,
  20275. method: 'POST',
  20276. data: {
  20277. prodInfo: prodInfo
  20278. },
  20279. }).success(function (data) {
  20280. $scope.loading = false;
  20281. if (data.success) {
  20282. toaster.pop('success', '提示', data.success);
  20283. $timeout(function () {
  20284. //提交后跳转到详情页面,防止重复提交
  20285. window.location.href = "#/purc/prodList/" + data.id;
  20286. // window.location.href="#/purc/product";
  20287. }, 500);
  20288. }
  20289. if (data.error) {
  20290. toaster.pop('error', '提示', data.error);
  20291. $timeout(function () {
  20292. //提交后跳转到详情页面,防止重复提交
  20293. window.location.href = "#/purc/prodList/" + data.id;
  20294. // window.location.href="#/purc/product";
  20295. }, 500);
  20296. }
  20297. }).error(function (data, status, headers, config) {
  20298. $scope.loading = false;
  20299. $scope.loadingShow = false;
  20300. if (status == 403) {
  20301. toaster.pop('error', '操作失败', data);
  20302. } else {
  20303. toaster.pop('error', '操作失败', data.error);
  20304. }
  20305. });
  20306. };
  20307. $scope.previewShow = false;
  20308. $scope.pdfShow = false;
  20309. $scope.noneFileShow = true;
  20310. $scope.$watch('myFiles', function () {
  20311. if ($scope.myFiles) {
  20312. $scope.noneFileShow = false;
  20313. var file = $scope.myFiles[0];
  20314. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20315. $scope.pdfShow = true;
  20316. $scope.previewShow = false;
  20317. $scope.imgPreviewName = file.name;
  20318. } else {
  20319. if (typeof(Worker) !== "undefined") {//支持HTML5
  20320. $scope.imgPreview = getObjectURL(file);
  20321. $scope.imgPreviewName = file.name;
  20322. } else {//不支持HTML5
  20323. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20324. $scope.imgPreviewName = file.name;
  20325. }
  20326. $scope.previewShow = true;
  20327. $scope.pdfShow = false;
  20328. }
  20329. } else {
  20330. $scope.noneFileShow = true;
  20331. $scope.previewShow = false;
  20332. $scope.pdfShow = false;
  20333. }
  20334. });
  20335. //建立一个可存取到该file的url
  20336. var imgurl = null;
  20337. var getObjectURL = function (file) {
  20338. var url = null;
  20339. if (window.createObjectURL != undefined) { // basic
  20340. url = window.createObjectURL(file);
  20341. } else if (window.URL != undefined) { // mozilla(firefox)
  20342. url = window.URL.createObjectURL(file);
  20343. } else if (window.webkitURL != undefined) { // webkit or chrome
  20344. url = window.webkitURL.createObjectURL(file);
  20345. }
  20346. imgurl = url;
  20347. return url;
  20348. };
  20349. // 取消
  20350. $scope.cancel = function () {
  20351. $scope.prodInfo = angular.copy($scope.prodInfo);
  20352. };
  20353. // 查看大图
  20354. $scope.showImg = function () {
  20355. var src = imgurl, box = $('#image-box');
  20356. box.show();
  20357. box.find('img').attr('src', src);
  20358. box.find('a').click(function () {
  20359. box.hide();
  20360. });
  20361. box.dblclick(function () {
  20362. box.hide();
  20363. });
  20364. };
  20365. }]);
  20366. /**
  20367. * 物料详情(采购)
  20368. */
  20369. app.controller('PurcProdDetailCtrl', ['$scope', 'GetProductInfo', '$upload', 'ngTableParams', '$stateParams', 'toaster', 'AuthenticationService', '$filter', 'BaseService', '$modal', 'Products', function ($scope, GetProductInfo, $upload, ngTableParams, $stateParams, toaster, AuthenticationService, $filter, BaseService, $modal, Products) {
  20370. BaseService.scrollBackToTop();
  20371. // 录入人
  20372. AuthenticationService.getAuthentication().success(function (data) {
  20373. $scope.loading = false;
  20374. $scope.user = data;
  20375. });
  20376. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20377. $scope.editstatus = false;
  20378. var loadData = function () {
  20379. GetProductInfo.getPurcProduct({id: $stateParams.id}, function (data) {
  20380. if (data.attach) {
  20381. GetProductInfo.getAttach({id: data.attach.id}, function (data) {
  20382. $scope.imgPreview = data.url;
  20383. $scope.previewShow = true;
  20384. })
  20385. }
  20386. $scope.prodInfo = data;
  20387. if ($scope.prodInfo.isbusiness == 0) {
  20388. $scope.editstatus = true;
  20389. }
  20390. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  20391. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  20392. $scope.matchresults = data;
  20393. }, function (response) {
  20394. toaster.pop('error', '提示', response.data);
  20395. });
  20396. }
  20397. $scope.loading = false;
  20398. }, function (response) {
  20399. toaster.pop('error', '数据加载失败', response.data);
  20400. });
  20401. };
  20402. loadData();
  20403. // 联想词 start
  20404. // 获取类目
  20405. $scope.getSimilarKinds = function (value) {
  20406. if (value) {
  20407. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20408. return data.map(function (item) {
  20409. return item;
  20410. });
  20411. });
  20412. }
  20413. };
  20414. // 设置类目
  20415. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20416. $scope.prodInfo.kind = kind.kindName;
  20417. }
  20418. // 设置名称
  20419. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  20420. $scope.prodInfo.title = kind.kindName;
  20421. }
  20422. $scope.getSimilarBrands = function (value) {
  20423. if (value) {
  20424. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20425. return data.map(function (item) {
  20426. return item;
  20427. });
  20428. });
  20429. }
  20430. }
  20431. // 设置导入品牌
  20432. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20433. $scope.prodInfo.brand = brand.brandName;
  20434. }
  20435. // 设置标准品牌
  20436. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  20437. $scope.prodInfo.pbranden = brand.brandName;
  20438. }
  20439. $scope.getSimilarComponents = function (value) {
  20440. if (value) {
  20441. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20442. return data.map(function (item) {
  20443. return item;
  20444. });
  20445. });
  20446. }
  20447. }
  20448. // 设置标准型号
  20449. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20450. $scope.prodInfo.pcmpcode = cmp.code;
  20451. }
  20452. // 设置导入的型号
  20453. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  20454. $scope.prodInfo.cmpCode = cmp.code;
  20455. }
  20456. // 联想词 end
  20457. // 选择类目
  20458. $scope.selectKind = function (cmpcode) {
  20459. if (cmpcode == null) {
  20460. $modal.open({
  20461. animation: true,
  20462. size: 'lg',
  20463. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20464. controller: 'KindChooseCtrl',
  20465. }).result.then(function (data) {
  20466. $scope.kindId = data;
  20467. var modalInstance = $modal.open({
  20468. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20469. controller: 'FindComponentCtrl',
  20470. size: 'lg',
  20471. resolve: {
  20472. KindId: function () {
  20473. return $scope.kindId;
  20474. }
  20475. }
  20476. });
  20477. modalInstance.result.then(function (data) {
  20478. $scope.prodInfo.cmpUuId = data.uuid;
  20479. $scope.prodInfo.pcmpcode = data.code;
  20480. $scope.prodInfo.pbranden = data.brand.nameEn;
  20481. $scope.prodInfo.pbrand = data.brand.nameCn;
  20482. }, function () {
  20483. });
  20484. }, function () {
  20485. });
  20486. }
  20487. };
  20488. $scope.isShow = true;
  20489. // 更新
  20490. $scope.update = function () {
  20491. $scope.prodInfo.$editing = true;
  20492. $scope.isShow = true;
  20493. };
  20494. // 取消
  20495. $scope.cancel = function () {
  20496. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  20497. $scope.prodInfo = data;
  20498. $scope.prodInfo.$editing = false;
  20499. $scope.isShow = false;
  20500. $scope.loading = false;
  20501. });
  20502. };
  20503. // 删除
  20504. $scope.clearfile = function () {
  20505. $scope.prodInfo.attach = null;
  20506. $scope.myFiles = null;
  20507. $scope.previewShow = false;
  20508. }
  20509. //删除
  20510. $scope.deleteById = function (id) {
  20511. GetProductInfo.deletePurcById({}, id, function (data) {
  20512. if (data.error) {
  20513. toaster.pop("error", "提示", data.error);
  20514. } else {
  20515. toaster.pop("success", "提示", "删除成功");
  20516. window.location.href = "#/purc/product";
  20517. }
  20518. }, function (response) {
  20519. toaster.pop("error", "删除失败", response.data);
  20520. });
  20521. }
  20522. $scope.submit = function (prodInfo) {
  20523. $scope.prodInfo.isPurchase = 1;
  20524. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20525. $upload.upload({
  20526. url: 'purcProduct/edit/updateProdInfo',
  20527. file: file,
  20528. method: 'POST',
  20529. data: {
  20530. prodInfo: $scope.prodInfo
  20531. },
  20532. }).success(function (data) {
  20533. if (data.success) {
  20534. toaster.pop('success', '提示', data.success);
  20535. loadData();
  20536. // window.location.href="#/sale/prodList";
  20537. }
  20538. if (data.error) {
  20539. toaster.pop('error', '提示', data.error);
  20540. }
  20541. }).error(function (data, status) {
  20542. $scope.loadingShow = false;
  20543. if (status == 403) {
  20544. toaster.pop('error', '操作失败', data);
  20545. } else {
  20546. toaster.pop('error', '操作失败', data.error);
  20547. }
  20548. });
  20549. }
  20550. $scope.previewShow = false;
  20551. $scope.pdfShow = false;
  20552. $scope.noneFileShow = true;
  20553. $scope.$watch('myFiles', function () {
  20554. if ($scope.myFiles) {
  20555. $scope.noneFileShow = false;
  20556. var file = $scope.myFiles[0];
  20557. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20558. $scope.pdfShow = true;
  20559. $scope.previewShow = false;
  20560. $scope.imgPreviewName = file.name;
  20561. } else {
  20562. if (typeof(Worker) !== "undefined") {//支持HTML5
  20563. $scope.imgPreview = getObjectURL(file);
  20564. $scope.imgPreviewName = file.name;
  20565. } else {//不支持HTML5
  20566. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20567. $scope.imgPreviewName = file.name;
  20568. }
  20569. $scope.previewShow = true;
  20570. $scope.pdfShow = false;
  20571. }
  20572. } else {
  20573. $scope.noneFileShow = true;
  20574. $scope.previewShow = false;
  20575. $scope.pdfShow = false;
  20576. }
  20577. });
  20578. //建立一个可存取到该file的url
  20579. var imgurl = null;
  20580. var getObjectURL = function (file) {
  20581. var url = null;
  20582. if (window.createObjectURL != undefined) { // basic
  20583. url = window.createObjectURL(file);
  20584. } else if (window.URL != undefined) { // mozilla(firefox)
  20585. url = window.URL.createObjectURL(file);
  20586. } else if (window.webkitURL != undefined) { // webkit or chrome
  20587. url = window.webkitURL.createObjectURL(file);
  20588. }
  20589. imgurl = url;
  20590. return url;
  20591. };
  20592. // 查看范例
  20593. $scope.showImg = function () {
  20594. if ($scope.prodInfo.attach) {
  20595. GetProductInfo.getAttach({id: $scope.prodInfo.attach.id}, function (data) {
  20596. var src = data.url, box = $('#image-box');
  20597. box.show();
  20598. box.find('img').attr('src', src);
  20599. box.find('a').click(function () {
  20600. box.hide();
  20601. });
  20602. box.dblclick(function () {
  20603. box.hide();
  20604. });
  20605. })
  20606. } else if (imgurl != null) {
  20607. var src = imgurl, box = $('#image-box');
  20608. box.show();
  20609. box.find('img').attr('src', src);
  20610. box.find('a').click(function () {
  20611. box.hide();
  20612. });
  20613. box.dblclick(function () {
  20614. box.hide();
  20615. });
  20616. }
  20617. };
  20618. }]);
  20619. // 供应商绩效考核
  20620. app.controller('VendorPerformanceAssessCtrl', ['$scope', 'VendorPerformanceAssessService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorPerformanceAssessService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  20621. BaseService.scrollBackToTop();
  20622. $scope.vendorPerformanceAssessParams = new ngTableParams({
  20623. page: 1,
  20624. count: 20
  20625. }, {
  20626. total: 0,
  20627. counts: [5, 10, 25, 50],
  20628. getData: function ($defer, params) {
  20629. $scope.loading = true;
  20630. var pageParams = params.url();
  20631. pageParams.keyword = $scope.keyword;
  20632. VendorPerformanceAssessService.get(BaseService.parseParams(pageParams), function (page) {
  20633. $scope.loading = false;
  20634. if (page) {
  20635. params.total(page.totalElement);
  20636. $defer.resolve(page.content);
  20637. $scope.keywordXls = pageParams.keyword;
  20638. }
  20639. $scope.totalCount = page.totalElement;
  20640. }, function (response) {
  20641. $scope.loading = false;
  20642. toaster.pop('error', '数据加载失败', response.data);
  20643. });
  20644. }
  20645. });
  20646. //设置消息已读
  20647. var setOrdersRead = function () {
  20648. var sourceId = [];
  20649. VendorPerformanceAssessService.setRead({}, sourceId, function (message) {
  20650. // $scope.getUnreadIds();
  20651. });
  20652. };
  20653. setOrdersRead();
  20654. // 搜索框回车
  20655. $scope.onSearch = function (keyword) {
  20656. $scope.vendorPerformanceAssessParams.page(1);
  20657. $scope.vendorPerformanceAssessParams.reload();
  20658. $scope.tip = keyword;
  20659. };
  20660. // 查看详情
  20661. $scope.viewDetail = function (id) {
  20662. window.location.hash = "#/sale/vendorPerformanceAssess/" + id;
  20663. }
  20664. }]);
  20665. // 客户详情
  20666. app.controller('VendorPerformanceAssessDetailCtrl', ['$scope', 'toaster', '$stateParams', 'VendorPerformanceAssessService', '$modal', 'ngTableParams', 'BaseService', '$rootScope', 'AuthenticationService', function ($scope, toaster, $stateParams, VendorPerformanceAssessService, $modal, ngTableParams, BaseService, $rootScope, AuthenticationService) {
  20667. BaseService.scrollBackToTop();
  20668. var loadData = function () {
  20669. VendorPerformanceAssessService.getDetail({id: $stateParams.id}, {}, function (data) {
  20670. $scope.vendorPerformanceAssess = data;
  20671. }, function (response) {
  20672. $scope.loading = false;
  20673. toaster.pop('error', '数据加载失败', response.data);
  20674. });
  20675. };
  20676. loadData();
  20677. }]);
  20678. /**
  20679. * 个人产品库
  20680. */
  20681. app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', '$rootScope', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal, $rootScope) {
  20682. BaseService.scrollBackToTop();
  20683. $rootScope.ids = [];// 每次加载先清空数据
  20684. $scope.searchMethod = false;
  20685. var getService = function () {
  20686. return $scope.searchMethod ? prodUser.getInfo : prodUser.info;
  20687. };
  20688. $scope.tableParams = new ngTableParams({ // ng-Table参数
  20689. page: 1,
  20690. count: 20,
  20691. sorting: {
  20692. 'date': 'desc',
  20693. 'id': 'desc'
  20694. }
  20695. }, {
  20696. total: 0,
  20697. counts: [],
  20698. getData: function ($defer, params) { // 获取数据的方法
  20699. $scope.loading = true;
  20700. var pageParams = params.url();
  20701. pageParams.keyword = $scope.keyword;
  20702. $scope.tip = $scope.keyword;
  20703. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  20704. $scope.loading = false;
  20705. if (page) {
  20706. params.total(page.totalElement);
  20707. $defer.resolve(page.content);
  20708. $scope.checkall = true;
  20709. if(page.content.length <= 2) {
  20710. $scope.checkall = false;
  20711. } else {
  20712. angular.forEach(page.content, function (prod) {
  20713. if ($rootScope.ids.indexOf(prod.id) > -1) {
  20714. prod.$selected = true;
  20715. } else {
  20716. $scope.checkall = false;
  20717. }
  20718. });
  20719. }
  20720. $scope.checkboxes = {
  20721. checked: $scope.checkall
  20722. };
  20723. }
  20724. }, function (response) {
  20725. $scope.loading = false;
  20726. toaster.pop('error', '数据加载失败', response.data);
  20727. });
  20728. }
  20729. });
  20730. // 搜索框回车
  20731. $scope.onSearch = function (keyword) {
  20732. // 每次搜索重置获取数据方法
  20733. $scope.searchMethod = false;
  20734. if(keyword != null && keyword != '') {
  20735. $scope.searchMethod = true;
  20736. $scope.tip = keyword;
  20737. }
  20738. $scope.tableParams.page(1);
  20739. $scope.tableParams.reload();
  20740. };
  20741. // 新增产品信息
  20742. $scope.addProduct = function() {
  20743. $modal.open({
  20744. animation: true,
  20745. size: 'lg',
  20746. templateUrl: 'static/tpl/index/approvalFlow/modal/userprod_new_modal.html',
  20747. controller: 'UserProductNewCtrl',
  20748. }).result.then(function (data) {
  20749. $scope.tableParams.page(1);
  20750. $scope.tableParams.reload();
  20751. }, function () {
  20752. });
  20753. }
  20754. // 导入商品信息
  20755. $scope.uploadByBatch = function () {
  20756. var modalInstance = $modal.open({
  20757. templateUrl: 'static/tpl/index/approvalFlow/modal/uplodaByBatch.html',
  20758. controller: 'UserProdUploadCtrl',
  20759. backdrop: 'static',
  20760. keyboard: false,
  20761. size: 'lg',
  20762. resolve: {}
  20763. });
  20764. modalInstance.result.then(function (data) {
  20765. $scope.tableParams.page(1);
  20766. $scope.tableParams.reload();
  20767. }, function () {
  20768. });
  20769. }
  20770. // 删除
  20771. $scope.deleteById = function(id) {
  20772. prodUser.deleteById({}, id, function(data) {
  20773. toaster.pop('success', '提示', '删除成功');
  20774. $scope.tableParams.page(1);
  20775. $scope.tableParams.reload();
  20776. }, function(res) {
  20777. toaster.pop('error', '提示', '删除失败');
  20778. });
  20779. }
  20780. $scope.checkboxes = {
  20781. checked: false
  20782. };
  20783. angular.forEach($scope.tableParams.data, function (item) {
  20784. $scope.checkboxes.checked = false;
  20785. if($rootScope.ids.in_array(item.id)) {
  20786. $rootScope.ids.remove(item.id);
  20787. $scope.checkboxes.checked = true;
  20788. }
  20789. });
  20790. // 点击勾选全部的复选框
  20791. $scope.checkAll = function () {
  20792. angular.forEach($scope.tableParams.data, function (item) {
  20793. item.$selected = $scope.checkboxes.checked;
  20794. if(item.$selected) {
  20795. if(!$rootScope.ids.in_array(item.id)) {
  20796. $rootScope.ids.push(item.id);
  20797. }
  20798. } else {
  20799. if($rootScope.ids.in_array(item.id)) {
  20800. $rootScope.ids.remove(item.id);
  20801. }
  20802. }
  20803. });
  20804. };
  20805. // 判断数组中是否存在某个对象
  20806. Array.prototype.S = String.fromCharCode(2);
  20807. Array.prototype.in_array = function(e) {
  20808. var r = new RegExp(this.S + e + this.S);
  20809. return (r.test(this.S + this.join(this.S) + this.S));
  20810. }
  20811. // 从数组中移除某个对象
  20812. Array.prototype.remove = function(val) {
  20813. var index = this.indexOf(val);
  20814. if (index > -1) {
  20815. this.splice(index, 1);
  20816. }
  20817. };
  20818. // 点击其中一个明细的复选框
  20819. $scope.checkOne = function (product) {
  20820. var result = true;
  20821. angular.forEach($scope.tableParams.data, function (item) {
  20822. if (item.$selected != true) {
  20823. result = false;
  20824. return;
  20825. }
  20826. });
  20827. if(product.$selected) {
  20828. if(!$rootScope.ids.in_array(product.id)) {
  20829. $rootScope.ids.push(product.id);
  20830. }
  20831. } else {
  20832. if($rootScope.ids.in_array(product.id)) {
  20833. $rootScope.ids.remove(product.id);
  20834. }
  20835. }
  20836. $scope.checkboxes = {
  20837. checked: result
  20838. };
  20839. };
  20840. // 批量删除
  20841. $scope.deleteByBatch = function() {
  20842. var ids = angular.toJson($rootScope.ids);
  20843. if($rootScope.ids.length > 0) {
  20844. prodUser.deleteByBatch({ids: ids}, {}, function(data) {
  20845. toaster.pop('success', '提示', '成功移除' + $rootScope.ids.length + '个产品');
  20846. $rootScope.ids = [];
  20847. $scope.tableParams.page(1);
  20848. $scope.tableParams.reload();
  20849. }, function(res) {
  20850. toaster.pop('error', '提示', '移除失败');
  20851. });
  20852. } else {
  20853. toaster.pop('error', '提示', '请先选择产品');
  20854. }
  20855. }
  20856. }]);
  20857. /**
  20858. * 用户产品新增产品
  20859. */
  20860. app.controller('UserProductNewCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', function($scope, toaster, prodUser, $modalInstance) {
  20861. // 确定
  20862. $scope.submit = function(prodInfo) {
  20863. prodUser.addProduct({}, prodInfo, function(data) {
  20864. if(data.success) {
  20865. toaster.pop('success', '提示', data.success);
  20866. } else if(data.info) {
  20867. toaster.pop('info', '提示', data.info);
  20868. }
  20869. $modalInstance.close('success');
  20870. }, function(res) {
  20871. toaster.pop('error', '提示', '添加失败');
  20872. });
  20873. }
  20874. // 取消
  20875. $scope.cancel = function() {
  20876. $modalInstance.dismiss();
  20877. }
  20878. }]);
  20879. /**
  20880. * 用户产品批量导入产品
  20881. */
  20882. app.controller('UserProdUploadCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', '$upload', function($scope, toaster, prodUser, $modalInstance, $upload) {
  20883. // 通过excel批量上传物料
  20884. $scope.upload = function () {
  20885. $scope.loading = true;
  20886. if ($scope.myFiles) {
  20887. var file = $scope.myFiles[0];
  20888. if (file.name) {
  20889. $upload.upload({
  20890. url: 'productuser/edit/release/excel',
  20891. file: file,
  20892. method: 'POST'
  20893. }).success(function (data) {
  20894. $scope.loading = false;
  20895. if (data.error) {
  20896. toaster.pop('error', '提示', data.error);
  20897. }
  20898. $scope.result = data;
  20899. $scope.success = $scope.result.success;
  20900. $scope.total = $scope.result.total;
  20901. $scope.myFiles[0] = "";
  20902. $scope.fileName = "";
  20903. }).error(function (response) {
  20904. $scope.loading = false;
  20905. toaster.pop('error', response.data || response);
  20906. });
  20907. } else {
  20908. $scope.loading = false;
  20909. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20910. }
  20911. } else {
  20912. $scope.loading = false;
  20913. }
  20914. };
  20915. // 取消
  20916. $scope.cancel = function() {
  20917. $modalInstance.dismiss();
  20918. }
  20919. // 下载模板
  20920. $scope.download = function () {
  20921. window.location.href = 'productuser/upload/template';
  20922. };
  20923. // 确定
  20924. $scope.enSure = function() {
  20925. $modalInstance.close('success');
  20926. }
  20927. }]);
  20928. /**
  20929. * 针对卖家,已转询价的公共询价单列表
  20930. */
  20931. app.controller('SalePubInquiryCtrl', ['$scope', '$filter', 'PubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', 'customer', 'AuthenticationService','$stateParams',
  20932. function ($scope, $filter, PubInquirySearchInfo, ngTableParams, toaster, BaseService, PubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, $modal, AccountEnterprise, $http, customer, AuthenticationService, $stateParams) {
  20933. BaseService.scrollBackToTop();
  20934. // 获取当前用户是否为普通用户
  20935. CurrentRole.isUser({}, {}, function (data) {
  20936. $scope.isUser = data.isUser;
  20937. });
  20938. /**
  20939. * active 状态说明:
  20940. * all: 客户公共询价单全部
  20941. * done: 已报价
  20942. * agreed: 已采纳
  20943. * refused: 未采纳
  20944. * invalid: 已失效
  20945. * todo**: 待报价
  20946. * todoAll: 所有公共询价
  20947. * todoRemind: 个人商机
  20948. * todoComRemind: 企业商机
  20949. */
  20950. if ($rootScope.active) {
  20951. $scope.active = $rootScope.active;
  20952. $rootScope.active = null;
  20953. } else {
  20954. $scope.active = 'todoComRemind';
  20955. }
  20956. $scope.agreedText = '全部';
  20957. $scope.dateZoneText = '最近一个月';
  20958. $scope.condition = {dateZone: 1};
  20959. /* 时间筛选初始化*/
  20960. var fromDate = new Date();
  20961. var toDate = new Date();
  20962. fromDate.setMonth(fromDate.getMonth() - 1);
  20963. fromDate.setHours(0, 0, 0, 0);
  20964. toDate.setHours(23, 59, 59, 999);
  20965. $scope.condition.dateFrom = fromDate;
  20966. $scope.condition.dateTo = toDate;
  20967. $scope.changeAgreed = function (agreed) {
  20968. $scope.condition.agreed = agreed;
  20969. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  20970. $scope.condition.$agreedOpen = false;
  20971. };
  20972. $scope.changeDateZone = function (zone) {
  20973. $scope.condition.dateZone = zone;
  20974. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  20975. $scope.condition.$dateZoneOpen = false;
  20976. getDateCondition(zone, $scope.condition);
  20977. $scope.tableParams.page(1);
  20978. $scope.tableParams.reload();
  20979. };
  20980. $scope.setActive = function (state) {
  20981. if ($scope.active != state) {
  20982. $scope.active = state;
  20983. if ($scope.tableParams.page() == 1)
  20984. $scope.tableParams.reload();
  20985. else
  20986. $scope.tableParams.page(1);
  20987. }
  20988. };
  20989. $scope.url = null;
  20990. $scope.tableParams = new ngTableParams({
  20991. page: 1,
  20992. count: 20,
  20993. sorting: {
  20994. 'inquiry.date': 'desc',
  20995. 'inquiry.enterprise.enName': 'asc',
  20996. 'inquiry.code': 'asc'
  20997. }
  20998. }, {
  20999. total: 0,
  21000. counts: [5, 10, 25, 50],
  21001. getData: function ($defer, params) {
  21002. $scope.loading = true;
  21003. var pageParams = params.url();
  21004. pageParams.searchFilter = { // 筛选条件
  21005. keyword: $scope.keyword,
  21006. fromDate: getDateTime($scope.condition.dateFrom),
  21007. endDate: getDateTime($scope.condition.dateTo)
  21008. };
  21009. if ($scope.active == 'overdue') {
  21010. $scope.active = 'end';
  21011. }
  21012. AccountEnterprise.get({}, function(data) {
  21013. $scope.currentEn = data;
  21014. publicInquiry.getUrl({}, function(data) {
  21015. var url = data.url;
  21016. $scope.url = url;
  21017. if ($scope.active == 'todoComRemind') {// 企业商机
  21018. AuthenticationService.getAuthentication().success(function (data) {
  21019. $scope.loading = false;
  21020. $scope.thisUser = data;
  21021. $http({
  21022. method: 'get',
  21023. dataType: 'json',
  21024. url: url + '/inquiry/sale/enremind',
  21025. params: {
  21026. pageNumber: pageParams.page,
  21027. pageSize: pageParams.count,
  21028. useruu: $scope.thisUser.userUU,
  21029. enuu: $scope.currentEn.uu,
  21030. keyword: $scope.keyword,
  21031. fromDate: getDateTime($scope.condition.dateFrom),
  21032. endDate: getDateTime($scope.condition.dateTo),
  21033. enableOffer: 1
  21034. }
  21035. }).success(function (response) {
  21036. $scope.loading = false;
  21037. if (response) {
  21038. params.total(response.totalElements);
  21039. $defer.resolve(response.content);
  21040. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  21041. }
  21042. }).error(function (err) {
  21043. $scope.loading = false;
  21044. toaster.pop('error', '数据加载失败', err);
  21045. });
  21046. });
  21047. } else if ($scope.active == 'todoRemind') {// 推荐报价信息
  21048. AuthenticationService.getAuthentication().success(function (data) {
  21049. $scope.loading = false;
  21050. $scope.thisUser = data;
  21051. $http({
  21052. method: 'get',
  21053. dataType: 'json',
  21054. url: url + '/inquiry/sale/remind',
  21055. params: {
  21056. pageNumber: pageParams.page,
  21057. pageSize: pageParams.count,
  21058. useruu: $scope.thisUser.userUU,
  21059. enuu: $scope.currentEn.uu,
  21060. enableOffer: 1,
  21061. keyword: $scope.keyword,
  21062. fromDate: getDateTime($scope.condition.dateFrom),
  21063. endDate: getDateTime($scope.condition.dateTo)
  21064. }
  21065. }).success(function (response) {
  21066. $scope.loading = false;
  21067. if (response) {
  21068. params.total(response.totalElements);
  21069. $defer.resolve(response.content);
  21070. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  21071. }
  21072. }).error(function (err) {
  21073. $scope.loading = false;
  21074. toaster.pop('error', '数据加载失败', err);
  21075. });
  21076. });
  21077. } else if ($scope.active == 'todoAll') {// 全部
  21078. $http({
  21079. method: 'get',
  21080. dataType: 'json',
  21081. url: url + '/inquiry/public',
  21082. params: {pageNumber: pageParams.page, pageSize: pageParams.count, enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21083. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo), distribute: $scope.distribute, remind: $scope.remind}
  21084. }).success(function (response) {
  21085. $scope.loading = false;
  21086. if (response) {
  21087. params.total(response.totalElements);
  21088. $defer.resolve(response.content);
  21089. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  21090. }
  21091. }).error(function (err) {
  21092. $scope.loading = false;
  21093. toaster.pop('error', '数据加载失败', err);
  21094. });
  21095. } else {
  21096. var filter = {vendUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21097. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21098. $http({
  21099. method: 'get',
  21100. dataType: 'json',
  21101. url: url + '/inquiry/public/quotation/list',
  21102. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21103. }).success(function (response) {
  21104. $scope.loading = false;
  21105. if (response) {
  21106. params.total(response.totalElements);
  21107. $defer.resolve(response.content);
  21108. }
  21109. }).error(function (err) {
  21110. $scope.loading = false;
  21111. toaster.pop('error', '数据加载失败', err);
  21112. });
  21113. }
  21114. });
  21115. });
  21116. }
  21117. });
  21118. $scope.getMinDate = function (item) {
  21119. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21120. };
  21121. // 搜索框回车
  21122. $scope.onSearch = function (keyword) {
  21123. // 每次搜索重置获取数据方法
  21124. $scope.searchMethod = false;
  21125. if(keyword != null && keyword != '') {
  21126. $scope.searchMethod = true;
  21127. }
  21128. $scope.tableParams.page(1);
  21129. $scope.tableParams.reload();
  21130. };
  21131. // 取消
  21132. $scope.cancel = function () {
  21133. $scope.tableParams.reload();
  21134. }
  21135. // 导出
  21136. $scope.exportXls = function () {
  21137. PurcInquiry.exportXls({}, {}, function (data) {
  21138. if (data.success) {
  21139. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21140. }
  21141. }, function (response) {
  21142. toaster.pop('error', '数据加载失败', response.data);
  21143. })
  21144. }
  21145. $scope.isOverDue = function (date) {
  21146. if (date) {
  21147. var ndate = new Date();
  21148. ndate.setHours(23, 59, 59 ,999);
  21149. ndate.setDate(ndate.getDate());
  21150. var timestamp = Date.parse(ndate);
  21151. if (date > timestamp) {
  21152. return true;
  21153. } else {
  21154. return false;
  21155. }
  21156. } else {
  21157. return true;
  21158. }
  21159. }
  21160. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  21161. customer.distribute({}, function(data) {
  21162. $scope.customer = data;
  21163. });
  21164. $scope.toDetail = function (item) {
  21165. if (item.quoted == 0) {
  21166. window.location.hash = '#/baseInfo/inquiryList/' + item.id;
  21167. } else {
  21168. window.open("#/sale/pubinquiry/" + item.quteId);
  21169. }
  21170. };
  21171. // 转客户询价
  21172. $scope.qute = function (remind) {
  21173. $http({
  21174. method: 'get',
  21175. dataType: 'json',
  21176. url: $scope.url + '/inquiry/sale/quote',
  21177. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  21178. }).success(function (response) {
  21179. $scope.loading = false;
  21180. if (response.inquiry != null) {
  21181. toaster.pop('error', '该单据已报价');
  21182. } else {
  21183. $http({
  21184. method: 'get',
  21185. dataType: 'json',
  21186. url: $scope.url + '/inquiry/public/findItemByItemId',
  21187. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  21188. }).success(function (response) {
  21189. var inquiryItem = response;
  21190. var modalInstance = $modal.open({
  21191. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  21192. controller: 'QuoteCtrl',
  21193. size: 'lg',
  21194. resolve: {
  21195. inquiryItem: function () {
  21196. return inquiryItem
  21197. }
  21198. }
  21199. });
  21200. modalInstance.result.then(function (data) {
  21201. $scope.tableParams.reload();
  21202. }, function () {
  21203. });
  21204. }).error(function (error) {
  21205. toaster.pop('error', '数据加载失败', error);
  21206. });
  21207. }
  21208. }).error(function (err) {
  21209. toaster.pop('error', '数据加载失败', err);
  21210. });
  21211. }
  21212. // 跳转详情
  21213. $scope.remindDetail = function(remind) {
  21214. if (remind.newId == null) {
  21215. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  21216. } else {
  21217. window.open("#/sale/pubinquiry/" + remind.newId);
  21218. }
  21219. }
  21220. // 搜索框回车
  21221. $scope.onSearch = function () {
  21222. $scope.tableParams.page(1);
  21223. $scope.tableParams.reload();
  21224. };
  21225. // 转客户询价
  21226. $scope.transtoInquiry = function (inquiryItem) {
  21227. if ($scope.currentEn.uu == inquiryItem.inquiry.enUU) {
  21228. toaster.pop('warning', '不能对自己企业报价');
  21229. } else {
  21230. var modalInstance = $modal.open({
  21231. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  21232. controller: 'QuoteCtrl',
  21233. size: 'lg',
  21234. resolve: {
  21235. inquiryItem: function () {
  21236. return inquiryItem
  21237. }
  21238. }
  21239. });
  21240. modalInstance.result.then(function (data) {
  21241. $scope.tableParams.reload();
  21242. }, function () {
  21243. });
  21244. }
  21245. }
  21246. // 跳转到我的报价列表
  21247. $scope.linkToInquiry = function () {
  21248. window.open("#/sale/pubinquiry");
  21249. }
  21250. }]);
  21251. /**
  21252. * 针对卖家,已转询价单的客户公共询价单明细
  21253. */
  21254. app.controller('SalePubInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'publicInquiry', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole, publicInquiry) {
  21255. // 获取当前用户是否为普通用户
  21256. var loadData = function () {
  21257. publicInquiry.inquiryDetail({id: $stateParams.id}, function (data) {
  21258. $scope.inquiryItem = data;
  21259. var inquiry = data.inquiry;
  21260. angular.forEach(inquiry.attachs, function (attach) {
  21261. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21262. });
  21263. $scope.inquiry = inquiry;
  21264. $scope.attach = null;
  21265. if ($scope.inquiryItem.attaches.length > 0) {
  21266. $scope.attach = $scope.inquiryItem.attaches[0];
  21267. }
  21268. }, function (response) {
  21269. $scope.loading = false;
  21270. toaster.pop('error', '', response.data);
  21271. });
  21272. };
  21273. loadData();
  21274. $scope.getMinDate = function (item) {
  21275. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21276. };
  21277. $scope.replyPrices = [];
  21278. $scope.replylapQtys = [];
  21279. $scope.replyPrices.push(true);
  21280. $scope.replylapQtys.push(true);
  21281. $scope.addStep = function (inquiryItem) {
  21282. if (inquiryItem.replies.length >= 10) {
  21283. toaster.pop('warning', '提示', '最多支持10个分段!');
  21284. } else
  21285. inquiryItem.replies.push({});
  21286. };
  21287. $scope.removeStep = function (inquiryItem, stepIndex) {
  21288. inquiryItem.replies.splice(stepIndex, 1);
  21289. };
  21290. $scope.openDatePicker = function ($event, item, openParam) {
  21291. $event.preventDefault();
  21292. $event.stopPropagation();
  21293. item[openParam] = !item[openParam];
  21294. };
  21295. $scope.getHistory = function (item) {
  21296. if (!item.history) {
  21297. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21298. item.history = data;
  21299. });
  21300. }
  21301. };
  21302. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21303. $scope.verify = function (value, type) {
  21304. var regex = /^\d+(.\d{1,6})?$/;//
  21305. switch (type) {
  21306. case 'minOrderQty':
  21307. $scope.minOrderQtyVerify = regex.test(value);
  21308. break;
  21309. case 'minPackQty':
  21310. $scope.minPackQtyVerify = regex.test(value);
  21311. break;
  21312. case 'leadtime':
  21313. $scope.leadtimeVerify = regex.test(value);
  21314. break;
  21315. default:
  21316. $scope.replyPrices[type] = regex.test(value);
  21317. break;
  21318. }
  21319. }
  21320. $scope.verifylapQty = function (value, index, inquiryItem) {
  21321. value = parseInt(value);
  21322. var regex = /^\d+(.\d{1,6})?$/;
  21323. var valid = true;
  21324. angular.forEach(inquiryItem.replies, function(reply, $index) {
  21325. if ($index < index && reply.lapQty >= value) {
  21326. valid = false;
  21327. }
  21328. });
  21329. $scope.replylapQtys[index] = regex.test(value) && valid;
  21330. };
  21331. $scope.isValid = function (item, withSteps) {
  21332. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  21333. if (!withSteps || !bool)
  21334. return bool;
  21335. angular.forEach(item.replies, function (r, i) {
  21336. $scope.verifylapQty(r.lapQty, i, item);
  21337. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  21338. });
  21339. return bool;
  21340. };
  21341. $scope.deleteAttach = function (attaches, index) {
  21342. attaches.splice(index, 1);
  21343. };
  21344. $scope.onReplyClick = function (item, withSteps) {
  21345. if (item.vendFromDate instanceof Date) {
  21346. item.vendFromDate = item.vendFromDate.getTime();
  21347. }
  21348. if (item.vendToDate instanceof Date) {
  21349. item.vendToDate = item.vendToDate.getTime();
  21350. }
  21351. if (item.vendFromDate > item.vendToDate) {
  21352. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  21353. return;
  21354. }
  21355. var replies = [];
  21356. var valid = true;
  21357. var validLapQty = 0;
  21358. angular.forEach(item.replies, function (r, i) {
  21359. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  21360. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  21361. valid = false;
  21362. validLapQty = r.lapQty;
  21363. }
  21364. if ((i > 0 ? r.lapQty : 1) || r.price)
  21365. replies.push(r);
  21366. });
  21367. item.replies = replies;
  21368. $scope.loading = true;
  21369. if (!valid) { // 不合法时给出提示
  21370. if (validLapQty) {
  21371. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  21372. } else {
  21373. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  21374. }
  21375. $scope.loading = false;
  21376. } else {
  21377. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  21378. if (withSteps) {
  21379. if(null != file) {
  21380. $upload.upload({
  21381. url: 'sale/pubInquiry/addAttach',
  21382. file: file,
  21383. method: 'POST',
  21384. data: {
  21385. item: item,
  21386. method: 'reply'
  21387. }
  21388. }).success(function (data) {
  21389. if (data.item) {
  21390. item = data.item;
  21391. }
  21392. toaster.pop('success', '提示', '报价成功');
  21393. loadData();
  21394. }).error(function () {
  21395. toaster.pop('error', '提示', '报价失败');
  21396. });
  21397. } else {
  21398. publicInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  21399. $scope.loading = false;
  21400. toaster.pop('success', '提示', '报价成功');
  21401. loadData();
  21402. }, function (response) {
  21403. $scope.loading = false;
  21404. toaster.pop('error', '询价失效', response.data);
  21405. });
  21406. }
  21407. } else {
  21408. if(null != file) {
  21409. $upload.upload({
  21410. url: 'sale/pubInquiry/addAttach',
  21411. file: file,
  21412. method: 'POST',
  21413. data: {
  21414. item: item,
  21415. method: 'save'
  21416. }
  21417. }).success(function (data) {
  21418. if (data.item) {
  21419. item = data.item;
  21420. }
  21421. toaster.pop('success', '提示', '保存成功');
  21422. loadData();
  21423. }).error(function () {
  21424. toaster.pop('error', '提示', '保存失败');
  21425. });
  21426. } else {
  21427. publicInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  21428. $scope.loading = false;
  21429. toaster.pop('info', '提示', '保存成功');
  21430. loadData();
  21431. }, function (response) {
  21432. $scope.loading = false;
  21433. toaster.pop('error', '保存失败', response.data);
  21434. });
  21435. }
  21436. }
  21437. }
  21438. };
  21439. // 取消
  21440. $scope.cancel = function () {
  21441. $scope.tableParams.reload();
  21442. }
  21443. }]);
  21444. /**
  21445. * 针对买家,已转询价的公共询价单列表
  21446. */
  21447. app.controller('PurcPubInquiryCtrl', ['$scope', '$filter', 'PurcPubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PurcPubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', 'AccountEnterprise', '$http', function ($scope, $filter, PurcPubInquirySearchInfo, ngTableParams, toaster, BaseService, PurcPubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, AccountEnterprise, $http) {
  21448. BaseService.scrollBackToTop();
  21449. // 获取当前用户是否为普通用户
  21450. CurrentRole.isUser({}, {}, function (data) {
  21451. $scope.isUser = data.isUser;
  21452. });
  21453. if ($rootScope.active) {
  21454. $scope.active = $rootScope.active;
  21455. $rootScope.active = null;
  21456. } else {
  21457. $scope.active = 'all';
  21458. }
  21459. $scope.agreedText = '全部';
  21460. $scope.dateZoneText = '最近一个月';
  21461. $scope.condition = {dateZone: 1};
  21462. /* 时间筛选初始化*/
  21463. var fromDate = new Date();
  21464. var toDate = new Date();
  21465. fromDate.setMonth(fromDate.getMonth() - 1);
  21466. fromDate.setHours(0, 0, 0, 0);
  21467. toDate.setHours(23, 59, 59, 999);
  21468. $scope.condition.dateFrom = fromDate;
  21469. $scope.condition.dateTo = toDate;
  21470. $scope.changeAgreed = function (agreed) {
  21471. $scope.condition.agreed = agreed;
  21472. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  21473. $scope.condition.$agreedOpen = false;
  21474. };
  21475. $scope.changeDateZone = function (zone) {
  21476. $scope.condition.dateZone = zone;
  21477. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21478. $scope.condition.$dateZoneOpen = false;
  21479. getDateCondition(zone, $scope.condition);
  21480. $scope.tableParams.page(1);
  21481. $scope.tableParams.reload();
  21482. };
  21483. $scope.setActive = function (state) {
  21484. if ($scope.active != state) {
  21485. $scope.active = state;
  21486. if ($scope.tableParams.page() == 1)
  21487. $scope.tableParams.reload();
  21488. else
  21489. $scope.tableParams.page(1);
  21490. }
  21491. };
  21492. $scope.searchMethod = false;
  21493. var getService = function () {
  21494. return $scope.searchMethod ? PurcPubInquirySearchInfo : PurcPubInquiryNoSearchInfo;
  21495. };
  21496. $scope.tableParams = new ngTableParams({
  21497. page: 1,
  21498. count: 20,
  21499. sorting: {
  21500. 'inquiry.date': 'desc',
  21501. 'inquiry.enterprise.enName': 'asc',
  21502. 'inquiry.code': 'asc'
  21503. }
  21504. }, {
  21505. total: 0,
  21506. counts: [5, 10, 25, 50],
  21507. getData: function ($defer, params) {
  21508. $scope.loading = true;
  21509. var pageParams = params.url();
  21510. var realActive = {};
  21511. pageParams.searchFilter = { // 筛选条件
  21512. keyword: $scope.keyword,
  21513. fromDate: getDateTime($scope.condition.dateFrom),
  21514. endDate: getDateTime($scope.condition.dateTo)
  21515. };
  21516. if ($scope.active == 'overdue') {
  21517. $scope.active = 'end';
  21518. }
  21519. AccountEnterprise.get({}, function(data) {
  21520. $scope.currentEn = data;
  21521. publicInquiry.getUrl({}, function(data) {
  21522. var url = data.url;
  21523. var filter = {enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21524. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21525. $http({
  21526. method: 'get',
  21527. dataType: 'json',
  21528. url: url + '/inquiry/public/quotation/list',
  21529. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21530. }).success(function (response) {
  21531. $scope.loading = false;
  21532. if (response) {
  21533. params.total(response.totalElements);
  21534. $defer.resolve(response.content);
  21535. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  21536. }
  21537. }).error(function (err) {
  21538. $scope.loading = false;
  21539. toaster.pop('error', '数据加载失败', err);
  21540. });
  21541. });
  21542. });
  21543. }
  21544. });
  21545. $scope.isUnread = function (id) {
  21546. for (var i in $scope.unreadCode) {
  21547. if (id == $scope.unreadCode[i]) {
  21548. return true;
  21549. }
  21550. }
  21551. };
  21552. $scope.getMinDate = function (item) {
  21553. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21554. };
  21555. $scope.replyPrices = [];
  21556. $scope.replylapQtys = [];
  21557. $scope.replyPrices.push(true);
  21558. $scope.replylapQtys.push(true);
  21559. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21560. $event.preventDefault();
  21561. $event.stopPropagation();
  21562. item[openParam] = !item[openParam];
  21563. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21564. $scope.tableParams.reload();
  21565. }
  21566. };
  21567. $scope.getHistory = function (item) {
  21568. if (!item.history) {
  21569. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21570. item.history = data;
  21571. });
  21572. }
  21573. };
  21574. // 搜索框回车
  21575. $scope.onSearch = function (keyword) {
  21576. // 每次搜索重置获取数据方法
  21577. $scope.searchMethod = false;
  21578. if(keyword != null && keyword != '') {
  21579. $scope.searchMethod = true;
  21580. }
  21581. $scope.tableParams.page(1);
  21582. $scope.tableParams.reload();
  21583. };
  21584. // 采纳
  21585. $scope.accept = function (id) {
  21586. publicInquiry.accept({id: id}, {}, function (data) {
  21587. if (data.success) {
  21588. toaster.pop('success', '提示', data.success);
  21589. $scope.tableParams.page(1);
  21590. $scope.tableParams.reload();
  21591. }
  21592. if (data.error) {
  21593. toaster.pop('error', '提示', data.error);
  21594. $scope.tableParams.page(1);
  21595. $scope.tableParams.reload();
  21596. }
  21597. }, function (response) {
  21598. toaster.pop('error', '提示', '采纳失败');
  21599. $scope.tableParams.page(1);
  21600. $scope.tableParams.reload();
  21601. })
  21602. };
  21603. // 拒绝
  21604. $scope.refuse = function (id) {
  21605. publicInquiry.refuse({id: id}, {}, function (data) {
  21606. if (data.success) {
  21607. toaster.pop('success', '提示', data.success);
  21608. $scope.tableParams.page(1);
  21609. $scope.tableParams.reload();
  21610. }
  21611. if (data.error) {
  21612. toaster.pop('error', '提示', data.error);
  21613. $scope.tableParams.page(1);
  21614. $scope.tableParams.reload();
  21615. }
  21616. }, function (response) {
  21617. toaster.pop('error', '提示', '操作失败');
  21618. $scope.tableParams.page(1);
  21619. $scope.tableParams.reload();
  21620. })
  21621. }
  21622. // 导出
  21623. $scope.exportXls = function () {
  21624. PurcInquiry.exportXls({}, {}, function (data) {
  21625. if (data.success) {
  21626. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21627. }
  21628. }, function (response) {
  21629. toaster.pop('error', '数据加载失败', response.data);
  21630. })
  21631. }
  21632. }]);
  21633. /**
  21634. * 针对买家,已转询价单的客户公共询价单明细
  21635. */
  21636. app.controller('PurcPubInquiryDetailCtrl', ['$scope', '$stateParams', 'publicInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'AccountEnterprise', '$http', function ($scope, $stateParams, publicInquiry, $filter, toaster, $upload, token, CurrentRole, AccountEnterprise, $http) {
  21637. // 获取当前用户是否为普通用户
  21638. CurrentRole.isUser({}, {}, function (data) {
  21639. $scope.isUser = data.isUser;
  21640. });
  21641. AccountEnterprise.get({}, function(data) {
  21642. $scope.currentEn = data;
  21643. publicInquiry.getUrl({}, function(data) {
  21644. var url = data.url;
  21645. $http({
  21646. method: 'get',
  21647. dataType: 'json',
  21648. url: url + '/inquiry/buyer/detail',
  21649. params: {id: $stateParams.id, enuu: $scope.currentEn.uu}
  21650. }).success(function (response) {
  21651. $scope.newinquiryItems = response;
  21652. var inquiry = response;
  21653. angular.forEach(inquiry.attachs, function (attach) {
  21654. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21655. });
  21656. $scope.inquiry = inquiry;
  21657. });
  21658. });
  21659. });
  21660. $scope.getMinDate = function (item) {
  21661. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21662. };
  21663. $scope.replyPrices = [];
  21664. $scope.replylapQtys = [];
  21665. $scope.replyPrices.push(true);
  21666. $scope.replylapQtys.push(true);
  21667. $scope.getHistory = function (item) {
  21668. if (!item.history) {
  21669. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21670. item.history = data;
  21671. });
  21672. }
  21673. };
  21674. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21675. $scope.verify = function (value, type) {
  21676. var regex = /^\d+(.\d{1,6})?$/;//
  21677. switch (type) {
  21678. case 'minOrderQty':
  21679. $scope.minOrderQtyVerify = regex.test(value);
  21680. break;
  21681. case 'minPackQty':
  21682. $scope.minPackQtyVerify = regex.test(value);
  21683. break;
  21684. case 'leadtime':
  21685. $scope.leadtimeVerify = regex.test(value);
  21686. break;
  21687. default:
  21688. $scope.replyPrices[type] = regex.test(value);
  21689. break;
  21690. }
  21691. }
  21692. // 采纳
  21693. $scope.accept = function (id) {
  21694. publicInquiry.accept({id: id}, {}, function (data) {
  21695. if (data.success) {
  21696. toaster.pop('success', '提示', data.success);
  21697. loadData();
  21698. }
  21699. if (data.error) {
  21700. toaster.pop('error', '提示', data.error);
  21701. }
  21702. }, function (response) {
  21703. toaster.pop('error', '提示', response.data);
  21704. })
  21705. };
  21706. // 拒绝
  21707. $scope.refuse = function (id) {
  21708. publicInquiry.refuse({id: id}, {}, function (data) {
  21709. if (data.success) {
  21710. toaster.pop('success', '提示', data.success);
  21711. loadData();
  21712. }
  21713. if (data.error) {
  21714. toaster.pop('error', '提示', data.error);
  21715. }
  21716. }, function (response) {
  21717. toaster.pop('error', '提示', response.data);
  21718. })
  21719. }
  21720. }]);
  21721. /**
  21722. * 公共询价模态框(供应商报价)
  21723. */
  21724. app.controller('QuoteInquiryCtrl', ['$scope', '$stateParams', 'toaster', 'inquiryItem', '$modalInstance', '$upload', function ($scope, $stateParams, toaster, inquiryItem, $modalInstance, $upload) {
  21725. $scope.inquiryItem = inquiryItem;
  21726. $scope.replyPrices = [];
  21727. $scope.replylapQtys = [];
  21728. $scope.replyPrices.push(true);
  21729. $scope.replylapQtys.push(true);
  21730. // 增加一列分段报价
  21731. $scope.addStep = function (inquiryItem) {
  21732. $scope.replyPrices.push(true);
  21733. if (inquiryItem.replies.length >= 5) {
  21734. toaster.pop('warning', '提示', '最多支持5个分段!');
  21735. } else {
  21736. inquiryItem.replies.push({});
  21737. if (inquiryItem.replies.length != 1) {
  21738. $scope.replyPrices.push(true);
  21739. $scope.replylapQtys.push(true);
  21740. }
  21741. }
  21742. };
  21743. // 删除一列分段报价
  21744. $scope.removeStep = function (inquiryItem, stepIndex) {
  21745. inquiryItem.replies.splice(stepIndex, 1);
  21746. $scope.replyPrices.splice(stepIndex, 1);
  21747. $scope.replylapQtys.splice(stepIndex, 1);
  21748. };
  21749. // 取消,关闭弹出框
  21750. $scope.cancel = function() {
  21751. $modalInstance.dismiss();
  21752. }
  21753. // 保存报价信息
  21754. $scope.save = function(inquiryItem, method) {
  21755. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  21756. $upload.upload({
  21757. url: 'pubInquiry/turnToQuotation',
  21758. file: file,
  21759. method: 'POST',
  21760. data: {
  21761. item: inquiryItem,
  21762. method: method
  21763. }
  21764. }).success(function (data) {
  21765. if (data.item) {
  21766. item = data.item;
  21767. }
  21768. $scope.loading = false;
  21769. toaster.pop('info', '提示', '报价成功');
  21770. $scope.tableParams.reload();
  21771. }).error(function (data) {
  21772. $scope.loading = false;
  21773. toaster.pop('error', '报价失败');
  21774. });
  21775. }
  21776. }]);
  21777. /**
  21778. * 首页侧边栏询价列表
  21779. */
  21780. app.controller('InquiryMessageListCtrl', ['$scope', 'publicInquiry', 'AccountEnterprise', '$http', function($scope, publicInquiry, AccountEnterprise, $http) {
  21781. AccountEnterprise.get({}, function(data) {
  21782. $scope.currentEn = data;
  21783. publicInquiry.getUrl({}, function (data) {
  21784. var url = data.url;
  21785. $http({
  21786. method: 'get',
  21787. url: url + '/inquiry/public/messageList',
  21788. params: {enuu: $scope.currentEn.uu, size: 7},
  21789. dataType: 'json'
  21790. }).success(function(data) {
  21791. $scope.message = data;
  21792. }).error(function(error) {
  21793. });
  21794. });
  21795. });
  21796. }]);
  21797. /**
  21798. * 针对卖家,询价推荐列表
  21799. */
  21800. app.controller('SaleInquiryRemindCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', 'AuthenticationService', function ($scope, $filter, ngTableParams, toaster, BaseService, publicInquiry, $modal, AccountEnterprise, $http, AuthenticationService) {
  21801. BaseService.scrollBackToTop();
  21802. $scope.agreedText = '全部';
  21803. $scope.dateZoneText = '最近一个月';
  21804. $scope.condition = {dateZone: 1};
  21805. /* 时间筛选初始化*/
  21806. var fromDate = new Date();
  21807. var toDate = new Date();
  21808. fromDate.setMonth(fromDate.getMonth() - 1);
  21809. fromDate.setHours(0, 0, 0, 0);
  21810. toDate.setHours(23, 59, 59, 999);
  21811. $scope.condition.dateFrom = fromDate;
  21812. $scope.condition.dateTo = toDate;
  21813. $scope.changeDateZone = function (zone) {
  21814. $scope.condition.dateZone = zone;
  21815. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21816. $scope.condition.$dateZoneOpen = false;
  21817. getDateCondition(zone, $scope.condition);
  21818. $scope.tableParams.page(1);
  21819. $scope.tableParams.reload();
  21820. };
  21821. $scope.tableParams = new ngTableParams({
  21822. page: 1,
  21823. count: 20,
  21824. sorting: {
  21825. 'date': 'desc'
  21826. }
  21827. }, {
  21828. total: 0,
  21829. counts: [5, 10, 25, 50],
  21830. getData: function ($defer, params) {
  21831. $scope.loading = true;
  21832. var pageParams = params.url();
  21833. var realActive = {};
  21834. pageParams.searchFilter = { // 筛选条件
  21835. keyword: $scope.keyword,
  21836. fromDate: getDateTime($scope.condition.dateFrom),
  21837. endDate: getDateTime($scope.condition.dateTo)
  21838. };
  21839. if ($scope.active == 'overdue') {
  21840. $scope.active = 'end';
  21841. }
  21842. AccountEnterprise.get({}, function(data) {
  21843. $scope.currentEn = data;
  21844. publicInquiry.getUrl({}, function(data) {
  21845. $scope.url = data.url;
  21846. AuthenticationService.getAuthentication().success(function (data) {
  21847. $scope.loading = false;
  21848. $scope.thisUser = data;
  21849. $http({
  21850. method: 'get',
  21851. dataType: 'json',
  21852. url: $scope.url + '/inquiry/sale/remind',
  21853. params: {pageNumber: pageParams.page, pageSize: pageParams.count, useruu: $scope.thisUser.userUU, enuu: $scope.currentEn.uu,
  21854. keyword: $scope.keyword, fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)}
  21855. }).success(function (response) {
  21856. $scope.loading = false;
  21857. if (response) {
  21858. params.total(response.totalElements);
  21859. $defer.resolve(response.content);
  21860. }
  21861. }).error(function (err) {
  21862. $scope.loading = false;
  21863. toaster.pop('error', '数据加载失败', err);
  21864. });
  21865. });
  21866. });
  21867. });
  21868. }
  21869. });
  21870. $scope.getMinDate = function (item) {
  21871. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21872. };
  21873. $scope.openDatePicker = function ($event, item, openParam) {
  21874. $event.preventDefault();
  21875. $event.stopPropagation();
  21876. item[openParam] = !item[openParam];
  21877. };
  21878. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21879. $event.preventDefault();
  21880. $event.stopPropagation();
  21881. item[openParam] = !item[openParam];
  21882. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21883. $scope.tableParams.reload();
  21884. }
  21885. };
  21886. // 搜索框回车
  21887. $scope.onSearch = function (keyword) {
  21888. // 每次搜索重置获取数据方法
  21889. $scope.searchMethod = false;
  21890. if(keyword != null && keyword != '') {
  21891. $scope.searchMethod = true;
  21892. }
  21893. $scope.tableParams.page(1);
  21894. $scope.tableParams.reload();
  21895. };
  21896. // 取消
  21897. $scope.cancel = function () {
  21898. $scope.tableParams.reload();
  21899. }
  21900. // 转客户询价
  21901. $scope.qute = function (remind) {
  21902. $http({
  21903. method: 'get',
  21904. dataType: 'json',
  21905. url: $scope.url + '/inquiry/sale/quote',
  21906. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  21907. }).success(function (response) {
  21908. $scope.loading = false;
  21909. if (response.inquiry != null) {
  21910. toaster.pop('error', '该单据已报价');
  21911. } else {
  21912. $http({
  21913. method: 'get',
  21914. dataType: 'json',
  21915. url: $scope.url + '/inquiry/public/findItemByItemId',
  21916. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  21917. }).success(function (response) {
  21918. var inquiryItem = response;
  21919. var modalInstance = $modal.open({
  21920. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  21921. controller: 'QuoteCtrl',
  21922. size: 'lg',
  21923. resolve: {
  21924. inquiryItem: function () {
  21925. return inquiryItem
  21926. }
  21927. }
  21928. });
  21929. modalInstance.result.then(function (data) {
  21930. $scope.tableParams.reload();
  21931. }, function () {
  21932. });
  21933. }).error(function (error) {
  21934. toaster.pop('error', '数据加载失败', error);
  21935. });
  21936. }
  21937. }).error(function (err) {
  21938. toaster.pop('error', '数据加载失败', err);
  21939. });
  21940. }
  21941. // 跳转详情
  21942. $scope.toDetail = function(remind) {
  21943. if (remind.newId == null) {
  21944. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  21945. } else {
  21946. window.open("#/sale/pubinquiry/" + remind.newId);
  21947. }
  21948. }
  21949. }]);
  21950. /**
  21951. * 采购变更单列表
  21952. *
  21953. * @author hejq
  21954. * @date 2018-06-25 17:13
  21955. */
  21956. app.controller('PurcChangeListCtrl', ['$scope', '$filter', 'change', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, change, ngTableParams, toaster, BaseService, CurrentRole) {
  21957. BaseService.scrollBackToTop();
  21958. $scope.active = 'todo';
  21959. $scope.agreedText = '全部';
  21960. $scope.dateZoneText = '一个月内';
  21961. $scope.condition = {dateZone: 1};
  21962. /* 时间筛选初始化*/
  21963. var fromDate = new Date();
  21964. var toDate = new Date();
  21965. fromDate.setMonth(fromDate.getMonth() - 1);
  21966. fromDate.setHours(0, 0, 0, 0);
  21967. toDate.setHours(23, 59, 59, 999);
  21968. $scope.condition.dateFrom = fromDate;
  21969. $scope.condition.dateTo = toDate;
  21970. $scope.changeAgreed = function (agreed) {
  21971. $scope.condition.agreed = agreed;
  21972. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  21973. $scope.condition.$agreedOpen = false;
  21974. };
  21975. $scope.changeDateZone = function (zone) {
  21976. $scope.condition.dateZone = zone;
  21977. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  21978. $scope.condition.$dateZoneOpen = false;
  21979. getDateCondition(zone, $scope.condition);
  21980. $scope.tableParams.page(1);
  21981. $scope.tableParams.reload();
  21982. };
  21983. $scope.setActive = function (state) {
  21984. if ($scope.active != state) {
  21985. $scope.active = state;
  21986. if ($scope.tableParams.page() == 1)
  21987. $scope.tableParams.reload();
  21988. else
  21989. $scope.tableParams.page(1);
  21990. }
  21991. };
  21992. var getService = function () {
  21993. return change;
  21994. };
  21995. $scope.tableParams = new ngTableParams({
  21996. page: 1,
  21997. count: 20,
  21998. sorting: {
  21999. date: 'desc'
  22000. }
  22001. }, {
  22002. total: 0,
  22003. counts: [5, 10, 25, 50],
  22004. getData: function ($defer, params) {
  22005. $scope.loading = true;
  22006. var pageParams = params.url();
  22007. pageParams.searchFilter = {
  22008. keyword: $scope.keyword,
  22009. fromDate: getDateTime($scope.condition.dateFrom),
  22010. endDate: getDateTime($scope.condition.dateTo)
  22011. };
  22012. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  22013. $scope.loading = false;
  22014. if (page) {
  22015. params.total(page.totalElement);
  22016. $defer.resolve(page.content);
  22017. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  22018. }
  22019. }, function (response) {
  22020. $scope.loading = false;
  22021. toaster.pop('error', '数据加载失败', response.data);
  22022. });
  22023. }
  22024. });
  22025. $scope.openDatePicker = function ($event, item, openParam) {
  22026. $event.preventDefault();
  22027. $event.stopPropagation();
  22028. item[openParam] = !item[openParam];
  22029. };
  22030. $scope.openFilterDatePicker = function ($event, item, openParam) {
  22031. $event.preventDefault();
  22032. $event.stopPropagation();
  22033. item[openParam] = !item[openParam];
  22034. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  22035. $scope.tableParams.reload();
  22036. }
  22037. };
  22038. // 搜索框回车
  22039. $scope.onSearch = function (keyword) {
  22040. $scope.tableParams.page(1);
  22041. $scope.tableParams.reload();
  22042. };
  22043. // 导出
  22044. $scope.exportXls = function () {
  22045. change.exportXls({}, {}, function (data) {
  22046. if (data.success){
  22047. window.location.href = 'purc/change/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  22048. }
  22049. }, function (response) {
  22050. toaster.pop('error', '数据加载失败', response.data);
  22051. });
  22052. }
  22053. }]);
  22054. /**
  22055. * 新增采购变更单
  22056. *
  22057. * @author hejq
  22058. * @date 2018-06-25 16:38
  22059. */
  22060. app.controller('PurcChangeNewCtrl', ['$scope', 'toaster', 'BaseService', 'AuthenticationService', '$modal', '$filter', 'change',
  22061. function ($scope, toaster, BaseService, AuthenticationService, $modal, $filter, change) {
  22062. // 获取登录人员信息
  22063. AuthenticationService.getAuthentication().success(function (data) {
  22064. $scope.user = data;
  22065. initChange();
  22066. });
  22067. // 初始化变更单信息
  22068. var initChange = function () {
  22069. $scope.change = {
  22070. date: new Date(),
  22071. recorder: $scope.user.userName,
  22072. orderCode: null,
  22073. code: 'B2BPC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  22074. orderId: null,
  22075. orderChangeItems: []
  22076. }
  22077. }
  22078. $scope.getEnableOrders = function() {
  22079. initChange();
  22080. var modalInstance = $modal.open({
  22081. animation: true,
  22082. size: 'lg',
  22083. templateUrl: 'static/tpl/index/purc/modal/enableOrderList.html',
  22084. controller: 'EnableChangeListCtrl',
  22085. resolve: {
  22086. }
  22087. });
  22088. modalInstance.result.then(function (data) {
  22089. $scope.change.orderCode = data.code;
  22090. $scope.change.orderId = data.id;
  22091. $scope.orderItems = data.orderItems;
  22092. $scope.change.oldCurrency = data.currency;
  22093. $scope.change.oldPayments = data.payments;
  22094. $scope.change.oldRate = data.rate;
  22095. $scope.change.vendUU = data.vendUU;
  22096. $scope.change.apVendorName = data.receiveName;
  22097. $scope.change.vendUserUU = data.vendUserUU;
  22098. $scope.change.newCurrency = data.currency != null ? data.currency :null;
  22099. $scope.change.newPayments = data.payments != null ? data.payments :null;
  22100. angular.forEach($scope.orderItems, function (item, index) {
  22101. $scope.change.orderChangeItems.push({
  22102. oldProductId: item.productId,
  22103. orderItemId: item.id,
  22104. orderItemNumber: item.number,
  22105. oldQty: item.qty,
  22106. oldPrice: item.price,
  22107. oldTaxrate: item.taxrate,
  22108. oldDelivery: item.delivery,
  22109. newQty: item.qty != null ? item.qty :null,
  22110. newPrice: item.price != null ? item.price :null,
  22111. newTaxrate: item.taxrate != null ? item.taxrate :null,
  22112. newDelivery: item.delivery != null ? item.delivery :null,
  22113. oldProduct: item.product,
  22114. number: index + 1
  22115. });
  22116. });
  22117. });
  22118. }
  22119. // 删除明细
  22120. $scope.del = function (index) {
  22121. $scope.change.orderChangeItems.splice(index, 1);
  22122. }
  22123. $scope.getMinDate = function () {
  22124. return $filter('date')(new Date, 'yyyy-MM-dd');
  22125. };
  22126. $scope.openDatePicker = function ($event, openParam, index) {
  22127. $event.preventDefault();
  22128. $event.stopPropagation();
  22129. $scope.change.orderChangeItems[index].$dateOpen = !openParam;
  22130. };
  22131. $scope.save = function() {
  22132. if ($scope.change.unNeedReply == null) {
  22133. toaster.pop('error', '请选择是否需要供应商确认');
  22134. } else if ($scope.change.orderChangeItems.length == 0) {
  22135. toaster.pop('error', '请至少选择一条采购明细')
  22136. } else {
  22137. change.save({}, $scope.change, function (data) {
  22138. window.location.hash = "/purc/change/" + data.id;
  22139. toaster.pop('success', '采购变更单保存成功');
  22140. }, function(res) {
  22141. toaster.pop('error','请输入正确的信息')
  22142. });
  22143. }
  22144. }
  22145. }]);
  22146. /**
  22147. * 获取可以作为采购变更单的采购单
  22148. *
  22149. * @author hejq
  22150. * @date 2018-06-25 18:41
  22151. */
  22152. app.controller('EnableChangeListCtrl', ['$scope', 'change', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance',
  22153. function ($scope, change, BaseService, ngTableParams, toaster, $modalInstance) {
  22154. $scope.dateZoneText = '一个月内';
  22155. $scope.condition = {dateZone: 1};
  22156. /* 时间筛选初始化*/
  22157. var fromDate = new Date();
  22158. var toDate = new Date();
  22159. fromDate.setMonth(fromDate.getMonth() - 1);
  22160. fromDate.setHours(0, 0, 0, 0);
  22161. toDate.setHours(23, 59, 59, 999);
  22162. $scope.condition.dateFrom = fromDate;
  22163. $scope.condition.dateTo = toDate;
  22164. $scope.changeDateZone = function (zone) {
  22165. $scope.condition.dateZone = zone;
  22166. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  22167. $scope.condition.$dateZoneOpen = false;
  22168. getDateCondition(zone, $scope.condition);
  22169. $scope.tableParams.page(1);
  22170. $scope.tableParams.reload();
  22171. };
  22172. $scope.openFilterDatePicker = function ($event, item, openParam) {
  22173. $event.preventDefault();
  22174. $event.stopPropagation();
  22175. item[openParam] = !item[openParam];
  22176. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  22177. $scope.tableParams.reload();
  22178. }
  22179. };
  22180. $scope.tableParams = new ngTableParams({
  22181. page: 1,
  22182. count: 5,
  22183. sorting: {
  22184. 'id': 'desc'
  22185. }
  22186. }, {
  22187. total: 0,
  22188. counts: [],
  22189. getData: function ($defer, params) {
  22190. $scope.loading = true;
  22191. var pageParams = params.url();
  22192. pageParams.searchFilter = { // 筛选条件
  22193. keyword: $scope.keyword,
  22194. fromDate: getDateTime($scope.condition.dateFrom),
  22195. endDate: getDateTime($scope.condition.dateTo)
  22196. };
  22197. change.getEnableOrderList.call(null, BaseService.parseParams(pageParams), function (page) {
  22198. $scope.loading = false;
  22199. if (page) {
  22200. params.total(page.totalElement);
  22201. $defer.resolve(page.content);
  22202. }
  22203. }, function (response) {
  22204. $scope.loading = false;
  22205. toaster.pop('error', '数据加载失败', response.data);
  22206. });
  22207. }
  22208. });
  22209. $scope.checkedOrder = null;
  22210. var checkItems = [];
  22211. // 单选
  22212. $scope.checkOne = function (order) {
  22213. var changeflag = false;
  22214. order.checked = !order.checked;
  22215. if ((order.checked) && ($scope.checkedOrder != null) && ($scope.checkedOrder != order)) {
  22216. $scope.checkedOrder.checked = false;
  22217. angular.forEach($scope.checkedOrder.orderItems, function (item) {
  22218. item.checked = false;
  22219. });
  22220. $scope.checkedOrder = null;
  22221. checkItems = [];
  22222. }
  22223. if (order.checked) {
  22224. $scope.checkedOrder = order;
  22225. angular.forEach(order.orderItems, function (item) {
  22226. if (item.change) {
  22227. item.checked = false;
  22228. changeflag = true;
  22229. } else {
  22230. item.checked = true;
  22231. checkItems.push(item);
  22232. }
  22233. });
  22234. } else {
  22235. $scope.checkedOrder = null;
  22236. angular.forEach(order.orderItems, function (item) {
  22237. item.checked = false;
  22238. });
  22239. checkItems = [];
  22240. }
  22241. if (checkItems.length == 0 && changeflag) {
  22242. order.checked =false;
  22243. toaster.pop('warning', '提示', "该采购单所有明细正在变更中,在供应商确认之前不可再次变更");
  22244. }
  22245. };
  22246. // 明细
  22247. $scope.checkItem = function (item, order) {
  22248. // 先判断选中信息
  22249. if (item.change) {
  22250. toaster.pop('warning', '提示', "该明细正在变更中,在供应商确认之前不可再次变更");
  22251. item.checked = null;
  22252. return;
  22253. }
  22254. order.checked = true;
  22255. if ($scope.checkedOrder != null && order.id != $scope.checkedOrder.id) {
  22256. $scope.checkedOrder.checked = false;
  22257. $scope.checkedOrder = order;
  22258. order.checked = true;
  22259. angular.forEach(checkItems, function (checkItem) {
  22260. checkItem.checked = false;
  22261. });
  22262. checkItems = [];
  22263. }
  22264. item.checked = !item.checked;
  22265. if (item.checked) {
  22266. checkItems.push(item);
  22267. if ($scope.checkedOrder == null) {
  22268. $scope.checkedOrder = order;
  22269. }
  22270. order.checked = true;
  22271. } else {
  22272. angular.forEach(checkItems, function (checkItem, index) {
  22273. if (checkItem.id == item.id) {
  22274. checkItems.splice(index, 1);
  22275. }
  22276. });
  22277. }
  22278. if (checkItems.length == 0) {
  22279. $scope.checkedOrder = null;
  22280. order.checked = false;
  22281. }
  22282. };
  22283. // 搜索框回车
  22284. $scope.onSearch = function (keyword) {
  22285. $scope.tableParams.page(1);
  22286. $scope.tableParams.reload();
  22287. };
  22288. $scope.getCartTotal = function (items) {
  22289. var sum = 0;
  22290. angular.forEach(items, function (item) {
  22291. sum += item.qty * item.price;
  22292. });
  22293. return sum;
  22294. };
  22295. // 选择
  22296. $scope.choose = function () {
  22297. if ($scope.checkedOrder == null || checkItems.length == 0) {
  22298. toaster.pop('error', '请先选择采购单信息');
  22299. } else {
  22300. $scope.checkedOrder.orderItems = checkItems;
  22301. $modalInstance.close($scope.checkedOrder);
  22302. }
  22303. }
  22304. // 关闭
  22305. $scope.close = function () {
  22306. $modalInstance.dismiss();
  22307. };
  22308. }]);
  22309. /**
  22310. * 采购变更单详情
  22311. */
  22312. app.controller('PurcChangeDetailCtrl', ['$scope', '$stateParams', 'change', 'toaster', 'CurrentRole',
  22313. function ($scope, $stateParams, change, toaster, CurrentRole) {
  22314. // 获取当前用户是否为普通用户
  22315. CurrentRole.isUser({}, {}, function (data) {
  22316. $scope.isUser = data.isUser;
  22317. });
  22318. var loadData = function () {
  22319. change.getItem({id: $stateParams.id}, function (data) {
  22320. $scope.change = data;
  22321. }, function (response) {
  22322. toaster.pop('error', '', response.data);
  22323. });
  22324. };
  22325. loadData();
  22326. $scope.openDatePicker = function ($event, item, openParam) {
  22327. $event.preventDefault();
  22328. $event.stopPropagation();
  22329. item[openParam] = !item[openParam];
  22330. };
  22331. }]);
  22332. /**
  22333. * B2C搜索
  22334. */
  22335. app.controller('SearchCtrl', ['$scope', '$http', '$rootScope', 'SessionService', 'AccountEnterprise', function($scope, $http, $rootScope, SessionService, AccountEnterprise) {
  22336. $scope.hotwords = new Array();
  22337. var hasBrand = false;
  22338. var hasComponent = false;
  22339. // 热词搜索品牌
  22340. var hotBrand = function () {
  22341. $http.get($scope.toB2cLink + '/api/product/brand/mostSearchBrands'
  22342. ).success(function(data){
  22343. hasBrand = true;
  22344. angular.forEach(data, function (value) {
  22345. $scope.hotwords.push({name: value.nameEn, url: $scope.toB2cLink + '/search?w='+ value.nameEn +'&type=brand'})
  22346. })
  22347. if (hasBrand) {
  22348. hotComponent();
  22349. }
  22350. }).error(function(response) {
  22351. console.log(response)
  22352. });
  22353. };
  22354. // 热词搜索器件
  22355. var hotComponent = function () {
  22356. $http.get($scope.toB2cLink + '/api/product/component/mostSearchComponent'
  22357. ).success(function(data){
  22358. hasComponent = true;
  22359. if (hasBrand && hasComponent) {
  22360. angular.forEach(data, function (value) {
  22361. $scope.hotwords.push({name: value.code, url: $scope.toB2cLink + '/search?w='+ value.code +'&type=component'})
  22362. })
  22363. }
  22364. }).error(function(response) {
  22365. console.log(response)
  22366. });
  22367. };
  22368. AccountEnterprise.getB2cUrl({}, function(data) {
  22369. $scope.toB2cLink = data.url
  22370. hotBrand();
  22371. });
  22372. // 默认搜索类型
  22373. $scope.searchType = 'component';
  22374. $scope.placeholderSearch = '请输入型号';
  22375. // 选搜索类型
  22376. $scope.setTypeClick = function (type) {
  22377. $scope.keyword = '';
  22378. $scope.searchType = type;
  22379. if (type === 'kind') {
  22380. $scope.placeholderSearch = '请输入物料名称';
  22381. } else if (type === 'store') {
  22382. $scope.placeholderSearch = '请输入卖家名称';
  22383. } else if (type === 'brand') {
  22384. $scope.placeholderSearch = '请输入品牌';
  22385. } else {
  22386. $scope.placeholderSearch = '请输入型号';
  22387. }
  22388. };
  22389. // 搜索
  22390. $scope.search = function() {
  22391. if($scope.keyword) {
  22392. SessionService.set('brand', true);
  22393. SessionService.unset('component');
  22394. window.location.href = $scope.toB2cLink + '/search?w=' + encodeURI($scope.keyword) + '&type=' + $scope.searchType;
  22395. }
  22396. };
  22397. // 搜索框获得焦点,显示联想框
  22398. $scope.onFocus = function() {
  22399. $scope.associate = true;
  22400. $scope.selectIndex = -1;
  22401. if(!$scope.keyword) $scope.keyword = '';
  22402. };
  22403. // 搜索框失去焦点,关闭联想框
  22404. $scope.onBlur = function() {
  22405. $scope.associate = false;
  22406. };
  22407. // 搜索框通过按键选取想要的联想词
  22408. $scope.onKeyup = function() {
  22409. if($scope.associates && $scope.associates.length) {
  22410. if(event.keyCode == 40) { //监听到按下键
  22411. $scope.selectIndex ++;
  22412. if($scope.selectIndex >= $scope.associates.length) $scope.selectIndex = 0;
  22413. $scope.keyword = $scope.associates[$scope.selectIndex];
  22414. } else if(event.keyCode == 38) { //监听到按上键
  22415. $scope.selectIndex --;
  22416. if($scope.selectIndex < 0) $scope.selectIndex = $scope.associates.length - 1;
  22417. $scope.keyword = $scope.keyword = $scope.associates[$scope.selectIndex];
  22418. } else if(event.keyCode == 13) { //确定键
  22419. $scope.search();
  22420. }
  22421. }
  22422. };
  22423. // 输入框内容变化,获取新的联想词
  22424. $scope.onChange = function() {
  22425. if ($scope.keyword) {
  22426. var params = {
  22427. keyword: $scope.keyword,
  22428. type: $scope.searchType
  22429. };
  22430. $http.get($scope.toB2cLink + '/search/similarKeywords', {
  22431. params : params
  22432. }).success(function(data){
  22433. $scope.associates = data.result;// 联想词数组
  22434. }).error(function(response) {
  22435. console.log(response)
  22436. });
  22437. } else {
  22438. $scope.associates = [];// 联想词数组
  22439. }
  22440. };
  22441. // 点击联想词
  22442. $scope.onAssociateClick = function(component) {
  22443. $scope.keyword = component;
  22444. $scope.search();
  22445. };
  22446. // 鼠标进入联想词框,不能关闭联想词框
  22447. $scope.onAssociateEnter = function() {
  22448. $scope.associateEnter = true;
  22449. };
  22450. // 鼠标离开联想词框,可以关闭联想词框
  22451. $scope.onAssociateLeave = function() {
  22452. $scope.associateEnter = false;
  22453. };
  22454. // 跳转到B2C
  22455. $scope.b2cLink = function (url) {
  22456. window.location.href = $scope.toB2cLink + url;
  22457. };
  22458. // 头部固定
  22459. window.addEventListener('scroll', function () {
  22460. var obj = document.getElementById('fixed-header');
  22461. var scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  22462. $scope.$apply(function () {
  22463. $scope.isFixed = scrolled >= obj.offsetTop;
  22464. });
  22465. }, false);
  22466. }]);
  22467. /**
  22468. * 树结构
  22469. */
  22470. app.controller('treeController', ['$scope', '$location', function($scope, $location){
  22471. $scope.roleList = [
  22472. { "roleName" : "卖家中心(销售)", "roleId" : "role1", 'path': 'sale', level: 0, collapsed: true, "children" : [
  22473. { "roleName" : "商机管理", "roleId" : "role1-1", collapsed: true, "children" : [
  22474. { "roleName" : "客户采购询价", "roleId" : "role1-1-1", 'link' : '#/sale/inquiry', "children" : [] },
  22475. { "roleName" : "客户公共询价", "roleId" : "role1-1-2", 'link' : '#/sale/pubinquiry', "children" : [] },
  22476. { "roleName" : "客户模具询价", "roleId" : "role1-1-3", 'link' : '#/sale/mould', "children" : [] },
  22477. { "roleName" : "主动报价", "roleId" : "role1-1-4", 'link' : '#/sale/quotation/list', "children" : [] },
  22478. { "roleName" : "客户招标", "roleId" : "role1-1-5", 'link' : '#/sale/tender', "children" : [] }
  22479. ] },
  22480. { "roleName" : "订单管理", "roleId" : "role1-2", collapsed: true, "children" : [
  22481. { "roleName" : "客户采购订单", "roleId" : "role1-2-1", 'link' : '#/sale/order', "children" : [] },
  22482. { "roleName" : "客户采购变更单", "roleId" : "role1-2-2", 'link' : '#/sale/change', "children" : [] },
  22483. { "roleName" : "客户委外单", "roleId" : "role1-2-3", 'link' : '#/sale/maketodo/makeorder', "children" : [] },
  22484. { "roleName" : "委外变更单", "roleId" : "role1-2-4", 'link' : '#/sale/makechange', "children" : [] },
  22485. { "roleName" : "客户发货提醒", "roleId" : "role1-2-5", 'link' : '#/sale/notice', "children" : [] },
  22486. { "roleName" : "发货单", "roleId" : "role1-2-6", 'link' : '#/sale/send', "children" : [] }
  22487. ]},
  22488. { "roleName" : "客户出入库", "roleId" : "role1-3", collapsed: true, "children" : [
  22489. { "roleName" : "MRB单", "roleId" : "role1211", 'link' : '#/sale/MRB', "children" : [] },
  22490. { "roleName" : "不良品出库单", "roleId" : "role1-3-1", 'link' : '#/sale/badOut', "children" : [] },
  22491. { "roleName" : "不良品入库单", "roleId" : "role1-3-2", 'link' : '#/sale/badIn', "children" : [] },
  22492. { "roleName" : "客户采购验收单", "roleId" : "role1-3-3", 'link' : '#/sale/accept', "children" : [] },
  22493. { "roleName" : "客户采购验退单", "roleId" : "role1-3-4", 'link' : '#/sale/returns', "children" : [] },
  22494. { "roleName" : "客户委外验收单", "roleId" : "role1-3-5", 'link' : '#/sale/makeaccept', "children" : [] },
  22495. { "roleName" : "客户委外验退单", "roleId" : "role1-3-6", 'link' : '#/sale/makereturns', "children" : [] }
  22496. ] },
  22497. { "roleName" : "样品管理", "roleId" : "role1-4", collapsed: true, "children" : [
  22498. { "roleName" : "客户打样申请", "roleId" : "role1-4-1", 'link' : '#/sale/sample', "children" : [] },
  22499. { "roleName" : "客户认定单", "roleId" : "role1-4-2", 'link' : '#/sale/approval', "children" : [] }
  22500. ] },
  22501. { "roleName" : "基础资料", "roleId" : "role1-5", collapsed: true, "children" : [
  22502. { "roleName" : "客户资料", "roleId" : "role1-5-1", 'link' : '#/sale/customer', "children" : [] },
  22503. { "roleName" : "绩效考核", "roleId" : "role1-5-2", 'link' : '#/sale/vendorPerformanceAssess', "children" : [] },
  22504. { "roleName" : "产品导入", "roleId" : "role1-5-3", 'link' : '#/sale/prodList', "children" : [] }
  22505. ] }
  22506. ]},
  22507. { "roleName" : "买家中心(采购)", "roleId" : "role2", 'path': 'purc', level: 0, collapsed: true, "children" : [
  22508. { "roleName" : "供应商资料", "roleId" : "role2-1-1", 'link' : '#/purc/vendor', "children" : [] },
  22509. { "roleName" : "供应商服务", "roleId" : "role2-1-2", 'link' : '#/purc/vendor/serve', "children" : [] },
  22510. { "roleName" : "采购物料", "roleId" : "role2-1-3", 'link' : '#/purc/product', "children" : [] },
  22511. { "roleName" : "采购招标", "roleId" : "role2-1-4", 'link' : '#/purc/tender', "children" : [] },
  22512. { "roleName" : "采购询价", "roleId" : "role2-1-5", 'link' : '#/purc/purchaseinquiry', "children" : [] },
  22513. { "roleName" : "公共询价", "roleId" : "role2-1-6", 'link' : '#/purc/publicInquiry', "children" : [] },
  22514. { "roleName" : "采购订单", "roleId" : "role2-1-7", 'link' : '#/purc/order', "children" : [] },
  22515. { "roleName" : "采购变更单", "roleId" : "role2-1-8", 'link' : '#/purc/change', "children" : [] },
  22516. { "roleName" : "代采订单", "roleId" : "role2-1-9", 'link' : '#/purc/deputy', "children" : [] },
  22517. { "roleName" : "委外订单", "roleId" : "role2-1-10", 'link' : '#/purc/makeoutorder', "children" : [] }
  22518. ]},
  22519. { "roleName" : "财务", "roleId" : "role3", 'path': 'fa', level: 0, collapsed: true, "children" : [
  22520. { "roleName" : "应收", "roleId" : "role3-1", collapsed: true, "children" : [
  22521. { "roleName" : "发票", "roleId" : "role3-1-1", 'link' : '#/fa/apBill', "children" : [] },
  22522. { "roleName" : "应收对账单", "roleId" : "role3-1-2", 'link' : '#/fa/apCheck', "children" : [] }
  22523. ] },
  22524. { "roleName" : "应付", "roleId" : "role3-2", collapsed: true, "children" : [
  22525. { "roleName" : "应付对账单", "roleId" : "role3-2-1", 'link' : '#/fa/arCheck', "children" : [] }
  22526. ]}
  22527. ]},
  22528. { "roleName" : "企业圈", "roleId" : "role4", 'path': 'baseInfo', level: 0, collapsed: true, "children" : [
  22529. { "roleName" : "我的合作伙伴", "roleId" : "role4-1-1", 'link' : '#/baseInfo/myRequest', "children" : [] },
  22530. { "roleName" : "新的合作伙伴", "roleId" : "role4-1-2", 'link' : '#/baseInfo/newPartner', "children" : [] }
  22531. ]},
  22532. { "roleName" : "基础设置", "roleId" : "role5", 'path': 'approvalFlow', collapsed: true, level: 0, "children" : [
  22533. { "roleName" : "企业信息", "roleId" : "role5-1-1", 'link' : '#/approvalFlow/enterprise', "children" : [] },
  22534. { "roleName" : "物料信息", "roleId" : "role5-1-2", 'link' : '#/approvalFlow/product', "children" : [] },
  22535. { "roleName" : "我的产品库", "roleId" : "role5-1-3", 'link' : '#/approvalFlow/userProduct', "children" : [] },
  22536. { "roleName" : "人员信息", "roleId" : "role5-1-4", 'link' : '#/approvalFlow/user', "children" : [] },
  22537. { "roleName" : "角色权限", "roleId" : "role5-1-5", 'link' : '#/approvalFlow/role', "children" : [] },
  22538. { "roleName" : "审批流", "roleId" : "role5-1-6", 'link' : '#/approvalFlow/flow', "children" : [] },
  22539. { "roleName" : "操作日志", "roleId" : "role5-1-7", 'link' : '#/approvalFlow/log', "children" : [] }
  22540. ]}
  22541. ];
  22542. $scope.currentObj = {};
  22543. var hasChildrenObj = function (target) {
  22544. var flag = false;
  22545. if ($scope.currentObj.roleId && target && target.children) {
  22546. angular.forEach(target.children, function (item) {
  22547. if (item.roleId == $scope.currentObj.roleId) {
  22548. flag = true;
  22549. }
  22550. if (item.children.length && hasChildrenObj(item)) {
  22551. flag = true;
  22552. }
  22553. });
  22554. }
  22555. return flag;
  22556. }
  22557. var roopCall = function (arr, callBack) {
  22558. angular.forEach(arr, function (item) {
  22559. if (item.children && item.children.length) {
  22560. roopCall(item.children, callBack);
  22561. }
  22562. callBack(item);
  22563. })
  22564. }
  22565. var initObj = function (arr, flag) {
  22566. angular.forEach(arr, function (item) {
  22567. if (flag) {
  22568. item.collapsed = false;
  22569. }
  22570. if (item.children && item.children.length) {
  22571. initObj(item.children, item.path && item.path == $location.$$path.split('/')[1]);
  22572. } else {
  22573. if (item.link && item.link.split('#')[1] == $location.$$path) {
  22574. item.selected = 'selected';
  22575. $scope.currentObj = item;
  22576. }
  22577. }
  22578. })
  22579. }
  22580. initObj($scope.roleList);
  22581. var initClose = function () {
  22582. roopCall($scope.roleList, function (item) {
  22583. item.collapsed = !hasChildrenObj(item);
  22584. })
  22585. }
  22586. initClose();
  22587. var closeRow = function (arr) {
  22588. angular.forEach(arr, function (item) {
  22589. item.selected = undefined;
  22590. if (item.children) {
  22591. closeRow(item.children);
  22592. }
  22593. })
  22594. }
  22595. $scope.$watch( 'myTree.currentNode', function( newObj, oldObj ) {
  22596. if( $scope.myTree && angular.isObject($scope.myTree.currentNode) ) {
  22597. $scope.currentObj = newObj;
  22598. if (newObj.link) {
  22599. window.location.href = newObj.link
  22600. }
  22601. roopCall($scope.roleList, function (item) {
  22602. if (item.roleId == newObj.roleId) {
  22603. $scope.currentObj = item;
  22604. // item.collapsed = !item.collapsed;
  22605. } else {
  22606. item.collapsed = !hasChildrenObj(item) && (item.roleId != newObj.roleId);
  22607. }
  22608. })
  22609. // 父级菜单不选择
  22610. if ($scope.currentObj.link) {
  22611. closeRow($scope.roleList);
  22612. $scope.currentObj.selected = 'selected';
  22613. } else {
  22614. $scope.currentObj.selected = null;
  22615. }
  22616. }
  22617. }, false);
  22618. }])
  22619. return app;
  22620. });