app.js 909 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464
  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'], 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']);
  4. app.init = function () {
  5. angular.bootstrap(document, ['myApp']);
  6. };
  7. app.config(['$httpProvider', function ($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function ($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function (response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. window.location.href = response.data.loginUrl || 'index';
  16. return $q.reject(response);
  17. }
  18. return $q.reject(response);
  19. }
  20. }
  21. return httpInterceptor;
  22. }]);
  23. app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
  24. $stateProvider.state('index', {
  25. url: "/index",
  26. views: {
  27. "left-view": {
  28. templateUrl: "static/tpl/index/home/left.html",
  29. controller: 'LeftCtrl'
  30. },
  31. "right-view": {
  32. templateUrl: "static/tpl/index/home/right.html",
  33. controller: 'RightCtrl'
  34. }
  35. }
  36. }).state('home', {
  37. url: "/",
  38. views: {
  39. "left-view": {
  40. templateUrl: "static/tpl/index/home/left.html",
  41. controller: 'LeftCtrl'
  42. },
  43. "right-view": {
  44. templateUrl: "static/tpl/index/home/right.html",
  45. controller: 'RightCtrl'
  46. }
  47. }
  48. }).state('sale', {
  49. url: "/sale",
  50. views: {
  51. "left-view": {
  52. templateUrl: "static/tpl/index/sale/left.html",
  53. controller: 'LeftCtrl'
  54. },
  55. "right-view": {
  56. templateUrl: "static/tpl/index/sale/right.html"
  57. }
  58. },
  59. controller: function ($scope) {
  60. $scope.truck = [];
  61. $scope.dataChanged = false;
  62. }
  63. }).state('sale.index', {
  64. url: "",
  65. templateUrl: "static/tpl/index/sale/index.html"
  66. }).state('sale.home', {
  67. url: "/",
  68. templateUrl: "static/tpl/index/sale/index.html"
  69. }).state('purc', {
  70. url: "/purc",
  71. views: {
  72. "left-view": {
  73. templateUrl: "static/tpl/index/purc/left.html",
  74. controller: 'LeftCtrl'
  75. },
  76. "right-view": {
  77. templateUrl: "static/tpl/index/purc/right.html"
  78. }
  79. },
  80. controller: function ($scope) {
  81. $scope.truck = [];
  82. $scope.dataChanged = false;
  83. }
  84. }).state('purc.index', {
  85. url: "",
  86. templateUrl: "static/tpl/index/purc/index.html"
  87. }).state('purc.home', {
  88. url: "/",
  89. templateUrl: "static/tpl/index/purc/index.html"
  90. }).state('purc.introduce', {
  91. url: "/introduce",
  92. templateUrl: "static/tpl/index/purc/introduce.html"
  93. }).state('purc.order', {
  94. url: "/order",
  95. templateUrl: "static/tpl/index/purc/order.html",
  96. controller: 'PurcOrderCtrl'
  97. }).state('purc.order_detail', {
  98. url: "/order/:id",
  99. templateUrl: "static/tpl/index/purc/order_detail.html",
  100. controller: 'PurcOrderDetailCtrl'
  101. }).state('purc.newOrder', {
  102. url: "/addOrder",
  103. templateUrl: "static/tpl/index/purc/addOrder.html",
  104. controller: 'PurcNewOrderCtrl'
  105. }).state('purc.cart', {
  106. url: "/cart",
  107. templateUrl: "static/tpl/index/purc/cart.html",
  108. controller: 'CartController'
  109. }).state('purc.cartDetail', {
  110. url: "/cart/:id",
  111. templateUrl: "static/tpl/index/purc/cart_detail.html",
  112. controller: 'CartDetailController'
  113. }).state('purc.deputy', {
  114. url: "/deputy",
  115. templateUrl: "static/tpl/index/purc/deputyOrder.html",
  116. controller: 'DeputyOrderCtrl'
  117. }).state('purc.deputylog', {
  118. url: "/deputylog",
  119. templateUrl: "static/tpl/index/purc/deputyorders_log.html",
  120. controller: 'DeputyOrderLogCtrl'
  121. }).state('purc.newdeputy', {
  122. url: "/deputy/add",
  123. templateUrl: "static/tpl/index/purc/deputyOrder_new.html",
  124. controller: 'NewDeputyOrderCtrl'
  125. }).state('purc.deputydetail', {
  126. url: "/deputy/:id",
  127. templateUrl: "static/tpl/index/purc/deputyOrder_detail.html",
  128. controller: 'DeputyOrderDetailCtrl'
  129. /* 招标列表 */
  130. }).state('purc.tenderlist', {
  131. url: "/tender",
  132. templateUrl: "static/tpl/index/purc/tenderlist.html",
  133. controller: 'PurcTenderCtrl'
  134. /* 招标答疑列表 */
  135. }).state('purc.tenderanswerlist', {
  136. url: "/tender/answer",
  137. templateUrl: "static/tpl/index/purc/tender_answer_list.html",
  138. controller: 'PurcTenderAnswerListCtrl'
  139. /* 招标答疑详情 */
  140. }).state('purc.tenderanswerdetail', {
  141. url: "/tender/answer/:id",
  142. templateUrl: "static/tpl/index/purc/tender_answer_detail.html",
  143. controller: 'PurcTenderAnswerDetailCtrl'
  144. }).state('purc.waiting.tenderlist', {
  145. url: "/tender",
  146. templateUrl: "static/tpl/index/purc/tenderlist.html",
  147. controller: 'PurcTenderCtrl'
  148. }).state('purc.todo.tenderlist', {
  149. url: "/tender/todo",
  150. templateUrl: "static/tpl/index/purc/tenderlist.html",
  151. controller: 'PurcTenderCtrl'
  152. /* 招标 */
  153. }).state('purc.tender', {
  154. url: "/addTender",
  155. templateUrl: "static/tpl/index/purc/tender.html",
  156. controller: 'PurcNewTenderCtrl'
  157. }).state('purc.savedtender', {
  158. url: "/tender/:id",
  159. templateUrl: "static/tpl/index/purc/tender.html",
  160. controller: 'PurcNewTenderCtrl'
  161. /* 评标 */
  162. }).state('purc.evaluation', {
  163. url: "/evaluation/:id",
  164. templateUrl: "static/tpl/index/purc/tender_evaluation.html",
  165. controller: 'PurcEvaluationCtrl'
  166. /* 采购供应商资料 */
  167. }).state('purc.vendor', {
  168. url: "/vendor",
  169. templateUrl: "static/tpl/index/purc/vendor.html",
  170. controller: 'PurcVendorCtrl'
  171. /* 采购供应商资料 详情*/
  172. }).state('purc.vendorserve', {
  173. url: "/vendor/serve",
  174. templateUrl: "static/tpl/index/cs/right.html",
  175. controller: 'CustServeCtrl'
  176. }).state('purc.vendordetail', {
  177. url: "/vendor/:id",
  178. templateUrl: "static/tpl/index/purc/vendor_detail.html",
  179. controller: 'PurcVendorDetailCtrl'
  180. /* 客户指定招标列表 */
  181. }).state('purc.makeoutorder', {
  182. url: "/makeoutorder",
  183. templateUrl: "static/tpl/index/make/outorder.html",
  184. controller: 'MakeOutOrderCtrl'
  185. }).state('purc.outorder_detail', {
  186. url: "/makeoutorder/:id",
  187. templateUrl: "static/tpl/index/make/outorder_detail.html",
  188. controller: 'MakeOutOrderDetailCtrl'
  189. /*平台新增询价单*/
  190. }).state('purc.inquiry_new', {
  191. url: "/purcinquiry",
  192. templateUrl: "static/tpl/index/purc/inquiry_new.html",
  193. controller: 'PurcInquiryCtrl'
  194. }).state('purc.purcinquiry_new', {
  195. url: "/purcinquiry/:bussinessCode",
  196. templateUrl: "static/tpl/index/purc/purcinquiry_new.html",
  197. controller: 'PurcInquiryNewCtrl'
  198. }).state('purc.inquiry', {
  199. url: "/purchaseinquiry",
  200. templateUrl: "static/tpl/index/purc/inquiry.html",
  201. controller: 'PurchaseInquiryCtrl'
  202. }).state('purc.inquiry_detail', {
  203. url: "/purcinquirydetail",
  204. templateUrl: "static/tpl/index/purc/inquiry_detail.html",
  205. controller: 'PurcInquiryDetailCtrl'
  206. }).state('purc.inquiryInfo_detail', {
  207. url: "/purcinquirydetail/:id",
  208. templateUrl: "static/tpl/index/purc/inquiryInfo_detail.html",
  209. controller: 'PurcInquiryInfoDetailCtrl'
  210. }).state('purc.inquiry_unapply', {
  211. url: "/inquiry_unapply",
  212. templateUrl: "static/tpl/index/purc/inquiry_unapply.html",
  213. controller: 'UnapplyInquiryCtrl'
  214. }).state('purc.product', {
  215. url: "/product",
  216. templateUrl: "static/tpl/index/purc/prodList.html",
  217. controller: 'PurcProductCtrl'
  218. }).state('purc.newProduct', {
  219. url: "/newProduct",
  220. templateUrl: "static/tpl/index/purc/newProdInfo.html",
  221. controller: 'PurcNewProdInfoCtrl'
  222. }).state('purc.productDetail', {
  223. url: "/prodList/:id",
  224. templateUrl: "static/tpl/index/purc/productDetail.html",
  225. controller: 'PurcProdDetailCtrl'
  226. }).state('purc.productmatches', {
  227. url: "/productmatches",
  228. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  229. controller: 'ProductmatchesForPurcCtrl'
  230. }).state('purc.uploadProduct', {
  231. url: "/uploadProduct",
  232. templateUrl: "static/tpl/index/purc/uploadByBatch.html",
  233. controller: 'UploadProductCtrl'
  234. }).state('sale.tenderlist', {
  235. url: "/tender",
  236. templateUrl: "static/tpl/index/sale/tenderlist.html",
  237. controller: 'SaleTenderCtrl'
  238. /* 招标提问列表 */
  239. }).state('sale.tenderquestionlist', {
  240. url: "/tender/question",
  241. templateUrl: "static/tpl/index/sale/tender_question_list.html",
  242. controller: 'SaleTenderQuestionListCtrl'
  243. /* 招标提问详情 */
  244. }).state('sale.tenderquestiondetail', {
  245. url: "/tender/question/:id",
  246. templateUrl: "static/tpl/index/sale/tender_question_detail.html",
  247. controller: 'SaleTenderQuestionDetailCtrl'
  248. }).state('sale.todo.tenderlist', {
  249. url: "/tender",
  250. templateUrl: "static/tpl/index/sale/tenderlist.html",
  251. controller: 'SaleTenderCtrl'
  252. /* 平台公开招标列表 */
  253. }).state('baseInfo.openTenderList', {
  254. url: "/openTenderList",
  255. templateUrl: "static/tpl/index/sale/open_tender_list.html",
  256. controller: 'SaleOpenTenderCtrl'
  257. /* 查看公开招标详情 */
  258. }).state('baseInfo.open_tender_detail', {
  259. url: "/openTenderDetail/:id",
  260. templateUrl: "static/tpl/index/sale/open_tender_detail.html",
  261. controller: 'OpenSaleTenderDetailCtrl'
  262. /* 投标 */
  263. }).state('sale.tender', {
  264. url: "/tender/:id",
  265. templateUrl: "static/tpl/index/sale/tender.html",
  266. controller: 'SaleTenderDetailCtrl'
  267. /* 采购方查看供应商投标 */
  268. }).state('sale.vendortender', {
  269. url: "/tender/:vendUU/:id",
  270. templateUrl: "static/tpl/index/sale/vendor_tender.html",
  271. controller: 'SaleVendorTenderDetailCtrl'
  272. }).state('sale.todo', {
  273. url: "/todo",
  274. templateUrl: "static/tpl/index/sale/todo.html"
  275. }).state('sale.todo.inquiry', {
  276. url: "/inquiry",
  277. templateUrl: "static/tpl/index/sale/inquiry.html",
  278. controller: 'SaleInquiryCtrl'
  279. }).state('sale.todo.order', {
  280. url: "/order",
  281. templateUrl: "static/tpl/index/sale/order.html",
  282. controller: 'SaleOrderCtrl'
  283. }).state('sale.todo.change', {
  284. url: "/change",
  285. templateUrl: "static/tpl/index/sale/change.html",
  286. controller: 'SaleChangeCtrl'
  287. }).state('sale.todo.notice', {
  288. url: "/notice",
  289. templateUrl: "static/tpl/index/sale/notice.html",
  290. controller: 'SaleNoticeCtrl'
  291. }).state('sale.customer', {
  292. url: "/customer",
  293. templateUrl: "static/tpl/index/sale/customer.html",
  294. controller: 'CustomerCtrl'
  295. }).state('sale.customer_detail', {
  296. url: "/customer/:id",
  297. templateUrl: "static/tpl/index/sale/customer_detail.html",
  298. controller: 'CustomerDetailCtrl'
  299. }).state('sale.customerProduct', {
  300. url: "/customerProduct",
  301. templateUrl: "static/tpl/index/sale/customer.html",
  302. controller: 'CustomerCtrl'
  303. }).state('sale.inquiry', {
  304. url: "/inquiry",
  305. templateUrl: "static/tpl/index/sale/inquiry.html",
  306. controller: 'SaleInquiryCtrl'
  307. }).state('sale.inquirymould', {
  308. url: "/mould",
  309. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  310. controller: 'SaleInquiryMouldCtrl'
  311. }).state('sale.todo.inquirymould', {
  312. url: "/mould",
  313. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  314. controller: 'SaleInquiryMouldCtrl'
  315. }).state('sale.inquiry_mould_detail', {
  316. url: "/mould/:id",
  317. templateUrl: "static/tpl/index/sale/inquiry_mould_detail.html",
  318. controller: 'SaleInquiryMouldDetailCtrl'
  319. }).state('sale.inquiry_detail', {
  320. url: "/inquiry/:id",
  321. templateUrl: "static/tpl/index/sale/inquiry_detail.html",
  322. controller: 'SaleInquiryDetailCtrl'
  323. }).state('sale.quotation', {
  324. url: "/quotation",
  325. templateUrl: "static/tpl/index/sale/quotation.html"
  326. }).state('sale.quotation.new', {
  327. url: "/new",
  328. templateUrl: "static/tpl/index/sale/quotation_new.html",
  329. controller: 'SaleQuotationNewCtrl'
  330. }).state('sale.quotation.list', {
  331. url: "/list",
  332. templateUrl: "static/tpl/index/sale/quotation_list.html",
  333. controller: 'SaleQuotationListCtrl'
  334. }).state('sale.quotation.item', {
  335. url: "/:id",
  336. templateUrl: "static/tpl/index/sale/quotation_new.html",
  337. controller: 'SaleQuotationNewCtrl'
  338. }).state('sale.order', {
  339. url: "/order",
  340. templateUrl: "static/tpl/index/sale/order.html",
  341. controller: 'SaleOrderCtrl'
  342. }).state('sale.order_detail', {
  343. url: "/order/:id",
  344. templateUrl: "static/tpl/index/sale/order_detail.html",
  345. controller: 'SaleOrderDetailCtrl'
  346. }).state('sale.change', {
  347. url: "/change",
  348. templateUrl: "static/tpl/index/sale/change.html",
  349. controller: 'SaleChangeCtrl'
  350. }).state('sale.change_detail', {
  351. url: "/change/:id",
  352. templateUrl: "static/tpl/index/sale/change_detail.html",
  353. controller: 'SaleChangeDetailCtrl'
  354. }).state('sale.notice', {
  355. url: "/notice",
  356. templateUrl: "static/tpl/index/sale/notice.html",
  357. controller: 'SaleNoticeCtrl'
  358. }).state('sale.send', {
  359. url: "/send",
  360. templateUrl: "static/tpl/index/sale/send.html",
  361. controller: 'SaleSendCtrl'
  362. }).state('sale.send_detail', {
  363. url: "/send/:id",
  364. templateUrl: "static/tpl/index/sale/send_detail.html",
  365. controller: 'SaleSendDetailCtrl'
  366. }).state('sale.forecast', {
  367. url: "/forecast",
  368. templateUrl: "static/tpl/index/sale/forecast.html",
  369. controller: 'SaleForecastCtrl'
  370. }).state('sale.accept', {
  371. url: "/accept",
  372. templateUrl: "static/tpl/index/sale/accept.html",
  373. controller: 'SaleAcceptCtrl'
  374. }).state('sale.accept_detail', {
  375. url: "/accept/:id",
  376. templateUrl: "static/tpl/index/sale/accept_detail.html",
  377. controller: 'SaleAcceptDetailCtrl'
  378. }).state('sale.returns', {
  379. url: "/returns",
  380. templateUrl: "static/tpl/index/sale/returns.html",
  381. controller: 'SaleReturnsCtrl'
  382. }).state('sale.return_detail', {
  383. url: "/return/:id",
  384. templateUrl: "static/tpl/index/sale/return_detail.html",
  385. controller: 'SaleReturnsDetailCtrl'
  386. }).state('sale.sample', {
  387. url: "/sample",
  388. templateUrl: "static/tpl/index/sale/sample.html",
  389. controller: 'SaleSampleCtrl'
  390. }).state('sale.sample_detail', {
  391. url: "/sample/:id",
  392. templateUrl: "static/tpl/index/sale/sample_detail.html",
  393. controller: 'SaleSampleDetailCtrl'
  394. }).state('sale.approval', {
  395. url: "/approval",
  396. templateUrl: "static/tpl/index/sale/approval.html",
  397. controller: 'SaleApprovalCtrl'
  398. }).state('sale.prodList', {
  399. url: "/prodList",
  400. templateUrl: "static/tpl/index/baseInfo/prodList.html",
  401. controller: 'ProductListCtrl'
  402. }).state('sale.newProdInfo', {
  403. url: "/newProdInfo",
  404. templateUrl: "static/tpl/index/baseInfo/newProdInfo.html",
  405. controller: 'NewProdInfoCtrl'
  406. }).state('sale.uploadByBatch', {
  407. url: "/uploadByBatch",
  408. templateUrl: "static/tpl/index/baseInfo/uploadByBatch.html",
  409. controller: 'UploadByBatchCtrl'
  410. }).state('sale.productDetail', {
  411. url: "/prodList/:id",
  412. templateUrl: "static/tpl/index/baseInfo/productDetail.html",
  413. controller: 'ProductDetailCtrl'
  414. }).state('sale.productmatches', {
  415. url: "/productmatches",
  416. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  417. controller: 'ProductmatchesForSaleCtrl'
  418. }).state('sale.maketodo', {
  419. url: "/maketodo",
  420. templateUrl: "static/tpl/index/make/todo.html"
  421. }).state('sale.maketodo.order', {
  422. url: "/makeorder",
  423. templateUrl: "static/tpl/index/make/order.html",
  424. controller: 'MakeOrderCtrl'
  425. }).state('sale.makeorder', {
  426. url: "/makeorder",
  427. templateUrl: "static/tpl/index/make/order.html",
  428. controller: 'MakeOrderCtrl'
  429. }).state('sale.makeorder_detail', {
  430. url: "/makeorder/:id",
  431. templateUrl: "static/tpl/index/make/order_detail.html",
  432. controller: 'MakeOrderDetailCtrl'
  433. }).state('sale.badOut', {
  434. url: "/badOut",
  435. templateUrl: "static/tpl/index/qc/badOut.html",
  436. controller: 'SaleBadOutCtrl'
  437. }).state('sale.MRB', {
  438. url: "/MRB",
  439. templateUrl: "static/tpl/index/qc/MRB.html",
  440. controller: 'SaleMRBCtrl'
  441. }).state('sale.badIn', {
  442. url: "/badIn",
  443. templateUrl: "static/tpl/index/qc/badIn.html",
  444. controller: 'SaleBadInCtrl'
  445. }).state('sale.makeaccept', {
  446. url: "/makeaccept",
  447. templateUrl: "static/tpl/index/make/accept.html",
  448. controller: 'MakeAcceptCtrl'
  449. }).state('sale.makereturns', {
  450. url: "/makereturns",
  451. templateUrl: "static/tpl/index/make/returns.html",
  452. controller: 'MakeReturnCtrl'
  453. }).state('sale.makechange', {
  454. url: "/makechange",
  455. templateUrl: "static/tpl/index/make/change.html",
  456. controller: 'MakeChangeCtrl'
  457. }).state('sale.makechange_detail', {
  458. url: "/makechange/:id",
  459. templateUrl: "static/tpl/index/make/change_detail.html",
  460. controller: 'MakeChangeDetailCtrl'
  461. }).state('account', {
  462. url: "/account",
  463. views: {
  464. "left-view": {
  465. templateUrl: "static/tpl/index/account/left.html",
  466. controller: 'LeftCtrl'
  467. },
  468. "right-view": {
  469. templateUrl: "static/tpl/index/account/right.html"
  470. }
  471. }
  472. }).state('account.index', {
  473. url: "",
  474. templateUrl: "static/tpl/index/account/index.html",
  475. controller: 'RightCtrl'
  476. }).state('account.home', {
  477. url: "/",
  478. templateUrl: "static/tpl/index/account/index.html",
  479. controller: 'RightCtrl'
  480. }).state('baseInfo', {//基础资料
  481. url: "/baseInfo",
  482. views: {
  483. "left-view": {},
  484. "right-view": {
  485. templateUrl: "static/tpl/index/baseInfo/right.html"
  486. }
  487. }
  488. }).state('baseInfo.index', {
  489. url: "/enterpriseList",
  490. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  491. controller: 'EnterpriseListCtrl'
  492. }).state('baseInfo.home', {
  493. url: "/enterpriseList",
  494. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  495. controller: 'EnterpriseListCtrl'
  496. }).state('baseInfo.enterpriseList', {
  497. url: "/enterpriseList",
  498. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  499. controller: 'EnterpriseListCtrl'
  500. }).state('baseInfo.myClient', {
  501. url: "/myClient",
  502. templateUrl: "static/tpl/index/baseInfo/myClient.html",
  503. controller: 'MyClientCtrl'
  504. }).state('baseInfo.mySupplier', {
  505. url: "/mySupplier",
  506. templateUrl: "static/tpl/index/baseInfo/mySupplier.html",
  507. controller: 'MySupplierCtrl'
  508. }).state('baseInfo.myRequest', {
  509. url: "/myRequest",
  510. templateUrl: "static/tpl/index/baseInfo/myRequest.html",
  511. controller: 'AddPartnerRequestCtrl'
  512. }).state('baseInfo.newPartner', {
  513. url: "/newPartner",
  514. templateUrl: "static/tpl/index/baseInfo/newPartner.html",
  515. controller: 'NewPartnerCtrl'
  516. }).state('baseInfo.myMessage', {
  517. url: "/myMessage",
  518. templateUrl: "static/tpl/index/baseInfo/myMessage.html",
  519. controller: 'AddPartnerMessageCtrl'
  520. }).state('baseInfo.myPartners', {
  521. url: '/myPartners',
  522. templateUrl: "static/tpl/index/baseInfo/myPartners.html",
  523. controller: 'MyPartnersCtrl'
  524. }).state('baseInfo.businessGroups', {
  525. url: '/businessGroups',
  526. controller: 'BusinessGroupsCtrl'
  527. }).state('baseInfo.inquiryList', {
  528. url: '/inquiryList',
  529. templateUrl: "static/tpl/index/baseInfo/inquiry_list.html",
  530. controller: 'PublicInquiryListCtrl'
  531. }).state('baseInfo.inquiryListDetail', {
  532. url: '/inquiryList/:id',
  533. templateUrl: "static/tpl/index/baseInfo/inquiryItem_detail.html",
  534. controller: 'PublicInquiryListDetailCtrl'
  535. }).state('baseInfo.vendorInfo', {
  536. url: '/enume/vendorInfo',
  537. templateUrl: "static/tpl/index/baseInfo/vendorsInfo.html",
  538. controller: 'VendorsInfoCtrl'
  539. }).state('baseInfo.servicerInfo', {
  540. url: '/enume/servicerInfo',
  541. templateUrl: "static/tpl/index/baseInfo/servicerInfo.html",
  542. controller: 'ServicerInfoCtrl'
  543. }).state('baseInfo.customerInfo', {
  544. url: '/enume/customerInfo',
  545. templateUrl: "static/tpl/index/baseInfo/customersInfo.html",
  546. controller: 'CustomersInfoCtrl'
  547. }).state('baseInfo.enume', {
  548. url: '/enume',
  549. templateUrl: "static/tpl/index/baseInfo/vendorAndCustomer.html"
  550. }).state('baseInfo.partner', {
  551. url: '/partner',
  552. templateUrl: "static/tpl/index/baseInfo/addPartners.html",
  553. controller: 'AddPartnersCtrl'
  554. }).state('baseInfo.partner_searchresult', {
  555. url: '/search',
  556. templateUrl: "static/tpl/index/baseInfo/searchresult.html",
  557. controller: 'EnterpriseSearchCtrl'
  558. }).state('baseInfo.invitation', {
  559. url: '/invitation',
  560. templateUrl: "static/tpl/index/baseInfo/invitation.html",
  561. controller: 'InvitationCtrl'
  562. }).state('qc', {
  563. url: "/qc",
  564. views: {
  565. "left-view": {
  566. templateUrl: "static/tpl/index/qc/left.html"
  567. },
  568. "right-view": {
  569. templateUrl: "static/tpl/index/qc/right.html"
  570. }
  571. }
  572. }).state('qc.index', {
  573. url: "",
  574. templateUrl: "static/tpl/index/qc/index.html"
  575. }).state('qc.home', {
  576. url: "/",
  577. templateUrl: "static/tpl/index/qc/index.html"
  578. }).state('fa', {
  579. url: "/fa",
  580. views: {
  581. "left-view": {
  582. templateUrl: "static/tpl/index/fa/left.html"
  583. },
  584. "right-view": {
  585. templateUrl: "static/tpl/index/fa/right.html"
  586. }
  587. }
  588. }).state('fa.index', {
  589. url: "",
  590. templateUrl: "static/tpl/index/fa/index.html"
  591. }).state('fa.home', {
  592. url: "/",
  593. templateUrl: "static/tpl/index/fa/index.html"
  594. }).state('fa.apBill', {
  595. url: "/apBill",
  596. templateUrl: "static/tpl/index/fa/apBill.html",
  597. controller: 'SaleApBillCtrl'
  598. }).state('fa.apBill_detail', {
  599. url: "/apBill/:id",
  600. templateUrl: "static/tpl/index/fa/apBill_detail.html",
  601. controller: 'SaleApBillDetailCtrl'
  602. }).state('fa.arCheck', {
  603. url: "/arCheck",
  604. templateUrl: "static/tpl/index/fa/arCheck.html",
  605. controller: 'SaleArCheckCtrl'
  606. }).state('fa.arCheck_detail', {
  607. url: "/arCheck/:id",
  608. templateUrl: "static/tpl/index/fa/arCheck_detail.html",
  609. controller: 'SaleArCheckDetailCtrl'
  610. }).state('fa.apCheck', {
  611. url: "/apCheck",
  612. params: {
  613. 'id': null
  614. },
  615. templateUrl: "static/tpl/index/fa/apCheck.html",
  616. controller: 'PurchaseApCheckCtrl'
  617. }).state('fa.apCheck_detail', {
  618. url: "/apCheck/:id",
  619. templateUrl: "static/tpl/index/fa/apCheck_detail.html",
  620. controller: 'PurchaseApCheckDetailCtrl'
  621. }).state('fa.apCheckList', {
  622. url: "/apCheckList",
  623. templateUrl: "static/tpl/index/fa/apCheckList.html",
  624. controller: 'PurchaseApCheckListCtrl'
  625. }).state('fa.apBillOut', {
  626. url: "/apBillOut",
  627. params:{
  628. 'id':null
  629. },
  630. templateUrl: "static/tpl/index/fa/apBillOut.html",
  631. controller: 'PurchaseApBillOutCtrl'
  632. }).state('fa.apBillOut_detail', {
  633. url: "/apBillOut/:id",
  634. templateUrl: "static/tpl/index/fa/apBillOut_detail.html",
  635. controller: 'PurchaseApBillOutDetailCtrl'
  636. }).state('fa.apBillOutList', {
  637. url: "/apBillOutList",
  638. templateUrl: "static/tpl/index/fa/apBillOutList.html",
  639. controller: 'PurchaseApBillOutListCtrl'
  640. }).state('fa.adjustList', {
  641. url: "/adjustList",
  642. templateUrl: "static/tpl/index/fa/adjustList.html",
  643. controller: 'PurchaseAdjustListCtrl'
  644. }).state('make', {
  645. url: "/make",
  646. views: {
  647. "left-view": {
  648. templateUrl: "static/tpl/index/make/left.html"
  649. },
  650. "right-view": {
  651. templateUrl: "static/tpl/index/make/right.html"
  652. }
  653. }
  654. }).state('make.index', {
  655. url: "",
  656. templateUrl: "static/tpl/index/make/index.html"
  657. }).state('make.home', {
  658. url: "/",
  659. templateUrl: "static/tpl/index/make/index.html"
  660. }).state('cs', {// 客户服务
  661. url: "/cs",
  662. views: {
  663. "left-view": {
  664. templateUrl: "static/tpl/index/cs/left.html"
  665. },
  666. "right-view": {
  667. templateUrl: "static/tpl/index/cs/right.html"
  668. }
  669. }
  670. }).state('cs.index', {
  671. url: "",
  672. templateUrl: "static/tpl/index/cs/index.html"
  673. }).state('cs.home', {
  674. url: "/",
  675. templateUrl: "static/tpl/index/cs/index.html"
  676. }).state('search', { //顶部搜索
  677. url: "/search?keyword=",
  678. views: {
  679. "left-view": {
  680. templateUrl: "static/tpl/index/search/left.html"
  681. },
  682. "right-view": {
  683. templateUrl: "static/tpl/index/search/search_result.html",
  684. controller: 'TopSearchCtrl'
  685. }
  686. }
  687. }).state('approvalflow', { //审批流
  688. url: "/approvalFlow",
  689. views: {
  690. "left-view": {
  691. templateUrl: "static/tpl/index/approvalFlow/left.html"
  692. },
  693. "right-view": {
  694. templateUrl: "static/tpl/index/approvalFlow/right.html",
  695. }
  696. }
  697. }).state('approvalflow.flow', {
  698. url: "/flow",
  699. templateUrl: "static/tpl/index/approvalFlow/home.html",
  700. controller: 'approvalFlowCtrl'
  701. }).state('approvalflow.enterprise', {
  702. url: "/enterprise",
  703. templateUrl: "static/tpl/index/approvalFlow/enterprise.html",
  704. controller: 'EnterpriseCtrl'
  705. }).state('approvalflow.user', {
  706. url: "/user",
  707. templateUrl: "static/tpl/index/approvalFlow/user.html",
  708. controller: 'UserCtrl'
  709. }).state('approvalflow.log', {
  710. url: "/log",
  711. templateUrl: "static/tpl/index/approvalFlow/log.html",
  712. controller: 'LogCtrl'
  713. }).state('approvalflow.resource', {
  714. url: "/resource",
  715. templateUrl: "static/tpl/index/approvalFlow/resource.html",
  716. controller: 'ResourceCtrl'
  717. }).state('approvalflow.role', {
  718. url: "/role",
  719. templateUrl: "static/tpl/index/approvalFlow/role.html",
  720. controller: 'RoleCtrl'
  721. }).state('approvalflow.product', {
  722. url: "/product",
  723. templateUrl: "static/tpl/index/approvalFlow/prodList.html",
  724. controller: 'ProductAllCtrl'
  725. }).state('approvalflow.userProduct', {
  726. url: "/userProduct",
  727. templateUrl: "static/tpl/index/approvalFlow/userProduct.html",
  728. controller: 'UserProductCtrl'
  729. }).state('approvalflow.productmatches', {
  730. url: "/productmatches",
  731. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  732. controller: 'ProductmatchesCtrl'
  733. }).state('sale.vendorPerformanceAssess', {
  734. url: "/vendorPerformanceAssess",
  735. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess.html",
  736. controller: 'VendorPerformanceAssessCtrl'
  737. }).state('sale.vendorPerformanceAssess_detail', {
  738. url: "/vendorPerformanceAssess/:id",
  739. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess_detail.html",
  740. controller: 'VendorPerformanceAssessDetailCtrl'
  741. });
  742. $urlRouterProvider.otherwise('/index');
  743. }]);
  744. /**
  745. * 表示符号
  746. */
  747. app.factory('Symbol', function () {
  748. return {
  749. currency: function (cur) {
  750. if (cur == 'RMB') return '¥';
  751. else if (cur == 'USD') return '$';
  752. else if (cur == 'EUR') return '€';
  753. else if (cur == null || cur == '') return '¥';
  754. else return cur;
  755. }
  756. };
  757. }).factory('Lodop', function () {
  758. return {
  759. getLodop: function (oOBJECT, oEMBED) {
  760. var CreatedOKLodop7766 = null;
  761. /**************************
  762. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  763. IE系列、IE内核系列的浏览器采用oOBJECT,
  764. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  765. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  766. 64位浏览器指向64位的安装程序install_lodop64.exe。
  767. **************************/
  768. var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  769. var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  770. var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  771. var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  772. var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  773. var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  774. var LODOP;
  775. try {
  776. //=====判断浏览器类型:===============
  777. var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
  778. var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
  779. //=====如果页面有Lodop就直接使用,没有则新建:==========
  780. if (oOBJECT != undefined || oEMBED != undefined) {
  781. if (isIE)
  782. LODOP = oOBJECT;
  783. else
  784. LODOP = oEMBED;
  785. } else {
  786. if (CreatedOKLodop7766 == null) {
  787. LODOP = document.createElement("object");
  788. LODOP.setAttribute("width", 0);
  789. LODOP.setAttribute("height", 0);
  790. LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  791. if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  792. else LODOP.setAttribute("type", "application/x-print-lodop");
  793. document.documentElement.appendChild(LODOP);
  794. CreatedOKLodop7766 = LODOP;
  795. } else
  796. LODOP = CreatedOKLodop7766;
  797. }
  798. ;
  799. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  800. if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
  801. if (navigator.userAgent.indexOf('Chrome') >= 0)
  802. document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
  803. if (navigator.userAgent.indexOf('Firefox') >= 0)
  804. document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
  805. if (is64IE) document.write(strHtm64_Install); else if (isIE) document.write(strHtmInstall); else
  806. document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
  807. return LODOP;
  808. } else if (LODOP.VERSION < "6.1.9.8") {
  809. if (is64IE) document.write(strHtm64_Update); else if (isIE) document.write(strHtmUpdate); else
  810. document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
  811. return LODOP;
  812. }
  813. ;
  814. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  815. LODOP.SET_LICENSES("深圳市优软科技有限公司", "BBF53BD5AB0D522B3207D05CDE381F65", "", "");
  816. //============================================================
  817. return LODOP;
  818. } catch (err) {
  819. if (is64IE)
  820. document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML; else
  821. document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML;
  822. return LODOP;
  823. }
  824. ;
  825. }
  826. }
  827. });
  828. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', 'toaster', function ($scope, $rootScope, $modal, toaster) {
  829. $rootScope.$on('$locationChangeSuccess', function (evt, newUrl) {
  830. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  831. if (routeState.indexOf('/') > -1)
  832. routeState = routeState.substring(0, routeState.indexOf('/'));
  833. if (routeState.indexOf('.') > -1)
  834. routeState = routeState.substring(0, routeState.indexOf('.'));
  835. $scope.routeState = routeState || 'home';
  836. });
  837. $scope.search = function (keyword) {
  838. if (keyword != null && keyword != '') {
  839. $rootScope.searchKeyword = keyword;
  840. window.location.hash = '#/search?keyword=' + keyword;
  841. } else {
  842. $rootScope.searchKeyword = null;
  843. window.location.hash = '#/search';
  844. }
  845. };
  846. $scope.showMessage = function () {
  847. var modalInstance = $modal.open({
  848. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  849. controller: 'PagingReleaseCtrl'
  850. });
  851. };
  852. // 连接到询价
  853. $scope.linktoInquiry = function (active) {
  854. $rootScope.active = active;
  855. window.location.href = "#/sale/inquiry";
  856. }
  857. // 连接到招标
  858. $scope.linktoSaleTender = function (active) {
  859. $rootScope.active = active;
  860. window.location.href = "#/sale/tender";
  861. }
  862. // 链接到打样申请
  863. $scope.linktoSample = function (active) {
  864. $rootScope.active = active;
  865. window.location.href = "#/sale/sample";
  866. }
  867. // 链接到采购招标
  868. $scope.linktoPurcTender = function (active) {
  869. $rootScope.tenderActive = active;
  870. window.location.href = "#/purc/tender";
  871. }
  872. $scope.linktoPurcInquiry = function (active) {
  873. $rootScope.active = active;
  874. window.location.href = "#/purc/purchaseinquiry";
  875. }
  876. }]);
  877. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'PagingReleaseInfo', function ($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance, PagingReleaseInfo) {
  878. // BaseService.scrollBackToTop();
  879. $scope.active = "todo";
  880. $scope.searchStatus = false; // 默认从数据库直接获取
  881. $scope.setActive = function (state) {
  882. if ($scope.active != state) {
  883. $scope.active = state;
  884. if ($scope.tableParams.page() == 1)
  885. $scope.tableParams.reload();
  886. else
  887. $scope.tableParams.page(1);
  888. }
  889. };
  890. var getService = function () {
  891. if ($scope.searchStatus) {
  892. return PagingRelease;
  893. } else {
  894. return PagingReleaseInfo;
  895. }
  896. };
  897. $scope.tableParams = new ngTableParams({
  898. page: 1,
  899. count: 20,
  900. sorting: {
  901. 'pagingRelease.date': 'desc'
  902. }
  903. }, {
  904. total: 0,
  905. counts: [5, 10, 25, 50],
  906. getData: function ($defer, params) {
  907. $scope.loading = true;
  908. var pageParams = params.url();
  909. var realActive = {};
  910. pageParams.searchFilter = { // 筛选条件
  911. keyword: $scope.keyword
  912. // fromDate: getDateTime($scope.condition.dateFrom),
  913. // endDate: getDateTime($scope.condition.dateTo)
  914. };
  915. // AccountEnterprise.get({}, function(data){
  916. // $scope.currentEn = data;
  917. // });
  918. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  919. $scope.loading = false;
  920. if (page) {
  921. params.total(page.totalElement);
  922. $defer.resolve(page.content);
  923. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  924. }
  925. }, function (response) {
  926. $scope.loading = false;
  927. toaster.pop('error', '数据加载失败', response.data);
  928. });
  929. }
  930. });
  931. $scope.close = function () {
  932. $modalInstance.close();
  933. window.location.reload();
  934. };
  935. $scope.checks = {
  936. checked: false
  937. };// 全选框
  938. $scope.checkAll = function () {
  939. angular.forEach($scope.tableParams.data, function (message) {
  940. message.checked = $scope.checks.checked;
  941. });
  942. };
  943. // 单选
  944. $scope.checkOne = function (vendor) {
  945. vendor.checked = true;
  946. var checked = true;
  947. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  948. if (!message.checked) {
  949. checked = false;
  950. }
  951. });
  952. $scope.checks.checked = checked;
  953. };
  954. // 单反选
  955. $scope.unCheckOne = function (vendor) {
  956. vendor.checked = false;
  957. $scope.checks.checked = false;
  958. };
  959. // 标为已读
  960. $scope.setRead = function () {
  961. var selectedMessages = [];
  962. angular.forEach($scope.tableParams.data, function (message) {
  963. if (message.checked) {
  964. selectedMessages.push(message);
  965. }
  966. });
  967. PagingRelease.setRead({}, selectedMessages, function (message) {
  968. $scope.checks = {
  969. checked: false
  970. };
  971. toaster.pop("success", "成功", "设置成功");
  972. $scope.tableParams.page(1);
  973. $scope.tableParams.reload();
  974. });
  975. };
  976. // 点击内容连接之后,信息标为已读
  977. $scope.setOneRead = function (id) {
  978. $modalInstance.close();
  979. PagingRelease.setOneRead({id: id}, {}, function (data) {
  980. }, function (response) {
  981. toaster.pop('error', '提示', response.data);
  982. });
  983. };
  984. // 搜索框回车
  985. $scope.onSearch = function () {
  986. $scope.searchStatus = true;
  987. $scope.tableParams.page(1);
  988. $scope.tableParams.reload();
  989. };
  990. }]);
  991. // 高亮显示关键词
  992. app.filter('getkey', ['$sce', '$rootScope', function ($sce, $rootScope) {
  993. var search = $rootScope.searchKeyword;
  994. return function (content, search) {
  995. content = encodeURI(content);
  996. search = encodeURI(search);
  997. var reg = new RegExp(search, 'gim');
  998. var result = content.replace(reg, '<font color="red">$&</font>');
  999. result = decodeURI(result);
  1000. return $sce.trustAsHtml(result);
  1001. };
  1002. $rootScope.searchKeyword = null;// 清除缓存的关键字
  1003. }]);
  1004. /**
  1005. * 顶部搜索
  1006. */
  1007. 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) {
  1008. BaseService.scrollBackToTop();
  1009. $scope.active = 'all';
  1010. $scope.tip = $rootScope.searchKeyword;
  1011. // 企业搜索
  1012. var getService = function () {
  1013. return getAccountUserSpace;
  1014. };
  1015. $scope.tableParams = new ngTableParams({
  1016. page: 1,
  1017. count: 20,
  1018. sorting: {}
  1019. }, {
  1020. total: 0,
  1021. counts: [5, 10, 25, 50],
  1022. getData: function ($defer, params) {
  1023. $scope.loading = true;
  1024. var pageParams = params.url();
  1025. pageParams.keyword = $rootScope.searchKeyword;
  1026. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1027. $scope.loading = false;
  1028. if (page) {
  1029. $scope.total = page.totalElement;
  1030. params.total(page.totalElement);
  1031. $defer.resolve(page.content);
  1032. }
  1033. }, function (response) {
  1034. $scope.loading = false;
  1035. toaster.pop('error', '数据加载失败', response.data);
  1036. });
  1037. }
  1038. });
  1039. // 添加合作关系
  1040. $scope.addPartner = function (name, businessCode) {
  1041. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  1042. if (data.success) {
  1043. toaster.pop("success", '添加成功', data.success);
  1044. $scope.tableParams.reload();
  1045. }
  1046. if (data.error) {
  1047. toaster.pop("error", '添加失败', data.error);
  1048. }
  1049. }, function (response) {
  1050. toaster.pop('error', '失败', response.data);
  1051. });
  1052. }
  1053. // 物料搜索
  1054. var getProdService = function () {
  1055. return SearchProd;
  1056. };
  1057. $scope.prodTableParams = new ngTableParams({
  1058. page: 1,
  1059. count: 20,
  1060. sorting: {}
  1061. }, {
  1062. total: 0,
  1063. counts: [5, 10, 25, 50],
  1064. getData: function ($defer, params) {
  1065. $scope.loading = true;
  1066. var pageParams = params.url();
  1067. pageParams.keyword = $rootScope.searchKeyword;
  1068. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1069. $scope.loading = false;
  1070. if (page) {
  1071. $scope.prodtotal = page.totalElement;
  1072. params.total(page.totalElement);
  1073. $defer.resolve(page.content);
  1074. }
  1075. }, function (response) {
  1076. $scope.loading = false;
  1077. toaster.pop('error', '数据加载失败', response.data);
  1078. });
  1079. }
  1080. });
  1081. /**
  1082. * 向企业购买
  1083. */
  1084. $scope.PurcByEn = function (businessCode) {
  1085. $rootScope.businessCode = businessCode;
  1086. window.location.hash = "#/purc/addOrder";
  1087. }
  1088. /**
  1089. * 选中单个物料购买
  1090. * @param businessCode
  1091. * @param id
  1092. */
  1093. $scope.PurcByEnAndProd = function (businessCode, id) {
  1094. $rootScope.businessCode = businessCode;
  1095. $rootScope.prodId = id;
  1096. window.location.hash = "#/purc/addOrder";
  1097. }
  1098. /**
  1099. * 询价
  1100. */
  1101. $scope.PurcInquiry = function (businessCode, id) {
  1102. $rootScope.prodId = id;
  1103. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1104. }
  1105. /**
  1106. * 邀请注册商务平台
  1107. */
  1108. $scope.invite = function (name) {
  1109. var modalInstance = $modal.open({
  1110. animation: true,
  1111. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1112. controller: 'InviteCtrl',
  1113. resolve: {
  1114. enname: function () {
  1115. return name
  1116. }
  1117. }
  1118. });
  1119. modalInstance.result.then(function (data) {
  1120. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1121. if (data.success) {
  1122. toaster.pop('success', '提示', data.success);
  1123. }
  1124. if (data.error) {
  1125. toaster.pop('error', '提示', data.error);
  1126. }
  1127. }, function (response) {
  1128. toaster.pop('error', '提示', response.data);
  1129. });
  1130. });
  1131. }
  1132. /**
  1133. * 立即查看
  1134. */
  1135. $scope.view = function (name) {
  1136. $rootScope.vendName = name;
  1137. window.location.hash = "#/baseInfo/newPartner";
  1138. }
  1139. }]);
  1140. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', function ($scope, toaster, $modalInstance, enname) {
  1141. $scope.enter = {
  1142. vendname: enname
  1143. };
  1144. $scope.save = function (enter) {
  1145. if (!enter.vendusertel && !enter.venduseremail) {
  1146. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1147. } else {
  1148. $modalInstance.close(enter);
  1149. }
  1150. }
  1151. $scope.cancel = function () {
  1152. $modalInstance.dismiss();
  1153. }
  1154. }]);
  1155. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function ($scope, toaster, $modalInstance, id, InvitationRecord) {
  1156. var loadData = function (id) {
  1157. InvitationRecord.getRecordById({id: id}, {}, function (data) {
  1158. if (data.user !== null) {
  1159. data.user = {};
  1160. }
  1161. $scope.enter = data;
  1162. });
  1163. };
  1164. loadData(id);
  1165. $scope.save = function (enter) {
  1166. if (!enter.vendusertel && !enter.venduseremail) {
  1167. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1168. } else {
  1169. $modalInstance.close(enter);
  1170. }
  1171. };
  1172. $scope.cancel = function () {
  1173. $modalInstance.dismiss();
  1174. }
  1175. }]);
  1176. /**
  1177. * 邀请记录
  1178. */
  1179. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function ($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1180. BaseService.scrollBackToTop();
  1181. $scope.status = "invitation";
  1182. $scope.active = "invitation";
  1183. var getService = function () {
  1184. if ($scope.active === "invitation") {
  1185. return InvitationRecord.records;
  1186. } else if ($scope.active === "invitationTeam") {
  1187. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1188. }
  1189. };
  1190. $scope.setActive = function (state) {
  1191. if ($scope.active !== state) {
  1192. $scope.active = state;
  1193. if ($scope.tableParams.page() === 1)
  1194. $scope.tableParams.reload();
  1195. else
  1196. $scope.tableParams.page(1);
  1197. }
  1198. };
  1199. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1200. page: 1,
  1201. count: 20,
  1202. sorting: {}
  1203. }, {
  1204. total: 0,
  1205. counts: [],
  1206. getData: function ($defer, params) { // 获取数据的方法
  1207. $scope.loading = true;
  1208. var pageParams = params.url();
  1209. pageParams.keyword = $scope.keyword;
  1210. $scope.tip = $scope.keyword;
  1211. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  1212. $scope.loading = false;
  1213. if (page) {
  1214. params.total(page.totalElement);
  1215. $defer.resolve(page.content);
  1216. }
  1217. }, function (response) {
  1218. $scope.loading = false;
  1219. toaster.pop('error', '数据加载失败', response.data);
  1220. });
  1221. }
  1222. });
  1223. $scope.onSearch = function (keyword) {
  1224. $scope.tableParams.page(1);
  1225. $scope.tableParams.reload();
  1226. $scope.tip = keyword;
  1227. }
  1228. $scope.search = function (name) {
  1229. $modal.open({
  1230. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1231. controller: 'FuzzySearchCtrl',
  1232. resolve: {
  1233. name: function () {
  1234. return name
  1235. }
  1236. }
  1237. }).result.then(function (data) {
  1238. });
  1239. };
  1240. // 再次邀请
  1241. $scope.reInvite = function (id) {
  1242. var modalInstance = $modal.open({
  1243. animation: true,
  1244. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1245. controller: 'ReInviteCtrl',
  1246. resolve: {
  1247. id: function () {
  1248. return id
  1249. }
  1250. }
  1251. });
  1252. modalInstance.result.then(function (data) {
  1253. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1254. if (data.success) {
  1255. toaster.pop('success', '提示', data.success);
  1256. $scope.tableParams.reload();
  1257. }
  1258. if (data.error) {
  1259. toaster.pop('error', '提示', data.error);
  1260. }
  1261. }, function (response) {
  1262. toaster.pop('error', '提示', response.data);
  1263. });
  1264. });
  1265. }
  1266. }]);
  1267. /**
  1268. * 模糊查询相似的企业名称
  1269. */
  1270. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function ($scope, name, InvitationRecord, toaster, BaseService) {
  1271. $scope.name = name;
  1272. if ($scope.name != null) {
  1273. InvitationRecord.enterpriseList({name: $scope.name}, {}, function (data) {
  1274. $scope.enterprises = data;
  1275. }, function (response) {
  1276. toaster.pop('error', '提示', response.data);
  1277. });
  1278. }
  1279. }]);
  1280. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function ($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1281. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1282. //手机号码格式验证
  1283. // var checkTel = function(data){
  1284. // var userTel = data.userTel;
  1285. // $scope.checkResult = false;
  1286. // var telephone = /^1[3|4|5|7|8]\d{9}$/;
  1287. // if(!(telephone).test(userTel)){
  1288. // var modalInstance = $modal.open({
  1289. // animation: true,
  1290. // templateUrl: 'static/tpl/index/account/checkTel.html',
  1291. // controller: 'CheckTelCtrl',
  1292. // backdrop: 'static',
  1293. // keyboard: false,
  1294. // resolve: {
  1295. // user: function(){
  1296. // return data;
  1297. // },
  1298. // }
  1299. // });
  1300. // modalInstance.result.then(function(){
  1301. // }, function(){
  1302. //
  1303. // });
  1304. // } else {
  1305. // $scope.checkResult = true;
  1306. // }
  1307. // };
  1308. AuthenticationService.getAuthentication().success(function (data) {
  1309. if (data.enterprises) {
  1310. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1311. if (data.enterprises.length > 1) {
  1312. var enSelect = [];
  1313. angular.forEach(data.enterprises, function (e) {
  1314. if (e.current)
  1315. data.enterprise = e;
  1316. else
  1317. enSelect.push(e);
  1318. });
  1319. data.enSelect = enSelect;
  1320. }
  1321. }
  1322. $scope.userInfo = data;
  1323. if (data == null || !data.userUU) {
  1324. $scope.isAuthed = false;
  1325. AuthenticationService.redirectSignin();
  1326. } else {
  1327. //跳转到手机号码验证
  1328. // checkTel($scope.userInfo);
  1329. }
  1330. });
  1331. $scope.logout = function () {
  1332. $modal.open({
  1333. templateUrl: 'static/tpl/index/account/logout.html',
  1334. controller: 'LogOutCtrl'
  1335. }).result.then(function (s) {
  1336. if (s) {
  1337. AuthenticationService.logout();
  1338. }
  1339. });
  1340. };
  1341. $scope.switchto = function (enUU) {// 切换企业
  1342. AuthenticationService.reSignin(enUU).success(function () {
  1343. $window.location.reload();
  1344. });
  1345. };
  1346. $scope.addFavorite = function () {
  1347. var url = encodeURI(window.location.href);
  1348. try {
  1349. //ie浏览器收藏方式
  1350. window.external.addFavorite(url, "优软商务平台");
  1351. } catch (e) {
  1352. try {
  1353. //火狐浏览器收藏方式
  1354. window.sidebar.addPanel("优软商务平台", url);
  1355. } catch (e) {
  1356. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加," +
  1357. "或手动在浏览器里进行设置。");
  1358. }
  1359. }
  1360. };
  1361. }]);
  1362. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1363. $scope.close = function (confirm) {
  1364. $modalInstance.close(confirm);
  1365. };
  1366. }]);
  1367. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1368. $scope.image = {src: null};
  1369. // 图片上传成功之后
  1370. $scope.onUploadSuccess = function (data) {
  1371. var path = data.path;
  1372. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1373. $scope.$apply(function () {
  1374. $scope.image.src = data.path;
  1375. $scope.image.thumb = path;
  1376. });
  1377. };
  1378. $scope.close = function () {
  1379. $modalInstance.dismiss();
  1380. };
  1381. $scope.confirm = function () {
  1382. $modalInstance.close($scope.image);
  1383. $scope.imageUrl = null;
  1384. };
  1385. }]);
  1386. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function ($scope, SnapshotService, BaseService, $rootScope) {
  1387. BaseService.scrollBackToTop();
  1388. SnapshotService.getTodo(function (data) {
  1389. $scope.todo = data;
  1390. });
  1391. var getUnread = function () {
  1392. SnapshotService.getUnread('all', function (data) {
  1393. $scope.unread = data;
  1394. });
  1395. };
  1396. getUnread();
  1397. //去除红点
  1398. $scope.setOrdersRead = function (type) {
  1399. switch (type){
  1400. case 'product':
  1401. $scope.unread.product = 0;
  1402. break;
  1403. case 'vendorPerformanceAssess':
  1404. $scope.unread.vendorPerformanceAssess = 0;
  1405. break;
  1406. case 'customer':
  1407. $scope.unread.customer = 0;
  1408. break;
  1409. case 'purcProduct':
  1410. $scope.unread.purcProduct = 0;
  1411. break;
  1412. case 'vendor':
  1413. $scope.unread.purcVendor = 0;
  1414. break;
  1415. }
  1416. };
  1417. $scope.setTenderActive = function (active) {
  1418. $rootScope.tenderActive = active;
  1419. window.location.hash = '#/purc/tender';
  1420. }
  1421. }]);
  1422. // header
  1423. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1424. SnapshotService.getMessage(function (data) {
  1425. $scope.message = data;
  1426. });
  1427. }]);
  1428. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function ($scope, $rootScope, $modal, SaleTruck) {
  1429. SaleTruck.query({}, function (data) {
  1430. $rootScope.truck = data;
  1431. $scope.truckCount = data ? data.length : 0;
  1432. });
  1433. $scope.$watch(function () {
  1434. return $rootScope.truck;
  1435. }, function (data) {
  1436. $scope.truckCount = data ? data.length : 0;
  1437. }, true);
  1438. $scope.clearAll = function () {
  1439. SaleTruck.remove({}, function () {
  1440. $rootScope.truck = [];
  1441. });
  1442. };
  1443. $scope.openTrack = function () {
  1444. $modal.open({
  1445. templateUrl: 'static/tpl/index/sale/track.html',
  1446. controller: 'TruckModalCtrl',
  1447. size: 'lg'
  1448. }).result.then(function (s) {
  1449. if (s) {
  1450. $scope.clearAll();
  1451. $rootScope.dataChanged = true;
  1452. }
  1453. });
  1454. };
  1455. }]);
  1456. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', 'token', function ($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout, token) {
  1457. $scope.saleSend = {sendItems: []};
  1458. SaleTruck.detail({}, function (data) {
  1459. // 按物料编号排序
  1460. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1461. });
  1462. $scope.remove = function (index, notice) {
  1463. SaleTruck.remove({noticeId: notice.id}, function (data) {
  1464. $rootScope.truck = data;
  1465. $scope.notices.splice(index, 1);
  1466. });
  1467. };
  1468. $scope.$watch(function () {
  1469. return $scope.notices;
  1470. }, function (data) {
  1471. var q = 0, t = 0;
  1472. if (data) {
  1473. angular.forEach(data, function (d) {
  1474. q += d.thisSendQty;
  1475. t += d.thisSendQty * d.orderItem.price;
  1476. });
  1477. }
  1478. $scope.totalQty = q;
  1479. $scope.total = t;
  1480. }, true);
  1481. $scope.cancel = function () {
  1482. $modalInstance.close();
  1483. };
  1484. $scope.lockstatus = false;
  1485. // 锁定时间按钮5秒
  1486. $scope.lockClick = function () {
  1487. $scope.lockstatus = true;
  1488. $timeout(function () {
  1489. $scope.lockstatus = false;
  1490. }, 5000);
  1491. }
  1492. var getToken = function() {
  1493. token.info({userType: 'salenotice'}, {}, function(data) {
  1494. $scope.token = data.token;
  1495. }, function(response) {
  1496. toaster.pop('error', '提示', response.data);
  1497. });
  1498. }
  1499. getToken();
  1500. $scope.send = function () {// 发货
  1501. if (!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1502. toaster.pop('error', '错误', '请输入送货单号');
  1503. return;
  1504. }
  1505. var currency = $scope.notices[0].orderItem.order.currency,
  1506. custUU = $scope.notices[0].enUU,
  1507. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1508. var num = 1;
  1509. for (var i in $scope.notices) {
  1510. var item = $scope.notices[i];
  1511. if (item.id) {
  1512. if (item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1513. valid = false;
  1514. break;
  1515. }
  1516. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++};
  1517. }
  1518. }
  1519. if (!valid) {
  1520. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致、采购员一致才能一起发货。');
  1521. } else {
  1522. var send = angular.extend(angular.copy($scope.saleSend), {
  1523. currency: currency,
  1524. custUU: custUU,
  1525. payments: payments,
  1526. sendItems: items
  1527. });
  1528. if($scope.token != null) {
  1529. PurcNotice.sendByBatch({token: $scope.token}, send, function (data) {
  1530. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1531. $modalInstance.close(true);
  1532. $state.go('sale.send_detail', {id: data.id});
  1533. }, function (response) {
  1534. toaster.pop('error', '错误', response.data);
  1535. });
  1536. }
  1537. }
  1538. $scope.setCheckedNoticeRead = function () {
  1539. var ids = [];
  1540. for (var i in $scope.notices) {
  1541. var item = $scope.notices[i];
  1542. if (item.id) {
  1543. ids.push(item.id);
  1544. }
  1545. }
  1546. PurcNotice.setRead({}, ids, function (message) {
  1547. });
  1548. }
  1549. };
  1550. }]);
  1551. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1552. SaleStat.cust({}, function (data) {
  1553. var p = [], q = [];
  1554. angular.forEach(data.month, function (d) {
  1555. p.push({
  1556. x: (d.enterprise.enShortname || d.enterprise.enName),
  1557. y: [(d.total || 0)],
  1558. tooltip: (d.total || 0)
  1559. });
  1560. });
  1561. angular.forEach(data.year, function (d) {
  1562. q.push({
  1563. x: (d.enterprise.enShortname || d.enterprise.enName),
  1564. y: [(d.total || 0)],
  1565. tooltip: (d.total || 0)
  1566. });
  1567. });
  1568. $scope.custCharts = {
  1569. month: {
  1570. chartType: 'pie',
  1571. datas: {
  1572. data: p
  1573. },
  1574. config: {
  1575. labels: false,
  1576. title: "客户月采购量排行榜",
  1577. legend: {
  1578. display: true,
  1579. position: 'right'
  1580. },
  1581. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1582. click: function (d) {
  1583. },
  1584. mouseover: function (d) {
  1585. },
  1586. mouseout: function (d) {
  1587. },
  1588. innerRadius: 0,
  1589. lineLegend: 'lineEnd'
  1590. }
  1591. },
  1592. year: {
  1593. chartType: 'pie',
  1594. datas: {
  1595. data: q
  1596. },
  1597. config: {
  1598. labels: false,
  1599. title: "客户年采购量排行榜",
  1600. legend: {
  1601. display: true,
  1602. position: 'right'
  1603. },
  1604. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1605. click: function (d) {
  1606. },
  1607. mouseover: function (d) {
  1608. },
  1609. mouseout: function (d) {
  1610. },
  1611. innerRadius: 0,
  1612. lineLegend: 'lineEnd'
  1613. }
  1614. }
  1615. };
  1616. });
  1617. SaleStat.seller({}, function (data) {
  1618. var p = [], q = [];
  1619. angular.forEach(data.month, function (d) {
  1620. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1621. });
  1622. angular.forEach(data.year, function (d) {
  1623. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1624. });
  1625. $scope.sellerCharts = {
  1626. month: {
  1627. chartType: 'pie',
  1628. datas: {
  1629. data: p
  1630. },
  1631. config: {
  1632. labels: false,
  1633. title: "业务员月销量排行榜",
  1634. legend: {
  1635. display: true,
  1636. position: 'right'
  1637. },
  1638. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1639. click: function (d) {
  1640. },
  1641. mouseover: function (d) {
  1642. },
  1643. mouseout: function (d) {
  1644. },
  1645. innerRadius: 0,
  1646. lineLegend: 'lineEnd'
  1647. }
  1648. },
  1649. year: {
  1650. chartType: 'pie',
  1651. datas: {
  1652. data: q
  1653. },
  1654. config: {
  1655. labels: false,
  1656. title: "业务员年销量排行榜",
  1657. legend: {
  1658. display: true,
  1659. position: 'right'
  1660. },
  1661. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1662. click: function (d) {
  1663. },
  1664. mouseover: function (d) {
  1665. },
  1666. mouseout: function (d) {
  1667. },
  1668. innerRadius: 0,
  1669. lineLegend: 'lineEnd'
  1670. }
  1671. }
  1672. };
  1673. });
  1674. }]);
  1675. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1676. SaleStat.get({}, function (data) {
  1677. var p = [], q = [], r = [];
  1678. angular.forEach(data.day, function (d) {
  1679. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1680. });
  1681. angular.forEach(data.month, function (d) {
  1682. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1683. });
  1684. angular.forEach(data.year, function (d) {
  1685. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1686. });
  1687. $scope.charts = {
  1688. day: {
  1689. chartType: "line",
  1690. datas: {
  1691. series: ['销售额'],
  1692. data: p
  1693. },
  1694. config: {
  1695. "labels": false,
  1696. "title": "销售额统计(近15日线)",
  1697. "legend": {
  1698. "display": true,
  1699. "position": "right"
  1700. },
  1701. colors: ['#4D9934'],
  1702. "innerRadius": 0,
  1703. "lineLegend": "lineEnd"
  1704. }
  1705. },
  1706. month: {
  1707. chartType: "line",
  1708. datas: {
  1709. series: ['销售额'],
  1710. data: q
  1711. },
  1712. config: {
  1713. "labels": false,
  1714. "title": "销售额统计(近12月线)",
  1715. "legend": {
  1716. "display": true,
  1717. "position": "right"
  1718. },
  1719. colors: ['#4D9934'],
  1720. "innerRadius": 0,
  1721. "lineLegend": "lineEnd"
  1722. }
  1723. },
  1724. year: {
  1725. chartType: "line",
  1726. datas: {
  1727. series: ['销售额'],
  1728. data: r
  1729. },
  1730. config: {
  1731. "labels": false,
  1732. "title": "销售额统计(近10年线)",
  1733. "legend": {
  1734. "display": true,
  1735. "position": "right"
  1736. },
  1737. colors: ['#4D9934'],
  1738. "innerRadius": 0,
  1739. "lineLegend": "lineEnd"
  1740. }
  1741. }
  1742. };
  1743. });
  1744. }]);
  1745. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1746. SnapshotService.getNotice(5, function (data) { //5表示首页显示的公告条数
  1747. $scope.notices = data;
  1748. });
  1749. $scope.dateTime = new Date();
  1750. }]);
  1751. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1752. // SnapshotService.getTender(250, function(data){
  1753. // $scope.tenders = data;
  1754. // var newDate = new Date();
  1755. // newDate = newDate.setDate(newDate.getDate() - 3);
  1756. // angular.forEach($scope.tenders, function(tender) {
  1757. // if (tender.date > newDate) {
  1758. // tender.isNew = true;
  1759. // } else {
  1760. // tender.isNew = false;
  1761. // }
  1762. // });
  1763. // });
  1764. SnapshotService.getOpenTender(5, function (data) {
  1765. $scope.openTenders = data;
  1766. var newDate = new Date();
  1767. newDate = newDate.getTime() - 3 * 24 * 60 * 60 * 1000;
  1768. angular.forEach($scope.openTenders, function (tender) {
  1769. if (tender.date - newDate > 0) {
  1770. tender.isNew = true;
  1771. } else {
  1772. tender.isNew = false;
  1773. }
  1774. });
  1775. });
  1776. $scope.dateTime = new Date();
  1777. }]);
  1778. app.controller('VendCountCtrl', ['$scope', 'VendorService', function ($scope, VendorService) {
  1779. VendorService.getCount(function (date) {
  1780. $scope.count = date;
  1781. });
  1782. }]);
  1783. // 客户
  1784. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  1785. BaseService.scrollBackToTop();
  1786. $scope.userInfoResult = true;
  1787. AuthenticationService.getAuthentication().success(function (data) {
  1788. $scope.loading = false;
  1789. $scope.thisUser = data;
  1790. });
  1791. // 获取当前用户分配客户的操作权限
  1792. CurrentRole.roles({}, function (data) {
  1793. $scope.enabled = data.count > 0 ? true : false ;
  1794. }, function (response) {
  1795. });
  1796. var getCustInfos = function (custuu) {
  1797. if (custuu) {
  1798. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  1799. $scope.custInfos = data;
  1800. var getPage = function (page, size) {
  1801. if ($scope.custInfos) {
  1802. var result = {};
  1803. result.totalCount = $scope.custInfos.length;
  1804. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  1805. if ($scope.custInfos.length % size == 0) {
  1806. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1807. } else {
  1808. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1809. }
  1810. result.first = page == 1;
  1811. result.last = page == result.totalPage;
  1812. result.page = page;
  1813. result.next = page - 0 + 1;
  1814. result.pre = page - 1;
  1815. return result;
  1816. }
  1817. }
  1818. $scope.userdata = getPage(1, 4);
  1819. $scope.first = function () {
  1820. $scope.userdata = getPage($scope.userdata.pre, 4);
  1821. }
  1822. $scope.last = function () {
  1823. $scope.userdata = getPage($scope.userdata.next, 4);
  1824. }
  1825. }, function (response) {
  1826. $scope.loading = false;
  1827. toaster.pop('error', '数据加载失败', response.data);
  1828. });
  1829. }
  1830. }
  1831. // 分配用户
  1832. $scope.addUserInfo = function (customer) {
  1833. if (!$scope.enabled) {
  1834. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  1835. return;
  1836. }
  1837. // 获取当前用户在当前企业是否被转移权限
  1838. AccountUser.getEnTransfer ({custUU: customer.myEnterprise.uu}, function(data) {
  1839. customer.enTransfer = data.result;
  1840. //是管理员,或者被转移了权限时
  1841. if ($scope.enabled || customer.enTransfer) {
  1842. var modalInstance = $modal.open({
  1843. animation: true,
  1844. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1845. controller: 'AddUserInfoCtrl',
  1846. resolve: {
  1847. customer: function () {
  1848. return customer;
  1849. }
  1850. }
  1851. });
  1852. modalInstance.result.then(function (changed, checked) {
  1853. if (changed) {
  1854. if (checked)
  1855. $scope.newUser.roles = checked;
  1856. else
  1857. loadUsers();
  1858. }
  1859. });
  1860. } else {
  1861. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  1862. }
  1863. });
  1864. };
  1865. // 转移权限
  1866. $scope.transferUserInfo = function (customer) {
  1867. customer.enDistribute = null;
  1868. if (!$scope.enabled) {
  1869. toaster.pop('error', '您没有转移当前客户权限的权限!');
  1870. return;
  1871. }
  1872. // 获取当前用户在当前企业是否被转移权限
  1873. AccountUser.getDistribute ({custUU: customer.myEnterprise.uu}, function(data) {
  1874. customer.enDistribute = data.result;
  1875. //是管理员,或者被分配时
  1876. if ($scope.enabled || customer.enDistribute) {
  1877. var modalInstance = $modal.open({
  1878. animation: true,
  1879. templateUrl: 'static/tpl/index/account/transfer_userInfo.html',
  1880. controller: 'TransferUserInfoCtrl',
  1881. resolve: {
  1882. customer: function () {
  1883. return customer;
  1884. }
  1885. }
  1886. });
  1887. modalInstance.result.then(function (changed, checked) {
  1888. if (changed) {
  1889. if (checked)
  1890. $scope.newUser.roles = checked;
  1891. else
  1892. loadUsers();
  1893. }
  1894. });
  1895. } else {
  1896. toaster.pop('error', '您没有转移当前客户权限的权限!');
  1897. }
  1898. });
  1899. };
  1900. $scope.showUserInfo = function (customer, boo) {
  1901. $scope.custInfo = customer;
  1902. if (boo) {
  1903. getCustInfos(customer.myEnterprise.uu);
  1904. $scope.userInfoResult = true;
  1905. }
  1906. };
  1907. var getService = function () {
  1908. return VendorService;
  1909. };
  1910. $scope.customerParams = new ngTableParams({
  1911. page: 1,
  1912. count: 20
  1913. }, {
  1914. total: 0,
  1915. counts: [5, 10, 25, 50],
  1916. getData: function ($defer, params) {
  1917. $scope.loading = true;
  1918. var pageParams = params.url();
  1919. pageParams.keyword = $scope.keyword;
  1920. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  1921. $scope.loading = false;
  1922. if (page) {
  1923. params.total(page.totalElement);
  1924. $defer.resolve(page.content);
  1925. $scope.keywordXls = pageParams.keyword;
  1926. }
  1927. $scope.totalCount = page.totalElement;
  1928. }, function (response) {
  1929. $scope.loading = false;
  1930. toaster.pop('error', '数据加载失败', response.data);
  1931. });
  1932. }
  1933. });
  1934. //设置消息已读
  1935. var setOrdersRead = function () {
  1936. var sourceId = [];
  1937. Vendor.setRead({}, sourceId, function (message) {
  1938. // $scope.getUnreadIds();
  1939. });
  1940. };
  1941. setOrdersRead();
  1942. // 搜索框回车
  1943. $scope.onSearch = function (keyword) {
  1944. $scope.customerParams.page(1);
  1945. $scope.customerParams.reload();
  1946. $scope.tip = keyword;
  1947. };
  1948. // 查看详情
  1949. $scope.viewDetail = function (id) {
  1950. window.location.hash = "#/sale/customer/" + id;
  1951. }
  1952. // 导出客户资料列表
  1953. $scope.exportXls = function () {
  1954. VendorService.exportXls.get({}, {}, function (data) {
  1955. if (data.success){
  1956. window.location.href = 'vendor/customer/xls?keyword='+ ($scope.keywordXls || '');
  1957. }
  1958. }, function (response) {
  1959. toaster.pop('error', '数据加载失败', response.data);
  1960. });
  1961. }
  1962. }]);
  1963. // 客户详情
  1964. 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) {
  1965. BaseService.scrollBackToTop();
  1966. $scope.userInfoResult = true;
  1967. AuthenticationService.getAuthentication().success(function (data) {
  1968. $scope.loading = false;
  1969. $scope.thisUser = data;
  1970. });
  1971. $scope.vendorContacts = [];
  1972. var loadData = function () {
  1973. Vendor.getCustomerDetail({id: $stateParams.id}, {}, function (data) {
  1974. $scope.customer = data.myEnterprise;
  1975. $scope.customerInfo = data;
  1976. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function (data) {
  1977. $scope.Contacts = data;
  1978. });
  1979. // 查看已分配人员
  1980. VendorService.userInfo.query({uu: $scope.customer.uu}, null, function (data) {
  1981. $scope.custInfos = data;
  1982. var getPage = function (page, size) {
  1983. if ($scope.custInfos) {
  1984. var result = {};
  1985. result.totalCount = $scope.custInfos.length;
  1986. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  1987. if ($scope.custInfos.length % size == 0) {
  1988. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1989. } else {
  1990. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1991. }
  1992. result.first = page == 1;
  1993. result.last = page == result.totalPage;
  1994. result.page = page;
  1995. result.next = page - 0 + 1;
  1996. result.pre = page - 1;
  1997. return result;
  1998. }
  1999. }
  2000. $scope.userdata = getPage(1, 4);
  2001. $scope.first = function () {
  2002. $scope.userdata = getPage($scope.userdata.pre, 4);
  2003. }
  2004. $scope.last = function () {
  2005. $scope.userdata = getPage($scope.userdata.next, 4);
  2006. }
  2007. }, function (response) {
  2008. $scope.loading = false;
  2009. toaster.pop('error', '数据加载失败', response.data);
  2010. });
  2011. }, function (response) {
  2012. $scope.loading = false;
  2013. toaster.pop('error', '数据加载失败', response.data);
  2014. });
  2015. };
  2016. loadData();
  2017. // 新增客户联系人
  2018. $scope.addContact = function (uu) {
  2019. var modalInstance = $modal.open({
  2020. animation: true,
  2021. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2022. controller: 'AddContacCtrl',
  2023. resolve: {}
  2024. });
  2025. modalInstance.result.then(function (data) {
  2026. $scope.contact = data;
  2027. $scope.contact.myenuu = uu;
  2028. Vendor.saveCustContact({}, $scope.contact, function (data) {
  2029. toaster.pop('success', '提示', '联系人保存成功');
  2030. $scope.Contacts.push(data);
  2031. }, function (response) {
  2032. toaster.pop('error', '失败', response.data);
  2033. });
  2034. });
  2035. }
  2036. // 编辑客户联系人
  2037. $scope.edit = function (contact) {
  2038. var modalInstance = $modal.open({
  2039. animation: true,
  2040. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2041. controller: 'EditContacCtrl',
  2042. resolve: {
  2043. contact: function () {
  2044. return contact;
  2045. }
  2046. }
  2047. });
  2048. modalInstance.result.then(function (data) {
  2049. Vendor.saveContact({}, data, function (data) {
  2050. loadData();
  2051. toaster.pop('success', '提示', '联系人修改成功');
  2052. }, function (response) {
  2053. toaster.pop('error', '失败', response.data);
  2054. });
  2055. });
  2056. }
  2057. // 删除客户联系人
  2058. $scope.deleteById = function (id, index) {
  2059. $scope.Contacts.splice(index, 1);
  2060. Vendor.deleteContact({id: id}, {}, function (data) {
  2061. toaster.pop('success', '提示', '客户联系人删除成功');
  2062. loadData();
  2063. }, function (response) {
  2064. toaster.pop('error', '提示', response.data);
  2065. });
  2066. }
  2067. // 供应商物料信息
  2068. $scope.viewProdList = function (uu) {
  2069. $scope.uu = uu;
  2070. $scope.tableParams.page(1);
  2071. $scope.tableParams.reload();
  2072. };
  2073. // 搜索框回车
  2074. $scope.onSearch = function (keyword) {
  2075. $scope.keyword = keyword;
  2076. $scope.tableParams.page(1);
  2077. $scope.tableParams.reload();
  2078. };
  2079. // 供应商物料信息
  2080. $scope.tableParams = new ngTableParams({
  2081. page: 1,
  2082. count: 20
  2083. }, {
  2084. total: 0,
  2085. counts: [5, 10, 25, 50],
  2086. getData: function ($defer, params) {
  2087. $scope.loading = true;
  2088. var pageParams = params.url();
  2089. pageParams.custUU = $scope.uu;
  2090. pageParams.keyword = $scope.keyword;
  2091. $scope.tip = $scope.keyword;
  2092. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  2093. $scope.loading = false;
  2094. if (page) {
  2095. params.total(page.totalElement);
  2096. $scope.total = page.totalElement;
  2097. $defer.resolve(page.content);
  2098. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2099. }
  2100. }, function (response) {
  2101. $scope.loading = false;
  2102. toaster.pop('error', '数据加载失败', response.data);
  2103. });
  2104. }
  2105. });
  2106. $scope.addUserInfo = function () {
  2107. //TODO
  2108. if ($scope.thisUser.sys) {
  2109. var modalInstance = $modal.open({
  2110. animation: true,
  2111. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2112. controller: 'AddUserInfoCtrl',
  2113. resolve: {
  2114. customer: function () {
  2115. return $scope.customerInfo;
  2116. }
  2117. }
  2118. });
  2119. modalInstance.result.then(function (changed, checked) {
  2120. loadData();
  2121. if (changed) {
  2122. if (checked) {
  2123. $scope.newUser.roles = checked;
  2124. } else {
  2125. loadUsers();
  2126. }
  2127. }
  2128. });
  2129. } else {
  2130. toaster.pop('error', '您不是管理员,无权限分配用户!');
  2131. }
  2132. }
  2133. $scope.Quotation = function (uu, id) {
  2134. $rootScope.custuu = uu;
  2135. $rootScope.prodId = id;
  2136. window.location.hash = "#/sale/quotation/new";
  2137. }
  2138. }]);
  2139. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function ($scope, $modalInstance, customer, AccountUser, toaster) {
  2140. $scope.checkboxes = {
  2141. checked: false
  2142. };
  2143. $scope.loading = true;
  2144. $scope.distribute = [];
  2145. AccountUser.findUsers({uu: customer.myEnterprise.uu}, null, function (data) {
  2146. $scope.userinfos = data;
  2147. var distribute = [];
  2148. angular.forEach($scope.userinfos, function (user, index) {
  2149. if (user.distribute) {
  2150. distribute.push({num: index});
  2151. }
  2152. });
  2153. $scope.distribute = distribute;
  2154. $scope.havedone = angular.copy($scope.distribute);
  2155. $scope.loading = false;
  2156. })
  2157. var checkStatus = function (userinfos) {
  2158. var distribute = [];
  2159. angular.forEach(userinfos, function (user, index) {
  2160. if (user.distribute) {
  2161. distribute.push({num: index});
  2162. }
  2163. });
  2164. $scope.distribute = distribute;
  2165. $scope.isChanged = !angular.equals($scope.havedone, $scope.distribute);
  2166. }
  2167. $scope.isChanged = false;
  2168. $scope.isChangedAll = false;
  2169. $scope.changes = [];
  2170. // 点击勾选全部的复选框
  2171. $scope.checkAll = function () {
  2172. angular.forEach($scope.userinfos, function (item, index) {
  2173. item.distribute = $scope.checkboxes.checked;
  2174. });
  2175. checkStatus($scope.userinfos);
  2176. };
  2177. // 点击其中一个明细的复选框
  2178. $scope.checkOne = function () {
  2179. var result = true;
  2180. angular.forEach($scope.userinfos, function (item) {
  2181. if (item.distribute != true) {
  2182. result = false;
  2183. return;
  2184. }
  2185. });
  2186. $scope.checkboxes.checked = result;
  2187. checkStatus($scope.userinfos);
  2188. };
  2189. $scope.close = function (save) {
  2190. var chooseResult = [];
  2191. if (save) {
  2192. if (customer.myEnterprise.uu) {
  2193. angular.forEach($scope.userinfos, function (item, i) {
  2194. chooseResult.push(item);
  2195. });
  2196. if (chooseResult.length > 0) {
  2197. $scope.loading = true;
  2198. AccountUser.addUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2199. $scope.loading = false;
  2200. toaster.pop('success', '提示', '保存成功');
  2201. $modalInstance.close(false);
  2202. }, function (response) {
  2203. $scope.loading = false;
  2204. toaster.pop('error', '保存失败', response.data);
  2205. $modalInstance.close(false);
  2206. })
  2207. } else {
  2208. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2209. }
  2210. } else {
  2211. $modalInstance.close(true, $scope.checkboxes.checked);
  2212. }
  2213. } else {
  2214. $modalInstance.close(false);
  2215. }
  2216. };
  2217. }]);
  2218. // 转移权限
  2219. app.controller('TransferUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', 'AuthenticationService', function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
  2220. AuthenticationService.getAuthentication().success(function (data) {
  2221. $scope.loading = false;
  2222. $scope.thisUser = data;
  2223. });
  2224. $scope.checkboxes = {
  2225. checked: false
  2226. };
  2227. $scope.loading = true;
  2228. $scope.transfer = [];
  2229. AccountUser.findUsers({uu: customer.myEnterprise.uu}, {}, function (data) {
  2230. $scope.userinfos = data;
  2231. var transfer = [];
  2232. angular.forEach($scope.userinfos, function (user, index) {
  2233. // 当前用户是被管理员转移权限时,转移的是被管理员转移的权限。
  2234. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2235. $scope.thisUser.transfer = true;
  2236. }
  2237. });
  2238. angular.forEach($scope.userinfos, function (user, index) {
  2239. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2240. if (user.transfer) {
  2241. transfer.push({num: index});
  2242. user.checked = true;
  2243. }
  2244. } else {
  2245. if (user.distribute) {
  2246. transfer.push({num: index});
  2247. user.checked = true;
  2248. }
  2249. }
  2250. });
  2251. $scope.transfer = transfer;
  2252. $scope.havedone = angular.copy($scope.transfer);
  2253. $scope.loading = false;
  2254. });
  2255. var checkStatus = function (userinfos) {
  2256. var transfer = [];
  2257. angular.forEach(userinfos, function (user, index) {
  2258. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2259. if (user.transfer) {
  2260. transfer.push({num: index});
  2261. }
  2262. } else {
  2263. if (user.distribute) {
  2264. transfer.push({num: index});
  2265. }
  2266. }
  2267. });
  2268. $scope.transfer = transfer;
  2269. $scope.isChanged = !angular.equals($scope.havedone, $scope.transfer);
  2270. };
  2271. $scope.isChanged = false;
  2272. $scope.isChangedAll = false;
  2273. $scope.changes = [];
  2274. // 点击其中一个明细的复选框
  2275. $scope.checkOne = function (user) {
  2276. $scope.changes = [];
  2277. if ($scope.thisUser.sys) { // 管理员操作
  2278. user.$checked = !user.$checked;
  2279. angular.forEach($scope.userinfos, function (userInfo) {
  2280. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2281. $scope.thisUser.transfer = true;
  2282. }
  2283. if (user.userUU !== userInfo.userUU) {
  2284. userInfo.transfer = false;
  2285. }
  2286. });
  2287. } else if ($scope.thisUser.transfer) { // 被管理员转移权限的非管理员操作
  2288. user.$checked = !user.$checked;
  2289. angular.forEach($scope.userinfos, function (userInfo) {
  2290. if (user.userUU !== userInfo.userUU) {
  2291. userInfo.transfer = false;
  2292. } else {
  2293. userInfo.transfer = true;
  2294. }
  2295. });
  2296. } else { // 被分配客户的用户
  2297. user.$checked = !user.$checked;
  2298. angular.forEach($scope.userinfos, function (userInfo) {
  2299. if (user.userUU !== userInfo.userUU) {
  2300. userInfo.distribute = false;
  2301. } else {
  2302. userInfo.distribute = true;
  2303. }
  2304. });
  2305. }
  2306. checkStatus($scope.userinfos);
  2307. };
  2308. $scope.close = function (save) {
  2309. var chooseResult = [];
  2310. if (save) {
  2311. if (customer.myEnterprise.uu) {
  2312. // 当前用户是管理员时
  2313. if ($scope.thisUser.sys) {
  2314. angular.forEach($scope.userinfos, function (item, i) {
  2315. chooseResult.push(item);
  2316. });
  2317. if (chooseResult.length > 0) {
  2318. $scope.loading = true;
  2319. AccountUser.transferUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2320. $scope.loading = false;
  2321. toaster.pop('success', '提示', '保存成功');
  2322. $modalInstance.close(false);
  2323. }, function (response) {
  2324. $scope.loading = false;
  2325. toaster.pop('error', '保存失败', response.data);
  2326. $modalInstance.close(false);
  2327. })
  2328. } else {
  2329. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2330. }
  2331. } else {
  2332. // 非管理员转移自己的权限时
  2333. angular.forEach($scope.userinfos, function (item, i) {
  2334. if (item.transfer && item.userUU !== $scope.thisUser.userUU) {
  2335. $scope.target = item;
  2336. }
  2337. });
  2338. if (!$scope.target) {
  2339. toaster.pop('error', '保存失败', "您未选择权限转移对象");
  2340. } else {
  2341. $scope.loading = true;
  2342. AccountUser.transferMyDistribute({custUU: customer.myEnterprise.uu, userUU: $scope.target.userUU}, {} ,function (data) {
  2343. $scope.loading = false;
  2344. toaster.pop('success', '提示', '保存成功');
  2345. $modalInstance.close(false);
  2346. }, function (response) {
  2347. $scope.loading = false;
  2348. toaster.pop('error', '保存失败', response.data);
  2349. $modalInstance.close(false);
  2350. });
  2351. }
  2352. }
  2353. } else {
  2354. $modalInstance.close(true, $scope.checkboxes.checked);
  2355. }
  2356. } else {
  2357. $modalInstance.close(false);
  2358. }
  2359. };
  2360. }]);
  2361. /**
  2362. * 页面状态按钮过滤
  2363. */
  2364. var getState = function (active) {
  2365. var fn = 'get';
  2366. switch (active) {
  2367. case 'done':
  2368. fn = 'getDone';
  2369. break;
  2370. case 'todo':
  2371. fn = 'getTodo';
  2372. break;
  2373. case 'end':
  2374. fn = 'getEnd';
  2375. break;
  2376. case 'waiting':
  2377. fn = 'getWaiting';
  2378. break;
  2379. case 'received':
  2380. fn = 'getReceived';
  2381. break;
  2382. case 'invalid':
  2383. fn = 'getInvalid';
  2384. break;
  2385. // 已采纳
  2386. case 'agreed':
  2387. fn = 'getAgreed';
  2388. break;
  2389. // 未采纳
  2390. case 'refused':
  2391. fn = 'getRefused';
  2392. break;
  2393. // 个人
  2394. case 'personal':
  2395. fn = 'getPersonal';
  2396. break;
  2397. // 集体
  2398. case 'teams':
  2399. fn = 'getTeams';
  2400. break;
  2401. // 非标准
  2402. case 'nonstandard':
  2403. fn = 'getNonstandard';
  2404. break;
  2405. // 标准
  2406. case 'standard':
  2407. fn = 'getStandard';
  2408. break;
  2409. // 变更单无需确认
  2410. case 'unread':
  2411. fn = 'getUnread';
  2412. break;
  2413. }
  2414. return fn;
  2415. };
  2416. /**
  2417. * 改变单据日期范围
  2418. */
  2419. var getDateCondition = function (zone, condition) {
  2420. var fromDate = new Date();
  2421. var toDate = new Date();
  2422. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  2423. fromDate.setHours(0, 0, 0, 0);
  2424. toDate.setHours(23, 59, 59, 999);
  2425. if (zone == -1) { // 自定义时间,什么都不做
  2426. } else if (zone == 1) {
  2427. fromDate.setMonth(fromDate.getMonth() - 1);
  2428. condition.dateFrom = fromDate;
  2429. condition.dateTo = toDate;
  2430. } else if (zone == 3) {
  2431. fromDate.setMonth(fromDate.getMonth() - 3);
  2432. condition.dateFrom = fromDate;
  2433. condition.dateTo = toDate;
  2434. } else if (zone == 6) {
  2435. fromDate.setMonth(fromDate.getMonth() - 6);
  2436. condition.dateFrom = fromDate;
  2437. condition.dateTo = toDate;
  2438. } else {
  2439. condition.dateFrom = null;
  2440. condition.dateTo = null;
  2441. }
  2442. };
  2443. /**
  2444. * 改变单据交货日期范围
  2445. */
  2446. var getDelveryCondition = function (zone, condition) {
  2447. var date = new Date();
  2448. if (zone == -1) {
  2449. condition.deliveryFrom = null;
  2450. condition.deliveryTo = null;
  2451. } else if (zone == 1) {
  2452. date.setMonth(date.getMonth() + 1);
  2453. condition.deliveryTo = date;
  2454. condition.deliveryFrom = new Date();
  2455. } else if (zone == 2) {
  2456. date.setMonth(date.getMonth() + 2);
  2457. condition.deliveryTo = date;
  2458. condition.deliveryFrom = new Date();
  2459. }
  2460. };
  2461. /**
  2462. * 将日期转化为整数日期
  2463. */
  2464. var getDateTime = function (date) {
  2465. if (angular.isDate(date)) {
  2466. return date.getTime();
  2467. } else {
  2468. return null;
  2469. }
  2470. };
  2471. /**
  2472. * 删除数组里某个特定的值
  2473. */
  2474. var removeByValue = function (arr, val) {
  2475. for(var i=0; i<arr.length; i++) {
  2476. if(arr[i] == val) {
  2477. arr.splice(i, 1);
  2478. break;
  2479. }
  2480. }
  2481. };
  2482. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrders', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope', 'PurchaseOrder', 'PurcOrdersInfo', 'PurcOrderItem', 'CurrentRole',
  2483. function ($scope, $filter, PurcOrders, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope, PurchaseOrder, PurcOrdersInfo, PurcOrderItem, CurrentRole) {
  2484. BaseService.scrollBackToTop();
  2485. // 获取当前用户是否为普通用户
  2486. CurrentRole.isUser({}, {}, function (data) {
  2487. $scope.isUser = data.isUser;
  2488. });
  2489. if ($rootScope.active) {
  2490. $scope.active = $rootScope.active;
  2491. $rootScope.active = null;
  2492. } else {
  2493. $scope.active = 'all';
  2494. }
  2495. $scope.dateZoneText = '不限';
  2496. $scope.deliveryZoneText = '不限';
  2497. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2498. /* 时间筛选初始化*/
  2499. var fromDate = new Date();
  2500. var toDate = new Date();
  2501. fromDate.setMonth(fromDate.getMonth() - 1);
  2502. fromDate.setHours(0, 0, 0, 0);
  2503. toDate.setHours(23, 59, 59, 999);
  2504. $scope.condition.dateFrom = fromDate;
  2505. $scope.condition.dateTo = toDate;
  2506. $scope.changeDateZone = function (zone) {
  2507. $scope.condition.dateZone = zone;
  2508. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2509. $scope.condition.$dateZoneOpen = false;
  2510. getDateCondition(zone, $scope.condition);
  2511. $scope.tableParams.page(1);
  2512. $scope.tableParams.reload();
  2513. };
  2514. $scope.changeDeliveryZone = function (zone) {
  2515. $scope.condition.deliveryZoneText = zone;
  2516. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2517. $scope.condition.$delievryZoneOpen = false;
  2518. getDelveryCondition(zone, $scope.condition);
  2519. $scope.tableParams.reload();
  2520. };
  2521. $scope.searchMethod = false;
  2522. var getService = function () {
  2523. return $scope.searchMethod ? PurcOrders : PurcOrdersInfo;
  2524. };
  2525. // 切换单据类型
  2526. $scope.setActive = function (state) {
  2527. if ($scope.active != state) {
  2528. $scope.active = state;
  2529. if ($scope.tableParams.page() == 1)
  2530. $scope.tableParams.reload();
  2531. else
  2532. $scope.tableParams.page(1);
  2533. }
  2534. };
  2535. var getPurcStatus = function (active) {
  2536. var fn = 'getPurcAll';
  2537. switch (active) {
  2538. case 'done':
  2539. fn = 'getPurcDone';
  2540. break;
  2541. case 'todo':
  2542. fn = 'getPurcTodo';
  2543. break;
  2544. case 'end':
  2545. fn = 'getPurcEnd';
  2546. break;
  2547. case 'waiting':
  2548. fn = 'getPurcWaiting';
  2549. break;
  2550. }
  2551. return fn;
  2552. };
  2553. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2554. page: 1,
  2555. count: 20,
  2556. sorting: {
  2557. display: 'desc',
  2558. date: 'desc'
  2559. }
  2560. }, {
  2561. total: 0,
  2562. counts: [5, 10, 15, 25, 50],
  2563. getData: function ($defer, params) {// 获取数据的方法
  2564. $scope.loading = true;
  2565. var pageParams = params.url();
  2566. pageParams.searchFilter = { // 筛选条件
  2567. keyword: $scope.keyword,
  2568. fromDate: getDateTime($scope.condition.dateFrom),
  2569. endDate: getDateTime($scope.condition.dateTo)
  2570. };
  2571. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2572. $scope.loading = false;
  2573. if (page) {
  2574. $defer.resolve(page.content);
  2575. $scope.total = page.totalElement;
  2576. params.total(page.totalElement);
  2577. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2578. }
  2579. }, function (response) {
  2580. $scope.loading = false;
  2581. toaster.pop('error', '数据加载失败', response.data);
  2582. });
  2583. }
  2584. });
  2585. //获得各分类未阅读数量
  2586. var getUnreadCount = function () {
  2587. PurcOrders.getUnreadCount(null, function (data) {
  2588. $scope.unread = data;
  2589. });
  2590. };
  2591. getUnreadCount();
  2592. //设置单据已读
  2593. $scope.setOrdersRead = function (id) {
  2594. // 如果单据本身已读,则不发送请求修改数据
  2595. if (!$scope.isUnread(id)){
  2596. return;
  2597. }
  2598. var sourceId = [];
  2599. sourceId.push(id);
  2600. PurcOrders.setRead({}, sourceId, function (message) {
  2601. // $scope.getUnreadIds();
  2602. getUnreadCount();
  2603. });
  2604. };
  2605. //获取未读单据id
  2606. var getUnreadIds = function () {
  2607. PurcOrders.getUnreadIds({}, "", function (message) {
  2608. $scope.unreadCode = message.content;
  2609. });
  2610. };
  2611. getUnreadIds();
  2612. //判断单据是否未读
  2613. $scope.isUnread = function (id) {
  2614. for (var i in $scope.unreadCode) {
  2615. if (id == $scope.unreadCode[i]) {
  2616. return true;
  2617. }
  2618. }
  2619. };
  2620. $scope.getReply = function (item) {
  2621. if (!item.replies) {
  2622. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2623. item.replies = replies;
  2624. });
  2625. }
  2626. };
  2627. $scope.getOrderTotal = function (items) {
  2628. var sum = 0;
  2629. angular.forEach(items, function (item) {
  2630. sum += item.qty * item.price;
  2631. });
  2632. return sum;
  2633. };
  2634. // 需方 打印 采购单
  2635. $scope.custPrint = function (order) {
  2636. var newPage = window.open("about:blank");
  2637. PurcOrder.printPermission({}, function () {
  2638. PurcOrder.custPrintCount({id: order.id}, {});//增加打印此次
  2639. ReportService.print(order.enUU, 'PURCLIST_CUST', "where purc$orders.pu_id=" + order.id, newPage);
  2640. }, function (response) {
  2641. newPage.close();
  2642. toaster.pop('error', '打印失败', response.data);
  2643. });
  2644. };
  2645. $scope.openDatePicker = function ($event, item, openParam) {
  2646. $event.preventDefault();
  2647. $event.stopPropagation();
  2648. item[openParam] = !item[openParam];
  2649. };
  2650. $scope.openFilterDatePicker = function ($event, item, openParam) {
  2651. $event.preventDefault();
  2652. $event.stopPropagation();
  2653. item[openParam] = !item[openParam];
  2654. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  2655. $scope.tableParams.reload();
  2656. }
  2657. };
  2658. $scope.parseDate = function (dateStr) {
  2659. if (dateStr)
  2660. return Date.parse(dateStr, 'yyyy-MM-dd');
  2661. return new Date();
  2662. };
  2663. $scope.checkboxes = {
  2664. checked: false
  2665. };
  2666. // 点击勾选全部的复选框
  2667. $scope.checkAll = function () {
  2668. angular.forEach($scope.tableParams.data, function (item) {
  2669. item.$selected = $scope.checkboxes.checked;
  2670. });
  2671. };
  2672. // 点击其中一个明细的复选框
  2673. $scope.checkOne = function (order) {
  2674. var result = true;
  2675. angular.forEach($scope.tableParams.data, function (item) {
  2676. if (item.$selected != true) {
  2677. result = false;
  2678. return;
  2679. }
  2680. });
  2681. $scope.checkboxes.checked = result;
  2682. };
  2683. // 搜索框回车
  2684. $scope.onSearch = function (keyword) {
  2685. // 每次搜索重置获取数据方法
  2686. $scope.searchMethod = false;
  2687. if(keyword != null && keyword != '') {
  2688. $scope.searchMethod = true;
  2689. }
  2690. $scope.tableParams.page(1);
  2691. $scope.tableParams.reload();
  2692. $scope.tip = keyword;
  2693. };
  2694. // 选择查找日期
  2695. $scope.onDateCondition = function () {
  2696. $scope.tableParams.page(1);
  2697. $scope.tableParams.reload();
  2698. };
  2699. // 复制订单
  2700. $scope.copyorder = function (id) {
  2701. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  2702. if (data.id) {
  2703. toaster.pop('success', '提示', '单据复制成功');
  2704. window.location.hash = "#purc/cart/" + data.id;
  2705. }
  2706. }, function (response) {
  2707. toaster.pop('error', '提示', response.data);
  2708. });
  2709. }
  2710. // 导出
  2711. $scope.exportXls = function () {
  2712. PurcOrders.exportXls({}, {}, function (data) {
  2713. if (data.success){
  2714. window.location.href = 'sale/orders/purc/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  2715. }
  2716. }, function (response) {
  2717. toaster.pop('error', '数据加载失败', response.data);
  2718. });
  2719. }
  2720. }]);
  2721. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'PurcOrdersInfo', 'CurrentRole', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, PurcOrdersInfo, CurrentRole) {
  2722. // 获取当前用户是否为普通用户
  2723. CurrentRole.isUser({}, {}, function (data) {
  2724. $scope.isUser = data.isUser;
  2725. });
  2726. var loadData = function () {
  2727. PurcOrdersInfo.getAll({id: $stateParams.id}, function (data) {
  2728. $scope.order = data;
  2729. var sum = 0;
  2730. angular.forEach($scope.order.orderItems, function (item) {
  2731. sum += item.qty * item.price;
  2732. });
  2733. $scope.order.total = sum;
  2734. // if($scope.order.display == 1) {//未查看的设为已查看
  2735. // $scope.setDisplay('setRead', $scope.order.id);
  2736. // }
  2737. $scope.loading = false;
  2738. });
  2739. };
  2740. loadData();
  2741. $scope.getReply = function (item) {
  2742. if (!item.replies) {
  2743. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2744. item.replies = replies;
  2745. });
  2746. }
  2747. };
  2748. $scope.openDatePicker = function ($event, item, openParam) {
  2749. $event.preventDefault();
  2750. $event.stopPropagation();
  2751. item[openParam] = !item[openParam];
  2752. };
  2753. $scope.onReplyClick = function (item, inverse) {
  2754. if (item.reply) {
  2755. if (!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2756. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2757. return;
  2758. }
  2759. var reply = angular.copy(item.reply);
  2760. if (reply.delivery) {
  2761. if (typeof reply.delivery == 'object')
  2762. reply.delivery = reply.delivery.getTime();
  2763. } else {
  2764. reply.delivery = item.delivery;
  2765. }
  2766. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2767. $scope.loading = true;
  2768. PurcOrderItem.reply({orderItemId: item.id}, reply, function () {
  2769. $scope.loading = false;
  2770. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  2771. loadData();
  2772. }, function (response) {
  2773. $scope.loading = false;
  2774. toaster.pop('error', '回复失败', response.data);
  2775. });
  2776. }
  2777. };
  2778. // // 采购单
  2779. // $scope.print = function(order) {
  2780. // PurcOrder.printCount({id: order.id},{});//增加打印此次
  2781. // ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id);
  2782. // };
  2783. //设置为已查看
  2784. $scope.setDisplay = function (state, orderId) {
  2785. if (orderId) {//设置单个
  2786. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  2787. // $scope.tableParams.reload();
  2788. }, function () {
  2789. toaster.pop('error', '错误', "设置失败");
  2790. });
  2791. } else {//设置已勾选的
  2792. var str = null;
  2793. angular.forEach($scope.tableParams.data, function (order) {
  2794. if (order.$selected == true) {
  2795. if (str != null && str != '') str += ',';
  2796. str += order.id;
  2797. }
  2798. });
  2799. if (str != null && str != '') {
  2800. PurcOrder[state].call({}, {ids: '' + str}, function () {
  2801. $scope.tableParams.reload();
  2802. }, function () {
  2803. toaster.pop('error', '错误', "设置失败");
  2804. });
  2805. }
  2806. }
  2807. };
  2808. }]);
  2809. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis', 'PagingRelease', 'SnapshotService', 'PurcOrderItemInfo', 'token', 'CurrentRole', '$timeout', function ($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis, PagingRelease, SnapshotService, PurcOrderItemInfo, token, CurrentRole, $timeout) {
  2810. BaseService.scrollBackToTop();
  2811. // 判断是否为普通用户
  2812. CurrentRole.isUser({}, {}, function (data) {
  2813. $scope.isUser = data.isUser;
  2814. });
  2815. $scope.active = 'todo';
  2816. $scope.dateZoneText = '不限';
  2817. $scope.deliveryZoneText = '不限';
  2818. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2819. /* 时间筛选初始化*/
  2820. var fromDate = new Date();
  2821. var toDate = new Date();
  2822. fromDate.setMonth(fromDate.getMonth() - 1);
  2823. fromDate.setHours(0, 0, 0, 0);
  2824. toDate.setHours(23, 59, 59, 999);
  2825. $scope.condition.dateFrom = fromDate;
  2826. $scope.condition.dateTo = toDate;
  2827. $scope.changeDateZone = function (zone) {
  2828. $scope.condition.dateZone = zone;
  2829. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2830. $scope.condition.$dateZoneOpen = false;
  2831. getDateCondition(zone, $scope.condition);
  2832. $scope.tableParams.page(1);
  2833. $scope.tableParams.reload();
  2834. };
  2835. $scope.changeDeliveryZone = function (zone) {
  2836. $scope.condition.deliveryZoneText = zone;
  2837. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2838. $scope.condition.$delievryZoneOpen = false;
  2839. getDelveryCondition(zone, $scope.condition);
  2840. $scope.tableParams.reload();
  2841. };
  2842. $scope.nowdate = new Date();
  2843. // 切换单据类型
  2844. $scope.setActive = function (state) {
  2845. if ($scope.active != state) {
  2846. $scope.active = state;
  2847. if ($scope.tableParams.page() == 1)
  2848. $scope.tableParams.reload();
  2849. else
  2850. $scope.tableParams.page(1);
  2851. }
  2852. };
  2853. $scope.searchMethod = false;
  2854. // 切换数据来源(正常数据 or 历史数据)
  2855. var getService = function () {
  2856. return $scope.searchMethod ? PurcOrderItem : PurcOrderItemInfo;
  2857. };
  2858. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2859. page: 1,
  2860. count: 20,
  2861. sorting: {
  2862. display: 'desc',
  2863. date: 'desc',
  2864. id: 'desc'
  2865. }
  2866. }, {
  2867. total: 0,
  2868. counts: [5, 10, 15, 25, 50],
  2869. getData: function ($defer, params) { // 获取数据的方法
  2870. $scope.loading = true;
  2871. var pageParams = params.url();
  2872. pageParams.searchFilter = { // 筛选条件
  2873. keyword: $scope.keyword,
  2874. fromDate: getDateTime($scope.condition.dateFrom),
  2875. endDate: getDateTime($scope.condition.dateTo)
  2876. };
  2877. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2878. $scope.loading = false;
  2879. if (page) {
  2880. //获取每个明细单最新回复数
  2881. angular.forEach(page.content, function(order){
  2882. angular.forEach(order.orderItems, function(item){
  2883. PurcOrderItem.getLatestReplyQty({orderItemId: item.id}, null, function (map) {
  2884. item.latestReplyQty = map.latestReplyQty;
  2885. });
  2886. });
  2887. });
  2888. $defer.resolve(page.content);
  2889. params.total(page.totalElement);
  2890. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2891. }
  2892. }, function (response) {
  2893. $scope.loading = false;
  2894. toaster.pop('error', '数据加载失败', response.data);
  2895. });
  2896. }
  2897. });
  2898. //获得各分类未阅读数量
  2899. var getUnreadCount = function () {
  2900. PurcOrderItem.getUnreadCount(null, function (data) {
  2901. $scope.unread = data;
  2902. });
  2903. };
  2904. getUnreadCount();
  2905. //设置单据已读
  2906. $scope.setOrdersRead = function (id) {
  2907. // 如果单据本身已读,则不发送请求修改数据
  2908. if (!$scope.isUnread(id)){
  2909. return;
  2910. }
  2911. var sourceId = [];
  2912. sourceId.push(id);
  2913. PurcOrderItem.setRead({}, sourceId, function (message) {
  2914. // var success = message.success;
  2915. // if(success && $scope.isUnread(id)){
  2916. // $scope.unread.all = $scope.unread.all - 1;
  2917. // }
  2918. getUnreadCount();
  2919. });
  2920. };
  2921. //批量设置单据已读
  2922. $scope.setOrdersReadByBatch = function () {
  2923. var sourceId = [];
  2924. angular.forEach($scope.tableParams.data, function (order) {
  2925. if (order.$selected == true) {
  2926. sourceId.push(order.id);
  2927. }
  2928. });
  2929. PurcOrderItem.setRead({}, sourceId, function (message) {
  2930. getUnreadCount();
  2931. });
  2932. };
  2933. $scope.setOrdersReadByState = function () {
  2934. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  2935. return;
  2936. }
  2937. PurcOrderItem.setReadByState({}, function () {
  2938. getUnreadIds();
  2939. getUnreadCount();
  2940. });
  2941. };
  2942. var getUnreadIds = function () {
  2943. PurcOrderItem.getUnreadIds({}, "", function (message) {
  2944. $scope.unreadCode = message.content;
  2945. });
  2946. };
  2947. getUnreadIds();
  2948. $scope.isUnread = function (id) {
  2949. for (var i in $scope.unreadCode) {
  2950. if (id == $scope.unreadCode[i]) {
  2951. return true;
  2952. }
  2953. }
  2954. };
  2955. $scope.getOrderTotal = function (items) {
  2956. var sum = 0;
  2957. angular.forEach(items, function (item) {
  2958. sum += item.qty * item.price;
  2959. });
  2960. return sum;
  2961. };
  2962. $scope.openDatePicker = function ($event, item, openParam) {
  2963. $event.preventDefault();
  2964. $event.stopPropagation();
  2965. item[openParam] = !item[openParam];
  2966. };
  2967. $scope.openFilterDatePicker = function ($event, item, openParam) {
  2968. $event.preventDefault();
  2969. $event.stopPropagation();
  2970. item[openParam] = !item[openParam];
  2971. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  2972. $scope.tableParams.reload();
  2973. }
  2974. };
  2975. $scope.parseDate = function (dateStr) {
  2976. if (dateStr)
  2977. return Date.parse(dateStr, 'yyyy-MM-dd');
  2978. return new Date();
  2979. };
  2980. // 获取token信息
  2981. $scope.getToken = function() {
  2982. token.info({userType: 'sale'}, {}, function(data) {
  2983. $scope.token = data.token;
  2984. }, function(response) {
  2985. toaster.pop('error', '提示', response.data);
  2986. });
  2987. }
  2988. $scope.onReplyClick = function (item, inverse) {
  2989. if (item.reply) {
  2990. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  2991. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2992. return;
  2993. }
  2994. var reply = angular.copy(item.reply);
  2995. if (reply.delivery) {
  2996. if (typeof reply.delivery == 'object')
  2997. reply.delivery = reply.delivery.getTime();
  2998. } else {
  2999. reply.delivery = item.delivery;
  3000. }
  3001. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3002. $scope.loading = true;
  3003. if($scope.token != null) {
  3004. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3005. $scope.loading = false;
  3006. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3007. $scope.tableParams.reload();
  3008. }, function (response) {
  3009. $scope.loading = false;
  3010. toaster.pop('error', '回复失败', response.data);
  3011. });
  3012. }
  3013. }
  3014. };
  3015. //打印 采购单
  3016. $scope.print = function (order) {
  3017. var newPage = window.open("about:blank");
  3018. PurcOrder.printPermission({}, function () {
  3019. PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
  3020. if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  3021. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
  3022. $scope.tableParams.reload();
  3023. },function (response) {
  3024. newPage.close();
  3025. toaster.pop('error', '打印失败', response.data);
  3026. });
  3027. };
  3028. $scope.getReply = function (item) {
  3029. if (!item.replies) {
  3030. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3031. item.replies = replies;
  3032. });
  3033. }
  3034. };
  3035. $scope.checkboxes = {
  3036. checked: false
  3037. };
  3038. // 点击勾选全部的复选框
  3039. $scope.checkAll = function () {
  3040. angular.forEach($scope.tableParams.data, function (item) {
  3041. item.$selected = $scope.checkboxes.checked;
  3042. });
  3043. };
  3044. // 点击其中一个明细的复选框
  3045. $scope.checkOne = function (order) {
  3046. var result = true;
  3047. angular.forEach($scope.tableParams.data, function (item) {
  3048. if (item.$selected != true) {
  3049. result = false;
  3050. return;
  3051. }
  3052. });
  3053. $scope.checkboxes.checked = result;
  3054. };
  3055. //批量回复采购订单
  3056. $scope.replyByBatch = function () {
  3057. $scope.loading = true;
  3058. var str = '';
  3059. angular.forEach($scope.tableParams.data, function (order) {
  3060. if (order.$selected == true) {
  3061. angular.forEach(order.orderItems, function (item) {
  3062. str += item.id;
  3063. str += ',';
  3064. });
  3065. }
  3066. });
  3067. if (!(str == '')) {
  3068. str = str.substr(0, str.length - 1);
  3069. PurcOrderItem.replyByBatch(str, function () {
  3070. $scope.loading = false;
  3071. $scope.tableParams.reload();
  3072. toaster.pop('success', '提示', '批量回复成功');
  3073. }, function (response) {
  3074. $scope.loading = false;
  3075. toaster.pop('error', '批量回复失败', response.data);
  3076. });
  3077. } else {//没有勾选其中的明细
  3078. $scope.loading = false;
  3079. }
  3080. };
  3081. // 搜索框回车
  3082. $scope.onSearch = function (keyword) {
  3083. // 每次搜索重置获取数据方法
  3084. $scope.searchMethod = false;
  3085. if(keyword != null && keyword != '') {
  3086. $scope.searchMethod = true;
  3087. }
  3088. $scope.tableParams.page(1);
  3089. $scope.tableParams.reload();
  3090. };
  3091. // 选择查找日期
  3092. $scope.onDateCondition = function () {
  3093. $scope.tableParams.page(1);
  3094. $scope.tableParams.reload();
  3095. };
  3096. //设置为已查看
  3097. $scope.setDisplay = function (state, orderId) {
  3098. if (orderId) {//设置单个
  3099. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3100. $scope.tableParams.reload();
  3101. }, function () {
  3102. toaster.pop('error', '错误', "设置失败");
  3103. });
  3104. } else {//设置已勾选的
  3105. var str = null;
  3106. angular.forEach($scope.tableParams.data, function (order) {
  3107. if (order.$selected == true) {
  3108. if (str != null && str != '') str += ',';
  3109. str += order.id;
  3110. }
  3111. });
  3112. if (str != null && str != '') {
  3113. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3114. $scope.tableParams.reload();
  3115. }, function () {
  3116. toaster.pop('error', '错误', "设置失败");
  3117. });
  3118. }
  3119. }
  3120. };
  3121. // 导出
  3122. $scope.exportXls = function () {
  3123. PurcOrderItem.exportXls({}, {}, function (data) {
  3124. if (data.success){
  3125. window.location.href = 'sale/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3126. }
  3127. }, function (response) {
  3128. toaster.pop('error', '数据加载失败', response.data);
  3129. });
  3130. }
  3131. }]);
  3132. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token',function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token) {
  3133. // 获取当前用户是否为普通用户
  3134. CurrentRole.isUser({}, {}, function (data) {
  3135. $scope.isUser = data.isUser;
  3136. });
  3137. var loadData = function () {
  3138. PurcOrder.get({id: $stateParams.id}, function (data) {
  3139. $scope.order = data;
  3140. var sum = 0;
  3141. angular.forEach($scope.order.orderItems, function (item) {
  3142. sum += item.qty * item.price;
  3143. //获取最新回复数
  3144. PurcOrderItem.getLatestReplyQty({orderItemId: item.id}, null, function (map) {
  3145. item.latestReplyQty = map.latestReplyQty;
  3146. });
  3147. });
  3148. $scope.order.total = sum;
  3149. if ($scope.order.display == 1) {//未查看的设为已查看
  3150. $scope.setDisplay('setRead', $scope.order.id);
  3151. }
  3152. $scope.loading = false;
  3153. }, function (response) {
  3154. toaster.pop('error', '', response.data);
  3155. });
  3156. };
  3157. loadData();
  3158. $scope.getReply = function (item) {
  3159. if (!item.replies) {
  3160. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3161. item.replies = replies;
  3162. });
  3163. }
  3164. };
  3165. $scope.openDatePicker = function ($event, item, openParam) {
  3166. $event.preventDefault();
  3167. $event.stopPropagation();
  3168. item[openParam] = !item[openParam];
  3169. };
  3170. // 获取token信息
  3171. var getToken = function() {
  3172. token.info({userType: 'sale'}, {}, function(data) {
  3173. $scope.token = data.token;
  3174. }, function(response) {
  3175. toaster.pop('error', '提示', response.data);
  3176. });
  3177. };
  3178. getToken();
  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. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id, newPage);
  3212. },function (response) {
  3213. newPage.close();
  3214. toaster.pop('error', '打印失败', response.data);
  3215. });
  3216. };
  3217. //设置为已查看
  3218. $scope.setDisplay = function (state, orderId) {
  3219. if (orderId) {//设置单个
  3220. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3221. $scope.tableParams.reload();
  3222. }, function () {
  3223. toaster.pop('error', '错误', "设置失败");
  3224. });
  3225. } else {//设置已勾选的
  3226. var str = null;
  3227. angular.forEach($scope.tableParams.data, function (order) {
  3228. if (order.$selected == true) {
  3229. if (str != null && str != '') str += ',';
  3230. str += order.id;
  3231. }
  3232. });
  3233. if (str != null && str != '') {
  3234. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3235. $scope.tableParams.reload();
  3236. }, function () {
  3237. toaster.pop('error', '错误', "设置失败");
  3238. });
  3239. }
  3240. }
  3241. };
  3242. }]);
  3243. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', 'CurrentRole', function ($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, PurcChangeHis, CurrentRole) {
  3244. BaseService.scrollBackToTop();
  3245. // 获取当前用户是否为普通用户
  3246. CurrentRole.isUser({}, {}, function (data) {
  3247. $scope.isUser = data.isUser;
  3248. });
  3249. $scope.active = 'todo';
  3250. $scope.agreedText = '全部';
  3251. $scope.dateZoneText = '一个月内';
  3252. $scope.condition = {dateZone: 1};
  3253. /* 时间筛选初始化*/
  3254. var fromDate = new Date();
  3255. var toDate = new Date();
  3256. fromDate.setMonth(fromDate.getMonth() - 1);
  3257. fromDate.setHours(0, 0, 0, 0);
  3258. toDate.setHours(23, 59, 59, 999);
  3259. $scope.condition.dateFrom = fromDate;
  3260. $scope.condition.dateTo = toDate;
  3261. $scope.changeAgreed = function (agreed) {
  3262. $scope.condition.agreed = agreed;
  3263. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3264. $scope.condition.$agreedOpen = false;
  3265. };
  3266. $scope.changeDateZone = function (zone) {
  3267. $scope.condition.dateZone = zone;
  3268. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3269. $scope.condition.$dateZoneOpen = false;
  3270. getDateCondition(zone, $scope.condition);
  3271. $scope.tableParams.page(1);
  3272. $scope.tableParams.reload();
  3273. };
  3274. $scope.setActive = function (state) {
  3275. if ($scope.active != state) {
  3276. $scope.active = state;
  3277. if ($scope.tableParams.page() == 1)
  3278. $scope.tableParams.reload();
  3279. else
  3280. $scope.tableParams.page(1);
  3281. }
  3282. };
  3283. $scope.searchMethod = false;
  3284. var getService = function () {
  3285. return $scope.searchMethod ? PurcChange : PurcChanges;
  3286. };
  3287. $scope.tableParams = new ngTableParams({
  3288. page: 1,
  3289. count: 20,
  3290. sorting: {
  3291. date: 'desc'
  3292. }
  3293. }, {
  3294. total: 0,
  3295. counts: [5, 10, 25, 50],
  3296. getData: function ($defer, params) {
  3297. $scope.loading = true;
  3298. var pageParams = params.url();
  3299. pageParams.searchFilter = {
  3300. keyword: $scope.keyword,
  3301. fromDate: getDateTime($scope.condition.dateFrom),
  3302. endDate: getDateTime($scope.condition.dateTo)
  3303. };
  3304. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3305. $scope.loading = false;
  3306. if (page) {
  3307. params.total(page.totalElement);
  3308. $defer.resolve(page.content);
  3309. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3310. }
  3311. }, function (response) {
  3312. $scope.loading = false;
  3313. toaster.pop('error', '数据加载失败', response.data);
  3314. });
  3315. }
  3316. });
  3317. //获得各分类未阅读数量
  3318. var getUnreadCount = function () {
  3319. PurcChange.getUnreadCount(null, function(data){
  3320. $scope.unread = data;
  3321. });
  3322. };
  3323. getUnreadCount();
  3324. //设置单据已读
  3325. $scope.setOrdersRead = function (id) {
  3326. // 如果单据本身已读,则不发送请求修改数据
  3327. if (!$scope.isUnread(id)){
  3328. return;
  3329. }
  3330. var sourceId = [];
  3331. sourceId.push(id);
  3332. PurcChange.setRead({}, sourceId, function (message) {
  3333. // $scope.getUnreadIds();
  3334. getUnreadCount();
  3335. });
  3336. };
  3337. $scope.setOrdersReadByState = function () {
  3338. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3339. return;
  3340. }
  3341. PurcChange.setReadByState({}, function () {
  3342. getUnreadIds();
  3343. getUnreadCount();
  3344. });
  3345. };
  3346. //获取未读单据id
  3347. var getUnreadIds = function (){
  3348. PurcChange.getUnreadIds({}, "", function (message) {
  3349. $scope.unreadCode = message.content;
  3350. });
  3351. };
  3352. getUnreadIds();
  3353. //判断单据是否未读
  3354. $scope.isUnread = function (id){
  3355. for (var i in $scope.unreadCode) {
  3356. if (id == $scope.unreadCode[i]) {
  3357. return true;
  3358. }
  3359. }
  3360. };
  3361. $scope.openDatePicker = function ($event, item, openParam) {
  3362. $event.preventDefault();
  3363. $event.stopPropagation();
  3364. item[openParam] = !item[openParam];
  3365. };
  3366. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3367. $event.preventDefault();
  3368. $event.stopPropagation();
  3369. item[openParam] = !item[openParam];
  3370. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3371. $scope.tableParams.reload();
  3372. }
  3373. };
  3374. $scope.onReplyClick = function (change) {
  3375. if (change.$agreed) {
  3376. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3377. $scope.loading = true;
  3378. PurcChange.reply({changeId: change.id}, reply, function () {
  3379. $scope.loading = false;
  3380. toaster.pop('info', '提示', '回复成功');
  3381. $scope.tableParams.reload();
  3382. }, function (response) {
  3383. $scope.loading = false;
  3384. toaster.pop('error', '回复失败', response.data);
  3385. });
  3386. }
  3387. };
  3388. // 搜索框回车
  3389. $scope.onSearch = function (keyword) {
  3390. // 每次搜索重置获取数据方法
  3391. $scope.searchMethod = false;
  3392. if(keyword != null && keyword != '') {
  3393. $scope.searchMethod = true;
  3394. }
  3395. $scope.tableParams.page(1);
  3396. $scope.tableParams.reload();
  3397. };
  3398. // 导出
  3399. $scope.exportXls = function () {
  3400. PurcChange.exportXls({}, {}, function (data) {
  3401. if (data.success){
  3402. window.location.href = 'sale/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3403. }
  3404. }, function (response) {
  3405. toaster.pop('error', '数据加载失败', response.data);
  3406. });
  3407. }
  3408. }]);
  3409. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcChange, toaster, CurrentRole) {
  3410. // 获取当前用户是否为普通用户
  3411. CurrentRole.isUser({}, {}, function (data) {
  3412. $scope.isUser = data.isUser;
  3413. });
  3414. var loadData = function () {
  3415. PurcChange.getItem({id: $stateParams.id}, function (data) {
  3416. $scope.change = data;
  3417. }, function (response) {
  3418. toaster.pop('error', '', response.data);
  3419. });
  3420. };
  3421. loadData();
  3422. $scope.openDatePicker = function ($event, item, openParam) {
  3423. $event.preventDefault();
  3424. $event.stopPropagation();
  3425. item[openParam] = !item[openParam];
  3426. };
  3427. $scope.onReplyClick = function (change) {
  3428. if (change.$agreed) {
  3429. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3430. PurcChange.reply({changeId: change.id}, reply, function () {
  3431. toaster.pop('info', '提示', '回复成功');
  3432. loadData();
  3433. }, function (response) {
  3434. toaster.pop('error', '回复失败', response.data);
  3435. });
  3436. }
  3437. };
  3438. }]);
  3439. //客户采购询价
  3440. 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) {
  3441. BaseService.scrollBackToTop();
  3442. // 获取当前用户是否为普通用户
  3443. CurrentRole.isUser({}, {}, function (data) {
  3444. $scope.isUser = data.isUser;
  3445. });
  3446. if ($rootScope.active) {
  3447. $scope.active = $rootScope.active;
  3448. $rootScope.active = null;
  3449. } else {
  3450. $scope.active = 'todo';
  3451. }
  3452. $scope.agreedText = '全部';
  3453. $scope.dateZoneText = '最近一个月';
  3454. $scope.condition = {dateZone: 1};
  3455. /* 时间筛选初始化*/
  3456. var fromDate = new Date();
  3457. var toDate = new Date();
  3458. fromDate.setMonth(fromDate.getMonth() - 1);
  3459. fromDate.setHours(0, 0, 0, 0);
  3460. toDate.setHours(23, 59, 59, 999);
  3461. $scope.condition.dateFrom = fromDate;
  3462. $scope.condition.dateTo = toDate;
  3463. $scope.changeAgreed = function (agreed) {
  3464. $scope.condition.agreed = agreed;
  3465. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3466. $scope.condition.$agreedOpen = false;
  3467. };
  3468. $scope.changeDateZone = function (zone) {
  3469. $scope.condition.dateZone = zone;
  3470. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  3471. $scope.condition.$dateZoneOpen = false;
  3472. getDateCondition(zone, $scope.condition);
  3473. $scope.tableParams.page(1);
  3474. $scope.tableParams.reload();
  3475. };
  3476. $scope.setActive = function (state) {
  3477. if ($scope.active != state) {
  3478. $scope.active = state;
  3479. if ($scope.tableParams.page() == 1)
  3480. $scope.tableParams.reload();
  3481. else
  3482. $scope.tableParams.page(1);
  3483. }
  3484. };
  3485. // 得到消息
  3486. PurcInquiry.getMessage({}, function (data) {
  3487. $scope.message = data;
  3488. }, function (response) {
  3489. });
  3490. $scope.searchMethod = false;
  3491. var getService = function () {
  3492. return $scope.searchMethod ? PurcInquiry : PurcInquiryInfo;
  3493. };
  3494. $scope.tableParams = new ngTableParams({
  3495. page: 1,
  3496. count: 20,
  3497. sorting: {
  3498. 'inquiry.date': 'desc',
  3499. 'inquiry.enterprise.enName': 'asc',
  3500. 'inquiry.code': 'asc'
  3501. }
  3502. }, {
  3503. total: 0,
  3504. counts: [5, 10, 25, 50],
  3505. getData: function ($defer, params) {
  3506. $scope.loading = true;
  3507. var pageParams = params.url();
  3508. var realActive = {};
  3509. pageParams.searchFilter = { // 筛选条件
  3510. keyword: $scope.keyword,
  3511. fromDate: getDateTime($scope.condition.dateFrom),
  3512. endDate: getDateTime($scope.condition.dateTo)
  3513. };
  3514. if ($scope.active == 'overdue') {
  3515. $scope.active = 'end';
  3516. }
  3517. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3518. $scope.loading = false;
  3519. if (page) {
  3520. params.total(page.totalElement);
  3521. $defer.resolve(page.content);
  3522. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3523. }
  3524. }, function (response) {
  3525. $scope.loading = false;
  3526. toaster.pop('error', '数据加载失败', response.data);
  3527. });
  3528. }
  3529. });
  3530. //获得各分类未阅读数量
  3531. var getUnreadCount = function () {
  3532. PurcInquiry.getUnreadCount(null, function (data) {
  3533. $scope.unread = data;
  3534. });
  3535. };
  3536. getUnreadCount();
  3537. //设置单据已读
  3538. $scope.setOrdersRead = function (id) {
  3539. // 如果单据本身已读,则不发送请求修改数据
  3540. if (!$scope.isUnread(id)){
  3541. return;
  3542. }
  3543. var sourceId = [];
  3544. sourceId.push(id);
  3545. PurcInquiry.setRead({}, sourceId, function (message) {
  3546. getUnreadCount();
  3547. removeByValue($scope.unreadCode, id);
  3548. });
  3549. };
  3550. $scope.setOrdersReadByState = function () {
  3551. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3552. return;
  3553. }
  3554. PurcInquiry.setReadByState({}, function () {
  3555. getUnreadIds();
  3556. getUnreadCount();
  3557. });
  3558. };
  3559. var getUnreadIds = function () {
  3560. PurcInquiry.getUnreadIds({}, "", function (message) {
  3561. $scope.unreadCode = message.content;
  3562. });
  3563. };
  3564. getUnreadIds();
  3565. $scope.isUnread = function (id) {
  3566. for (var i in $scope.unreadCode) {
  3567. if (id == $scope.unreadCode[i]) {
  3568. return true;
  3569. }
  3570. }
  3571. };
  3572. $scope.getMinDate = function (item) {
  3573. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3574. };
  3575. $scope.replyPrices = [];
  3576. $scope.replylapQtys = [];
  3577. $scope.replyPrices.push(true);
  3578. $scope.replylapQtys.push(true);
  3579. $scope.addStep = function (inquiryItem) {
  3580. $scope.replyPrices.push(true);
  3581. if (inquiryItem.replies.length >= 10) {
  3582. toaster.pop('warning', '提示', '最多支持10个分段!');
  3583. } else {
  3584. inquiryItem.replies.push({});
  3585. if (inquiryItem.replies.length != 1) {
  3586. $scope.replyPrices.push(true);
  3587. $scope.replylapQtys.push(true);
  3588. }
  3589. }
  3590. };
  3591. $scope.removeStep = function (inquiryItem, stepIndex) {
  3592. inquiryItem.replies.splice(stepIndex, 1);
  3593. $scope.replyPrices.splice(stepIndex, 1);
  3594. $scope.replylapQtys.splice(stepIndex, 1);
  3595. };
  3596. $scope.openDatePicker = function ($event, item, openParam) {
  3597. $event.preventDefault();
  3598. $event.stopPropagation();
  3599. item[openParam] = !item[openParam];
  3600. };
  3601. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3602. $event.preventDefault();
  3603. $event.stopPropagation();
  3604. item[openParam] = !item[openParam];
  3605. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3606. $scope.tableParams.reload();
  3607. }
  3608. };
  3609. $scope.getHistory = function (item) {
  3610. if (!item.history) {
  3611. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  3612. item.history = data;
  3613. });
  3614. }
  3615. };
  3616. // 获取token信息
  3617. $scope.getToken = function() {
  3618. token.info({userType: 'saleinquiry'}, {}, function(data) {
  3619. $scope.token = data.token;
  3620. }, function(response) {
  3621. toaster.pop('error', '提示', response.data);
  3622. });
  3623. };
  3624. $scope.deleteAttach = function (attaches, index) {
  3625. attaches.splice(index, 1);
  3626. };
  3627. $scope.onReplyClick = function (item, withSteps) {
  3628. if (item.vendFromDate instanceof Date) {
  3629. item.vendFromDate = item.vendFromDate.getTime();
  3630. }
  3631. if (item.vendToDate instanceof Date) {
  3632. item.vendToDate = item.vendToDate.getTime();
  3633. }
  3634. if (item.vendFromDate > item.vendToDate) {
  3635. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3636. return;
  3637. }
  3638. var replies = [];
  3639. // 判断分段数是否合法
  3640. var valid = true;
  3641. var validLapQty = 0;
  3642. angular.forEach(item.replies, function (r, i) {
  3643. if ((i > 0 ? r.lapQty : 1) || r.price) {
  3644. replies.push(r);
  3645. }
  3646. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  3647. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  3648. valid = false;
  3649. validLapQty = r.lapQty;
  3650. }
  3651. });
  3652. item.replies = replies;
  3653. $scope.loading = true;
  3654. if (!valid) {
  3655. if (validLapQty) {
  3656. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  3657. } else {
  3658. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  3659. }
  3660. $scope.loading = false;
  3661. } else {
  3662. if (withSteps) { // 保存并报价
  3663. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  3664. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3665. $upload.upload({
  3666. url: 'sale/inquiry/addAttach',
  3667. file: file,
  3668. method: 'POST',
  3669. data: {
  3670. item: item
  3671. }
  3672. }).success(function (data) {
  3673. if (data.item) {
  3674. item = data.item;
  3675. }
  3676. $scope.loading = false;
  3677. toaster.pop('info', '提示', '报价成功');
  3678. $scope.tableParams.reload();
  3679. }).error(function (data) {
  3680. $scope.loading = false;
  3681. toaster.pop('error', '附件上传失败');
  3682. });
  3683. }, function (response) {
  3684. $scope.loading = false;
  3685. toaster.pop('error', '询价失效', response.data);
  3686. });
  3687. } else { // 保存
  3688. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  3689. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3690. $upload.upload({
  3691. url: 'sale/inquiry/addAttach',
  3692. file: file,
  3693. method: 'POST',
  3694. data: {
  3695. item: item
  3696. }
  3697. }).success(function (data) {
  3698. if (data.item) {
  3699. item = data.item;
  3700. }
  3701. $scope.loading = false;
  3702. toaster.pop('info', '提示', '保存成功');
  3703. $scope.tableParams.reload();
  3704. }).error(function (data) {
  3705. $scope.loading = false;
  3706. toaster.pop('error', '附件上传失败');
  3707. });
  3708. }, function (response) {
  3709. $scope.loading = false;
  3710. toaster.pop('error', '保存失败', response.data);
  3711. });
  3712. }
  3713. }
  3714. };
  3715. $scope.isValid = function (item, withSteps) {
  3716. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3717. if (!withSteps || !bool)
  3718. return bool;
  3719. angular.forEach(item.replies, function (r, i) {
  3720. $scope.verifylapQty(r.lapQty, i, item);
  3721. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  3722. });
  3723. return bool;
  3724. };
  3725. $scope.verifylapQty = function (value, index, inquiryItem) {
  3726. value = parseInt(value);
  3727. var regex = /^\d+(.\d{1,5})?$/;
  3728. var valid = true;
  3729. angular.forEach(inquiryItem.replies, function(reply, $index) {
  3730. if ($index < index && reply.lapQty >= value) {
  3731. valid = false;
  3732. }
  3733. });
  3734. $scope.replylapQtys[index] = regex.test(value) && valid;
  3735. };
  3736. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  3737. $scope.verify = function (value, type) {
  3738. var regex = /^\d+(.\d{1,5})?$/;//
  3739. switch (type) {
  3740. case 'minOrderQty':
  3741. $scope.minOrderQtyVerify = regex.test(value);
  3742. break;
  3743. case 'minPackQty':
  3744. $scope.minPackQtyVerify = regex.test(value);
  3745. break;
  3746. case 'leadtime':
  3747. $scope.leadtimeVerify = regex.test(value);
  3748. break;
  3749. default:
  3750. $scope.replyPrices[type] = regex.test(value);
  3751. break;
  3752. }
  3753. }
  3754. // 搜索框回车
  3755. $scope.onSearch = function (keyword) {
  3756. // 每次搜索重置获取数据方法
  3757. $scope.searchMethod = false;
  3758. if(keyword != null && keyword != '') {
  3759. $scope.searchMethod = true;
  3760. }
  3761. $scope.tableParams.page(1);
  3762. $scope.tableParams.reload();
  3763. };
  3764. // 取消
  3765. $scope.cancel = function () {
  3766. $scope.tableParams.reload();
  3767. }
  3768. // 导出
  3769. $scope.exportXls = function () {
  3770. PurcInquiry.exportXls({}, {}, function (data) {
  3771. if (data.success) {
  3772. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3773. }
  3774. }, function (response) {
  3775. toaster.pop('error', '数据加载失败', response.data);
  3776. })
  3777. }
  3778. }]);
  3779. // 询价单明细
  3780. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole) {
  3781. // 获取当前用户是否为普通用户
  3782. CurrentRole.isUser({}, {}, function (data) {
  3783. $scope.isUser = data.isUser;
  3784. });
  3785. var loadData = function () {
  3786. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  3787. $scope.newinquiryItems = data;
  3788. var inquiry = data[0].inquiry;
  3789. //inquiry.inquiryItems = data;
  3790. angular.forEach(inquiry.attachs, function (attach) {
  3791. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  3792. });
  3793. $scope.inquiry = inquiry;
  3794. }, function (response) {
  3795. $scope.loading = false;
  3796. toaster.pop('error', '', response.data);
  3797. });
  3798. };
  3799. loadData();
  3800. $scope.getMinDate = function (item) {
  3801. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3802. };
  3803. $scope.replyPrices = [];
  3804. $scope.replylapQtys = [];
  3805. $scope.replyPrices.push(true);
  3806. $scope.replylapQtys.push(true);
  3807. $scope.addStep = function (inquiryItem) {
  3808. if (inquiryItem.replies.length >= 10) {
  3809. toaster.pop('warning', '提示', '最多支持10个分段!');
  3810. } else
  3811. inquiryItem.replies.push({});
  3812. };
  3813. $scope.removeStep = function (inquiryItem, stepIndex) {
  3814. inquiryItem.replies.splice(stepIndex, 1);
  3815. };
  3816. $scope.openDatePicker = function ($event, item, openParam) {
  3817. $event.preventDefault();
  3818. $event.stopPropagation();
  3819. item[openParam] = !item[openParam];
  3820. };
  3821. $scope.getHistory = function (item) {
  3822. if (!item.history) {
  3823. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  3824. item.history = data;
  3825. });
  3826. }
  3827. };
  3828. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  3829. $scope.verify = function (value, type) {
  3830. var regex = /^\d+(.\d{1,5})?$/;//
  3831. switch (type) {
  3832. case 'minOrderQty':
  3833. $scope.minOrderQtyVerify = regex.test(value);
  3834. break;
  3835. case 'minPackQty':
  3836. $scope.minPackQtyVerify = regex.test(value);
  3837. break;
  3838. case 'leadtime':
  3839. $scope.leadtimeVerify = regex.test(value);
  3840. break;
  3841. default:
  3842. $scope.replyPrices[type] = regex.test(value);
  3843. break;
  3844. }
  3845. }
  3846. $scope.verifylapQty = function (value, index, inquiryItem) {
  3847. value = parseInt(value);
  3848. var regex = /^\d+(.\d{1,5})?$/;
  3849. var valid = true;
  3850. angular.forEach(inquiryItem.replies, function(reply, $index) {
  3851. if ($index < index && reply.lapQty >= value) {
  3852. valid = false;
  3853. }
  3854. });
  3855. $scope.replylapQtys[index] = regex.test(value) && valid;
  3856. };
  3857. $scope.isValid = function (item, withSteps) {
  3858. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3859. if (!withSteps || !bool)
  3860. return bool;
  3861. angular.forEach(item.replies, function (r, i) {
  3862. $scope.verifylapQty(r.lapQty, i, item);
  3863. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  3864. });
  3865. return bool;
  3866. };
  3867. // 获取token信息
  3868. $scope.getToken = function() {
  3869. token.info({userType: 'saleinquiry'}, {}, function(data) {
  3870. $scope.token = data.token;
  3871. }, function(response) {
  3872. toaster.pop('error', '提示', response.data);
  3873. });
  3874. };
  3875. $scope.deleteAttach = function (attaches, index) {
  3876. attaches.splice(index, 1);
  3877. };
  3878. $scope.onReplyClick = function (item, withSteps) {
  3879. if (item.vendFromDate instanceof Date) {
  3880. item.vendFromDate = item.vendFromDate.getTime();
  3881. }
  3882. if (item.vendToDate instanceof Date) {
  3883. item.vendToDate = item.vendToDate.getTime();
  3884. }
  3885. if (item.vendFromDate > item.vendToDate) {
  3886. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3887. return;
  3888. }
  3889. var replies = [];
  3890. var valid = true;
  3891. var validLapQty = 0;
  3892. angular.forEach(item.replies, function (r, i) {
  3893. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  3894. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  3895. valid = false;
  3896. validLapQty = r.lapQty;
  3897. }
  3898. if ((i > 0 ? r.lapQty : 1) || r.price)
  3899. replies.push(r);
  3900. });
  3901. item.replies = replies;
  3902. $scope.loading = true;
  3903. if (!valid) { // 不合法时给出提示
  3904. if (validLapQty) {
  3905. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  3906. } else {
  3907. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  3908. }
  3909. $scope.loading = false;
  3910. } else {
  3911. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3912. $upload.upload({
  3913. url: 'sale/inquiry/addAttach',
  3914. file: file,
  3915. method: 'POST',
  3916. data: {
  3917. item: item
  3918. }
  3919. }).success(function (data) {
  3920. if (data.item) {
  3921. item = data.item;
  3922. }
  3923. });
  3924. if (withSteps) {
  3925. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  3926. $scope.loading = false;
  3927. toaster.pop('info', '提示', '报价成功');
  3928. // loadData();
  3929. window.location.reload();
  3930. }, function (response) {
  3931. $scope.loading = false;
  3932. toaster.pop('error', '询价失效', response.data);
  3933. });
  3934. } else {
  3935. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  3936. $scope.loading = false;
  3937. toaster.pop('info', '提示', '保存成功');
  3938. // loadData();
  3939. window.location.reload();
  3940. }, function (response) {
  3941. $scope.loading = false;
  3942. toaster.pop('error', '保存失败', response.data);
  3943. });
  3944. }
  3945. }
  3946. };
  3947. // 取消
  3948. $scope.cancel = function () {
  3949. $scope.tableParams.reload();
  3950. }
  3951. }]);
  3952. // 平台新增的询价单
  3953. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'PurcProduct', 'PurcProductNewest', '$timeout', '$http', 'ShipAddress', 'Search', 'ComponentActiveAPI', function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, PurcProduct, PurcProductNewest, $timeout, $http, ShipAddress, Search, ComponentActiveAPI) {
  3954. $scope.status = 'InquiryNew';
  3955. $scope.active = 'all';
  3956. $rootScope.tenderVendor = null;// 清除掉已选择的
  3957. $scope.searchMethod = false;
  3958. var getService = function () {
  3959. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  3960. };
  3961. $scope.inquiry = {
  3962. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  3963. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  3964. priceType: '采购',
  3965. isOpen: 1,
  3966. invoice: 0,
  3967. ifTax: 1,
  3968. currency: 'RMB',
  3969. inquirytype: '询价'
  3970. };
  3971. $scope.changeCurrency = function (inquiry) {
  3972. if (inquiry.currency !== 'RMB') {
  3973. $scope.notRMB = true;
  3974. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  3975. inquiry.invoice = 0;
  3976. } else {
  3977. $scope.notRMB = false;
  3978. }
  3979. };
  3980. // 获取收货地址列表
  3981. var loadShipAddress = function () {
  3982. ShipAddress.shipAddList({}, function (data) {
  3983. $scope.ships = data;
  3984. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  3985. });
  3986. };
  3987. loadShipAddress();
  3988. // 获取地址信息
  3989. $http.get('resources/citydata/city.json', {
  3990. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  3991. }).then(function (response) {
  3992. $scope.provinces = response.data;
  3993. });
  3994. // 新增收货地址保存
  3995. $scope.saveShipAddress = function (ship) {
  3996. ship.address = ship.province + ship.city + ship.district;
  3997. ShipAddress.saveAddress({}, ship, function (data) {
  3998. if (data.success) {
  3999. // 获取收货地址列表
  4000. loadShipAddress();
  4001. toaster.pop('success', '提示', data.success);
  4002. }
  4003. if (data.error) {
  4004. toaster.pop('error', '提示', data.error);
  4005. }
  4006. });
  4007. };
  4008. $scope.currentDay = function () {
  4009. return $filter('date')(new Date(), 'yyyy-MM-dd');
  4010. };
  4011. $scope.vendors = [];
  4012. // 查找供应商
  4013. $scope.dbfindVendor = function () {
  4014. var modalInstance = $modal.open({
  4015. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  4016. controller: 'DbfindVendorCtrl',
  4017. size: 'lg',
  4018. resolve: {}
  4019. });
  4020. modalInstance.result.then(function (data) {
  4021. var ifPush = true;
  4022. modalInstance.result.then(function (data) {
  4023. angular.forEach(data, function (vendor) {
  4024. if (!$scope.vendors) {// 不存在就先创建
  4025. $scope.vendors = [{}];
  4026. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  4027. } else {
  4028. for (var i = 0; i < $scope.vendors.length; i++) {
  4029. ifPush = true;
  4030. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  4031. ifPush = false;
  4032. break; // 判定到已存在供应商,就终止循环。
  4033. }
  4034. }
  4035. if (ifPush) {
  4036. $scope.vendors.push({
  4037. enName: vendor.vendorEnterprise.enName,
  4038. enuu: vendor.vendorEnterprise.uu
  4039. });
  4040. }
  4041. }
  4042. });
  4043. $rootScope.tenderVendor = $scope.vendors;
  4044. }, function () {
  4045. });
  4046. }, function () {
  4047. });
  4048. };
  4049. // 删除一个供应商
  4050. $scope.removeVendor = function (index) {
  4051. $scope.vendors.splice(index, 1);
  4052. };
  4053. $scope.removeChecked = function () {
  4054. if ($scope.vendors.length > 0) {
  4055. $scope.vendors = [];
  4056. $rootScope.tenderVendor = '';
  4057. }
  4058. }
  4059. // 物料信息
  4060. $scope.tableParams = new ngTableParams({
  4061. page: 1,
  4062. count: 20,
  4063. sorting: {
  4064. id: 'desc'
  4065. }
  4066. }, {
  4067. total: 0,
  4068. counts: [5, 10, 25, 50],
  4069. getData: function ($defer, params) {
  4070. $scope.loading = true;
  4071. var pageParams = params.url();
  4072. pageParams.keyword = $scope.keyword;
  4073. $scope.tip = $scope.keyword;
  4074. pageParams.searchFilter = $scope.searchFilter;
  4075. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4076. $scope.loading = false;
  4077. if (page) {
  4078. params.total(page.totalElement);
  4079. $scope.total = page.totalElement;
  4080. $defer.resolve(page.content);
  4081. }
  4082. }, function (response) {
  4083. $scope.loading = false;
  4084. toaster.pop('error', '数据加载失败', response.data);
  4085. });
  4086. }
  4087. });
  4088. // 搜索框回车
  4089. $scope.onSearch = function (keyword) {
  4090. // 每次搜索重置获取数据方法
  4091. $scope.searchMethod = false;
  4092. if(keyword != null && keyword != '') {
  4093. $scope.searchMethod = true;
  4094. }
  4095. $scope.tableParams.page(1);
  4096. $scope.tableParams.reload();
  4097. };
  4098. $scope.inquiry.inquiryItems = [];
  4099. var prod = {
  4100. prodCode: null,
  4101. prodTitle: null,
  4102. inbrand: null,
  4103. toDate: null,
  4104. unit: 'PCS',
  4105. needquantity: null
  4106. };
  4107. $scope.inquiry.inquiryItems.push(prod);
  4108. // 联想词start
  4109. // 获取品牌联想词
  4110. $scope.getSimilarBrands = function (value) {
  4111. if (value) {
  4112. // 获取品牌联想词
  4113. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  4114. return data.map(function (item) {
  4115. return item;
  4116. });
  4117. });
  4118. }
  4119. };
  4120. // 获取产品型号联想词
  4121. $scope.getSimilarCodes = function (value) {
  4122. if (value) {
  4123. // 获取产品型号联想词
  4124. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  4125. return data.map(function (item) {
  4126. return item;
  4127. })
  4128. });
  4129. }
  4130. };
  4131. $scope.selectKind = function (prod) {
  4132. var submit = [];
  4133. $modal.open({
  4134. animation: true,
  4135. size: 'lg',
  4136. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  4137. controller: 'ProdKindChooseCtrl',
  4138. resolve: {
  4139. actives: function () {
  4140. return $scope.actives;
  4141. }
  4142. }
  4143. }).result.then(function (data) {
  4144. $scope.actives = data.actives;
  4145. var size = data.actives.length;
  4146. submit.gradeOneKiName = '';
  4147. submit.gradeTwoKiName = '';
  4148. submit.gradeThreeKiName = '';
  4149. if (size > 0) {
  4150. submit.gradeOneKiName = $scope.actives[0].nameCn;
  4151. prod.prodTitle = submit.gradeOneKiName;
  4152. if (size > 1) {
  4153. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  4154. prod.prodTitle = submit.gradeTwoKiName;
  4155. if (size > 2) {
  4156. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  4157. prod.prodTitle = submit.gradeThreeKiName;
  4158. }
  4159. }
  4160. }
  4161. }, function () {
  4162. });
  4163. };
  4164. // 点击联想词获取品牌信息
  4165. $scope.onAssociateBrandClick = function (brand, prod) {
  4166. if (brand instanceof String) {
  4167. prod.inbrand = brand;
  4168. } else if (brand instanceof Object) {
  4169. prod.inbrand = brand.brandCn;
  4170. }
  4171. };
  4172. // 打开品牌选择的模态框
  4173. $scope.selectBrand = function (prod) { //打开模态
  4174. var modalInstance = $modal.open({
  4175. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  4176. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  4177. });
  4178. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  4179. });
  4180. modalInstance.result.then(function (brand) {
  4181. prod.inbrand = brand.nameCn;
  4182. }, function (reason) {
  4183. });
  4184. };
  4185. // 点击联想词获取器件信息 带入产品分类和品牌
  4186. $scope.onAssociateCmpClick = function (cmp, prod) {
  4187. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  4188. $scope.component = data;
  4189. prod.prodCode = data.code;
  4190. prod.prodTitle = data.kind.nameCn;
  4191. prod.inbrand = data.brand.nameCn;
  4192. }, function (res) {
  4193. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  4194. })
  4195. };
  4196. //联想词end
  4197. // 导入商品信息
  4198. $scope.uplodaByBatch = function () {
  4199. var modalInstance = $modal.open({
  4200. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  4201. controller: 'PurcInquiryUploadCtrl',
  4202. size: 'lg',
  4203. resolve: {}
  4204. });
  4205. modalInstance.result.then(function (data) {
  4206. angular.forEach(data, function (prod) {
  4207. $scope.inquiry.inquiryItems.push(prod);
  4208. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4209. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4210. $scope.inquiry.inquiryItems.splice(i, 1);
  4211. }
  4212. }
  4213. })
  4214. }, function () {
  4215. });
  4216. }
  4217. //增加商品
  4218. $scope.add = function () {
  4219. $scope.inquiry.inquiryItems.push(
  4220. {
  4221. prodCode: null,
  4222. prodTitle: null,
  4223. unit: 'PCS',
  4224. ibrand: null,
  4225. toDate: null,
  4226. needquantity: null
  4227. });
  4228. };
  4229. //删除商品
  4230. $scope.del = function (index) {
  4231. $scope.inquiry.inquiryItems.splice(index, 1);
  4232. };
  4233. $scope.check = function (product) {
  4234. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4235. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4236. $scope.inquiry.inquiryItems.splice(i, 1);
  4237. }
  4238. }
  4239. $scope.inquiry.inquiryItems.push({
  4240. prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  4241. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand
  4242. });
  4243. }
  4244. $scope.getMinDate = function (item) {
  4245. return $filter('date')(new Date, 'yyyy-MM-dd');
  4246. };
  4247. $scope.openDatePicker = function ($event, openParam, index) {
  4248. $event.preventDefault();
  4249. $event.stopPropagation();
  4250. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  4251. };
  4252. $scope.openEndDatePicker = function ($event, item, openParam) {
  4253. $event.preventDefault();
  4254. $event.stopPropagation();
  4255. item[openParam] = !item[openParam];
  4256. };
  4257. $scope.ifrepeat = false;
  4258. // 保存
  4259. $scope.save = function () {
  4260. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4261. $scope.item = $scope.inquiry.inquiryItems[i];
  4262. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4263. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4264. if (i != j) {
  4265. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4266. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4267. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4268. $scope.ifrepeat = true;
  4269. }
  4270. }
  4271. }
  4272. }
  4273. if (!$scope.ifrepeat) {
  4274. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4275. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4276. if ($scope.vendors.length > 0) {
  4277. $upload.upload({
  4278. url: 'purc/inquiry/save/withVendor',
  4279. file: file,
  4280. method: 'POST',
  4281. data: {
  4282. inquiry: $scope.inquiry,
  4283. contacts: $scope.vendors
  4284. },
  4285. }).success(function (data) {
  4286. if (data.success) {
  4287. toaster.pop('success', '提示', data.success);
  4288. $timeout(function () {
  4289. $rootScope.active = 'todo';
  4290. window.location.hash = "#/purc/inquiry_unapply";
  4291. }, 500);
  4292. }
  4293. if (data.error) {
  4294. toaster.pop('error', '提示', data.error);
  4295. }
  4296. }).error(function (data, status, headers, config) {
  4297. $scope.loadingShow = false;
  4298. if (status == 403) { // 抛异常专用
  4299. toaster.pop('error', '操作失败', data);
  4300. } else {
  4301. toaster.pop('error', '操作失败', data.error);
  4302. }
  4303. });
  4304. } else {
  4305. toaster.pop('info', '提示', '请先选择供应商');
  4306. }
  4307. } else {
  4308. $upload.upload({
  4309. url: 'purc/inquiry/save/withoutVendor',
  4310. file: file,
  4311. method: 'POST',
  4312. data: {
  4313. inquiry: $scope.inquiry,
  4314. },
  4315. }).success(function (data) {
  4316. if (data.success) {
  4317. toaster.pop('success', '提示', data.success);
  4318. $timeout(function () {
  4319. $rootScope.active = 'done';
  4320. window.location.hash = "#/purc/inquiry_unapply";
  4321. }, 500);
  4322. }
  4323. if (data.error) {
  4324. toaster.pop('error', '提示', data.error);
  4325. }
  4326. }).error(function (data, status, headers, config) {
  4327. $scope.loadingShow = false;
  4328. if (status == 403) { // 抛异常专用
  4329. toaster.pop('error', '操作失败', data);
  4330. } else {
  4331. toaster.pop('error', '操作失败', data.error);
  4332. }
  4333. });
  4334. }
  4335. } else {
  4336. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4337. }
  4338. }
  4339. // 保存并提交
  4340. $scope.submit = function () {
  4341. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4342. $scope.item = $scope.inquiry.inquiryItems[i];
  4343. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4344. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4345. if (i != j) {
  4346. if ($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4347. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4348. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4349. $scope.ifrepeat = true;
  4350. }
  4351. }
  4352. }
  4353. }
  4354. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4355. if (!$scope.ifrepeat) {
  4356. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4357. if ($scope.vendors.length > 0) {
  4358. $upload.upload({
  4359. url: 'purc/inquiry/submit/withVendor',
  4360. file: file,
  4361. method: 'POST',
  4362. data: {
  4363. inquiry: $scope.inquiry,
  4364. contacts: $scope.vendors
  4365. },
  4366. }).success(function (data) {
  4367. if (data.success) {
  4368. toaster.pop('success', '提示', data.success);
  4369. $timeout(function () {
  4370. window.location.hash = "#/purc/purchaseinquiry";
  4371. }, 500);
  4372. }
  4373. if (data.error) {
  4374. toaster.pop('error', '提示', data.error);
  4375. }
  4376. }).error(function (data, status, headers, config) {
  4377. $scope.loadingShow = false;
  4378. if (status == 403) { // 抛异常专用
  4379. toaster.pop('error', '操作失败', data);
  4380. } else {
  4381. toaster.pop('error', '操作失败', data.error);
  4382. }
  4383. });
  4384. } else {
  4385. toaster.pop('info', '提示', '请先选择供应商');
  4386. }
  4387. } else {
  4388. $upload.upload({
  4389. url: 'purc/inquiry/submit/withoutVendor',
  4390. file: file,
  4391. method: 'POST',
  4392. data: {
  4393. inquiry: $scope.inquiry,
  4394. },
  4395. }).success(function (data) {
  4396. if (data.success) {
  4397. toaster.pop('success', '提示', data.success);
  4398. $timeout(function () {
  4399. window.location.hash = "#/purc/purchaseinquiry";
  4400. }, 500);
  4401. }
  4402. if (data.error) {
  4403. toaster.pop('error', '提示', data.error);
  4404. }
  4405. }).error(function (data, status, headers, config) {
  4406. $scope.loadingShow = false;
  4407. if (status == 403) { // 抛异常专用
  4408. toaster.pop('error', '操作失败', data);
  4409. } else {
  4410. toaster.pop('error', '操作失败', data.error);
  4411. }
  4412. });
  4413. }
  4414. } else {
  4415. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4416. }
  4417. }
  4418. $scope.previewShow = false;
  4419. $scope.pdfShow = false;
  4420. $scope.noneFileShow = true;
  4421. $scope.$watch('myFiles', function () {
  4422. if ($scope.myFiles) {
  4423. $scope.noneFileShow = false;
  4424. var file = $scope.myFiles[0];
  4425. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  4426. $scope.pdfShow = true;
  4427. $scope.previewShow = false;
  4428. $scope.imgPreviewName = file.name;
  4429. } else {
  4430. if (typeof(Worker) !== "undefined") {//支持HTML5
  4431. $scope.imgPreview = getObjectURL(file);
  4432. $scope.imgPreviewName = file.name;
  4433. } else {//不支持HTML5
  4434. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  4435. $scope.imgPreviewName = file.name;
  4436. }
  4437. $scope.previewShow = true;
  4438. $scope.pdfShow = false;
  4439. }
  4440. } else {
  4441. $scope.noneFileShow = true;
  4442. $scope.previewShow = false;
  4443. $scope.pdfShow = false;
  4444. }
  4445. });
  4446. //建立一个可存取到该file的url
  4447. var getObjectURL = function (file) {
  4448. var url = null;
  4449. if (window.createObjectURL != undefined) { // basic
  4450. url = window.createObjectURL(file);
  4451. } else if (window.URL != undefined) { // mozilla(firefox)
  4452. url = window.URL.createObjectURL(file);
  4453. } else if (window.webkitURL != undefined) { // webkit or chrome
  4454. url = window.webkitURL.createObjectURL(file);
  4455. }
  4456. return url;
  4457. };
  4458. }]);
  4459. /**
  4460. * 代采订单批量导入
  4461. */
  4462. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  4463. // 通过excel批量上传物料
  4464. $scope.result = null;
  4465. $scope.upload = function () {
  4466. var file = $scope.myFiles[0];
  4467. $upload.upload({
  4468. url: 'purc/inquiry/release/excel',
  4469. file: file,
  4470. method: 'POST'
  4471. }).success(function (data) {
  4472. $scope.result = data;
  4473. $scope.success = $scope.result.success;
  4474. $scope.total = $scope.result.total;
  4475. $scope.alters = $scope.result.alters;
  4476. }).error(function (response) {
  4477. toaster.pop('error', response.data || response);
  4478. });
  4479. };
  4480. // 查看范例
  4481. $scope.showImg = function () {
  4482. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  4483. box.show();
  4484. box.find('img').attr('src', src);
  4485. box.find('a').click(function () {
  4486. box.hide();
  4487. });
  4488. box.dblclick(function () {
  4489. box.hide();
  4490. });
  4491. };
  4492. // 下载模板
  4493. $scope.download = function () {
  4494. window.location.href = 'purc/inquiry/upload/template';
  4495. };
  4496. $scope.enSure = function () {
  4497. $modalInstance.close($scope.result.items);
  4498. }
  4499. $scope.cancel = function () {
  4500. $modalInstance.dismiss();
  4501. }
  4502. }]);
  4503. // 平台询价单(已提交)
  4504. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', 'CurrentRole', function ($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope, CurrentRole) {
  4505. $scope.status = 'InquirySubmit';
  4506. BaseService.scrollBackToTop();
  4507. // 获取当前用户是否为普通用户
  4508. CurrentRole.isUser({}, {}, function (data) {
  4509. $scope.isUser = data.isUser;
  4510. });
  4511. if ($rootScope.active) {
  4512. $scope.active = $rootScope.active;
  4513. $rootScope.active = null;
  4514. } else {
  4515. $scope.active = 'todo';
  4516. }
  4517. $scope.agreedText = '全部';
  4518. $scope.dateZoneText = '一个月内';
  4519. $scope.condition = {dateZone: 1};
  4520. /* 时间筛选初始化*/
  4521. var fromDate = new Date();
  4522. var toDate = new Date();
  4523. fromDate.setMonth(fromDate.getMonth() - 1);
  4524. fromDate.setHours(0, 0, 0, 0);
  4525. toDate.setHours(23, 59, 59, 999);
  4526. $scope.condition.dateFrom = fromDate;
  4527. $scope.condition.dateTo = toDate;
  4528. $scope.changeAgreed = function (agreed) {
  4529. $scope.condition.agreed = agreed;
  4530. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4531. $scope.condition.$agreedOpen = false;
  4532. };
  4533. $scope.changeDateZone = function (zone) {
  4534. $scope.condition.dateZone = zone;
  4535. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4536. $scope.condition.$dateZoneOpen = false;
  4537. getDateCondition(zone, $scope.condition);
  4538. $scope.tableParams.page(1);
  4539. $scope.tableParams.reload();
  4540. };
  4541. $scope.setActive = function (state) {
  4542. if ($scope.active != state) {
  4543. $scope.active = state;
  4544. if ($scope.tableParams.page() == 1) {
  4545. $scope.tableParams.reload();
  4546. } else {
  4547. $scope.tableParams.page(1);
  4548. }
  4549. }
  4550. }
  4551. var getService = function () {
  4552. return PurchaseInquiry;
  4553. };
  4554. $scope.tableParams = new ngTableParams({
  4555. page: 1,
  4556. count: 20,
  4557. sorting: {
  4558. 'inquiry.date': 'desc',
  4559. 'inquiry.enterprise.enName': 'asc',
  4560. 'inquiry.code': 'asc'
  4561. }
  4562. }, {
  4563. total: 0,
  4564. counts: [5, 10, 25, 50],
  4565. getData: function ($defer, params) {
  4566. $scope.loading = true;
  4567. var pageParams = params.url();
  4568. var realActive = {};
  4569. pageParams.searchFilter = {
  4570. keyword: $scope.keyword,
  4571. fromDate: getDateTime($scope.condition.dateFrom),
  4572. endDate: getDateTime($scope.condition.dateTo)
  4573. };
  4574. if ($scope.active == 'overdue') {
  4575. $scope.active = 'end';
  4576. }
  4577. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4578. $scope.loading = false;
  4579. if (page) {
  4580. params.total(page.totalElement);
  4581. $defer.resolve(page.content);
  4582. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4583. }
  4584. }, function (response) {
  4585. $scope.loading = false;
  4586. toaster.pop('error', '数据加载失败', response.data);
  4587. });
  4588. }
  4589. });
  4590. //获得各分类未阅读数量
  4591. var getUnreadCount = function () {
  4592. PurchaseInquiry.getUnreadCount(null, function(data){
  4593. $scope.unread = data;
  4594. });
  4595. };
  4596. getUnreadCount();
  4597. //设置单据已读
  4598. $scope.setOrdersRead = function (id) {
  4599. // 如果单据本身已读,则不发送请求修改数据
  4600. if (!$scope.isUnread(id)){
  4601. return;
  4602. }
  4603. var sourceId = [];
  4604. sourceId.push(id);
  4605. PurchaseInquiry.setRead({}, sourceId, function (message) {
  4606. getUnreadIds();
  4607. getUnreadCount();
  4608. });
  4609. };
  4610. //获得未读单据id
  4611. var getUnreadIds = function (){
  4612. PurchaseInquiry.getUnreadIds({}, "", function (message) {
  4613. $scope.unreadCode = message.content;
  4614. });
  4615. };
  4616. getUnreadIds();
  4617. //判断单据是否未读
  4618. $scope.isUnread = function (id){
  4619. for (var i in $scope.unreadCode) {
  4620. if (id == $scope.unreadCode[i]) {
  4621. return true;
  4622. }
  4623. }
  4624. };
  4625. $scope.openDatePicker = function ($event, item, openParam) {
  4626. $event.preventDefault();
  4627. $event.stopPropagation();
  4628. item[openParam] = !item[openParam];
  4629. };
  4630. $scope.openFilterDatePicker = function ($event, item, openParam) {
  4631. $event.preventDefault();
  4632. $event.stopPropagation();
  4633. item[openParam] = !item[openParam];
  4634. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  4635. $scope.tableParams.reload();
  4636. }
  4637. };
  4638. // 搜索框回车
  4639. $scope.onSearch = function () {
  4640. $scope.tableParams.page(1);
  4641. $scope.tableParams.reload();
  4642. };
  4643. // 采纳
  4644. $scope.accept = function (id) {
  4645. PurchaseInquiry.accept({id: id}, {}, function (data) {
  4646. if (data.success) {
  4647. toaster.pop('success', '提示', data.success);
  4648. $scope.tableParams.reload();
  4649. }
  4650. if (data.error) {
  4651. toaster.pop('error', '提示', data.error);
  4652. }
  4653. }, function (response) {
  4654. toaster.pop('error', '提示', response.data);
  4655. })
  4656. };
  4657. // 拒绝
  4658. $scope.refuse = function (id) {
  4659. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  4660. if (data.success) {
  4661. toaster.pop('success', '提示', data.success);
  4662. $scope.tableParams.reload();
  4663. }
  4664. if (data.error) {
  4665. toaster.pop('error', '提示', data.error);
  4666. }
  4667. }, function (response) {
  4668. toaster.pop('error', '提示', response.data);
  4669. })
  4670. }
  4671. // 导出
  4672. $scope.exportXls = function () {
  4673. PurchaseInquiry.exportXls({}, {}, function (data) {
  4674. if (data.success){
  4675. window.location.href = 'purc/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4676. }
  4677. }, function (response) {
  4678. toaster.pop('error', '数据加载失败', response.data);
  4679. });
  4680. }
  4681. }]);
  4682. // 平台询价单(未提交)
  4683. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function ($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  4684. BaseService.scrollBackToTop();
  4685. if ($rootScope.active = 'done') {
  4686. $scope.active = 'done';
  4687. $rootScope.active = '';
  4688. }
  4689. if ($rootScope.active = 'todo') {
  4690. $scope.active = 'todo';
  4691. $rootScope.active = '';
  4692. }
  4693. var getService = function () {
  4694. if ($scope.active == 'todo') {
  4695. return PurchaseInquiry.getUnapply;
  4696. }
  4697. if ($scope.active == 'done') {
  4698. return PurchaseInquiry.getSubmit;
  4699. }
  4700. }
  4701. $scope.setActive = function (state) {
  4702. if ($scope.active != state) {
  4703. $scope.active = state;
  4704. if ($scope.tableParams.page() == 1) {
  4705. $scope.tableParams.reload();
  4706. } else {
  4707. $scope.tableParams.page(1);
  4708. }
  4709. }
  4710. }
  4711. $scope.tableParams = new ngTableParams({
  4712. page: 1,
  4713. count: 20,
  4714. sorting: {
  4715. 'date': 'desc',
  4716. 'enterprise.enName': 'asc',
  4717. 'code': 'asc'
  4718. }
  4719. }, {
  4720. total: 0,
  4721. counts: [5, 10, 25, 50],
  4722. getData: function ($defer, params) {
  4723. $scope.loading = true;
  4724. var pageParams = params.url();
  4725. var realActive = {};
  4726. if ($scope.active == 'overdue') {
  4727. $scope.active = 'end';
  4728. }
  4729. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  4730. $scope.loading = false;
  4731. if (page) {
  4732. params.total(page.totalElements);
  4733. $defer.resolve(page.content);
  4734. }
  4735. }, function (response) {
  4736. $scope.loading = false;
  4737. toaster.pop('error', '数据加载失败', response.data);
  4738. });
  4739. }
  4740. });
  4741. // 删除明细
  4742. $scope.deleteById = function (id) {
  4743. PurchaseInquiry.deleteById({id: id}, {}, function (data) {
  4744. toaster.pop('success', '提示', '删除成功');
  4745. $scope.tableParams.reload();
  4746. }, function (response) {
  4747. toaster.pop('error', '提示', response.data);
  4748. });
  4749. }
  4750. // 删除主表
  4751. $scope.clearOrder = function (id) {
  4752. PurchaseInquiry.clearOrder({id: id}, {}, function (data) {
  4753. toaster.pop('success', '提示', '删除成功');
  4754. $scope.tableParams.reload();
  4755. }, function (response) {
  4756. toaster.pop('error', '提示', response.data);
  4757. });
  4758. }
  4759. // 提交
  4760. $scope.submit = function (id) {
  4761. PurchaseInquiry.submitUnapply({id: id}, {}, function (data) {
  4762. toaster.pop('success', '提示', '单据提交成功');
  4763. $scope.active = 'done';
  4764. $scope.tableParams.reload();
  4765. }, function (response) {
  4766. toaster.pop('error', '提示', response.data);
  4767. })
  4768. }
  4769. // 发布公共询价
  4770. $scope.publish = function (id) {
  4771. PurchaseInquiry.publishInquiry({id: id}, {}, function (data) {
  4772. toaster.pop('success', '提示', data.success);
  4773. $scope.active = 'done';
  4774. $scope.tableParams.reload();
  4775. }, function (response) {
  4776. toaster.pop('error', '提示', response.data);
  4777. })
  4778. }
  4779. }]);
  4780. // 公共询价列表
  4781. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams) {
  4782. BaseService.scrollBackToTop();
  4783. /**
  4784. * 改变单据日期范围
  4785. */
  4786. var getTenderDateCondition = function (zone, condition) {
  4787. var date = new Date();
  4788. if (zone == -1) {
  4789. condition.dateFrom = null;
  4790. condition.dateTo = null;
  4791. } else if (zone == 7) { // 一星期内
  4792. date.setDate(date.getDate() - 7);
  4793. condition.dateFrom = date;
  4794. condition.dateTo = new Date();
  4795. } else if (zone == 1) { // 一个月内
  4796. date.setMonth(date.getMonth() - 1);
  4797. condition.dateFrom = date;
  4798. condition.dateTo = new Date();
  4799. } else if (zone == 3) { // 三个月内
  4800. date.setMonth(date.getMonth() - 3);
  4801. condition.dateFrom = date;
  4802. condition.dateTo = new Date();
  4803. } else if (zone == 6) { // 半年内
  4804. date.setMonth(date.getMonth() - 6);
  4805. condition.dateFrom = date;
  4806. condition.dateTo = new Date();
  4807. } else { // 一年内
  4808. date.setYear(date.getYear() - 1);
  4809. condition.dateFrom = date;
  4810. condition.dateTo = new Date();
  4811. }
  4812. };
  4813. $scope.dateZoneText = '不限';
  4814. $scope.deliveryZoneText = '不限';
  4815. $scope.condition = {dateZone: -1};
  4816. $scope.changeDateZone = function (zone) {
  4817. $scope.condition.dateZone = zone;
  4818. $scope.condition.$dateZoneOpen = false;
  4819. getTenderDateCondition(zone, $scope.condition);
  4820. $scope.tableParams.page(1);
  4821. $scope.tableParams.reload();
  4822. };
  4823. $scope.openDatePicker = function ($event, item, openParam) {
  4824. $event.preventDefault();
  4825. $event.stopPropagation();
  4826. item[openParam] = !item[openParam];
  4827. };
  4828. $scope.parseDate = function (dateStr) {
  4829. if (dateStr)
  4830. return Date.parse(dateStr, 'yyyy-MM-dd');
  4831. return new Date();
  4832. };
  4833. // 选择查找日期
  4834. $scope.onDateCondition = function () {
  4835. $scope.tableParams.page(1);
  4836. $scope.tableParams.reload();
  4837. };
  4838. // $scope.setActive = function(state) {
  4839. // if($scope.active != state) {
  4840. // $scope.active = state;
  4841. // if($scope.tableParams.page() == 1)
  4842. // $scope.tableParams.reload();
  4843. // else
  4844. // $scope.tableParams.page(1);
  4845. // }
  4846. // };
  4847. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  4848. var getOpenState = function (active) {
  4849. var fn = 'getOpenAll';
  4850. switch (active) {
  4851. case 'all':
  4852. fn = 'getOpenAll';
  4853. break;
  4854. case 'todo':
  4855. fn = 'getOpenTodo';
  4856. break;
  4857. case 'end':
  4858. fn = 'getOpenEnd';
  4859. break;
  4860. }
  4861. return fn;
  4862. };
  4863. $scope.tableParams = new ngTableParams({
  4864. page: 1,
  4865. count: 20,
  4866. sorting: {
  4867. // 'tender.endDate': 'desc',
  4868. // 'tender.enterprise.enName': 'asc',
  4869. // 'tender.code': 'asc'
  4870. }
  4871. }, {
  4872. total: 0,
  4873. counts: [10, 25, 50, 100],
  4874. getData: function ($defer, params) {
  4875. $scope.loading = true;
  4876. var pageParams = params.url();
  4877. // var realActive = {};
  4878. pageParams.searchFilter = { // 筛选条件
  4879. keyword: $scope.keyword,
  4880. fromDate: getDateTime($scope.condition.dateFrom),
  4881. endDate: getDateTime($scope.condition.dateTo)
  4882. };
  4883. // AccountEnterprise.get({}, function(data){
  4884. // $scope.currentEn = data;
  4885. // });
  4886. PurchaseInquiry.publicInquiryItem.call(null, BaseService.parseParams(pageParams), function (page) {
  4887. $scope.loading = false;
  4888. if (page) {
  4889. params.total(page.totalElement);
  4890. $defer.resolve(page.content);
  4891. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  4892. }
  4893. }, function (response) {
  4894. $scope.loading = false;
  4895. toaster.pop('error', '数据加载失败', response.data);
  4896. });
  4897. }
  4898. });
  4899. $scope.toDetail = function (id) {
  4900. window.location.hash = '#/baseInfo/inquiryList/' + id;
  4901. };
  4902. // 搜索框回车
  4903. $scope.onSearch = function () {
  4904. $scope.tableParams.page(1);
  4905. $scope.tableParams.reload();
  4906. };
  4907. }]);
  4908. /**
  4909. * 公共询价详情
  4910. */
  4911. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise) {
  4912. BaseService.scrollBackToTop();
  4913. $scope.currentHasBid = false;
  4914. var loadData = function () {
  4915. PurchaseInquiry.inquiryItemDetail({id: $stateParams.id}, function (data) {
  4916. $scope.inquiryItem = data.inquiryItem;
  4917. if (data.id) {
  4918. $scope.id = data.id;
  4919. $scope.currentHasBid = true;
  4920. }
  4921. }, function (response) {
  4922. toaster.pop('error', '提示', response.data);
  4923. });
  4924. };
  4925. loadData();
  4926. // 当前时间
  4927. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  4928. // 当前企业
  4929. AccountEnterprise.get({}, function (data) {
  4930. $scope.enterprise = data;
  4931. });
  4932. // 转客户询价
  4933. $scope.transtoInquiry = function (id) {
  4934. PurchaseInquiry.transtoInquiry({id: id}, {}, function (data) {
  4935. if (data.success) {
  4936. toaster.pop('success', '提示', data.success);
  4937. window.location.hash = "sale/inquiry/" + data.id;
  4938. }
  4939. if (data.error) {
  4940. toaster.pop('error', '提示', data.error);
  4941. }
  4942. if (data.info) {
  4943. toaster.pop('info', '提示', data.info);
  4944. }
  4945. }, function (response) {
  4946. toaster.pop('error', '提示', response.data);
  4947. });
  4948. }
  4949. }]);
  4950. // 询价单明细
  4951. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, CurrentRole) {
  4952. // 获取当前用户是否为普通用户
  4953. CurrentRole.isUser({}, {}, function (data) {
  4954. $scope.isUser = !data.isUser;
  4955. });
  4956. var loadData = function () {
  4957. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  4958. $scope.newinquiryItems = data;
  4959. var inquiry = data[0].inquiry;
  4960. //inquiry.inquiryItems = data;
  4961. angular.forEach(inquiry.attachs, function (attach) {
  4962. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  4963. });
  4964. $scope.inquiry = inquiry;
  4965. });
  4966. };
  4967. loadData();
  4968. $scope.getMinDate = function (item) {
  4969. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4970. };
  4971. $scope.addStep = function (inquiryItem) {
  4972. if (inquiryItem.replies.length >= 10) {
  4973. toaster.pop('warning', '提示', '最多支持10个分段!');
  4974. } else
  4975. inquiryItem.replies.push({});
  4976. };
  4977. $scope.removeStep = function (inquiryItem, stepIndex) {
  4978. inquiryItem.replies.splice(stepIndex, 1);
  4979. };
  4980. $scope.openDatePicker = function ($event, item, openParam) {
  4981. $event.preventDefault();
  4982. $event.stopPropagation();
  4983. item[openParam] = !item[openParam];
  4984. };
  4985. $scope.getHistory = function (item) {
  4986. if (!item.history) {
  4987. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  4988. item.history = data;
  4989. });
  4990. }
  4991. };
  4992. $scope.isValid = function (item, withSteps) {
  4993. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4994. if (!withSteps || !bool)
  4995. return bool;
  4996. angular.forEach(item.replies, function (r, i) {
  4997. bool = (i > 0 ? r.lapQty : 1) && r.price;
  4998. });
  4999. return bool;
  5000. };
  5001. $scope.onReplyClick = function (item, withSteps) {
  5002. if (item.vendFromDate instanceof Date) {
  5003. item.vendFromDate = item.vendFromDate.getTime();
  5004. }
  5005. if (item.vendToDate instanceof Date) {
  5006. item.vendToDate = item.vendToDate.getTime();
  5007. }
  5008. if (item.vendFromDate > item.vendToDate) {
  5009. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5010. return;
  5011. }
  5012. var replies = [];
  5013. angular.forEach(item.replies, function (r, i) {
  5014. if ((i > 0 ? r.lapQty : 1) || r.price)
  5015. replies.push(r);
  5016. });
  5017. item.replies = replies;
  5018. if (withSteps) {
  5019. PurcInquiry.reply({itemId: item.id}, item, function () {
  5020. toaster.pop('info', '提示', '报价成功');
  5021. loadData();
  5022. }, function (response) {
  5023. toaster.pop('error', '报价失败', response.data);
  5024. });
  5025. }
  5026. };
  5027. }]);
  5028. // 询价单明细(发出)
  5029. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, CurrentRole) {
  5030. // 获取当前用户是否为普通用户
  5031. CurrentRole.isUser({}, {}, function (data) {
  5032. $scope.isUser = data.isUser;
  5033. });
  5034. var loadData = function () {
  5035. PurchaseInquiry.detail({id: $stateParams.id}, function (data) {
  5036. $scope.inquiry = data;
  5037. });
  5038. };
  5039. loadData();
  5040. $scope.getMinDate = function (item) {
  5041. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5042. };
  5043. $scope.nowDate = new Date().getTime();
  5044. $scope.addStep = function (inquiryItem) {
  5045. if (inquiryItem.replies.length >= 10) {
  5046. toaster.pop('warning', '提示', '最多支持10个分段!');
  5047. } else
  5048. inquiryItem.replies.push({});
  5049. };
  5050. $scope.removeStep = function (inquiryItem, stepIndex) {
  5051. inquiryItem.replies.splice(stepIndex, 1);
  5052. };
  5053. $scope.openDatePicker = function ($event, item, openParam) {
  5054. $event.preventDefault();
  5055. $event.stopPropagation();
  5056. item[openParam] = !item[openParam];
  5057. };
  5058. $scope.getHistory = function (item) {
  5059. if (!item.history) {
  5060. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5061. item.history = data;
  5062. });
  5063. }
  5064. };
  5065. $scope.isValid = function (item, withSteps) {
  5066. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5067. if (!withSteps || !bool)
  5068. return bool;
  5069. angular.forEach(item.replies, function (r, i) {
  5070. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5071. });
  5072. return bool;
  5073. };
  5074. $scope.onReplyClick = function (item, withSteps) {
  5075. if (item.vendFromDate instanceof Date) {
  5076. item.vendFromDate = item.vendFromDate.getTime();
  5077. }
  5078. if (item.vendToDate instanceof Date) {
  5079. item.vendToDate = item.vendToDate.getTime();
  5080. }
  5081. if (item.vendFromDate > item.vendToDate) {
  5082. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5083. return;
  5084. }
  5085. var replies = [];
  5086. angular.forEach(item.replies, function (r, i) {
  5087. if ((i > 0 ? r.lapQty : 1) || r.price)
  5088. replies.push(r);
  5089. });
  5090. item.replies = replies;
  5091. if (withSteps) {
  5092. PurcInquiry.reply({itemId: item.id}, item, function () {
  5093. toaster.pop('info', '提示', '报价成功');
  5094. loadData();
  5095. }, function (response) {
  5096. toaster.pop('error', '报价失败', response.data);
  5097. });
  5098. }
  5099. };
  5100. // 采纳
  5101. $scope.accept = function (id) {
  5102. PurchaseInquiry.accept({id: id}, {}, function (data) {
  5103. if (data.success) {
  5104. toaster.pop('success', '提示', data.success);
  5105. loadData();
  5106. }
  5107. if (data.error) {
  5108. toaster.pop('error', '提示', data.error);
  5109. }
  5110. }, function (response) {
  5111. toaster.pop('error', '提示', response.data);
  5112. })
  5113. };
  5114. // 拒绝
  5115. $scope.refuse = function (id) {
  5116. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  5117. if (data.success) {
  5118. toaster.pop('success', '提示', data.success);
  5119. loadData();
  5120. }
  5121. if (data.error) {
  5122. toaster.pop('error', '提示', data.error);
  5123. }
  5124. }, function (response) {
  5125. toaster.pop('error', '提示', response.data);
  5126. })
  5127. }
  5128. }]);
  5129. // 模具询价管理
  5130. app.controller('SaleInquiryMouldCtrl', ['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', 'PurcInquiryMouldSql', 'CurrentRole', function ($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload, PurcInquiryMouldSql, CurrentRole) {
  5131. BaseService.scrollBackToTop();
  5132. // 获取当前用户是否为普通用户
  5133. CurrentRole.isUser({}, {}, function (data) {
  5134. $scope.isUser = data.isUser;
  5135. });
  5136. $scope.active = 'todo';
  5137. $scope.agreedText = '全部';
  5138. $scope.dateZoneText = '不限';
  5139. $scope.condition = {dateZone: 1};
  5140. /* 时间筛选初始化*/
  5141. var fromDate = new Date();
  5142. var toDate = new Date();
  5143. fromDate.setMonth(fromDate.getMonth() - 1);
  5144. fromDate.setHours(0, 0, 0, 0);
  5145. toDate.setHours(23, 59, 59, 999);
  5146. $scope.condition.dateFrom = fromDate;
  5147. $scope.condition.dateTo = toDate;
  5148. var inquiryMould_copy = {};
  5149. $scope.changeAgreed = function (agreed) {
  5150. $scope.condition.agreed = agreed;
  5151. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  5152. $scope.condition.$agreedOpen = false;
  5153. };
  5154. $scope.changeDateZone = function (zone) {
  5155. $scope.condition.dateZone = zone;
  5156. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5157. $scope.condition.$dateZoneOpen = false;
  5158. getDateCondition(zone, $scope.condition);
  5159. $scope.tableParams.page(1);
  5160. $scope.tableParams.reload();
  5161. };
  5162. $scope.setActive = function (state) {
  5163. if ($scope.active != state) {
  5164. $scope.active = state;
  5165. if ($scope.tableParams.page() == 1) {
  5166. $scope.tableParams.reload();
  5167. } else {
  5168. $scope.tableParams.page(1);
  5169. }
  5170. }
  5171. };
  5172. var getService = function () {
  5173. if ($scope.keyword) {
  5174. return PurcInquiryMould;
  5175. } else {
  5176. return PurcInquiryMouldSql;
  5177. }
  5178. };
  5179. $scope.tableParams = new ngTableParams({
  5180. page: 1,
  5181. count: 5
  5182. }, {
  5183. total: 0,
  5184. counts: [5, 10, 25, 50],
  5185. getData: function ($defer, params) {
  5186. $scope.loading = true;
  5187. var pageParams = params.url();
  5188. var realActive = {};
  5189. pageParams.searchFilter = {
  5190. keyword: $scope.keyword,
  5191. fromDate: getDateTime($scope.condition.dateFrom),
  5192. endDate: getDateTime($scope.condition.dateTo)
  5193. };
  5194. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  5195. $scope.loading = false;
  5196. // 用来验证价格修改
  5197. var mould = page.content;
  5198. inquiryMould_copy = angular.copy(mould);
  5199. if (page) {
  5200. params.total(page.totalElement);
  5201. $defer.resolve(page.content);
  5202. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5203. }
  5204. }, function (response) {
  5205. $scope.loading = false;
  5206. toaster.pop('error', '数据加载失败', response.data);
  5207. });
  5208. }
  5209. });
  5210. //获得各分类未阅读数量
  5211. var getUnreadCount = function () {
  5212. PurcInquiryMould.getUnreadCount(null, function(data){
  5213. $scope.unread = data;
  5214. });
  5215. };
  5216. getUnreadCount();
  5217. //设置单据已读
  5218. $scope.setOrdersRead = function (id) {
  5219. // 如果单据本身已读,则不发送请求修改数据
  5220. if (!$scope.isUnread(id)){
  5221. return;
  5222. }
  5223. var sourceId = [];
  5224. sourceId.push(id);
  5225. PurcInquiryMould.setRead({}, sourceId, function (message) {
  5226. // $scope.getUnreadIds();
  5227. getUnreadCount();
  5228. });
  5229. };
  5230. $scope.setOrdersReadByState = function () {
  5231. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  5232. return;
  5233. }
  5234. PurcInquiryMould.setReadByState({}, function () {
  5235. getUnreadIds();
  5236. getUnreadCount();
  5237. });
  5238. };
  5239. //获取未读单据id
  5240. var getUnreadIds = function (){
  5241. PurcInquiryMould.getUnreadIds({}, "", function (message) {
  5242. $scope.unreadCode = message.content;
  5243. });
  5244. };
  5245. getUnreadIds();
  5246. //判断单据是否未读
  5247. $scope.isUnread = function (id){
  5248. for (var i in $scope.unreadCode) {
  5249. if (id == $scope.unreadCode[i]) {
  5250. return true;
  5251. }
  5252. }
  5253. };
  5254. $scope.getMinDate = function (item) {
  5255. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  5256. };
  5257. $scope.replyPrices = [];
  5258. $scope.replyPrices.push(true);
  5259. // 取消
  5260. $scope.reload = function () {
  5261. $scope.tableParams.reload();
  5262. $scope.canSave = false;
  5263. }
  5264. // 能否保存设置
  5265. $scope.canSave = false;
  5266. // items价格验证
  5267. $scope.verifyItems = function (price, reply) {
  5268. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  5269. if (regex.test(price) && price != 0) {
  5270. if (price != reply) {
  5271. $scope.canSave = true;
  5272. } else {
  5273. $scope.canSave = false;
  5274. }
  5275. } else {
  5276. $scope.canSave = false;
  5277. }
  5278. }
  5279. // prod下prods价格验证
  5280. $scope.verifyProds = function (price, reply) {
  5281. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5282. if (regex.test(price) && price != 0) {
  5283. if (price != reply) {
  5284. $scope.canSave = true;
  5285. } else {
  5286. $scope.canSave = false;
  5287. }
  5288. } else {
  5289. $scope.canSave = false;
  5290. }
  5291. }
  5292. //有价格为0或者不符合正则式,则不能报价
  5293. $scope.notZero = function (mould) {
  5294. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5295. angular.forEach(mould.inquiryMouldItems, function (item) {
  5296. if (item.price == 0 || !regex.test(item.price)) {
  5297. $scope.canSave = false;
  5298. }
  5299. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5300. if (detail.price == 0 || !regex.test(detail.price)) {
  5301. $scope.canSave = false;
  5302. }
  5303. })
  5304. });
  5305. }
  5306. $scope.blurPrice = function (price) {
  5307. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5308. if (!regex.test(price)) {
  5309. toaster.pop('warning', '格式错误', '请输入有效价格');
  5310. }
  5311. }
  5312. // 获取历史报价
  5313. $scope.getHistory = function (mould) {
  5314. if (!mould.history) {
  5315. PurcInquiryMould.getHistory({id: mould.id}, function (data) {
  5316. mould.history = data;
  5317. });
  5318. }
  5319. };
  5320. var uploadAttach = function (mould, file) {
  5321. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5322. $scope.mould = mould;
  5323. $upload.upload({
  5324. url: 'sale/mould/' + mould.id + '/send',
  5325. method: 'POST',
  5326. file: file,
  5327. data: {
  5328. json: $scope.mould
  5329. }
  5330. }).success(function (res) {
  5331. $scope.mould.sellAttachs.push(res);
  5332. }).error(function (res) {
  5333. });
  5334. }
  5335. $scope.pushFile = function(mould, file) {
  5336. // var file = $scope.myFiles;
  5337. if (file.length > 0) {
  5338. for (var i = 0; i < file.length; i++) {
  5339. console.log(file[i].name);
  5340. var flag = true;
  5341. if (mould.sellAttachs.length > 0) {
  5342. for (var j = 0; j < mould.sellAttachs.length; j++) {
  5343. if (mould.sellAttachs[j].name == file[i].name
  5344. && mould.sellAttachs[j].size == file[i].size) {
  5345. flag = false;
  5346. break;
  5347. }
  5348. }
  5349. }
  5350. if (flag) {
  5351. uploadAttach(mould, file[i]);
  5352. $scope.canSave = true;
  5353. }
  5354. }
  5355. }
  5356. document.getElementById("inquiryMould.sellAttachs").value = "";
  5357. };
  5358. $scope.removeFile = function(mould, file) {
  5359. $scope.inquiryMould = mould;
  5360. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5361. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5362. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5363. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5364. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5365. }
  5366. }
  5367. }
  5368. };
  5369. // 保存并确认报价
  5370. $scope.onReplyClick = function (mould, withSteps) {
  5371. $scope.loading = true;
  5372. //// var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5373. // var file = mould.attachs[0];
  5374. // $scope.mould = mould;
  5375. // $upload.upload({
  5376. // url: 'sale/mould/' + mould.id + '/send',
  5377. // method: 'POST',
  5378. // file: file,
  5379. // data: {
  5380. // json: $scope.mould
  5381. // }
  5382. // }).success(function(res){
  5383. // console.log("success");
  5384. // console.log(res);
  5385. // }).error(function(res){
  5386. // console.log("failure");
  5387. // });
  5388. if (withSteps) {
  5389. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5390. $scope.loading = false;
  5391. toaster.pop('info', '提示', '报价成功');
  5392. $scope.tableParams.reload();
  5393. $scope.canSave = false;
  5394. }, function (response) {
  5395. $scope.loading = false;
  5396. toaster.pop('error', '报价失败', response.data);
  5397. });
  5398. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5399. }, function (response) {
  5400. });
  5401. } else {
  5402. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5403. $scope.loading = false;
  5404. toaster.pop('info', '提示', '保存成功');
  5405. $scope.tableParams.reload();
  5406. }, function (response) {
  5407. $scope.loading = false;
  5408. toaster.pop('error', '保存失败', response.data);
  5409. });
  5410. }
  5411. };
  5412. // 搜索框回车
  5413. $scope.onSearch = function () {
  5414. $scope.tableParams.page(1);
  5415. $scope.tableParams.reload();
  5416. };
  5417. $scope.openDatePicker = function ($event, item, openParam) {
  5418. $event.preventDefault();
  5419. $event.stopPropagation();
  5420. item[openParam] = !item[openParam];
  5421. };
  5422. $scope.openFilterDatePicker = function ($event, item, openParam) {
  5423. $event.preventDefault();
  5424. $event.stopPropagation();
  5425. item[openParam] = !item[openParam];
  5426. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  5427. $scope.tableParams.reload();
  5428. }
  5429. };
  5430. $scope.parseDate = function (dateStr) {
  5431. if (dateStr)
  5432. return Date.parse(dateStr, 'yyyy-MM-dd');
  5433. return new Date();
  5434. };
  5435. // 导出客户资料列表
  5436. $scope.exportXls = function () {
  5437. PurcInquiryMould.exportXls({}, {}, function (data) {
  5438. if (data.success){
  5439. window.location.href = 'sale/mould/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  5440. }
  5441. }, function (response) {
  5442. toaster.pop('error', '数据加载失败', response.data);
  5443. });
  5444. }
  5445. }]);
  5446. // 模具询价单明细
  5447. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould', '$filter', 'toaster', '$upload', 'CurrentRole', function ($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload, CurrentRole) {
  5448. // 获取当前用户是否为普通用户
  5449. CurrentRole.isUser({}, {}, function (data) {
  5450. $scope.isUser = data.isUser;
  5451. });
  5452. var inquiryMould_copy = {};
  5453. var loadData = function () {
  5454. PurcInquiryMould.getAll({id: $stateParams.id}, function (data) {
  5455. // 用来验证价格修改
  5456. inquiryMould_copy = angular.copy(data);
  5457. $scope.inquiryMould_copy = inquiryMould_copy;
  5458. $scope.newinquirymould = data;
  5459. var mould = data;
  5460. angular.forEach(mould.attachs, function (attach) {
  5461. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5462. });
  5463. $scope.inquiryMould = mould;
  5464. }, function (response) {
  5465. toaster.pop('error', '数据加载失败', response.data);
  5466. });
  5467. };
  5468. loadData();
  5469. $scope.getMinDate = function (item) {
  5470. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5471. };
  5472. // 取消
  5473. $scope.reload = function () {
  5474. loadData();
  5475. $scope.canSave = false;
  5476. }
  5477. //有价格为0,则不能报价
  5478. $scope.notZero = function (mould) {
  5479. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5480. angular.forEach(mould.inquiryMouldItems, function (item) {
  5481. if (item.price == 0 || !regex.test(item.price)) {
  5482. $scope.canSave = false;
  5483. }
  5484. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5485. if (detail.price == 0 || !regex.test(detail.price)) {
  5486. $scope.canSave = false;
  5487. }
  5488. })
  5489. });
  5490. }
  5491. $scope.blurPrice = function (price) {
  5492. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5493. if (!regex.test(price)) {
  5494. toaster.pop('warning', '格式错误', '请输入有效价格');
  5495. }
  5496. }
  5497. // 获取历史报价
  5498. $scope.getHistory = function (mould) {
  5499. if (!mould.history) {
  5500. PurcInquiryMould.getHistory({id: mould.id}, function (data) {
  5501. mould.history = data;
  5502. });
  5503. }
  5504. };
  5505. $scope.canSave = false;
  5506. // items价格验证
  5507. $scope.verifyItems = function (price, index) {
  5508. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5509. if (regex.test(price) && price != 0) {
  5510. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  5511. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  5512. $scope.canSave = true;
  5513. } else {
  5514. $scope.canSave = false;
  5515. }
  5516. } else {
  5517. $scope.canSave = false;
  5518. }
  5519. }
  5520. // prod下prods价格验证
  5521. $scope.verifyProds = function (price, index, parentIndex) {
  5522. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5523. if (regex.test(price) && price != 0) {
  5524. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  5525. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  5526. $scope.canSave = true;
  5527. } else {
  5528. $scope.canSave = false;
  5529. }
  5530. } else {
  5531. $scope.canSave = false;
  5532. }
  5533. }
  5534. // 上传附件
  5535. var uploadAttach = function(file) {
  5536. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5537. $scope.mould = $scope.inquiryMould;
  5538. $upload.upload({
  5539. url: 'sale/mould/' + $scope.mould.id + '/send',
  5540. method: 'POST',
  5541. file: file,
  5542. data: {
  5543. json: $scope.mould
  5544. }
  5545. }).success(function(attach){
  5546. if (attach){
  5547. $scope.inquiryMould.sellAttachs.push(attach);
  5548. }
  5549. }).error(function(res){
  5550. console.log("failure");
  5551. console.log(res);
  5552. });
  5553. }
  5554. $scope.pushFile = function(file) {
  5555. // var file = $scope.myFiles;
  5556. if (file.length > 0) {
  5557. for (var i = 0; i < file.length; i++) {
  5558. console.log(file[i].name);
  5559. var flag = true;
  5560. if ($scope.inquiryMould.sellAttachs.length > 0) {
  5561. for (var j = 0; j < $scope.inquiryMould.sellAttachs.length; j++) {
  5562. if ($scope.inquiryMould.sellAttachs[j].name == file[i].name
  5563. && $scope.inquiryMould.sellAttachs[j].size == file[i].size) {
  5564. flag = false;
  5565. break;
  5566. }
  5567. }
  5568. }
  5569. if (flag) {
  5570. uploadAttach(file[i]);
  5571. }
  5572. }
  5573. }
  5574. };
  5575. $scope.removeFile = function(file) {
  5576. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5577. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5578. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5579. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5580. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5581. document.getElementById("file").value = "";
  5582. }
  5583. }
  5584. }
  5585. };
  5586. $scope.onReplyClick = function (mould, withSteps) {
  5587. $scope.loading = true;
  5588. // var file = mould.attachs[0];
  5589. // $scope.mould = mould;
  5590. // $upload.upload({
  5591. // url: 'sale/mould/' + mould.id + '/send',
  5592. // method: 'POST',
  5593. // file: file,
  5594. // data: {
  5595. // json: $scope.mould
  5596. // }
  5597. // }).success(function(res){
  5598. //
  5599. // }).error(function(res){
  5600. // console.log(res);
  5601. // });
  5602. if (withSteps) {
  5603. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5604. $scope.loading = false;
  5605. toaster.pop('info', '提示', '报价成功');
  5606. loadData();
  5607. $scope.canSave = false;
  5608. }, function (response) {
  5609. $scope.loading = false;
  5610. toaster.pop('error', '报价失败', response.data);
  5611. });
  5612. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5613. }, function (response) {
  5614. });
  5615. } else {
  5616. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5617. $scope.loading = false;
  5618. toaster.pop('info', '提示', '保存成功');
  5619. loadData();
  5620. }, function (response) {
  5621. $scope.loading = false;
  5622. toaster.pop('error', '保存失败', response.data);
  5623. });
  5624. }
  5625. };
  5626. }]);
  5627. // 主动报价 - 列表
  5628. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', 'QuotationInfo', 'CurrentRole', function ($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope, QuotationInfo, CurrentRole) {
  5629. BaseService.scrollBackToTop();
  5630. // 获取当前用户是否为普通用户
  5631. CurrentRole.isUser({}, {}, function (data) {
  5632. $scope.isUser = data.isUser;
  5633. });
  5634. $rootScope.enteryStatus = false;
  5635. $scope.active = 'todo';
  5636. $scope.agreedText = '全部';
  5637. $scope.dateZoneText = '一个月内';
  5638. $scope.condition = {dateZone: 1};
  5639. /* 时间筛选初始化*/
  5640. var fromDate = new Date();
  5641. var toDate = new Date();
  5642. fromDate.setMonth(fromDate.getMonth() - 1);
  5643. fromDate.setHours(0, 0, 0, 0);
  5644. toDate.setHours(23, 59, 59, 999);
  5645. $scope.condition.dateFrom = fromDate;
  5646. $scope.condition.dateTo = toDate;
  5647. $scope.changeDateZone = function (zone) {
  5648. $scope.condition.dateZone = zone;
  5649. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5650. $scope.condition.$dateZoneOpen = false;
  5651. getDateCondition(zone, $scope.condition);
  5652. $scope.tableParams.page(1);
  5653. $scope.tableParams.reload();
  5654. };
  5655. $scope.setActive = function (state) {
  5656. if ($scope.active != state) {
  5657. $scope.active = state;
  5658. if ($scope.tableParams.page() == 1)
  5659. $scope.tableParams.reload();
  5660. else
  5661. $scope.tableParams.page(1);
  5662. }
  5663. };
  5664. $scope.searchMethod = false;
  5665. var getService = function () {
  5666. return $scope.searchMethod ? Quotation : QuotationInfo;
  5667. };
  5668. $scope.tableParams = new ngTableParams({
  5669. page: 1,
  5670. count: 20,
  5671. sorting: {
  5672. 'date': 'desc'
  5673. }
  5674. }, {
  5675. total: 0,
  5676. counts: [5, 10, 25, 50],
  5677. getData: function ($defer, params) {
  5678. $scope.loading = true;
  5679. var pageParams = params.url();
  5680. pageParams.searchFilter = {
  5681. keyword: $scope.keyword,
  5682. fromDate: getDateTime($scope.condition.dateFrom),
  5683. endDate: getDateTime($scope.condition.dateTo)
  5684. };
  5685. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  5686. $scope.loading = false;
  5687. if (page) {
  5688. params.total(page.totalElement);
  5689. $defer.resolve(page.content);
  5690. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5691. }
  5692. }, function (response) {
  5693. $scope.loading = false;
  5694. toaster.pop('error', '数据加载失败', response.data);
  5695. });
  5696. }
  5697. });
  5698. $scope.openDatePicker = function ($event, item, openParam) {
  5699. $event.preventDefault();
  5700. $event.stopPropagation();
  5701. item[openParam] = !item[openParam];
  5702. };
  5703. $scope.openFilterDatePicker = function ($event, item, openParam) {
  5704. $event.preventDefault();
  5705. $event.stopPropagation();
  5706. item[openParam] = !item[openParam];
  5707. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  5708. $scope.tableParams.reload();
  5709. }
  5710. };
  5711. $scope.getHistory = function (item) {
  5712. if (!item.history) {
  5713. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5714. item.history = data;
  5715. });
  5716. }
  5717. };
  5718. $scope.isValid = function (item, withSteps) {
  5719. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5720. if (!withSteps || !bool)
  5721. return bool;
  5722. angular.forEach(item.replies, function (r, i) {
  5723. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5724. });
  5725. return bool;
  5726. };
  5727. // 搜索框回车
  5728. $scope.onSearch = function (keyword) {
  5729. // 每次搜索重置获取数据方法
  5730. $scope.searchMethod = false;
  5731. if(keyword != null && keyword != '') {
  5732. $scope.searchMethod = true;
  5733. }
  5734. $scope.tableParams.page(1);
  5735. $scope.tableParams.reload();
  5736. };
  5737. // 导出
  5738. $scope.exportXls = function () {
  5739. Quotation.exportXls({}, {}, function (data) {
  5740. if (data.success){
  5741. window.location.href = 'sale/quotation/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  5742. }
  5743. }, function (response) {
  5744. toaster.pop('error', '数据加载失败', response.data);
  5745. });
  5746. }
  5747. }]);
  5748. // Controller 主动报价 - 新增
  5749. 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) {
  5750. BaseService.scrollBackToTop();
  5751. // 获取当前用户是否为普通用户
  5752. CurrentRole.isUser({}, {}, function (data) {
  5753. $scope.isUser = data.isUser;
  5754. });
  5755. var staticItem = null;
  5756. if (!angular.isUndefined($stateParams.id)) {// 查看模式
  5757. $scope.loading = true;
  5758. $rootScope.enteryStatus = true;
  5759. Quotation.getItem({id: $stateParams.id}, function (data) {
  5760. // data.$editing = false;
  5761. $scope.item = data;
  5762. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  5763. staticItem = angular.copy(data);
  5764. $scope.loading = false;
  5765. }, function (response) {
  5766. $scope.loading = false;
  5767. toaster.pop('error', '数据加载失败', response.data);
  5768. });
  5769. } else {// 新增模式
  5770. $rootScope.enteryStatus = false;
  5771. $scope.item = {
  5772. quotation: {
  5773. currency: 'RMB',
  5774. taxrate: 17,
  5775. date: new Date()
  5776. },
  5777. product: {},
  5778. prices: [{lapQty: 0}],
  5779. minOrderQty: 1,
  5780. minPackQty: 1,
  5781. $endDateOpen: false,
  5782. $editing: true
  5783. };
  5784. }
  5785. $scope.getMinDate = function (item) {
  5786. return $filter('date')(new Date, 'yyyy-MM-dd');
  5787. };
  5788. //是否不能被点击
  5789. $scope.isDisabled = function () {
  5790. return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
  5791. }
  5792. $scope.openDatePicker = function ($event, openParam) {
  5793. $event.preventDefault();
  5794. $event.stopPropagation();
  5795. $scope.item.$endDateOpen = !openParam;
  5796. };
  5797. // 增加一个分段
  5798. $scope.addPrice = function () {
  5799. if ($scope.item.prices.length >= 10) {
  5800. toaster.pop('warning', '提示', '最多支持10个分段!');
  5801. } else
  5802. $scope.item.prices.push({});
  5803. };
  5804. // 删除一个分段
  5805. $scope.removePrice = function (index) {
  5806. $scope.item.prices.splice(index, 1);
  5807. };
  5808. // 查找客户
  5809. $scope.dbfindCust = function () {
  5810. if ($scope.item.$editing) {
  5811. var modalInstance = $modal.open({
  5812. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  5813. controller: 'DbfindCustCtrl',
  5814. size: 'lg',
  5815. resolve: {}
  5816. });
  5817. modalInstance.result.then(function (data) {
  5818. $scope.item.quotation.cust = data.myEnterprise;
  5819. $scope.item.quotation.custUser = data.myUser;
  5820. $scope.item.product = null;
  5821. }, function () {
  5822. });
  5823. }
  5824. };
  5825. // 赋值客户信息
  5826. if ($rootScope.custuu) {
  5827. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function (data) {
  5828. $scope.item.quotation.cust = data.myEnterprise;
  5829. $scope.item.quotation.custUser = data.myUser;
  5830. })
  5831. }
  5832. // 赋值物料信息
  5833. if ($rootScope.prodId) {
  5834. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  5835. $scope.item.product.code = data.code;
  5836. $scope.item.product.title = data.title;
  5837. $scope.item.product.spec = data.spec;
  5838. $scope.item.product.unit = data.unit;
  5839. $scope.item.product.id = data.id;
  5840. }, function (response) {
  5841. });
  5842. }
  5843. // 查找客户物料
  5844. $scope.dbfindCustProd = function () {
  5845. if ($scope.item.$editing) {
  5846. if ($scope.item.quotation.cust) {
  5847. var modalInstance = $modal.open({
  5848. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  5849. controller: 'DbfindCustProdCtrl',
  5850. size: 'lg',
  5851. resolve: {
  5852. custUU: function () {
  5853. return $scope.item.quotation.cust.uu
  5854. }
  5855. }
  5856. });
  5857. modalInstance.result.then(function (data) {
  5858. $scope.item.product = data;
  5859. }, function () {
  5860. });
  5861. } else {
  5862. toaster.pop('error', '错误', '请先选择客户');
  5863. }
  5864. }
  5865. };
  5866. // 保存
  5867. $scope.save = function () {
  5868. var valid = true;
  5869. angular.forEach($scope.item.prices, function(price, $index) {
  5870. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  5871. valid = false;
  5872. }
  5873. });
  5874. if (!valid) {
  5875. toaster.pop('info', '提示', '分段数量请保持递增!');
  5876. } else {
  5877. $scope.loading = true;
  5878. if (!$scope.item.quotation.code) //新增,设单号
  5879. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  5880. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  5881. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  5882. $scope.item.productId = $scope.item.product.id;
  5883. // $scope.item.quotation.status = 100;//在录入
  5884. if ($scope.item.quotation.date instanceof Date) {
  5885. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  5886. }
  5887. if ($scope.item.quotation.endDate instanceof Date) {
  5888. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  5889. }
  5890. Quotation.save({}, $scope.item, function (data) {
  5891. $scope.loading = false;
  5892. $scope.item = data;
  5893. toaster.pop('success', '成功', '保存成功');
  5894. if ($stateParams.id)
  5895. window.location.reload();
  5896. else
  5897. // window.location.hash = '#/sale/quotation/' + data.id;
  5898. window.location.hash = '#/sale/quotation/list';
  5899. }, function (response) {
  5900. $scope.loading = false;
  5901. toaster.pop('error', '保存失败', response.data);
  5902. });
  5903. }
  5904. };
  5905. // 更新
  5906. $scope.update = function () {
  5907. $scope.item.$editing = true;
  5908. };
  5909. // 取消
  5910. $scope.cancel = function () {
  5911. $scope.item.$editing = false;
  5912. $scope.item = angular.copy(staticItem);
  5913. };
  5914. // 提交
  5915. $scope.submit = function () {
  5916. var valid = true;
  5917. angular.forEach($scope.item.prices, function(price, $index) {
  5918. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  5919. valid = false;
  5920. }
  5921. });
  5922. if (!valid) {
  5923. toaster.pop('info', '提示', '分段数量请保持递增!');
  5924. } else {
  5925. $scope.loading = true;
  5926. if (!$scope.item.quotation.code) //新增,设单号
  5927. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  5928. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  5929. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  5930. $scope.item.productId = $scope.item.product.id;
  5931. // $scope.item.quotation.status = 101;//已提交
  5932. if ($scope.item.quotation.date instanceof Date) {
  5933. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  5934. }
  5935. if ($scope.item.quotation.endDate instanceof Date) {
  5936. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  5937. }
  5938. Quotation.submit({}, $scope.item, function (data) {
  5939. $scope.loading = false;
  5940. $scope.item = data;
  5941. toaster.pop('success', '成功', '提交成功');
  5942. // window.location.hash = '#/sale/quotation/' + data.id;
  5943. window.location.hash = '#/sale/quotation/list';
  5944. }, function (response) {
  5945. $scope.loading = false;
  5946. toaster.pop('error', '保存失败', response.data);
  5947. });
  5948. }
  5949. };
  5950. $scope.deleteById = function (id) {
  5951. Quotation.deleteById({id: id}, {}, function (data) {
  5952. window.location.href = "#/sale/quotation/list";
  5953. }, function (response) {
  5954. toaster.pop('error', '提示', response.data);
  5955. })
  5956. }
  5957. }]);
  5958. // 查找客户
  5959. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function ($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance) {
  5960. BaseService.scrollBackToTop();
  5961. $scope.tableParams = new ngTableParams({
  5962. page: 1,
  5963. count: 20
  5964. }, {
  5965. total: 0,
  5966. counts: [5, 10, 25, 50],
  5967. getData: function ($defer, params) {
  5968. $scope.loading = true;
  5969. var pageParams = params.url();
  5970. pageParams.keyword = $scope.keyword;
  5971. Customer.get(BaseService.parseParams(pageParams), function (page) {
  5972. $scope.loading = false;
  5973. if (page) {
  5974. params.total(page.totalElement);
  5975. $defer.resolve(page.content);
  5976. }
  5977. $scope.totalCount = page.totalElement;
  5978. }, function (response) {
  5979. $scope.loading = false;
  5980. toaster.pop('error', '数据加载失败', response.data);
  5981. });
  5982. }
  5983. });
  5984. $scope.onSearch = function () {
  5985. $scope.tableParams.page(1);
  5986. $scope.tableParams.reload();
  5987. };
  5988. $scope.cancel = function () {
  5989. $modalInstance.dismiss();
  5990. };
  5991. $scope.check = function (cust) {
  5992. $modalInstance.close(cust);
  5993. };
  5994. }]);
  5995. // 查找客户物料
  5996. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function ($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU) {
  5997. BaseService.scrollBackToTop();
  5998. $scope.tableParams = new ngTableParams({
  5999. page: 1,
  6000. count: 20
  6001. }, {
  6002. total: 0,
  6003. counts: [5, 10, 25, 50],
  6004. getData: function ($defer, params) {
  6005. $scope.loading = true;
  6006. var pageParams = params.url();
  6007. pageParams.keyword = $scope.keyword;
  6008. pageParams.custUU = custUU;
  6009. Product.get.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.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6015. }
  6016. }, function (response) {
  6017. $scope.loading = false;
  6018. toaster.pop('error', '数据加载失败', response.data);
  6019. });
  6020. }
  6021. });
  6022. // 取消
  6023. $scope.cancel = function () {
  6024. $modalInstance.dismiss();
  6025. };
  6026. // 选择
  6027. $scope.check = function (cust) {
  6028. $modalInstance.close(cust);
  6029. };
  6030. // 搜索框回车
  6031. $scope.onSearch = function () {
  6032. $scope.tableParams.page(1);
  6033. $scope.tableParams.reload();
  6034. };
  6035. }]);
  6036. // 查找供应商
  6037. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', '$rootScope', function ($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope) {
  6038. BaseService.scrollBackToTop();
  6039. // 搜索框回车
  6040. $scope.onSearch = function (keyword) {
  6041. $scope.keyword = keyword;
  6042. $scope.tableParams.page(1);
  6043. $scope.tableParams.reload();
  6044. };
  6045. $scope.tableParams = new ngTableParams({
  6046. page: 1,
  6047. count: 20
  6048. }, {
  6049. total: 0,
  6050. counts: [10, 25, 50, 100],
  6051. getData: function ($defer, params) {
  6052. $scope.loading = true;
  6053. var pageParams = params.url();
  6054. pageParams.keyword = $scope.keyword;
  6055. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  6056. $scope.loading = false;
  6057. if (page) {
  6058. params.total(page.totalElement);
  6059. $defer.resolve(page.content);
  6060. // 添加供应商时,将已存在的选中
  6061. if ($rootScope.tenderVendor) {
  6062. angular.forEach(page.content, function (vendor) {
  6063. for (var i = 0; i < $rootScope.tenderVendor.length; i++) {
  6064. vendor.checked = false;
  6065. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  6066. vendor.checked = true;
  6067. break;
  6068. }
  6069. }
  6070. });
  6071. }
  6072. }
  6073. $scope.totalCount = page.totalElement;
  6074. }, function (response) {
  6075. $scope.loading = false;
  6076. toaster.pop('error', '数据加载失败', response.data);
  6077. });
  6078. }
  6079. });
  6080. $scope.cancel = function () {
  6081. $modalInstance.dismiss();
  6082. };
  6083. $scope.checks = {
  6084. checked: false
  6085. };// 全选框
  6086. $scope.checkAll = function () {
  6087. angular.forEach($scope.tableParams.data, function (vendor) {
  6088. vendor.checked = $scope.checks.checked;
  6089. });
  6090. };
  6091. // 单选
  6092. $scope.checkOne = function (vendor) {
  6093. vendor.checked = true;
  6094. var checked = true;
  6095. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  6096. if (!message.checked) {
  6097. checked = false;
  6098. }
  6099. });
  6100. $scope.checks.checked = checked;
  6101. };
  6102. // 单反选
  6103. $scope.unCheckOne = function (vendor) {
  6104. vendor.checked = false;
  6105. $scope.checks.checked = false;
  6106. };
  6107. $scope.close = function () {
  6108. var vendors = [];
  6109. angular.forEach($scope.tableParams.data, function (vendor) {
  6110. if (vendor.checked) {
  6111. vendors.push(vendor);
  6112. $modalInstance.close(vendors);
  6113. }
  6114. });
  6115. };
  6116. }]);
  6117. // 发货提醒
  6118. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', '$timeout', 'PurcNoticeInfo', 'token', 'CurrentRole', function ($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state, $timeout, PurcNoticeInfo, token, CurrentRole) {
  6119. BaseService.scrollBackToTop();
  6120. // 获取当前用户是否为普通用户
  6121. CurrentRole.isUser({}, {}, function (data) {
  6122. $scope.isUser = data.isUser;
  6123. });
  6124. // 用来记录已经选择的id
  6125. $rootScope.ids = [];
  6126. $scope.active = 'todo';
  6127. $scope.currency = Symbol.currency;
  6128. $scope.dateZoneText = '不限';
  6129. $scope.condition = {dateZone: 1};
  6130. $scope.searchStatus = false;
  6131. /* 时间筛选初始化*/
  6132. var fromDate = new Date();
  6133. var toDate = new Date();
  6134. fromDate.setMonth(fromDate.getMonth() - 1);
  6135. fromDate.setHours(0, 0, 0, 0);
  6136. toDate.setHours(23, 59, 59, 999);
  6137. $scope.condition.dateFrom = fromDate;
  6138. $scope.condition.dateTo = toDate;
  6139. $scope.changeDateZone = function (zone) {
  6140. $scope.condition.dateZone = zone;
  6141. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6142. $scope.condition.$dateZoneOpen = false;
  6143. getDateCondition(zone, $scope.condition);
  6144. $scope.tableParams.page(1);
  6145. $scope.tableParams.reload();
  6146. };
  6147. $scope.setActive = function (state) {
  6148. if ($scope.active != state) {
  6149. $scope.active = state;
  6150. if ($scope.tableParams.page() == 1)
  6151. $scope.tableParams.reload();
  6152. else
  6153. $scope.tableParams.page(1);
  6154. }
  6155. };
  6156. var getService = function () {
  6157. if ($scope.searchStatus) {
  6158. return PurcNotice;
  6159. }
  6160. return PurcNoticeInfo;
  6161. };
  6162. $scope.tableParams = new ngTableParams({
  6163. page: 1,
  6164. count: 20,
  6165. sorting: {
  6166. 'id': 'desc'
  6167. }
  6168. }, {
  6169. total: 0,
  6170. counts: [5, 10, 25, 50],
  6171. getData: function ($defer, params) {
  6172. $scope.loading = true;
  6173. var pageParams = params.url();
  6174. pageParams.keyword = $scope.keyword;
  6175. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6176. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6177. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6178. $scope.loading = false;
  6179. if (page) {
  6180. params.total(page.totalElement);
  6181. $defer.resolve(page.content);
  6182. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6183. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6184. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6185. $scope.checkall = true;
  6186. angular.forEach(page.content, function (notice) {
  6187. if ($rootScope.ids.indexOf(notice.id) > -1) {
  6188. notice.$selected = true;
  6189. } else {
  6190. $scope.checkall = false;
  6191. }
  6192. });
  6193. $scope.checkboxes = {
  6194. checked: $scope.checkall
  6195. };
  6196. }
  6197. }, function (response) {
  6198. $scope.loading = false;
  6199. toaster.pop('error', '数据加载失败', response.data);
  6200. });
  6201. }
  6202. });
  6203. //获得各分类未阅读数量
  6204. var getUnreadCount = function () {
  6205. PurcNotice.getUnreadCount(null, function (data) {
  6206. $scope.unread = data;
  6207. });
  6208. };
  6209. getUnreadCount();
  6210. //设置单据已读
  6211. $scope.setOrdersRead = function (id) {
  6212. // 如果单据本身已读,则不发送请求修改数据
  6213. if (!$scope.isUnread(id)){
  6214. return;
  6215. }
  6216. var sourceId = [];
  6217. sourceId.push(id);
  6218. PurcNotice.setRead({}, sourceId, function (message) {
  6219. // $scope.getUnreadIds();
  6220. getUnreadCount();
  6221. });
  6222. };
  6223. $scope.setOrdersReadByState = function () {
  6224. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  6225. return;
  6226. }
  6227. PurcNotice.setReadByState({}, function () {
  6228. getUnreadIds();
  6229. getUnreadCount();
  6230. });
  6231. };
  6232. var getUnreadIds = function () {
  6233. PurcNotice.getUnreadIds({}, "", function (message) {
  6234. $scope.unreadCode = message.content;
  6235. });
  6236. };
  6237. getUnreadIds();
  6238. $scope.isUnread = function (id) {
  6239. for (var i in $scope.unreadCode) {
  6240. if (id == $scope.unreadCode[i]) {
  6241. return true;
  6242. }
  6243. }
  6244. };
  6245. $scope.openDatePicker = function ($event, item, openParam) {
  6246. $event.preventDefault();
  6247. $event.stopPropagation();
  6248. item[openParam] = !item[openParam];
  6249. };
  6250. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6251. $event.preventDefault();
  6252. $event.stopPropagation();
  6253. item[openParam] = !item[openParam];
  6254. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6255. $scope.tableParams.reload();
  6256. }
  6257. };
  6258. //生成随机单号
  6259. $scope.autoCode = function (notice) {
  6260. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  6261. };
  6262. // 获取token信息
  6263. $scope.getToken = function() {
  6264. token.info({userType: 'salenotice'}, {}, function(data) {
  6265. $scope.token = data.token;
  6266. }, function(response) {
  6267. toaster.pop('error', '提示', response.data);
  6268. });
  6269. }
  6270. //可送货日期
  6271. $scope.sendDate = function (notice) {
  6272. var stock = notice.orderItem.product.ltinstock || 0;
  6273. var de = new Date(notice.delivery);
  6274. if (stock == -1) {
  6275. de.setMonth(de.getMonth() - 1);
  6276. de.setDate(25);
  6277. } else if (stock >= 0) {
  6278. de.setDate(de.getDate() - stock - 1);
  6279. }
  6280. return de;
  6281. };
  6282. $scope.lockstatus = false;
  6283. // 锁定时间按钮5秒
  6284. $scope.lockClick = function (notice) {
  6285. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6286. } else if (!notice.send.code) {
  6287. } else {
  6288. $scope.lockstatus = true;
  6289. $timeout(function () {
  6290. $scope.lockstatus = false;
  6291. }, 5000);
  6292. }
  6293. };
  6294. var isSumbit = false;
  6295. $scope.onReplyClick = function (notice) {
  6296. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6297. toaster.pop('warning', '警告', '数量填写错误!');
  6298. } else if (!notice.send.code) {
  6299. toaster.pop('warning', '警告', '请填写发货单号!');
  6300. } else {
  6301. if (!isSumbit) {
  6302. var send = {
  6303. code: notice.send.code,
  6304. remark: notice.send.remark,
  6305. sendItems: [{qty: notice.send.qty}]
  6306. };
  6307. $scope.loading = true;
  6308. PurcNotice.save({id: notice.id, token: $scope.token}, send, function (data) {
  6309. $scope.loading = false;
  6310. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  6311. $state.go('sale.send_detail', {id: data.id});
  6312. }, function (response) {
  6313. $scope.loading = false;
  6314. toaster.pop('error', '发货失败', response.data);
  6315. });
  6316. isSumbit = true;
  6317. return true;
  6318. } else {
  6319. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6320. return false;
  6321. }
  6322. }
  6323. }
  6324. $scope.checkboxes = {
  6325. checked: false
  6326. };
  6327. angular.forEach($scope.tableParams.data, function (item) {
  6328. $scope.checkboxes.checked = false;
  6329. if($rootScope.ids.in_array(item.id)) {
  6330. $rootScope.ids.remove(item.id);
  6331. $scope.checkboxes.checked = true;
  6332. }
  6333. });
  6334. // 点击勾选全部的复选框
  6335. $scope.checkAll = function () {
  6336. angular.forEach($scope.tableParams.data, function (item) {
  6337. if (!item.waiting) {
  6338. item.$selected = $scope.checkboxes.checked;
  6339. if(item.$selected) {
  6340. if(!$rootScope.ids.in_array(item.id)) {
  6341. $rootScope.ids.push(item.id);
  6342. }
  6343. } else {
  6344. if($rootScope.ids.in_array(item.id)) {
  6345. $rootScope.ids.remove(item.id);
  6346. }
  6347. }
  6348. }
  6349. });
  6350. };
  6351. // 判断数组中是否存在某个对象
  6352. Array.prototype.S = String.fromCharCode(2);
  6353. Array.prototype.in_array = function(e) {
  6354. var r = new RegExp(this.S + e + this.S);
  6355. return (r.test(this.S + this.join(this.S) + this.S));
  6356. }
  6357. // 从数组中移除某个对象
  6358. Array.prototype.remove = function(val) {
  6359. var index = this.indexOf(val);
  6360. if (index > -1) {
  6361. this.splice(index, 1);
  6362. }
  6363. };
  6364. // 点击其中一个明细的复选框
  6365. $scope.checkOne = function (order) {
  6366. var result = true;
  6367. angular.forEach($scope.tableParams.data, function (item) {
  6368. if (item.$selected != true) {
  6369. result = false;
  6370. return;
  6371. }
  6372. });
  6373. if(order.$selected) {
  6374. if(!$rootScope.ids.in_array(order.id)) {
  6375. $rootScope.ids.push(order.id);
  6376. }
  6377. } else {
  6378. if($rootScope.ids.in_array(order.id)) {
  6379. $rootScope.ids.remove(order.id);
  6380. }
  6381. }
  6382. $scope.checkboxes = {
  6383. checked: result
  6384. };
  6385. };
  6386. // 打开批量发货模态框
  6387. var sendByBatch = function() {
  6388. var modalInstance = $modal.open({
  6389. animation: true,
  6390. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  6391. controller: 'SaleNoticeSendByBatchCtrl',
  6392. size: 'lg',
  6393. resolve: {
  6394. selectedNotices: function () {
  6395. return $scope.tableParams.data;
  6396. },
  6397. token: function() {
  6398. return $scope.token;
  6399. },
  6400. ids: function() {
  6401. return $rootScope.ids;
  6402. }
  6403. }
  6404. });
  6405. modalInstance.result.then(function () {
  6406. $scope.tableParams.reload();
  6407. }, function () {
  6408. });
  6409. }
  6410. $scope.sendByBatch = function () {
  6411. if($scope.token == null) {
  6412. token.info({userType: 'salenotice'}, {}, function(data) {
  6413. $scope.token = data.token;
  6414. sendByBatch();
  6415. }, function(response) {
  6416. toaster.pop('error', '提示', response.data);
  6417. });
  6418. } else {
  6419. sendByBatch();
  6420. }
  6421. };
  6422. $scope.getSends = function (notice) {
  6423. if (!notice.sends && notice.endQty > 0) {
  6424. notice.getSendsing = true;
  6425. notice.getSendsError = false;
  6426. PurcNotice.getSends({id: notice.id}, function (data) {
  6427. notice.getSendsing = false;
  6428. notice.getSendsError = false;
  6429. notice.sends = data;
  6430. }, function (response) {
  6431. notice.getSendsing = false;
  6432. notice.getSendsError = true;
  6433. notice.getErrorMessage = response.data;
  6434. });
  6435. }
  6436. };
  6437. // 搜索框回车
  6438. $scope.onSearch = function () {
  6439. $scope.searchStatus = true;
  6440. $scope.tableParams.page(1);
  6441. $scope.tableParams.reload();
  6442. };
  6443. // 选择查找日期
  6444. $scope.onDateCondition = function () {
  6445. $scope.tableParams.page(1);
  6446. $scope.tableParams.reload();
  6447. };
  6448. //货车功能
  6449. var truck = $rootScope.truck;
  6450. if (!truck) {
  6451. SaleTruck.query({}, function (data) {
  6452. $rootScope.truck = data;
  6453. });
  6454. }
  6455. $scope.isInTruck = function (noticeId) {
  6456. return truck.indexOf(noticeId) > -1;
  6457. };
  6458. $scope.addtoTruck = function (notice) {
  6459. SaleTruck.save({noticeId: notice.id}, {}, function (data) {
  6460. $rootScope.truck = data;
  6461. });
  6462. };
  6463. $scope.delFromTruck = function (notice) {
  6464. SaleTruck.remove({noticeId: notice.id}, {}, function (data) {
  6465. $rootScope.truck = data;
  6466. });
  6467. };
  6468. $scope.$watch(function () {
  6469. return $rootScope.truck;
  6470. }, function (data) {
  6471. truck = $rootScope.truck;
  6472. }, true);
  6473. $scope.$watch(function () {
  6474. return $rootScope.dataChanged;
  6475. }, function (data) {
  6476. data && ($scope.tableParams.reload());
  6477. }, true);
  6478. // 导出
  6479. $scope.exportXls = function () {
  6480. PurcNotice.exportXls({}, {}, function (data) {
  6481. if (data.success){
  6482. window.location.href = 'sale/notice/xls?_state='+$scope.active+
  6483. '&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  6484. }
  6485. }, function (response) {
  6486. toaster.pop('error', '数据加载失败', response.data);
  6487. });
  6488. }
  6489. }]);
  6490. 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) {
  6491. // $scope.notices = angular.copy(selectedNotices);
  6492. PurcNotice.findByIds({ids : angular.toJson(ids)}, function(data) {
  6493. $scope.notices = angular.copy(data);
  6494. }, function(res) {
  6495. toaster.pop('error', '提示', '发货提醒查询失败');
  6496. });
  6497. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6498. $scope.saleSend = {
  6499. code: '',
  6500. payments: '',
  6501. currency: '',
  6502. custUU: null,
  6503. custUserUU: null,
  6504. remark: '批量发货',
  6505. sendItems: []
  6506. };
  6507. // 计算总数、总额
  6508. $scope.$watch(function () {
  6509. return $scope.notices;
  6510. }, function (data) {
  6511. var q = 0, t = 0;
  6512. if (data) {
  6513. angular.forEach(data, function (d) {
  6514. q += (d.thisSendQty || 0);
  6515. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  6516. });
  6517. }
  6518. $scope.totalQty = q;
  6519. $scope.total = t;
  6520. }, true);
  6521. /**
  6522. * 删除一个已选中的送货提醒
  6523. */
  6524. $scope.removeOne = function (index) {
  6525. $scope.notices.splice(index, 1);
  6526. };
  6527. $scope.lockstatus = false;
  6528. // 锁定时间按钮5秒
  6529. $scope.lockClick = function () {
  6530. $scope.lockstatus = true;
  6531. $timeout(function () {
  6532. $scope.lockstatus = false;
  6533. }, 5000);
  6534. }
  6535. $scope.lockstatus = false;
  6536. // 锁定时间按钮5秒
  6537. $scope.lockClick = function (notice) {
  6538. if ($scope.saleSend.code == '') {//送货单号为空
  6539. return;
  6540. } else {
  6541. $scope.lockstatus = true;
  6542. $timeout(function () {
  6543. $scope.lockstatus = false;
  6544. }, 5000);
  6545. }
  6546. };
  6547. var isSumbit = false;
  6548. //确认送货
  6549. $scope.sendByBatch = function () {
  6550. $scope.saleSend.sendItems = [];
  6551. if ($scope.saleSend.code == '') {//送货单号为空
  6552. toaster.pop('error', '错误', '请输入送货单号');
  6553. return;
  6554. }
  6555. var a = 0;
  6556. var num = 1;
  6557. var valid = true;
  6558. angular.forEach($scope.notices, function (item, key) {
  6559. if (a == 0) {//第一次
  6560. $scope.saleSend.currency = item.orderItem.order.currency;
  6561. $scope.saleSend.custUU = item.enUU;
  6562. $scope.saleSend.payments = item.orderItem.order.payments;
  6563. a = 1;
  6564. } else {//其他
  6565. if ($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  6566. if ($scope.saleSend.custUU != item.enUU) valid = false;
  6567. if ($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  6568. }
  6569. $scope.saleSend.sendItems.push({
  6570. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++
  6571. });
  6572. });
  6573. if (!valid) {
  6574. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  6575. } else {
  6576. if (!isSumbit) {
  6577. PurcNotice.sendByBatch({token: token}, $scope.saleSend, function (data) {
  6578. if(data.id) {
  6579. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  6580. $modalInstance.close('success');
  6581. $state.go('sale.send_detail', {id: data.id});
  6582. } else if(data.info) {
  6583. toaster.pop('error', '提示', '发货失败,请刷新页面重试');
  6584. }
  6585. }, function (response) {
  6586. toaster.pop('error', '错误', '发货失败');
  6587. });
  6588. isSumbit = true;
  6589. return true;
  6590. } else {
  6591. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6592. return false;
  6593. }
  6594. }
  6595. };
  6596. $scope.cancel = function () {
  6597. $modalInstance.dismiss();
  6598. };
  6599. }]);
  6600. /**
  6601. * 发货单
  6602. */
  6603. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'ReportService', function ($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService) {
  6604. BaseService.scrollBackToTop();
  6605. $scope.active = 'all';
  6606. $scope.currency = Symbol.currency;
  6607. $scope.dateZoneText = '不限';
  6608. $scope.condition = {dateZone: 1};
  6609. /* 时间筛选初始化*/
  6610. var fromDate = new Date();
  6611. var toDate = new Date();
  6612. fromDate.setMonth(fromDate.getMonth() - 1);
  6613. fromDate.setHours(0, 0, 0, 0);
  6614. toDate.setHours(23, 59, 59, 999);
  6615. $scope.condition.dateFrom = fromDate;
  6616. $scope.condition.dateTo = toDate;
  6617. $scope.changeDateZone = function (zone) {
  6618. $scope.condition.dateZone = zone;
  6619. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6620. $scope.condition.$dateZoneOpen = false;
  6621. getDateCondition(zone, $scope.condition);
  6622. $scope.tableParams.page(1);
  6623. $scope.tableParams.reload();
  6624. };
  6625. $scope.setActive = function (state) {
  6626. if ($scope.active != state) {
  6627. $scope.active = state;
  6628. if ($scope.tableParams.page() == 1)
  6629. $scope.tableParams.reload();
  6630. else
  6631. $scope.tableParams.page(1);
  6632. }
  6633. };
  6634. var getService = function () {
  6635. return SaleSend;
  6636. };
  6637. $scope.tableParams = new ngTableParams({
  6638. page: 1,
  6639. count: 20,
  6640. sorting: {
  6641. date: 'desc'
  6642. }
  6643. }, {
  6644. total: 0,
  6645. counts: [5, 10, 25, 50],
  6646. getData: function ($defer, params) {
  6647. $scope.loading = true;
  6648. var pageParams = params.url();
  6649. pageParams.keyword = $scope.keyword;
  6650. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6651. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6652. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6653. $scope.loading = false;
  6654. if (page) {
  6655. params.total(page.totalElement);
  6656. $defer.resolve(page.content);
  6657. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6658. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6659. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6660. }
  6661. }, function (response) {
  6662. $scope.loading = false;
  6663. toaster.pop('error', '数据加载失败', response.data);
  6664. });
  6665. }
  6666. });
  6667. //打印 发货单
  6668. $scope.print = function (send) {
  6669. var newPage = window.open("about:blank");
  6670. SaleSend.printPermission({}, function () {
  6671. SaleSend.printCount({id: send.id}, {}); //增加打印此次
  6672. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id, newPage);
  6673. $scope.tableParams.reload();
  6674. }, function (response) {
  6675. newPage.close();
  6676. toaster.pop('error', '打印失败', response.data);
  6677. });
  6678. };
  6679. $scope.openDatePicker = function ($event, item, openParam) {
  6680. $event.preventDefault();
  6681. $event.stopPropagation();
  6682. item[openParam] = !item[openParam];
  6683. };
  6684. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6685. $event.preventDefault();
  6686. $event.stopPropagation();
  6687. item[openParam] = !item[openParam];
  6688. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6689. $scope.tableParams.reload();
  6690. }
  6691. };
  6692. // 搜索框回车
  6693. $scope.onSearch = function () {
  6694. $scope.tableParams.page(1);
  6695. $scope.tableParams.reload();
  6696. };
  6697. // 选择查找日期
  6698. $scope.onDateCondition = function () {
  6699. $scope.tableParams.page(1);
  6700. $scope.tableParams.reload();
  6701. };
  6702. $scope.exportXls = function () {
  6703. SaleSend.exportXls({}, {}, function (data) {
  6704. if (data.success){
  6705. window.location.href = 'sale/notice/sends/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  6706. }
  6707. }, function (response) {
  6708. toaster.pop('error', '数据加载失败', response.data);
  6709. });
  6710. }
  6711. }]);
  6712. /**
  6713. * 发货单(包括发货条码维护)
  6714. */
  6715. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService', 'ngTableParams', 'Lodop', '$modal', 'CurrentRole', function ($scope, $stateParams, SaleSend, toaster, ReportService, ngTableParams, Lodop, $modal, CurrentRole) {
  6716. // 获取当前用户是否为普通用户
  6717. CurrentRole.isUser({}, {}, function (data) {
  6718. $scope.isUser = data.isUser;
  6719. });
  6720. var loading = true;
  6721. $scope.checkBarCode = [];
  6722. $scope.checkBoxCode = [];
  6723. var vm = $scope.vm = {};
  6724. $scope.getCheckedItems = {};
  6725. vm.editBar = false;
  6726. vm.showBarCode = [];
  6727. $scope.barCode = function () {
  6728. vm.editBar = !vm.editBar;
  6729. }
  6730. $scope.checkboxes = {
  6731. checked: false
  6732. };
  6733. $scope.checkbars = {
  6734. checked: false
  6735. };
  6736. // 点击勾选barCode全部的复选框
  6737. $scope.checkBarAll = function () {
  6738. angular.forEach($scope.checkBarCode, function (item, key) {
  6739. $scope.checkBarCode[key] = $scope.checkbars.checked;
  6740. });
  6741. };
  6742. //点击barCode单选
  6743. $scope.checkBarOne = function () {
  6744. var result = true;
  6745. angular.forEach($scope.checkBarCode, function (item, key) {
  6746. if (item != true) {
  6747. result = false;
  6748. return;
  6749. }
  6750. });
  6751. $scope.checkbars.checked = result;
  6752. }
  6753. // 点击boxCode全部的复选框
  6754. $scope.checkBoxAll = function () {
  6755. angular.forEach($scope.checkBoxCode, function (item, key) {
  6756. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  6757. });
  6758. };
  6759. //点击boxCode单选
  6760. $scope.checkBoxOne = function () {
  6761. var result = true;
  6762. angular.forEach($scope.checkBoxCode, function (item) {
  6763. if (item != true) {
  6764. result = false;
  6765. return;
  6766. }
  6767. });
  6768. $scope.checkboxes.checked = result;
  6769. }
  6770. /**
  6771. * 生成条码和箱号
  6772. */
  6773. $scope.generateBarCode = function (item) {
  6774. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  6775. $scope.getCheckedItems = [];
  6776. var warningdata = '';
  6777. angular.forEach($scope.checkBarCode, function (item, key) {
  6778. $scope.getCheckedItem = {};
  6779. if (item == true) {
  6780. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  6781. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  6782. $scope.getCheckedItems.push($scope.getCheckedItem);
  6783. //判断是否生成过条码
  6784. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  6785. warningdata += $scope.order.sendItems[key].number + ","
  6786. }
  6787. }
  6788. });
  6789. if ($scope.getCheckedItems.length == 0) {
  6790. toaster.pop('warning', '提示', '请勾选需要生成条码的明细行!');
  6791. return;
  6792. }
  6793. if (warningdata != '') {
  6794. if (!confirm('明细行序号:' + warningdata + "已经生成了条码,继续生成将清空原有条码?")) {
  6795. return;
  6796. }
  6797. }
  6798. SaleSend.generateBarcodes({id: $scope.order.id}, angular.fromJson($scope.getCheckedItems), function (data) {
  6799. toaster.pop('success', '提示', '生成成功!');
  6800. loadData();
  6801. }, function (response) {
  6802. $scope.loading = false;
  6803. toaster.pop('error', '生成失败', response.data);
  6804. });
  6805. }
  6806. /**
  6807. * 打印条码和箱号
  6808. */
  6809. $scope.printCode = function (type) {
  6810. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  6811. //勾选需要打印的行
  6812. $scope.getCheckedItems = [];
  6813. var warningdata = ''
  6814. angular.forEach($scope.checkBarCode, function (item, key) {
  6815. $scope.getCheckedItem = {};
  6816. if (item == true) {
  6817. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  6818. $scope.getCheckedItems.push($scope.getCheckedItem);
  6819. //判断是否生成过条码
  6820. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  6821. warningdata += $scope.order.sendItems[key].number + ","
  6822. }
  6823. }
  6824. });
  6825. if ($scope.getCheckedItems.length == 0) {
  6826. toaster.pop('warning', '提示', '请勾选需要打印的明细行!');
  6827. return;
  6828. }
  6829. if (warningdata == '') {
  6830. toaster.pop('warning', '提示', '明细行序号:' + warningdata + '未生成条码无法打印');
  6831. return;
  6832. }
  6833. //选择打印模板
  6834. var modalInstance = $modal.open({
  6835. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  6836. controller: 'BarPrintModalCtrl',
  6837. resolve: {
  6838. typeItem: function () {
  6839. return {'type': type, 'id': $scope.order.id};
  6840. }
  6841. }
  6842. });
  6843. modalInstance.result.then(function (s) {
  6844. if (s) {
  6845. //获取打印数据
  6846. SaleSend.getPrintBarcodes({lpsId: s.tp_id}, angular.fromJson($scope.getCheckedItems), function (data) {
  6847. if (s.type == 'print') {//判断选择是打印还是打印预览
  6848. lodopPrint(data.message, LODOP, type);
  6849. } else if (s.type == 'printPreview') {
  6850. lodopPrintPreview(data.message, LODOP, type);
  6851. }
  6852. }, function (response) {
  6853. toaster.pop('error', '获取打印数据失败', response.data);
  6854. });
  6855. }
  6856. });
  6857. };
  6858. //打印单个条码
  6859. $scope.printSingleCode = function (id) {
  6860. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  6861. //选择打印模板
  6862. var modalInstance = $modal.open({
  6863. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  6864. controller: 'BarPrintModalCtrl',
  6865. resolve: {
  6866. typeItem: function () {
  6867. return {'type': 'Bar', 'id': $scope.order.id};
  6868. }
  6869. }
  6870. });
  6871. modalInstance.result.then(function (s) {
  6872. if (s) {
  6873. //获取打印数据
  6874. SaleSend.getSPrintBarcode({lpsId: s.tp_id, bsnId: id}, function (data) {
  6875. if (s.type == 'print') {//判断选择是打印还是打印预览
  6876. lodopSPrint(data.message, LODOP);
  6877. } else if (s.type == 'printPreview') {
  6878. lodopSPrintPreview(data.message, LODOP);
  6879. }
  6880. }, function (response) {
  6881. toaster.pop('error', '获取打印数据失败', response.data);
  6882. });
  6883. }
  6884. });
  6885. }
  6886. var lodopSPrint = function (printStore, LODOP) {//单个条码打印
  6887. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  6888. if (selectOrNot != -1) {
  6889. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  6890. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  6891. var strs = pagesize.split("*"); //字符分割
  6892. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  6893. angular.forEach(printStore, function (data, index) {
  6894. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  6895. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  6896. if (data['LP_VALUETYPE'] == 'barcode') {
  6897. 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']);
  6898. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  6899. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  6900. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  6901. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  6902. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  6903. } else if (data['LP_VALUETYPE'] == 'text') {
  6904. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  6905. }
  6906. });
  6907. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  6908. LODOP.PRINT();
  6909. }
  6910. };
  6911. var lodopSPrintPreview = function (printStore, LODOP) {//单个条码打印预览
  6912. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  6913. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  6914. var strs = pagesize.split("*"); //字符分割
  6915. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  6916. angular.forEach(printStore, function (data, index) {
  6917. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  6918. if (data['LP_VALUETYPE'] == 'barcode') {
  6919. 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']);
  6920. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  6921. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  6922. } else if (data['LP_VALUETYPE'] == 'text') {
  6923. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  6924. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  6925. }
  6926. });
  6927. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  6928. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  6929. LODOP.PREVIEW();//打印预览
  6930. };
  6931. var lodopPrint = function (printStore, LODOP, type) {//勾选发货单明细进行打印
  6932. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  6933. if (selectOrNot != -1) {
  6934. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  6935. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  6936. var strs = new Array(); //定义一数组
  6937. strs = pagesize.split("*"); //字符分割
  6938. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  6939. var ids = new Array();
  6940. angular.forEach(printStore, function (value, key) {
  6941. //LODOP.NewPage();
  6942. angular.forEach(value['data'], function (record, key) {
  6943. angular.forEach(record['store'], function (data, index) {
  6944. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  6945. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  6946. if (data['LP_VALUETYPE'] == 'barcode') {
  6947. 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']);
  6948. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  6949. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  6950. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  6951. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  6952. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  6953. } else if (data['LP_VALUETYPE'] == 'text') {
  6954. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  6955. }
  6956. });
  6957. });
  6958. var o = new Object();
  6959. o['id'] = record['si_id']
  6960. ids.push(o);
  6961. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  6962. LODOP.PRINT();
  6963. });
  6964. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  6965. if (type == 'Bar') {
  6966. //更新打印状态
  6967. SaleSend.updatePrintStatus({}, ids, function (data) {
  6968. }, function (res) {
  6969. });
  6970. }
  6971. }
  6972. };
  6973. var lodopPrintPreview = function (printData, LODOP, type) {//打印预览
  6974. var ids = new Array();
  6975. angular.forEach(printData, function (record, index) {
  6976. angular.forEach(record['data'], function (value, index) {
  6977. LODOP.NewPage();
  6978. angular.forEach(value['store'], function (data, index) {
  6979. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  6980. if (data['LP_VALUETYPE'] == 'barcode') {
  6981. 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']);
  6982. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  6983. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  6984. } else if (data['LP_VALUETYPE'] == 'text') {
  6985. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  6986. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  6987. }
  6988. });
  6989. });
  6990. var o = new Object();
  6991. o['id'] = record['si_id']
  6992. ids.push(o);
  6993. });
  6994. var pagesize = printData[0]['pagesize'];//获取标签的大小
  6995. var strs = new Array(); //定义一数组
  6996. strs = pagesize.split("*"); //字符分割
  6997. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  6998. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  6999. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7000. var times = LODOP.PREVIEW();//打印预览
  7001. if (times > 0) {//点击了打印预览内的打印按钮
  7002. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7003. if (type == 'Bar') {
  7004. //更新打印状态
  7005. SaleSend.updatePrintStatus({}, ids, function (data) {
  7006. loadData();
  7007. }, function (res) {
  7008. });
  7009. }
  7010. }
  7011. };
  7012. /**
  7013. * 查看条码按钮
  7014. */
  7015. $scope.showBarCode = function (number) {
  7016. $scope.keys = number;
  7017. for (var i = 0; i < vm.showBarCode.length; i++) {
  7018. if (i != number) {
  7019. vm.showBarCode[i] = false;
  7020. }
  7021. }
  7022. vm.showBarCode[number] = !vm.showBarCode[number];
  7023. $scope.barcodes = [];
  7024. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  7025. var getPage = function (page, size) {
  7026. if ($scope.barcodes) {
  7027. var result = {};
  7028. result.totalCount = $scope.barcodes.length;
  7029. result.content = $scope.barcodes.slice((page - 1) * size, page * size);
  7030. if ($scope.barcodes.length % size == 0) {
  7031. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  7032. } else {
  7033. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  7034. }
  7035. result.first = page == 1;
  7036. result.last = page == result.totalPage;
  7037. result.page = page;
  7038. result.next = page - 0 + 1;
  7039. result.pre = page - 1;
  7040. return result;
  7041. }
  7042. }
  7043. $scope.barData = getPage(1, 5);
  7044. $scope.first = function () {
  7045. $scope.barData = getPage($scope.barData.pre, 5);
  7046. }
  7047. $scope.last = function () {
  7048. $scope.barData = getPage($scope.barData.next, 5);
  7049. }
  7050. };
  7051. /**
  7052. * 更新外箱号
  7053. */
  7054. $scope.updateOutBox = function (item, number) {
  7055. if ($scope.oldoutBoxQty[number] == item.outBoxQty) {
  7056. } else {
  7057. if (item.outBoxQty > 0) {
  7058. if (!(item.outBoxQty % item.packageQty)) {
  7059. SaleSend.update({id: item.id}, item, function () {
  7060. toaster.pop('success', '提示', '保存成功!');
  7061. loadData();
  7062. }, function (response) {
  7063. $scope.loading = false;
  7064. toaster.pop('error', '回复失败', response.data);
  7065. })
  7066. } else {
  7067. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  7068. }
  7069. } else {
  7070. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7071. }
  7072. }
  7073. loadData();
  7074. };
  7075. /**
  7076. * 更新最小包数
  7077. */
  7078. $scope.updatePackage = function (item, number) {
  7079. if (item.packageQty == $scope.oldpackageQty[number]) {
  7080. } else {
  7081. if (item.orderItem.product.minPack != 0) {
  7082. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7083. if (!(item.packageQty % item.orderItem.product.minPack)) {
  7084. SaleSend.update({id: item.id}, item, function () {
  7085. toaster.pop('success', '提示', '保存成功!');
  7086. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7087. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7088. }
  7089. loadData();
  7090. }, function (response) {
  7091. $scope.loading = false;
  7092. toaster.pop('error', '回复失败', response.data);
  7093. })
  7094. } else {
  7095. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  7096. }
  7097. } else {
  7098. toaster.pop('warning', '提示', '请填写有效的数量!');
  7099. }
  7100. } else {
  7101. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7102. SaleSend.update({id: item.id}, item, function () {
  7103. toaster.pop('success', '提示', '保存成功!');
  7104. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7105. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7106. }
  7107. loadData();
  7108. }, function (response) {
  7109. $scope.loading = false;
  7110. toaster.pop('error', '回复失败', response.data);
  7111. })
  7112. } else {
  7113. toaster.pop('warning', '提示', '请填写有效的数量!');
  7114. }
  7115. }
  7116. }
  7117. loadData();
  7118. };
  7119. var loadData = function () {
  7120. SaleSend.getItem({id: $stateParams.id}, function (data) {
  7121. $scope.order = data;
  7122. var orderCount = $scope.order.sendItems.length;
  7123. $scope.oldpackageQty = [];
  7124. $scope.oldoutBoxQty = [];
  7125. var sum = 0;
  7126. vm.oldpackageQty = [];
  7127. angular.forEach(data.sendItems, function (value, key) {
  7128. //给showBarCode数组赋初值
  7129. if (vm.showBarCode.length < orderCount) {
  7130. vm.showBarCode.push(false);
  7131. }
  7132. if ($scope.checkBarCode.length < orderCount) {
  7133. $scope.checkBarCode.push(false);
  7134. }
  7135. if ($scope.checkBoxCode.length < orderCount) {
  7136. $scope.checkBoxCode.push(false);
  7137. }
  7138. //给个初值
  7139. if (!value.packageQty) {
  7140. value.packageQty = value.orderItem.product.minPack;
  7141. }
  7142. $scope.oldpackageQty.push(value.packageQty);
  7143. if (value.outBoxQty) {
  7144. $scope.oldoutBoxQty.push(value.outBoxQty);
  7145. }
  7146. sum += value.price * value.qty;
  7147. });
  7148. data.total = sum;
  7149. $scope.loading = false;
  7150. }, function (response) {
  7151. loading = false;
  7152. toaster.pop('error', '获取数据失败', response.data);
  7153. });
  7154. };
  7155. loadData();
  7156. }]);
  7157. app.controller('BarPrintModalCtrl', ['$scope', 'typeItem', 'SaleSend', 'toaster', '$modalInstance', function ($scope, typeItem, SaleSend, toaster, $modalInstance) {
  7158. $scope.typeItem = typeItem;
  7159. $scope.template = [];
  7160. $scope.choose = {};
  7161. //获取打印模板
  7162. SaleSend.getPrintTemplate({id: $scope.typeItem.id, type: $scope.typeItem.type}, function (data) {
  7163. if (data.message) {
  7164. $scope.template = data.message;
  7165. $scope.choose.tp_id = $scope.template[0].id;
  7166. }
  7167. }, function (res) {
  7168. toaster.pop('error', '获取模板错误', res.data);
  7169. });
  7170. $scope.print = function () {
  7171. $scope.choose.type = 'print';
  7172. $modalInstance.close($scope.choose);
  7173. };
  7174. $scope.printPreview = function () {
  7175. $scope.choose.type = 'printPreview';
  7176. $modalInstance.close($scope.choose);
  7177. }
  7178. $scope.cancel = function () {
  7179. $modalInstance.close();
  7180. }
  7181. }]);
  7182. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', 'CurrentRole', function ($scope, $stateParams, PurcSample, toaster, $modal, BaseService, CurrentRole) {
  7183. BaseService.scrollBackToTop();
  7184. // 获取当前用户是否为普通用户
  7185. CurrentRole.isUser({}, {}, function (data) {
  7186. $scope.isUser = data.isUser;
  7187. });
  7188. var loading = true;
  7189. var loadData = function () {
  7190. PurcSample.getItem({id: $stateParams.id}, function (data) {
  7191. $scope.sample = data;
  7192. if (!$scope.sample.sends) {
  7193. $scope.sample.getSendInfo = '加载中...';
  7194. PurcSample.getSend({id: $stateParams.id}, function (sendData) {
  7195. if (sendData) {
  7196. $scope.sample.getSendInfo = null;
  7197. $scope.sample.sends = sendData;
  7198. } else {
  7199. $scope.sample.getSendInfo = '无送样信息';
  7200. $scope.sample.sends = '无送样信息';
  7201. }
  7202. }, function (response) {
  7203. $scope.sample.getSendInfo = '加载失败!';
  7204. toaster.pop('error', '', response.data);
  7205. });
  7206. }
  7207. $scope.loading = false;
  7208. }, function (response) {
  7209. loading = false;
  7210. toaster.pop('error', '获取数据失败', response.data);
  7211. });
  7212. };
  7213. loadData();
  7214. $scope.openSend = function (index, sample) {
  7215. var modalInstance = $modal.open({
  7216. animation: true,
  7217. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7218. controller: 'SampleSendCtrl',
  7219. resolve: {
  7220. sampleItem: function () {
  7221. return sample;
  7222. }
  7223. }
  7224. });
  7225. modalInstance.result.then(function () {
  7226. toaster.pop('info', '提示', '送样成功');
  7227. $scope.tableParams.reload();
  7228. }, function () {
  7229. });
  7230. };
  7231. }]);
  7232. /**
  7233. * 客户打样申请
  7234. */
  7235. 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) {
  7236. BaseService.scrollBackToTop();
  7237. // 获取当前用户是否为普通用户
  7238. CurrentRole.isUser({}, {}, function (data) {
  7239. $scope.isUser = data.isUser;
  7240. });
  7241. if ($rootScope.active) {
  7242. $scope.active = $rootScope.active;
  7243. $rootScope.active = null;
  7244. } else {
  7245. $scope.active = 'todo';
  7246. }
  7247. $scope.agreedText = '全部';
  7248. $scope.dateZoneText = '一个月内';
  7249. $scope.condition = {dateZone: 1};
  7250. /*初始化筛选时间*/
  7251. var fromDate = new Date();
  7252. var toDate = new Date();
  7253. fromDate.setMonth(fromDate.getMonth() - 1);
  7254. fromDate.setHours(0, 0, 0, 0);
  7255. toDate.setHours(23, 59, 59, 999);
  7256. $scope.condition.dateFrom = fromDate;
  7257. $scope.condition.dateTo = toDate;
  7258. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7259. $scope.changeAgreed = function (agreed) {
  7260. $scope.condition.agreed = agreed;
  7261. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7262. $scope.condition.$agreedOpen = false;
  7263. };
  7264. $scope.changeDateZone = function (zone) {
  7265. $scope.condition.dateZone = zone;
  7266. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7267. $scope.condition.$dateZoneOpen = false;
  7268. getDateCondition(zone, $scope.condition);
  7269. $scope.tableParams.page(1);
  7270. $scope.tableParams.reload();
  7271. };
  7272. $scope.setActive = function (state) {
  7273. if ($scope.active != state) {
  7274. $scope.active = state;
  7275. if ($scope.tableParams.page() == 1)
  7276. $scope.tableParams.reload();
  7277. else
  7278. $scope.tableParams.page(1);
  7279. }
  7280. };
  7281. $scope.searchMethod = false;
  7282. var getService = function () {
  7283. return $scope.searchMethod ? PurcSample : PurcSampleInfo;
  7284. };
  7285. $scope.tableParams = new ngTableParams({
  7286. page: 1,
  7287. count: 20,
  7288. sorting: {
  7289. proofingDate: 'desc'
  7290. }
  7291. }, {
  7292. total: 0,
  7293. counts: [5, 10, 25, 50],
  7294. getData: function ($defer, params) {
  7295. $scope.loading = true;
  7296. var pageParams = params.url();
  7297. pageParams.searchFilter = {
  7298. keyword: $scope.keyword,
  7299. fromDate: getDateTime($scope.condition.dateFrom),
  7300. endDate: getDateTime($scope.condition.dateTo)
  7301. };
  7302. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7303. $scope.loading = false;
  7304. if (page) {
  7305. params.total(page.totalElement);
  7306. $defer.resolve(page.content);
  7307. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7308. }
  7309. getUnreadCount();
  7310. }, function (response) {
  7311. $scope.loading = false;
  7312. toaster.pop('error', '数据加载失败', response.data);
  7313. });
  7314. }
  7315. });
  7316. //获得各分类未阅读数量
  7317. var getUnreadCount = function () {
  7318. PurcSample.getUnreadCount(null, function(data){
  7319. $scope.unread = data;
  7320. });
  7321. };
  7322. getUnreadCount();
  7323. //设置单个单据已读
  7324. $scope.setOrdersRead = function (id) {
  7325. if (!$scope.isUnread(id)) {
  7326. return;
  7327. }
  7328. var sourceId = [];
  7329. sourceId.push(id);
  7330. PurcSample.setRead({}, sourceId, function (message) {
  7331. getUnreadIds();
  7332. getUnreadCount();
  7333. });
  7334. };
  7335. //获取未读单据id
  7336. var getUnreadIds = function (){
  7337. PurcSample.getUnreadIds({}, "", function (message) {
  7338. $scope.unreadCode = message.content;
  7339. });
  7340. };
  7341. getUnreadIds();
  7342. //判断单据是否未读
  7343. $scope.isUnread = function (id){
  7344. for (var i in $scope.unreadCode) {
  7345. if (id == $scope.unreadCode[i]) {
  7346. return true;
  7347. }
  7348. }
  7349. };
  7350. $scope.openDatePicker = function ($event, item, openParam) {
  7351. $event.preventDefault();
  7352. $event.stopPropagation();
  7353. item[openParam] = !item[openParam];
  7354. };
  7355. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7356. $event.preventDefault();
  7357. $event.stopPropagation();
  7358. item[openParam] = !item[openParam];
  7359. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7360. $scope.tableParams.reload();
  7361. }
  7362. };
  7363. $scope.openSend = function (index, sample) {
  7364. var modalInstance = $modal.open({
  7365. animation: true,
  7366. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7367. controller: 'SampleSendCtrl',
  7368. resolve: {
  7369. sampleItem: function () {
  7370. return sample;
  7371. }
  7372. }
  7373. });
  7374. modalInstance.result.then(function () {
  7375. toaster.pop('info', '提示', '送样成功');
  7376. $scope.tableParams.reload();
  7377. }, function () {
  7378. });
  7379. };
  7380. //打印 样品采购单
  7381. $scope.print = function (sample) {
  7382. var newPage = window.open("about:blank");
  7383. PurcSample.printPermission({}, function () {
  7384. PurcSample.printCount({id: sample.id}, {});//增加打印此次
  7385. ReportService.print(sample.proofing.enUU, 'PURCPROOFING', "where purc$proofingitems.ppi_id =" + sample.id, newPage);
  7386. }, function (response) {
  7387. newPage.close();
  7388. toaster.pop('error', '打印失败', response.data);
  7389. });
  7390. };
  7391. $scope.getSend = function (proofing) {
  7392. if (!proofing.sends) {
  7393. proofing.getSendInfo = '加载中...';
  7394. PurcSample.getSend({id: proofing.id}, function (data) {
  7395. if (data) {
  7396. proofing.getSendInfo = null;
  7397. proofing.sends = data;
  7398. } else {
  7399. proofing.getSendInfo = '无送样信息';
  7400. proofing.sends = '无送样信息';
  7401. }
  7402. }, function (response) {
  7403. proofing.getSendInfo = '加载失败!';
  7404. });
  7405. }
  7406. };
  7407. // 搜索框回车
  7408. $scope.onSearch = function (keyword) {
  7409. // 每次搜索重置获取数据方法
  7410. $scope.searchMethod = false;
  7411. if(keyword != null && keyword != '') {
  7412. $scope.searchMethod = true;
  7413. }
  7414. $scope.tableParams.page(1);
  7415. $scope.tableParams.reload();
  7416. };
  7417. // 导出
  7418. $scope.exportXls = function () {
  7419. PurcSample.exportXls({}, {}, function (data) {
  7420. if (data.success){
  7421. window.location.href = 'sale/sample/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  7422. }
  7423. }, function (response) {
  7424. toaster.pop('error', '数据加载失败', response.data);
  7425. });
  7426. }
  7427. }]);
  7428. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function ($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster) {
  7429. if (!sampleItem.sends) {
  7430. PurcSample.getSend({id: sampleItem.id}, function (data) {
  7431. if (data) {
  7432. sampleItem.sends = data; // 获取送样信息
  7433. angular.forEach(data, function (send) {
  7434. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  7435. });
  7436. }
  7437. }, function (response) {
  7438. });
  7439. }
  7440. $scope.sampleItem = sampleItem;
  7441. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  7442. //确认送样
  7443. $scope.ok = function (form) {
  7444. $scope.loading = true;
  7445. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  7446. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  7447. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  7448. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  7449. $upload.upload({
  7450. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  7451. method: 'POST',
  7452. file: file,
  7453. data: {
  7454. json: $scope.sampleItem.sampleSend
  7455. }
  7456. }).success(function (data) {
  7457. $scope.loading = false;
  7458. $modalInstance.close('success');
  7459. }).error(function (data) {
  7460. $scope.loading = false;
  7461. toaster.pop('danger', '错误', data);
  7462. });
  7463. };
  7464. $scope.cancel = function () {
  7465. $modalInstance.dismiss(sampleItem);
  7466. };
  7467. //设置单个单据已读
  7468. $scope.setOrdersRead = function (id) {
  7469. var sourceId = [];
  7470. sourceId.push(id);
  7471. PurcSample.setRead({}, sourceId, function (message) {
  7472. // $scope.getUnreadIds();
  7473. });
  7474. };
  7475. }]);
  7476. /**
  7477. * 客户认定单
  7478. */
  7479. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol) {
  7480. BaseService.scrollBackToTop();
  7481. $scope.active = 'all';
  7482. $scope.agreedText = '全部';
  7483. $scope.dateZoneText = '一个月内';
  7484. $scope.condition = {dateZone: 1};
  7485. /* 时间筛选初始化*/
  7486. var fromDate = new Date();
  7487. var toDate = new Date();
  7488. fromDate.setMonth(fromDate.getMonth() - 1);
  7489. fromDate.setHours(0, 0, 0, 0);
  7490. toDate.setHours(23, 59, 59, 999);
  7491. $scope.condition.dateFrom = fromDate;
  7492. $scope.condition.dateTo = toDate;
  7493. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7494. $scope.changeDateZone = function (zone) {
  7495. $scope.condition.dateZone = zone;
  7496. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7497. $scope.condition.$dateZoneOpen = false;
  7498. getDateCondition(zone, $scope.condition);
  7499. $scope.tableParams.page(1);
  7500. $scope.tableParams.reload();
  7501. };
  7502. $scope.setActive = function (state) {
  7503. if ($scope.active != state) {
  7504. $scope.active = state;
  7505. if ($scope.tableParams.page() == 1)
  7506. $scope.tableParams.reload();
  7507. else
  7508. $scope.tableParams.page(1);
  7509. }
  7510. };
  7511. var getService = function () {
  7512. return PurcApproval;
  7513. };
  7514. $scope.tableParams = new ngTableParams({
  7515. page: 1,
  7516. count: 20,
  7517. sorting: {
  7518. inDate: 'desc'
  7519. }
  7520. }, {
  7521. total: 0,
  7522. counts: [5, 10, 25, 50],
  7523. getData: function ($defer, params) {
  7524. $scope.loading = true;
  7525. var pageParams = params.url();
  7526. pageParams.keyword = $scope.keyword;
  7527. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7528. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7529. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7530. $scope.loading = false;
  7531. if (page) {
  7532. params.total(page.totalElement);
  7533. $defer.resolve(page.content);
  7534. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7535. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7536. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7537. }
  7538. }, function (response) {
  7539. $scope.loading = false;
  7540. toaster.pop('error', '数据加载失败', response.data);
  7541. });
  7542. }
  7543. });
  7544. $scope.openDatePicker = function ($event, item, openParam) {
  7545. $event.preventDefault();
  7546. $event.stopPropagation();
  7547. item[openParam] = !item[openParam];
  7548. };
  7549. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7550. $event.preventDefault();
  7551. $event.stopPropagation();
  7552. item[openParam] = !item[openParam];
  7553. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7554. $scope.tableParams.reload();
  7555. }
  7556. };
  7557. $scope.parseDate = function (dateStr) {
  7558. if (dateStr)
  7559. return Date.parse(dateStr, 'yyyy-MM-dd');
  7560. return new Date();
  7561. };
  7562. // 搜索框回车
  7563. $scope.onSearch = function () {
  7564. $scope.tableParams.page(1);
  7565. $scope.tableParams.reload();
  7566. };
  7567. // 选择查找日期
  7568. $scope.onDateCondition = function () {
  7569. $scope.tableParams.page(1);
  7570. $scope.tableParams.reload();
  7571. };
  7572. // 导出
  7573. $scope.exportXls = function () {
  7574. PurcApproval.exportXls({}, {}, function (data) {
  7575. if (data.success){
  7576. window.location.href = 'sale/sample/approval/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7577. }
  7578. }, function (response) {
  7579. toaster.pop('error', '数据加载失败', response.data);
  7580. });
  7581. }
  7582. }]);
  7583. /**
  7584. * 客户采购预测
  7585. */
  7586. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol) {
  7587. BaseService.scrollBackToTop();
  7588. $scope.active = 'all';
  7589. $scope.agreedText = '全部';
  7590. $scope.dateZoneText = '一个月内';
  7591. $scope.condition = {dateZone: 1};
  7592. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7593. $scope.changeAgreed = function (agreed) {
  7594. $scope.condition.agreed = agreed;
  7595. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7596. $scope.condition.$agreedOpen = false;
  7597. };
  7598. $scope.changeDateZone = function (zone) {
  7599. $scope.condition.dateZone = zone;
  7600. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7601. $scope.condition.$dateZoneOpen = false;
  7602. };
  7603. $scope.setActive = function (state) {
  7604. if ($scope.active != state) {
  7605. $scope.active = state;
  7606. if ($scope.tableParams.page() == 1)
  7607. $scope.tableParams.reload();
  7608. else
  7609. $scope.tableParams.page(1);
  7610. }
  7611. };
  7612. var getService = function () {
  7613. return PurcForecast;
  7614. };
  7615. $scope.tableParams = new ngTableParams({
  7616. page: 1,
  7617. count: 20,
  7618. sorting: {
  7619. orderDate: 'desc'
  7620. }
  7621. }, {
  7622. total: 0,
  7623. counts: [5, 10, 25, 50],
  7624. getData: function ($defer, params) {
  7625. $scope.loading = true;
  7626. var pageParams = params.url();
  7627. pageParams.keyword = $scope.keyword;
  7628. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7629. $scope.loading = false;
  7630. if (page) {
  7631. params.total(page.totalElement);
  7632. $defer.resolve(page.content);
  7633. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7634. }
  7635. }, function (response) {
  7636. $scope.loading = false;
  7637. toaster.pop('error', '数据加载失败', response.data);
  7638. });
  7639. }
  7640. });
  7641. $scope.openDatePicker = function ($event, item, openParam) {
  7642. $event.preventDefault();
  7643. $event.stopPropagation();
  7644. item[openParam] = !item[openParam];
  7645. };
  7646. // 搜索框回车
  7647. $scope.onSearch = function () {
  7648. $scope.tableParams.page(1);
  7649. $scope.tableParams.reload();
  7650. };
  7651. }]);
  7652. /**
  7653. * 客户采购验收
  7654. */
  7655. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  7656. BaseService.scrollBackToTop();
  7657. // 获取当前用户是否为普通用户
  7658. CurrentRole.isUser({}, {}, function (data) {
  7659. $scope.isUser = data.isUser;
  7660. });
  7661. $scope.active = 'all';
  7662. $scope.dateZoneText = '不限';
  7663. $scope.deliveryZoneText = '不限';
  7664. $scope.condition = {dateZone: 1, deliveryZone: -1};
  7665. /* 时间筛选初始化*/
  7666. var fromDate = new Date();
  7667. var toDate = new Date();
  7668. fromDate.setMonth(fromDate.getMonth() - 1);
  7669. fromDate.setHours(0, 0, 0, 0);
  7670. toDate.setHours(23, 59, 59, 999);
  7671. $scope.condition.dateFrom = fromDate;
  7672. $scope.condition.dateTo = toDate;
  7673. $scope.changeDateZone = function (zone) {
  7674. $scope.condition.dateZone = zone;
  7675. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7676. $scope.condition.$dateZoneOpen = false;
  7677. getDateCondition(zone, $scope.condition);
  7678. $scope.tableParams.page(1);
  7679. $scope.tableParams.reload();
  7680. };
  7681. $scope.changeDeliveryZone = function (zone) {
  7682. $scope.condition.deliveryZoneText = zone;
  7683. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  7684. $scope.condition.$delievryZoneOpen = false;
  7685. getDelveryCondition(zone, $scope.condition);
  7686. $scope.tableParams.reload();
  7687. };
  7688. $scope.setActive = function (state) {
  7689. if ($scope.active != state) {
  7690. $scope.active = state;
  7691. if ($scope.tableParams.page() == 1)
  7692. $scope.tableParams.reload();
  7693. else
  7694. $scope.tableParams.page(1);
  7695. }
  7696. };
  7697. var getService = function () {
  7698. return PurcAccept;
  7699. };
  7700. $scope.tableParams = new ngTableParams({
  7701. page: 1,
  7702. count: 20,
  7703. sorting: {
  7704. date: 'desc'
  7705. }
  7706. }, {
  7707. total: 0,
  7708. counts: [5, 10, 25, 50],
  7709. getData: function ($defer, params) {
  7710. $scope.loading = true;
  7711. var pageParams = params.url();
  7712. pageParams.searchFilter = { // 筛选条件
  7713. keyword: $scope.keyword,
  7714. fromDate: getDateTime($scope.condition.dateFrom),
  7715. endDate: getDateTime($scope.condition.dateTo)
  7716. };
  7717. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7718. $scope.loading = false;
  7719. if (page) {
  7720. params.total(page.totalElement);
  7721. $defer.resolve(page.content);
  7722. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7723. }
  7724. }, function (response) {
  7725. $scope.loading = false;
  7726. toaster.pop('error', '数据加载失败', response.data);
  7727. });
  7728. }
  7729. });
  7730. $scope.openDatePicker = function ($event, item, openParam) {
  7731. $event.preventDefault();
  7732. $event.stopPropagation();
  7733. item[openParam] = !item[openParam];
  7734. };
  7735. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7736. $event.preventDefault();
  7737. $event.stopPropagation();
  7738. item[openParam] = !item[openParam];
  7739. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7740. $scope.tableParams.reload();
  7741. }
  7742. };
  7743. $scope.parseDate = function (dateStr) {
  7744. if (dateStr)
  7745. return Date.parse(dateStr, 'yyyy-MM-dd');
  7746. return new Date();
  7747. };
  7748. // 选择查找日期
  7749. $scope.onDateCondition = function () {
  7750. $scope.tableParams.page(1);
  7751. $scope.tableParams.reload();
  7752. };
  7753. // 搜索框回车
  7754. $scope.onSearch = function () {
  7755. $scope.tableParams.page(1);
  7756. $scope.tableParams.reload();
  7757. };
  7758. // 导出
  7759. $scope.exportXls = function () {
  7760. PurcAccept.exportXls({}, {}, function (data) {
  7761. if (data.success){
  7762. window.location.href = 'sale/accept/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  7763. }
  7764. }, function (response) {
  7765. toaster.pop('error', '数据加载失败', response.data);
  7766. });
  7767. }
  7768. }]);
  7769. /**
  7770. * 客户采购验收详情
  7771. */
  7772. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcAccept, toaster, BaseService, $stateParams, CurrentRole) {
  7773. BaseService.scrollBackToTop();
  7774. // 获取当前用户是否为普通用户
  7775. CurrentRole.isUser({}, {}, function (data) {
  7776. $scope.isUser = data.isUser;
  7777. });
  7778. if ($stateParams.id) {
  7779. PurcAccept.getDetail({id: $stateParams.id}, {}, function (data) {
  7780. $scope.accept = data;
  7781. if ($scope.accept.acceptItems != null) {
  7782. var sum = 0;
  7783. angular.forEach($scope.accept.acceptItems, function (item) {
  7784. sum += item.orderPrice * item.qty;
  7785. });
  7786. $scope.totalPrice = sum;
  7787. }
  7788. }, function (response) {
  7789. toaster.pop('error', '提示', response.data);
  7790. });
  7791. }
  7792. }]);
  7793. /**
  7794. * 客户采购验退
  7795. */
  7796. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  7797. BaseService.scrollBackToTop();
  7798. // 获取当前用户是否为普通用户
  7799. CurrentRole.isUser({}, {}, function (data) {
  7800. $scope.isUser = data.isUser;
  7801. });
  7802. $scope.active = 'all';
  7803. $scope.agreedText = '全部';
  7804. $scope.dateZoneText = '一个月内';
  7805. $scope.condition = {dateZone: 1};
  7806. /* 时间筛选初始化*/
  7807. var fromDate = new Date();
  7808. var toDate = new Date();
  7809. fromDate.setMonth(fromDate.getMonth() - 1);
  7810. fromDate.setHours(0, 0, 0, 0);
  7811. toDate.setHours(23, 59, 59, 999);
  7812. $scope.condition.dateFrom = fromDate;
  7813. $scope.condition.dateTo = toDate;
  7814. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7815. $scope.changeAgreed = function (agreed) {
  7816. $scope.condition.agreed = agreed;
  7817. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7818. $scope.condition.$agreedOpen = false;
  7819. };
  7820. $scope.changeDateZone = function (zone) {
  7821. $scope.condition.dateZone = zone;
  7822. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7823. $scope.condition.$dateZoneOpen = false;
  7824. getDateCondition(zone, $scope.condition);
  7825. $scope.tableParams.page(1);
  7826. $scope.tableParams.reload();
  7827. };
  7828. $scope.setActive = function (state) {
  7829. if ($scope.active != state) {
  7830. $scope.active = state;
  7831. if ($scope.tableParams.page() == 1)
  7832. $scope.tableParams.reload();
  7833. else
  7834. $scope.tableParams.page(1);
  7835. }
  7836. };
  7837. var getService = function () {
  7838. return PurcReturn;
  7839. };
  7840. $scope.tableParams = new ngTableParams({
  7841. page: 1,
  7842. count: 20,
  7843. sorting: {
  7844. date: 'desc'
  7845. }
  7846. }, {
  7847. total: 0,
  7848. counts: [5, 10, 25, 50],
  7849. getData: function ($defer, params) {
  7850. $scope.loading = true;
  7851. var pageParams = params.url();
  7852. pageParams.searchFilter = {
  7853. keyword: $scope.keyword,
  7854. fromDate: getDateTime($scope.condition.dateFrom),
  7855. endDate: getDateTime($scope.condition.dateTo)
  7856. };
  7857. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7858. $scope.loading = false;
  7859. if (page) {
  7860. params.total(page.totalElement);
  7861. $defer.resolve(page.content);
  7862. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7863. angular.forEach(page.content, function (data) {
  7864. if (!data.returnItems[0].orderItem) {
  7865. PurcReturn.getEnterpriseName({id: data.id, enuu: data.enUU}, function (enterprise) {
  7866. data.enName = enterprise.enName;
  7867. });
  7868. }
  7869. });
  7870. }
  7871. }, function (response) {
  7872. $scope.loading = false;
  7873. toaster.pop('error', '数据加载失败', response.data);
  7874. });
  7875. }
  7876. });
  7877. $scope.openDatePicker = function ($event, item, openParam) {
  7878. $event.preventDefault();
  7879. $event.stopPropagation();
  7880. item[openParam] = !item[openParam];
  7881. };
  7882. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7883. $event.preventDefault();
  7884. $event.stopPropagation();
  7885. item[openParam] = !item[openParam];
  7886. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7887. $scope.tableParams.reload();
  7888. }
  7889. };
  7890. // 搜索框回车
  7891. $scope.onSearch = function () {
  7892. $scope.tableParams.page(1);
  7893. $scope.tableParams.reload();
  7894. };
  7895. // 导出
  7896. $scope.exportXls = function () {
  7897. PurcReturn.exportXls({}, {}, function (data) {
  7898. if (data.success){
  7899. window.location.href = 'sale/return/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  7900. }
  7901. }, function (response) {
  7902. toaster.pop('error', '数据加载失败', response.data);
  7903. });
  7904. }
  7905. }]);
  7906. /**
  7907. * 客户采购验退详情
  7908. */
  7909. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcReturn, toaster, BaseService, $stateParams, CurrentRole) {
  7910. BaseService.scrollBackToTop();'' +
  7911. // 获取当前用户是否为普通用户
  7912. CurrentRole.isUser({}, {}, function (data) {
  7913. $scope.isUser = data.isUser;
  7914. });
  7915. if ($stateParams.id != null) {
  7916. PurcReturn.getDetail({id: $stateParams.id}, {}, function (data) {
  7917. $scope.returns = data;
  7918. if ($scope.returns.returnItems != null) {
  7919. var sum = 0;
  7920. angular.forEach($scope.returns.returnItems, function (item) {
  7921. sum += item.orderPrice * item.qty;
  7922. });
  7923. $scope.totalPrice = sum;
  7924. }
  7925. }, function (response) {
  7926. toaster.pop('error', '提示', response.data);
  7927. });
  7928. }
  7929. }]);
  7930. /**
  7931. * 客户不良品入库
  7932. */
  7933. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  7934. BaseService.scrollBackToTop();
  7935. // 获取当前用户是否为普通用户
  7936. CurrentRole.isUser({}, {}, function (data) {
  7937. $scope.isUser = data.isUser;
  7938. });
  7939. $scope.active = 'all';
  7940. $scope.agreedText = '全部';
  7941. $scope.dateZoneText = '一个月内';
  7942. $scope.condition = {dateZone: 1};
  7943. /* 时间筛选初始化*/
  7944. var fromDate = new Date();
  7945. var toDate = new Date();
  7946. fromDate.setMonth(fromDate.getMonth() - 1);
  7947. fromDate.setHours(0, 0, 0, 0);
  7948. toDate.setHours(23, 59, 59, 999);
  7949. $scope.condition.dateFrom = fromDate;
  7950. $scope.condition.dateTo = toDate;
  7951. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7952. $scope.changeAgreed = function (agreed) {
  7953. $scope.condition.agreed = agreed;
  7954. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7955. $scope.condition.$agreedOpen = false;
  7956. };
  7957. $scope.changeDateZone = function (zone) {
  7958. $scope.condition.dateZone = zone;
  7959. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7960. $scope.condition.$dateZoneOpen = false;
  7961. getDateCondition(zone, $scope.condition);
  7962. $scope.tableParams.page(1);
  7963. $scope.tableParams.reload();
  7964. };
  7965. $scope.setActive = function (state) {
  7966. if ($scope.active != state) {
  7967. $scope.active = state;
  7968. if ($scope.tableParams.page() == 1)
  7969. $scope.tableParams.reload();
  7970. else
  7971. $scope.tableParams.page(1);
  7972. }
  7973. };
  7974. var getService = function () {
  7975. return PurcBadIn;
  7976. };
  7977. $scope.tableParams = new ngTableParams({
  7978. page: 1,
  7979. count: 20,
  7980. sorting: {
  7981. date: 'desc'
  7982. }
  7983. }, {
  7984. total: 0,
  7985. counts: [5, 10, 25, 50],
  7986. getData: function ($defer, params) {
  7987. $scope.loading = true;
  7988. var pageParams = params.url();
  7989. pageParams.searchFilter = {
  7990. keyword: $scope.keyword,
  7991. fromDate: getDateTime($scope.condition.dateFrom),
  7992. endDate: getDateTime($scope.condition.dateTo)
  7993. };
  7994. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7995. $scope.loading = false;
  7996. if (page) {
  7997. params.total(page.totalElement);
  7998. $defer.resolve(page.content);
  7999. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8000. }
  8001. }, function (response) {
  8002. $scope.loading = false;
  8003. toaster.pop('error', '数据加载失败', response.data);
  8004. });
  8005. }
  8006. });
  8007. $scope.openDatePicker = function ($event, item, openParam) {
  8008. $event.preventDefault();
  8009. $event.stopPropagation();
  8010. item[openParam] = !item[openParam];
  8011. };
  8012. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8013. $event.preventDefault();
  8014. $event.stopPropagation();
  8015. item[openParam] = !item[openParam];
  8016. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8017. $scope.tableParams.reload();
  8018. }
  8019. };
  8020. // 搜索框回车
  8021. $scope.onSearch = function (keyword) {
  8022. $scope.keyword = keyword;
  8023. $scope.tableParams.page(1);
  8024. $scope.tableParams.reload();
  8025. };
  8026. // 导出
  8027. $scope.exportXls = function () {
  8028. PurcBadIn.exportXls({}, {}, function (data) {
  8029. if (data.success){
  8030. window.location.href = 'sale/badIn/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8031. }
  8032. }, function (response) {
  8033. toaster.pop('error', '数据加载失败', response.data);
  8034. });
  8035. }
  8036. }]);
  8037. /**
  8038. * 客户不良品出库
  8039. */
  8040. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8041. BaseService.scrollBackToTop();
  8042. // 获取当前用户是否为普通用户
  8043. CurrentRole.isUser({}, {}, function (data) {
  8044. $scope.isUser = data.isUser;
  8045. });
  8046. $scope.active = 'all';
  8047. $scope.agreedText = '全部';
  8048. $scope.dateZoneText = '一个月内';
  8049. $scope.condition = {dateZone: 1};
  8050. /* 时间筛选初始化*/
  8051. var fromDate = new Date();
  8052. var toDate = new Date();
  8053. fromDate.setMonth(fromDate.getMonth() - 1);
  8054. fromDate.setHours(0, 0, 0, 0);
  8055. toDate.setHours(23, 59, 59, 999);
  8056. $scope.condition.dateFrom = fromDate;
  8057. $scope.condition.dateTo = toDate;
  8058. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8059. $scope.changeAgreed = function (agreed) {
  8060. $scope.condition.agreed = agreed;
  8061. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8062. $scope.condition.$agreedOpen = false;
  8063. };
  8064. $scope.changeDateZone = function (zone) {
  8065. $scope.condition.dateZone = zone;
  8066. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8067. $scope.condition.$dateZoneOpen = false;
  8068. getDateCondition(zone, $scope.condition);
  8069. $scope.tableParams.page(1);
  8070. $scope.tableParams.reload();
  8071. };
  8072. $scope.setActive = function (state) {
  8073. if ($scope.active != state) {
  8074. $scope.active = state;
  8075. if ($scope.tableParams.page() == 1)
  8076. $scope.tableParams.reload();
  8077. else
  8078. $scope.tableParams.page(1);
  8079. }
  8080. };
  8081. var getService = function () {
  8082. return PurcBadOut;
  8083. };
  8084. $scope.tableParams = new ngTableParams({
  8085. page: 1,
  8086. count: 20,
  8087. sorting: {
  8088. date: 'desc'
  8089. }
  8090. }, {
  8091. total: 0,
  8092. counts: [5, 10, 25, 50],
  8093. getData: function ($defer, params) {
  8094. $scope.loading = true;
  8095. var pageParams = params.url();
  8096. pageParams.searchFilter = {
  8097. keyword: $scope.keyword,
  8098. fromDate: getDateTime($scope.condition.dateFrom),
  8099. endDate: getDateTime($scope.condition.dateTo)
  8100. };
  8101. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8102. $scope.loading = false;
  8103. if (page) {
  8104. params.total(page.totalElement);
  8105. $defer.resolve(page.content);
  8106. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8107. }
  8108. }, function (response) {
  8109. $scope.loading = false;
  8110. toaster.pop('error', '数据加载失败', response.data);
  8111. });
  8112. }
  8113. });
  8114. $scope.openDatePicker = function ($event, item, openParam) {
  8115. $event.preventDefault();
  8116. $event.stopPropagation();
  8117. item[openParam] = !item[openParam];
  8118. };
  8119. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8120. $event.preventDefault();
  8121. $event.stopPropagation();
  8122. item[openParam] = !item[openParam];
  8123. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8124. $scope.tableParams.reload();
  8125. }
  8126. };
  8127. // 搜索框回车
  8128. $scope.onSearch = function () {
  8129. $scope.tableParams.page(1);
  8130. $scope.tableParams.reload();
  8131. };
  8132. // 导出
  8133. $scope.exportXls = function () {
  8134. PurcBadOut.exportXls({}, {}, function (data) {
  8135. if (data.success){
  8136. window.location.href = 'sale/badOut/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8137. }
  8138. }, function (response) {
  8139. toaster.pop('error', '数据加载失败', response.data);
  8140. });
  8141. }
  8142. }]);
  8143. /**
  8144. * 客户MRB
  8145. */
  8146. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol) {
  8147. BaseService.scrollBackToTop();
  8148. $scope.active = 'all';
  8149. $scope.agreedText = '全部';
  8150. $scope.dateZoneText = '一个月内';
  8151. $scope.condition = {dateZone: 1};
  8152. /* 时间筛选初始化*/
  8153. var fromDate = new Date();
  8154. var toDate = new Date();
  8155. fromDate.setMonth(fromDate.getMonth() - 1);
  8156. fromDate.setHours(0, 0, 0, 0);
  8157. toDate.setHours(23, 59, 59, 999);
  8158. $scope.condition.dateFrom = fromDate;
  8159. $scope.condition.dateTo = toDate;
  8160. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8161. $scope.changeAgreed = function (agreed) {
  8162. $scope.condition.agreed = agreed;
  8163. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8164. $scope.condition.$agreedOpen = false;
  8165. };
  8166. $scope.changeDateZone = function (zone) {
  8167. $scope.condition.dateZone = zone;
  8168. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8169. $scope.condition.$dateZoneOpen = false;
  8170. getDateCondition(zone, $scope.condition);
  8171. $scope.tableParams.page(1);
  8172. $scope.tableParams.reload();
  8173. };
  8174. $scope.setActive = function (state) {
  8175. if ($scope.active != state) {
  8176. $scope.active = state;
  8177. if ($scope.tableParams.page() == 1)
  8178. $scope.tableParams.reload();
  8179. else
  8180. $scope.tableParams.page(1);
  8181. }
  8182. };
  8183. var getService = function () {
  8184. return PurcMRB;
  8185. };
  8186. $scope.tableParams = new ngTableParams({
  8187. page: 1,
  8188. count: 20,
  8189. sorting: {
  8190. date: 'desc'
  8191. }
  8192. }, {
  8193. total: 0,
  8194. counts: [5, 10, 25, 50],
  8195. getData: function ($defer, params) {
  8196. $scope.loading = true;
  8197. var pageParams = params.url();
  8198. pageParams.searchFilter = {
  8199. keyword: $scope.keyword,
  8200. fromDate: getDateTime($scope.condition.dateFrom),
  8201. endDate: getDateTime($scope.condition.dateTo)
  8202. };
  8203. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8204. $scope.loading = false;
  8205. if (page) {
  8206. params.total(page.totalElement);
  8207. $defer.resolve(page.content);
  8208. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8209. }
  8210. }, function (response) {
  8211. $scope.loading = false;
  8212. toaster.pop('error', '数据加载失败', response.data);
  8213. });
  8214. }
  8215. });
  8216. $scope.openDatePicker = function ($event, item, openParam) {
  8217. $event.preventDefault();
  8218. $event.stopPropagation();
  8219. item[openParam] = !item[openParam];
  8220. };
  8221. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8222. $event.preventDefault();
  8223. $event.stopPropagation();
  8224. item[openParam] = !item[openParam];
  8225. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8226. $scope.tableParams.reload();
  8227. }
  8228. };
  8229. // 搜索框回车
  8230. $scope.onSearch = function () {
  8231. $scope.tableParams.page(1);
  8232. $scope.tableParams.reload();
  8233. };
  8234. // 导出
  8235. $scope.exportXls = function () {
  8236. PurcMRB.exportXls({}, {}, function (data) {
  8237. if (data.success){
  8238. window.location.href = 'sale/MRB/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8239. }
  8240. }, function (response) {
  8241. toaster.pop('error', '数据加载失败', response.data);
  8242. });
  8243. }
  8244. }]);
  8245. //客户航天开票
  8246. app.controller('PurchaseApBillOutCtrl',['$scope', 'FaApBillOut', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function ($scope, FaApBillOut, BaseService, ngTableParams, toaster, ReportService , Symbol) {
  8247. BaseService.scrollBackToTop();
  8248. $scope.dateZoneText = '不限';
  8249. $scope.condition = {dateZone: 1};
  8250. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8251. $scope.active = 'all';
  8252. /* 时间筛选初始化*/
  8253. var fromDate = new Date();
  8254. var toDate = new Date();
  8255. fromDate.setMonth(fromDate.getMonth() - 1);
  8256. fromDate.setHours(0,0,0,0);
  8257. toDate.setHours(23,59,59,999);
  8258. $scope.condition.dateFrom = fromDate;
  8259. $scope.condition.dateTo = toDate;
  8260. //打印 开票单
  8261. $scope.print = function (billOut) {
  8262. FaApBillOut.printCount({id: billOut.id},function (data) {
  8263. if(!data.error) {
  8264. toaster.pop('success', '提示', '打印成功');
  8265. //$scope.tableParams.reload();
  8266. }else{
  8267. toaster.pop('error', '提示', '打印失败');
  8268. }
  8269. });
  8270. //ReportService.print(billOut.custUu, 'PURCBILLOUT', 'where purc$apbillout.pabo_id =' + billOut.id);
  8271. };
  8272. //状态
  8273. $scope.setActive = function (state) {
  8274. if($scope.active != state) {
  8275. $scope.active = state;
  8276. if($scope.tableParams.page() == 1)
  8277. $scope.tableParams.reload();
  8278. else
  8279. $scope.tableParams.page(1);
  8280. }
  8281. };
  8282. $scope.changeDateZone = function (zone) {
  8283. $scope.condition.dateZone = zone;
  8284. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8285. $scope.condition.$dateZoneOpen = false;
  8286. getDateCondition(zone, $scope.condition);
  8287. $scope.tableParams.page(1);
  8288. $scope.tableParams.reload();
  8289. };
  8290. //获取全部已确定应收对账单
  8291. $scope.tableParams = new ngTableParams({
  8292. page: 1,
  8293. count: 20,
  8294. sorting: {
  8295. recordDate: 'desc'
  8296. }
  8297. }, {
  8298. total: 0,
  8299. counts: [5, 10, 25, 50],
  8300. getData: function ($defer, params) {
  8301. $scope.loading = true;
  8302. var pageParams = params.url();
  8303. pageParams.searchFilter = { // 筛选条件
  8304. keyword: $scope.keyword,
  8305. fromDate: getDateTime($scope.condition.dateFrom),
  8306. endDate: getDateTime($scope.condition.dateTo)
  8307. };
  8308. FaApBillOut[getState($scope.active )](BaseService.parseParams(pageParams), function (page) {
  8309. $scope.loading = false;
  8310. if(page) {
  8311. params.total(page.totalElement);
  8312. $scope.data = $defer.resolve(page.content);
  8313. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  8314. }
  8315. }, function (response) {
  8316. $scope.loading = false;
  8317. toaster.pop('error', '数据加载失败', response.data);
  8318. });
  8319. }
  8320. });
  8321. $scope.openDatePicker = function ($event, item, openParam) {
  8322. $event.preventDefault();
  8323. $event.stopPropagation();
  8324. item[openParam] = !item[openParam];
  8325. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  8326. $scope.tableParams.reload();
  8327. }
  8328. };
  8329. // 计算开票数量
  8330. $scope.getTotalProd = function (billOut) {
  8331. var total = 0;
  8332. if(billOut.items) {
  8333. angular.forEach(billOut.items, function (value) {
  8334. total += value.NowQty;
  8335. });
  8336. }
  8337. return total;
  8338. };
  8339. // 搜索框回车
  8340. $scope.onSearch = function () {
  8341. $scope.tableParams.page(1);
  8342. $scope.tableParams.reload();
  8343. };
  8344. // 选择查找日期
  8345. $scope.onDateCondition = function () {
  8346. $scope.tableParams.page(1);
  8347. $scope.tableParams.reload();
  8348. };
  8349. }]);
  8350. //开票单详情
  8351. app.controller('PurchaseApBillOutDetailCtrl',['$scope', 'toaster', 'FaApBillOut', 'FaApCheck', '$stateParams', 'BaseService', function ($scope, toaster, FaApBillOut, FaApCheck, $stateParams, BaseService) {
  8352. BaseService.scrollBackToTop();
  8353. $scope.haveSelected = true;
  8354. $scope.data = {};
  8355. //控制提交和删除按钮的显示
  8356. $scope.ifShow = true;
  8357. var loadData = function () {
  8358. FaApBillOut.get({id:$stateParams.id},function (data) {
  8359. $scope.data = data;
  8360. if($scope.data.status){
  8361. }else{
  8362. $scope.ifShow = true;
  8363. }
  8364. })
  8365. };
  8366. if($stateParams.id){
  8367. loadData();
  8368. }
  8369. $scope.haveSource = false;
  8370. //TODO 提交开票单
  8371. $scope.invoiceIssued = function (apBillOut) {
  8372. $scope.loading = true;
  8373. FaApBillOut.invoiceIssued({id:apBillOut.id},function (data) {
  8374. $scope.loading = false;
  8375. if(data.apBillOut) {
  8376. $scope.haveSelected = false;
  8377. window.location.href = '#/fa/apBillOut';
  8378. toaster.pop('success', '提示', '提交成功');
  8379. }else {
  8380. /*$scope.haveSource = true;
  8381. loadData();
  8382. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  8383. $scope.haveSelected = true;*/
  8384. $scope.loading = false;
  8385. toaster.pop('error', '提示', data.error);
  8386. }
  8387. }/*,function(){
  8388. $scope.loading = false;
  8389. toaster.pop('error', '提示', '更新已转数失败');
  8390. }*/);
  8391. }
  8392. //删除开票单(后台同时更新对账单明细表已开票数)
  8393. $scope.deleteApBillOut = function () {
  8394. FaApBillOut.deleteApBillOut({id:$stateParams.id},function (data) {
  8395. window.location.href = '#/fa/apBillOut';
  8396. toaster.pop('success','提示','删除成功');
  8397. },function () {
  8398. toaster.pop('error','提示','删除失败');
  8399. });
  8400. $scope.haveSelected = false;
  8401. }
  8402. //TODO 作废开票单
  8403. $scope.InvoiceCancel = function () {
  8404. $scope.loading = true;
  8405. FaApBillOut.InvoiceCancel({id:$stateParams.id},function (data) {
  8406. $scope.loading = false;
  8407. if(!data.error) {
  8408. toaster.pop('success', '提示', '作废成功');
  8409. window.location.href = '#/fa/apBillOut';
  8410. $scope.tableParams.reload();
  8411. }else{
  8412. toaster.pop('error', '提示', data.error);
  8413. }
  8414. },function (response) {
  8415. $scope.loading = false;
  8416. toaster.pop('error', '提示', response.data);
  8417. });
  8418. }
  8419. }]);
  8420. //航天开票单据列表
  8421. app.controller('PurchaseApBillOutListCtrl',['$scope', 'FaApCheck', 'FaApBillOut', 'toaster', '$state','$filter', '$modal', function ($scope, FaApCheck, FaApBillOut, toaster, $state, $filter, $modal) {
  8422. $scope.data = [];// 列表数据
  8423. $scope.condition = {
  8424. $fromOpened: false
  8425. }
  8426. $scope.openDatePicker = function ($event, item, openParam) {
  8427. $event.preventDefault();
  8428. $event.stopPropagation();
  8429. item[openParam] = !item[openParam];
  8430. }
  8431. //查找客户
  8432. $scope.searchCust = function (suuorname) {
  8433. var modalInstance = $modal.open({
  8434. animation: true,
  8435. templateUrl: 'static/tpl/index/fa/custInfo.html',
  8436. controller: 'SearchCustInfoCtrl',
  8437. resolve: {
  8438. suuorname: function () {
  8439. return suuorname;
  8440. }
  8441. }
  8442. });
  8443. modalInstance.result.then(function (suuorname) {
  8444. $scope.suuorname = suuorname;
  8445. });
  8446. }
  8447. // 点击筛选根据条件选择数据
  8448. $scope.suuorname = '';
  8449. // 默认本月
  8450. $scope.sdateTo = new Date();
  8451. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  8452. $scope.vuuorname = '';
  8453. $scope.factory = '';
  8454. $scope.prodTitle = '';
  8455. $scope.prodSpec = '';
  8456. $scope.condition.uuorname = '';
  8457. $scope.condition.dateFrom = '';
  8458. $scope.condition.dateTo = '';
  8459. $scope.condition.venduuorname = '';
  8460. $scope.condition.factory = '';
  8461. $scope.condition.prodTitle = '';
  8462. $scope.condition.prodSpec = '';
  8463. $scope.searchOrder = function (check) {
  8464. $scope.data = [];
  8465. $scope.checkboxes.checked = false;
  8466. $scope.totalMoney = 0;
  8467. $scope.condition.uuorname = $scope.suuorname;
  8468. $scope.condition.factory = $scope.factory;
  8469. $scope.condition.prodTitle = $scope.prodTitle;
  8470. $scope.condition.prodSpec = $scope.prodSpec;
  8471. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  8472. $scope.thisdatato = ($scope.sdateTo || 0);
  8473. if($scope.thisdatato != 0) {
  8474. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  8475. } else {
  8476. $scope.condition.dateTo = ($scope.sdateTo || 0);
  8477. }
  8478. $scope.condition.venduuorname = $scope.vuuorname;
  8479. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  8480. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8481. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8482. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  8483. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  8484. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  8485. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  8486. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  8487. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8488. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  8489. if(!$scope.suuorname) {
  8490. toaster.pop('warning','提示', '请先选择客户');
  8491. document.getElementById('suuorname').focus();//光标默认在客户
  8492. } else {
  8493. $scope.loading = true;
  8494. FaApBillOut.getDoneApCheckByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  8495. if(data.length > 0) {
  8496. angular.forEach(data, function (checkItem) {
  8497. checkItem.$selected = true;
  8498. if(checkItem.billed) {
  8499. checkItem.thisBilledQty = checkItem.checkQty - checkItem.billed;
  8500. //$filter('number')(checkItem.thisBilledQty, 2);
  8501. } else {
  8502. checkItem.billed = 0;
  8503. checkItem.thisBilledQty = checkItem.checkQty;
  8504. }
  8505. //最大最小开票数
  8506. checkItem.maxThisBilledQty = checkItem.thisBilledQty;
  8507. checkItem.minThisBilledQty = 0;
  8508. });
  8509. $scope.data = data;
  8510. $scope.checkboxes.checked = true;
  8511. $scope.getTotalMoney();
  8512. } else {
  8513. toaster.pop('info', '提示', '当前没有需要对账记录');
  8514. }
  8515. $scope.loading = false;
  8516. }, function (response) {
  8517. $scope.loading = false;
  8518. toaster.pop('error', '提示', response.data);
  8519. });
  8520. }
  8521. }
  8522. }
  8523. /**
  8524. * 点击勾选框,选中要转应收对账单的订单
  8525. * */
  8526. $scope.totalMoney = 0;
  8527. $scope.checkboxes = {
  8528. checked: false
  8529. };
  8530. // 点击勾选全部的复选框
  8531. $scope.checkAll = function () {
  8532. $scope.totalMoney = 0;
  8533. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  8534. var uuorname = $scope.suuorname;
  8535. var venduuorname = $scope.venduuorname;
  8536. var dateFrom = $scope.condition.dateFrom;
  8537. var dateTo = $scope.condition.dateTo;
  8538. var prodTitle = $scope.condition.prodTitle;
  8539. var prodSpec = $scope.condition.prodSpec;
  8540. var factory = $scope.condition.factory;
  8541. angular.forEach($scope.filteredData, function (item) {
  8542. if((item.apCheck.apDate >= dateFrom || dateFrom == '') && (item.apCheck.apDate < dateTo || dateTo == '')){
  8543. item.$selected = $scope.checkboxes.checked;
  8544. }
  8545. });
  8546. $scope.getTotalMoney();
  8547. };
  8548. //获取已选单据总金额
  8549. var total = true;
  8550. $scope.getTotalMoney = function () {
  8551. $scope.totalMoney = 0;
  8552. angular.forEach($scope.data, function (check) {
  8553. if(check.$selected){
  8554. $scope.totalMoney += (check.CheckQty || 0)*(check.orderPrice || 0);
  8555. }else{
  8556. $scope.totalMoney += 0;
  8557. }
  8558. });
  8559. }
  8560. // 点击其中一个明细的复选框
  8561. $scope.checkOne = function (check) {
  8562. var result = true;
  8563. angular.forEach($scope.data, function (item) {
  8564. if(item.$selected != true){
  8565. result = false;
  8566. return;
  8567. }
  8568. });
  8569. $scope.checkboxes.checked = result;
  8570. };
  8571. $scope.haveSelected = false;
  8572. //生成开票单
  8573. $scope.createApBillOut = function () {
  8574. //保存应收对账单主记录字段
  8575. $scope.apBillOut = {
  8576. custUu: '',
  8577. custName: '',
  8578. beginDate: '',
  8579. endDate: '',
  8580. enUu: '',
  8581. recordDate: '',
  8582. checkStatus: '未开票',
  8583. currency: '',
  8584. rate: '',
  8585. //billed:'',
  8586. //apBillOutItemId:'',
  8587. items: [],
  8588. sourceInfos: []
  8589. };
  8590. //保存来源单据相关信息
  8591. //var sourceInfos = [];
  8592. //所允许的本次对账最大最小数量
  8593. //$scope.data.maxThisCheckQty = 0;
  8594. //$scope.data.minThisCheckQty = 0;
  8595. $scope.sameCust = true;
  8596. $scope.validQty = true;
  8597. $scope.loading = true;
  8598. angular.forEach($scope.data, function (checkItem) {
  8599. //保存开票单明细行数据
  8600. $scope.item = {
  8601. inoutno: '',
  8602. inoutnodetno: '',
  8603. orderCode: '',
  8604. orderClass: '',
  8605. orderDetno: '',
  8606. price: '',
  8607. NowQty: '',
  8608. //amount: '',
  8609. sourceId:'',
  8610. sourceTable:'',
  8611. //oldYCheckQty:'',
  8612. status: 0,
  8613. //receiveCode:'',
  8614. //receiveName:'',
  8615. prodCode:'',
  8616. //prodSpec:'',
  8617. taxrate: '',
  8618. //sendcode: '',
  8619. //whname: '',
  8620. };
  8621. //开票单明细行来源表信息(新的已开票数)
  8622. $scope.sourceInfo = {
  8623. sourceId: '',
  8624. sourceTable: '',
  8625. newBilledQty: 0
  8626. };
  8627. //本次开票新的开票数
  8628. //$scope.thisBilledQty = 0;
  8629. if(checkItem.$selected == true) {
  8630. $scope.apBillOut.custName = checkItem.apCheck.custName;
  8631. $scope.apBillOut.enUu = checkItem.apCheck.enUu;
  8632. $scope.item.inoutno = checkItem.inoutno;
  8633. $scope.item.inoutnodetno = checkItem.inoutnodetno;
  8634. $scope.item.orderCode = checkItem.orderCode;
  8635. $scope.item.orderClass = checkItem.orderClass;
  8636. $scope.item.orderDetno = checkItem.orderDetno;
  8637. $scope.item.NowQty = checkItem.thisBilledQty;
  8638. if (typeof(checkItem.billed) == "undefined") {
  8639. checkItem.billed = 0;
  8640. $scope.sourceInfo.newBilledQty =checkItem.thisBilledQty;
  8641. } else {
  8642. //TODO 变成了字符串相加?
  8643. $scope.sourceInfo.newBilledQty = checkItem.thisBilledQty + checkItem.billed;
  8644. }
  8645. //$scope.apBillOut.apBillOutItemId = check.id;
  8646. $scope.apBillOut.recordDate = checkItem.recordDate;
  8647. $scope.apBillOut.rate = checkItem.apCheck.rate;
  8648. //必须是同一家客户才能生成对账单,否则提示错误
  8649. if($scope.apBillOut.custUu == ''){
  8650. $scope.apBillOut.custUu = checkItem.apCheck.custUu;
  8651. }else if($scope.apBillOut.custUu !== checkItem.apCheck.custUu){
  8652. $scope.sameCust = false;
  8653. $scope.loading = false;
  8654. toaster.pop('error', '请选择同一家客户');
  8655. }
  8656. //必须是相同币别才能生成对账单,否则提示错误
  8657. if($scope.apBillOut.currency == ''){
  8658. $scope.apBillOut.currency = checkItem.apCheck.currency;
  8659. }else if($scope.apBillOut.currency !== checkItem.apCheck.currency){
  8660. $scope.sameCust = false;
  8661. $scope.loading = false;
  8662. toaster.pop('error', '请选择同一种币别');
  8663. }
  8664. //本次对账数量必须小于总对账数量
  8665. if(checkItem.checkQty > 0){
  8666. //$scope.data.maxThisCheckQty = checkItem.CheckQty - checkItem.billed;
  8667. //$scope.data.minThisCheckQty = 0;
  8668. //if(checkItem.qty - (checkItem.yCheckQty || 0) < checkItem.CheckQty || checkItem.CheckQty < 0 || checkItem.CheckQty == 0){
  8669. if(checkItem.minThisBilledQty >checkItem.thisBilledQty || checkItem.maxThisBilledQty <checkItem.thisBilledQty) {
  8670. $scope.validQty = false;
  8671. $scope.loading = false;
  8672. toaster.pop('error','本次开票数量,填写有误!');
  8673. }
  8674. }else if(check.qty < 0){
  8675. $scope.data.maxCheckQty = 0;
  8676. $scope.data.minCheckQty = check.qty;
  8677. if(((-check.qty)-(-check.yCheckQty) < (-check.CheckQty)) || check.CheckQty > 0 || check.CheckQty == 0){
  8678. $scope.validQty = false;
  8679. $scope.loading = false;
  8680. toaster.pop('error','本次开票数量,填写有误!');
  8681. }
  8682. }
  8683. //TODO
  8684. //获取最小时间作为对账区间的起始时间
  8685. if($scope.apBillOut.beginDate == ''){
  8686. $scope.apBillOut.beginDate = checkItem.apCheck.apDate;
  8687. }else{
  8688. $scope.apBillOut.beginDate = $scope.apBillOut.beginDate>checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.beginDate;
  8689. }
  8690. //获取最大时间作为对账区间的截止时间
  8691. if($scope.apBillOut.endDate == ''){
  8692. $scope.apBillOut.endDate = checkItem.apCheck.apDate;
  8693. }else{
  8694. $scope.apBillOut.endDate = $scope.apBillOut.endDate<checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.endDate;
  8695. }
  8696. //应收开票单明细行数据
  8697. //$scope.item.orderCode = check.orderCode;
  8698. //$scope.item.orderClass = check.piClass;
  8699. //$scope.item.orderDetno = check.orderDetno;
  8700. $scope.item.price = checkItem.price;
  8701. //$scope.item.price = check.orderPrice;
  8702. //$scope.item.NowQty = check.checkQty;
  8703. //$scope.item.amount = (check.CheckQty || 0)*(check.orderPrice || 0);
  8704. $scope.item.sourceId = checkItem.id;
  8705. $scope.item.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  8706. $scope.item.NowQty = checkItem.thisBilledQty;
  8707. //$scope.item.oldYCheckQty = check.yCheckQty;
  8708. $scope.item.prodCode = checkItem.prodCode;
  8709. //$scope.item.prodTitle = check.prodTitle;
  8710. ////$scope.item.prodSpec = check.prodSpec;
  8711. //$scope.item.inoutno = check.inOutNo;
  8712. //$scope.item.inoutnodetno = check.detno;
  8713. $scope.item.taxrate = checkItem.taxrate;
  8714. //$scope.item.receiveCode = check.receiveCode;
  8715. //$scope.item.receiveName = check.receiveName;
  8716. //$scope.item.sendcode = check.sendcode;
  8717. //$scope.item.whname = check.whname;
  8718. //来源表相关信息
  8719. $scope.sourceInfo.sourceId = checkItem.id;
  8720. $scope.sourceInfo.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  8721. $scope.sourceInfo.newBilledQty = ((checkItem.billed || 0) + checkItem.thisBilledQty);
  8722. //sourceInfos.push($scope.sourceInfo);
  8723. $scope.apBillOut.items.push($scope.item);
  8724. $scope.apBillOut.sourceInfos.push($scope.sourceInfo);
  8725. $scope.haveSelected = true;
  8726. }
  8727. });
  8728. //保存生成的开票单,后台同时更新对账单明细表中已开票数
  8729. $scope.saveApBillOut = function () {
  8730. FaApBillOut.saveApBillOut({}, $scope.apBillOut, function (data) {
  8731. $scope.loading = false;
  8732. toaster.pop('success', '成功', '生成开票单成功');
  8733. $state.go('fa.apBillOut_detail', {id: data.id}, {reload:true});
  8734. }, function (response) {
  8735. toaster.pop('error', '生成开票单失败', response.data);
  8736. });
  8737. };
  8738. //如果是同一家客户,生成对账单的同时,关闭模态框
  8739. if($scope.sameCust && $scope.validQty) {
  8740. $scope.saveApBillOut();
  8741. }
  8742. }
  8743. }]);
  8744. /**
  8745. * 客户应付发票
  8746. */
  8747. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8748. BaseService.scrollBackToTop();
  8749. // 获取当前用户是否为普通用户
  8750. CurrentRole.isUser({}, {}, function (data) {
  8751. $scope.isUser = data.isUser;
  8752. });
  8753. $scope.active = 'all';
  8754. $scope.dateZoneText = '不限';
  8755. $scope.condition = {dateZone: 1};
  8756. /* 时间筛选初始化*/
  8757. var fromDate = new Date();
  8758. var toDate = new Date();
  8759. fromDate.setMonth(fromDate.getMonth() - 1);
  8760. fromDate.setHours(0, 0, 0, 0);
  8761. toDate.setHours(23, 59, 59, 999);
  8762. $scope.condition.dateFrom = fromDate;
  8763. $scope.condition.dateTo = toDate;
  8764. $scope.changeDateZone = function (zone) {
  8765. $scope.condition.dateZone = zone;
  8766. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8767. $scope.condition.$dateZoneOpen = false;
  8768. getDateCondition(zone, $scope.condition);
  8769. $scope.tableParams.page(1);
  8770. $scope.tableParams.reload();
  8771. };
  8772. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8773. $scope.setActive = function (state) {
  8774. if ($scope.active != state) {
  8775. $scope.active = state;
  8776. if ($scope.tableParams.page() == 1)
  8777. $scope.tableParams.reload();
  8778. else
  8779. $scope.tableParams.page(1);
  8780. }
  8781. };
  8782. var getService = function () {
  8783. return FaApBill;
  8784. };
  8785. $scope.tableParams = new ngTableParams({
  8786. page: 1,
  8787. count: 20,
  8788. sorting: {
  8789. date: 'desc'
  8790. }
  8791. }, {
  8792. total: 0,
  8793. counts: [5, 10, 25, 50],
  8794. getData: function ($defer, params) {
  8795. $scope.loading = true;
  8796. var pageParams = params.url();
  8797. pageParams.searchFilter = { // 筛选条件
  8798. keyword: $scope.keyword,
  8799. fromDate: getDateTime($scope.condition.dateFrom),
  8800. endDate: getDateTime($scope.condition.dateTo)
  8801. };
  8802. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8803. $scope.loading = false;
  8804. if (page) {
  8805. params.total(page.totalElement);
  8806. $defer.resolve(page.content);
  8807. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  8808. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8809. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8810. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  8811. }
  8812. }, function (response) {
  8813. $scope.loading = false;
  8814. toaster.pop('error', '数据加载失败', response.data);
  8815. });
  8816. }
  8817. });
  8818. $scope.openDatePicker = function ($event, item, openParam) {
  8819. $event.preventDefault();
  8820. $event.stopPropagation();
  8821. item[openParam] = !item[openParam];
  8822. };
  8823. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8824. $event.preventDefault();
  8825. $event.stopPropagation();
  8826. item[openParam] = !item[openParam];
  8827. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8828. $scope.tableParams.reload();
  8829. }
  8830. };
  8831. $scope.parseDate = function (dateStr) {
  8832. if (dateStr)
  8833. return Date.parse(dateStr, 'yyyy-MM-dd');
  8834. return new Date();
  8835. };
  8836. // 搜索框回车
  8837. $scope.onSearch = function () {
  8838. $scope.tableParams.page(1);
  8839. $scope.tableParams.reload();
  8840. };
  8841. // 选择查找日期
  8842. $scope.onDateCondition = function () {
  8843. $scope.tableParams.page(1);
  8844. $scope.tableParams.reload();
  8845. };
  8846. // 导出
  8847. $scope.exportXls = function () {
  8848. FaApBill.exportXls({}, {}, function (data) {
  8849. if (data.success){
  8850. window.location.href = 'sale/apBill/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  8851. }
  8852. }, function (response) {
  8853. toaster.pop('error', '数据加载失败', response.data);
  8854. });
  8855. }
  8856. }]);
  8857. /**
  8858. * 客户应付发票详情
  8859. */
  8860. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, $filter, FaApBill, toaster, $stateParams, BaseService, CurrentRole) {
  8861. BaseService.scrollBackToTop();
  8862. // 获取当前用户是否为普通用户
  8863. CurrentRole.isUser({}, {}, function (data) {
  8864. $scope.isUser = data.isUser;
  8865. });
  8866. var loadData = function () {
  8867. FaApBill.getAll({id: $stateParams.id}, function (data) {
  8868. $scope.bill = data;
  8869. $scope.loading = false;
  8870. }, function (response) {
  8871. toaster.pop('error', '', response.data);
  8872. });
  8873. };
  8874. loadData(); // 初始获取单据数据
  8875. }]);
  8876. /**
  8877. * 应付对账单
  8878. */
  8879. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol) {
  8880. BaseService.scrollBackToTop();
  8881. $scope.active = 'all';
  8882. $scope.dateZoneText = '不限';
  8883. $scope.condition = {dateZone: 1};
  8884. /* 时间筛选初始化*/
  8885. var fromDate = new Date();
  8886. var toDate = new Date();
  8887. fromDate.setMonth(fromDate.getMonth() - 1);
  8888. fromDate.setHours(0, 0, 0, 0);
  8889. toDate.setHours(23, 59, 59, 999);
  8890. $scope.condition.dateFrom = fromDate;
  8891. $scope.condition.dateTo = toDate;
  8892. $scope.changeDateZone = function (zone) {
  8893. $scope.condition.dateZone = zone;
  8894. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8895. $scope.condition.$dateZoneOpen = false;
  8896. getDateCondition(zone, $scope.condition);
  8897. $scope.tableParams.page(1);
  8898. $scope.tableParams.reload();
  8899. };
  8900. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8901. $scope.setActive = function (state) {
  8902. if ($scope.active != state) {
  8903. $scope.active = state;
  8904. if ($scope.tableParams.page() == 1)
  8905. $scope.tableParams.reload();
  8906. else
  8907. $scope.tableParams.page(1);
  8908. }
  8909. };
  8910. var getService = function () {
  8911. return FaArCheck;
  8912. };
  8913. $scope.tableParams = new ngTableParams({
  8914. page: 1,
  8915. count: 20,
  8916. sorting: {
  8917. date: 'desc'
  8918. }
  8919. }, {
  8920. total: 0,
  8921. counts: [5, 10, 25, 50],
  8922. getData: function ($defer, params) {
  8923. $scope.loading = true;
  8924. var pageParams = params.url();
  8925. pageParams.searchFilter = {};
  8926. pageParams.searchFilter.keyword = $scope.keyword;
  8927. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8928. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8929. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8930. $scope.loading = false;
  8931. if (page) {
  8932. params.total(page.totalElement);
  8933. $defer.resolve(page.content);
  8934. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8935. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8936. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  8937. }
  8938. }, function (response) {
  8939. $scope.loading = false;
  8940. toaster.pop('error', '数据加载失败', response.data);
  8941. });
  8942. }
  8943. });
  8944. $scope.openDatePicker = function ($event, item, openParam) {
  8945. $event.preventDefault();
  8946. $event.stopPropagation();
  8947. item[openParam] = !item[openParam];
  8948. };
  8949. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8950. $event.preventDefault();
  8951. $event.stopPropagation();
  8952. item[openParam] = !item[openParam];
  8953. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8954. $scope.tableParams.reload();
  8955. }
  8956. };
  8957. // 计算单据的商品总数
  8958. $scope.getTotalProd = function (check) {
  8959. var total = 0;
  8960. if (check.items) {
  8961. angular.forEach(check.items, function (value) {
  8962. total += value.qty;
  8963. });
  8964. }
  8965. return total;
  8966. };
  8967. // 搜索框回车
  8968. $scope.onSearch = function () {
  8969. $scope.tableParams.page(1);
  8970. $scope.tableParams.reload();
  8971. };
  8972. // 选择查找日期
  8973. $scope.onDateCondition = function () {
  8974. $scope.tableParams.page(1);
  8975. $scope.tableParams.reload();
  8976. };
  8977. }]);
  8978. // 应付对账单详情页
  8979. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function ($scope, $stateParams, FaArCheck, toaster, $state, BaseService) {
  8980. BaseService.scrollBackToTop();
  8981. var loadData = function () {
  8982. FaArCheck.get({id: $stateParams.id}, function (data) {
  8983. $scope.order = data;
  8984. $scope.loading = false;
  8985. });
  8986. };
  8987. loadData(); // 初始获取单据数据
  8988. $scope.onReplyClick = function (item, isAgreed) {
  8989. if (isAgreed) {// 同意确认
  8990. FaArCheck.agree({itemId: item.id}, {}, function (data) {
  8991. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  8992. }, function (response) {
  8993. toaster.pop('danger', '确认失败', response.data);
  8994. });
  8995. } else {// 不同意回复
  8996. FaArCheck.disagree({itemId: item.id}, {
  8997. qty: item.$replyQty,
  8998. remark: item.$replyRemark
  8999. }, function (data) {
  9000. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  9001. }, function (response) {
  9002. toaster.pop('danger', '确认失败', response.data);
  9003. });
  9004. }
  9005. };
  9006. // 获取明细的回复记录
  9007. $scope.getReplies = function (item) {
  9008. if (!item.replies) {
  9009. FaArCheck.getReplies({itemId: item.id}, function (data) {
  9010. item.replies = data;
  9011. }, function (response) {
  9012. toaster.pop('danger', '获取对账记录失败', response.data);
  9013. });
  9014. }
  9015. };
  9016. }]);
  9017. //应收对账单列表
  9018. app.controller('PurchaseApCheckCtrl', ['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster', 'ReportService', 'Symbol', 'CurrentRole', function ($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService, Symbol, CurrentRole) {
  9019. BaseService.scrollBackToTop();
  9020. // 获取当前用户是否为普通用户
  9021. CurrentRole.isUser({}, {}, function (data) {
  9022. $scope.isUser = data.isUser;
  9023. });
  9024. $scope.dateZoneText = '不限';
  9025. $scope.condition = {dateZone: 1};
  9026. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9027. $scope.active = 'todo';
  9028. /* 时间筛选初始化*/
  9029. var fromDate = new Date();
  9030. var toDate = new Date();
  9031. fromDate.setMonth(fromDate.getMonth() - 1);
  9032. fromDate.setHours(0, 0, 0, 0);
  9033. toDate.setHours(23, 59, 59, 999);
  9034. $scope.condition.dateFrom = fromDate;
  9035. $scope.condition.dateTo = toDate;
  9036. //打印 对账单
  9037. $scope.print = function (check) {
  9038. var newPage = window.open("about:blank");
  9039. FaApCheck.printPermission({}, function () {
  9040. FaApCheck.printCount({id: check.id}, {});//增加打印此次
  9041. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id, newPage);
  9042. }, function (response) {
  9043. newPage.close();
  9044. toaster.pop('error', '打印失败', response.data);
  9045. });
  9046. };
  9047. //状态
  9048. $scope.setActive = function (state) {
  9049. if ($scope.active != state) {
  9050. $scope.active = state;
  9051. if ($scope.tableParams.page() == 1)
  9052. $scope.tableParams.reload();
  9053. else
  9054. $scope.tableParams.page(1);
  9055. }
  9056. };
  9057. $scope.changeDateZone = function (zone) {
  9058. $scope.condition.dateZone = zone;
  9059. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9060. $scope.condition.$dateZoneOpen = false;
  9061. getDateCondition(zone, $scope.condition);
  9062. $scope.tableParams.page(1);
  9063. $scope.tableParams.reload();
  9064. };
  9065. //获取应收对账单全部
  9066. $scope.tableParams = new ngTableParams({
  9067. page: 1,
  9068. count: 20,
  9069. sorting: {
  9070. recordDate: 'desc'
  9071. }
  9072. }, {
  9073. total: 0,
  9074. counts: [5, 10, 25, 50],
  9075. getData: function ($defer, params) {
  9076. $scope.loading = true;
  9077. var pageParams = params.url();
  9078. pageParams.searchFilter = { // 筛选条件
  9079. keyword: $scope.keyword,
  9080. fromDate: getDateTime($scope.condition.dateFrom),
  9081. endDate: getDateTime($scope.condition.dateTo)
  9082. };
  9083. FaApCheck[getState($scope.active)](BaseService.parseParams(pageParams), function (page) {
  9084. $scope.loading = false;
  9085. if (page) {
  9086. params.total(page.totalElement);
  9087. $scope.data = $defer.resolve(page.content);
  9088. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  9089. }
  9090. }, function (response) {
  9091. $scope.loading = false;
  9092. toaster.pop('error', '数据加载失败', response.data);
  9093. });
  9094. }
  9095. });
  9096. //获得各分类未阅读数量
  9097. var getUnreadCount = function () {
  9098. FaApCheck.getUnreadCount(null, function(data){
  9099. $scope.unread = data;
  9100. });
  9101. };
  9102. getUnreadCount();
  9103. //设置单据已读
  9104. $scope.setOrdersRead = function (id) {
  9105. // 如果单据本身已读,则不发送请求修改数据
  9106. if (!$scope.isUnread(id)){
  9107. return;
  9108. }
  9109. var sourceId = [];
  9110. sourceId.push(id);
  9111. FaApCheck.setRead({}, sourceId, function (message) {
  9112. getUnreadCount();
  9113. });
  9114. };
  9115. //获取未读单据id
  9116. var getUnreadIds = function (){
  9117. FaApCheck.getUnreadIds({}, "", function (message) {
  9118. $scope.unreadCode = message.content;
  9119. });
  9120. };
  9121. getUnreadIds();
  9122. //判断单据是否未读
  9123. $scope.isUnread = function (id){
  9124. for (var i in $scope.unreadCode) {
  9125. if (id == $scope.unreadCode[i]) {
  9126. return true;
  9127. }
  9128. }
  9129. };
  9130. $scope.openDatePicker = function ($event, item, openParam) {
  9131. $event.preventDefault();
  9132. $event.stopPropagation();
  9133. item[openParam] = !item[openParam];
  9134. };
  9135. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9136. $event.preventDefault();
  9137. $event.stopPropagation();
  9138. item[openParam] = !item[openParam];
  9139. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9140. $scope.tableParams.reload();
  9141. }
  9142. };
  9143. // 计算单据的商品总数
  9144. $scope.getTotalProd = function (check) {
  9145. var total = 0;
  9146. if (check.items) {
  9147. angular.forEach(check.items, function (value) {
  9148. total += value.checkQty;
  9149. });
  9150. }
  9151. return total;
  9152. };
  9153. // 搜索框回车
  9154. $scope.onSearch = function () {
  9155. $scope.tableParams.page(1);
  9156. $scope.tableParams.reload();
  9157. };
  9158. // 选择查找日期
  9159. $scope.onDateCondition = function () {
  9160. $scope.tableParams.page(1);
  9161. $scope.tableParams.reload();
  9162. };
  9163. // 导出
  9164. $scope.exportXls = function () {
  9165. FaApCheck.exportXls({}, {}, function (data) {
  9166. if (data.success){
  9167. window.location.href = 'sale/apCheck/xls/list?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  9168. }
  9169. }, function (response) {
  9170. toaster.pop('error', '数据加载失败', response.data);
  9171. });
  9172. }
  9173. }]);
  9174. //应收对账单详情
  9175. app.controller('PurchaseApCheckDetailCtrl', ['$scope', 'toaster', 'FaApCheck', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, toaster, FaApCheck, $stateParams, BaseService, CurrentRole) {
  9176. BaseService.scrollBackToTop();
  9177. // 获取当前用户是否为普通用户
  9178. CurrentRole.isUser({}, {}, function (data) {
  9179. $scope.isUser = data.isUser;
  9180. });
  9181. $scope.haveSelected = true;
  9182. $scope.data = {};
  9183. //控制提交和删除按钮的显示
  9184. $scope.ifShow = true;
  9185. var loadData = function () {
  9186. FaApCheck.getItem({id: $stateParams.id}, function (data) {
  9187. $scope.data = data;
  9188. if ($scope.data.status) {
  9189. } else {
  9190. $scope.ifShow = true;
  9191. }
  9192. }, function (response) {
  9193. toaster.pop('error', '', response.data);
  9194. })
  9195. };
  9196. if ($stateParams.id) {
  9197. loadData();
  9198. }
  9199. $scope.haveSource = false;
  9200. //提交应收对账单
  9201. $scope.submitApCheck = function () {
  9202. FaApCheck.updateStatus({id: $stateParams.id}, {}, function (data) {
  9203. if (data.result) {
  9204. toaster.pop('success', '提示', '提交成功');
  9205. $scope.haveSelected = false;
  9206. window.location.href = '#/fa/apCheck';
  9207. } else {
  9208. $scope.haveSource = true;
  9209. loadData();
  9210. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  9211. $scope.haveSelected = true;
  9212. }
  9213. }, function (response) {
  9214. $scope.loading = false;
  9215. toaster.pop('error', '更新已转数失败', response.data);
  9216. });
  9217. }
  9218. //删除应收对账单的同时更新来源表已转数
  9219. var updateYCheckQty = function () {
  9220. var sourceInfos = [];
  9221. angular.forEach($scope.data.items, function (item) {
  9222. $scope.sourceInfo = {
  9223. sourceId: '',
  9224. sourceTable: '',
  9225. newYCheckQty: ''
  9226. };
  9227. $scope.sourceInfo.sourceId = item.sourceId;
  9228. $scope.sourceInfo.sourceTable = item.sourceTable;
  9229. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  9230. sourceInfos.push($scope.sourceInfo);
  9231. });
  9232. FaApCheck.update({}, sourceInfos, function () {
  9233. }, function (response) {
  9234. $scope.loading = false;
  9235. toaster.pop('error', '更新已转数失败', response.data);
  9236. });
  9237. }
  9238. //删除应收对账单
  9239. $scope.deleteApCheck = function () {
  9240. FaApCheck.deleteApCheck({id: $stateParams.id}, {}, function (data) {
  9241. updateYCheckQty();
  9242. toaster.pop('success', '提示', '删除成功');
  9243. }, function (response) {
  9244. toaster.pop('error', '删除失败', response.data);
  9245. });
  9246. $scope.haveSelected = false;
  9247. }
  9248. //作废应收对账单
  9249. $scope.cancelApCheck = function (check) {
  9250. FaApCheck.cancel({id: check.id}, {}, function (data) {
  9251. $scope.checkResult = false;
  9252. if (data.result) {
  9253. $scope.checkResult = true;
  9254. toaster.pop('success', '提示', '作废成功');
  9255. $scope.tableParams.reload();
  9256. } else {
  9257. toaster.pop('error', '提示', '作废失败');
  9258. }
  9259. }, function (response) {
  9260. $scope.loading = false;
  9261. toaster.pop('error', '作废失败', response.data);
  9262. });
  9263. }
  9264. }]);
  9265. //未对账单据列表
  9266. app.controller('PurchaseApCheckListCtrl', ['$scope', 'FaApCheck', 'toaster', '$state', '$filter', '$modal', 'Vendor', 'DecimalNumber', function ($scope, FaApCheck, toaster, $state, $filter, $modal, Vendor, DecimalNumber) {
  9267. $scope.data = [];// 列表数据
  9268. $scope.condition = {
  9269. $fromOpened: false
  9270. }
  9271. $scope.openDatePicker = function ($event, item, openParam) {
  9272. $event.preventDefault();
  9273. $event.stopPropagation();
  9274. item[openParam] = !item[openParam];
  9275. }
  9276. // 客户联想词
  9277. $scope.getSimilarCustomers = function (value) {
  9278. if (value) {
  9279. return Vendor.getSimilarCustomers({keyword: value}).$promise.then(function (data) {
  9280. return data.map(function (item) {
  9281. return item;
  9282. });
  9283. });
  9284. }
  9285. };
  9286. $scope.onAssociateCustomerClick = function (vendor) {
  9287. if (vendor.apcheck == 0) {
  9288. toaster.pop('info', '提示', '该客户暂未启用平台对账功能');
  9289. $scope.suuorname = '';
  9290. } else {
  9291. $scope.suuorname = vendor.custName;
  9292. }
  9293. }
  9294. //查找客户
  9295. $scope.searchCust = function (suuorname) {
  9296. var modalInstance = $modal.open({
  9297. animation: true,
  9298. templateUrl: 'static/tpl/index/fa/apcheck_customer.html',
  9299. controller: 'SearchCustInfoCtrl',
  9300. size: 'lg',
  9301. resolve: {
  9302. suuorname: function () {
  9303. return suuorname;
  9304. }
  9305. }
  9306. });
  9307. modalInstance.result.then(function (customer) {
  9308. $scope.suuorname = customer.myEnterprise.enName;
  9309. });
  9310. }
  9311. // 点击筛选根据条件选择数据
  9312. $scope.suuorname = '';
  9313. // 默认本月
  9314. $scope.sdateTo = new Date();
  9315. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  9316. $scope.vuuorname = '';
  9317. $scope.factory = '';
  9318. $scope.prodTitle = '';
  9319. $scope.prodSpec = '';
  9320. $scope.condition.uuorname = '';
  9321. $scope.condition.dateFrom = '';
  9322. $scope.condition.dateTo = '';
  9323. $scope.condition.venduuorname = '';
  9324. $scope.condition.factory = '';
  9325. $scope.condition.prodTitle = '';
  9326. $scope.condition.prodSpec = '';
  9327. $scope.searchOrder = function (check) {
  9328. $scope.data = [];
  9329. $scope.checkboxes.checked = false;
  9330. $scope.totalMoney = 0;
  9331. $scope.condition.uuorname = $scope.suuorname;
  9332. $scope.condition.factory = $scope.factory
  9333. $scope.condition.prodTitle = $scope.prodTitle;
  9334. $scope.condition.prodSpec = $scope.prodSpec;
  9335. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9336. $scope.thisdatato = ($scope.sdateTo || 0);
  9337. if ($scope.thisdatato != 0) {
  9338. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9339. } else {
  9340. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9341. }
  9342. $scope.condition.venduuorname = $scope.vuuorname;
  9343. if ($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9344. $scope.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9345. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9346. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  9347. + "|" + ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  9348. + "|" + ($scope.condition.factory == null ? "" : $scope.condition.factory)
  9349. + "|" + ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  9350. + "|" + ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  9351. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9352. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9353. if (!$scope.suuorname) {
  9354. toaster.pop('warning', '提示', '请先选择客户');
  9355. document.getElementById('suuorname').focus();//光标默认在客户
  9356. } else {
  9357. $scope.loading = true;
  9358. FaApCheck.getAllByKeywords({
  9359. fromDate: $scope.fromDate,
  9360. endDate: $scope.endDate,
  9361. keyword: $scope.keywordXls
  9362. }, function (data) {
  9363. if (data.length > 0) {
  9364. angular.forEach(data, function (item) {
  9365. item.$selected = true;
  9366. });
  9367. $scope.data = data;
  9368. $scope.checkboxes.checked = true;
  9369. $scope.getTotalMoney();
  9370. } else {
  9371. toaster.pop('info', '提示', '当前没有需要对账记录');
  9372. }
  9373. $scope.loading = false;
  9374. }, function (response) {
  9375. $scope.loading = false;
  9376. toaster.pop('error', '提示', response.data);
  9377. });
  9378. }
  9379. }
  9380. }
  9381. /**
  9382. * 点击勾选框,选中要转应收对账单的订单
  9383. * */
  9384. $scope.totalMoney = 0;
  9385. $scope.checkboxes = {
  9386. checked: false
  9387. };
  9388. // 点击勾选全部的复选框
  9389. $scope.checkAll = function () {
  9390. $scope.totalMoney = 0;
  9391. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  9392. var uuorname = $scope.suuorname;
  9393. var venduuorname = $scope.venduuorname;
  9394. var dateFrom = $scope.condition.dateFrom;
  9395. var dateTo = $scope.condition.dateTo;
  9396. var prodTitle = $scope.condition.prodTitle;
  9397. var prodSpec = $scope.condition.prodSpec;
  9398. var factory = $scope.condition.factory;
  9399. angular.forEach($scope.filteredData, function (item) {
  9400. if ((item.piDate >= dateFrom || dateFrom == '') && (item.piDate < dateTo || dateTo == '')) {
  9401. item.$selected = $scope.checkboxes.checked;
  9402. }
  9403. });
  9404. $scope.getTotalMoney();
  9405. };
  9406. //获取已选单据总金额
  9407. var total = true;
  9408. $scope.getTotalMoney = function () {
  9409. $scope.totalMoney = 0;
  9410. angular.forEach($scope.data, function (check) {
  9411. if (check.$selected) {
  9412. var price = DecimalNumber.accMul((check.thisCheckQty || 0), (check.orderPrice || 0));
  9413. $scope.totalMoney += Math.round(price * 100) / 100;
  9414. } else {
  9415. $scope.totalMoney += 0;
  9416. }
  9417. });
  9418. }
  9419. // 点击其中一个明细的复选框
  9420. $scope.checkOne = function (check) {
  9421. var result = true;
  9422. angular.forEach($scope.data, function (item) {
  9423. if (item.$selected != true) {
  9424. result = false;
  9425. return;
  9426. }
  9427. });
  9428. $scope.checkboxes.checked = result;
  9429. };
  9430. $scope.haveSelected = false;
  9431. //生成应收对账单
  9432. $scope.createApCheck = function () {
  9433. //保存应收对账单主记录字段
  9434. $scope.apCheck = {
  9435. custUu: '',
  9436. custName: '',
  9437. enUu: '',
  9438. apDate: '',
  9439. beginDate: '',
  9440. endDate: '',
  9441. checkStatus: '未对账',
  9442. checkAmount: 0,
  9443. currency: '',
  9444. rate: '',
  9445. items: []
  9446. };
  9447. //保存来源单据相关信息
  9448. var sourceInfos = [];
  9449. //所允许的本次对账最大最小数量
  9450. $scope.data.maxThisCheckQty = 0;
  9451. $scope.data.minThisCheckQty = 0;
  9452. $scope.sameCust = true;
  9453. $scope.validQty = true;
  9454. $scope.loading = true;
  9455. angular.forEach($scope.data, function (check) {
  9456. //保存应收对账单明细行数据
  9457. $scope.item = {
  9458. inoutno: '',
  9459. inoutnodetno: '',
  9460. orderCode: '',
  9461. orderClass: '',
  9462. orderDetno: '',
  9463. price: '',
  9464. checkQty: '',
  9465. amount: '',
  9466. sourceId: '',
  9467. sourceTable: '',
  9468. oldYCheckQty: '',
  9469. status: 0,
  9470. receiveCode: '',
  9471. receiveName: '',
  9472. prodCode: '',
  9473. prodTitle: '',
  9474. prodSpec: '',
  9475. taxrate: '',
  9476. sendcode: '',
  9477. whname: '',
  9478. };
  9479. //应收对账单明细行来源表信息
  9480. $scope.sourceInfo = {
  9481. sourceId: '',
  9482. sourceTable: '',
  9483. newYCheckQty: ''
  9484. };
  9485. //此次对账后新的已转数
  9486. $scope.newYCheckQty = 0;
  9487. if (check.$selected == true) {
  9488. $scope.apCheck.custName = check.custName;
  9489. $scope.apCheck.enUu = check.enUu;
  9490. $scope.apCheck.checkAmount += (check.thisCheckQty || 0) * (check.orderPrice || 0);
  9491. $scope.apCheck.apDate = check.piDate;
  9492. $scope.apCheck.rate = check.rate;
  9493. //必须是同一家客户才能生成对账单,否则提示错误
  9494. if ($scope.apCheck.custUu == '') {
  9495. $scope.apCheck.custUu = check.custUu;
  9496. } else if ($scope.apCheck.custUu !== check.custUu) {
  9497. $scope.sameCust = false;
  9498. $scope.loading = false;
  9499. toaster.pop('error', '请选择同一家客户');
  9500. }
  9501. //必须是相同币别才能生成对账单,否则提示错误
  9502. if ($scope.apCheck.currency == '') {
  9503. $scope.apCheck.currency = check.currency;
  9504. } else if ($scope.apCheck.currency !== check.currency) {
  9505. $scope.sameCust = false;
  9506. $scope.loading = false;
  9507. toaster.pop('error', '请选择同一种币别');
  9508. }
  9509. //本次对账数量必须小于总对账数量
  9510. if (check.qty > 0) {
  9511. $scope.data.maxThisCheckQty = check.qty;
  9512. $scope.data.minThisCheckQty = 0;
  9513. if (check.qty - (check.yCheckQty || 0) < check.thisCheckQty || check.thisCheckQty < 0 || check.thisCheckQty == 0) {
  9514. $scope.validQty = false;
  9515. $scope.loading = false;
  9516. toaster.pop('error', '本次对账数量,填写有误!');
  9517. }
  9518. } else if (check.qty < 0) {
  9519. $scope.data.maxThisCheckQty = 0;
  9520. $scope.data.minThisCheckQty = check.qty;
  9521. if (((-check.qty) - (-check.yCheckQty) < (-check.thisCheckQty)) || check.thisCheckQty > 0 || check.thisCheckQty == 0) {
  9522. $scope.validQty = false;
  9523. $scope.loading = false;
  9524. toaster.pop('error', '本次对账数量,填写有误!');
  9525. }
  9526. }
  9527. //获取最小时间作为对账区间的起始时间
  9528. if ($scope.apCheck.beginDate == '') {
  9529. $scope.apCheck.beginDate = check.piDate;
  9530. } else {
  9531. $scope.apCheck.beginDate = $scope.apCheck.beginDate > check.piDate ? check.piDate : $scope.apCheck.beginDate;
  9532. }
  9533. //获取最大时间作为对账区间的截止时间
  9534. if ($scope.apCheck.endDate == '') {
  9535. $scope.apCheck.endDate = check.piDate;
  9536. } else {
  9537. $scope.apCheck.endDate = $scope.apCheck.endDate < check.piDate ? check.piDate : $scope.apCheck.endDate;
  9538. }
  9539. //应收对账单明细行数据
  9540. $scope.item.orderCode = check.orderCode;
  9541. $scope.item.orderClass = check.piClass;
  9542. $scope.item.orderDetno = check.orderDetno;
  9543. $scope.item.price = check.orderPrice;
  9544. $scope.item.checkQty = check.thisCheckQty;
  9545. $scope.item.amount = (check.thisCheckQty || 0) * (check.orderPrice || 0);
  9546. $scope.item.sourceId = check.sourceId;
  9547. $scope.item.sourceTable = check.sourceTable;
  9548. $scope.item.oldYCheckQty = check.yCheckQty;
  9549. $scope.item.prodCode = check.prodCode;
  9550. $scope.item.prodTitle = check.prodTitle;
  9551. $scope.item.prodSpec = check.prodSpec;
  9552. $scope.item.inoutno = check.inOutNo;
  9553. $scope.item.inoutnodetno = check.detno;
  9554. $scope.item.taxrate = check.taxrate;
  9555. $scope.item.receiveCode = check.receiveCode;
  9556. $scope.item.receiveName = check.receiveName;
  9557. $scope.item.sendcode = check.sendcode;
  9558. $scope.item.whname = check.whname;
  9559. //来源表相关信息
  9560. $scope.sourceInfo.sourceId = check.sourceId;
  9561. $scope.sourceInfo.sourceTable = check.sourceTable;
  9562. $scope.sourceInfo.newYCheckQty = ((check.yCheckQty || 0) + check.thisCheckQty);
  9563. sourceInfos.push($scope.sourceInfo);
  9564. $scope.apCheck.items.push($scope.item);
  9565. $scope.haveSelected = true;
  9566. }
  9567. });
  9568. //保存生成的应收对账单
  9569. $scope.saveApCheck = function () {
  9570. FaApCheck.saveApCheck({}, $scope.apCheck, function (data) {
  9571. $scope.loading = false;
  9572. toaster.pop('success', '成功', '生成应收对账成功');
  9573. $state.go('fa.apCheck_detail', {id: data.id}, {reload: true});
  9574. }, function (response) {
  9575. $scope.loading = false;
  9576. toaster.pop('error', '生成对账单失败', response.data);
  9577. })
  9578. };
  9579. //如果是同一家客户,生成对账单的同时,关闭模态框
  9580. if ($scope.sameCust && $scope.validQty) {
  9581. $scope.saveApCheck();
  9582. }
  9583. }
  9584. }]);
  9585. // 企业信息设置
  9586. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function ($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder) {
  9587. BaseService.scrollBackToTop();
  9588. $scope.loading = true;
  9589. AccountEnterprise.get({}, function (data) {
  9590. $scope.loading = false;
  9591. $scope.enterprise = data;
  9592. if (data.tags) {
  9593. $scope.tags = data.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  9594. } else {
  9595. $scope.tags = [];
  9596. }
  9597. // 获取付款企业信息
  9598. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  9599. $scope.pays = data;
  9600. }, function (response) {
  9601. toaster.pop('error', '提示', response.data);
  9602. });
  9603. // 获取企业开票信息
  9604. AccountEnterprise.getApBillOutInfo({enuu: $scope.enterprise.uu}, {}, function(data) {
  9605. $scope.apBillOutInfo = data;
  9606. }, function(response) {
  9607. toaster.pop('error', '提示', response.data);
  9608. });
  9609. });
  9610. AccountEnterprise.growth({}, function (data) {
  9611. if (data != null && data.length > 0) {
  9612. var growth = [], years = [];
  9613. angular.forEach(data, function (d) {
  9614. var date = new Date(d.date), year = date.getFullYear();
  9615. d.date = (date.getMonth() + 1) + '月' + (date.getDate()) + '日';
  9616. if (years.indexOf(year) == -1) {
  9617. years.push(year);
  9618. growth.push({year: year});
  9619. }
  9620. growth.push(d);
  9621. });
  9622. $scope.growth = growth;
  9623. }
  9624. });
  9625. // 更新企业信息
  9626. $scope.updateDetailInfo = function () {
  9627. $scope.loading = true;
  9628. $scope.enterprise = $scope.copyEnterprise;
  9629. $scope.enterprise.tags = $scope.tags.join(','); // 将标签数组转换成逗号分隔的字符串,便于储存
  9630. AccountEnterprise.save($scope.enterprise, function () {
  9631. $scope.loading = false;
  9632. $scope.connectionEditing = false;
  9633. toaster.pop('success', '提示', '修改企业信息成功');
  9634. $state.reload();
  9635. }, function (response) {
  9636. $scope.loading = false;
  9637. toaster.pop('error', '修改信息失败', response.data);
  9638. });
  9639. };
  9640. // 更新企业开票信息
  9641. $scope.updateApBillOutInfo = function(uu){
  9642. $scope.loading = true;
  9643. $scope.apBillOutInfo.uu = uu;
  9644. AccountEnterprise.saveApBillOutInfo($scope.apBillOutInfo, function(){
  9645. $scope.loading = false;
  9646. $scope.apBillOutInfoEditing = false;
  9647. toaster.pop('success', '提示', '修改企业开票信息成功');
  9648. $state.reload();
  9649. }, function(response){
  9650. $scope.loading = false;
  9651. toaster.pop('error', '修改信息失败', response.data);
  9652. });
  9653. };
  9654. // 申请Saas
  9655. $scope.applySaas = function () {
  9656. if ($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  9657. var modalInstance = $modal.open({
  9658. animation: true,
  9659. templateUrl: 'static/tpl/index/account/applySaas.html',
  9660. controller: 'ApplySaasCtrl',
  9661. resolve: {
  9662. enterprise: function () {
  9663. return angular.copy($scope.enterprise);
  9664. }
  9665. }
  9666. });
  9667. modalInstance.result.then(function () {
  9668. $state.reload();
  9669. }, function () {
  9670. });
  9671. } else {
  9672. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  9673. }
  9674. };
  9675. // 获取收货地址列表
  9676. ShipAddress.shipAddList({}, function (data) {
  9677. $scope.ships = data;
  9678. });
  9679. // 判断是否是代采企业
  9680. DeputyOrder.isDeputyEnterprise({}, function (data) {
  9681. $scope.deputyEnter = data;
  9682. });
  9683. // 获取地址信息
  9684. $http.get('resources/citydata/city.json', {
  9685. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9686. }).then(function (response) {
  9687. $scope.provinces = response.data;
  9688. });
  9689. // 新增收货地址保存
  9690. $scope.saveShipAddress = function (ship) {
  9691. ship.address = ship.province + ship.city + ship.district;
  9692. ShipAddress.saveAddress({}, ship, function (data) {
  9693. if (data.success) {
  9694. ShipAddress.shipAddList({}, function (data) {
  9695. $scope.ships = data;
  9696. });
  9697. toaster.pop('success', '提示', data.success);
  9698. }
  9699. if (data.error) {
  9700. toaster.pop('error', '提示', data.error);
  9701. }
  9702. });
  9703. }
  9704. // 删除收货地址
  9705. $scope.removeShip = function (id, index) {
  9706. ShipAddress.removeShipAddress({id: id}, {}, function (data) {
  9707. $scope.ships.splice(index, 1);
  9708. toaster.pop('success', '提示', '收货地址删除成功');
  9709. }, function (response) {
  9710. toaster.pop('error', '提示', response.data);
  9711. });
  9712. };
  9713. // 编辑收货地址
  9714. $scope.editShip = function (ship) {
  9715. var modalInstance = $modal.open({
  9716. animation: true,
  9717. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  9718. controller: 'ShipAddressCtrl',
  9719. resolve: {
  9720. ship: function () {
  9721. return ship;
  9722. }
  9723. }
  9724. });
  9725. modalInstance.result.then(function () {
  9726. ShipAddress.shipAddList({}, function (data) {
  9727. $scope.ships = data;
  9728. });
  9729. }, function () {
  9730. });
  9731. };
  9732. // 新增付款企业
  9733. $scope.addPayCompany = function () {
  9734. var modalInstance = $modal.open({
  9735. animation: true,
  9736. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  9737. controller: 'PayCompanyCtrl',
  9738. resolve: {
  9739. pay: function () {
  9740. return null;
  9741. }
  9742. }
  9743. });
  9744. modalInstance.result.then(function () {
  9745. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  9746. $scope.pays = data;
  9747. // 获取付款企业信息
  9748. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  9749. $scope.pays = data;
  9750. }, function (response) {
  9751. toaster.pop('error', '提示', response.data);
  9752. });
  9753. }, function (response) {
  9754. toaster.pop('error', '提示', response.data);
  9755. });
  9756. }, function () {
  9757. });
  9758. }
  9759. // 删除付款企业
  9760. $scope.removePay = function (id, index) {
  9761. DeputyOrder.removePayCompany({id: id}, {}, function (data) {
  9762. $scope.pays.splice(index, 1);
  9763. toaster.pop('success', '提示', '付款企业信息删除成功');
  9764. }, function (response) {
  9765. toaster.pop('error', '提示', response.data);
  9766. });
  9767. };
  9768. // 编辑付款企业
  9769. $scope.editPay = function (pay, uu) {
  9770. var modalInstance = $modal.open({
  9771. animation: true,
  9772. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  9773. controller: 'PayCompanyCtrl',
  9774. resolve: {
  9775. pay: function () {
  9776. return pay;
  9777. }
  9778. }
  9779. });
  9780. modalInstance.result.then(function () {
  9781. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  9782. $scope.pays = data;
  9783. }, function (response) {
  9784. toaster.pop('error', '提示', response.data);
  9785. });
  9786. }, function () {
  9787. });
  9788. };
  9789. // 设置logo
  9790. $scope.showImageDialog = function (modal) {
  9791. require(['jquery-uploadify'], function () {
  9792. $modal.open({
  9793. templateUrl: 'static/tpl/index/home/insert.html',
  9794. controller: 'ImageInsertCtrl',
  9795. backdrop: 'static'
  9796. }).result.then(function (image) {
  9797. $scope.imageUrl = image.thumb;
  9798. User.postImageUrl(null, angular.toJson($scope.imageUrl), function (data) {
  9799. $scope.user = data;
  9800. }, function (response) {
  9801. toaster.pop('error', '设置图像失败,' + response.data);
  9802. });
  9803. });
  9804. });
  9805. }
  9806. // 添加经营范围标签
  9807. $scope.addTag = function () {
  9808. if ($scope.tags.indexOf($scope.tag) == -1){
  9809. if (null != $scope.tag && '' != $scope.tag) {
  9810. $scope.tags.push($scope.tag);
  9811. }
  9812. }
  9813. $scope.tag = '';
  9814. }
  9815. // 移除经营范围标签
  9816. $scope.removeTag = function (tag) {
  9817. removeByValue($scope.tags, tag);
  9818. }
  9819. // 获取行业信息
  9820. $http.get('static/data/profession.json').success(function (data) {
  9821. $scope.list = data;
  9822. });
  9823. // 选择行业
  9824. $scope.profession = new Array();
  9825. $scope.showProfession = false;
  9826. $scope.selectProfession = function () {
  9827. $scope.professionArray = [];
  9828. $scope.active = [];
  9829. $scope.showProfession = !$scope.showProfession;
  9830. $scope.profession[0] = $scope.list;
  9831. }
  9832. $scope.isInList = false;
  9833. $scope.isInInput = false;
  9834. $scope.hideList = function () {
  9835. if (!$scope.isInList && !$scope.isInInput && $scope.showProfession) {
  9836. $scope.showProfession = false;
  9837. }
  9838. }
  9839. // 行业子菜单点击
  9840. $scope.onItemClick = function (key, index, value) {
  9841. $scope.active[index] = key;
  9842. if (angular.isString(value)){ // 值为字符串说明点击的是最后一级
  9843. $scope.copyEnterprise.profession = value;
  9844. $scope.showProfession = false;
  9845. return;
  9846. }
  9847. $scope.professionArray = [];
  9848. $scope.profession.splice(index+1);
  9849. if (angular.isArray(value)){ // 值为数组说明下一级是最后一级
  9850. $scope.professionArray = value;
  9851. } else if (angular.isObject(value)) {
  9852. $scope.profession[index+1] = value;
  9853. }
  9854. }
  9855. // 判断值是否为字符串
  9856. $scope.isString = function (value) {
  9857. return angular.isString(value);
  9858. }
  9859. // 拷贝企业数据,在编辑企业数据是使用拷贝数据
  9860. $scope.copyData = function () {
  9861. $scope.copyEnterprise = angular.copy($scope.enterprise);
  9862. if ($scope.enterprise.tags) {
  9863. $scope.tags = $scope.enterprise.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  9864. } else {
  9865. $scope.tags = [];
  9866. }
  9867. }
  9868. }]);
  9869. // 编辑收货地址
  9870. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function ($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  9871. $scope.ship = ship;
  9872. // 获取地址信息
  9873. $http.get('resources/citydata/city.json', {
  9874. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9875. }).then(function (response) {
  9876. $scope.provinces = response.data;
  9877. });
  9878. // 新增收货地址保存
  9879. $scope.saveShipAddress = function (ship) {
  9880. ship.address = ship.province + ship.city + ship.district;
  9881. ShipAddress.saveAddress({}, ship, function (data) {
  9882. if (data.success) {
  9883. toaster.pop('success', '提示', data.success);
  9884. $modalInstance.close();
  9885. }
  9886. if (data.error) {
  9887. toaster.pop('error', '提示', data.error);
  9888. }
  9889. });
  9890. }
  9891. $scope.cancel = function () {
  9892. $modalInstance.dismiss();
  9893. }
  9894. }]);
  9895. // 编辑付款企业信息
  9896. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function ($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  9897. $scope.pay = pay;
  9898. // 获取地址信息
  9899. $http.get('resources/citydata/city.json', {
  9900. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9901. }).then(function (response) {
  9902. $scope.provinces = response.data;
  9903. });
  9904. // 新增收货地址保存
  9905. $scope.savePayCompany = function (pay) {
  9906. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  9907. DeputyOrder.savePaycompany({}, pay, function (data) {
  9908. toaster.pop('success', '提示', '保存成功');
  9909. $modalInstance.dismiss();
  9910. }, function (response) {
  9911. toaster.pop('error', '提示', response.data);
  9912. });
  9913. }
  9914. $scope.cancel = function () {
  9915. $modalInstance.dismiss();
  9916. }
  9917. }]);
  9918. // 申请Saas Controller
  9919. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function ($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http) {
  9920. $scope.enterprise = enterprise;
  9921. $scope.checking = false;
  9922. $scope.$watch('enterprise.enSaasUrl', function () {
  9923. if ($scope.enterprise.enSaasUrl) {
  9924. $http.get('signup/saasUrlEnable', {
  9925. params: {
  9926. enSaasUrl: $scope.enterprise.enSaasUrl
  9927. }
  9928. }).success(function (data) {
  9929. if (data && data == 'true') {
  9930. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  9931. } else {
  9932. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  9933. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  9934. }
  9935. }).error(function () {
  9936. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  9937. $scope.enSaasUrlErrorInfo = '验证出错';
  9938. });
  9939. } else {
  9940. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  9941. }
  9942. });
  9943. var setSaasUrl = function (url) {
  9944. var index = url.indexOf('www.');
  9945. if (index != -1) {//包含www.
  9946. var substr = url.substring(index + 4, url.length);
  9947. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  9948. } else {
  9949. $scope.enterprise.enSaasUrl = getHost(url);
  9950. }
  9951. };
  9952. // 解析获取网址的一级域名
  9953. var getHost = function (host) {
  9954. var newhost;
  9955. var domain;
  9956. var ArrDomain = new Array('.com.cn', '.net.cn', '.org.cn', '.gov.cn', '.com', '.cn', '.tel', '.mobi', '.net', '.org', '.asia', '.me', '.cc', '.name', '.info');//枚举所有后缀
  9957. for (var k in ArrDomain) {
  9958. var re = eval('/\\' + ArrDomain[k] + '$/g');
  9959. newhost = host.replace(re, '');
  9960. if (newhost != host) {
  9961. domain = ArrDomain[k];
  9962. break;
  9963. }
  9964. }
  9965. var hostar = newhost.split('.');
  9966. var s = hostar[hostar.length - 1];
  9967. return s;
  9968. };
  9969. // 设置优企云服域名为官网网址一级域名
  9970. if ($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  9971. $scope.apply = function () {
  9972. $scope.loading = true;
  9973. AccountEnterprise.applySaas({
  9974. enUU: $scope.enterprise.uu,
  9975. enSaasUrl: $scope.enterprise.enSaasUrl,
  9976. enAdminPassword: $scope.enterprise.enAdminPassword
  9977. }, {}, function () {
  9978. $scope.loading = false;
  9979. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  9980. $modalInstance.close();
  9981. }, function (response) {
  9982. $scope.loading = false;
  9983. toaster.pop('error', '申请失败', response.data);
  9984. });
  9985. };
  9986. $scope.cancel = function () {
  9987. $modalInstance.dismiss();
  9988. };
  9989. }]);
  9990. 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) {
  9991. BaseService.scrollBackToTop();
  9992. $scope.editing = false;
  9993. $scope.loading = true;
  9994. $scope.enterprise = null;
  9995. $scope.searchMthod = false;
  9996. $scope.keyword = null;
  9997. AccountUser.findDistribute({}, function (data) {
  9998. $scope.distributes = data;
  9999. }, function (response) {
  10000. toaster.pop('error', '系统错误', response.data);
  10001. });
  10002. AuthenticationService.getAuthentication().success(function (data) {
  10003. $scope.loading = false;
  10004. $scope.user = data;
  10005. });
  10006. var users = [];
  10007. var getMangagerInfo = function() {
  10008. CurrentRole.isManager({}, function(data) {
  10009. $scope.isManager = data.isManager || $scope.user.sys;
  10010. });
  10011. CurrentRole.roles({}, function(data) {
  10012. $scope.roles = data.count || $scope.user.sys;
  10013. });
  10014. };
  10015. getMangagerInfo();
  10016. $scope.tableParams = new ngTableParams({
  10017. page: 1,
  10018. count: 20,
  10019. sorting: {
  10020. userName: 'asc'
  10021. }
  10022. }, {
  10023. total: 0,
  10024. counts: [15, 25, 50, 100],
  10025. getData: function ($defer, params) {
  10026. var orderedData = params.sorting ? $filter('orderBy')(users, params.orderBy()) : users;
  10027. orderedData = params.filter ? $filter('filter')(orderedData, params.filter()) : orderedData;
  10028. $scope.users = orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
  10029. angular.forEach($scope.users, function (user) {
  10030. AccountEnterprise.get({}, function (data) {
  10031. $scope.loading = false;
  10032. $scope.enterprise = data;
  10033. });
  10034. });
  10035. params.total(orderedData.length);
  10036. $defer.resolve($scope.users);
  10037. }
  10038. });
  10039. var loadUsers = function () {
  10040. $scope.loading = true;
  10041. if($scope.searchMthod) {
  10042. AccountUser.findUsersByKeyword({keyword: $scope.keyword}, {}, function(data) {
  10043. users = data;
  10044. if(users.length > 0) {
  10045. angular.forEach(users, function (user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  10046. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  10047. $scope.user.userIdcode = user.userIdcode;
  10048. }
  10049. });
  10050. }
  10051. $scope.tableParams.reload();
  10052. $scope.loading = false;
  10053. });
  10054. } else {
  10055. AccountUser.query({}, function (data) {
  10056. users = data;
  10057. angular.forEach(users, function (user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  10058. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  10059. $scope.user.userIdcode = user.userIdcode;
  10060. }
  10061. });
  10062. $scope.tableParams.reload();
  10063. $scope.loading = false;
  10064. });
  10065. }
  10066. };
  10067. loadUsers();
  10068. $scope.onSearch = function(keyword) {
  10069. if(keyword != null && keyword != '') {
  10070. $scope.searchMthod = true;
  10071. $scope.keyword = keyword;
  10072. } else {
  10073. $scope.searchMthod = false;
  10074. }
  10075. loadUsers();
  10076. }
  10077. $scope.saveUser = function () {
  10078. $scope.loading = true;
  10079. AccountUser.update({}, $scope.user, function (data) {
  10080. $scope.loading = false;
  10081. toaster.pop('success', '提示', '修改用户信息成功');
  10082. AuthenticationService.getAuthentication().success(function (data) {
  10083. $scope.user = data;
  10084. });
  10085. loadUsers();
  10086. $scope.editing = false;
  10087. }, function (reponse) {
  10088. $scope.loading = false;
  10089. toaster.pop('error', '失败', reponse.data);
  10090. });
  10091. };
  10092. $scope.updatePassword = function () {
  10093. var modalInstance = $modal.open({
  10094. animation: true,
  10095. templateUrl: 'updatePassword.html',
  10096. controller: 'PasswordCtrl',
  10097. resolve: {
  10098. user: function () {
  10099. return $scope.user;
  10100. }
  10101. }
  10102. });
  10103. modalInstance.result.then(function () {
  10104. }, function () {
  10105. });
  10106. };
  10107. $scope.newUser = {};
  10108. //弹出添加用户模态框
  10109. $scope.addExistUser = function () {
  10110. var modalInstance = $modal.open({
  10111. animation: true,
  10112. templateUrl: 'static/tpl/index/account/addExistUser.html',
  10113. controller: 'AddExistUserCtrl'
  10114. });
  10115. modalInstance.result.then(function () {
  10116. $scope.userTelSuccess = false;
  10117. $scope.userTelError = false;
  10118. loadUsers();
  10119. }, function () {
  10120. });
  10121. };
  10122. /**
  10123. * 添加未注册用户
  10124. */
  10125. $scope.submit = false;
  10126. $scope.addUser = function () {
  10127. $scope.submit = true;
  10128. $scope.adding = true;
  10129. $scope.loading = true;
  10130. AccountUser.save({}, $scope.newUser, function (data) {
  10131. $scope.loading = false;
  10132. $scope.submit = false;
  10133. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  10134. $scope.newUser = {userSex: 'M'};
  10135. loadUsers();
  10136. $scope.adding = false;
  10137. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10138. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10139. $scope.userTelSuccess = false;
  10140. $scope.userTelError = false;
  10141. $scope.userEmailSuccess = false;
  10142. $scope.userEmailError = false;
  10143. }, function (response) {
  10144. $scope.submit = false;
  10145. $scope.loading = false;
  10146. toaster.pop('error', '错误', response.data);
  10147. });
  10148. };
  10149. /**
  10150. * 验证手机号是否可用
  10151. */
  10152. $scope.telValid = function (tel) {
  10153. if (tel) {
  10154. $http.get('account/user/telEnable', {
  10155. params: {
  10156. tel: tel
  10157. }
  10158. }).success(function (data) {
  10159. data = eval(data);
  10160. if (data == true) {
  10161. $scope.newUserForm.newUserTel.$setValidity('available', true);
  10162. $scope.userTelSuccess = true;
  10163. $scope.userTelError = false;
  10164. } else {
  10165. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10166. $scope.userTelError = true;
  10167. $scope.userTelSuccess = false;
  10168. if (tel.length == 11)
  10169. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  10170. }
  10171. }).error(function () {
  10172. $scope.userTelSuccess = false;
  10173. $scope.userTelError = true;
  10174. });
  10175. } else {
  10176. $scope.userTelSuccess = false;
  10177. $scope.userTelError = false;
  10178. }
  10179. };
  10180. /**
  10181. * 验证邮箱是否可用
  10182. */
  10183. $scope.emailValid = function (email) {
  10184. if (email) {
  10185. $http.get('account/user/emailEnable', {
  10186. params: {
  10187. email: email
  10188. }
  10189. }).success(function (data) {
  10190. data = eval(data);
  10191. if (data == true) {
  10192. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  10193. $scope.userEmailSuccess = true;
  10194. $scope.userEmailError = false;
  10195. } else {
  10196. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10197. $scope.userEmailError = true;
  10198. $scope.userEmailSuccess = false;
  10199. }
  10200. }).error(function () {
  10201. $scope.userEmailError = true;
  10202. $scope.userEmailSuccess = false;
  10203. });
  10204. } else {
  10205. $scope.userEmailError = false;
  10206. $scope.userEmailSuccess = false;
  10207. }
  10208. };
  10209. /**
  10210. * 删除用户
  10211. */
  10212. $scope.removeUser = function (user) {
  10213. new ngAlert({
  10214. title: '提示',
  10215. content: '确定删除用户(' + user.userName + ')吗?'
  10216. }, function () {
  10217. AccountUser.remove({uu: user.userUU}, function () {
  10218. toaster.pop('success', '提示', '用户删除成功。');
  10219. loadUsers();
  10220. }, function (response) {
  10221. toaster.pop('error', '删除失败', response.data);
  10222. });
  10223. });
  10224. };
  10225. // 编辑用户的角色
  10226. $scope.editUserRole = function (user) {
  10227. var modalInstance = $modal.open({
  10228. animation: true,
  10229. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  10230. controller: 'UserRoleCtrl',
  10231. resolve: {
  10232. user: function () {
  10233. return user;
  10234. }
  10235. }
  10236. });
  10237. modalInstance.result.then(function (changed, checked) {
  10238. if (changed) {
  10239. if (checked)
  10240. $scope.newUser.roles = checked;
  10241. else
  10242. loadUsers();
  10243. }
  10244. });
  10245. };
  10246. // 为用户分配角色(删除企业)
  10247. $scope.removeVendor = function (user) {
  10248. var resultRole = true;
  10249. angular.forEach(user.roles, function (role) {
  10250. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10251. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10252. resultRole = false;
  10253. return;
  10254. }
  10255. });
  10256. if (resultRole) {
  10257. var modalInstance = $modal.open({
  10258. animation: true,
  10259. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  10260. controller: 'RemoveVendorCtrl',
  10261. resolve: {
  10262. user: function () {
  10263. return user;
  10264. }
  10265. }
  10266. });
  10267. }
  10268. };
  10269. // 为用户分配角色(添加企业)
  10270. $scope.addVendor = function (user, isIssy) {
  10271. if (!$scope.roles) {
  10272. toaster.pop('error', '提示', '你不是管理员或销售经理,无权限分配!请立即联系管理员');
  10273. return;
  10274. }
  10275. var resultRole = true;
  10276. angular.forEach(user.roles, function (role) {
  10277. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10278. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10279. resultRole = false;
  10280. return;
  10281. }
  10282. })
  10283. if (resultRole) {
  10284. var modalInstance = $modal.open({
  10285. animation: true,
  10286. templateUrl: 'static/tpl/index/account/add_vendor.html',
  10287. controller: 'AddVendorCtrl',
  10288. resolve: {
  10289. user: function () {
  10290. return user;
  10291. }
  10292. }
  10293. });
  10294. modalInstance.result.then(function (changed, checked) {
  10295. if (changed) {
  10296. if (checked)
  10297. $scope.newUser.roles = checked;
  10298. else
  10299. loadUsers();
  10300. }
  10301. });
  10302. }
  10303. };
  10304. }]);
  10305. // 登录手机号码验证
  10306. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function ($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout) {
  10307. $scope.user = user;
  10308. $scope.cancel = function () {
  10309. $modalInstance.close();
  10310. }
  10311. /*$scope.loading = false;
  10312. $scope.btnState = false;
  10313. $scope.clicks = 0;
  10314. var storage = window.localStorage;
  10315. //手机验证码定时器
  10316. $scope.msgInfoError = false;
  10317. var setBtnTimeDown = function(value) {
  10318. if(value > 0) {
  10319. $scope.btnState = true;
  10320. $timeout(function() {
  10321. $scope.$apply(function(){
  10322. storage.setItem("btnTimes", $scope.btnTimes);
  10323. $scope.btnTimes --;
  10324. value --;
  10325. setBtnTimeDown (value);
  10326. });
  10327. }, 500);
  10328. }else{
  10329. $scope.btnState = false;
  10330. }
  10331. };
  10332. if(storage.btnTimes > 1){
  10333. $scope.btnTimes = storage.btnTimes;
  10334. setBtnTimeDown(storage.btnTimes)
  10335. }else{
  10336. storage.removeItem("btnTimes");
  10337. }
  10338. $scope.updateTel = function(phoneCode, userTel, uu){
  10339. $scope.loading = true;
  10340. $scope.msgInfoError = false;
  10341. $scope.result = false;
  10342. //更新联系方式
  10343. AccountUser.updateWithCode({code: phoneCode, tel : userTel, uu: uu},{}, function(data){
  10344. $scope.loading = false;
  10345. $scope.msgInfoError2 = false;
  10346. $scope.result = true;
  10347. AuthenticationService.getAuthentication().success(function(data) {
  10348. $timeout(function(){
  10349. $modalInstance.dismiss();
  10350. window.location.reload();
  10351. }, 1000);
  10352. }).error(function(response) {
  10353. });
  10354. }, function(response){
  10355. $scope.loading = false;
  10356. $scope.msgInfoError2 = response;
  10357. });
  10358. };
  10359. //获取验证码
  10360. $scope.getPhoneCode = function(userTel){
  10361. var timeInfo = 10;
  10362. $scope.clicks ++;
  10363. $scope.timeInfo = timeInfo;
  10364. if($scope.clicks >= 5){
  10365. $scope.errorloading = true;
  10366. $scope.msgInfoSuccess = false;
  10367. $scope.msgInfoError = false;
  10368. }else{
  10369. $scope.loading = true;
  10370. SendCheckMsg.sendMsgInfos({userTel: userTel},function(data){
  10371. $scope.loading = false;
  10372. $scope.msgInfoSuccess = data.success;
  10373. $scope.sendMsg = data;
  10374. $scope.btnTimes = 60;
  10375. setBtnTimeDown($scope.btnTimes);
  10376. $scope.msgInfoError = false;
  10377. },function(response){
  10378. $scope.loading = false;
  10379. $scope.msgInfoError = false;
  10380. $scope.sendCheckMsg = false;
  10381. $scope.msgInfoSuccess = true;
  10382. });
  10383. }
  10384. }; */
  10385. }]);
  10386. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10387. $scope.checkboxes = {
  10388. checked: false
  10389. };
  10390. $scope.loading = true;
  10391. AccountUser.findChooseVendor({uu: user.userUU}, function (data) {
  10392. $scope.enters = data;
  10393. $scope.loading = false;
  10394. angular.forEach($scope.enters, function (item) {
  10395. item:{
  10396. $selected:true;
  10397. }
  10398. });
  10399. })
  10400. // 点击勾选全部的复选框
  10401. $scope.checkAll = function () {
  10402. angular.forEach($scope.enters, function (item) {
  10403. item.$selected = $scope.checkboxes.checked;
  10404. });
  10405. };
  10406. // 点击其中一个明细的复选框
  10407. $scope.checkOne = function (vendor) {
  10408. var result = true;
  10409. angular.forEach($scope.enters, function (item) {
  10410. if (item.$selected != true) {
  10411. result = false;
  10412. return;
  10413. }
  10414. });
  10415. $scope.checkboxes.checked = result;
  10416. };
  10417. $scope.close = function (save) {
  10418. var chooseResult = [];
  10419. if (save) {
  10420. if (user.userUU) {
  10421. angular.forEach($scope.enters, function (item, i) {
  10422. if (item.$selected) {
  10423. chooseResult.push(item.id);
  10424. }
  10425. });
  10426. if (chooseResult.length > 0) {
  10427. $scope.loading = true;
  10428. AccountUser.removeChooseVendor({uu: user.userUU}, chooseResult, function (data) {
  10429. $scope.loading = false;
  10430. toaster.pop('success', '提示', '删除成功');
  10431. $modalInstance.close(false);
  10432. }, function (response) {
  10433. $scope.loading = false;
  10434. toaster.pop('error', '删除失败', response.data);
  10435. $modalInstance.close(false);
  10436. })
  10437. } else {
  10438. toaster.pop('error', '删除失败', "您未勾选任何记录");
  10439. }
  10440. } else {
  10441. $modalInstance.close(true, $scope.checkboxes.checked);
  10442. }
  10443. } else {
  10444. $modalInstance.close(false);
  10445. }
  10446. };
  10447. }]);
  10448. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10449. $scope.checkboxes = {
  10450. checked: false
  10451. };
  10452. $scope.loading = true;
  10453. AccountUser.findVendor({uu: user.userUU}, function (data) {
  10454. $scope.enters = data;
  10455. $scope.loading = false;
  10456. // angular.forEach($scope.enters, function(item) {
  10457. // if(item.distribute) {
  10458. // item:{
  10459. // $selected:false;
  10460. // }
  10461. // } else {
  10462. // item:{
  10463. // $selected:true;
  10464. // }
  10465. // }
  10466. // });
  10467. })
  10468. // 点击勾选全部的复选框
  10469. $scope.checkAll = function () {
  10470. angular.forEach($scope.enters, function (item) {
  10471. item.distribute = $scope.checkboxes.checked;
  10472. });
  10473. };
  10474. // 点击其中一个明细的复选框
  10475. $scope.checkOne = function (vendor) {
  10476. var result = true;
  10477. angular.forEach($scope.enters, function (item) {
  10478. if (item.distribute != true) {
  10479. result = false;
  10480. return;
  10481. }
  10482. });
  10483. $scope.checkboxes.checked = result;
  10484. };
  10485. $scope.close = function (save) {
  10486. var chooseResult = [];
  10487. if (save) {
  10488. if (user.userUU) {
  10489. angular.forEach($scope.enters, function (item, i) {
  10490. // if(item.distribute) {
  10491. chooseResult.push(item);
  10492. // }
  10493. });
  10494. if (chooseResult.length > 0) {
  10495. $scope.loading = true;
  10496. AccountUser.addVendor({uu: user.userUU}, chooseResult, function (data) {
  10497. $scope.loading = false;
  10498. toaster.pop('success', '提示', '保存成功');
  10499. $modalInstance.close(false);
  10500. }, function (response) {
  10501. $scope.loading = false;
  10502. toaster.pop('error', '保存失败', response.data);
  10503. $modalInstance.close(false);
  10504. })
  10505. } else {
  10506. toaster.pop('error', '保存失败', "您未勾选任何记录");
  10507. }
  10508. } else {
  10509. $modalInstance.close(true, $scope.checkboxes.checked);
  10510. }
  10511. } else {
  10512. $modalInstance.close(false);
  10513. }
  10514. };
  10515. }]);
  10516. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountRole, AccountUser, toaster) {
  10517. $scope.checked = [];
  10518. $scope.master = [];
  10519. AccountRole.query({}, function (data) {
  10520. if (user && data) {
  10521. var rs = [], checked = [];
  10522. angular.forEach(user.roles, function (r) {
  10523. rs.push(r.id);
  10524. });
  10525. angular.forEach(data, function (d) {
  10526. if (rs.indexOf(d.id) > -1) {
  10527. d.$checked = true;
  10528. checked.push(d);
  10529. }
  10530. });
  10531. }
  10532. $scope.roles = data;
  10533. $scope.checked = checked;
  10534. $scope.master = angular.copy($scope.checked);
  10535. });
  10536. $scope.select = function (role) {
  10537. role.$checked = !role.$checked;
  10538. if (role.$checked) {
  10539. if (role.desc === '管理员' || role.desc === '普通用户') {
  10540. $scope.checked = [];
  10541. angular.forEach($scope.roles, function (r) {
  10542. r.$checked = false;
  10543. });
  10544. role.$checked = true;
  10545. $scope.checked.push(role);
  10546. } else {
  10547. angular.forEach( $scope.checked, function (r, i) {
  10548. if (r.desc === '管理员' || r.desc === '普通用户') {
  10549. $scope.checked.splice(i, 1);
  10550. }
  10551. });
  10552. angular.forEach($scope.roles, function (r) {
  10553. if (r.desc === '管理员' || r.desc === '普通用户') {
  10554. r.$checked = false;
  10555. }
  10556. });
  10557. $scope.checked.push(role);
  10558. }
  10559. } else {
  10560. angular.forEach($scope.checked, function (c, i) {
  10561. if (c.id == role.id)
  10562. $scope.checked.splice(i, 1);
  10563. });
  10564. }
  10565. };
  10566. $scope.isChanged = function () {
  10567. return !angular.equals($scope.master, $scope.checked);
  10568. };
  10569. $scope.close = function (save) {
  10570. if (save) {
  10571. if (user.userUU) {
  10572. user.roles = $scope.checked;
  10573. AccountUser.updateRole({}, user, function () {
  10574. toaster.pop('success', '提示', '保存成功');
  10575. $modalInstance.close(true);
  10576. }, function (response) {
  10577. toaster.pop('error', '保存失败', response.data);
  10578. });
  10579. } else {
  10580. $modalInstance.close(true, $scope.checked);
  10581. }
  10582. } else {
  10583. $modalInstance.close(false);
  10584. }
  10585. };
  10586. }]);
  10587. // 修改密码Controller
  10588. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10589. $scope.user = user;
  10590. $scope.checking = false;
  10591. //输入原密码后验证原密码是否正确
  10592. $scope.checkPassword = function (password) {
  10593. $scope.checking = true;
  10594. $scope.checkSuccess = false;
  10595. $scope.checkFailed = false;
  10596. AccountUser.checkPassword({password: password}, function (data) {
  10597. $scope.checkSuccess = true;
  10598. $scope.checking = false;
  10599. $scope.checkFailed = false;
  10600. }, function (response) {
  10601. $scope.checkFailed = true;
  10602. $scope.checking = false;
  10603. $scope.checkSuccess = false;
  10604. });
  10605. };
  10606. //修改密码
  10607. $scope.ok = function () {
  10608. if ($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  10609. AccountUser.updatePassword({
  10610. password: $scope.user.password,
  10611. newPassword: $scope.user.newPassword
  10612. }, {}, function (data) {
  10613. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  10614. toaster.pop('success', '成功', tip);
  10615. $scope.user.password = null;
  10616. $scope.user.newPassword = null;
  10617. $scope.user.newPassword1 = null;
  10618. $scope.checking = false;
  10619. $scope.checkSuccess = false;
  10620. $scope.checkFailed = false;
  10621. $modalInstance.close();
  10622. }, function (response) {
  10623. toaster.pop('error', '错误', response.data);
  10624. });
  10625. } else {
  10626. toaster.pop('error', '错误', '重复密码不一致');
  10627. }
  10628. };
  10629. $scope.cancel = function () {
  10630. $modalInstance.dismiss();
  10631. };
  10632. }]);
  10633. /*
  10634. * 绑定用户到企业
  10635. */
  10636. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function ($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster) {
  10637. $scope.searching = false;
  10638. //根据输入的内容查找用户
  10639. $scope.searchUser = function (keyWord) {
  10640. $scope.searching = true;
  10641. $scope.searchSuccess = false;
  10642. $scope.searchFailed = false;
  10643. $scope.illegalError = false;
  10644. $scope.reBindError = false;
  10645. $scope.okDisabled = false;
  10646. FuzzySearch.searchUser({keyWord: keyWord}, function (data) {
  10647. $scope.searchSuccess = true;
  10648. $scope.searchFailed = false;
  10649. $scope.user = data; //查询到的用户
  10650. }, function (response) {
  10651. $scope.searchSuccess = false;
  10652. $scope.searchFailed = true;
  10653. });
  10654. };
  10655. //确认绑定
  10656. $scope.ok = function (keyWord) {
  10657. AuthenticationService.getAuthentication().success(function (data) {
  10658. $scope.currentUser = data; //当前登录的用户(管理员)
  10659. //不可自己绑定自己
  10660. if ($scope.currentUser.userUU == $scope.user.userUU) {
  10661. $scope.illegalError = true;
  10662. $scope.okDisabled = true;
  10663. return false;
  10664. }
  10665. //用户未绑定到任何企业时
  10666. if (!$scope.user.enterprises) {
  10667. //正常绑定
  10668. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  10669. $scope.okDisabled = true;
  10670. toaster.pop("success", "提示", "用户绑定成功");
  10671. $modalInstance.close(true);
  10672. }, function (response) {
  10673. });
  10674. return true;
  10675. }
  10676. //用户已绑定到某些企业时
  10677. for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
  10678. if ($scope.currentUser.enterprises[i].current) {
  10679. for (var j = 0; j < $scope.user.enterprises.length; j++) {
  10680. //该用户已绑定到当前企业,不可重复绑定
  10681. if ($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu) {
  10682. $scope.reBindError = true;
  10683. $scope.okDisabled = true;
  10684. return false;
  10685. }
  10686. }
  10687. //该用户未绑定到当前企业,可以进行绑定
  10688. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  10689. $scope.okDisabled = true;
  10690. toaster.pop("success", "提示", "用户绑定成功");
  10691. $modalInstance.close(true);
  10692. }, function (response) {
  10693. console.log("绑定失败!");
  10694. });
  10695. }
  10696. }
  10697. });
  10698. };
  10699. $scope.cancel = function () {
  10700. $modalInstance.dismiss();
  10701. };
  10702. }]);
  10703. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function ($scope, BaseService, ngTableParams, ErpLog, UsageLog) {
  10704. $scope.erpParams = new ngTableParams({
  10705. page: 1,
  10706. count: 20,
  10707. sorting: {
  10708. time: 'desc'
  10709. }
  10710. }, {
  10711. total: 0,
  10712. counts: [5, 10, 25, 50],
  10713. getData: function ($defer, params) {
  10714. $scope.loading = true;
  10715. ErpLog.get(BaseService.parseParams(params.url()), function (page) {
  10716. $scope.loading = false;
  10717. if (page) {
  10718. params.total(page.totalElements);
  10719. $defer.resolve(page.content);
  10720. }
  10721. }, function (response) {
  10722. $scope.loading = false;
  10723. toaster.pop('error', '数据加载失败', response.data);
  10724. });
  10725. }
  10726. });
  10727. $scope.usageParams = new ngTableParams({
  10728. page: 1,
  10729. count: 20,
  10730. sorting: {
  10731. time: 'desc'
  10732. }
  10733. }, {
  10734. total: 0,
  10735. counts: [5, 10, 25, 50],
  10736. getData: function ($defer, params) {
  10737. $scope.loading = true;
  10738. UsageLog.get(BaseService.parseParams(params.url()), function (page) {
  10739. $scope.loading = false;
  10740. if (page) {
  10741. params.total(page.totalElements);
  10742. $defer.resolve(page.content);
  10743. }
  10744. }, function (response) {
  10745. $scope.loading = false;
  10746. toaster.pop('error', '数据加载失败', response.data);
  10747. });
  10748. }
  10749. });
  10750. }]);
  10751. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function ($scope, AccountResource) {
  10752. AccountResource.query({}, function (data) {
  10753. if (data && data.length > 0) {
  10754. data[0].$open = true;
  10755. }
  10756. $scope.resources = data;
  10757. });
  10758. }]);
  10759. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function ($scope, $modal, AccountRole) {
  10760. $scope.roles = {};
  10761. var getData = function () {
  10762. AccountRole.query({}, function (data) {
  10763. var defaults = [], custom = [];
  10764. angular.forEach(data, function (d) {
  10765. if (d.isdefault == 1)
  10766. defaults.push(d);
  10767. else
  10768. custom.push(d);
  10769. });
  10770. $scope.roles = {defaults: defaults, custom: custom};
  10771. });
  10772. };
  10773. getData();
  10774. $scope.editRole = function (role) {
  10775. var modalInstance = $modal.open({
  10776. animation: true,
  10777. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  10778. controller: 'RoleEditCtrl',
  10779. resolve: {
  10780. role: function () {
  10781. return role;
  10782. }
  10783. }
  10784. });
  10785. modalInstance.result.then(function (added) {
  10786. added && (getData());
  10787. });
  10788. };
  10789. }]);
  10790. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', 'CurrentRole', function ($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService, CurrentRole) {
  10791. BaseService.scrollBackToTop();
  10792. // 获取当前用户是否为管理员
  10793. CurrentRole.isManager({}, {}, function (data) {
  10794. $scope.isManager = data.isManager || $scope.user.sys;
  10795. });
  10796. $scope.role = role;
  10797. $scope.master = angular.copy($scope.role);
  10798. var isNew = role == null;
  10799. $scope.cancel = function () {
  10800. $modalInstance.close(false);
  10801. };
  10802. AccountResource.query({}, function (data) {
  10803. if (data && data.length > 0) {
  10804. if (role && role.resourceItems) {
  10805. var rs = [];// 已分配的资源的id
  10806. angular.forEach(role.resourceItems, function (item) {
  10807. rs.push(item.id);
  10808. });
  10809. angular.forEach(data, function (resource) {
  10810. var c = 0;
  10811. angular.forEach(resource.items, function (item) {
  10812. if (rs.indexOf(item.id) > -1) {
  10813. item.$checked = true;
  10814. c += 1;
  10815. }
  10816. });
  10817. resource.$checked = c == resource.items.length;
  10818. });
  10819. }
  10820. $scope.resourceItems = data[0].items;
  10821. data[0].$active = true;
  10822. }
  10823. $scope.resources = data;
  10824. $timeout(function () {
  10825. angular.forEach($scope.resources, function (resource) {
  10826. var c = 0;
  10827. angular.forEach(resource.items, function (item) {
  10828. item.$checked && (c += 1);
  10829. });
  10830. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  10831. });
  10832. }, 100);
  10833. });
  10834. $scope.onItemClick = function (resource) {
  10835. $scope.resourceItems = resource.items;
  10836. angular.forEach($scope.resources, function (r) {
  10837. r.$active = false;
  10838. });
  10839. resource.$active = true;
  10840. };
  10841. var getChecked = function () {
  10842. var items = [];
  10843. angular.forEach($scope.resources, function (resource) {
  10844. angular.forEach(resource.items, function (item) {
  10845. item.$checked && (items.push(item));
  10846. });
  10847. });
  10848. $scope.role.resourceItems = items;
  10849. };
  10850. $scope.onResourceChange = function (resource) {
  10851. angular.forEach(resource.items, function (item) {
  10852. item.$checked = resource.$checked;
  10853. });
  10854. getChecked();
  10855. };
  10856. $scope.onItemChange = function () {
  10857. angular.forEach($scope.resources, function (resource) {
  10858. if (resource.$active) {
  10859. var c = 0;
  10860. angular.forEach(resource.items, function (item) {
  10861. item.$checked && (c += 1);
  10862. });
  10863. resource.$checked = (c == resource.items.length);
  10864. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  10865. }
  10866. });
  10867. getChecked();
  10868. };
  10869. $scope.isChanged = function (formData) {
  10870. if (!$scope.master)
  10871. return true;
  10872. return !angular.equals(formData, $scope.master);
  10873. };
  10874. $scope.save = function () {
  10875. $scope.master = angular.copy($scope.role);
  10876. AccountRole.save($scope.master, function () {
  10877. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
  10878. $modalInstance.close(true);
  10879. }, function (response) {
  10880. toaster.pop('error', '错误', response.data);
  10881. });
  10882. };
  10883. $scope.del = function () {
  10884. new ngAlert({
  10885. title: '提示',
  10886. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  10887. }, function () {
  10888. AccountRole.remove({id: role.id}, {}, function () {
  10889. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  10890. $modalInstance.close(true);
  10891. }, function (response) {
  10892. toaster.pop('error', '错误', response.data);
  10893. });
  10894. })
  10895. };
  10896. $scope.updateDefault = function () {
  10897. new ngAlert({
  10898. title: '提示',
  10899. content: '确定把(' + $scope.role.desc + ')信息更新到标准库吗?'
  10900. }, function () {
  10901. AccountRole.updateDefault({desc: $scope.role.desc}, $scope.role.resourceItems, function () {
  10902. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 更新成功');
  10903. $modalInstance.close(true);
  10904. }, function (response) {
  10905. toaster.pop('error', '错误', response.data);
  10906. });
  10907. })
  10908. }
  10909. $scope.recover = function () {
  10910. new ngAlert({
  10911. title: '提示',
  10912. content: '确定将“' + $scope.role.desc + '”恢复默认权限吗?'
  10913. }, function () {
  10914. AccountRole.recover({roleId: role.id}, {}, function () {
  10915. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 恢复默认权限成功');
  10916. $modalInstance.close(true);
  10917. }, function (response) {
  10918. toaster.pop('error', '错误', response.data);
  10919. });
  10920. })
  10921. };
  10922. }]);
  10923. /**
  10924. * 委外订单
  10925. */
  10926. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole',
  10927. function ($scope, $filter, MakeOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  10928. BaseService.scrollBackToTop();
  10929. // 获取当前用户是否为普通用户
  10930. CurrentRole.isUser({}, {}, function (data) {
  10931. $scope.isUser = data.isUser;
  10932. });
  10933. $scope.active = 'todo';
  10934. $scope.dateZoneText = '不限';
  10935. $scope.condition = {dateZone: 1};
  10936. /* 时间筛选初始化*/
  10937. var fromDate = new Date();
  10938. var toDate = new Date();
  10939. fromDate.setMonth(fromDate.getMonth() - 1);
  10940. fromDate.setHours(0, 0, 0, 0);
  10941. toDate.setHours(23, 59, 59, 999);
  10942. $scope.condition.dateFrom = fromDate;
  10943. $scope.condition.dateTo = toDate;
  10944. $scope.changeDateZone = function (zone) {
  10945. $scope.condition.dateZone = zone;
  10946. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  10947. $scope.condition.$dateZoneOpen = false;
  10948. getDateCondition(zone, $scope.condition);
  10949. $scope.tableParams.page(1);
  10950. $scope.tableParams.reload();
  10951. };
  10952. $scope.setActive = function (state) {
  10953. if ($scope.active != state) {
  10954. $scope.active = state;
  10955. if ($scope.tableParams.page() == 1)
  10956. $scope.tableParams.reload();
  10957. else
  10958. $scope.tableParams.page(1);
  10959. }
  10960. };
  10961. var getService = function () {
  10962. return MakeOrder;
  10963. };
  10964. $scope.tableParams = new ngTableParams({
  10965. page: 1,
  10966. count: 20,
  10967. sorting: {
  10968. date: 'desc'
  10969. }
  10970. }, {
  10971. total: 0,
  10972. counts: [5, 10, 25, 50],
  10973. getData: function ($defer, params) {
  10974. $scope.loading = true;
  10975. var pageParams = params.url();
  10976. pageParams.searchFilter = {
  10977. keyword: $scope.keyword,
  10978. fromDate: getDateTime($scope.condition.dateFrom),
  10979. endDate: getDateTime($scope.condition.dateTo)
  10980. };
  10981. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  10982. $scope.loading = false;
  10983. if (page) {
  10984. params.total(page.totalElement);
  10985. $defer.resolve(page.content);
  10986. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  10987. }
  10988. }, function (response) {
  10989. $scope.loading = false;
  10990. toaster.pop('error', '数据加载失败', response.data);
  10991. });
  10992. }
  10993. });
  10994. //获得各分类未阅读数量
  10995. var getUnreadCount = function () {
  10996. MakeOrder.getUnreadCount(null, function (data) {
  10997. $scope.unread = data;
  10998. });
  10999. };
  11000. getUnreadCount();
  11001. //设置单据已读
  11002. $scope.setOrdersRead = function (id) {
  11003. // 如果单据本身已读,则不发送请求修改数据
  11004. if (!$scope.isUnread(id)){
  11005. return;
  11006. }
  11007. var sourceId = [];
  11008. sourceId.push(id);
  11009. MakeOrder.setRead({}, sourceId, function (message) {
  11010. // $scope.getUnreadIds();
  11011. getUnreadCount();
  11012. });
  11013. };
  11014. $scope.setOrdersReadByState = function () {
  11015. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  11016. return;
  11017. }
  11018. MakeOrder.setReadByState({}, function () {
  11019. getUnreadIds();
  11020. getUnreadCount();
  11021. });
  11022. };
  11023. var getUnreadIds = function () {
  11024. MakeOrder.getUnreadIds({}, "", function (message) {
  11025. $scope.unreadCode = message.content;
  11026. });
  11027. };
  11028. getUnreadIds();
  11029. $scope.isUnread = function (id) {
  11030. for (var i in $scope.unreadCode) {
  11031. if (id == $scope.unreadCode[i]) {
  11032. return true;
  11033. }
  11034. }
  11035. };
  11036. $scope.getOrderTotal = function (items) {
  11037. var sum = 0;
  11038. angular.forEach(items, function (item) {
  11039. sum += item.qty * item.price;
  11040. });
  11041. return sum;
  11042. };
  11043. $scope.openDatePicker = function ($event, item, openParam) {
  11044. $event.preventDefault();
  11045. $event.stopPropagation();
  11046. item[openParam] = !item[openParam];
  11047. };
  11048. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11049. $event.preventDefault();
  11050. $event.stopPropagation();
  11051. item[openParam] = !item[openParam];
  11052. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11053. $scope.tableParams.reload();
  11054. }
  11055. };
  11056. $scope.parseDate = function (dateStr) {
  11057. if (dateStr)
  11058. return Date.parse(dateStr, 'yyyy-MM-dd');
  11059. return new Date();
  11060. };
  11061. // 打开回复
  11062. $scope.openReply = function (order) {
  11063. if (!order.reply) {
  11064. order.reply = {
  11065. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11066. delivery: order.delivery
  11067. }
  11068. }
  11069. order.$editing = true;
  11070. };
  11071. // 关闭回复
  11072. $scope.closeReply = function (order) {
  11073. order.$editing = false;
  11074. }
  11075. // 搜索框回车
  11076. $scope.onSearch = function () {
  11077. $scope.tableParams.page(1);
  11078. $scope.tableParams.reload();
  11079. };
  11080. // 选择查找日期
  11081. $scope.onDateCondition = function () {
  11082. $scope.tableParams.page(1);
  11083. $scope.tableParams.reload();
  11084. };
  11085. // 点击回复
  11086. $scope.onReplyClick = function (order, inverse) {
  11087. if (order.reply) {
  11088. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11089. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11090. return;
  11091. }
  11092. var reply = angular.copy(order.reply);
  11093. if (reply.delivery) {
  11094. if (typeof reply.delivery == 'object')
  11095. reply.delivery = reply.delivery.getTime();
  11096. } else {
  11097. reply.delivery = order.delivery;
  11098. }
  11099. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11100. $scope.loading = true;
  11101. MakeOrder.reply({orderId: order.id}, reply, function () {
  11102. $scope.loading = false;
  11103. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11104. $scope.tableParams.reload();
  11105. }, function (response) {
  11106. $scope.loading = false;
  11107. toaster.pop('error', '回复失败', response.data);
  11108. });
  11109. }
  11110. };
  11111. //委外加工单
  11112. $scope.print = function (order) {
  11113. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11114. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  11115. };
  11116. // 获取回复记录
  11117. $scope.getReply = function (order) {
  11118. if (!order.replies) {
  11119. MakeOrder.getReply({orderId: order.id}, function (replies) {
  11120. order.replies = replies;
  11121. });
  11122. }
  11123. };
  11124. // 导出
  11125. $scope.exportXls = function () {
  11126. MakeOrder.exportXls({}, {}, function (data) {
  11127. if (data.success){
  11128. window.location.href = 'make/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11129. }
  11130. }, function (response) {
  11131. toaster.pop('error', '数据加载失败', response.data);
  11132. });
  11133. }
  11134. }]);
  11135. /**
  11136. * 委外加工单详细
  11137. */
  11138. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService, CurrentRole) {
  11139. BaseService.scrollBackToTop();
  11140. // 获取当前用户是否为普通用户
  11141. CurrentRole.isUser({}, {}, function (data) {
  11142. $scope.isUser = data.isUser;
  11143. });
  11144. var loadData = function () {
  11145. MakeOrder.getItem({id: $stateParams.id}, function (data) {
  11146. $scope.order = data;
  11147. var sum = $scope.order.qty * $scope.order.price;
  11148. $scope.order.total = sum;
  11149. $scope.loading = false;
  11150. }, function (response) {
  11151. toaster.pop('error', '', response.data);
  11152. });
  11153. };
  11154. loadData();
  11155. // 获取回复记录
  11156. $scope.getReply = function (item) {
  11157. if (!item.replies) {
  11158. MakeOrder.getReply({orderId: item.id}, function (replies) {
  11159. item.replies = replies;
  11160. });
  11161. }
  11162. };
  11163. $scope.openDatePicker = function ($event, item, openParam) {
  11164. $event.preventDefault();
  11165. $event.stopPropagation();
  11166. item[openParam] = !item[openParam];
  11167. };
  11168. // 点击回复
  11169. $scope.onReplyClick = function (order, inverse) {
  11170. if (order.reply) {
  11171. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11172. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11173. return;
  11174. }
  11175. var reply = angular.copy(order.reply);
  11176. if (reply.delivery) {
  11177. if (typeof reply.delivery == 'object')
  11178. reply.delivery = reply.delivery.getTime();
  11179. } else {
  11180. reply.delivery = order.delivery;
  11181. }
  11182. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11183. $scope.loading = true;
  11184. MakeOrder.reply({orderId: order.id}, reply, function () {
  11185. $scope.loading = false;
  11186. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11187. loadData();
  11188. }, function (response) {
  11189. $scope.loading = false;
  11190. toaster.pop('error', '回复失败', response.data);
  11191. });
  11192. }
  11193. };
  11194. // 打开回复
  11195. $scope.openReply = function (order) {
  11196. if (!order.reply) {
  11197. order.reply = {
  11198. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11199. delivery: order.delivery
  11200. }
  11201. }
  11202. order.$editing = true;
  11203. };
  11204. // 关闭回复
  11205. $scope.closeReply = function (order) {
  11206. order.$editing = false;
  11207. }
  11208. // 委外订单
  11209. $scope.print = function (order) {
  11210. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11211. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  11212. };
  11213. }]);
  11214. /**
  11215. * 客户委外验收
  11216. */
  11217. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11218. BaseService.scrollBackToTop();
  11219. // 获取当前用户是否为普通用户
  11220. CurrentRole.isUser({}, {}, function (data) {
  11221. $scope.isUser = data.isUser;
  11222. });
  11223. $scope.active = 'all';
  11224. $scope.agreedText = '全部';
  11225. $scope.dateZoneText = '一个月内';
  11226. $scope.condition = {dateZone: 1};
  11227. /* 时间筛选初始化*/
  11228. var fromDate = new Date();
  11229. var toDate = new Date();
  11230. fromDate.setMonth(fromDate.getMonth() - 1);
  11231. fromDate.setHours(0, 0, 0, 0);
  11232. toDate.setHours(23, 59, 59, 999);
  11233. $scope.condition.dateFrom = fromDate;
  11234. $scope.condition.dateTo = toDate;
  11235. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11236. $scope.changeAgreed = function (agreed) {
  11237. $scope.condition.agreed = agreed;
  11238. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11239. $scope.condition.$agreedOpen = false;
  11240. };
  11241. $scope.changeDateZone = function (zone) {
  11242. $scope.condition.dateZone = zone;
  11243. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11244. $scope.condition.$dateZoneOpen = false;
  11245. getDateCondition(zone, $scope.condition);
  11246. $scope.tableParams.page(1);
  11247. $scope.tableParams.reload();
  11248. };
  11249. $scope.setActive = function (state) {
  11250. if ($scope.active != state) {
  11251. $scope.active = state;
  11252. if ($scope.tableParams.page() == 1)
  11253. $scope.tableParams.reload();
  11254. else
  11255. $scope.tableParams.page(1);
  11256. }
  11257. };
  11258. var getService = function () {
  11259. return MakeAccept;
  11260. };
  11261. $scope.tableParams = new ngTableParams({
  11262. page: 1,
  11263. count: 20,
  11264. sorting: {
  11265. date: 'desc'
  11266. }
  11267. }, {
  11268. total: 0,
  11269. counts: [5, 10, 25, 50],
  11270. getData: function ($defer, params) {
  11271. $scope.loading = true;
  11272. var pageParams = params.url();
  11273. pageParams.searchFilter = {};
  11274. pageParams.searchFilter.keyword = $scope.keyword;
  11275. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11276. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11277. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11278. $scope.loading = false;
  11279. if (page) {
  11280. params.total(page.totalElement);
  11281. $defer.resolve(page.content);
  11282. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11283. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11284. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11285. }
  11286. }, function (response) {
  11287. $scope.loading = false;
  11288. toaster.pop('error', '数据加载失败', response.data);
  11289. });
  11290. }
  11291. });
  11292. $scope.openDatePicker = function ($event, item, openParam) {
  11293. $event.preventDefault();
  11294. $event.stopPropagation();
  11295. item[openParam] = !item[openParam];
  11296. };
  11297. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11298. $event.preventDefault();
  11299. $event.stopPropagation();
  11300. item[openParam] = !item[openParam];
  11301. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11302. $scope.tableParams.reload();
  11303. }
  11304. };
  11305. // 搜索框回车
  11306. $scope.onSearch = function () {
  11307. $scope.tableParams.page(1);
  11308. $scope.tableParams.reload();
  11309. };
  11310. // 选择查找日期
  11311. $scope.onDateCondition = function () {
  11312. $scope.tableParams.page(1);
  11313. $scope.tableParams.reload();
  11314. };
  11315. // 导出
  11316. $scope.exportXls = function () {
  11317. MakeAccept.exportXls({}, {}, function (data) {
  11318. if (data.success){
  11319. window.location.href = 'make/accept/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11320. }
  11321. }, function (response) {
  11322. toaster.pop('error', '数据加载失败', response.data);
  11323. });
  11324. }
  11325. }]);
  11326. /**
  11327. * 客户委外验退
  11328. */
  11329. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11330. BaseService.scrollBackToTop();
  11331. // 获取当前用户是否为普通用户
  11332. CurrentRole.isUser({}, {}, function (data) {
  11333. $scope.isUser = data.isUser;
  11334. });
  11335. $scope.active = 'all';
  11336. $scope.agreedText = '全部';
  11337. $scope.dateZoneText = '一个月内';
  11338. $scope.condition = {dateZone: 1};
  11339. /* 时间筛选初始化*/
  11340. var fromDate = new Date();
  11341. var toDate = new Date();
  11342. fromDate.setMonth(fromDate.getMonth() - 1);
  11343. fromDate.setHours(0, 0, 0, 0);
  11344. toDate.setHours(23, 59, 59, 999);
  11345. $scope.condition.dateFrom = fromDate;
  11346. $scope.condition.dateTo = toDate;
  11347. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11348. $scope.changeAgreed = function (agreed) {
  11349. $scope.condition.agreed = agreed;
  11350. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11351. $scope.condition.$agreedOpen = false;
  11352. };
  11353. $scope.changeDateZone = function (zone) {
  11354. $scope.condition.dateZone = zone;
  11355. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11356. $scope.condition.$dateZoneOpen = false;
  11357. getDateCondition(zone, $scope.condition);
  11358. $scope.tableParams.page(1);
  11359. $scope.tableParams.reload();
  11360. };
  11361. $scope.setActive = function (state) {
  11362. if ($scope.active != state) {
  11363. $scope.active = state;
  11364. if ($scope.tableParams.page() == 1)
  11365. $scope.tableParams.reload();
  11366. else
  11367. $scope.tableParams.page(1);
  11368. }
  11369. };
  11370. var getService = function () {
  11371. return MakeReturn;
  11372. };
  11373. $scope.tableParams = new ngTableParams({
  11374. page: 1,
  11375. count: 20,
  11376. sorting: {
  11377. date: 'desc'
  11378. }
  11379. }, {
  11380. total: 0,
  11381. counts: [5, 10, 25, 50],
  11382. getData: function ($defer, params) {
  11383. $scope.loading = true;
  11384. var pageParams = params.url();
  11385. pageParams.searchFilter = {};
  11386. pageParams.searchFilter.keyword = $scope.keyword;
  11387. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11388. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11389. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11390. $scope.loading = false;
  11391. if (page) {
  11392. params.total(page.totalElement);
  11393. $defer.resolve(page.content);
  11394. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11395. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11396. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11397. }
  11398. }, function (response) {
  11399. $scope.loading = false;
  11400. toaster.pop('error', '数据加载失败', response.data);
  11401. });
  11402. }
  11403. });
  11404. $scope.openDatePicker = function ($event, item, openParam) {
  11405. $event.preventDefault();
  11406. $event.stopPropagation();
  11407. item[openParam] = !item[openParam];
  11408. };
  11409. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11410. $event.preventDefault();
  11411. $event.stopPropagation();
  11412. item[openParam] = !item[openParam];
  11413. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11414. $scope.tableParams.reload();
  11415. }
  11416. };
  11417. // 搜索框回车
  11418. $scope.onSearch = function () {
  11419. $scope.tableParams.page(1);
  11420. $scope.tableParams.reload();
  11421. };
  11422. // 选择查找日期
  11423. $scope.onDateCondition = function () {
  11424. $scope.tableParams.page(1);
  11425. $scope.tableParams.reload();
  11426. };
  11427. // 导出
  11428. $scope.exportXls = function () {
  11429. MakeReturn.exportXls({}, {}, function (data) {
  11430. if (data.success){
  11431. window.location.href = 'make/return/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11432. }
  11433. }, function (response) {
  11434. toaster.pop('error', '数据加载失败', response.data);
  11435. });
  11436. }
  11437. }]);
  11438. /**
  11439. * 委外加工变更
  11440. */
  11441. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeChange, ngTableParams, toaster, BaseService, CurrentRole) {
  11442. BaseService.scrollBackToTop();
  11443. // 获取当前用户是否为普通用户
  11444. CurrentRole.isUser({}, {}, function (data) {
  11445. $scope.isUser = data.isUser;
  11446. });
  11447. $scope.active = 'all';
  11448. $scope.agreedText = '全部';
  11449. $scope.dateZoneText = '一个月内';
  11450. $scope.condition = {dateZone: 1};
  11451. /* 时间筛选初始化*/
  11452. var fromDate = new Date();
  11453. var toDate = new Date();
  11454. fromDate.setMonth(fromDate.getMonth() - 1);
  11455. fromDate.setHours(0, 0, 0, 0);
  11456. toDate.setHours(23, 59, 59, 999);
  11457. $scope.condition.dateFrom = fromDate;
  11458. $scope.condition.dateTo = toDate;
  11459. $scope.changeAgreed = function (agreed) {
  11460. $scope.condition.agreed = agreed;
  11461. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11462. $scope.condition.$agreedOpen = false;
  11463. };
  11464. $scope.changeDateZone = function (zone) {
  11465. $scope.condition.dateZone = zone;
  11466. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11467. $scope.condition.$dateZoneOpen = false;
  11468. getDateCondition(zone, $scope.condition);
  11469. $scope.tableParams.page(1);
  11470. $scope.tableParams.reload();
  11471. };
  11472. $scope.setActive = function (state) {
  11473. if ($scope.active != state) {
  11474. $scope.active = state;
  11475. if ($scope.tableParams.page() == 1)
  11476. $scope.tableParams.reload();
  11477. else
  11478. $scope.tableParams.page(1);
  11479. }
  11480. };
  11481. var getService = function () {
  11482. return MakeChange;
  11483. };
  11484. $scope.tableParams = new ngTableParams({
  11485. page: 1,
  11486. count: 20,
  11487. sorting: {
  11488. orderChangeDate: 'desc'
  11489. }
  11490. }, {
  11491. total: 0,
  11492. counts: [5, 10, 25, 50],
  11493. getData: function ($defer, params) {
  11494. $scope.loading = true;
  11495. var pageParams = params.url();
  11496. pageParams.searchFilter = {
  11497. keyword: $scope.keyword,
  11498. fromDate: getDateTime($scope.condition.dateFrom),
  11499. endDate: getDateTime($scope.condition.dateTo)
  11500. };
  11501. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11502. $scope.loading = false;
  11503. if (page) {
  11504. params.total(page.totalElement);
  11505. $defer.resolve(page.content);
  11506. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11507. }
  11508. }, function (response) {
  11509. $scope.loading = false;
  11510. toaster.pop('error', '数据加载失败', response.data);
  11511. });
  11512. }
  11513. });
  11514. $scope.openDatePicker = function ($event, item, openParam) {
  11515. $event.preventDefault();
  11516. $event.stopPropagation();
  11517. item[openParam] = !item[openParam];
  11518. };
  11519. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11520. $event.preventDefault();
  11521. $event.stopPropagation();
  11522. item[openParam] = !item[openParam];
  11523. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11524. $scope.tableParams.reload();
  11525. }
  11526. };
  11527. // 打开回复
  11528. $scope.openReply = function (change) {
  11529. change.$editing = true;
  11530. };
  11531. // 关闭回复
  11532. $scope.closeReply = function (change) {
  11533. change.$editing = false;
  11534. }
  11535. // 确定回复
  11536. $scope.onReplyClick = function (change) {
  11537. if (change.$agreed) {
  11538. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11539. $scope.loading = true;
  11540. MakeChange.reply({itemId: change.id}, reply, function () {
  11541. $scope.loading = false;
  11542. toaster.pop('info', '提示', '回复成功');
  11543. $scope.tableParams.reload();
  11544. }, function (response) {
  11545. $scope.loading = false;
  11546. toaster.pop('error', '回复失败', response.data);
  11547. });
  11548. }
  11549. };
  11550. // 搜索框回车
  11551. $scope.onSearch = function () {
  11552. $scope.tableParams.page(1);
  11553. $scope.tableParams.reload();
  11554. };
  11555. // 选择查找日期
  11556. $scope.onDateCondition = function () {
  11557. $scope.tableParams.page(1);
  11558. $scope.tableParams.reload();
  11559. };
  11560. // 导出
  11561. $scope.exportXls = function () {
  11562. MakeChange.exportXls({}, {}, function (data) {
  11563. if (data.success){
  11564. window.location.href = 'make/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11565. }
  11566. }, function (response) {
  11567. toaster.pop('error', '数据加载失败', response.data);
  11568. });
  11569. }
  11570. }]);
  11571. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeChange, toaster, BaseService, CurrentRole) {
  11572. BaseService.scrollBackToTop();
  11573. CurrentRole.isUser({}, {}, function (data) {
  11574. $scope.isUser = data.isUser;
  11575. });
  11576. var loadData = function () {
  11577. MakeChange.getItem({id: $stateParams.id}, function (data) {
  11578. $scope.change = data;
  11579. }, function (response) {
  11580. toaster.pop('error', '数据加载失败', response.data);
  11581. });
  11582. };
  11583. loadData();
  11584. $scope.openDatePicker = function ($event, item, openParam) {
  11585. $event.preventDefault();
  11586. $event.stopPropagation();
  11587. item[openParam] = !item[openParam];
  11588. };
  11589. $scope.onReplyClick = function (change) {
  11590. if (change.$agreed) {
  11591. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11592. MakeChange.reply({itemId: change.id}, reply, function () {
  11593. toaster.pop('info', '提示', '回复成功');
  11594. loadData();
  11595. }, function (response) {
  11596. toaster.pop('error', '回复失败', response.data);
  11597. });
  11598. }
  11599. };
  11600. }]);
  11601. /**
  11602. * 委外加工
  11603. */
  11604. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeOutOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  11605. BaseService.scrollBackToTop();
  11606. // 获取当前用户是否为普通用户
  11607. CurrentRole.isUser({}, {}, function (data) {
  11608. $scope.isUser = data.isUser;
  11609. });
  11610. $scope.active = 'all';
  11611. $scope.agreedText = '全部';
  11612. $scope.dateZoneText = '一个月内';
  11613. $scope.condition = {dateZone: 1};
  11614. /* 时间筛选初始化*/
  11615. var fromDate = new Date();
  11616. var toDate = new Date();
  11617. fromDate.setMonth(fromDate.getMonth() - 1);
  11618. fromDate.setHours(0, 0, 0, 0);
  11619. toDate.setHours(23, 59, 59, 999);
  11620. $scope.condition.dateFrom = fromDate;
  11621. $scope.condition.dateTo = toDate;
  11622. $scope.changeAgreed = function (agreed) {
  11623. $scope.condition.agreed = agreed;
  11624. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11625. $scope.condition.$agreedOpen = false;
  11626. };
  11627. $scope.changeDateZone = function (zone) {
  11628. $scope.condition.dateZone = zone;
  11629. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11630. $scope.condition.$dateZoneOpen = false;
  11631. getDateCondition(zone, $scope.condition);
  11632. $scope.tableParams.page(1);
  11633. $scope.tableParams.reload();
  11634. };
  11635. $scope.setActive = function (state) {
  11636. if ($scope.active != state) {
  11637. $scope.active = state;
  11638. if ($scope.tableParams.page() == 1)
  11639. $scope.tableParams.reload();
  11640. else
  11641. $scope.tableParams.page(1);
  11642. }
  11643. };
  11644. var getService = function () {
  11645. return MakeOutOrder;
  11646. };
  11647. $scope.tableParams = new ngTableParams({
  11648. page: 1,
  11649. count: 20,
  11650. sorting: {
  11651. date: 'desc'
  11652. }
  11653. }, {
  11654. total: 0,
  11655. counts: [5, 10, 25, 50],
  11656. getData: function ($defer, params) {
  11657. $scope.loading = true;
  11658. var pageParams = params.url();
  11659. pageParams.searchFilter = {};
  11660. pageParams.searchFilter.keyword = $scope.keyword;
  11661. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11662. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11663. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11664. $scope.loading = false;
  11665. if (page) {
  11666. params.total(page.totalElement);
  11667. $defer.resolve(page.content);
  11668. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11669. }
  11670. }, function (response) {
  11671. $scope.loading = false;
  11672. toaster.pop('error', '数据加载失败', response.data);
  11673. });
  11674. }
  11675. });
  11676. $scope.openDatePicker = function ($event, item, openParam) {
  11677. $event.preventDefault();
  11678. $event.stopPropagation();
  11679. item[openParam] = !item[openParam];
  11680. };
  11681. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11682. $event.preventDefault();
  11683. $event.stopPropagation();
  11684. item[openParam] = !item[openParam];
  11685. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11686. $scope.tableParams.reload();
  11687. }
  11688. };
  11689. // 打开回复
  11690. $scope.openReply = function (change) {
  11691. change.$editing = true;
  11692. };
  11693. // 关闭回复
  11694. $scope.closeReply = function (change) {
  11695. change.$editing = false;
  11696. }
  11697. // 确定回复
  11698. $scope.onReplyClick = function (change) {
  11699. if (change.$agreed) {
  11700. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11701. $scope.loading = true;
  11702. MakeOutOrder.reply({itemId: change.id}, reply, function () {
  11703. $scope.loading = false;
  11704. toaster.pop('info', '提示', '回复成功');
  11705. $scope.tableParams.reload();
  11706. }, function (response) {
  11707. $scope.loading = false;
  11708. toaster.pop('error', '回复失败', response.data);
  11709. });
  11710. }
  11711. };
  11712. // 搜索框回车
  11713. $scope.onSearch = function () {
  11714. $scope.tableParams.page(1);
  11715. $scope.tableParams.reload();
  11716. };
  11717. // 选择查找日期
  11718. $scope.onDateCondition = function () {
  11719. $scope.tableParams.page(1);
  11720. $scope.tableParams.reload();
  11721. };
  11722. // 导出
  11723. $scope.exportXls = function () {
  11724. MakeOutOrder.exportXls({}, {}, function (data) {
  11725. if (data.success){
  11726. window.location.href = 'make/outorders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11727. }
  11728. }, function (response) {
  11729. toaster.pop('error', '数据加载失败', response.data);
  11730. });
  11731. }
  11732. }]);
  11733. /**
  11734. * 委外加工详细
  11735. */
  11736. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService, CurrentRole) {
  11737. BaseService.scrollBackToTop();
  11738. // 获取当前用户是否为普通用户
  11739. CurrentRole.isUser({}, {}, function (data) {
  11740. $scope.isUser = data.isUser;
  11741. });
  11742. var loadData = function () {
  11743. MakeOutOrder.getItem({id: $stateParams.id}, function (data) {
  11744. $scope.order = data;
  11745. var sum = $scope.order.qty * $scope.order.price;
  11746. $scope.order.total = sum;
  11747. $scope.loading = false;
  11748. });
  11749. };
  11750. loadData();
  11751. // 获取回复记录
  11752. $scope.getReply = function (item) {
  11753. if (!item.replies) {
  11754. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  11755. item.replies = replies;
  11756. });
  11757. }
  11758. };
  11759. $scope.openDatePicker = function ($event, item, openParam) {
  11760. $event.preventDefault();
  11761. $event.stopPropagation();
  11762. item[openParam] = !item[openParam];
  11763. };
  11764. // 点击回复
  11765. $scope.onReplyClick = function (order, inverse) {
  11766. if (order.reply) {
  11767. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11768. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11769. return;
  11770. }
  11771. var reply = angular.copy(order.reply);
  11772. if (reply.delivery) {
  11773. if (typeof reply.delivery == 'object')
  11774. reply.delivery = reply.delivery.getTime();
  11775. } else {
  11776. reply.delivery = order.delivery;
  11777. }
  11778. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11779. $scope.loading = true;
  11780. MakeOutOrder.reply({orderId: order.id}, reply, function () {
  11781. $scope.loading = false;
  11782. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11783. loadData();
  11784. }, function (response) {
  11785. $scope.loading = false;
  11786. toaster.pop('error', '回复失败', response.data);
  11787. });
  11788. }
  11789. };
  11790. // 打开回复
  11791. $scope.openReply = function (order) {
  11792. if (!order.reply) {
  11793. order.reply = {
  11794. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11795. delivery: order.delivery
  11796. }
  11797. }
  11798. order.$editing = true;
  11799. };
  11800. // 关闭回复
  11801. $scope.closeReply = function (order) {
  11802. order.$editing = false;
  11803. }
  11804. // 自己委外加工订单
  11805. $scope.print = function (order) {
  11806. MakeOutOrder.printCount({id: order.id}, {});//增加打印此次
  11807. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  11808. };
  11809. }]);
  11810. /**
  11811. * 计算时间差
  11812. */
  11813. app.filter('timespan', function () {
  11814. return function (time) {
  11815. if (time == null)
  11816. return '9999年';
  11817. var now = new Date().getTime(), span = time - now,
  11818. d = Math.ceil(span / 86400000), h = Math.ceil(span / 3600000),
  11819. m = Math.ceil(span / 60000);
  11820. if (span < 0)
  11821. return '1天';
  11822. if (d > 0)
  11823. return d + 1 + '天';
  11824. if (h > 0)
  11825. return h + '小时';
  11826. if (m > 0)
  11827. return m + '分钟';
  11828. return '0天';
  11829. };
  11830. });
  11831. app.filter('firstchar', function () {
  11832. return function (str) {
  11833. if (str == null)
  11834. return null;
  11835. return str.substring(0, 1);
  11836. };
  11837. });
  11838. app.filter('summary', function () {
  11839. return function (data, field) {
  11840. var sum = 0;
  11841. if (data) {
  11842. angular.forEach(data, function (d) {
  11843. sum += d[field];
  11844. });
  11845. }
  11846. return sum;
  11847. };
  11848. });
  11849. /**
  11850. * 搜索框,回车触发
  11851. */
  11852. app.directive('ngSearch', ['$parse', function ($parse) {
  11853. return {
  11854. require: '?ngModel',
  11855. restrict: 'A',
  11856. link: function (scope, element, attrs, ngModel) {
  11857. var searchFn = $parse(attrs.ngSearch);
  11858. element.bind('keypress', function (event) {
  11859. if (event.keyCode == '13') {
  11860. event.preventDefault();
  11861. event.stopPropagation();
  11862. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  11863. }
  11864. });
  11865. }
  11866. };
  11867. }]);
  11868. /**
  11869. * 状态码 -> 描述
  11870. */
  11871. app.filter('status', function () {
  11872. return function (data) {
  11873. var statusConfig = {
  11874. '101': '已提交',
  11875. '102': '已审核',
  11876. '103': '未通过',
  11877. '200': '未回复',
  11878. '201': '已回复',
  11879. '313': '已激活',
  11880. '316': '已过账',
  11881. '311': '申请中',
  11882. '312': '未激活'
  11883. };
  11884. return statusConfig[data];
  11885. }
  11886. });
  11887. //弹出问题反馈模态框
  11888. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function ($scope, $modal, AuthenticationService) {
  11889. //获取当前用户
  11890. AuthenticationService.getAuthentication().success(function (data) {
  11891. $scope.user = data;
  11892. });
  11893. $scope.showModal = function () {
  11894. var modalInstance = $modal.open({
  11895. animation: true,
  11896. templateUrl: 'static/tpl/serve/feedback.html',
  11897. controller: 'FeedbackCtrl',
  11898. resolve: {
  11899. user: function () {
  11900. return $scope.user;
  11901. } //传递当前用户到模态框Controller
  11902. }
  11903. });
  11904. modalInstance.result.then(function () {
  11905. }, function () {
  11906. });
  11907. }
  11908. }]);
  11909. /*
  11910. * 提交我的反馈
  11911. */
  11912. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function ($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user) {
  11913. $scope.isPublic = 1; //默认公开
  11914. $scope.classId = 1; //默认类别
  11915. $scope.user = user;
  11916. $scope.ok = function () {
  11917. if (!$scope.user) { //用户未登录
  11918. $scope.uu = null;
  11919. } else { //用户已登录
  11920. $scope.uu = $scope.user.userUU;
  11921. }
  11922. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  11923. FeedBackService.feedBackQuestion({
  11924. classId: $scope.classId,
  11925. isPublic: $scope.isPublic,
  11926. title: $scope.title,
  11927. userUU: $scope.uu
  11928. }, {},
  11929. function (data) {
  11930. toaster.pop('success', '成功', '您的问题反馈成功!');
  11931. $scope.cancel();
  11932. }, function (response) {
  11933. toaster.pop('error', '错误', response.data);
  11934. });
  11935. }
  11936. $scope.cancel = function () {
  11937. $modalInstance.dismiss();
  11938. };
  11939. }]);
  11940. //“我的问题反馈”跳转控制
  11941. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function ($scope, AuthenticationService, toaster, $rootScope) {
  11942. $scope.myFeedback = function () {
  11943. AuthenticationService.getAuthentication().success(function (data) {
  11944. $scope.user = data;
  11945. if (!$scope.user) {
  11946. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  11947. return false;
  11948. } else {
  11949. window.location.href = "./serve#/question/myFeedback";
  11950. }
  11951. });
  11952. };
  11953. $scope.getSaleOrderCount = function (unread) {
  11954. if (unread != undefined) {
  11955. return unread.order + unread.change + unread.makeOrder;
  11956. }
  11957. };
  11958. $scope.getSaleInquiryCount = function (unread) {
  11959. if (unread != undefined) {
  11960. return unread.inquiry + unread.mould;
  11961. }
  11962. };
  11963. $scope.setActive = function (active) {
  11964. $rootScope.active = active;
  11965. }
  11966. }]);
  11967. //客户服务
  11968. app.controller('CustServeCtrl', ['$scope', 'Vendor', function ($scope, Vendor) {
  11969. Vendor.getServe(function (datas) {
  11970. $scope.vendors = datas;
  11971. // 自动跳转
  11972. if (datas && datas.length == 1)
  11973. $scope.redirect(datas[0]);
  11974. });
  11975. $scope.redirect = function (vendor) {
  11976. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  11977. };
  11978. }]);
  11979. /**
  11980. * 物料资料
  11981. */
  11982. 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) {
  11983. BaseService.scrollBackToTop();
  11984. var loadAccount = function () {
  11985. AccountEnterprise.get({}, function (data) {
  11986. $scope.loading = false;
  11987. $scope.enterprise = data;
  11988. $scope.saleStatus = $scope.enterprise.prodsale;
  11989. });
  11990. }
  11991. loadAccount();
  11992. $scope.active = 'all';
  11993. $scope.agreedText = '全部';
  11994. $scope.dateZoneText = '一个月内';
  11995. $scope.condition = {dateZone: 1};
  11996. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11997. $scope.changeAgreed = function (agreed) {
  11998. $scope.condition.agreed = agreed;
  11999. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12000. $scope.condition.$agreedOpen = false;
  12001. };
  12002. $scope.changeDateZone = function (zone) {
  12003. $scope.condition.dateZone = zone;
  12004. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12005. $scope.condition.$dateZoneOpen = false;
  12006. getDateCondition(zone, $scope.condition);
  12007. $scope.tableParams.reload();
  12008. };
  12009. $scope.setActive = function (state) {
  12010. if ($scope.active != state) {
  12011. $scope.active = state;
  12012. if ($scope.tableParams.page() == 1)
  12013. $scope.tableParams.reload();
  12014. else
  12015. $scope.tableParams.page(1);
  12016. }
  12017. };
  12018. $scope.searchMethod = false;
  12019. var getService = function () {
  12020. return $scope.searchMethod ? GetProductInfo : GetProductInfoNewest;
  12021. };
  12022. $scope.tableParams = new ngTableParams({
  12023. page: 1,
  12024. count: 20,
  12025. sorting: {
  12026. id: 'desc',
  12027. }
  12028. }, {
  12029. total: 0,
  12030. counts: [5, 10, 25, 50],
  12031. getData: function ($defer, params) {
  12032. $scope.loading = true;
  12033. var pageParams = params.url();
  12034. pageParams.keyword = $scope.keyword;
  12035. pageParams.searchFilter = $scope.searchFilter;
  12036. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12037. $scope.loading = false;
  12038. if (page) {
  12039. params.total(page.totalElement);
  12040. $defer.resolve(page.content);
  12041. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12042. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  12043. }
  12044. }, function (response) {
  12045. $scope.loading = false;
  12046. toaster.pop('error', '数据加载失败', response.data);
  12047. });
  12048. }
  12049. });
  12050. // //设置单据已读
  12051. // var setOrdersRead = function () {
  12052. // var ids = [];
  12053. // GetProductInfo.setRead({}, ids, function (message) {
  12054. // });
  12055. // };
  12056. // setOrdersRead();
  12057. // 搜索框回车
  12058. $scope.onSearch = function (keyword) {
  12059. // 每次搜索重置获取数据方法
  12060. $scope.searchMethod = false;
  12061. if(keyword != null && keyword != '') {
  12062. $scope.searchMethod = true;
  12063. }
  12064. $scope.tableParams.page(1);
  12065. $scope.tableParams.reload();
  12066. };
  12067. //删除
  12068. $scope.deleteById = function (id) {
  12069. GetProductInfo.deleteById({}, id, function (data) {
  12070. if (data.error) {
  12071. toaster.pop("error", "提示", data.error);
  12072. } else {
  12073. toaster.pop("success", "提示", "删除成功");
  12074. $timeout(function () {
  12075. $scope.tableParams.reload();
  12076. }, 500);
  12077. }
  12078. }, function (response) {
  12079. toaster.pop("error", "删除失败", response.data);
  12080. });
  12081. };
  12082. $rootScope.isProductEdit = false;
  12083. // 编辑
  12084. $scope.isProductEdit = function () {
  12085. $rootScope.isProductEdit = true;
  12086. };
  12087. // 一键开启关闭
  12088. $scope.toggle = function (status) {
  12089. if ($scope.saleStatus == 0) {
  12090. $scope.saleStatus = 1;
  12091. } else {
  12092. $scope.saleStatus = 0;
  12093. }
  12094. $scope.loading = true;
  12095. GetProductInfo.toggle({status: status}, {}, function (data) {
  12096. $scope.loading = false;
  12097. toaster.pop('success', '提示', '操作成功');
  12098. loadAccount();
  12099. $scope.tableParams.reload();
  12100. }, function (response) {
  12101. $scope.loading = false;
  12102. toaster.pop('error', '提示', response.data);
  12103. })
  12104. }
  12105. var products = [];
  12106. $scope.checks = {
  12107. checked: false
  12108. };
  12109. // 全选框
  12110. $scope.checkAll = function () {
  12111. products = [];// 每次选择时先清空,防止重复
  12112. angular.forEach($scope.tableParams.data, function (product) {
  12113. if (product.cmpUuId == null) {
  12114. product.checked = $scope.checks.checked;
  12115. }
  12116. });
  12117. };
  12118. // 单选
  12119. $scope.checkOne = function (product) {
  12120. products = [];// 每次选择时先清空,防止重复
  12121. var result = true;
  12122. angular.forEach($scope.tableParams.data, function (item) {
  12123. if (item.$selected != true) {
  12124. result = false;
  12125. return;
  12126. }
  12127. });
  12128. $scope.checks.checked = result;
  12129. var checked = true;
  12130. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  12131. if (!message.checked) {
  12132. checked = false;
  12133. }
  12134. });
  12135. $scope.checks.checked = checked;
  12136. };
  12137. $scope.updateByBatch = function (updatetype) {
  12138. var modalInstance = $modal.open({
  12139. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  12140. controller: 'UpdateByBatchCtrl',
  12141. size: 'md',
  12142. resolve: {
  12143. updatetype: function () {
  12144. return updatetype;
  12145. },
  12146. active: function () {
  12147. return $scope.active;
  12148. },
  12149. type: function () {
  12150. return 'sale';
  12151. }
  12152. }
  12153. });
  12154. modalInstance.result.then(function (data) {
  12155. toaster.pop('success', '提示', data.success);
  12156. $scope.tableParams.reload();
  12157. }, function () {
  12158. });
  12159. }
  12160. // 一键匹配
  12161. $scope.matchall = function () {
  12162. $scope.loading = true;
  12163. $scope.type = "sale";
  12164. GetProductInfo.matchbytype({type: $scope.type}, {}, function (data) {
  12165. if (data.error) {
  12166. $scope.loading = false;
  12167. toaster.pop('error', '提示', data.error);
  12168. } else {
  12169. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  12170. window.location.href = "#/sale/productmatches";
  12171. }
  12172. }, function (response) {
  12173. $scope.loading = false;
  12174. toaster.pop('error', '提示', response.data);
  12175. });
  12176. }
  12177. $scope.exportXls = function () {
  12178. GetProductInfo.exportXls({},{}, function (data) {
  12179. if (data.success) {
  12180. window.location.href = 'product/baseInfo/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  12181. }
  12182. }, function (response) {
  12183. toaster.pop('error', '数据加载失败', response.data);
  12184. })
  12185. }
  12186. }]);
  12187. /**
  12188. * 批量修改
  12189. */
  12190. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function ($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  12191. $scope.updatetype = updatetype;
  12192. $scope.changed = false;
  12193. $scope.parameter = {
  12194. updatetype: updatetype,
  12195. standard: active,
  12196. type: type,
  12197. oldvalue: null,
  12198. newvalue: null
  12199. };
  12200. $scope.cancel = function () {
  12201. $modalInstance.dismiss();
  12202. }
  12203. if (updatetype === '品牌')
  12204. var loadData = function () {
  12205. Products.getBrands({parameter: $scope.parameter}, {}, function (data) {
  12206. $scope.products = data;
  12207. }, function (response) {
  12208. toaster.pop('error', '提示', response.data);
  12209. })
  12210. }
  12211. if (updatetype === '名称(类目)')
  12212. var loadData = function () {
  12213. Products.getTitles({parameter: $scope.parameter}, {}, function (data) {
  12214. $scope.products = data;
  12215. }, function (response) {
  12216. toaster.pop('error', '提示', response.data);
  12217. })
  12218. }
  12219. loadData();
  12220. $scope.okay = function (newvalue) {
  12221. if (newvalue == '' || newvalue == null) {
  12222. toaster.pop('error', '提示', '修改的值不能为空');
  12223. } else {
  12224. Products.alterByBatch({parameter: $scope.parameter}, {}, function (data) {
  12225. $modalInstance.close(data);
  12226. }, function (response) {
  12227. toaster.pop('error', '提示', response.data);
  12228. });
  12229. }
  12230. }
  12231. }]);
  12232. /**
  12233. * 物料批量上传
  12234. */
  12235. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  12236. BaseService.scrollBackToTop();
  12237. $scope.$watch('myFiles', function () {
  12238. if ($scope.myFiles) {
  12239. var file = $scope.myFiles[0];
  12240. $scope.fileName = file.name;
  12241. }
  12242. })
  12243. // 通过excel批量上传物料
  12244. $scope.upload = function () {
  12245. $scope.loading = true;
  12246. if ($scope.myFiles) {
  12247. var file = $scope.myFiles[0];
  12248. if (file.name) {
  12249. $upload.upload({
  12250. url: 'product/baseInfo/edit/release/excel',
  12251. file: file,
  12252. method: 'POST'
  12253. }).success(function (data) {
  12254. $scope.loading = false;
  12255. if (data.error) {
  12256. toaster.pop('error', '提示', data.error);
  12257. }
  12258. $scope.result = data;
  12259. $scope.products = $scope.result.products;
  12260. $scope.success = $scope.result.success;
  12261. $scope.total = $scope.result.total;
  12262. $scope.alters = $scope.result.alters;
  12263. $scope.infos = $scope.result.infos;
  12264. $scope.myFiles[0] = "";
  12265. $scope.fileName = "";
  12266. }).error(function (response) {
  12267. $scope.loading = false;
  12268. toaster.pop('error', response.data || response);
  12269. });
  12270. } else {
  12271. $scope.loading = false;
  12272. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  12273. }
  12274. } else {
  12275. $scope.loading = false;
  12276. }
  12277. };
  12278. // 查看范例
  12279. $scope.showImg = function () {
  12280. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  12281. box.show();
  12282. box.find('img').attr('src', src);
  12283. box.find('a').click(function () {
  12284. box.hide();
  12285. });
  12286. box.dblclick(function () {
  12287. box.hide();
  12288. });
  12289. };
  12290. // 下载模板
  12291. $scope.download = function () {
  12292. window.location.href = 'product/baseInfo/upload/template';
  12293. };
  12294. }]);
  12295. /**
  12296. * 物料详情
  12297. */
  12298. 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) {
  12299. BaseService.scrollBackToTop();
  12300. // 录入人
  12301. AuthenticationService.getAuthentication().success(function (data) {
  12302. $scope.loading = false;
  12303. $scope.user = data;
  12304. });
  12305. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12306. $scope.editstatus = false;
  12307. var loadData = function () {
  12308. GetProductInfo.getSaleProduct({id: $stateParams.id}, function (data) {
  12309. if (data.attach) {
  12310. GetProductInfo.getAttach({id: data.attach.id}, function (data) {
  12311. $scope.imgPreview = data.url;
  12312. $scope.previewShow = true;
  12313. });
  12314. }
  12315. $scope.prodInfo = data;
  12316. if ($scope.prodInfo.isbusiness == 0) {
  12317. $scope.editstatus = true;
  12318. }
  12319. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  12320. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  12321. $scope.matchresults = data;
  12322. }, function (response) {
  12323. toaster.pop('error', '提示', response.data);
  12324. });
  12325. }
  12326. $scope.loading = false;
  12327. }, function (response) {
  12328. $scope.loading = false;
  12329. toaster.pop('error', '数据加载失败', response.data);
  12330. });
  12331. };
  12332. loadData();
  12333. // 联想词 start
  12334. // 获取类目
  12335. $scope.getSimilarKinds = function (value) {
  12336. if (value) {
  12337. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12338. return data.map(function (item) {
  12339. return item;
  12340. });
  12341. });
  12342. }
  12343. };
  12344. // 设置类目
  12345. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12346. $scope.prodInfo.kind = kind.kindName;
  12347. }
  12348. // 设置名称
  12349. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  12350. $scope.prodInfo.title = kind.kindName;
  12351. }
  12352. $scope.getSimilarBrands = function (value) {
  12353. if (value) {
  12354. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12355. return data.map(function (item) {
  12356. return item;
  12357. });
  12358. });
  12359. }
  12360. }
  12361. // 设置导入品牌
  12362. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12363. $scope.prodInfo.brand = brand.brandName;
  12364. }
  12365. // 设置标准品牌
  12366. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  12367. $scope.prodInfo.pbranden = brand.brandName;
  12368. }
  12369. $scope.getSimilarComponents = function (value) {
  12370. if (value) {
  12371. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12372. return data.map(function (item) {
  12373. return item;
  12374. });
  12375. });
  12376. }
  12377. }
  12378. // 设置标准型号
  12379. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12380. $scope.prodInfo.pcmpcode = cmp.code;
  12381. }
  12382. // 设置导入的型号
  12383. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  12384. $scope.prodInfo.cmpCode = cmp.code;
  12385. }
  12386. // 联想词 end
  12387. //更新为标准器件
  12388. $scope.updateone = function (id) {
  12389. Products.updateone({id: id}, {}, function (data) {
  12390. if (data.success) {
  12391. toaster.pop('success', '提示', data.success);
  12392. window.location.reload();
  12393. }
  12394. }, function (response) {
  12395. toaster.pop('error', '提示', response.data);
  12396. });
  12397. }
  12398. // 选择类目
  12399. $scope.selectKind = function (cmpcode) {
  12400. if (cmpcode == null) {
  12401. $modal.open({
  12402. animation: true,
  12403. size: 'lg',
  12404. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12405. controller: 'KindChooseCtrl',
  12406. }).result.then(function (data) {
  12407. $scope.kindId = data;
  12408. var modalInstance = $modal.open({
  12409. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12410. controller: 'FindComponentCtrl',
  12411. size: 'lg',
  12412. resolve: {
  12413. KindId: function () {
  12414. return $scope.kindId;
  12415. }
  12416. }
  12417. });
  12418. modalInstance.result.then(function (data) {
  12419. $scope.prodInfo.cmpUuId = data.uuid;
  12420. $scope.prodInfo.pcmpcode = data.code;
  12421. $scope.prodInfo.pbranden = data.brand.nameEn;
  12422. $scope.prodInfo.pbrand = data.brand.nameCn;
  12423. }, function () {
  12424. });
  12425. }, function () {
  12426. });
  12427. }
  12428. };
  12429. $scope.isShow = true;
  12430. // 更新
  12431. $scope.update = function () {
  12432. $scope.prodInfo.$editing = true;
  12433. $scope.isShow = true;
  12434. };
  12435. // 取消
  12436. $scope.cancel = function () {
  12437. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  12438. $scope.prodInfo = data;
  12439. $scope.prodInfo.$editing = false;
  12440. $scope.isShow = false;
  12441. $scope.loading = false;
  12442. });
  12443. };
  12444. // 删除
  12445. $scope.clearfile = function () {
  12446. $scope.prodInfo.attach = null;
  12447. $scope.myFiles = null;
  12448. $scope.previewShow = false;
  12449. }
  12450. //删除
  12451. $scope.deleteById = function (id) {
  12452. GetProductInfo.deleteById({}, id, function (data) {
  12453. if (data.error) {
  12454. toaster.pop("error", "提示", data.error);
  12455. } else {
  12456. toaster.pop("success", "提示", "删除成功");
  12457. window.location.href = "#/sale/prodList";
  12458. }
  12459. }, function (response) {
  12460. toaster.pop("error", "删除失败", response.data);
  12461. });
  12462. };
  12463. $scope.submit = function (prodInfo) {
  12464. $scope.prodInfo.isSale = 1;
  12465. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12466. $upload.upload({
  12467. url: 'product/baseInfo/edit/updateProdInfo',
  12468. file: file,
  12469. method: 'POST',
  12470. data: {
  12471. prodInfo: $scope.prodInfo
  12472. },
  12473. }).success(function (data) {
  12474. if (data.success) {
  12475. toaster.pop('success', '提示', data.success);
  12476. $rootScope.isProductEdit = false;
  12477. loadData();
  12478. // window.location.href="#/sale/prodList";
  12479. }
  12480. if (data.error) {
  12481. toaster.pop('error', '提示', data.error);
  12482. }
  12483. }).error(function (data, status) {
  12484. $scope.loadingShow = false;
  12485. if (status == 403){
  12486. toaster.pop('error', '操作失败', data);
  12487. } else {
  12488. toaster.pop('error', '操作失败', data.error);
  12489. }
  12490. });
  12491. }
  12492. $scope.previewShow = false;
  12493. $scope.pdfShow = false;
  12494. $scope.noneFileShow = true;
  12495. $scope.$watch('myFiles', function () {
  12496. if ($scope.myFiles) {
  12497. $scope.noneFileShow = false;
  12498. var file = $scope.myFiles[0];
  12499. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12500. $scope.pdfShow = true;
  12501. $scope.previewShow = false;
  12502. $scope.imgPreviewName = file.name;
  12503. } else {
  12504. if (typeof(Worker) !== "undefined") {//支持HTML5
  12505. $scope.imgPreview = getObjectURL(file);
  12506. $scope.imgPreviewName = file.name;
  12507. } else {//不支持HTML5
  12508. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12509. $scope.imgPreviewName = file.name;
  12510. }
  12511. $scope.previewShow = true;
  12512. $scope.pdfShow = false;
  12513. }
  12514. } else {
  12515. $scope.noneFileShow = true;
  12516. $scope.previewShow = false;
  12517. $scope.pdfShow = false;
  12518. }
  12519. });
  12520. //建立一个可存取到该file的url
  12521. var imgurl = null;
  12522. var getObjectURL = function (file) {
  12523. var url = null;
  12524. if (window.createObjectURL != undefined) { // basic
  12525. url = window.createObjectURL(file);
  12526. } else if (window.URL != undefined) { // mozilla(firefox)
  12527. url = window.URL.createObjectURL(file);
  12528. } else if (window.webkitURL != undefined) { // webkit or chrome
  12529. url = window.webkitURL.createObjectURL(file);
  12530. }
  12531. imgurl = url;
  12532. return url;
  12533. };
  12534. // 查看范例
  12535. $scope.showImg = function () {
  12536. if ($scope.prodInfo.attach) {
  12537. GetProductInfo.getAttach({id: $scope.prodInfo.attach.id}, function (data) {
  12538. $scope.imgPreview = data.url;
  12539. var src = data.url, box = $('#image-box');
  12540. box.show();
  12541. box.find('img').attr('src', src);
  12542. box.find('a').click(function () {
  12543. box.hide();
  12544. });
  12545. box.dblclick(function () {
  12546. box.hide();
  12547. });
  12548. });
  12549. $scope.previewShow = true;
  12550. } else if (imgurl != null) {
  12551. var src = imgurl, box = $('#image-box');
  12552. box.show();
  12553. box.find('img').attr('src', src);
  12554. box.find('a').click(function () {
  12555. box.hide();
  12556. });
  12557. box.dblclick(function () {
  12558. box.hide();
  12559. });
  12560. }
  12561. };
  12562. }]);
  12563. /**
  12564. * 新增物料(销售)
  12565. */
  12566. 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) {
  12567. BaseService.scrollBackToTop();
  12568. // 录入人
  12569. AuthenticationService.getAuthentication().success(function (data) {
  12570. $scope.loading = false;
  12571. $scope.user = data;
  12572. });
  12573. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12574. $scope.prodInfo = {};
  12575. // 选择类目
  12576. $scope.selectKind = function () {
  12577. $modal.open({
  12578. animation: true,
  12579. size: 'lg',
  12580. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12581. controller: 'KindChooseCtrl',
  12582. }).result.then(function (data) {
  12583. $scope.kindId = data;
  12584. var modalInstance = $modal.open({
  12585. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12586. controller: 'FindComponentCtrl',
  12587. size: 'lg',
  12588. resolve: {
  12589. KindId: function () {
  12590. return $scope.kindId;
  12591. }
  12592. }
  12593. });
  12594. modalInstance.result.then(function (data) {
  12595. $scope.prodInfo.cmpUuId = data.uuid;
  12596. $scope.prodInfo.pcmpcode = data.code;
  12597. $scope.prodInfo.pbranden = data.brand.nameEn;
  12598. $scope.prodInfo.pbrand = data.brand.nameCn;
  12599. }, function () {
  12600. });
  12601. }, function () {
  12602. });
  12603. };
  12604. // 联想词 start
  12605. // 获取类目
  12606. $scope.getSimilarKinds = function (value) {
  12607. if (value) {
  12608. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12609. return data.map(function (item) {
  12610. return item;
  12611. });
  12612. });
  12613. }
  12614. };
  12615. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12616. $scope.prodInfo.title = kind.kindName;
  12617. }
  12618. $scope.getSimilarBrands = function (value) {
  12619. if (value) {
  12620. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12621. return data.map(function (item) {
  12622. return item;
  12623. });
  12624. });
  12625. }
  12626. }
  12627. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12628. $scope.prodInfo.brand = brand.brandName;
  12629. }
  12630. $scope.getSimilarComponents = function (value) {
  12631. if (value) {
  12632. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12633. return data.map(function (item) {
  12634. return item;
  12635. });
  12636. });
  12637. }
  12638. }
  12639. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12640. $scope.prodInfo.cmpCode = cmp.code;
  12641. }
  12642. // 联想词 end
  12643. // 删除
  12644. $scope.clearfile = function () {
  12645. $scope.myFiles = null;
  12646. $scope.previewShow = false;
  12647. }
  12648. //提交
  12649. $scope.submit = function (prodInfo) {
  12650. $scope.prodInfo.isSale = 1;
  12651. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12652. $upload.upload({
  12653. url: 'product/baseInfo/edit/addNewProduct',
  12654. file: file,
  12655. method: 'POST',
  12656. data: {
  12657. prodInfo: prodInfo
  12658. },
  12659. }).success(function (data) {
  12660. if (data.success) {
  12661. toaster.pop('success', '提示', '产品添加成功');
  12662. $timeout(function () {
  12663. //提交后跳转到详情页面,防止重复提交
  12664. window.location.href = "#/sale/prodList/" + data.id;
  12665. // window.location.href="#/sale/prodList";
  12666. }, 500);
  12667. }
  12668. if (data.error) {
  12669. toaster.pop('error', '提示', data.error);
  12670. $timeout(function () {
  12671. //提交后跳转到详情页面,防止重复提交
  12672. window.location.href = "#/sale/prodList/" + data.id;
  12673. // window.location.href="#/sale/prodList";
  12674. }, 500);
  12675. }
  12676. }).error(function (data, status) {
  12677. $scope.loadingShow = false;
  12678. if (status == 403) {
  12679. toaster.pop('error', '操作失败', data);
  12680. } else {
  12681. toaster.pop('error', '操作失败', data.error);
  12682. }
  12683. });
  12684. };
  12685. $scope.previewShow = false;
  12686. $scope.pdfShow = false;
  12687. $scope.noneFileShow = true;
  12688. $scope.$watch('myFiles', function () {
  12689. if ($scope.myFiles) {
  12690. $scope.noneFileShow = false;
  12691. var file = $scope.myFiles[0];
  12692. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12693. $scope.pdfShow = true;
  12694. $scope.previewShow = false;
  12695. $scope.imgPreviewName = file.name;
  12696. } else {
  12697. if (typeof(Worker) !== "undefined") {//支持HTML5
  12698. $scope.imgPreview = getObjectURL(file);
  12699. $scope.imgPreviewName = file.name;
  12700. } else {//不支持HTML5
  12701. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12702. $scope.imgPreviewName = file.name;
  12703. }
  12704. $scope.previewShow = true;
  12705. $scope.pdfShow = false;
  12706. }
  12707. } else {
  12708. $scope.noneFileShow = true;
  12709. $scope.previewShow = false;
  12710. $scope.pdfShow = false;
  12711. }
  12712. });
  12713. //建立一个可存取到该file的url
  12714. var imgUrl = null
  12715. var getObjectURL = function (file) {
  12716. var url = null;
  12717. if (window.createObjectURL != undefined) { // basic
  12718. url = window.createObjectURL(file);
  12719. } else if (window.URL != undefined) { // mozilla(firefox)
  12720. url = window.URL.createObjectURL(file);
  12721. } else if (window.webkitURL != undefined) { // webkit or chrome
  12722. url = window.webkitURL.createObjectURL(file);
  12723. }
  12724. imgUrl = url;
  12725. return url;
  12726. };
  12727. // 查看范例
  12728. $scope.showImg = function () {
  12729. var src = imgUrl, box = $('#image-box');
  12730. box.show();
  12731. box.find('img').attr('src', src);
  12732. box.find('a').click(function () {
  12733. box.hide();
  12734. });
  12735. box.dblclick(function () {
  12736. box.hide();
  12737. });
  12738. };
  12739. // 取消
  12740. $scope.cancel = function () {
  12741. $scope.prodInfo = angular.copy($scope.prodInfo);
  12742. };
  12743. }]);
  12744. /**
  12745. * 类目选择模态框
  12746. */
  12747. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function ($scope, KindAPI, toaster, $modalInstance, $modal) {
  12748. $scope.kindId = null;
  12749. $scope.kinds = [[], [], [], []];
  12750. // 获取子类目
  12751. var getChildren = function (pid, deep) {
  12752. KindAPI.getChildren({parentId: pid}, function (data) {
  12753. $scope.kinds[deep] = data;
  12754. }, function (response) {
  12755. toaster.pop('error', '获取子类目失败', response.data);
  12756. });
  12757. };
  12758. // 改变节点选中状态
  12759. var changeStatus = function (item, deep) {
  12760. var kindId = null, level = 0;
  12761. angular.forEach($scope.kinds, function (ks, i) {
  12762. if (i > deep) {
  12763. $scope.kinds[i] = [];
  12764. } else {
  12765. angular.forEach(ks, function (k, j) {
  12766. if (i == deep) {
  12767. if (k.id == item.id) {
  12768. $scope.kinds[i][j].$active = true;
  12769. kindId = k.id;
  12770. } else {
  12771. k.$active = null;
  12772. }
  12773. }
  12774. });
  12775. }
  12776. });
  12777. // 选择的节点
  12778. $scope.kindId = kindId;
  12779. $scope.active = item;
  12780. // 当前可操作的层级
  12781. if (deep < 3) {
  12782. $scope.activeDeep = deep + 1;
  12783. }
  12784. };
  12785. // 节点点击后获取子类目,节点被选中
  12786. $scope.onItemClick = function (item, deep) {
  12787. changeStatus(item, deep);
  12788. if (!item.isLeaf) {
  12789. getChildren(item.id, deep + 1);
  12790. }
  12791. };
  12792. // 重新加载数据
  12793. function reload(deep) {
  12794. var pid;
  12795. if (deep) {
  12796. pid = $scope.actives[deep - 1].id;
  12797. } else {
  12798. pid = 0;
  12799. deep = 0;
  12800. }
  12801. getChildren(pid, deep);
  12802. }
  12803. // 初始加载数据,获取第一层的类目
  12804. if ($scope.actives) {
  12805. angular.forEach($scope.actives, function (v, k) {
  12806. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  12807. $scope.kinds[k] = data;
  12808. angular.forEach($scope.kinds[k], function (kind, i) {
  12809. if (kind.id == v.id) {
  12810. $scope.kinds[k][i].$active = true;
  12811. $scope.actives[k] = $scope.kinds[k][i];
  12812. }
  12813. })
  12814. }, function (response) {
  12815. toaster.pop('error', '获取子类目失败', response.data);
  12816. });
  12817. });
  12818. } else {
  12819. reload();
  12820. }
  12821. // 取消
  12822. $scope.cancel = function () {
  12823. $modalInstance.dismiss();
  12824. };
  12825. // 确认选择
  12826. $scope.check = function () {
  12827. $modalInstance.close($scope.kindId);
  12828. };
  12829. }]);
  12830. /**
  12831. * 器件筛选
  12832. */
  12833. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  12834. //状态
  12835. $scope.setActive = function (state) {
  12836. if ($scope.active != state) {
  12837. $scope.active = state;
  12838. if ($scope.tableParams.page() == 1)
  12839. $scope.tableParams.reload();
  12840. else
  12841. $scope.tableParams.page(1);
  12842. }
  12843. };
  12844. $scope.tableParams = new ngTableParams({
  12845. page: 1,
  12846. count: 20
  12847. }, {
  12848. total: 0,
  12849. counts: [5, 10, 25, 50],
  12850. getData: function ($defer, params) {
  12851. $scope.loading = true;
  12852. var pageParams = params.url();
  12853. pageParams.keyword = $scope.keyword;
  12854. pageParams.kindId = KindId;
  12855. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function (page) {
  12856. $scope.loading = false;
  12857. if (page) {
  12858. params.total(page.totalElement);
  12859. $defer.resolve(page.content);
  12860. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  12861. }
  12862. }, function (response) {
  12863. $scope.loading = false;
  12864. toaster.pop('error', '数据加载失败', response.data);
  12865. });
  12866. }
  12867. });
  12868. // 取消
  12869. $scope.cancel = function () {
  12870. $modalInstance.dismiss();
  12871. };
  12872. // 选择
  12873. $scope.check = function (data) {
  12874. $modalInstance.close(data);
  12875. };
  12876. // 搜索框回车
  12877. $scope.onSearch = function () {
  12878. $scope.tableParams.page(1);
  12879. $scope.tableParams.reload();
  12880. };
  12881. }]);
  12882. /**
  12883. * 企业列表
  12884. */
  12885. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  12886. BaseService.scrollBackToTop();
  12887. $scope.active = 'all';
  12888. $scope.agreedText = '全部';
  12889. $scope.dateZoneText = '一个月内';
  12890. $scope.condition = {dateZone: 1};
  12891. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12892. $scope.changeAgreed = function (agreed) {
  12893. $scope.condition.agreed = agreed;
  12894. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12895. $scope.condition.$agreedOpen = false;
  12896. };
  12897. $scope.changeDateZone = function (zone) {
  12898. $scope.condition.dateZone = zone;
  12899. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12900. $scope.condition.$dateZoneOpen = false;
  12901. getDateCondition(zone, $scope.condition);
  12902. $scope.tableParams.reload();
  12903. };
  12904. $scope.setActive = function (state) {
  12905. if ($scope.active != state) {
  12906. $scope.active = state;
  12907. if ($scope.tableParams.page() == 1)
  12908. $scope.tableParams.reload();
  12909. else
  12910. $scope.tableParams.page(1);
  12911. }
  12912. };
  12913. var getService = function () {
  12914. return getAccountUserSpace;
  12915. };
  12916. $scope.tableParams = new ngTableParams({
  12917. page: 1,
  12918. count: 20,
  12919. sorting: {}
  12920. }, {
  12921. total: 0,
  12922. counts: [5, 10, 25, 50],
  12923. getData: function ($defer, params) {
  12924. $scope.loading = true;
  12925. var pageParams = params.url();
  12926. pageParams.keyword = $scope.keyword;
  12927. $scope.tip = $scope.keyword;
  12928. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12929. $scope.loading = false;
  12930. if (page) {
  12931. params.total(page.totalElement);
  12932. $defer.resolve(page.content);
  12933. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12934. }
  12935. }, function (response) {
  12936. $scope.loading = false;
  12937. toaster.pop('error', '数据加载失败', response.data);
  12938. });
  12939. }
  12940. });
  12941. // 搜索框回车
  12942. $scope.onSearch = function () {
  12943. $scope.tableParams.page(1);
  12944. $scope.tableParams.reload();
  12945. };
  12946. // 添加合作关系
  12947. $scope.addPartner = function (name, businessCode) {
  12948. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  12949. if (data.success) {
  12950. toaster.pop("success", '添加成功', data.success);
  12951. $scope.tableParams.reload();
  12952. }
  12953. if (data.error) {
  12954. toaster.pop("error", '添加失败', data.error);
  12955. }
  12956. }, function (response) {
  12957. toaster.pop('error', '失败', response.data);
  12958. });
  12959. }
  12960. $scope.status = 'enList';
  12961. }]);
  12962. /**
  12963. * 新增采购单
  12964. */
  12965. app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token) {
  12966. BaseService.scrollBackToTop();
  12967. // 每次进入时先清除掉rootScope下的venduu
  12968. $rootScope.venduu = null;
  12969. // 获取收货地址列表
  12970. ShipAddress.shipAddList({}, function (data) {
  12971. $scope.ships = data;
  12972. $scope.order.shipadd = $scope.ships[0];
  12973. });
  12974. // 获取地址信息
  12975. $http.get('resources/citydata/city.json', {
  12976. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  12977. }).then(function (response) {
  12978. $scope.provinces = response.data;
  12979. });
  12980. var getToken = function() {
  12981. if($scope.token == null) {
  12982. token.info({userType: 'purcorder'}, {}, function(data) {
  12983. $scope.token = data.token;
  12984. }, function(response) {
  12985. toaster.pop('error', '提示', response.data);
  12986. });
  12987. }
  12988. }
  12989. getToken();
  12990. $scope.order = {
  12991. date: new Date(),
  12992. cust: {
  12993. uu: '',
  12994. },
  12995. custUser: {},
  12996. code: $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  12997. orderItems: {
  12998. product: {},
  12999. },
  13000. rate: 17
  13001. };
  13002. //商品信息
  13003. $scope.order.orderItems = [];
  13004. var item = {
  13005. code: null,
  13006. title: null,
  13007. spec: null,
  13008. unit: null,
  13009. qty: null,
  13010. price: null,
  13011. remark: null,
  13012. delivery: null,
  13013. prid: null,
  13014. taxrate: null
  13015. };
  13016. if ($rootScope.businessCode) {
  13017. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function (data) {
  13018. $scope.id = data.id;
  13019. $scope.order.cust.enName = data.vendorEnterprise.enName;
  13020. $scope.order.cust.enAddress = data.vendorEnterprise.enAddress;
  13021. $scope.order.cust.uu = data.vendorEnterprise.uu;
  13022. $scope.order.paymethods = data.paymethod;
  13023. $rootScope.venduu = data.vendorEnterprise.uu;
  13024. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function (data) {
  13025. $scope.contacts = data;
  13026. $scope.order.vendor = $scope.contacts[0];
  13027. });
  13028. }, function (response) {
  13029. });
  13030. }
  13031. ;
  13032. // 查找供应商
  13033. $scope.dbfindVend = function () {
  13034. var modalInstance = $modal.open({
  13035. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  13036. controller: 'DbfindVendorInfoCtrl',
  13037. size: 'lg',
  13038. resolve: {
  13039. orderItems: function () {
  13040. return $scope.order.orderItems;
  13041. }
  13042. }
  13043. });
  13044. modalInstance.result.then(function (data) {
  13045. $rootScope.venduu = data.vendorEnterprise.uu;
  13046. $scope.id = data.id;
  13047. $scope.order.cust = data.vendorEnterprise;
  13048. $scope.order.cust.enName = data.vendorEnterprise.enName;
  13049. $scope.order.custUser = data.vendorUser;
  13050. $scope.order.payments = data.paymethod;
  13051. $scope.order.orderItems = [];
  13052. var item = {
  13053. code: null,
  13054. title: null,
  13055. spec: null,
  13056. unit: null,
  13057. qty: null,
  13058. price: null,
  13059. remark: null,
  13060. delivery: null,
  13061. taxrate: null
  13062. };
  13063. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function (data) {
  13064. $scope.contacts = data;
  13065. $scope.order.vendor = $scope.contacts[0];
  13066. });
  13067. }, function () {
  13068. });
  13069. };
  13070. // 联想词 start
  13071. // 获取供应商
  13072. $scope.getSimilarVendors = function (value) {
  13073. if (value) {
  13074. return Vendor.getSimilarVendors({keyword: value}).$promise.then(function (data) {
  13075. return data.map(function (item) {
  13076. return item;
  13077. });
  13078. });
  13079. }
  13080. };
  13081. $scope.onAssociateCmpClick = function (vendor, order) {
  13082. $scope.order.cust.uu = vendor.venduu;
  13083. $scope.id = vendor.id;
  13084. $scope.order.payments = vendor.paymethod;
  13085. $rootScope.venduu = $scope.order.cust.uu;
  13086. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function (data) {
  13087. $scope.contacts = data;
  13088. $scope.order.vendor = $scope.contacts[0];
  13089. });
  13090. }
  13091. // 联想词 end
  13092. // $scope.order.orderItems.push(item);
  13093. if ($rootScope.prodId) {
  13094. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  13095. item.code = data.code;
  13096. item.title = data.title;
  13097. item.spec = data.spec;
  13098. item.unit = data.unit;
  13099. item.id = data.id;
  13100. $scope.order.orderItems.push(item);
  13101. $rootScope.prodId = null;// 清除掉prodId
  13102. }, function (response) {
  13103. });
  13104. }
  13105. //增加商品
  13106. $scope.addProduct = function (index) {
  13107. if ($scope.order.orderItems[index].code == null) {
  13108. toaster.pop('info', '提示', '请先选择商品');
  13109. } else {
  13110. $scope.order.orderItems.push({
  13111. code: null,
  13112. title: null,
  13113. spec: null,
  13114. unit: null,
  13115. qty: null,
  13116. price: null,
  13117. remark: null,
  13118. delivery: null,
  13119. $endDateOpen: false,
  13120. taxrate: $scope.order.rate,
  13121. prodsource: 'seller'
  13122. });
  13123. }
  13124. };
  13125. //删除商品
  13126. $scope.deleteProduct = function (index) {
  13127. $scope.order.orderItems.splice(index, 1);
  13128. };
  13129. // 搜索框回车
  13130. $scope.onSearch = function (keyword) {
  13131. $scope.keyword = keyword;
  13132. $scope.tableParams.page(1);
  13133. $scope.tableParams.reload();
  13134. };
  13135. $scope.tableParams = new ngTableParams({
  13136. page: 1,
  13137. count: 20
  13138. }, {
  13139. total: 0,
  13140. counts: [5, 10, 25, 50],
  13141. getData: function ($defer, params) {
  13142. $scope.loading = true;
  13143. var pageParams = params.url();
  13144. pageParams.keyword = $scope.keyword;
  13145. $scope.tip = $scope.keyword;
  13146. pageParams.custUU = $scope.order.cust.uu;
  13147. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  13148. $scope.loading = false;
  13149. if (page) {
  13150. params.total(page.totalElement);
  13151. $scope.total = page.totalElement;
  13152. $defer.resolve(page.content);
  13153. }
  13154. }, function (response) {
  13155. $scope.loading = false;
  13156. toaster.pop('error', '数据加载失败', response.data);
  13157. });
  13158. }
  13159. });
  13160. // 选择
  13161. $scope.check = function (data) {
  13162. $scope.order.orderItems.push({
  13163. code: data.code,
  13164. title: data.title,
  13165. spec: data.spec,
  13166. unit: data.unit,
  13167. qty: null,
  13168. price: null,
  13169. remark: null,
  13170. delivery: null,
  13171. prid: data.id,
  13172. taxrate: $scope.order.rate,
  13173. prodsource: 'seller'
  13174. });
  13175. };
  13176. // 导入商品信息
  13177. $scope.uplodaByBatch = function () {
  13178. var modalInstance = $modal.open({
  13179. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  13180. controller: 'PurcUploadByBatchCtrl',
  13181. size: 'lg',
  13182. resolve: {}
  13183. });
  13184. modalInstance.result.then(function (data) {
  13185. angular.forEach(data, function (prod) {
  13186. $scope.order.orderItems.push({
  13187. code: prod.code,
  13188. title: prod.title,
  13189. unit: 'PCS',
  13190. spec: prod.spec,
  13191. qty: prod.amount,
  13192. price: prod.price,
  13193. remark: prod.remark,
  13194. delivery: prod.date,
  13195. prid: prod.id,
  13196. taxrate: prod.rate,
  13197. prodsource: 'purchaser'
  13198. });
  13199. })
  13200. }, function () {
  13201. });
  13202. };
  13203. // 监听custuu发生变化,重新加载物料信息
  13204. $scope.$watch('order.cust.uu', function (n, o) {
  13205. if (n == o) {
  13206. return;
  13207. } else {
  13208. $scope.tableParams.page(1);
  13209. $scope.tableParams.reload();
  13210. }
  13211. }, true);
  13212. $scope.getMinDate = function (item) {
  13213. return $filter('date')(new Date, 'yyyy-MM-dd');
  13214. };
  13215. $scope.openDatePicker = function ($event, openParam, index) {
  13216. $event.preventDefault();
  13217. $event.stopPropagation();
  13218. $scope.order.orderItems[index].$endDateOpen = !openParam;
  13219. };
  13220. // 添加到购物车
  13221. $scope.addToCart = function (order) {
  13222. $scope.loading = true;
  13223. $scope.order.status = 311;
  13224. $scope.order.vendusertel = order.vendor.tel;
  13225. $scope.order.venduser = order.vendor.venduser;
  13226. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13227. $scope.order.custUU = $scope.order.cust.uu;
  13228. $scope.order.custUserUU = $scope.order.custUser.userUU;
  13229. if ($scope.order.date instanceof Date) {
  13230. $scope.order.date = $scope.order.date.getTime();
  13231. }
  13232. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13233. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13234. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13235. }
  13236. if ($scope.order.currency != 'RMB') {
  13237. $scope.order.orderItems[i].rate = 0;
  13238. }
  13239. }
  13240. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13241. $scope.loading = false;
  13242. toaster.pop('success', '成功', '保存成功');
  13243. window.location.hash = '#/purc/cart/' + data.id;
  13244. $window.location.reload();
  13245. }, function (response) {
  13246. $scope.loading = false;
  13247. toaster.pop('error', '保存失败', response.data);
  13248. });
  13249. };
  13250. // 立即购买
  13251. $scope.addToOrder = function (order) {
  13252. $scope.loading = true;
  13253. $scope.order.status = 200;
  13254. $scope.order.vendusertel = order.vendor.tel;
  13255. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  13256. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13257. $scope.order.custUU = $scope.order.cust.uu;
  13258. $scope.order.custUserUU = $scope.order.custUser.userUU;
  13259. if ($scope.order.date instanceof Date) {
  13260. $scope.order.date = $scope.order.date.getTime();
  13261. }
  13262. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13263. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13264. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13265. }
  13266. if ($scope.order.currency != 'RMB') {
  13267. $scope.order.orderItems[i].rate = 0;
  13268. }
  13269. }
  13270. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13271. $scope.loading = false;
  13272. toaster.pop('success', '成功', '保存成功');
  13273. window.location.hash = '#/purc/order/' + data.id;
  13274. }, function (response) {
  13275. $scope.loading = false;
  13276. toaster.pop('error', '保存失败', response.data);
  13277. });
  13278. };
  13279. // 新增收货地址保存
  13280. $scope.saveShipAddress = function (ship) {
  13281. ship.address = ship.province + ship.city + ship.district;
  13282. ShipAddress.saveAddress({}, ship, function (data) {
  13283. if (data.success) {
  13284. ShipAddress.shipAddList({}, function (data) {
  13285. $scope.ships = data;
  13286. $scope.order.shipadd = $scope.ships[0];
  13287. });
  13288. toaster.pop('success', '提示', data.success);
  13289. }
  13290. if (data.error) {
  13291. toaster.pop('error', '提示', data.error);
  13292. }
  13293. });
  13294. }
  13295. // 新增供应商联系人
  13296. $scope.addContact = function (uu) {
  13297. var modalInstance = $modal.open({
  13298. animation: true,
  13299. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13300. controller: 'AddContacCtrl',
  13301. resolve: {}
  13302. });
  13303. modalInstance.result.then(function (data) {
  13304. $scope.contact = data;
  13305. $scope.contact.venduu = uu;
  13306. Vendor.saveContact({}, $scope.contact, function (data) {
  13307. Vendor.contacts({venduu: $scope.order.cust.uu}, {}, function (data) {
  13308. $scope.contacts = data;
  13309. $scope.order.vendor = $scope.contacts[0];
  13310. });
  13311. toaster.pop('success', '提示', '联系人保存成功');
  13312. }, function (response) {
  13313. toaster.pop('error', '失败', response.data);
  13314. });
  13315. });
  13316. }
  13317. }]);
  13318. /**
  13319. * 采购批量导入
  13320. */
  13321. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  13322. // 通过excel批量上传物料
  13323. $scope.result = null;
  13324. $scope.loading = false;
  13325. $scope.upload = function () {
  13326. $scope.loading = true;
  13327. var file = $scope.myFiles[0];
  13328. $upload.upload({
  13329. url: 'purchase/release/excel',
  13330. file: file,
  13331. method: 'POST'
  13332. }).success(function (data) {
  13333. $scope.loading = false;
  13334. $scope.result = data;
  13335. $scope.success = $scope.result.success;
  13336. $scope.total = $scope.result.total;
  13337. $scope.alters = $scope.result.alters;
  13338. }).error(function (response) {
  13339. $scope.loading = false;
  13340. toaster.pop('error', response.data || response);
  13341. });
  13342. };
  13343. // 下载模板
  13344. $scope.download = function () {
  13345. window.location.href = 'purchase/upload/template';
  13346. };
  13347. $scope.enSure = function () {
  13348. $modalInstance.close($scope.result.products);
  13349. }
  13350. // 点击确定时增加加载标志
  13351. $scope.addClass = function() {
  13352. $scope.loading = true;
  13353. }
  13354. $scope.cancel = function () {
  13355. $modalInstance.dismiss();
  13356. }
  13357. }]);
  13358. // 查找供应商
  13359. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems) {
  13360. $scope.prod = false;
  13361. if (orderItems.length != 0) {
  13362. $scope.prod = true;
  13363. }
  13364. BaseService.scrollBackToTop();
  13365. if ($rootScope.venduu != null) {
  13366. $scope.venduu = $rootScope.venduu;
  13367. }
  13368. // 搜索框回车
  13369. $scope.onSearch = function (keyword) {
  13370. $scope.keyword = keyword;
  13371. $scope.customerParams.page(1);
  13372. $scope.customerParams.reload();
  13373. };
  13374. $scope.customerParams = new ngTableParams({
  13375. page: 1,
  13376. count: 20
  13377. }, {
  13378. total: 0,
  13379. counts: [5, 10, 25, 50],
  13380. getData: function ($defer, params) {
  13381. $scope.loading = true;
  13382. var pageParams = params.url();
  13383. pageParams.keyword = $scope.keyword;
  13384. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13385. $scope.loading = false;
  13386. if (page) {
  13387. params.total(page.totalElement);
  13388. $defer.resolve(page.content);
  13389. }
  13390. $scope.totalCount = page.totalElement;
  13391. }, function (response) {
  13392. $scope.loading = false;
  13393. toaster.pop('error', '数据加载失败', response.data);
  13394. });
  13395. }
  13396. });
  13397. $scope.cancel = function () {
  13398. $modalInstance.dismiss();
  13399. };
  13400. $scope.ensure = false;
  13401. $scope.check = function (vendor) { // 需要进行判断的选择
  13402. $scope.vendorInfo = vendor;
  13403. $scope.ensure = true;
  13404. };
  13405. $scope.checkVendor = function (vendor) { // 直接选择
  13406. $modalInstance.close(vendor);
  13407. }
  13408. }]);
  13409. /**
  13410. * 我的客户
  13411. */
  13412. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster) {
  13413. $scope.userInfoResult = true;
  13414. AuthenticationService.getAuthentication().success(function (data) {
  13415. $scope.loading = false;
  13416. $scope.thisUser = data;
  13417. });
  13418. var getCustInfos = function (custuu) {
  13419. if (custuu) {
  13420. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  13421. $scope.custInfos = data;
  13422. var getPage = function (page, size) {
  13423. if ($scope.custInfos) {
  13424. var result = {};
  13425. result.totalCount = $scope.custInfos.length;
  13426. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  13427. if ($scope.custInfos.length % size == 0) {
  13428. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  13429. } else {
  13430. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  13431. }
  13432. result.first = page == 1;
  13433. result.last = page == result.totalPage;
  13434. result.page = page;
  13435. result.next = page - 0 + 1;
  13436. result.pre = page - 1;
  13437. return result;
  13438. }
  13439. }
  13440. $scope.userdata = getPage(1, 4);
  13441. $scope.first = function () {
  13442. $scope.userdata = getPage($scope.userdata.pre, 4);
  13443. }
  13444. $scope.last = function () {
  13445. $scope.userdata = getPage($scope.userdata.next, 4);
  13446. }
  13447. }, function (response) {
  13448. $scope.loading = false;
  13449. toaster.pop('error', '数据加载失败', response.data);
  13450. });
  13451. }
  13452. }
  13453. // 分配权限
  13454. $scope.addUserInfo = function (customer) {
  13455. //TODO
  13456. if ($scope.thisUser.sys) {
  13457. var modalInstance = $modal.open({
  13458. animation: true,
  13459. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  13460. controller: 'AddUserInfoCtrl',
  13461. resolve: {
  13462. customer: function () {
  13463. return customer;
  13464. }
  13465. }
  13466. });
  13467. modalInstance.result.then(function (changed, checked) {
  13468. if (changed) {
  13469. if (checked)
  13470. $scope.newUser.roles = checked;
  13471. else
  13472. loadUsers();
  13473. }
  13474. });
  13475. } else {
  13476. toaster.pop('error', '您没有分配用户的权限!');
  13477. }
  13478. };
  13479. $scope.showUserInfo = function (customer, boo) {
  13480. $scope.custInfo = customer;
  13481. if (boo) {
  13482. getCustInfos(customer.myEnterprise.uu);
  13483. $scope.userInfoResult = true;
  13484. }
  13485. }
  13486. $scope.customerParams = new ngTableParams({
  13487. page: 1,
  13488. count: 20
  13489. }, {
  13490. total: 0,
  13491. counts: [5, 10, 25, 50],
  13492. getData: function ($defer, params) {
  13493. $scope.loading = true;
  13494. VendorService.customer.get(BaseService.parseParams(params.url()), function (page) {
  13495. $scope.loading = false;
  13496. if (page) {
  13497. params.total(page.totalElement);
  13498. $defer.resolve(page.content);
  13499. }
  13500. $scope.totalCount = page.totalElement;
  13501. }, function (response) {
  13502. $scope.loading = false;
  13503. toaster.pop('error', '数据加载失败', response.data);
  13504. });
  13505. }
  13506. });
  13507. }]);
  13508. /**
  13509. * 我的供应商
  13510. */
  13511. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  13512. BaseService.scrollBackToTop();
  13513. // 搜索框回车
  13514. $scope.onSearch = function (keyword) {
  13515. $scope.keyword = keyword;
  13516. $scope.customerParams.page(1);
  13517. $scope.customerParams.reload();
  13518. };
  13519. $scope.customerParams = new ngTableParams({
  13520. page: 1,
  13521. count: 20
  13522. }, {
  13523. total: 0,
  13524. counts: [5, 10, 25, 50],
  13525. getData: function ($defer, params) {
  13526. $scope.loading = true;
  13527. var pageParams = params.url();
  13528. pageParams.keyword = $scope.keyword;
  13529. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13530. $scope.loading = false;
  13531. if (page) {
  13532. params.total(page.totalElement);
  13533. $scope.total = page.totalElement;
  13534. $defer.resolve(page.content);
  13535. }
  13536. $scope.totalCount = page.totalElement;
  13537. }, function (response) {
  13538. $scope.loading = false;
  13539. toaster.pop('error', '数据加载失败', response.data);
  13540. });
  13541. }
  13542. });
  13543. //设置消息已读
  13544. var setOrdersRead = function () {
  13545. var ids=[];
  13546. Vendor.setVendorRead({}, ids, function (message) {
  13547. });
  13548. };
  13549. setOrdersRead();
  13550. // 查看供应商详情
  13551. $scope.VendorDetail = function (id, uu) {
  13552. $rootScope.vendorId = id;
  13553. $rootScope.vendoruu = uu;
  13554. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  13555. }
  13556. // 向企业购买
  13557. $scope.purcByEn = function (businessCode) {
  13558. $rootScope.businessCode = businessCode;
  13559. window.location.hash = "#/purc/addOrder";
  13560. }
  13561. }]);
  13562. /**
  13563. * 供应商详情
  13564. */
  13565. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  13566. BaseService.scrollBackToTop();
  13567. $scope.vendorContacts = [];
  13568. var loadData = function () {
  13569. Vendor.getVendorDetail({id: $stateParams.id}, {}, function (data) {
  13570. $scope.vendor = data.vendorEnterprise;
  13571. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  13572. $scope.vendorContacts = data;
  13573. });
  13574. });
  13575. };
  13576. loadData();
  13577. // 新增供应商联系人
  13578. $scope.addContact = function (uu) {
  13579. var modalInstance = $modal.open({
  13580. animation: true,
  13581. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13582. controller: 'AddContacCtrl',
  13583. resolve: {}
  13584. });
  13585. modalInstance.result.then(function (data) {
  13586. $scope.contact = data;
  13587. $scope.contact.venduu = uu;
  13588. Vendor.saveContact({}, $scope.contact, function (data) {
  13589. toaster.pop('success', '提示', '联系人保存成功');
  13590. $scope.vendorContacts.push(data);
  13591. }, function (response) {
  13592. toaster.pop('error', '失败', response.data);
  13593. });
  13594. });
  13595. };
  13596. // 编辑供应商联系人
  13597. $scope.edit = function (contact) {
  13598. var modalInstance = $modal.open({
  13599. animation: true,
  13600. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13601. controller: 'EditContacCtrl',
  13602. resolve: {
  13603. contact: function () {
  13604. return contact;
  13605. }
  13606. }
  13607. });
  13608. modalInstance.result.then(function (data) {
  13609. Vendor.saveContact({}, data, function (data) {
  13610. loadData();
  13611. toaster.pop('success', '提示', '联系人修改成功');
  13612. }, function (response) {
  13613. toaster.pop('error', '失败', response.data);
  13614. });
  13615. });
  13616. }
  13617. // 删除供应商联系人
  13618. $scope.deleteById = function (id, index) {
  13619. $scope.vendorContacts.splice(index, 1);
  13620. Vendor.deleteContact({id: id}, {}, function (data) {
  13621. toaster.pop('success', '提示', '供应商联系人删除成功');
  13622. loadData();
  13623. }, function (response) {
  13624. toaster.pop('error', '提示', response.data);
  13625. });
  13626. }
  13627. // 供应商物料信息
  13628. $scope.viewProdList = function (uu) {
  13629. $scope.uu = uu;
  13630. $scope.tableParams.page(1);
  13631. $scope.tableParams.reload();
  13632. };
  13633. // 搜索框回车
  13634. $scope.onSearch = function (keyword) {
  13635. $scope.keyword = keyword;
  13636. $scope.tableParams.page(1);
  13637. $scope.tableParams.reload();
  13638. };
  13639. // 供应商物料信息
  13640. $scope.tableParams = new ngTableParams({
  13641. page: 1,
  13642. count: 20
  13643. }, {
  13644. total: 0,
  13645. counts: [5, 10, 25, 50],
  13646. getData: function ($defer, params) {
  13647. $scope.loading = true;
  13648. var pageParams = params.url();
  13649. pageParams.custUU = $scope.uu;
  13650. pageParams.keyword = $scope.keyword;
  13651. $scope.tip = $scope.keyword;
  13652. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  13653. $scope.loading = false;
  13654. if (page) {
  13655. params.total(page.totalElement);
  13656. $scope.total = page.totalElement;
  13657. $defer.resolve(page.content);
  13658. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13659. }
  13660. }, function (response) {
  13661. $scope.loading = false;
  13662. toaster.pop('error', '数据加载失败', response.data);
  13663. });
  13664. }
  13665. });
  13666. /**
  13667. * 选中单个物料购买
  13668. * @param businessCode
  13669. * @param id
  13670. */
  13671. $scope.PurcByEnAndProd = function (businessCode, id) {
  13672. $rootScope.businessCode = businessCode;
  13673. $rootScope.prodId = id;
  13674. window.location.hash = "#/purc/addOrder";
  13675. }
  13676. /**
  13677. * 询价
  13678. */
  13679. $scope.PurcInquiry = function (businessCode, id) {
  13680. $rootScope.prodId = id;
  13681. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  13682. }
  13683. }]);
  13684. /**
  13685. * 编辑供应商联系人
  13686. */
  13687. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function ($scope, toaster, $modalInstance, contact) {
  13688. $scope.contact = angular.copy(contact);
  13689. $scope.save = function (contact) {
  13690. $modalInstance.close(contact);
  13691. };
  13692. $scope.cancel = function () {
  13693. $modalInstance.dismiss();
  13694. }
  13695. }]);
  13696. /**
  13697. * 新增供应商联系人
  13698. */
  13699. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function ($scope, toaster, $modalInstance) {
  13700. $scope.save = function (contact) {
  13701. $modalInstance.close(contact);
  13702. };
  13703. $scope.cancel = function () {
  13704. $modalInstance.dismiss();
  13705. }
  13706. }]);
  13707. /**
  13708. * 建立合作关系申请 (我的合作伙伴)
  13709. */
  13710. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  13711. BaseService.scrollBackToTop();
  13712. $scope.status = "partner";
  13713. $scope.active = 'done';
  13714. var getRequestStatus = function (active) {
  13715. var fn = 'getAllRequest';
  13716. switch (active) {
  13717. case 'done':
  13718. fn = 'getRequestDone';
  13719. break;
  13720. case 'todo':
  13721. fn = 'getRequestTodo';
  13722. break;
  13723. case 'end':
  13724. fn = 'getRequestEnd';
  13725. break;
  13726. }
  13727. return fn;
  13728. }
  13729. // 切换单据类型
  13730. $scope.setActive = function (state) {
  13731. if ($scope.active != state) {
  13732. $scope.active = state;
  13733. if ($scope.tableParams.page() == 1)
  13734. $scope.tableParams.reload();
  13735. else
  13736. $scope.tableParams.page(1);
  13737. }
  13738. };
  13739. // 切换数据来源(正常数据 or 历史数据)
  13740. var getService = function () {
  13741. return AddPartnerMyRequest;
  13742. };
  13743. $scope.tableParams = new ngTableParams({ // ng-Table参数
  13744. page: 1,
  13745. count: 20,
  13746. sorting: {}
  13747. }, {
  13748. total: 0,
  13749. counts: [],
  13750. getData: function ($defer, params) { // 获取数据的方法
  13751. $scope.loading = true;
  13752. var pageParams = params.url();
  13753. pageParams.keyword = $scope.keyword;
  13754. if ($rootScope.vendName) {
  13755. pageParams.keyword = $rootScope.vendName;
  13756. $scope.keyword = $rootScope.vendName;
  13757. $rootScope.vendName = null;
  13758. }
  13759. $scope.tip = $scope.keyword;
  13760. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  13761. $scope.loading = false;
  13762. if (page) {
  13763. params.total(page.totalElement);
  13764. $defer.resolve(page.content);
  13765. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13766. }
  13767. }, function (response) {
  13768. $scope.loading = false;
  13769. toaster.pop('error', '数据加载失败', response.data);
  13770. });
  13771. }
  13772. });
  13773. // 再次申请
  13774. $scope.addAgain = function (name, businessCode) {
  13775. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  13776. if (data.success) {
  13777. toaster.pop("success", '添加成功', data.success);
  13778. $scope.tableParams.reload();
  13779. }
  13780. if (data.error) {
  13781. toaster.pop("error", '添加失败', data.error);
  13782. }
  13783. }, function (response) {
  13784. toaster.pop('error', '失败', response.data);
  13785. });
  13786. }
  13787. // 添加为供应商
  13788. $scope.addSupplier = function (vendUID) {
  13789. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  13790. if (data.success) {
  13791. toaster.pop('success', '提示', data.success);
  13792. $scope.tableParams.reload();
  13793. }
  13794. if (data.error) {
  13795. toaster.pop('error', '提示', data.error);
  13796. }
  13797. }, function (response) {
  13798. toaster.pop('error', '失败', response.data);
  13799. })
  13800. };
  13801. // 添加为供应商
  13802. $scope.addServicer = function (vendUID) {
  13803. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  13804. if (data.success) {
  13805. toaster.pop('success', '提示', data.success);
  13806. $scope.tableParams.reload();
  13807. }
  13808. if (data.error) {
  13809. toaster.pop('error', '提示', data.error);
  13810. }
  13811. }, function (response) {
  13812. toaster.pop('error', '失败', response.data);
  13813. })
  13814. };
  13815. // 添加客户
  13816. $scope.addCust = function (vendUID) {
  13817. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  13818. if (data.success) {
  13819. toaster.pop('success', '提示', data.success);
  13820. $scope.tableParams.reload();
  13821. }
  13822. if (data.error) {
  13823. toaster.pop('error', '提示', data.error);
  13824. }
  13825. }, function (response) {
  13826. toaster.pop('error', '失败', response.data);
  13827. })
  13828. };
  13829. // 搜索框回车
  13830. $scope.onSearch = function () {
  13831. $scope.tableParams.page(1);
  13832. $scope.tableParams.reload();
  13833. };
  13834. // 同意申请
  13835. $scope.agree = function (id) {
  13836. AddPartner.agreeRequest({id: id}, {}, function (data) {
  13837. if (data.success) {
  13838. toaster.pop('success', '提示', '操作成功');
  13839. }
  13840. if (data.error) {
  13841. toaster.pop('error', '提示', '操作失败');
  13842. }
  13843. // $scope.tableParams.reload();
  13844. $window.location.reload();
  13845. }, function (response) {
  13846. toaster.pop('error', '提示', response.data);
  13847. });
  13848. };
  13849. // 拒绝申请
  13850. $scope.refuse = function (id, reason) {
  13851. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  13852. if (data.success) {
  13853. toaster.pop('success', '提示', '操作成功');
  13854. }
  13855. if (data.error) {
  13856. toaster.pop('error', '提示', '操作失败');
  13857. }
  13858. // $scope.tableParams.reload();
  13859. $window.location.reload();
  13860. }, function (response) {
  13861. toaster.pop('error', '提示', response.data);
  13862. });
  13863. };
  13864. // 取消供应商关系
  13865. $scope.relieve = function (id) {
  13866. VendorInfo.relieve({id: id}, {}, function (data) {
  13867. if (data.success) {
  13868. toaster.pop('success', '提示', data.success);
  13869. }
  13870. // $scope.tableParams.page(1);
  13871. $scope.tableParams.reload();
  13872. }, function (response) {
  13873. toaster.pop('error', '提示', response.data);
  13874. });
  13875. };
  13876. // 建立供应商关系
  13877. $scope.activeVend = function (id) {
  13878. VendorInfo.activeVend({id: id}, {}, function (data) {
  13879. if (data.success) {
  13880. toaster.pop('success', '提示', data.success);
  13881. }
  13882. // $scope.tableParams.page(1);
  13883. $scope.tableParams.reload();
  13884. }, function (response) {
  13885. toaster.pop('error', '提示', response.data);
  13886. });
  13887. };
  13888. // 取消服务商
  13889. $scope.relieveServicer = function (id) {
  13890. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  13891. if (data.success) {
  13892. toaster.pop('success', '提示', data.success);
  13893. }
  13894. $scope.tableParams.reload();
  13895. }, function (response) {
  13896. toaster.pop('error', '提示', response.data);
  13897. });
  13898. };
  13899. // 启用服务商
  13900. $scope.activeServicer = function (id) {
  13901. VendorInfo.activeServicer({id: id}, {}, function (data) {
  13902. if (data.success) {
  13903. toaster.pop('success', '提示', data.success);
  13904. }
  13905. $scope.tableParams.reload();
  13906. }, function (response) {
  13907. toaster.pop('error', '提示', response.data);
  13908. });
  13909. };
  13910. // 取消客户关系
  13911. $scope.disableCust = function (id) {
  13912. VendorInfo.disableCust({id: id}, {}, function (data) {
  13913. if (data.success) {
  13914. toaster.pop('success', '提示', data.success);
  13915. }
  13916. $scope.tableParams.page(1);
  13917. $scope.tableParams.reload();
  13918. }, function (response) {
  13919. toaster.pop('error', '提示', response.data);
  13920. });
  13921. };
  13922. // 激活客户关系
  13923. $scope.activeCust = function (id) {
  13924. VendorInfo.activeCust({id: id}, {}, function (data) {
  13925. if (data.success) {
  13926. toaster.pop('success', '提示', data.success);
  13927. }
  13928. $scope.tableParams.page(1);
  13929. $scope.tableParams.reload();
  13930. }, function (response) {
  13931. toaster.pop('error', '提示', response.data);
  13932. });
  13933. }
  13934. }]);
  13935. /**
  13936. * 建立合作关系申请 (新的合作伙伴)
  13937. */
  13938. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  13939. BaseService.scrollBackToTop();
  13940. $scope.status = "partner";
  13941. $scope.active = 'all'; // 所有申请记录
  13942. var getRequestStatus = function (active) {
  13943. var fn = 'getAllRequest';
  13944. switch (active) {
  13945. case 'done':
  13946. fn = 'getRequestDone';
  13947. break;
  13948. case 'todo':
  13949. fn = 'getRequestTodo';
  13950. break;
  13951. case 'end':
  13952. fn = 'getRequestEnd';
  13953. break;
  13954. }
  13955. return fn;
  13956. }
  13957. // 切换单据类型
  13958. $scope.setActive = function (state) {
  13959. if ($scope.active != state) {
  13960. $scope.active = state;
  13961. if ($scope.tableParams.page() == 1)
  13962. $scope.tableParams.reload();
  13963. else
  13964. $scope.tableParams.page(1);
  13965. }
  13966. };
  13967. // 切换数据来源(正常数据 or 历史数据)
  13968. var getService = function () {
  13969. return AddPartnerMyRequest;
  13970. };
  13971. $scope.tableParams = new ngTableParams({ // ng-Table参数
  13972. page: 1,
  13973. count: 20,
  13974. sorting: {}
  13975. }, {
  13976. total: 0,
  13977. counts: [],
  13978. getData: function ($defer, params) { // 获取数据的方法
  13979. $scope.loading = true;
  13980. var pageParams = params.url();
  13981. pageParams.keyword = $scope.keyword;
  13982. if ($rootScope.vendName) {
  13983. pageParams.keyword = $rootScope.vendName;
  13984. $scope.keyword = $rootScope.vendName;
  13985. $rootScope.vendName = null;
  13986. }
  13987. $scope.tip = $scope.keyword;
  13988. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  13989. $scope.loading = false;
  13990. if (page) {
  13991. params.total(page.totalElement);
  13992. $defer.resolve(page.content);
  13993. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13994. }
  13995. }, function (response) {
  13996. $scope.loading = false;
  13997. toaster.pop('error', '数据加载失败', response.data);
  13998. });
  13999. }
  14000. });
  14001. // 再次申请
  14002. $scope.addAgain = function (name, businessCode) {
  14003. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14004. if (data.success) {
  14005. toaster.pop("success", '添加成功', data.success);
  14006. $scope.tableParams.reload();
  14007. }
  14008. if (data.error) {
  14009. toaster.pop("error", '添加失败', data.error);
  14010. }
  14011. }, function (response) {
  14012. toaster.pop('error', '失败', response.data);
  14013. });
  14014. }
  14015. // 添加为供应商
  14016. $scope.addSupplier = function (vendUID) {
  14017. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14018. if (data.success) {
  14019. toaster.pop('success', '提示', data.success);
  14020. $scope.tableParams.reload();
  14021. }
  14022. if (data.error) {
  14023. toaster.pop('error', '提示', data.error);
  14024. }
  14025. }, function (response) {
  14026. toaster.pop('error', '失败', response.data);
  14027. })
  14028. };
  14029. // 添加为供应商
  14030. $scope.addServicer = function (vendUID) {
  14031. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14032. if (data.success) {
  14033. toaster.pop('success', '提示', data.success);
  14034. $scope.tableParams.reload();
  14035. }
  14036. if (data.error) {
  14037. toaster.pop('error', '提示', data.error);
  14038. }
  14039. }, function (response) {
  14040. toaster.pop('error', '失败', response.data);
  14041. })
  14042. };
  14043. // 添加客户
  14044. $scope.addCust = function (vendUID) {
  14045. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14046. if (data.success) {
  14047. toaster.pop('success', '提示', data.success);
  14048. $scope.tableParams.reload();
  14049. }
  14050. if (data.error) {
  14051. toaster.pop('error', '提示', data.error);
  14052. }
  14053. }, function (response) {
  14054. toaster.pop('error', '失败', response.data);
  14055. })
  14056. };
  14057. // 搜索框回车
  14058. $scope.onSearch = function () {
  14059. $scope.tableParams.page(1);
  14060. $scope.tableParams.reload();
  14061. };
  14062. // 同意申请
  14063. $scope.agree = function (id) {
  14064. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14065. if (data.success) {
  14066. toaster.pop('success', '提示', '操作成功');
  14067. }
  14068. if (data.error) {
  14069. toaster.pop('error', '提示', '操作失败');
  14070. }
  14071. // $scope.tableParams.reload();
  14072. $window.location.reload();
  14073. }, function (response) {
  14074. toaster.pop('error', '提示', response.data);
  14075. });
  14076. };
  14077. AddPartnerMyRequest.requestAmount({}, function (data) {
  14078. $scope.requestTodo = data;
  14079. });
  14080. // 拒绝申请
  14081. $scope.refuse = function (id, reason) {
  14082. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14083. if (data.success) {
  14084. toaster.pop('success', '提示', '操作成功');
  14085. }
  14086. if (data.error) {
  14087. toaster.pop('error', '提示', '操作失败');
  14088. }
  14089. // $scope.tableParams.reload();
  14090. $window.location.reload();
  14091. }, function (response) {
  14092. toaster.pop('error', '提示', response.data);
  14093. });
  14094. };
  14095. // 取消供应商关系
  14096. $scope.relieve = function (id) {
  14097. VendorInfo.relieve({id: id}, {}, function (data) {
  14098. if (data.success) {
  14099. toaster.pop('success', '提示', data.success);
  14100. }
  14101. // $scope.tableParams.page(1);
  14102. $scope.tableParams.reload();
  14103. }, function (response) {
  14104. toaster.pop('error', '提示', response.data);
  14105. });
  14106. }
  14107. // 建立供应商关系
  14108. $scope.activeVend = function (id) {
  14109. VendorInfo.activeVend({id: id}, {}, function (data) {
  14110. if (data.success) {
  14111. toaster.pop('success', '提示', data.success);
  14112. }
  14113. // $scope.tableParams.page(1);
  14114. $scope.tableParams.reload();
  14115. }, function (response) {
  14116. toaster.pop('error', '提示', response.data);
  14117. });
  14118. }
  14119. // 取消服务商
  14120. $scope.relieveServicer = function (id) {
  14121. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14122. if (data.success) {
  14123. toaster.pop('success', '提示', data.success);
  14124. }
  14125. $scope.tableParams.reload();
  14126. }, function (response) {
  14127. toaster.pop('error', '提示', response.data);
  14128. });
  14129. }
  14130. // 启用服务商
  14131. $scope.activeServicer = function (id) {
  14132. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14133. if (data.success) {
  14134. toaster.pop('success', '提示', data.success);
  14135. }
  14136. $scope.tableParams.reload();
  14137. }, function (response) {
  14138. toaster.pop('error', '提示', response.data);
  14139. });
  14140. }
  14141. // 取消客户关系
  14142. $scope.disableCust = function (id) {
  14143. VendorInfo.disableCust({id: id}, {}, function (data) {
  14144. if (data.success) {
  14145. toaster.pop('success', '提示', data.success);
  14146. }
  14147. // $scope.tableParams.page(1);
  14148. $scope.tableParams.reload();
  14149. }, function (response) {
  14150. toaster.pop('error', '提示', response.data);
  14151. });
  14152. }
  14153. // 激活客户关系
  14154. $scope.activeCust = function (id) {
  14155. VendorInfo.activeCust({id: id}, {}, function (data) {
  14156. if (data.success) {
  14157. toaster.pop('success', '提示', data.success);
  14158. }
  14159. // $scope.tableParams.page(1);
  14160. $scope.tableParams.reload();
  14161. }, function (response) {
  14162. toaster.pop('error', '提示', response.data);
  14163. });
  14164. }
  14165. }]);
  14166. /**
  14167. * 建立合作关系处理申请
  14168. */
  14169. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', '$window', function ($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest, $window) {
  14170. BaseService.scrollBackToTop();
  14171. $scope.active = 'todo';
  14172. var getMessagetStatus = function (active) {
  14173. var fn = 'getAllMessage';
  14174. switch (active) {
  14175. case 'done':
  14176. fn = 'getMessageDone';
  14177. break;
  14178. case 'todo':
  14179. fn = 'getMessageTodo';
  14180. break;
  14181. case 'end':
  14182. fn = 'getMessageEnd';
  14183. break;
  14184. }
  14185. return fn;
  14186. }
  14187. // 切换单据类型
  14188. $scope.setActive = function (state) {
  14189. if ($scope.active != state) {
  14190. $scope.active = state;
  14191. if ($scope.tableParams.page() == 1)
  14192. $scope.tableParams.reload();
  14193. else
  14194. $scope.tableParams.page(1);
  14195. }
  14196. };
  14197. var getService = function () {
  14198. return AddPartnerMyMessage;
  14199. };
  14200. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14201. page: 1,
  14202. count: 20,
  14203. sorting: {}
  14204. }, {
  14205. total: 0,
  14206. counts: [5, 10, 15, 25, 50],
  14207. getData: function ($defer, params) { // 获取数据的方法
  14208. $scope.loading = true;
  14209. var pageParams = params.url();
  14210. pageParams.searchFilter = { // 筛选条件
  14211. keyword: $scope.keyword,
  14212. };
  14213. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14214. $scope.loading = false;
  14215. if (page) {
  14216. params.total(page.totalElement);
  14217. $defer.resolve(page.content);
  14218. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14219. }
  14220. }, function (response) {
  14221. $scope.loading = false;
  14222. toaster.pop('error', '数据加载失败', response.data);
  14223. });
  14224. }
  14225. });
  14226. // 同意申请
  14227. $scope.agree = function (id) {
  14228. AddPartner.agreeReq
  14229. uest({id: id}, {}, function (data) {
  14230. if (data.success) {
  14231. toaster.pop('success', '提示', '操作成功');
  14232. }
  14233. if (data.error) {
  14234. toaster.pop('error', '提示', '操作失败');
  14235. }
  14236. // $scope.tableParams.reload();
  14237. $window.location.reload();
  14238. }, function (response) {
  14239. toaster.pop('error', '提示', response.data);
  14240. });
  14241. };
  14242. // 拒绝申请
  14243. $scope.refuse = function (id, reason) {
  14244. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14245. if (data.success) {
  14246. toaster.pop('success', '提示', '操作成功');
  14247. }
  14248. if (data.error) {
  14249. toaster.pop('error', '提示', '操作失败');
  14250. }
  14251. // $scope.tableParams.reload();
  14252. $window.location.reload();
  14253. }, function (response) {
  14254. toaster.pop('error', '提示', response.data);
  14255. });
  14256. };
  14257. $scope.status = 'get';
  14258. }]);
  14259. /**
  14260. * 我的合作伙伴
  14261. */
  14262. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function ($scope, toaster, GetProductInfo, BaseService) {
  14263. BaseService.scrollBackToTop();
  14264. // 默认显示合作伙伴
  14265. $scope.status = 'news';
  14266. // 获取所有的合作伙伴
  14267. GetProductInfo.getAllPartners({}, function (data) {
  14268. $scope.partners = data;
  14269. }, function (res) {
  14270. toaster.pop('error', '获取列表失败', res.data);
  14271. });
  14272. // 添加为客户
  14273. $scope.addCust = function (partner) {
  14274. GetProductInfo.addCust({}, partner, function (data) {
  14275. toaster.pop('success', '提示', '添加客户成功');
  14276. $scope.tableParams.reload();
  14277. }, function (response) {
  14278. toaster.pop('error', '添加客户失败', response.data);
  14279. });
  14280. }
  14281. // 添加为供应商
  14282. $scope.addSupplier = function (partner) {
  14283. GetProductInfo.addSupplier({}, partner, function (data) {
  14284. toaster.pop('success', '提示', '添加供应商成功');
  14285. $scope.tableParams.reload();
  14286. }, function (response) {
  14287. toaster.pop('error', '添加供应商失败', response.data);
  14288. });
  14289. }
  14290. }]);
  14291. /**
  14292. * 财务对账时,企业进行筛选操作
  14293. */
  14294. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', 'VendorService', 'ngTableParams', 'BaseService', function ($scope, $modalInstance, suuorname, FaApCheck, VendorService, ngTableParams, BaseService) {
  14295. var getData = function () {
  14296. $scope.loading = true;
  14297. FaApCheck.getAllCustomers(function (data) {
  14298. $scope.custs = data;
  14299. $scope.loading = false;
  14300. });
  14301. };
  14302. getData();
  14303. $scope.customerParams = new ngTableParams({
  14304. page: 1,
  14305. count: 20
  14306. }, {
  14307. total: 0,
  14308. counts: [5, 10, 25, 50],
  14309. getData: function ($defer, params) {
  14310. $scope.loading = true;
  14311. var pageParams = params.url();
  14312. pageParams.keyword = $scope.keyword;
  14313. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  14314. $scope.loading = false;
  14315. if (page) {
  14316. params.total(page.totalElement);
  14317. $defer.resolve(page.content);
  14318. }
  14319. $scope.totalCount = page.totalElement;
  14320. }, function (response) {
  14321. $scope.loading = false;
  14322. toaster.pop('error', '数据加载失败', response.data);
  14323. });
  14324. }
  14325. });
  14326. // 搜索框回车
  14327. $scope.onSearch = function (keyword) {
  14328. $scope.customerParams.page(1);
  14329. $scope.customerParams.reload();
  14330. $scope.tip = keyword;
  14331. };
  14332. $scope.select = function (customer) {
  14333. $modalInstance.close(customer);
  14334. }
  14335. $scope.close = function () {
  14336. $modalInstance.dismiss();
  14337. }
  14338. }]);
  14339. /**
  14340. * 跳转到企业圈
  14341. */
  14342. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function ($scope, GetProductInfo, toaster) {
  14343. GetProductInfo.businessGroups({}, function (data) {
  14344. window.open(data.url);
  14345. }, function (response) {
  14346. toaster.pop('error', '提示', response.data);
  14347. });
  14348. }]);
  14349. /**
  14350. * 购物车
  14351. */
  14352. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', 'cartList', 'PurchaseOrder', function ($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout, cartList, PurchaseOrder) {
  14353. BaseService.scrollBackToTop();
  14354. $scope.active = 'all';
  14355. $scope.agreedText = '全部';
  14356. $scope.dateZoneText = '一个月内';
  14357. $scope.condition = {dateZone: 1};
  14358. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14359. $scope.hasClick = false;
  14360. /* 时间筛选初始化*/
  14361. var fromDate = new Date();
  14362. var toDate = new Date();
  14363. fromDate.setMonth(fromDate.getMonth() - 1);
  14364. fromDate.setHours(0, 0, 0, 0);
  14365. toDate.setHours(23, 59, 59, 999);
  14366. $scope.condition.dateFrom = fromDate;
  14367. $scope.condition.dateTo = toDate;
  14368. $scope.changeDateZone = function (zone) {
  14369. $scope.condition.dateZone = zone;
  14370. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14371. $scope.condition.$dateZoneOpen = false;
  14372. getDateCondition(zone, $scope.condition);
  14373. $scope.tableParams.page(1);
  14374. $scope.tableParams.reload();
  14375. };
  14376. $scope.changeDeliveryZone = function (zone) {
  14377. $scope.condition.deliveryZoneText = zone;
  14378. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  14379. $scope.condition.$delievryZoneOpen = false;
  14380. getDelveryCondition(zone, $scope.condition);
  14381. $scope.tableParams.reload();
  14382. };
  14383. $scope.setActive = function (state) {
  14384. if ($scope.active != state) {
  14385. $scope.active = state;
  14386. if ($scope.tableParams.page() == 1)
  14387. $scope.tableParams.reload();
  14388. else
  14389. $scope.tableParams.page(1);
  14390. }
  14391. };
  14392. $scope.searchMethod = false;
  14393. var getService = function () {
  14394. return $scope.searchMethod ? cartList : getCartList;
  14395. };
  14396. var getTodoCartCount = function () {
  14397. cartOperation.getTodoCartCount({}, function (data) {
  14398. $scope.countTodo = data.cartTodo;
  14399. });
  14400. };
  14401. getTodoCartCount();
  14402. $scope.tableParams = new ngTableParams({
  14403. page: 1,
  14404. count: 20,
  14405. sorting: {
  14406. date: 'desc'
  14407. }
  14408. }, {
  14409. total: 0,
  14410. counts: [5, 10, 25, 50],
  14411. getData: function ($defer, params) {
  14412. $scope.loading = true;
  14413. var pageParams = params.url();
  14414. pageParams.searchFilter = { // 筛选条件
  14415. keyword: $scope.keyword,
  14416. fromDate: getDateTime($scope.condition.dateFrom),
  14417. endDate: getDateTime($scope.condition.dateTo)
  14418. };
  14419. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14420. $scope.loading = false;
  14421. if (page) {
  14422. params.total(page.totalElement);
  14423. $defer.resolve(page.content);
  14424. }
  14425. }, function (response) {
  14426. $scope.loading = false;
  14427. toaster.pop('error', '数据加载失败', response.data);
  14428. });
  14429. }
  14430. });
  14431. $scope.getCartTotal = function (items) {
  14432. var sum = 0;
  14433. angular.forEach(items, function (item) {
  14434. sum += item.qty * item.price;
  14435. });
  14436. return sum;
  14437. };
  14438. // 搜索框回车
  14439. $scope.onSearch = function (keyword) {
  14440. // 每次搜索重置获取数据方法
  14441. $scope.searchMethod = false;
  14442. if(keyword != null && keyword != '') {
  14443. $scope.searchMethod = true;
  14444. }
  14445. $scope.tableParams.page(1);
  14446. $scope.tableParams.reload();
  14447. };
  14448. var changeClickStatus = function () {
  14449. $scope.hasClick = true;
  14450. $timeout(function () {
  14451. $scope.hasClick = false;
  14452. }, 500);
  14453. }
  14454. // 提交
  14455. $scope.addtoOrder = function (id) {
  14456. cartOperation.addToOrder({id: id}, {}, function (data) {
  14457. if (data.success) {
  14458. toaster.pop('success', '提示', data.success);
  14459. getTodoCartCount();
  14460. $timeout(function () {
  14461. window.location.hash = '#/purc/order/' + data.id;
  14462. window.location.reload();
  14463. }, 500);
  14464. }
  14465. if (data.error) {
  14466. toaster.pop('error', '提示', data.error);
  14467. }
  14468. }, function (response) {
  14469. toaster.pop('erroer', '提示', response.data);
  14470. });
  14471. };
  14472. // 删除一条主记录
  14473. $scope.deleteCart = function (id) {
  14474. changeClickStatus();
  14475. $scope.loading = true;
  14476. cartOperation.deleteCart({id: id}, {}, function (data) {
  14477. if (data.success) {
  14478. toaster.pop('success', '提示', data.success);
  14479. getTodoCartCount();
  14480. getTodoCartCount();
  14481. $timeout(function () {
  14482. $scope.tableParams.page(1);
  14483. $scope.tableParams.reload();
  14484. }, 500);
  14485. }
  14486. if (data.error) {
  14487. toaster.pop('error', '提示', data.error);
  14488. }
  14489. $scope.loading = false;
  14490. }, function (response) {
  14491. $scope.loading = false;
  14492. toaster.pop('erroer', '提示', response.data);
  14493. });
  14494. };
  14495. // 删除一条明细
  14496. $scope.deleteDetail = function (id) {
  14497. changeClickStatus();
  14498. $scope.loading = true;
  14499. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14500. if (data.success) {
  14501. toaster.pop('success', '提示', data.success);
  14502. $timeout(function () {
  14503. $scope.tableParams.reload();
  14504. }, 500);
  14505. }
  14506. if (data.error) {
  14507. toaster.pop('error', '提示', data.error);
  14508. }
  14509. $scope.loading = false;
  14510. }, function (response) {
  14511. toaster.pop('erroer', '提示', response.data);
  14512. $scope.loading = false;
  14513. });
  14514. };
  14515. // 清空购物车
  14516. $scope.clearCart = function () {
  14517. changeClickStatus();
  14518. $scope.loading = true;
  14519. cartOperation.deleteCarts({}, function (data) {
  14520. if (data.success) {
  14521. toaster.pop('success', '提示', data.success);
  14522. getTodoCartCount();
  14523. $timeout(function () {
  14524. $scope.tableParams.reload();
  14525. }, 500);
  14526. }
  14527. if (data.error) {
  14528. toaster.pop('error', '提示', data.error);
  14529. }
  14530. $scope.loading = false;
  14531. }, function (response) {
  14532. toaster.pop('erroer', '提示', response.data);
  14533. $scope.loading = false;
  14534. });
  14535. }
  14536. // 复制订单
  14537. $scope.copyorder = function (id) {
  14538. changeClickStatus();
  14539. $scope.loading = true;
  14540. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  14541. if (data.id) {
  14542. toaster.pop('success', '提示', '单据复制成功');
  14543. getTodoCartCount();
  14544. $scope.loading = false;
  14545. window.location.hash = "#purc/cart/" + data.id;
  14546. }
  14547. }, function (response) {
  14548. toaster.pop('error', '提示', response.data);
  14549. $scope.loading = false;
  14550. });
  14551. }
  14552. }]);
  14553. /**
  14554. * 购物车详情
  14555. */
  14556. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token) {
  14557. BaseService.scrollBackToTop();
  14558. $scope.loading = true;
  14559. var loadData = function () {
  14560. cartOperation.getCartDetail({id: $stateParams.id}, function (data) {
  14561. if (data.code) {
  14562. $scope.order = data;
  14563. var sum = 0;
  14564. angular.forEach($scope.order.orderItems, function (item) {
  14565. sum += item.qty * item.price;
  14566. });
  14567. $scope.order.total = sum;
  14568. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  14569. $scope.contacts = data;
  14570. $scope.order.vendor = $scope.order.venduser;
  14571. });
  14572. $scope.loading = false;
  14573. } else {
  14574. window.location.hash = '#/purc/cart';
  14575. }
  14576. });
  14577. };
  14578. loadData();
  14579. var getToken = function() {
  14580. token.info({userType: 'cart'}, {}, function(data) {
  14581. $scope.token = data.token;
  14582. }, function(response) {
  14583. toaster.pop('error', '提示', response.data);
  14584. });
  14585. }
  14586. getToken();
  14587. // 获取地址信息
  14588. $http.get('resources/citydata/city.json', {
  14589. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  14590. }).then(function (response) {
  14591. $scope.provinces = response.data;
  14592. });
  14593. // 获取收货地址列表
  14594. ShipAddress.shipAddList({}, function (data) {
  14595. $scope.ships = data;
  14596. $scope.order.shipadd = $scope.ships[0];
  14597. });
  14598. //增加商品
  14599. $scope.addProduct = function (index) {
  14600. if ($scope.order.orderItems[index].code == null) {
  14601. toaster.pop('info', '提示', '请先选择商品');
  14602. } else {
  14603. $scope.order.orderItems.push({
  14604. code: null,
  14605. title: null,
  14606. spec: null,
  14607. unit: null,
  14608. qty: null,
  14609. price: null,
  14610. remark: null,
  14611. delivery: null,
  14612. $endDateOpen: false,
  14613. taxrate: $scope.order.rate
  14614. });
  14615. }
  14616. };
  14617. //删除商品
  14618. $scope.deleteProduct = function (index, id) {
  14619. $scope.order.orderItems.splice(index, 1);
  14620. if (id != null) {
  14621. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14622. if (data.success) {
  14623. loadData();
  14624. }
  14625. if (data.error) {
  14626. toaster.pop('error', '提示', data.error);
  14627. }
  14628. }, function (response) {
  14629. toaster.pop('erroer', '提示', response.data);
  14630. });
  14631. }
  14632. };
  14633. // 搜索框回车
  14634. $scope.onSearch = function (keyword) {
  14635. $scope.keyword = keyword;
  14636. $scope.tableParams.page(1);
  14637. $scope.tableParams.reload();
  14638. };
  14639. $scope.tableParams = new ngTableParams({
  14640. page: 1,
  14641. count: 20
  14642. }, {
  14643. total: 0,
  14644. counts: [5, 10, 25, 50],
  14645. getData: function ($defer, params) {
  14646. $scope.loading = true;
  14647. var pageParams = params.url();
  14648. pageParams.keyword = $scope.keyword;
  14649. $scope.tip = $scope.keyword;
  14650. pageParams.custUU = $scope.order.receiveCode;
  14651. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  14652. $scope.loading = false;
  14653. if (page) {
  14654. params.total(page.totalElement);
  14655. $scope.total = page.totalElement;
  14656. $defer.resolve(page.content);
  14657. }
  14658. }, function (response) {
  14659. $scope.loading = false;
  14660. toaster.pop('error', '数据加载失败', response.data);
  14661. });
  14662. }
  14663. });
  14664. // 选择
  14665. $scope.check = function (data) {
  14666. $scope.order.orderItems.push({
  14667. code: data.code,
  14668. title: data.title,
  14669. spec: data.spec,
  14670. unit: data.unit,
  14671. qty: null,
  14672. price: null,
  14673. remark: null,
  14674. delivery: null,
  14675. prid: data.id,
  14676. rate: $scope.order.rate
  14677. });
  14678. };
  14679. // 导入商品信息
  14680. $scope.uplodaByBatch = function () {
  14681. var modalInstance = $modal.open({
  14682. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  14683. controller: 'PurcUploadByBatchCtrl',
  14684. size: 'lg',
  14685. resolve: {}
  14686. });
  14687. modalInstance.result.then(function (data) {
  14688. angular.forEach(data, function (prod) {
  14689. $scope.order.orderItems.push({
  14690. code: prod.code,
  14691. title: data.title,
  14692. unit: 'PCS',
  14693. spec: prod.spec,
  14694. qty: prod.amount,
  14695. price: prod.price,
  14696. remark: prod.remark,
  14697. delivery: prod.date,
  14698. prid: prod.id,
  14699. taxrate: prod.rate
  14700. });
  14701. })
  14702. }, function () {
  14703. });
  14704. }
  14705. // 删除一条主记录
  14706. $scope.deleteCart = function (id) {
  14707. cartOperation.deleteCart({id: id}, {}, function (data) {
  14708. if (data.success) {
  14709. toaster.pop('success', '提示', data.success);
  14710. $timeout(function () {
  14711. window.location.reload();
  14712. }, 500);
  14713. }
  14714. if (data.error) {
  14715. toaster.pop('error', '提示', data.error);
  14716. }
  14717. }, function (response) {
  14718. toaster.pop('erroer', '提示', response.data);
  14719. });
  14720. };
  14721. $scope.getMinDate = function (item) {
  14722. return $filter('date')(new Date, 'yyyy-MM-dd');
  14723. };
  14724. $scope.openDatePicker = function ($event, openParam, index) {
  14725. $event.preventDefault();
  14726. $event.stopPropagation();
  14727. $scope.order.orderItems[index].$endDateOpen = !openParam;
  14728. };
  14729. // 添加到购物车
  14730. $scope.addToCart = function (order) {
  14731. $scope.loading = true;
  14732. if (order.vendor.tel != null) {
  14733. $scope.order.vendusertel = order.vendor.tel;
  14734. }
  14735. if (order.vendor.venduser != null && order.vendor.tel != null) {
  14736. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  14737. }
  14738. if (order.shipadd != null) {
  14739. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  14740. }
  14741. if ($scope.order.date instanceof Date) {
  14742. $scope.order.date = $scope.order.date.getTime();
  14743. }
  14744. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  14745. if ($scope.order.orderItems[i].delivery instanceof Date) {
  14746. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  14747. }
  14748. if ($scope.order.currency != 'RMB') {
  14749. $scope.order.orderItems[i].rate = 0;
  14750. }
  14751. }
  14752. $scope.order.status = 311;
  14753. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  14754. $scope.loading = false;
  14755. toaster.pop('success', '成功', '保存成功');
  14756. loadData();
  14757. }, function (response) {
  14758. $scope.loading = false;
  14759. toaster.pop('error', '保存失败', response.data);
  14760. });
  14761. };
  14762. // 立即购买
  14763. $scope.addToOrder = function (order) {
  14764. $scope.loading = true;
  14765. if (order.vendor.tel != null) {
  14766. $scope.order.vendusertel = order.vendor.tel;
  14767. }
  14768. if (order.vendor.venduser != null && order.vendor.tel != null) {
  14769. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  14770. }
  14771. if (order.shipadd != null) {
  14772. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  14773. }
  14774. if ($scope.order.date instanceof Date) {
  14775. $scope.order.date = $scope.order.date.getTime();
  14776. }
  14777. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  14778. if ($scope.order.orderItems[i].delivery instanceof Date) {
  14779. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  14780. }
  14781. if ($scope.order.currency != 'RMB') {
  14782. $scope.order.orderItems[i].rate = 0;
  14783. }
  14784. }
  14785. $scope.order.status = 200;
  14786. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  14787. $scope.loading = false;
  14788. toaster.pop('success', '成功', '保存成功');
  14789. window.location.hash = '#/purc/order/' + data.id;
  14790. }, function (response) {
  14791. $scope.loading = false;
  14792. toaster.pop('error', '保存失败', response.data);
  14793. });
  14794. };
  14795. // 新增收货地址保存
  14796. $scope.saveShipAddress = function (ship) {
  14797. ship.address = ship.province + ship.city + ship.district;
  14798. ShipAddress.saveAddress({}, ship, function (data) {
  14799. if (data.success) {
  14800. ShipAddress.shipAddList({}, function (data) {
  14801. $scope.ships = data;
  14802. $scope.order.shipadd = $scope.ships[0];
  14803. });
  14804. toaster.pop('success', '提示', data.success);
  14805. }
  14806. if (data.error) {
  14807. toaster.pop('error', '提示', data.error);
  14808. }
  14809. });
  14810. }
  14811. // 新增供应商联系人
  14812. $scope.addContact = function (uu) {
  14813. var modalInstance = $modal.open({
  14814. animation: true,
  14815. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  14816. controller: 'AddContacCtrl',
  14817. resolve: {}
  14818. });
  14819. modalInstance.result.then(function (data) {
  14820. $scope.contact = data;
  14821. $scope.contact.venduu = $scope.order.receiveCode;
  14822. Vendor.saveContact({}, $scope.contact, function (data) {
  14823. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  14824. $scope.contacts = data;
  14825. });
  14826. toaster.pop('success', '提示', '联系人保存成功');
  14827. }, function (response) {
  14828. toaster.pop('error', '失败', response.data);
  14829. });
  14830. });
  14831. }
  14832. }]);
  14833. /**
  14834. * 审批流
  14835. */
  14836. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function ($scope, toaster, $modal, appFlow, BaseService) {
  14837. BaseService.scrollBackToTop();
  14838. $scope.vacation = false;
  14839. $scope.workovertime = false;
  14840. $scope.workdaily = false;
  14841. $scope.feeplease = false;
  14842. $scope.signapp = false;
  14843. appFlow.viewAppFlow({}, function (data) {// 获取已设置的列表
  14844. $scope.nodes = data;
  14845. angular.forEach($scope.nodes, function (node) {
  14846. if (node.appname = '请假单') {
  14847. $scope.vacation = true;
  14848. }
  14849. if (node.appname = '加班单') {
  14850. $scope.workovertime = true;
  14851. }
  14852. if (node.appname = '工作日报') {
  14853. $scope.workdaily = true;
  14854. }
  14855. if (node.appname = '出差单') {
  14856. $scope.feeplease = true;
  14857. }
  14858. if (node.appname = '申诉单') {
  14859. $scope.signapp = true;
  14860. }
  14861. });
  14862. }, function (response) {
  14863. });
  14864. $scope.NoteSet = function () {
  14865. var modalInstance = $modal.open({
  14866. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14867. controller: 'NoteStep1Ctrl',
  14868. size: 'lg',
  14869. resolve: {
  14870. AppName: function () {
  14871. return '请假单';
  14872. }
  14873. }
  14874. });
  14875. modalInstance.result.then(function (data) {
  14876. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14877. if (data.error) {
  14878. toaster.pop('error', '提示', data.error);
  14879. }
  14880. if (data.success) {
  14881. toaster.pop('success', '提示', data.success);
  14882. }
  14883. }, function (response) {
  14884. });
  14885. }, function () {
  14886. });
  14887. }
  14888. $scope.overTimeSet = function () {
  14889. var modalInstance = $modal.open({
  14890. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14891. controller: 'NoteStep1Ctrl',
  14892. size: 'lg',
  14893. resolve: {
  14894. AppName: function () {
  14895. return '加班单';
  14896. }
  14897. }
  14898. });
  14899. modalInstance.result.then(function (data) {
  14900. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14901. if (data.error) {
  14902. toaster.pop('error', '提示', data.error);
  14903. }
  14904. if (data.success) {
  14905. toaster.pop('success', '提示', data.success);
  14906. }
  14907. }, function (response) {
  14908. });
  14909. }, function () {
  14910. });
  14911. }
  14912. $scope.feePleaseSet = function () {
  14913. var modalInstance = $modal.open({
  14914. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14915. controller: 'NoteStep1Ctrl',
  14916. size: 'lg',
  14917. resolve: {
  14918. AppName: function () {
  14919. return '出差单';
  14920. }
  14921. }
  14922. });
  14923. modalInstance.result.then(function (data) {
  14924. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14925. if (data.error) {
  14926. toaster.pop('error', '提示', data.error);
  14927. }
  14928. if (data.success) {
  14929. toaster.pop('success', '提示', data.success);
  14930. }
  14931. }, function (response) {
  14932. });
  14933. }, function () {
  14934. });
  14935. }
  14936. $scope.workDailySet = function () {
  14937. var modalInstance = $modal.open({
  14938. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14939. controller: 'NoteStep1Ctrl',
  14940. size: 'lg',
  14941. resolve: {
  14942. AppName: function () {
  14943. return '工作日报';
  14944. }
  14945. }
  14946. });
  14947. modalInstance.result.then(function (data) {
  14948. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14949. if (data.error) {
  14950. toaster.pop('error', '提示', data.error);
  14951. }
  14952. if (data.success) {
  14953. toaster.pop('success', '提示', data.success);
  14954. }
  14955. }, function (response) {
  14956. });
  14957. }, function () {
  14958. });
  14959. }
  14960. $scope.signAppSet = function () {
  14961. var modalInstance = $modal.open({
  14962. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14963. controller: 'NoteStep1Ctrl',
  14964. size: 'lg',
  14965. resolve: {
  14966. AppName: function () {
  14967. return '申诉单';
  14968. }
  14969. }
  14970. });
  14971. modalInstance.result.then(function (data) {
  14972. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14973. if (data.error) {
  14974. toaster.pop('error', '提示', data.error);
  14975. }
  14976. if (data.success) {
  14977. toaster.pop('success', '提示', data.success);
  14978. }
  14979. }, function (response) {
  14980. });
  14981. }, function () {
  14982. });
  14983. }
  14984. }]);
  14985. /**
  14986. * 审核条件设置
  14987. */
  14988. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function ($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  14989. $scope.appName = AppName;// 标题名称
  14990. $scope.AppFlow = {
  14991. appName: $scope.appName,
  14992. appNodes: {}
  14993. };
  14994. $scope.AppFlow.appNodes = [];
  14995. appFlow.getNodeByName({name: AppName}, {}, function (data) {// 通过单据名称查询单个审批流
  14996. if (data.appNodes.length != 0) {
  14997. $scope.node = data;
  14998. $scope.AppFlow = data;
  14999. }
  15000. }, function () {
  15001. });
  15002. $scope.copy = function () {//复制
  15003. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  15004. toaster.pop('info', '提示', '复制成功');
  15005. $modalInstance.dismiss();
  15006. }
  15007. $scope.paste = function () {
  15008. $scope.AppFlow = {appName: $scope.appName, appNodes: {}};
  15009. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  15010. }
  15011. $scope.clear = function () {// 清空
  15012. $scope.AppFlow = {
  15013. appName: $scope.appName,
  15014. appNodes: {}
  15015. };
  15016. $scope.AppFlow.appNodes = [];
  15017. }
  15018. appFlow.getPositions({}, function (data) {// 获取人员信息
  15019. $scope.users = data;
  15020. }, function (response) {
  15021. });
  15022. appFlow.getPositionInfo({}, function (data) { // 获取职位信息
  15023. $scope.roles = data;
  15024. }, function (response) {
  15025. });
  15026. $scope.SelectUser = function (data) { // 添加人员
  15027. var item = {
  15028. useruu: null,
  15029. username: null,
  15030. level: null
  15031. };
  15032. item.useruu = data.useruu;
  15033. item.username = data.username;
  15034. // if($scope.AppFlow.appNodes.length != 0){
  15035. // for(var i = 0;i < $scope.AppFlow.appNodes.length; i++) {
  15036. // if($scope.AppFlow.appNodes[i] == item.useruu) {
  15037. // toaster.pop('info', '提示', '不能重复添加');
  15038. // } else {
  15039. // $scope.AppFlow.appNodes.push(item);
  15040. // }
  15041. // }
  15042. // } else {
  15043. $scope.AppFlow.appNodes.push(item);
  15044. // }
  15045. }
  15046. $scope.SelectRole = function (data) {// 添加职位
  15047. var item = {
  15048. position: null,
  15049. level: null
  15050. };
  15051. item.position = data;
  15052. $scope.AppFlow.appNodes.push(item);
  15053. }
  15054. $scope.deleteNode = function (index) {// 删除节点
  15055. $scope.AppFlow.appNodes.splice(index, 1);
  15056. };
  15057. $scope.saveNode = function () { // 保存
  15058. angular.forEach($scope.AppFlow.appNodes, function (value, key) {
  15059. $scope.AppFlow.appNodes[key].level = key;
  15060. });
  15061. if ($scope.AppFlow.appNodes.length == 0) {
  15062. toaster.pop('info', '提示', '您还未设置审批人');
  15063. } else {
  15064. $modalInstance.close($scope.AppFlow);
  15065. }
  15066. ;
  15067. };
  15068. $scope.cancel = function () {// 取消
  15069. $modalInstance.dismiss();
  15070. }
  15071. }]);
  15072. /***
  15073. * 代采定单
  15074. */
  15075. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', 'getOrderInfo', '$modal', 'CurrentRole', function ($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService, getOrderInfo, $modal, CurrentRole) {
  15076. BaseService.scrollBackToTop();
  15077. // 获取当前用户是否为普通用户
  15078. CurrentRole.isUser({}, {}, function (data) {
  15079. $scope.isUser = data.isUser;
  15080. });
  15081. $scope.active = 'all';
  15082. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15083. $scope.total = null;
  15084. $scope.setActive = function (state) {
  15085. if ($scope.active != state) {
  15086. $scope.active = state;
  15087. if ($scope.tableParams.page() == 1)
  15088. $scope.tableParams.reload();
  15089. else
  15090. $scope.tableParams.page(1);
  15091. }
  15092. };
  15093. $scope.agreedText = '全部';
  15094. $scope.dateZoneText = '不限';
  15095. $scope.condition = {dateZone: 1};
  15096. /* 时间筛选初始化*/
  15097. var fromDate = new Date();
  15098. var toDate = new Date();
  15099. fromDate.setMonth(fromDate.getMonth() - 1);
  15100. fromDate.setHours(0, 0, 0, 0);
  15101. toDate.setHours(23, 59, 59, 999);
  15102. $scope.condition.dateFrom = fromDate;
  15103. $scope.condition.dateTo = toDate;
  15104. $scope.changeDateZone = function (zone) {
  15105. $scope.condition.dateZone = zone;
  15106. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  15107. $scope.condition.$dateZoneOpen = false;
  15108. getDateCondition(zone, $scope.condition);
  15109. $scope.tableParams.page(1);
  15110. $scope.tableParams.reload();
  15111. };
  15112. $scope.openDatePicker = function ($event, item, openParam) {
  15113. $event.preventDefault();
  15114. $event.stopPropagation();
  15115. item[openParam] = !item[openParam];
  15116. };
  15117. $scope.openFilterDatePicker = function ($event, item, openParam) {
  15118. $event.preventDefault();
  15119. $event.stopPropagation();
  15120. item[openParam] = !item[openParam];
  15121. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  15122. $scope.tableParams.reload();
  15123. }
  15124. };
  15125. $scope.searchMethod = false;
  15126. var getSerivce = function() {
  15127. return $scope.searchMethod ? getDeOrder : getOrderInfo;
  15128. }
  15129. getSerivce();
  15130. // 获取订单总金额
  15131. var getOrdersAmount = function() {
  15132. DeputyOrder.odersAmount({}, function(data) {
  15133. $scope.odersAmount = data.amount;
  15134. });
  15135. }
  15136. getOrdersAmount();
  15137. $scope.tableParams = new ngTableParams({
  15138. page: 1,
  15139. count: 20,
  15140. sorting: {'date': 'desc', 'id': 'desc'}
  15141. }, {
  15142. total: 0,
  15143. counts: [5, 10, 25, 50],
  15144. getData: function ($defer, params) {
  15145. $scope.loading = true;
  15146. var pageParams = params.url();
  15147. pageParams.searchFilter = {
  15148. keyword: $scope.keyword,
  15149. fromDate: getDateTime($scope.condition.dateFrom),
  15150. endDate: getDateTime($scope.condition.dateTo)
  15151. };
  15152. getSerivce()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  15153. $scope.loading = false;
  15154. if (page) {
  15155. params.total(page.totalElement);
  15156. $scope.total = page.totalElement;
  15157. $defer.resolve(page.content);
  15158. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  15159. }
  15160. }, function (response) {
  15161. $scope.loading = false;
  15162. toaster.pop('error', '数据加载失败', response.data);
  15163. });
  15164. }
  15165. });
  15166. //打印
  15167. $scope.print = function (deputyOrder) {
  15168. DeputyOrder.printCount({id: deputyOrder.id}, {});//增加打印此次
  15169. $scope.tableParams.reload();
  15170. // ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  15171. // ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  15172. // ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  15173. // ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  15174. ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  15175. ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  15176. ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  15177. ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  15178. };
  15179. // 搜索框回车
  15180. $scope.onSearch = function (keyword) {
  15181. // 每次搜索重置获取数据方法
  15182. $scope.searchMethod = false;
  15183. if(keyword != null && keyword != '') {
  15184. $scope.searchMethod = true;
  15185. }
  15186. $scope.tableParams.page(1);
  15187. $scope.tableParams.reload();
  15188. };
  15189. // 复制采购单
  15190. $scope.copyorder = function (id) {
  15191. $scope.loading = true;
  15192. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  15193. $scope.loading = false;
  15194. if (data.id) {
  15195. toaster.pop('success', '提示', '复制生成单据成功');
  15196. window.location.hash = "#/purc/deputy/" + data.id;
  15197. }
  15198. if (data.error) {
  15199. toaster.pop('error', '提示', '保存失败');
  15200. }
  15201. }, function (response) {
  15202. $scope.loading = false;
  15203. toaster.pop('error', '提示', response.data);
  15204. });
  15205. }
  15206. // 删除代采订单
  15207. $scope.clear = function (id) {
  15208. $scope.loading = true;
  15209. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  15210. if (data.success) {
  15211. toaster.pop('success', '提示', data.success);
  15212. $scope.tableParams.reload();
  15213. }
  15214. $scope.loading = false;
  15215. }, function (response) {
  15216. $scope.loading = false;
  15217. toaster.pop('error', '提示', response.data);
  15218. });
  15219. }
  15220. $scope.viewApprove = function(salecode, uu) {
  15221. var modalInstance = $modal.open({
  15222. templateUrl: 'static/tpl/index/purc/modal/approval_detail.html',
  15223. controller: 'ViewApprovalDetailCtrl',
  15224. resolve: {
  15225. uu: function () {
  15226. return uu
  15227. },
  15228. salecode: function () {
  15229. return salecode
  15230. }
  15231. }
  15232. });
  15233. }
  15234. }]);
  15235. // 查询代采定单在信扬中的审批情况
  15236. app.controller('ViewApprovalDetailCtrl', ['$scope', 'toaster', '$modalInstance', 'DeputyOrder', 'BaseService', 'ngTableParams', 'uu', 'salecode', function ($scope, toaster, $modalInstance, DeputyOrder, BaseService, ngTableParams, uu, salecode) {
  15237. DeputyOrder.approve({uu: uu, code: salecode}, {}, function (data) {
  15238. $scope.nodes = data.nodes;
  15239. $scope.process = data.process;
  15240. if(data.error) {
  15241. toaster.pop('error', '提示', data.error);
  15242. }
  15243. }, function (response) {
  15244. toaster.pop('error', '提示', '暂未获取到相关单据的信息');
  15245. });
  15246. $scope.cancel = function () {
  15247. $modalInstance.dismiss();
  15248. };
  15249. $scope.select = function (company) { // 直接选择
  15250. $modalInstance.close(company);
  15251. }
  15252. }]);
  15253. /**
  15254. * 新增代采订单
  15255. */
  15256. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', 'DecimalNumber', function ($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService, DecimalNumber) {
  15257. BaseService.scrollBackToTop();
  15258. //默认采购单号不重复
  15259. $scope.orderCodeEnable = true;
  15260. $scope.deOrder = {
  15261. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  15262. entrydate: new Date(),
  15263. status: '在录入',
  15264. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  15265. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  15266. riskmethod: '甲方承担',
  15267. taxpaymentmethod: '甲方承担',
  15268. totalamount: 0,
  15269. totalpayament: 0,
  15270. orderamount: 0,
  15271. usdpayment: 0
  15272. };
  15273. $scope.deOrder.deputyOrderItems = [];
  15274. var item = {
  15275. prodname: null,
  15276. prodcode: null,
  15277. prodspec: null,
  15278. amount: null,
  15279. unitprice: null,
  15280. purcprice: null,
  15281. remark: null,
  15282. orderprice: null,
  15283. };
  15284. $scope.deOrder.deputyOrderItems.push(item);
  15285. // 代采企业列表
  15286. DeputyOrder.deputyEnterprise({}, function (data) {
  15287. $scope.deputyEnterprises = data;
  15288. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15289. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15290. });
  15291. // 更新名称时后台更改uu号
  15292. $scope.change = function (deputyname) {
  15293. DeputyOrder.deputyEnterprise({}, function (data) {
  15294. $scope.deputyEn = data;
  15295. angular.forEach($scope.deputyEn, function (en) {
  15296. if (deputyname == en.deputyenname) {
  15297. $scope.deputyuu = en.deputyenuu;
  15298. }
  15299. });
  15300. });
  15301. }
  15302. // 查找付款企业
  15303. $scope.dbfindPayCompany = function (deputyuu) {
  15304. var modalInstance = $modal.open({
  15305. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15306. controller: 'DbfindDeputyPayCompanyCtrl',
  15307. resolve: {
  15308. deputyuu: function () {
  15309. return deputyuu
  15310. }
  15311. }
  15312. });
  15313. modalInstance.result.then(function (data) {
  15314. $scope.deOrder.paycomname = data.enname;
  15315. $scope.deOrder.paycomaddress = data.address;
  15316. })
  15317. }
  15318. // 查询上次的关键词记录
  15319. $scope.getHisKeyword = function (tervendor) {
  15320. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function (data) {
  15321. $scope.deOrder.vendtel = data.vendtel;
  15322. $scope.deOrder.venduser = data.venduser;
  15323. $scope.deOrder.otherdata = data.otherdata;
  15324. $scope.deOrder.companyname = data.companyname;
  15325. $scope.deOrder.bankaccount = data.bankaccount;
  15326. $scope.deOrder.bankaddress = data.bankaddress;
  15327. $scope.deOrder.bankcode = data.bankcode;
  15328. $scope.deOrder.bankname = data.bankname;
  15329. $scope.deOrder.legalrepresent = data.legalrepresent;
  15330. $scope.deOrder.tervendaddress = data.tervendaddress;
  15331. $scope.deOrder.enfax = data.enfax;
  15332. $scope.deOrder.deliverymethod = data.deliverymethod;
  15333. }, function (response) {
  15334. toaster.pop('error', '提示', response.data);
  15335. });
  15336. }
  15337. // 查询历史供应商
  15338. DeputyOrder.hisvendors({}, function (data) {
  15339. $scope.hisvendors = data;
  15340. }, function (response) {
  15341. toaster.pop('error', '提示', response.data);
  15342. });
  15343. // 上次填写记录(不关联供应商)
  15344. DeputyOrder.lastKeywords({}, function (data) {
  15345. $scope.lastkeyowrds = data;
  15346. $scope.deOrder.madealdate = $scope.lastkeyowrds.madealdate;
  15347. $scope.deOrder.madealcode = $scope.lastkeyowrds.madealcode;
  15348. }, function (response) {
  15349. toaster.pop('error', '提示', response.data);
  15350. });
  15351. //增加商品
  15352. $scope.add = function (index) {
  15353. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15354. toaster.pop('info', '提示', '请先填写商品信息');
  15355. } else {
  15356. $scope.deOrder.deputyOrderItems.push(
  15357. {
  15358. prodname: null,
  15359. prodcode: null,
  15360. prodspec: null,
  15361. prodbrand: null,
  15362. amount: null,
  15363. unitprice: null,
  15364. purcprice: null,
  15365. remark: null,
  15366. orderprice: null
  15367. });
  15368. }
  15369. };
  15370. //删除商品
  15371. $scope.del = function (index) {
  15372. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15373. };
  15374. // 导入商品信息
  15375. $scope.uplodaByBatch = function () {
  15376. var modalInstance = $modal.open({
  15377. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15378. controller: 'DeputyOrderUploadCtrl',
  15379. size: 'lg',
  15380. resolve: {}
  15381. });
  15382. modalInstance.result.then(function (data) {
  15383. angular.forEach(data, function (data) {
  15384. $scope.deOrder.deputyOrderItems.push(data);
  15385. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15386. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15387. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15388. }
  15389. }
  15390. })
  15391. $scope.deOrder.totalamount = 0;
  15392. $scope.deOrder.usdpayment = 0;
  15393. $scope.deOrder.orderamount = 0;
  15394. $scope.deOrder.totalpayament = 0;
  15395. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15396. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15397. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15398. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15399. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15400. });
  15401. }, function () {
  15402. });
  15403. }
  15404. // 查找供应商
  15405. $scope.dbfindVendor = function (deputyuu) {
  15406. var modalInstance = $modal.open({
  15407. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  15408. controller: 'DbfindDeputyVendorInfoCtrl',
  15409. size: 'lg',
  15410. resolve: {
  15411. deputyuu: function () {
  15412. return deputyuu
  15413. }
  15414. }
  15415. });
  15416. modalInstance.result.then(function (data) {
  15417. $scope.deOrder.customer = data.vendorEnterprise.enName;
  15418. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  15419. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  15420. $scope.deOrder.usertel = data.vendorUser.userTel;
  15421. })
  15422. }
  15423. // 检验订单编号是否存在
  15424. $scope.checkOrder = function (salecode, deputyuu) {
  15425. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  15426. $scope.orderCodeEnable = true;
  15427. if (data.info) {
  15428. toaster.pop('error', '提示', data.info);
  15429. $scope.orderCodeEnable = false;
  15430. }
  15431. }, function (response) {
  15432. toaster.pop('error', '提示', response.data);
  15433. })
  15434. }
  15435. //计算采购单价
  15436. $scope.checkPrice = function (rate) {
  15437. $scope.deOrder.totalamount = 0;
  15438. $scope.deOrder.usdpayment = 0;
  15439. $scope.deOrder.orderamount = 0;
  15440. $scope.deOrder.totalpayament = 0;
  15441. if (rate == null) {
  15442. toaster.pop('info', '提示', '请先填入税率');
  15443. } else {
  15444. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15445. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  15446. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15447. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15448. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15449. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15450. });
  15451. }
  15452. }
  15453. // 获取订单总价
  15454. $scope.totalPrice = function () {
  15455. $scope.deOrder.totalamount = 0;
  15456. $scope.deOrder.usdpayment = 0;
  15457. $scope.deOrder.orderamount = 0;
  15458. $scope.deOrder.totalpayament = 0;
  15459. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15460. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  15461. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15462. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15463. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15464. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15465. }
  15466. });
  15467. }
  15468. $scope.checkresult = false;
  15469. var checkKeyword = function () {
  15470. if ($scope.deOrder.madealdate == null) {
  15471. toaster.pop('info', '提示', '主协议签订日期未选择');
  15472. } else if ($scope.deOrder.madealcode == null) {
  15473. toaster.pop('info', '提示', '主协议签订编号未填写');
  15474. } else if ($scope.deOrder.tervendor == null) {
  15475. toaster.pop('info', '提示', '终端供应商名称未填写');
  15476. } else if ($scope.deOrder.vendtel == null) {
  15477. toaster.pop('info', '提示', '电话号码未填写');
  15478. } else if ($scope.deOrder.venduser == null) {
  15479. toaster.pop('info', '提示', '联系人未填写');
  15480. } else if ($scope.deOrder.shipdate == null) {
  15481. toaster.pop('info', '提示', '供应商发货时间未选择');
  15482. } else if ($scope.deOrder.goodspacking == null) {
  15483. toaster.pop('info', '提示', '货物包装要求未填写');
  15484. } else if ($scope.deOrder.deliverymethod == null) {
  15485. toaster.pop('info', '提示', '供应商交货方式未填写');
  15486. } else if ($scope.deOrder.pickupmethod == null) {
  15487. toaster.pop('info', '提示', '我方提货方式未填写');
  15488. } else if ($scope.deOrder.paymentmethod == null) {
  15489. toaster.pop('info', '提示', '我方付款方式未填写');
  15490. } else if ($scope.deOrder.pickupdate == null) {
  15491. toaster.pop('info', '提示', '我方提货时间未选择');
  15492. } else if ($scope.deOrder.currency == null) {
  15493. toaster.pop('info', '提示', '交易币别未选择');
  15494. } else if ($scope.deOrder.deputyuu == null) {
  15495. toaster.pop('info', '提示', '代采企业未选择');
  15496. } else if ($scope.deOrder.salecode == null) {
  15497. toaster.pop('info', '提示', '订单编号未填写');
  15498. } else if ($scope.deOrder.paydeldate == null) {
  15499. toaster.pop('info', '提示', '我方付款提货时间未选择');
  15500. } else if ($scope.deOrder.riskmethod == null) {
  15501. toaster.pop('info', '提示', '风险承担方式未填写');
  15502. } else if ($scope.deOrder.taxpaymentmethod == null) {
  15503. toaster.pop('info', '提示', '运、税费承担方式');
  15504. } else if ($scope.deOrder.tervendaddress == null) {
  15505. toaster.pop('info', '提示', '终端供应商地址未填写');
  15506. } else if ($scope.deOrder.companyname == null) {
  15507. toaster.pop('info', '提示', '公司全称(英文)未填写');
  15508. } else if ($scope.deOrder.requirepaydate == null) {
  15509. toaster.pop('info', '提示', '要求付汇日期未选择');
  15510. } else if ($scope.deOrder.bankname == null) {
  15511. toaster.pop('info', '提示', '银行名称(英文)未填写');
  15512. } else if ($scope.deOrder.bankaccount == null) {
  15513. toaster.pop('info', '提示', '银行账号未填写');
  15514. } else if ($scope.deOrder.bankaddress == null) {
  15515. toaster.pop('info', '提示', '银行地址未填写');
  15516. } else if ($scope.deOrder.bankcode == null) {
  15517. toaster.pop('info', '提示', '银行代码未填写');
  15518. } else if ($scope.deOrder.salepocode == null) {
  15519. toaster.pop('info', '提示', '合同编号未填写');
  15520. } else if ($scope.deOrder.legalrepresent == null) {
  15521. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  15522. } else if ($scope.deOrder.paycomname == null) {
  15523. toaster.pop('info', '提示', '付款公司未填写');
  15524. } else if ($scope.deOrder.paycomaddress == null) {
  15525. toaster.pop('info', '提示', '付款公司地址未填写');
  15526. } else if ($scope.deOrder.enfax == null) {
  15527. toaster.pop('info', '提示', '供应商方法人电话未填写');
  15528. } else if ($scope.deOrder.paydate == null) {
  15529. toaster.pop('info', '提示', '货款支付时间未选择');
  15530. } else if ($scope.deOrder.paymethod == null) {
  15531. toaster.pop('info', '提示', '货款支付方式未填写');
  15532. } else if ($scope.deOrder.deliverydate == null) {
  15533. toaster.pop('info', '提示', '交货时间未选择');
  15534. } else if (!$scope.orderCodeEnable) {
  15535. toaster.pop('info', '提示', '采购单号重复');
  15536. }else {
  15537. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  15538. if (orderitem.prodname == null) {
  15539. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  15540. } else if (orderitem.prodcode == null) {
  15541. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  15542. } else if (orderitem.prodspec == null) {
  15543. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  15544. } else if (orderitem.prodbrand == null) {
  15545. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  15546. } else if (orderitem.amount == null) {
  15547. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  15548. } else if (orderitem.unitprice == null) {
  15549. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  15550. } else if (orderitem.purcprice == null) {
  15551. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  15552. } else {
  15553. $scope.checkresult = true;
  15554. $scope.checkresult = true;
  15555. if ($scope.deOrder.entrystatus == '保存') {
  15556. $scope.isSave = true;
  15557. } else if ($scope.deOrder.entrystatus == '已提交') {
  15558. $scope.isSubmit = true;
  15559. }
  15560. }
  15561. });
  15562. }
  15563. }
  15564. // 保存
  15565. $scope.isSave = false;
  15566. $scope.save = function () {
  15567. $scope.deOrder.entrystatus = '保存';
  15568. checkKeyword();
  15569. if ($scope.checkresult) {
  15570. $scope.deOrder.totalamount = 0;
  15571. $scope.deOrder.usdpayment = 0;
  15572. $scope.deOrder.orderamount = 0;
  15573. $scope.deOrder.totalpayament = 0;
  15574. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15575. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15576. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15577. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15578. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15579. });
  15580. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  15581. toaster.pop('info', '提示', '您还未填写任何商品信息');
  15582. } else {
  15583. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  15584. if (data.id) {
  15585. toaster.pop('success', '提示', '保存成功');
  15586. window.location.hash = "#/purc/deputy/" + data.id;
  15587. }
  15588. if (data.error) {
  15589. toaster.pop('error', '提示', '保存失败');
  15590. }
  15591. }, function (response) {
  15592. });
  15593. }
  15594. }
  15595. }
  15596. // 提交
  15597. $scope.isSubmit = false;
  15598. $scope.submit = function () {
  15599. $scope.deOrder.entrystatus = '已提交';
  15600. checkKeyword();
  15601. if ($scope.checkresult) {
  15602. $scope.deOrder.totalamount = 0;
  15603. $scope.deOrder.usdpayment = 0;
  15604. $scope.deOrder.orderamount = 0;
  15605. $scope.deOrder.totalpayament = 0;
  15606. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15607. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15608. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15609. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15610. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15611. });
  15612. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  15613. toaster.pop('info', '提示', '您还未填写任何商品信息');
  15614. } else {
  15615. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  15616. if (data.id) {
  15617. toaster.pop('success', '提示', '提交成功');
  15618. window.location.hash = "#/purc/deputy/" + data.id;
  15619. }
  15620. if (data.error) {
  15621. toaster.pop('error', '提示', '保存失败');
  15622. }
  15623. }, function (response) {
  15624. });
  15625. }
  15626. }
  15627. }
  15628. $scope.openDatePicker = function ($event, deOrder, openParam) {
  15629. $event.preventDefault();
  15630. $event.stopPropagation();
  15631. deOrder[openParam] = !deOrder[openParam];
  15632. };
  15633. }]);
  15634. // 代采企业供应商
  15635. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  15636. $scope.prod = false;
  15637. BaseService.scrollBackToTop();
  15638. // 搜索框回车
  15639. $scope.onSearch = function (keyword) {
  15640. $scope.keyword = keyword;
  15641. $scope.customerParams.page(1);
  15642. $scope.customerParams.reload();
  15643. };
  15644. $scope.customerParams = new ngTableParams({
  15645. page: 1,
  15646. count: 20
  15647. }, {
  15648. total: 0,
  15649. counts: [5, 10, 25, 50],
  15650. getData: function ($defer, params) {
  15651. $scope.loading = true;
  15652. var pageParams = params.url();
  15653. pageParams.keyword = $scope.keyword;
  15654. pageParams.enuu = deputyuu;
  15655. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function (page) {
  15656. $scope.loading = false;
  15657. if (page) {
  15658. params.total(page.totalElement);
  15659. $defer.resolve(page.content);
  15660. }
  15661. $scope.totalCount = page.totalElement;
  15662. }, function (response) {
  15663. $scope.loading = false;
  15664. toaster.pop('error', '数据加载失败', response.data);
  15665. });
  15666. }
  15667. });
  15668. $scope.cancel = function () {
  15669. $modalInstance.dismiss();
  15670. };
  15671. $scope.checkVendor = function (vendor) { // 直接选择
  15672. $modalInstance.close(vendor);
  15673. }
  15674. }]);
  15675. // 代采企业付款企业
  15676. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  15677. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function (data) {
  15678. $scope.paycompanies = data;
  15679. }, function (response) {
  15680. toaster.pop('error', '提示', response.data);
  15681. });
  15682. $scope.cancel = function () {
  15683. $modalInstance.dismiss();
  15684. };
  15685. $scope.select = function (company) { // 直接选择
  15686. $modalInstance.close(company);
  15687. }
  15688. }]);
  15689. /**
  15690. * 代采订单批量导入
  15691. */
  15692. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  15693. // 通过excel批量上传物料
  15694. $scope.result = null;
  15695. $scope.upload = function () {
  15696. var file = $scope.myFiles[0];
  15697. $upload.upload({
  15698. url: 'deputyOrder/release/excel',
  15699. file: file,
  15700. method: 'POST'
  15701. }).success(function (data) {
  15702. $scope.result = data;
  15703. $scope.success = $scope.result.success;
  15704. $scope.total = $scope.result.total;
  15705. $scope.alters = $scope.result.alters;
  15706. }).error(function (response) {
  15707. toaster.pop('error', response.data || response);
  15708. });
  15709. };
  15710. // 查看范例
  15711. $scope.showImg = function () {
  15712. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  15713. box.show();
  15714. box.find('img').attr('src', src);
  15715. box.find('a').click(function () {
  15716. box.hide();
  15717. });
  15718. box.dblclick(function () {
  15719. box.hide();
  15720. });
  15721. };
  15722. // 下载模板
  15723. $scope.download = function () {
  15724. window.location.href = 'deputyOrder/upload/template';
  15725. };
  15726. $scope.enSure = function () {
  15727. $modalInstance.close($scope.result.items);
  15728. }
  15729. $scope.cancel = function () {
  15730. $modalInstance.dismiss();
  15731. }
  15732. }]);
  15733. /**
  15734. * 代采详情
  15735. */
  15736. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', 'DecimalNumber', 'CurrentRole', function ($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal, DecimalNumber, CurrentRole) {
  15737. BaseService.scrollBackToTop();
  15738. // 获取当前用户是否为普通用户
  15739. CurrentRole.isUser({}, {}, function (data) {
  15740. $scope.isUser = data.isUser;
  15741. });
  15742. var loadData = function () {
  15743. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function (data) {
  15744. $scope.deOrder = data;
  15745. $scope.deOrder.$editing = true;
  15746. });
  15747. };
  15748. loadData();
  15749. //默认采购单号不重复
  15750. $scope.orderCodeEnable = true;
  15751. // 查询历史供应商
  15752. DeputyOrder.hisvendors({}, function (data) {
  15753. $scope.hisvendors = data;
  15754. }, function (response) {
  15755. toaster.pop('error', '提示', response.data);
  15756. });
  15757. // 代采企业列表
  15758. DeputyOrder.deputyEnterprise({}, function (data) {
  15759. $scope.deputyEnterprises = data;
  15760. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15761. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15762. });
  15763. // 更新代采企业时更新费率
  15764. $scope.change = function (deputyname) {
  15765. DeputyOrder.deputyEnterprise({}, function (data) {
  15766. $scope.deputyEn = data;
  15767. angular.forEach($scope.deputyEn, function (en) {
  15768. if (deputyname == en.deputyenname) {
  15769. $scope.deputyuu = en.deputyenuu;
  15770. }
  15771. });
  15772. });
  15773. }
  15774. // 查找付款企业
  15775. $scope.dbfindPayCompany = function (deputyuu) {
  15776. var modalInstance = $modal.open({
  15777. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15778. controller: 'DbfindDeputyPayCompanyCtrl',
  15779. resolve: {
  15780. deputyuu: function () {
  15781. return deputyuu
  15782. }
  15783. }
  15784. });
  15785. modalInstance.result.then(function (data) {
  15786. $scope.deOrder.paycomname = data.enname;
  15787. $scope.deOrder.paycomaddress = data.address;
  15788. })
  15789. }
  15790. // 删除明细
  15791. $scope.del = function (index, id) {
  15792. DeputyOrder.deleteProdById({id: id}, {}, function (data) {
  15793. if (data.success) {
  15794. toaster.pop('success', '提示', data.success);
  15795. $scope.deOrder.deputyOrderItems.splice(index, 1)
  15796. }
  15797. if (data.error) {
  15798. toaster.pop('error', '提示', data.error);
  15799. }
  15800. $scope.deOrder.totalamount = 0;
  15801. $scope.deOrder.usdpayment = 0;
  15802. $scope.deOrder.orderamount = 0;
  15803. $scope.deOrder.totalpayament = 0;
  15804. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  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. }, function (response) {
  15811. toaster.pop('error', '提示', response.data);
  15812. });
  15813. }
  15814. //增加商品
  15815. $scope.add = function (index) {
  15816. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15817. toaster.pop('info', '提示', '请先填写商品信息');
  15818. } else {
  15819. $scope.deOrder.deputyOrderItems.push(
  15820. {
  15821. prodname: null,
  15822. prodcode: null,
  15823. prodspec: null,
  15824. prodbrand: null,
  15825. amount: null,
  15826. unitprice: null,
  15827. remark: null,
  15828. orderprice: null
  15829. });
  15830. }
  15831. };
  15832. // 导入商品信息
  15833. $scope.uplodaByBatch = function () {
  15834. var modalInstance = $modal.open({
  15835. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15836. controller: 'DeputyOrderUploadCtrl',
  15837. size: 'lg',
  15838. resolve: {}
  15839. });
  15840. modalInstance.result.then(function (data) {
  15841. angular.forEach(data, function (data) {
  15842. $scope.deOrder.deputyOrderItems.push(data);
  15843. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15844. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15845. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15846. }
  15847. }
  15848. })
  15849. $scope.deOrder.totalamount = 0;
  15850. $scope.deOrder.usdpayment = 0;
  15851. $scope.deOrder.orderamount = 0;
  15852. $scope.deOrder.totalpayament = 0;
  15853. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15854. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15855. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15856. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15857. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15858. });
  15859. }, function () {
  15860. });
  15861. }
  15862. //删除商品
  15863. $scope.delItem = function (index) {
  15864. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15865. };
  15866. var getService = function () {
  15867. return DeputyOrder.getProdList;
  15868. };
  15869. $scope.update = function () {
  15870. $scope.deOrder.$editing = true;
  15871. }
  15872. $scope.cancel = function () {
  15873. $scope.deOrder.$editing = false;
  15874. }
  15875. // 检验订单编号是否存在
  15876. $scope.checkOrder = function (salecode, deputyuu) {
  15877. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  15878. $scope.orderCodeEnable = true;
  15879. if (data.info) {
  15880. toaster.pop('error', '提示', data.info);
  15881. $scope.orderCodeEnable = false;
  15882. }
  15883. }, function (response) {
  15884. toaster.pop('error', '提示', response.data);
  15885. })
  15886. }
  15887. //计算采购单价
  15888. $scope.checkPrice = function (rate) {
  15889. $scope.deOrder.totalamount = 0;
  15890. $scope.deOrder.usdpayment = 0;
  15891. $scope.deOrder.orderamount = 0;
  15892. $scope.deOrder.totalpayament = 0;
  15893. if (rate == null) {
  15894. toaster.pop('info', '提示', '请先填入税率');
  15895. } else {
  15896. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15897. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  15898. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15899. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15900. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15901. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15902. });
  15903. }
  15904. }
  15905. // 获取订单总价
  15906. $scope.totalPrice = function () {
  15907. $scope.deOrder.totalamount = 0;
  15908. $scope.deOrder.usdpayment = 0;
  15909. $scope.deOrder.orderamount = 0;
  15910. $scope.deOrder.totalpayament = 0;
  15911. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15912. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  15913. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15914. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15915. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15916. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15917. }
  15918. });
  15919. }
  15920. $scope.checkresult = false;
  15921. var checkKeyword = function () {
  15922. if ($scope.deOrder.madealdate == null) {
  15923. toaster.pop('info', '提示', '主协议签订日期未选择');
  15924. } else if ($scope.deOrder.madealcode == null) {
  15925. toaster.pop('info', '提示', '主协议签订编号未填写');
  15926. } else if ($scope.deOrder.tervendor == null) {
  15927. toaster.pop('info', '提示', '终端供应商名称未填写');
  15928. } else if ($scope.deOrder.vendtel == null) {
  15929. toaster.pop('info', '提示', '电话号码未填写');
  15930. } else if ($scope.deOrder.venduser == null) {
  15931. toaster.pop('info', '提示', '联系人未填写');
  15932. } else if ($scope.deOrder.shipdate == null) {
  15933. toaster.pop('info', '提示', '供应商发货时间未选择');
  15934. } else if ($scope.deOrder.goodspacking == null) {
  15935. toaster.pop('info', '提示', '货物包装要求未填写');
  15936. } else if ($scope.deOrder.deliverymethod == null) {
  15937. toaster.pop('info', '提示', '供应商交货方式未填写');
  15938. } else if ($scope.deOrder.pickupmethod == null) {
  15939. toaster.pop('info', '提示', '我方提货方式未填写');
  15940. } else if ($scope.deOrder.paymentmethod == null) {
  15941. toaster.pop('info', '提示', '我方付款方式未填写');
  15942. } else if ($scope.deOrder.pickupdate == null) {
  15943. toaster.pop('info', '提示', '我方提货时间未选择');
  15944. } else if ($scope.deOrder.currency == null) {
  15945. toaster.pop('info', '提示', '交易币别未选择');
  15946. } else if ($scope.deOrder.deputyuu == null) {
  15947. toaster.pop('info', '提示', '代采企业未选择');
  15948. } else if ($scope.deOrder.salecode == null) {
  15949. toaster.pop('info', '提示', '订单编号未填写');
  15950. } else if ($scope.deOrder.paydeldate == null) {
  15951. toaster.pop('info', '提示', '我方付款提货时间未选择');
  15952. } else if ($scope.deOrder.riskmethod == null) {
  15953. toaster.pop('info', '提示', '风险承担方式未填写');
  15954. } else if ($scope.deOrder.taxpaymentmethod == null) {
  15955. toaster.pop('info', '提示', '运、税费承担方式');
  15956. } else if ($scope.deOrder.tervendaddress == null) {
  15957. toaster.pop('info', '提示', '终端供应商地址未填写');
  15958. } else if ($scope.deOrder.companyname == null) {
  15959. toaster.pop('info', '提示', '公司全称(英文)未填写');
  15960. } else if ($scope.deOrder.requirepaydate == null) {
  15961. toaster.pop('info', '提示', '要求付汇日期未选择');
  15962. } else if ($scope.deOrder.bankname == null) {
  15963. toaster.pop('info', '提示', '银行名称(英文)未填写');
  15964. } else if ($scope.deOrder.bankaccount == null) {
  15965. toaster.pop('info', '提示', '银行账号未填写');
  15966. } else if ($scope.deOrder.bankaddress == null) {
  15967. toaster.pop('info', '提示', '银行地址未填写');
  15968. } else if ($scope.deOrder.bankcode == null) {
  15969. toaster.pop('info', '提示', '银行代码未填写');
  15970. } else if ($scope.deOrder.salepocode == null) {
  15971. toaster.pop('info', '提示', '合同编号未填写');
  15972. } else if ($scope.deOrder.legalrepresent == null) {
  15973. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  15974. } else if ($scope.deOrder.paycomname == null) {
  15975. toaster.pop('info', '提示', '付款公司未填写');
  15976. } else if ($scope.deOrder.paycomaddress == null) {
  15977. toaster.pop('info', '提示', '付款公司地址未填写');
  15978. } else if ($scope.deOrder.enfax == null) {
  15979. toaster.pop('info', '提示', '供应商方法人电话未填写');
  15980. } else if ($scope.deOrder.paydate == null) {
  15981. toaster.pop('info', '提示', '货款支付时间未选择');
  15982. } else if ($scope.deOrder.paymethod == null) {
  15983. toaster.pop('info', '提示', '货款支付方式未填写');
  15984. } else if ($scope.deOrder.deliverydate == null) {
  15985. toaster.pop('info', '提示', '交货时间未选择');
  15986. } else if (!$scope.orderCodeEnable) {
  15987. toaster.pop('info', '提示', '采购单号重复');
  15988. }else {
  15989. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  15990. if (orderitem.prodname == null) {
  15991. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  15992. } else if (orderitem.prodcode == null) {
  15993. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  15994. } else if (orderitem.prodspec == null) {
  15995. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  15996. } else if (orderitem.prodbrand == null) {
  15997. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  15998. } else if (orderitem.amount == null) {
  15999. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  16000. } else if (orderitem.unitprice == null) {
  16001. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  16002. } else if (orderitem.purcprice == null) {
  16003. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  16004. } else {
  16005. $scope.checkresult = true;
  16006. if ($scope.deOrder.entrystatus == '保存') {
  16007. $scope.isSave = true;
  16008. } else if ($scope.deOrder.entrystatus == '已提交') {
  16009. $scope.isSubmit = true;
  16010. }
  16011. }
  16012. });
  16013. }
  16014. }
  16015. // 保存
  16016. $scope.isSave = false;
  16017. $scope.save = function () {
  16018. checkKeyword();
  16019. if ($scope.checkresult) {
  16020. $scope.deOrder.totalamount = 0;
  16021. $scope.deOrder.usdpayment = 0;
  16022. $scope.deOrder.orderamount = 0;
  16023. $scope.deOrder.totalpayament = 0;
  16024. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16025. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16026. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16027. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16028. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16029. });
  16030. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  16031. toaster.pop('info', '提示', '您还未填写任何商品信息');
  16032. } else {
  16033. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  16034. if (data.id) {
  16035. toaster.pop('success', '提示', '保存成功');
  16036. loadData();
  16037. }
  16038. if (data.error) {
  16039. toaster.pop('error', '提示', '保存失败');
  16040. }
  16041. }, function (response) {
  16042. toaster.pop('error', '保存失败', response.data);
  16043. });
  16044. }
  16045. }
  16046. }
  16047. // 提交
  16048. $scope.isSubmit = false;
  16049. $scope.submit = function () {
  16050. checkKeyword();
  16051. if ($scope.checkresult) {
  16052. $scope.deOrder.totalamount = 0;
  16053. $scope.deOrder.usdpayment = 0;
  16054. $scope.deOrder.orderamount = 0;
  16055. $scope.deOrder.totalpayament = 0;
  16056. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16057. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16058. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16059. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16060. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16061. });
  16062. DeputyOrder.submitDeOrder({}, $scope.deOrder, function (data) {
  16063. if (data.id) {
  16064. toaster.pop('success', '提示', '提交成功');
  16065. window.location.hash = "#/purc/deputy/" + data.id;
  16066. }
  16067. if (data.error) {
  16068. toaster.pop('error', '提示', '保存失败');
  16069. }
  16070. }, function (response) {
  16071. toaster.pop('error', '保存失败', response.data);
  16072. });
  16073. }
  16074. }
  16075. $scope.openDatePicker = function ($event, deOrder, openParam) {
  16076. $event.preventDefault();
  16077. $event.stopPropagation();
  16078. deOrder[openParam] = !deOrder[openParam];
  16079. };
  16080. //复制采购单
  16081. $scope.copyorder = function (id) {
  16082. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  16083. if (data.id) {
  16084. toaster.pop('success', '提示', '复制生成单据成功');
  16085. window.location.hash = "#/purc/deputy/" + data.id;
  16086. }
  16087. if (data.error) {
  16088. toaster.pop('error', '提示', '保存失败');
  16089. }
  16090. }, function (response) {
  16091. toaster.pop('error', '提示', response.data);
  16092. });
  16093. }
  16094. // 删除代采订单
  16095. $scope.clear = function (id) {
  16096. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  16097. if (data.success) {
  16098. toaster.pop('success', '提示', data.success);
  16099. window.location.hash = "#/purc/deputy";
  16100. }
  16101. }, function (response) {
  16102. toaster.pop('error', '提示', response.data);
  16103. });
  16104. }
  16105. }]);
  16106. /**
  16107. * 代采错误日志
  16108. */
  16109. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function ($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  16110. BaseService.scrollBackToTop();
  16111. var getService = function () {
  16112. return DeputyOrder.getRepetitions;
  16113. };
  16114. $scope.tableParams = new ngTableParams({
  16115. page: 1,
  16116. count: 20,
  16117. sorting: {}
  16118. }, {
  16119. total: 0,
  16120. counts: [5, 10, 25, 50],
  16121. getData: function ($defer, params) {
  16122. $scope.loading = true;
  16123. var pageParams = params.url();
  16124. pageParams.keyword = $scope.keyword;
  16125. pageParams.searchFilter = $scope.searchFilter;
  16126. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  16127. $scope.loading = false;
  16128. if (page) {
  16129. params.total(page.totalElement);
  16130. $defer.resolve(page.content);
  16131. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  16132. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  16133. }
  16134. }, function (response) {
  16135. $scope.loading = false;
  16136. toaster.pop('error', '数据加载失败', response.data);
  16137. });
  16138. }
  16139. });
  16140. // 搜索框回车
  16141. $scope.onSearch = function () {
  16142. $scope.tableParams.page(1);
  16143. $scope.tableParams.reload();
  16144. };
  16145. //删除
  16146. $scope.deleteById = function (id) {
  16147. GetProductInfo.deleteById({id: id}, function (data) {
  16148. if (data.error) {
  16149. toaster.pop("error", "提示", data.error);
  16150. } else {
  16151. toaster.pop("success", "提示", "删除成功");
  16152. $timeout(function () {
  16153. $scope.tableParams.reload();
  16154. }, 500);
  16155. }
  16156. }), function (response) {
  16157. toaster.pop("error", "删除失败", response.data);
  16158. };
  16159. }
  16160. }]);
  16161. /**
  16162. * 招标单
  16163. */
  16164. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams',
  16165. '$modal', '$rootScope', 'PurcTenderInfo', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, PurcTenderInfo) {
  16166. BaseService.scrollBackToTop();
  16167. $scope.searchStatus = false;
  16168. if ($rootScope.tenderActive) {
  16169. $scope.active = $rootScope.tenderActive;
  16170. $rootScope.tenderActive = null;
  16171. } else {
  16172. $scope.active = 'todo';
  16173. }
  16174. $scope.dateZoneText = '不限';
  16175. $scope.deliveryZoneText = '不限';
  16176. $scope.condition = {dateZone: 1, deliveryZone: -1};
  16177. /* 时间筛选初始化*/
  16178. var fromDate = new Date();
  16179. var toDate = new Date();
  16180. fromDate.setMonth(fromDate.getMonth() - 1);
  16181. fromDate.setHours(0, 0, 0, 0);
  16182. toDate.setHours(23, 59, 59, 999);
  16183. $scope.condition.dateFrom = fromDate;
  16184. $scope.condition.dateTo = toDate;
  16185. $scope.changeDateZone = function (zone) {
  16186. $scope.condition.dateZone = zone;
  16187. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  16188. $scope.condition.$dateZoneOpen = false;
  16189. getDateCondition(zone, $scope.condition);
  16190. $scope.tableParams.reload();
  16191. };
  16192. $scope.changeDeliveryZone = function (zone) {
  16193. $scope.condition.deliveryZoneText = zone;
  16194. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  16195. $scope.condition.$delievryZoneOpen = false;
  16196. getDelveryCondition(zone, $scope.condition);
  16197. $scope.tableParams.page(1);
  16198. $scope.tableParams.reload();
  16199. };
  16200. $scope.setActive = function (state) {
  16201. if ($scope.active != state) {
  16202. $scope.active = state;
  16203. if ($scope.tableParams.page() == 1)
  16204. $scope.tableParams.reload();
  16205. else
  16206. $scope.tableParams.page(1);
  16207. }
  16208. };
  16209. var getTenderStatus = function (active) {
  16210. var fn = 'getMyAll';
  16211. switch (active) {
  16212. case 'done':
  16213. fn = 'getMyDone';
  16214. break;
  16215. case 'todo':
  16216. fn = 'getMyTodo';
  16217. break;
  16218. // case 'end':
  16219. // fn = 'getMyEnd';break;
  16220. case 'waiting':
  16221. fn = 'getMyWaiting';
  16222. break;
  16223. }
  16224. return fn;
  16225. };
  16226. var getService = function () {
  16227. if ($scope.searchStatus) {
  16228. return PurcTender;
  16229. }
  16230. return PurcTenderInfo;
  16231. };
  16232. $scope.tableParams = new ngTableParams({
  16233. page: 1,
  16234. count: 20,
  16235. sorting: {
  16236. 'id': 'desc'
  16237. }
  16238. }, {
  16239. total: 0,
  16240. counts: [5, 10, 25, 50],
  16241. getData: function ($defer, params) {
  16242. $scope.loading = true;
  16243. var pageParams = params.url();
  16244. var realActive = {};
  16245. pageParams.searchFilter = { // 筛选条件
  16246. keyword: $scope.keyword,
  16247. fromDate: getDateTime($scope.condition.dateFrom),
  16248. endDate: getDateTime($scope.condition.dateTo)
  16249. };
  16250. getService()[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16251. $scope.loading = false;
  16252. if (page) {
  16253. params.total(page.totalElement);
  16254. $defer.resolve(page.content);
  16255. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  16256. }
  16257. }, function (response) {
  16258. $scope.loading = false;
  16259. toaster.pop('error', '数据加载失败', response.data);
  16260. });
  16261. }
  16262. });
  16263. //获得各分类未阅读数量
  16264. var getUnreadCount = function () {
  16265. PurcTender.getPurcUnreadCount(null, function(data){
  16266. $scope.unread = data;
  16267. });
  16268. };
  16269. getUnreadCount();
  16270. //设置单据已读
  16271. $scope.setOrdersRead = function (id) {
  16272. // 如果单据本身已读,则不发送请求修改数据
  16273. if (!$scope.isUnread(id)){
  16274. return;
  16275. }
  16276. var sourceId = [];
  16277. sourceId.push(id);
  16278. PurcTender.setPurcRead({}, sourceId, function (message) {
  16279. // $scope.getUnreadIds();
  16280. getUnreadCount();
  16281. });
  16282. };
  16283. //获取未读单据id
  16284. var getUnreadIds = function (){
  16285. PurcTender.getPurcUnreadIds({}, "", function (message) {
  16286. $scope.unreadCode = message.content;
  16287. });
  16288. };
  16289. getUnreadIds();
  16290. //判断单据是否未读
  16291. $scope.isUnread = function (tender){
  16292. for (var i in $scope.unreadCode) {
  16293. if (tender.id == $scope.unreadCode[i]) {
  16294. var flag = tender.status == '待评标' && tender.overdue == 1 && tender.result != 1;
  16295. if (!flag) {
  16296. $scope.unreadCode.splice(i,1);
  16297. return false;
  16298. }
  16299. return true;
  16300. }
  16301. }
  16302. };
  16303. $scope.openDatePicker = function ($event, item, openParam) {
  16304. $event.preventDefault();
  16305. $event.stopPropagation();
  16306. item[openParam] = !item[openParam];
  16307. };
  16308. $scope.openFilterDatePicker = function ($event, item, openParam) {
  16309. $event.preventDefault();
  16310. $event.stopPropagation();
  16311. item[openParam] = !item[openParam];
  16312. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  16313. $scope.tableParams.reload();
  16314. }
  16315. };
  16316. $scope.parseDate = function (dateStr) {
  16317. if (dateStr)
  16318. return Date.parse(dateStr, 'yyyy-MM-dd');
  16319. return new Date();
  16320. };
  16321. // 选择查找日期
  16322. $scope.onDateCondition = function () {
  16323. $scope.tableParams.page(1);
  16324. $scope.tableParams.reload();
  16325. };
  16326. // 搜索框回车
  16327. $scope.onSearch = function () {
  16328. $scope.searchStatus = true;
  16329. $scope.tableParams.page(1);
  16330. $scope.tableParams.reload();
  16331. };
  16332. }]);
  16333. /**
  16334. * 新增招标单
  16335. */
  16336. 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) {
  16337. // 录入人
  16338. AuthenticationService.getAuthentication().success(function (data) {
  16339. $scope.user = data;
  16340. });
  16341. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16342. $scope.searchMethod = false;
  16343. var getService = function () {
  16344. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  16345. };
  16346. // 物料信息
  16347. $scope.tableParams = new ngTableParams({
  16348. page: 1,
  16349. count: 20,
  16350. sorting: {}
  16351. }, {
  16352. total: 0,
  16353. counts: [5, 10, 25, 50],
  16354. getData: function ($defer, params) {
  16355. $scope.loading = true;
  16356. var pageParams = params.url();
  16357. pageParams.keyword = $scope.keyword;
  16358. $scope.tip = $scope.keyword;
  16359. pageParams.searchFilter = $scope.searchFilter;
  16360. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16361. $scope.loading = false;
  16362. if (page) {
  16363. params.total(page.totalElement);
  16364. $scope.total = page.totalElement;
  16365. $defer.resolve(page.content);
  16366. }
  16367. }, function (response) {
  16368. $scope.loading = false;
  16369. toaster.pop('error', '数据加载失败', response.data);
  16370. });
  16371. }
  16372. });
  16373. // 搜索框回车
  16374. $scope.onSearch = function (keyword) {
  16375. // 每次搜索重置获取数据方法
  16376. $scope.searchMethod = false;
  16377. if(keyword != null && keyword != '') {
  16378. $scope.searchMethod = true;
  16379. }
  16380. $scope.tableParams.page(1);
  16381. $scope.tableParams.reload();
  16382. };
  16383. //在产品列表添加商品
  16384. $scope.check = function (product) {
  16385. $scope.tenderProd.push({
  16386. prodTitle: product.title,
  16387. prodCode: product.code,
  16388. brand: product.brand,
  16389. unit: product.unit,
  16390. qty: null
  16391. // 供应商企业信息
  16392. // enterpriseBaseInfo: [{}]
  16393. });
  16394. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16395. if ($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  16396. $scope.tenderProd.splice(i, 1);
  16397. }
  16398. }
  16399. };
  16400. $scope.loading = false;
  16401. // 获取收货地址列表
  16402. var loadShipAddress = function () {
  16403. ShipAddress.shipAddList({}, function (data) {
  16404. $scope.ships = data;
  16405. $scope.tender.shipadd = $scope.ships[0];
  16406. });
  16407. };
  16408. loadShipAddress();
  16409. // 获取地址信息
  16410. $http.get('resources/citydata/city.json', {
  16411. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  16412. }).then(function (response) {
  16413. $scope.provinces = response.data;
  16414. });
  16415. // 新增收货地址保存
  16416. $scope.saveShipAddress = function (ship) {
  16417. ship.address = ship.province + ship.city + ship.district;
  16418. ShipAddress.saveAddress({}, ship, function (data) {
  16419. if (data.success) {
  16420. // 获取收货地址列表
  16421. loadShipAddress();
  16422. toaster.pop('success', '提示', data.success);
  16423. }
  16424. if (data.error) {
  16425. toaster.pop('error', '提示', data.error);
  16426. }
  16427. });
  16428. };
  16429. // 可选的证照要求
  16430. $scope.certificates = [{name: '三/五证合一'}, {name: '营业执照'}, {name: '组织机构代码证'}, {name: '一般纳税人证明材料'}, {name: '统计登记证'}, {name: '社会保险登记证'}];
  16431. // 处理证照要求
  16432. var parseCertificate = function (a) {
  16433. if (a) {
  16434. var arr = a.split(',');
  16435. angular.forEach(arr, function (app) {
  16436. var contained = false;
  16437. angular.forEach($scope.certificates, function ($app) {
  16438. if ($app.name == app) {
  16439. $app.checked = true;
  16440. contained = true;
  16441. }
  16442. });
  16443. if (!contained) {
  16444. $scope.certificates.push({name: app, checked: true});
  16445. }
  16446. });
  16447. }
  16448. };
  16449. // 联想词start
  16450. // 获取品牌联想词
  16451. $scope.getSimilarBrands = function (value) {
  16452. if (value) {
  16453. // 获取品牌联想词
  16454. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  16455. return data.map(function (item) {
  16456. return item;
  16457. });
  16458. });
  16459. }
  16460. };
  16461. // 获取产品型号联想词
  16462. $scope.getSimilarCodes = function (value) {
  16463. if (value) {
  16464. // 获取产品型号联想词
  16465. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  16466. return data.map(function (item) {
  16467. return item;
  16468. })
  16469. });
  16470. }
  16471. };
  16472. // // 获取产品类目联想词
  16473. // $scope.getSimilarKinds = function(value) {
  16474. // if (value) {
  16475. // // getSimilarLeafKinds 根据类目名获取末级联想词
  16476. // // 获取类目联想词
  16477. // return Search.getSimilarKinds({keyword : value}).$promise.then(function(data) {
  16478. // return data.map(function(item) {
  16479. // return item;
  16480. // })
  16481. // });
  16482. // }
  16483. // };
  16484. // // 点击联想词获取类目信息
  16485. // $scope.onAssociateKindClick = function(kind, submit) {
  16486. // KindAPI.getParents({childId : kind.id}, {}, function(data) {
  16487. // $scope.actives = data;
  16488. // var size = data.length;
  16489. // if (size > 0) {
  16490. // submit.gradeOneKiName = $scope.actives[0].nameCn;
  16491. // submit.kiName = submit.gradeOneKiName;
  16492. // if (size > 1) {
  16493. // submit.gradeTwoKiName = $scope.actives[1].nameCn;
  16494. // submit.kiName = submit.gradeTwoKiName;
  16495. // if (kind.level < 3) {
  16496. // submit.gradeThreeKiName = null;
  16497. // } else if (size > 2) {
  16498. // submit.gradeThreeKiName = $scope.actives[2].nameCn;
  16499. // submit.kiName = submit.gradeThreeKiName;
  16500. // }
  16501. // }
  16502. // }
  16503. // })
  16504. // };
  16505. // 选择类目
  16506. $scope.selectKind = function (prod) {
  16507. var submit = [];
  16508. $modal.open({
  16509. animation: true,
  16510. size: 'lg',
  16511. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  16512. controller: 'ProdKindChooseCtrl',
  16513. resolve: {
  16514. actives: function () {
  16515. return $scope.actives;
  16516. }
  16517. }
  16518. }).result.then(function (data) {
  16519. $scope.actives = data.actives;
  16520. var size = data.actives.length;
  16521. submit.gradeOneKiName = '';
  16522. submit.gradeTwoKiName = '';
  16523. submit.gradeThreeKiName = '';
  16524. if (size > 0) {
  16525. submit.gradeOneKiName = $scope.actives[0].nameCn;
  16526. prod.prodTitle = submit.gradeOneKiName;
  16527. if (size > 1) {
  16528. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  16529. prod.prodTitle = submit.gradeTwoKiName;
  16530. if (size > 2) {
  16531. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  16532. prod.prodTitle = submit.gradeThreeKiName;
  16533. }
  16534. }
  16535. }
  16536. }, function () {
  16537. });
  16538. };
  16539. // // 验证分类信息
  16540. // $scope.checkKind = function() {
  16541. // setTimeout(function() {
  16542. // if($scope.activesString == null) {
  16543. // $scope.component.kindid = null;
  16544. // return;
  16545. // }
  16546. // KindAPI.getKindByName({name : encodeURIComponent($scope.activesString)}, function(kind) {
  16547. // $scope.component.kind = kind;
  16548. // $scope.component.kindid = kind.id;
  16549. // $scope.activesString = $scope.component.kind.nameCn;
  16550. // KindAPI.getPropertiesValues({kindId: $scope.component.kindid}, function(data) {
  16551. // $scope.kindProperties = data;
  16552. // angular.forEach($scope.kindProperties, function(kp) {
  16553. // angular.forEach($scope.component.properties, function(pro) {
  16554. // if (pro.value && (kp.propertyId == pro.propertyid)) {
  16555. // kp.value = pro.value;
  16556. // }
  16557. // });
  16558. // });
  16559. // }, function(response) {
  16560. // });
  16561. // }, function (response) {
  16562. // $scope.component.kindid = null;
  16563. // toaster.pop('error', response.data);
  16564. // });
  16565. // }, 500);
  16566. // };
  16567. // 点击联想词获取品牌信息
  16568. $scope.onAssociateBrandClick = function (brand, prod) {
  16569. if (brand instanceof String) {
  16570. prod.brand = brand;
  16571. } else if (brand instanceof Object) {
  16572. prod.brand = brand.brandCn;
  16573. }
  16574. };
  16575. // 打开品牌选择的模态框
  16576. $scope.selectBrand = function (prod) { //打开模态
  16577. var modalInstance = $modal.open({
  16578. size: 'lg',
  16579. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  16580. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  16581. });
  16582. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  16583. });
  16584. modalInstance.result.then(function (brand) {
  16585. prod.brand = brand.nameCn;
  16586. }, function (reason) {
  16587. });
  16588. };
  16589. // // 验证品牌是否正确
  16590. // $scope.checkBrand = function () {
  16591. // setTimeout(function () {
  16592. // BrandActiveAPI.findByName({name : encodeURIComponent($scope.component.brand.nameCn)}, function (data) {
  16593. // // $scope.component.brand = brand;
  16594. // // $scope.component.brandid = brand.id;
  16595. // }, function (response) {
  16596. // // $scope.component.brandid = null;
  16597. // toaster.pop('error', response.data);
  16598. // })
  16599. // } , 500);
  16600. // };
  16601. // 点击联想词获取器件信息 带入产品分类和品牌
  16602. $scope.onAssociateCmpClick = function (cmp, prod) {
  16603. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  16604. $scope.component = data;
  16605. prod.prodCode = data.code;
  16606. prod.prodTitle = data.kind.nameCn;
  16607. prod.brand = data.brand.nameCn;
  16608. }, function (res) {
  16609. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  16610. })
  16611. };
  16612. //联想词end
  16613. $scope.condition = {dateZone: 1};
  16614. $scope.tenderProd = [];
  16615. var prod = {
  16616. prodTitle: null,
  16617. prodCode: null,
  16618. brand: null,
  16619. unit: 'PCS',
  16620. qty: null
  16621. // 供应商企业信息
  16622. // enterpriseBaseInfo: [{}]
  16623. };
  16624. $scope.tender = {
  16625. date: new Date(),
  16626. unit: 'PCS',
  16627. currency: 'RMB',
  16628. ifOpen: 1,
  16629. ifTax: 1,
  16630. invoiceType: 2,
  16631. tenderAttachs: [{}]
  16632. };
  16633. //
  16634. $scope.tenderProd.push(prod);
  16635. //增加商品
  16636. $scope.add = function (index) {
  16637. $scope.tenderProd.push({
  16638. prodTitle: null,
  16639. prodCode: null,
  16640. brand: null,
  16641. unit: 'PCS',
  16642. qty: null
  16643. // 供应商企业信息
  16644. // enterpriseBaseInfo: [{}]
  16645. });
  16646. };
  16647. //删除商品
  16648. $scope.del = function (index) {
  16649. $scope.tenderProd.splice(index, 1);
  16650. };
  16651. // 批量导入
  16652. $scope.uplodaByBatch = function () {
  16653. var modalInstance = $modal.open({
  16654. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  16655. controller: 'PurcTenderUploadCtrl',
  16656. size: 'lg',
  16657. resolve: {}
  16658. });
  16659. modalInstance.result.then(function (data) {
  16660. // 获取上传的产品明细,前台展示
  16661. angular.forEach(data, function (data) {
  16662. $scope.tenderProd.push(data);
  16663. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16664. if ($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  16665. $scope.tenderProd.splice(i, 1);
  16666. }
  16667. }
  16668. });
  16669. }, function () {
  16670. });
  16671. };
  16672. $scope.isSave = false;
  16673. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  16674. if (!angular.isUndefined($stateParams.id)) {
  16675. $scope.isSave = true; // 用于判断是新增还是已保存
  16676. $scope.loading = true;
  16677. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  16678. data.$editing = false;
  16679. $scope.tender = data;
  16680. $scope.tenderProd = data.purchaseTenderProds;
  16681. parseCertificate($scope.tender.certificate);
  16682. $scope.firstProd = data.purchaseTenderProds[0];
  16683. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  16684. // 获取供应商联系人
  16685. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function (data) {
  16686. item.saleTender.enterpriseBaseInfo.contacts = data;
  16687. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  16688. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function (contact) {
  16689. if (item.saleTender.userTel === contact.tel) {
  16690. item.saleTender.enterpriseBaseInfo.contact = contact;
  16691. }
  16692. });
  16693. });
  16694. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  16695. $scope.tenderProd.enterpriseBaseInfo = [{}];
  16696. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  16697. } else {
  16698. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  16699. }
  16700. });
  16701. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  16702. $scope.loading = false;
  16703. $scope.attaches = $scope.tender.tenderAttaches;
  16704. }, function (response) {
  16705. $scope.loading = false;
  16706. toaster.pop('error', '数据加载失败', response.data);
  16707. });
  16708. }
  16709. if (angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  16710. $rootScope.tenderVendor = [{}];
  16711. }
  16712. $scope.changeShipAddress = false;
  16713. $scope.changeAddress = function () {
  16714. if ($scope.changeShipAddress) {
  16715. $scope.changeShipAddress = false;
  16716. } else {
  16717. $scope.changeShipAddress = true;
  16718. }
  16719. };
  16720. $scope.changeContactInfo = function (en) {
  16721. if (en.changeContact) {
  16722. en.changeContact = false;
  16723. } else {
  16724. en.changeContact = true;
  16725. }
  16726. };
  16727. $scope.changeCurrency = function (tender) {
  16728. if (tender.currency !== 'RMB') {
  16729. $scope.notRMB = true;
  16730. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  16731. tender.invoiceType = 0;
  16732. } else {
  16733. $scope.notRMB = false;
  16734. }
  16735. };
  16736. // $scope.validateNumber = function (value) { // 采购数量 正整数
  16737. // var regex = /^\+?[1-9][0-9]*$/;
  16738. // if (!regex.test(value) || value === 0 || value === null) {
  16739. // toaster.pop('warning', '警告', '采购数量不合法,请重新填写');
  16740. // }
  16741. // };
  16742. // 查找供应商
  16743. $scope.dbfindVendor = function () {
  16744. var modalInstance = $modal.open({
  16745. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  16746. controller: 'DbfindVendorCtrl',
  16747. size: 'lg',
  16748. resolve: {}
  16749. });
  16750. var ifPush = true;
  16751. modalInstance.result.then(function (data) {
  16752. angular.forEach(data, function (vendor) {
  16753. // 获取供应商联系人
  16754. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function (data) {
  16755. vendor.vendorEnterprise.contacts = data;
  16756. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  16757. });
  16758. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  16759. $scope.tenderProd.enterpriseBaseInfo = [{}];
  16760. // 获取供应商联系人
  16761. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  16762. } else {
  16763. for (var i = 0; i < $scope.tenderProd.enterpriseBaseInfo.length; i++) {
  16764. ifPush = true;
  16765. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  16766. ifPush = false;
  16767. break; // 判定到已存在供应商,就终止循环。
  16768. }
  16769. }
  16770. if (ifPush) {
  16771. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  16772. }
  16773. }
  16774. });
  16775. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  16776. }, function () {
  16777. });
  16778. };
  16779. // 新增供应商联系人
  16780. $scope.addContact = function (en) {
  16781. var modalInstance = $modal.open({
  16782. animation: true,
  16783. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  16784. controller: 'AddContacCtrl',
  16785. resolve: {}
  16786. });
  16787. modalInstance.result.then(function (data) {
  16788. en.contact = data;
  16789. en.contact.venduu = en.uu;
  16790. Vendor.saveContact({}, en.contact, function (data) {
  16791. Vendor.contacts({venduu: en.uu}, {}, function (data) {
  16792. en.contacts = data;
  16793. en.contact = data[0]; // 新增的作为联系人
  16794. });
  16795. toaster.pop('success', '提示', '联系人保存成功');
  16796. }, function (response) {
  16797. toaster.pop('error', '失败', response.data);
  16798. });
  16799. });
  16800. };
  16801. // 删除一个供应商
  16802. $scope.removeVendor = function (index) {
  16803. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  16804. };
  16805. // 删除供应商时,后台删除投标单
  16806. $scope.removeSaleTender = function (id, vendUU) {
  16807. var hasSaved = false;
  16808. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function (saleTenderItem) {
  16809. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  16810. hasSaved = true;
  16811. }
  16812. });
  16813. if (hasSaved) {
  16814. PurcTender.removeSaleTender({id: id, vendUU: vendUU}, {}, function (data) {
  16815. }, function (response) {
  16816. toaster.pop('error', '提示', response.data);
  16817. });
  16818. }
  16819. };
  16820. // 删除产品明细时,后台删除产品明细
  16821. $scope.deleteProd = function (tenderProd) {
  16822. if (tenderProd.id) {
  16823. PurcTender.deleteProd({tenderProdId: tenderProd.id}, {}, function (data) {
  16824. }, function (response) {
  16825. toaster.pop('error', '提示', response.data);
  16826. });
  16827. }
  16828. };
  16829. // // 查找客户物料
  16830. // $scope.dbfindCustProd = function(){
  16831. // if($scope.item.$editing) {
  16832. // if($scope.item.quotation.cust.uu) {
  16833. // var modalInstance = $modal.open({
  16834. // templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  16835. // controller: 'DbfindCustProdCtrl',
  16836. // size: 'lg',
  16837. // resolve: {
  16838. // custUU: function(){return $scope.item.quotation.cust.uu}
  16839. // }
  16840. // });
  16841. //
  16842. // modalInstance.result.then(function(data){
  16843. // $scope.item.product = data;
  16844. // }, function(){
  16845. //
  16846. // });
  16847. // } else {
  16848. // toaster.pop('error', '错误', '请先选择客户');
  16849. // }
  16850. // }
  16851. // };
  16852. if (!$scope.attaches) {
  16853. $scope.attaches = []; // 存放上传了的附件
  16854. }
  16855. $scope.upload = function (myFile) { // 上传附件
  16856. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  16857. $upload.upload({
  16858. url: 'tender/addTenderAttach',
  16859. file: file,
  16860. method: 'POST'
  16861. // data: {
  16862. // tender: $scope.tender
  16863. // }
  16864. }).success(function (attach) {
  16865. $scope.attaches.push(attach);
  16866. });
  16867. };
  16868. $scope.removeAttach = function (id, index) {
  16869. $scope.attaches.splice(index, 1);
  16870. // PurcTender.removeAttach({attachId:id}, function() {
  16871. //
  16872. // });
  16873. };
  16874. var sleep = function (d) {
  16875. for (var t = Date.now(); Date.now() - t <= d;);
  16876. };
  16877. // 保存和发布招标单
  16878. $scope.save = function (isPublish) {
  16879. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  16880. toaster.pop('info', '提示', '请先指定供应商');
  16881. } else {
  16882. $scope.loading = true;
  16883. // --组装证照要求
  16884. var myCertificate = [];
  16885. angular.forEach($scope.certificates, function (certificate) {
  16886. if (certificate.checked) {
  16887. myCertificate.push(certificate.name);
  16888. }
  16889. });
  16890. $scope.tender.certificate = myCertificate.join(',');
  16891. if (!$scope.tender.code) { //新增,设单号
  16892. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  16893. }
  16894. if ($scope.tender.date instanceof Date) {
  16895. $scope.tender.date = $scope.tender.date.getTime();
  16896. }
  16897. if ($scope.tender.endDate instanceof Date) {
  16898. $scope.tender.endDate = $scope.tender.endDate.getTime();
  16899. }
  16900. if ($scope.tender.publishDate instanceof Date) {
  16901. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  16902. }
  16903. if ($scope.tender.questionEndDate instanceof Date) {
  16904. $scope.tender.questionEndDate = $scope.tender.questionEndDate.getTime();
  16905. }
  16906. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  16907. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  16908. $scope.tender.purchaseTenderProds[i].index = i + 1;
  16909. }
  16910. $scope.tender.tenderAttaches = $scope.attaches;
  16911. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  16912. var enInfos = [];
  16913. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  16914. var enInfo = {
  16915. uu: null,
  16916. contact: null,
  16917. contactTel: null
  16918. };
  16919. enInfo.uu = enterpriseBaseInfo.uu;
  16920. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  16921. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  16922. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  16923. }
  16924. enInfos.push(enInfo);
  16925. });
  16926. if (isPublish) { // 发布
  16927. toaster.pop('info', '提示', '正在发布,请稍候');
  16928. $scope.tender.isPublish = 1;
  16929. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  16930. // sleep(1500); //当前方法暂停1.5秒
  16931. $scope.loading = false;
  16932. toaster.pop('success', '成功', '发布成功');
  16933. window.location.hash = '#/purc/tender';
  16934. }, function (response) {
  16935. $scope.loading = false;
  16936. toaster.pop('error', '发布失败', response.data);
  16937. });
  16938. } else { // 保存
  16939. toaster.pop('info', '提示', '正在保存,请稍候');
  16940. $scope.tender.isPublish = 0;
  16941. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  16942. $scope.loading = false;
  16943. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  16944. toaster.pop('success', '成功', '保存成功');
  16945. window.location.hash = '#/purc/tender';
  16946. }, function (response) {
  16947. $scope.loading = false;
  16948. toaster.pop('error', '保存失败', response.data);
  16949. });
  16950. }
  16951. }
  16952. };
  16953. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  16954. $scope.removeChecked = function () {
  16955. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  16956. $scope.tenderProd.enterpriseBaseInfo = [];
  16957. }
  16958. };
  16959. // 删除(在录入状态)
  16960. $scope.deleteThis = function (id) {
  16961. PurcTender.deleteOne({id: id}, {}, function (data) {
  16962. toaster.pop('info', '提示', '删除成功');
  16963. window.location.hash = '#/purc/tender';
  16964. });
  16965. };
  16966. // 更新和发布(在录入状态)
  16967. $scope.updateSaved = function (isPublish) {
  16968. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  16969. toaster.pop('info', '提示', '请先指定供应商');
  16970. } else {
  16971. $scope.loading = true;
  16972. // --组装证照要求
  16973. var myCertificate = [];
  16974. angular.forEach($scope.certificates, function (certificate) {
  16975. if (certificate.checked) {
  16976. myCertificate.push(certificate.name);
  16977. }
  16978. });
  16979. $scope.tender.certificate = myCertificate.join(',');
  16980. if ($scope.tender.endDate instanceof Date) {
  16981. $scope.tender.endDate = $scope.tender.endDate.getTime();
  16982. }
  16983. if ($scope.tender.publishDate instanceof Date) {
  16984. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  16985. }
  16986. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  16987. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  16988. $scope.tender.purchaseTenderProds[i].index = i + 1;
  16989. }
  16990. $scope.tender.tenderAttaches = $scope.attaches;
  16991. if ($scope.tender.shipadd) {
  16992. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  16993. }
  16994. angular.forEach($scope.tender.purchaseTenderProds, function (tenderProd) {
  16995. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  16996. });
  16997. var enInfos = [];
  16998. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  16999. var enInfo = {
  17000. uu: null,
  17001. contact: null,
  17002. contactTel: null
  17003. };
  17004. enInfo.uu = enterpriseBaseInfo.uu;
  17005. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17006. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17007. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17008. }
  17009. enInfos.push(enInfo);
  17010. });
  17011. if (isPublish) { // 发布
  17012. toaster.pop('info', '提示', '正在发布,请稍候');
  17013. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17014. $scope.loading = false;
  17015. toaster.pop('success', '成功', '发布成功');
  17016. window.location.hash = '#/purc/tender';
  17017. }, function (response) {
  17018. $scope.loading = false;
  17019. toaster.pop('error', '发布失败', response.data);
  17020. });
  17021. } else { // 保存
  17022. toaster.pop('info', '提示', '正在保存,请稍候');
  17023. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17024. $scope.loading = false;
  17025. toaster.pop('success', '成功', '保存成功');
  17026. window.location.reload();
  17027. }, function (response) {
  17028. $scope.loading = false;
  17029. toaster.pop('error', '保存失败', response.data);
  17030. });
  17031. }
  17032. }
  17033. };
  17034. $scope.currentDay = function () {
  17035. return $filter('date')(new Date(), 'yyyy-MM-dd');
  17036. };
  17037. $scope.getMinDate = function () {
  17038. // var now = new Date();
  17039. // now = now.setDate(now.getDate()+1);
  17040. // var minDate = angular.copy($scope.tender.endDate);
  17041. // minDate = minDate.setDate(minDate.getDate() + 1);
  17042. if ($scope.tender.endDate instanceof Date) {
  17043. var minDate = new Date($scope.tender.endDate.getTime() + 2 * 24 * 60 * 60 * 1000 + 1); // 公布结果日期与截止报价日期至少隔一天
  17044. }
  17045. 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');
  17046. };
  17047. $scope.getMaxDate = function () {
  17048. // var maxDate = angular.copy($scope.tender.publishDate);
  17049. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  17050. if ($scope.tender.publishDate instanceof Date) {
  17051. var maxDate = new Date($scope.tender.publishDate.getTime() - 24 * 60 * 60 * 1000 - 1); // 至少提前两天
  17052. }
  17053. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd') : "";
  17054. };
  17055. $scope.openDatePicker = function ($event, item, openParam) {
  17056. $event.preventDefault();
  17057. $event.stopPropagation();
  17058. item[openParam] = !item[openParam];
  17059. };
  17060. }]);
  17061. //类目选择模态框(招标产品明细)
  17062. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function ($scope, KindAPI, actives, toaster, $modalInstance) {
  17063. $scope.actives = actives;
  17064. $scope.kinds = [[], [], [], []];
  17065. // 获取子类目
  17066. var getChildren = function (pid, deep) {
  17067. KindAPI.getChildren({parentId: pid}, function (data) {
  17068. $scope.kinds[deep] = data;
  17069. }, function (response) {
  17070. toaster.pop('error', '获取子类目失败', response.data);
  17071. });
  17072. };
  17073. // 改变节点选中状态
  17074. var changeStatus = function (item, deep) {
  17075. var actives = [], level = 0;
  17076. angular.forEach($scope.kinds, function (ks, i) {
  17077. if (i > deep) {
  17078. $scope.kinds[i] = [];
  17079. } else {
  17080. angular.forEach(ks, function (k, j) {
  17081. if (i == deep) {
  17082. if (k.id == item.id) {
  17083. $scope.kinds[i][j].$active = true;
  17084. actives.push(k);
  17085. } else {
  17086. k.$active = null;
  17087. }
  17088. } else {
  17089. if (k.$active) {
  17090. actives.push(k);
  17091. }
  17092. }
  17093. });
  17094. }
  17095. });
  17096. // 选择的节点
  17097. $scope.actives = actives;
  17098. $scope.active = item;
  17099. // 当前可操作的层级
  17100. if (deep < 3) {
  17101. $scope.activeDeep = deep + 1;
  17102. }
  17103. };
  17104. // 节点点击后获取子类目,节点被选中
  17105. $scope.onItemClick = function (item, deep) {
  17106. changeStatus(item, deep);
  17107. if (!item.isLeaf) {
  17108. getChildren(item.id, deep + 1);
  17109. }
  17110. };
  17111. // 重新加载数据
  17112. function reload(deep) {
  17113. var pid;
  17114. if (deep) {
  17115. pid = $scope.actives[deep - 1].id;
  17116. } else {
  17117. pid = 0;
  17118. deep = 0;
  17119. }
  17120. getChildren(pid, deep);
  17121. }
  17122. // 初始加载数据,获取第一层的类目
  17123. if ($scope.actives) {
  17124. angular.forEach($scope.actives, function (v, k) {
  17125. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  17126. $scope.kinds[k] = data;
  17127. angular.forEach($scope.kinds[k], function (kind, i) {
  17128. if (kind.id == v.id) {
  17129. $scope.kinds[k][i].$active = true;
  17130. $scope.actives[k] = $scope.kinds[k][i];
  17131. }
  17132. })
  17133. }, function (response) {
  17134. toaster.pop('error', '获取子类目失败', response.data);
  17135. });
  17136. });
  17137. } else {
  17138. reload();
  17139. }
  17140. // 取消
  17141. $scope.cancel = function () {
  17142. $modalInstance.dismiss();
  17143. };
  17144. // 确认选择
  17145. $scope.check = function () {
  17146. var a = {
  17147. active: $scope.active,
  17148. actives: $scope.actives
  17149. };
  17150. $modalInstance.close(a);
  17151. };
  17152. }]);
  17153. //品牌选择模态框的controller
  17154. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function ($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  17155. $scope.filter = {};
  17156. $scope.brandsTableParams = new ngTableParams({
  17157. page: 1,
  17158. count: 6,
  17159. sorting: {
  17160. nameCn: 'asc'
  17161. }
  17162. }, {
  17163. total: 0,
  17164. counts: [],
  17165. getData: function ($defer, params) {
  17166. var param = BaseService.parseParams(params.url());
  17167. param.keyword = $scope.filter.keyword;
  17168. var keyword = $scope.filter.keyword;
  17169. // param.keyword = $scope.filter.keyword;
  17170. BrandActiveAPI.getSimpleInfoPage(param, {}, function (page) {
  17171. if (page) {
  17172. params.total(page.totalElements);
  17173. $defer.resolve(page.content);
  17174. }
  17175. }, function () {
  17176. });
  17177. }
  17178. });
  17179. // 搜索
  17180. $scope.search = function () {
  17181. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  17182. $scope.brandsTableParams.page(1);
  17183. $scope.brandsTableParams.reload();
  17184. };
  17185. // 选择
  17186. $scope.select = function (brand) {
  17187. $modalInstance.close(brand);
  17188. };
  17189. // 关闭
  17190. $scope.cancel = function () {
  17191. $modalInstance.dismiss();
  17192. };
  17193. }]);
  17194. /**
  17195. * 招标单批量导入
  17196. */
  17197. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  17198. // 通过excel批量上传物料
  17199. $scope.result = null;
  17200. $scope.upload = function () {
  17201. var file = $scope.myFiles[0];
  17202. $upload.upload({
  17203. url: 'tender/release/excel',
  17204. file: file,
  17205. method: 'POST'
  17206. }).success(function (data) {
  17207. $scope.result = data;
  17208. $scope.success = $scope.result.success;
  17209. $scope.total = $scope.result.total;
  17210. $scope.alters = $scope.result.alters;
  17211. }).error(function (response) {
  17212. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  17213. });
  17214. };
  17215. // 查看范例
  17216. $scope.showImg = function () {
  17217. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  17218. box.show();
  17219. box.find('img').attr('src', src);
  17220. box.find('a').click(function () {
  17221. box.hide();
  17222. });
  17223. box.dblclick(function () {
  17224. box.hide();
  17225. });
  17226. };
  17227. // 下载模板
  17228. $scope.download = function () {
  17229. window.location.href = 'tender/upload/template';
  17230. };
  17231. $scope.enSure = function () {
  17232. $modalInstance.close($scope.result.items);
  17233. }
  17234. $scope.cancel = function () {
  17235. $modalInstance.dismiss();
  17236. }
  17237. }]);
  17238. /**
  17239. * 评标
  17240. */
  17241. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, CurrentRole) {
  17242. BaseService.scrollBackToTop();
  17243. // 获取当前用户是否为普通用户
  17244. CurrentRole.isUser({}, {}, function (data) {
  17245. $scope.isUser = data.isUser;
  17246. });
  17247. $scope.tenderItems = [];
  17248. // 采购方获取评标单
  17249. var evaluation = function () {
  17250. $scope.loading = true;
  17251. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17252. data.$editing = false;
  17253. $scope.tender = data;
  17254. $scope.tableParams = new ngTableParams({}, {dataset: data});
  17255. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  17256. $scope.loading = false;
  17257. }, function (response) {
  17258. $scope.loading = false;
  17259. toaster.pop('error', '数据加载失败', response.data);
  17260. });
  17261. };
  17262. evaluation();
  17263. $scope.orderType = '';
  17264. // $scope.dir = '-';
  17265. // 改变排序顺序
  17266. $scope.changeOrder = function (type) {
  17267. $scope.orderType = type;
  17268. // if(!$scope.dir || $scope.dir === '') {
  17269. // $scope.dir = '-';
  17270. // }else {
  17271. // $scope.dir = '';
  17272. // }
  17273. };
  17274. $scope.submit = function (tender) {
  17275. var canSubmit = false;
  17276. var hasDecide = false;
  17277. angular.forEach(tender.purchaseTenderProds, function (tenderProd) {
  17278. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17279. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  17280. hasDecide = true;
  17281. }
  17282. });
  17283. if (hasDecide) {
  17284. canSubmit = true;
  17285. }
  17286. });
  17287. if (!canSubmit) {
  17288. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  17289. } else {
  17290. PurcTender.decide(tender, function () {
  17291. toaster.pop('success', '确认成功');
  17292. window.location.hash = '#/purc/tender';
  17293. }, function (response) {
  17294. toaster.pop('error', '确认失败', response.data);
  17295. });
  17296. }
  17297. }
  17298. }]);
  17299. /**
  17300. * 客户招标
  17301. *
  17302. */
  17303. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', 'PurcTenderInfo',
  17304. function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise, PurcTenderInfo) {
  17305. BaseService.scrollBackToTop();
  17306. if ($rootScope.active) {
  17307. $scope.active = $rootScope.active;
  17308. $rootScope.active = null;
  17309. } else {
  17310. $scope.active = 'todo';
  17311. }
  17312. $scope.searchStatus = false;
  17313. /**
  17314. * 改变类型
  17315. */
  17316. var getTypeCondition = function (zone, condition) {
  17317. if (zone == -1) {
  17318. condition.ifOpen = null;
  17319. } else if (zone == 1) {
  17320. condition.ifOpen = 1;
  17321. } else {
  17322. condition.ifOpen = 0;
  17323. }
  17324. };
  17325. $scope.dateZoneText = '不限';
  17326. $scope.typeText = '全部';
  17327. $scope.deliveryZoneText = '不限';
  17328. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17329. /* 时间筛选初始化*/
  17330. var fromDate = new Date();
  17331. var toDate = new Date();
  17332. fromDate.setMonth(fromDate.getMonth() - 1);
  17333. fromDate.setHours(0, 0, 0, 0);
  17334. toDate.setHours(23, 59, 59, 999);
  17335. $scope.condition.dateFrom = fromDate;
  17336. $scope.condition.dateTo = toDate;
  17337. $scope.changeDateZone = function (zone) {
  17338. $scope.condition.dateZone = zone;
  17339. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17340. $scope.condition.$dateZoneOpen = false;
  17341. getDateCondition(zone, $scope.condition);
  17342. $scope.tableParams.page(1);
  17343. $scope.tableParams.reload();
  17344. };
  17345. $scope.changeDeliveryZone = function (zone) {
  17346. $scope.condition.deliveryZoneText = zone;
  17347. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17348. $scope.condition.$delievryZoneOpen = false;
  17349. getDelveryCondition(zone, $scope.condition);
  17350. $scope.tableParams.page(1);
  17351. $scope.tableParams.reload();
  17352. };
  17353. $scope.changeType = function (type) {
  17354. $scope.condition.type = type;
  17355. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17356. getTypeCondition(type, $scope.condition);
  17357. $scope.tableParams.reload();
  17358. };
  17359. $scope.setActive = function (state) {
  17360. if ($scope.active != state) {
  17361. $scope.active = state;
  17362. if ($scope.tableParams.page() == 1)
  17363. $scope.tableParams.reload();
  17364. else
  17365. $scope.tableParams.page(1);
  17366. }
  17367. };
  17368. var getService = function () {
  17369. if ($scope.searchStatus) {
  17370. return PurcTender;
  17371. }
  17372. return PurcTenderInfo;
  17373. };
  17374. $scope.tableParams = new ngTableParams({
  17375. page: 1,
  17376. count: 20,
  17377. sorting: {
  17378. 'id': 'desc'
  17379. }
  17380. }, {
  17381. total: 0,
  17382. counts: [5, 10, 25, 50],
  17383. getData: function ($defer, params) {
  17384. $scope.loading = true;
  17385. var pageParams = params.url();
  17386. var realActive = {};
  17387. pageParams.searchFilter = { // 筛选条件
  17388. keyword: $scope.keyword,
  17389. pt_ifopen: $scope.condition.ifOpen,
  17390. fromDate: getDateTime($scope.condition.dateFrom),
  17391. endDate: getDateTime($scope.condition.dateTo)
  17392. };
  17393. AccountEnterprise.get({}, function (data) {
  17394. $scope.currentEn = data;
  17395. });
  17396. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17397. $scope.loading = false;
  17398. if (page) {
  17399. params.total(page.totalElement);
  17400. $defer.resolve(page.content);
  17401. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17402. angular.forEach(page.content, function (purcTender) {
  17403. purcTender.vendorHasBid = false;
  17404. angular.forEach(purcTender.purchaseTenderProds, function (tenderProd) {
  17405. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17406. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  17407. tenderProd.currentItem = saleTenderItem;
  17408. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  17409. purcTender.vendorHasBid = true;
  17410. }
  17411. }
  17412. });
  17413. });
  17414. });
  17415. }
  17416. }, function (response) {
  17417. $scope.loading = false;
  17418. toaster.pop('error', '数据加载失败', response.data);
  17419. });
  17420. }
  17421. });
  17422. //获得各分类未阅读数量
  17423. var getUnreadCount = function () {
  17424. PurcTender.getUnreadCount(null, function (data) {
  17425. $scope.unread = data;
  17426. });
  17427. };
  17428. getUnreadCount();
  17429. //设置单据已读
  17430. $scope.setOrdersRead = function (id) {
  17431. // 如果单据本身已读,则不发送请求修改数据
  17432. if (!$scope.isUnread(id)){
  17433. return;
  17434. }
  17435. var sourceId = [];
  17436. sourceId.push(id);
  17437. PurcTender.setRead({}, sourceId, function (message) {
  17438. // $scope.getUnreadIds();
  17439. getUnreadCount();
  17440. });
  17441. };
  17442. var getUnreadIds = function () {
  17443. PurcTender.getUnreadIds({}, "", function (message) {
  17444. $scope.unreadCode = message.content;
  17445. });
  17446. };
  17447. getUnreadIds();
  17448. $scope.isUnread = function (id) {
  17449. for (var i in $scope.unreadCode) {
  17450. if (id == $scope.unreadCode[i]) {
  17451. return true;
  17452. }
  17453. }
  17454. };
  17455. $scope.openDatePicker = function ($event, item, openParam) {
  17456. $event.preventDefault();
  17457. $event.stopPropagation();
  17458. item[openParam] = !item[openParam];
  17459. };
  17460. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17461. $event.preventDefault();
  17462. $event.stopPropagation();
  17463. item[openParam] = !item[openParam];
  17464. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17465. $scope.tableParams.reload();
  17466. }
  17467. };
  17468. $scope.parseDate = function (dateStr) {
  17469. if (dateStr)
  17470. return Date.parse(dateStr, 'yyyy-MM-dd');
  17471. return new Date();
  17472. };
  17473. // 选择查找日期
  17474. $scope.onDateCondition = function () {
  17475. $scope.tableParams.page(1);
  17476. $scope.tableParams.reload();
  17477. };
  17478. // 搜索框回车
  17479. $scope.onSearch = function () {
  17480. $scope.searchStatus = true;
  17481. $scope.tableParams.page(1);
  17482. $scope.tableParams.reload();
  17483. };
  17484. }]);
  17485. /**
  17486. * 招标提问列表
  17487. *
  17488. */
  17489. app.controller('SaleTenderQuestionListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17490. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17491. BaseService.scrollBackToTop();
  17492. if ($rootScope.active) {
  17493. $scope.active = $rootScope.active;
  17494. $rootScope.active = null;
  17495. } else {
  17496. $scope.active = 'todo';
  17497. }
  17498. $scope.searchStatus = false;
  17499. /**
  17500. * 改变类型
  17501. */
  17502. var getTypeCondition = function (zone, condition) {
  17503. if (zone == -1) {
  17504. condition.ifOpen = null;
  17505. } else if (zone == 1) {
  17506. condition.ifOpen = 1;
  17507. } else {
  17508. condition.ifOpen = 0;
  17509. }
  17510. };
  17511. $scope.dateZoneText = '不限';
  17512. $scope.typeText = '全部';
  17513. $scope.deliveryZoneText = '不限';
  17514. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17515. /* 时间筛选初始化*/
  17516. var fromDate = new Date();
  17517. var toDate = new Date();
  17518. fromDate.setMonth(fromDate.getMonth() - 1);
  17519. fromDate.setHours(0, 0, 0, 0);
  17520. toDate.setHours(23, 59, 59, 999);
  17521. $scope.condition.dateFrom = fromDate;
  17522. $scope.condition.dateTo = toDate;
  17523. $scope.changeDateZone = function (zone) {
  17524. $scope.condition.dateZone = zone;
  17525. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17526. $scope.condition.$dateZoneOpen = false;
  17527. getDateCondition(zone, $scope.condition);
  17528. $scope.tableParams.page(1);
  17529. $scope.tableParams.reload();
  17530. };
  17531. $scope.changeDeliveryZone = function (zone) {
  17532. $scope.condition.deliveryZoneText = zone;
  17533. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17534. $scope.condition.$delievryZoneOpen = false;
  17535. getDelveryCondition(zone, $scope.condition);
  17536. $scope.tableParams.page(1);
  17537. $scope.tableParams.reload();
  17538. };
  17539. $scope.changeType = function (type) {
  17540. $scope.condition.type = type;
  17541. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17542. getTypeCondition(type, $scope.condition);
  17543. $scope.tableParams.reload();
  17544. };
  17545. $scope.setActive = function (state) {
  17546. if ($scope.active != state) {
  17547. $scope.active = state;
  17548. if ($scope.tableParams.page() == 1)
  17549. $scope.tableParams.reload();
  17550. else
  17551. $scope.tableParams.page(1);
  17552. }
  17553. };
  17554. //TODO 增加直接从数据库取方法之后修改
  17555. var getService = function () {
  17556. if ($scope.searchStatus) {
  17557. return SaleTenderQuestion;
  17558. }
  17559. return SaleTenderQuestion;
  17560. };
  17561. $scope.tableParams = new ngTableParams({
  17562. page: 1,
  17563. count: 20,
  17564. sorting: {
  17565. 'id': 'desc'
  17566. }
  17567. }, {
  17568. total: 0,
  17569. counts: [5, 10, 25, 50],
  17570. getData: function ($defer, params) {
  17571. $scope.loading = true;
  17572. var pageParams = params.url();
  17573. var realActive = {};
  17574. pageParams.searchFilter = { // 筛选条件
  17575. keyword: $scope.keyword,
  17576. fromDate: getDateTime($scope.condition.dateFrom),
  17577. endDate: getDateTime($scope.condition.dateTo)
  17578. };
  17579. AccountEnterprise.get({}, function (data) {
  17580. $scope.currentEn = data;
  17581. });
  17582. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17583. $scope.loading = false;
  17584. params.total(page.totalElement);
  17585. $defer.resolve(page.content);
  17586. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17587. }, function (response) {
  17588. $scope.loading = false;
  17589. toaster.pop('error', '数据加载失败', response.data);
  17590. });
  17591. }
  17592. });
  17593. //TODO 获得各分类未阅读数量
  17594. //TODO 设置单据已读
  17595. $scope.openDatePicker = function ($event, item, openParam) {
  17596. $event.preventDefault();
  17597. $event.stopPropagation();
  17598. item[openParam] = !item[openParam];
  17599. };
  17600. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17601. $event.preventDefault();
  17602. $event.stopPropagation();
  17603. item[openParam] = !item[openParam];
  17604. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17605. $scope.tableParams.reload();
  17606. }
  17607. };
  17608. $scope.parseDate = function (dateStr) {
  17609. if (dateStr)
  17610. return Date.parse(dateStr, 'yyyy-MM-dd');
  17611. return new Date();
  17612. };
  17613. // 选择查找日期
  17614. $scope.onDateCondition = function () {
  17615. $scope.tableParams.page(1);
  17616. $scope.tableParams.reload();
  17617. };
  17618. // 搜索框回车
  17619. $scope.onSearch = function (keyword) {
  17620. // 每次搜索重置获取数据方法
  17621. $scope.searchMethod = false;
  17622. if(keyword != null && keyword != '') {
  17623. $scope.searchMethod = true;
  17624. }
  17625. $scope.tableParams.page(1);
  17626. $scope.tableParams.reload();
  17627. };
  17628. }]);
  17629. /**
  17630. * 投标单提问单详情
  17631. */
  17632. app.controller('SaleTenderQuestionDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams'
  17633. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams){
  17634. BaseService.scrollBackToTop();
  17635. $scope.loading = true;
  17636. var loadData = function () {
  17637. SaleTenderQuestion.getDetail({id: $stateParams.id}, function(data){
  17638. $scope.loading = false;
  17639. $scope.question = data;
  17640. } , function (response) {
  17641. $scope.loading = false;
  17642. toaster.pop('error', '数据加载失败');
  17643. });
  17644. };
  17645. loadData();
  17646. }]);
  17647. /**
  17648. * 招标答疑列表
  17649. *
  17650. */
  17651. app.controller('PurcTenderAnswerListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17652. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17653. BaseService.scrollBackToTop();
  17654. if ($rootScope.active) {
  17655. $scope.active = $rootScope.active;
  17656. $rootScope.active = null;
  17657. } else {
  17658. $scope.active = 'todo';
  17659. }
  17660. $scope.searchStatus = false;
  17661. /**
  17662. * 改变类型
  17663. */
  17664. var getTypeCondition = function (zone, condition) {
  17665. if (zone == -1) {
  17666. condition.ifOpen = null;
  17667. } else if (zone == 1) {
  17668. condition.ifOpen = 1;
  17669. } else {
  17670. condition.ifOpen = 0;
  17671. }
  17672. };
  17673. /**
  17674. * 当前页面状态按钮过滤
  17675. */
  17676. var getAnswer = function (active) {
  17677. var fn = 'getAllAnswer';
  17678. switch (active) {
  17679. case 'done':
  17680. fn = 'getDoneAnswer';
  17681. break;
  17682. case 'todo':
  17683. fn = 'getTodoAnswer';
  17684. break;
  17685. }
  17686. return fn;
  17687. };
  17688. $scope.dateZoneText = '不限';
  17689. $scope.typeText = '全部';
  17690. $scope.deliveryZoneText = '不限';
  17691. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17692. /* 时间筛选初始化*/
  17693. var fromDate = new Date();
  17694. var toDate = new Date();
  17695. fromDate.setMonth(fromDate.getMonth() - 1);
  17696. fromDate.setHours(0, 0, 0, 0);
  17697. toDate.setHours(23, 59, 59, 999);
  17698. $scope.condition.dateFrom = fromDate;
  17699. $scope.condition.dateTo = toDate;
  17700. $scope.changeDateZone = function (zone) {
  17701. $scope.condition.dateZone = zone;
  17702. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17703. $scope.condition.$dateZoneOpen = false;
  17704. getDateCondition(zone, $scope.condition);
  17705. $scope.tableParams.page(1);
  17706. $scope.tableParams.reload();
  17707. };
  17708. $scope.changeDeliveryZone = function (zone) {
  17709. $scope.condition.deliveryZoneText = zone;
  17710. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17711. $scope.condition.$delievryZoneOpen = false;
  17712. getDelveryCondition(zone, $scope.condition);
  17713. $scope.tableParams.page(1);
  17714. $scope.tableParams.reload();
  17715. };
  17716. $scope.changeType = function (type) {
  17717. $scope.condition.type = type;
  17718. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17719. getTypeCondition(type, $scope.condition);
  17720. $scope.tableParams.reload();
  17721. };
  17722. $scope.setActive = function (state) {
  17723. if ($scope.active != state) {
  17724. $scope.active = state;
  17725. if ($scope.tableParams.page() == 1)
  17726. $scope.tableParams.reload();
  17727. else
  17728. $scope.tableParams.page(1);
  17729. }
  17730. };
  17731. //TODO 增加直接从数据库取方法之后修改
  17732. var getService = function () {
  17733. if ($scope.searchStatus) {
  17734. return SaleTenderQuestion;
  17735. }
  17736. return SaleTenderQuestion;
  17737. };
  17738. $scope.tableParams = new ngTableParams({
  17739. page: 1,
  17740. count: 20,
  17741. sorting: {
  17742. 'id': 'desc'
  17743. }
  17744. }, {
  17745. total: 0,
  17746. counts: [5, 10, 25, 50],
  17747. getData: function ($defer, params) {
  17748. $scope.loading = true;
  17749. var pageParams = params.url();
  17750. var realActive = {};
  17751. pageParams.searchFilter = { // 筛选条件
  17752. keyword: $scope.keyword,
  17753. fromDate: getDateTime($scope.condition.dateFrom),
  17754. endDate: getDateTime($scope.condition.dateTo)
  17755. };
  17756. AccountEnterprise.get({}, function (data) {
  17757. $scope.currentEn = data;
  17758. });
  17759. getService()[getAnswer($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17760. $scope.loading = false;
  17761. params.total(page.totalElement);
  17762. $defer.resolve(page.content);
  17763. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17764. }, function (response) {
  17765. $scope.loading = false;
  17766. toaster.pop('error', '数据加载失败', response.data);
  17767. });
  17768. }
  17769. });
  17770. //TODO 获得各分类未阅读数量
  17771. //TODO 设置单据已读
  17772. $scope.openDatePicker = function ($event, item, openParam) {
  17773. $event.preventDefault();
  17774. $event.stopPropagation();
  17775. item[openParam] = !item[openParam];
  17776. };
  17777. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17778. $event.preventDefault();
  17779. $event.stopPropagation();
  17780. item[openParam] = !item[openParam];
  17781. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17782. $scope.tableParams.reload();
  17783. }
  17784. };
  17785. $scope.parseDate = function (dateStr) {
  17786. if (dateStr)
  17787. return Date.parse(dateStr, 'yyyy-MM-dd');
  17788. return new Date();
  17789. };
  17790. // 选择查找日期
  17791. $scope.onDateCondition = function () {
  17792. $scope.tableParams.page(1);
  17793. $scope.tableParams.reload();
  17794. };
  17795. // 搜索框回车
  17796. $scope.onSearch = function (keyword) {
  17797. // 每次搜索重置获取数据方法
  17798. $scope.searchMethod = false;
  17799. if(keyword != null && keyword != '') {
  17800. $scope.searchMethod = true;
  17801. }
  17802. $scope.tableParams.page(1);
  17803. $scope.tableParams.reload();
  17804. };
  17805. }]);
  17806. /**
  17807. * 招标答疑单详情
  17808. */
  17809. app.controller('PurcTenderAnswerDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams', '$modal'
  17810. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams, $modal){
  17811. BaseService.scrollBackToTop();
  17812. $scope.loading = true;
  17813. var loadData = function () {
  17814. SaleTenderQuestion.getAnswerDetail({id: $stateParams.id}, function(data){
  17815. $scope.loading = false;
  17816. $scope.answer = data;
  17817. var now = new Date();
  17818. if ($scope.answer.questionEndDate < now.getTime()) {
  17819. $scope.answer.questionEnd = 1;
  17820. } else {
  17821. $scope.answer.questionEnd = 0;
  17822. }
  17823. } , function (response) {
  17824. $scope.loading = false;
  17825. toaster.pop('error', '数据加载失败');
  17826. });
  17827. };
  17828. loadData();
  17829. // 回答
  17830. $scope.sendAnswer = function (){
  17831. var modalInstance = $modal.open({
  17832. animation: true,
  17833. templateUrl: 'static/tpl/index/purc/tender_answer.html',
  17834. controller: 'PurcTenderAnswerCtrl',
  17835. size: 'lg',
  17836. resolve: {
  17837. answer: function () {
  17838. return $scope.answer;
  17839. } //传递当前答疑单到模态框Controller
  17840. }
  17841. });
  17842. modalInstance.result.then(function () {
  17843. toaster.pop('success', '答疑成功');
  17844. }, function () {
  17845. });
  17846. };
  17847. }]);
  17848. /**
  17849. * 招标单答疑
  17850. */
  17851. app.controller('PurcTenderAnswerCtrl', ['$scope', 'answer','$modalInstance', '$upload', 'toaster', function($scope, answer, $modalInstance, $upload ,toaster){
  17852. $scope.answer = answer;
  17853. $scope.cancel = function() {
  17854. $modalInstance.dismiss();
  17855. };
  17856. //确认回答
  17857. $scope.ok = function (form) {
  17858. $scope.loading = true;
  17859. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  17860. $upload.upload({
  17861. url: 'tender/question/answer/send',
  17862. method: 'POST',
  17863. file: file,
  17864. data: {
  17865. json: $scope.answer
  17866. }
  17867. }).success(function (data) {
  17868. $scope.loading = false;
  17869. $modalInstance.close('success');
  17870. }).error(function (data) {
  17871. $scope.loading = false;
  17872. toaster.pop('error', '错误', '出现异常,答疑失败');
  17873. });
  17874. };
  17875. }]);
  17876. /**
  17877. * 平台公开招标
  17878. *
  17879. */
  17880. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17881. BaseService.scrollBackToTop();
  17882. /**
  17883. * 改变单据日期范围
  17884. */
  17885. var getTenderDateCondition = function (zone, condition) {
  17886. var date = new Date();
  17887. if (zone == -1) {
  17888. condition.dateFrom = null;
  17889. condition.dateTo = null;
  17890. } else if (zone == 7) { // 一星期内
  17891. date.setDate(date.getDate() - 7);
  17892. condition.dateFrom = date;
  17893. condition.dateTo = new Date();
  17894. } else if (zone == 1) { // 一个月内
  17895. date.setMonth(date.getMonth() - 1);
  17896. condition.dateFrom = date;
  17897. condition.dateTo = new Date();
  17898. } else if (zone == 3) { // 三个月内
  17899. date.setMonth(date.getMonth() - 3);
  17900. condition.dateFrom = date;
  17901. condition.dateTo = new Date();
  17902. } else if (zone == 6) { // 半年内
  17903. date.setMonth(date.getMonth() - 6);
  17904. condition.dateFrom = date;
  17905. condition.dateTo = new Date();
  17906. } else { // 一年内
  17907. date.setYear(date.getYear() - 1);
  17908. condition.dateFrom = date;
  17909. condition.dateTo = new Date();
  17910. }
  17911. };
  17912. $scope.active = 'all';
  17913. $scope.dateZoneText = '不限';
  17914. $scope.deliveryZoneText = '不限';
  17915. $scope.condition = {dateZone: -1};
  17916. $scope.changeDateZone = function (zone) {
  17917. $scope.condition.dateZone = zone;
  17918. $scope.condition.$dateZoneOpen = false;
  17919. getTenderDateCondition(zone, $scope.condition);
  17920. $scope.tableParams.page(1);
  17921. $scope.tableParams.reload();
  17922. };
  17923. $scope.openDatePicker = function ($event, item, openParam) {
  17924. $event.preventDefault();
  17925. $event.stopPropagation();
  17926. item[openParam] = !item[openParam];
  17927. };
  17928. $scope.parseDate = function (dateStr) {
  17929. if (dateStr)
  17930. return Date.parse(dateStr, 'yyyy-MM-dd');
  17931. return new Date();
  17932. };
  17933. // 选择查找日期
  17934. $scope.onDateCondition = function () {
  17935. $scope.tableParams.page(1);
  17936. $scope.tableParams.reload();
  17937. };
  17938. // $scope.setActive = function(state) {
  17939. // if($scope.active != state) {
  17940. // $scope.active = state;
  17941. // if($scope.tableParams.page() == 1)
  17942. // $scope.tableParams.reload();
  17943. // else
  17944. // $scope.tableParams.page(1);
  17945. // }
  17946. // };
  17947. var getOpenState = function (active) {
  17948. var fn = 'getOpenAll';
  17949. switch (active) {
  17950. case 'all':
  17951. fn = 'getOpenAll';
  17952. break;
  17953. // case 'done':
  17954. // fn = 'getOpenDone';break;
  17955. case 'todo':
  17956. fn = 'getOpenTodo';
  17957. break;
  17958. case 'end':
  17959. fn = 'getOpenEnd';
  17960. break;
  17961. // case 'waiting':
  17962. // fn = 'getOpenWaiting';break;
  17963. }
  17964. return fn;
  17965. };
  17966. $scope.tableParams = new ngTableParams({
  17967. page: 1,
  17968. count: 20,
  17969. sorting: {
  17970. 'tender.endDate': 'desc',
  17971. 'tender.enterprise.enName': 'asc',
  17972. 'tender.code': 'asc'
  17973. }
  17974. }, {
  17975. total: 0,
  17976. counts: [],
  17977. getData: function ($defer, params) {
  17978. $scope.loading = true;
  17979. var pageParams = params.url();
  17980. var realActive = {};
  17981. pageParams.searchFilter = { // 筛选条件
  17982. keyword: $scope.keyword,
  17983. fromDate: getDateTime($scope.condition.dateFrom),
  17984. endDate: getDateTime($scope.condition.dateTo)
  17985. };
  17986. AccountEnterprise.get({}, function (data) {
  17987. $scope.currentEn = data;
  17988. });
  17989. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17990. $scope.loading = false;
  17991. if (page) {
  17992. params.total(page.totalElement);
  17993. $defer.resolve(page.content);
  17994. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17995. }
  17996. }, function (response) {
  17997. $scope.loading = false;
  17998. toaster.pop('error', '数据加载失败', response.data);
  17999. });
  18000. }
  18001. });
  18002. $scope.toDetail = function (id) {
  18003. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  18004. };
  18005. // var stautsItem = [];
  18006. // $scope.getTenderStatus = function (tender) {
  18007. // angular.forEach(tender.purchaseTenderItems, function(thisItem){
  18008. // if ($scope.currentEn.uu == thisItem.enterpriseBaseInfo.uu) {
  18009. // stautsItem = thisItem;
  18010. // }
  18011. // });
  18012. // if (!stautsItem.price) {
  18013. // return "daitoubiao";
  18014. // } else if (!stautsItem.applystatus) {
  18015. // return "yitoubiao";
  18016. // } else if (stautsItem.applystatus == 1) {
  18017. // return "zhongbiao";
  18018. // } else if (stautsItem.applystatus == 0) {
  18019. // return "weizhongbiao";
  18020. // }
  18021. // };
  18022. // 搜索框回车
  18023. $scope.onSearch = function () {
  18024. $scope.tableParams.page(1);
  18025. $scope.tableParams.reload();
  18026. };
  18027. }]);
  18028. /**
  18029. * 采购方查看供应商投标单
  18030. */
  18031. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  18032. $scope.loading = true;
  18033. PurcTender.getVendorSaleTenderDetail({tenderId: $stateParams.id, vendUU:$stateParams.vendUU}, function (data) {
  18034. $scope.saleTender = data.saleTender;
  18035. $scope.tender = data.tender;
  18036. $scope.loading = false;
  18037. }, function (response) {
  18038. $scope.loading = false;
  18039. toaster.pop('error', '数据加载失败', response.data);
  18040. });
  18041. }]);
  18042. /**
  18043. * 查看投标单详情
  18044. */
  18045. 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) {
  18046. BaseService.scrollBackToTop();
  18047. if (!$scope.attaches) {
  18048. $scope.attaches = []; // 存放上传了的附件
  18049. }
  18050. AccountEnterprise.get({}, function (data) {
  18051. $scope.currentEn = data;
  18052. });
  18053. // 获取当前用户是否为普通用户
  18054. CurrentRole.isUser({}, {}, function (data) {
  18055. $scope.isUser = data.isUser;
  18056. });
  18057. $scope.loading = true;
  18058. PurcTender.getSaleTenderDetail({tenderId: $stateParams.id}, function (data) {
  18059. $scope.saleTender = data.saleTender;
  18060. $scope.tender = data.tender;
  18061. $scope.loading = false;
  18062. }, function (response) {
  18063. $scope.loading = false;
  18064. toaster.pop('error', '数据加载失败', response.data);
  18065. });
  18066. // 提问
  18067. $scope.sendQuestion = function (){
  18068. var modalInstance = $modal.open({
  18069. animation: true,
  18070. templateUrl: 'static/tpl/index/sale/tender_question.html',
  18071. controller: 'SaleTenderQuestionCtrl',
  18072. size: 'lg',
  18073. resolve: {
  18074. saleTender: function () {
  18075. return $scope.saleTender;
  18076. } //传递当前投标单到模态框Controller
  18077. }
  18078. });
  18079. modalInstance.result.then(function () {
  18080. toaster.pop('success', '提问成功');
  18081. }, function () {
  18082. });
  18083. };
  18084. // // 提问记录
  18085. // $scope.showQuestionHistory = function (){
  18086. // var modalInstance = $modal.open({
  18087. // animation: true,
  18088. // templateUrl: 'static/tpl/index/sale/tender_question_history.html',
  18089. // controller: 'saleTenderQuestionHistoryCtrl',
  18090. // size: 'lg',
  18091. // resolve: {
  18092. // saleTender: function () {
  18093. // return $scope.saleTender;
  18094. // } //传递当前投标单到模态框Controller
  18095. // }
  18096. // });
  18097. // modalInstance.result.then(function () {
  18098. //
  18099. // }, function () {
  18100. //
  18101. // });
  18102. // };
  18103. $scope.upload = function (myFile) { // 上传附件
  18104. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  18105. $upload.upload({
  18106. url: 'tender/addTenderItemAttach',
  18107. file: file,
  18108. method: 'POST'
  18109. }).success(function (attach) {
  18110. $scope.attaches.push(attach);
  18111. });
  18112. };
  18113. $scope.removeAttach = function (attachId, index) {
  18114. $scope.attaches.splice(index, 1);
  18115. };
  18116. var taxrateYes = false;
  18117. var cycleYes = false;
  18118. var priceYes = false;
  18119. $scope.canSave = false;
  18120. $scope.validateThis = function (value, type) {
  18121. if ("" != value) {
  18122. switch (type) {
  18123. case 'taxrate':
  18124. var regex = /^\+?[0-9][0-9]{0,1}$/;
  18125. if (regex.test(value)) {
  18126. taxrateYes = true;
  18127. } else {
  18128. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  18129. }
  18130. break;
  18131. case 'cycle':
  18132. regex = /^\+?[1-9][0-9]*$/;
  18133. if (regex.test(value)) {
  18134. cycleYes = true;
  18135. } else {
  18136. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  18137. }
  18138. break;
  18139. case 'price':
  18140. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18141. if (regex.test(value) && value !== 0) {
  18142. priceYes = true;
  18143. } else {
  18144. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  18145. }
  18146. break;
  18147. }
  18148. }
  18149. };
  18150. $scope.emNumYes = true;
  18151. $scope.validEmNum = function (value) {
  18152. var regex = /^\+?[1-9][0-9]*$/;
  18153. if (!regex.test(value) || value === 0 || value !== null) {
  18154. $scope.emNumYes = false;
  18155. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  18156. }
  18157. };
  18158. $scope.validateProds = function (saleTender) {
  18159. $scope.canSave = true;
  18160. var cycleRegex = /^\+?[1-9][0-9]*$/;
  18161. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  18162. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  18163. if ($scope.tender.ifAll == 1) { // 全包时需要所有信息都填写并合法才可以投标
  18164. // 全包全部需要填写,且需要符合正则式
  18165. angular.forEach(saleTender.saleTenderItems, function(item) {
  18166. if ((!item.cycle || !item.price) || (!cycleRegex.test(item.cycle) || !priceRegex.test(item.price))) {
  18167. $scope.canSave = false;
  18168. }
  18169. });
  18170. if (!saleTender.cycle || !saleTender.taxrate || !cycleRegex.test(saleTender.cycle) || !taxrateRegex.test(saleTender.taxrate)) {
  18171. $scope.canSave = false;
  18172. }
  18173. } else { // 非全包模式
  18174. angular.forEach(saleTender.saleTenderItems, function(item) {
  18175. if (item.cycle || item.taxrate || item.price) {
  18176. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18177. // 判断填写过的有为0或不符合正则式的,设置不能保存
  18178. if (!cycleRegex.test(item.cycle) || !taxrateRegex.test(item.taxrate) || !priceRegex.test(item.price)) {
  18179. $scope.canSave = false;
  18180. } else {
  18181. $scope.canSave = true;
  18182. }
  18183. }
  18184. });
  18185. }
  18186. };
  18187. // 投标
  18188. $scope.bidIt = function (saleTender) {
  18189. $scope.loading = true;
  18190. if (saleTender.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  18191. saleTender.enterpriseBaseInfo.enEstablishDate = saleTender.enterpriseBaseInfo.enEstablishDate.getTime();
  18192. }
  18193. saleTender.bidAttaches.push.apply(saleTender.bidAttaches, $scope.attaches);
  18194. angular.forEach(saleTender.saleTenderItems, function (item) {
  18195. item.tenderProd = {};
  18196. if ("" == item.price && "" == item.taxrate && "" == item.cycle) {
  18197. item.price = 0;
  18198. item.cycle = 0;
  18199. item.taxrate = 0;
  18200. }
  18201. });
  18202. PurcTender.reply({}, saleTender, function (data) {
  18203. $scope.loading = false;
  18204. toaster.pop('info', '成功', '投标成功');
  18205. // $window.location.reload();
  18206. // if (tender.ifOpen) { // 根据是否公开,选择跳转
  18207. // window.location.hash = '#/sale/opentender';
  18208. // } else {
  18209. window.location.hash = '#/sale/tender';
  18210. // }
  18211. }, function (response) {
  18212. $scope.loading = false;
  18213. toaster.pop('error', '投标失败', response.data);
  18214. });
  18215. };
  18216. $scope.condition = {
  18217. $fromOpened: false
  18218. };
  18219. $scope.getMaxDate = function () {
  18220. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18221. };
  18222. $scope.openDatePicker = function ($event, item, openParam) {
  18223. $event.preventDefault();
  18224. $event.stopPropagation();
  18225. item[openParam] = !item[openParam];
  18226. };
  18227. }]);
  18228. /**
  18229. * 投标单提问
  18230. */
  18231. app.controller('SaleTenderQuestionCtrl', ['$scope', 'saleTender','$modalInstance', '$upload', 'toaster', function($scope, saleTender, $modalInstance, $upload ,toaster){
  18232. $scope.saleTender = saleTender;
  18233. // 当前日期,用作新增提问
  18234. $scope.currentDay = new Date();
  18235. $scope.question = {
  18236. inDate : null,
  18237. replyDate : null,
  18238. topic : null,
  18239. status : null,
  18240. content : null,
  18241. questionAttaches : []
  18242. };
  18243. $scope.cancel = function() {
  18244. $modalInstance.dismiss();
  18245. };
  18246. //确认提问
  18247. $scope.ok = function (form) {
  18248. $scope.loading = true;
  18249. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18250. $upload.upload({
  18251. url: 'tender/question/send/' + $scope.saleTender.id,
  18252. method: 'POST',
  18253. file: file,
  18254. data: {
  18255. json: $scope.question
  18256. }
  18257. }).success(function (data) {
  18258. $scope.loading = false;
  18259. $modalInstance.close('success');
  18260. }).error(function (data) {
  18261. $scope.loading = false;
  18262. toaster.pop('error', '错误', '出现异常,提问失败');
  18263. });
  18264. };
  18265. }]);
  18266. // /**
  18267. // * 当前投标单提问记录
  18268. // */
  18269. // app.controller('saleTenderQuestionHistoryCtrl', ['$scope', 'saleTender','$modalInstance', 'toaster', function($scope, saleTender, $modalInstance, toaster){
  18270. // $scope.saleTender = saleTender;
  18271. //
  18272. //
  18273. // $scope.cancel = function() {
  18274. // $modalInstance.dismiss();
  18275. // };
  18276. //
  18277. // }]);
  18278. /**
  18279. * 公开招标转投标单
  18280. */
  18281. 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) {
  18282. BaseService.scrollBackToTop();
  18283. $scope.attaches = []; // 存放上传了的附件
  18284. var sleep = function (d) {
  18285. for (var t = Date.now(); Date.now() - t <= d;);
  18286. }
  18287. var getCurrentEn = function () {
  18288. AccountEnterprise.get({}, function (data) {
  18289. $scope.currentEn = data;
  18290. });
  18291. }
  18292. if (!angular.isUndefined($stateParams.id)) { // 获取招标单详情
  18293. $scope.loading = true;
  18294. getCurrentEn();
  18295. PurcTender.getOne({id: $stateParams.id}, function (data) {
  18296. data.$editing = false;
  18297. $scope.tender = data;
  18298. $scope.tenderProd = data.purchaseTenderProds;
  18299. // parseCertificate($scope.tender.certificate);
  18300. // $scope.firstProd = data.purchaseTenderProds[0];
  18301. $scope.currentHasBid = false; // 默认当前企业未转投标单
  18302. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  18303. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  18304. $scope.currentHasBid = true;
  18305. }
  18306. });
  18307. // $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  18308. $scope.loading = false;
  18309. $scope.attaches = $scope.tender.tenderAttaches;
  18310. }, function (response) {
  18311. $scope.loading = false;
  18312. toaster.pop('error', '数据加载失败', response.data);
  18313. });
  18314. }
  18315. $scope.hasClick = false;
  18316. $scope.iWantToBid = function (id) {
  18317. $scope.hasClick = true;
  18318. PurcTender.addItems({id: id}, {}, function (data) { // 添加明细
  18319. // $scope.tender = data;
  18320. // angular.forEach(data.purchaseTenderProds, function(tenderProd) {
  18321. // angular.forEach(tenderProd.saleTenderItems, function(saleTenderItem) {
  18322. // if (!$scope.currentEn) {
  18323. // AccountEnterprise.get({}, function(data){
  18324. // $scope.currentEn = data;
  18325. // });
  18326. // }
  18327. // if (saleTenderItem.saleTender.vendUU === $scope.currentEn.uu) {
  18328. // tenderProd.currentItem = saleTenderItem;
  18329. // $scope.saleTender = saleTenderItem.saleTender;
  18330. // $scope.attaches = saleTenderItem.saleTender.bidAttaches;
  18331. // $scope.currentEnBaseInfo = saleTenderItem.saleTender.enterpriseBaseInfo;
  18332. // }
  18333. // });
  18334. // });
  18335. toaster.pop('success', '成功', '转投标单成功');
  18336. window.location.hash = "#/sale/tender/" + id;
  18337. }, function (response) {
  18338. toaster.pop('error', '操作失败', response.data);
  18339. });
  18340. // $scope.upload = function(myFile) { // 上传附件
  18341. // var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  18342. // $upload.upload({
  18343. // url: 'tender/addTenderItemAttach',
  18344. // file: file,
  18345. // method: 'POST'
  18346. // }).success(function (attach) {
  18347. // $scope.attaches.push(attach);
  18348. // });
  18349. // };
  18350. };
  18351. // $scope.removeAttach = function(id, index) {
  18352. // $scope.attaches.splice(index, 1);
  18353. // PurcTender.removeAttach({attachId:id}, function() {
  18354. //
  18355. // });
  18356. // };
  18357. // var taxrateYes = false;
  18358. // var cycleYes = false;
  18359. // var priceYes = false;
  18360. // $scope.canSave = false;
  18361. // $scope.validateThis = function(value, type) {
  18362. // switch(type) {
  18363. // case 'taxrate':
  18364. // var regex = /^\+?[0-9][0-9]{0,1}$/;
  18365. // if (regex.test(value)) {
  18366. // taxrateYes = true;
  18367. // } else {
  18368. // toaster.pop('warning', '警告', '税率不合法,请重新填写');
  18369. // }
  18370. // break;
  18371. // case 'cycle':
  18372. // regex = /^\+?[1-9][0-9]*$/;
  18373. // if (regex.test(value)) {
  18374. // cycleYes = true;
  18375. // } else {
  18376. // toaster.pop('warning', '警告', '周期不合法,请重新填写');
  18377. // }
  18378. // break;
  18379. // case 'price':
  18380. // regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18381. // if (regex.test(value) && value !== 0) {
  18382. // priceYes = true;
  18383. // } else {
  18384. // if (!(value instanceof Number) || value) {
  18385. // toaster.pop('warning', '警告', '单价不合法,请重新填写');
  18386. // }
  18387. // }
  18388. // break;
  18389. // }
  18390. // };
  18391. //
  18392. // $scope.emNumYes = true;
  18393. //
  18394. // $scope.validEmNum = function (value) {
  18395. // var regex = /^\+?[1-9][0-9]*$/;
  18396. // if (!regex.test(value) || value == 0 || value !== null) {
  18397. // $scope.emNumYes = false;
  18398. // toaster.pop('warning', '警告', '人数不合法,请重新填写');
  18399. // }
  18400. // };
  18401. //
  18402. // $scope.validateProds = function(tenderProd) {
  18403. // // angular.forEach(tenderProds, function (tenderProd) {
  18404. // var cycleRegex = /^\+?[1-9][0-9]*$/;
  18405. // var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  18406. // var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  18407. // // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18408. // // 判断填写过的有为0或不符合正则式的,设置不能保存
  18409. // if (tenderProd.currentItem.cycle !== null && (!cycleRegex.test(tenderProd.currentItem.cycle)) || (tenderProd.currentItem.taxrate !== null && !taxrateRegex.test(tenderProd.currentItem.taxrate)) || (tenderProd.currentItem.price !==null && (!priceRegex.test(tenderProd.currentItem.price) && tenderProd.currentItem.price !== 0))) {
  18410. // $scope.canSave = false;
  18411. // } else {
  18412. // $scope.canSave = true;
  18413. // }
  18414. // // });
  18415. // };
  18416. //
  18417. // // 投标
  18418. // $scope.bidIt = function(tender, currentEnBaseInfo){
  18419. // $scope.loading = true;
  18420. // if(currentEnBaseInfo.enEstablishDate instanceof Date) {
  18421. // currentEnBaseInfo.enEstablishDate = currentEnBaseInfo.enEstablishDate.getTime();
  18422. // }
  18423. // var saleTenderItems = [];
  18424. // if (tender.ifOpen !== 1) { // 指定投标不把投标单主表设空会报header超长
  18425. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  18426. // if (tenderProd.currentItem) {
  18427. // tenderProd.currentItem.saleTender = {};
  18428. // saleTenderItems.push(tenderProd.currentItem);
  18429. // }
  18430. // });
  18431. // } else {
  18432. // angular.forEach(tender.purchaseTenderProds, function(tenderProd) {
  18433. // if (tenderProd.currentItem) {
  18434. // saleTenderItems.push(tenderProd.currentItem);
  18435. // }
  18436. // });
  18437. // }
  18438. // PurcTender.reply({tenderItems: saleTenderItems, enBaseInfo: currentEnBaseInfo, attaches:$scope.attaches}, {}, function(data){
  18439. // $scope.loading = false;
  18440. // toaster.pop('info', '成功', '投标成功');
  18441. // // $window.location.reload();
  18442. // // if (tender.ifOpen) { // 根据是否公开,选择跳转
  18443. // // window.location.hash = '#/sale/opentender';
  18444. // // } else {
  18445. // window.location.hash = '#/sale/tender';
  18446. // // }
  18447. // }, function(response){
  18448. // $scope.loading = false;
  18449. // toaster.pop('error', '投标失败', '出现异常,投标失败');
  18450. // });
  18451. //
  18452. // };
  18453. //
  18454. // $scope.condition = {
  18455. // $fromOpened:false
  18456. // };
  18457. //
  18458. // $scope.getMaxDate = function() {
  18459. // return $filter('date')(new Date(), 'yyyy-MM-dd');
  18460. // };
  18461. //
  18462. // $scope.openDatePicker = function($event, item, openParam) {
  18463. // $event.preventDefault();
  18464. // $event.stopPropagation();
  18465. // item[openParam] = !item[openParam];
  18466. // };
  18467. }]);
  18468. // 基础资料客户详情
  18469. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'VendorInfo', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, VendorInfo) {
  18470. BaseService.scrollBackToTop();
  18471. $scope.status = 'customer';
  18472. $scope.userInfoResult = true;
  18473. AuthenticationService.getAuthentication().success(function (data) {
  18474. $scope.loading = false;
  18475. $scope.thisUser = data;
  18476. });
  18477. $scope.customerParams = new ngTableParams({
  18478. page: 1,
  18479. count: 20
  18480. }, {
  18481. total: 0,
  18482. counts: [],
  18483. getData: function ($defer, params) {
  18484. $scope.loading = true;
  18485. var pageParams = params.url();
  18486. pageParams.keyword = $scope.keyword;
  18487. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18488. $scope.loading = false;
  18489. if (page) {
  18490. params.total(page.totalElement);
  18491. $scope.total = page.totalElement;
  18492. $defer.resolve(page.content);
  18493. }
  18494. $scope.totalCount = page.totalElement;
  18495. }, function (response) {
  18496. $scope.loading = false;
  18497. toaster.pop('error', '数据加载失败', response.data);
  18498. });
  18499. }
  18500. });
  18501. // 搜索框回车
  18502. $scope.onSearch = function (keyword) {
  18503. $scope.customerParams.page(1);
  18504. $scope.customerParams.reload();
  18505. $scope.tip = keyword;
  18506. };
  18507. // 查看详情
  18508. $scope.viewDetail = function (id) {
  18509. window.location.hash = "#/sale/customer/" + id;
  18510. }
  18511. // 取消合作关系
  18512. $scope.disableCust = function (id) {
  18513. VendorInfo.disableCust({id: id}, {}, function (data) {
  18514. if (data.success) {
  18515. toaster.pop('success', '提示', data.success);
  18516. }
  18517. // $scope.customerParams.page(1);
  18518. $scope.customerParams.reload();
  18519. }, function (response) {
  18520. toaster.pop('error', '提示', response.data);
  18521. });
  18522. }
  18523. // 解除禁用
  18524. $scope.activeCust = function (id) {
  18525. VendorInfo.activeCust({id: id}, {}, function (data) {
  18526. if (data.success) {
  18527. toaster.pop('success', '提示', data.success);
  18528. }
  18529. // $scope.customerParams.page(1);
  18530. $scope.customerParams.reload();
  18531. }, function (response) {
  18532. toaster.pop('error', '提示', response.data);
  18533. });
  18534. }
  18535. }]);
  18536. // 基础资料供应商
  18537. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18538. BaseService.scrollBackToTop();
  18539. $scope.status = 'vendor';
  18540. // 搜索框回车
  18541. $scope.onSearch = function () {
  18542. $scope.customerParams.page(1);
  18543. $scope.customerParams.reload();
  18544. };
  18545. $scope.customerParams = new ngTableParams({
  18546. page: 1,
  18547. count: 20
  18548. }, {
  18549. total: 0,
  18550. counts: [],
  18551. getData: function ($defer, params) {
  18552. $scope.loading = true;
  18553. var pageParams = params.url();
  18554. pageParams.keyword = $scope.keyword;
  18555. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  18556. $scope.loading = false;
  18557. if (page) {
  18558. params.total(page.totalElement);
  18559. $scope.total = page.totalElement;
  18560. $defer.resolve(page.content);
  18561. }
  18562. $scope.totalCount = page.totalElement;
  18563. }, function (response) {
  18564. $scope.loading = false;
  18565. toaster.pop('error', '数据加载失败', response.data);
  18566. });
  18567. }
  18568. });
  18569. // 查看供应商详情
  18570. $scope.VendorDetail = function (id, uu) {
  18571. $rootScope.vendorId = id;
  18572. $rootScope.vendoruu = uu;
  18573. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18574. }
  18575. // 向企业购买
  18576. $scope.purcByEn = function (businessCode) {
  18577. $rootScope.businessCode = businessCode;
  18578. window.location.hash = "#/purc/addOrder";
  18579. }
  18580. // 取消合作关系
  18581. $scope.relieve = function (id) {
  18582. VendorInfo.relieve({id: id}, {}, function (data) {
  18583. if (data.success) {
  18584. toaster.pop('success', '提示', data.success);
  18585. }
  18586. // $scope.customerParams.page(1);
  18587. $scope.customerParams.reload();
  18588. }, function (response) {
  18589. toaster.pop('error', '提示', response.data);
  18590. });
  18591. }
  18592. // 建立合作关系
  18593. $scope.activeVend = function (id) {
  18594. VendorInfo.activeVend({id: id}, {}, function (data) {
  18595. if (data.success) {
  18596. toaster.pop('success', '提示', data.success);
  18597. }
  18598. // $scope.customerParams.page(1);
  18599. $scope.customerParams.reload();
  18600. }, function (response) {
  18601. toaster.pop('error', '提示', response.data);
  18602. });
  18603. }
  18604. }]);
  18605. // 基础资料服务商
  18606. app.controller('ServicerInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18607. BaseService.scrollBackToTop();
  18608. $scope.status = 'servicer';
  18609. // 搜索框回车
  18610. $scope.onSearch = function () {
  18611. $scope.customerParams.page(1);
  18612. $scope.customerParams.reload();
  18613. };
  18614. $scope.customerParams = new ngTableParams({
  18615. page: 1,
  18616. count: 20
  18617. }, {
  18618. total: 0,
  18619. counts: [],
  18620. getData: function ($defer, params) {
  18621. $scope.loading = true;
  18622. var pageParams = params.url();
  18623. pageParams.keyword = $scope.keyword;
  18624. Vendor.getServicer.call(null, BaseService.parseParams(pageParams), function (page) {
  18625. $scope.loading = false;
  18626. if (page) {
  18627. params.total(page.totalElement);
  18628. $scope.total = page.totalElement;
  18629. $defer.resolve(page.content);
  18630. }
  18631. $scope.totalCount = page.totalElement;
  18632. }, function (response) {
  18633. $scope.loading = false;
  18634. toaster.pop('error', '数据加载失败', response.data);
  18635. });
  18636. }
  18637. });
  18638. // 查看服务商详情
  18639. $scope.VendorDetail = function (id, uu) {
  18640. $rootScope.vendorId = id;
  18641. $rootScope.vendoruu = uu;
  18642. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18643. };
  18644. // 取消合作关系
  18645. $scope.relieveServicer = function (id) {
  18646. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  18647. if (data.success) {
  18648. toaster.pop('success', '提示', data.success);
  18649. }
  18650. // $scope.customerParams.page(1);
  18651. $scope.customerParams.reload();
  18652. }, function (response) {
  18653. toaster.pop('error', '提示', response.data);
  18654. });
  18655. }
  18656. // 建立合作关系
  18657. $scope.activeServicer = function (id) {
  18658. VendorInfo.activeServicer({id: id}, {}, function (data) {
  18659. if (data.success) {
  18660. toaster.pop('success', '提示', data.success);
  18661. }
  18662. // $scope.customerParams.page(1);
  18663. $scope.customerParams.reload();
  18664. }, function (response) {
  18665. toaster.pop('error', '提示', response.data);
  18666. });
  18667. }
  18668. }]);
  18669. // 企业圈搜索界面
  18670. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
  18671. $scope.onSearch = function (keyword) {
  18672. $rootScope.enterpriseKeyword = keyword;
  18673. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  18674. }
  18675. }]);
  18676. // 企业圈搜索结果
  18677. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  18678. $scope.status = 'add';
  18679. BaseService.scrollBackToTop();
  18680. $scope.active = 'all';
  18681. $scope.agreedText = '全部';
  18682. $scope.dateZoneText = '一个月内';
  18683. $scope.condition = {dateZone: 1};
  18684. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18685. $scope.changeAgreed = function (agreed) {
  18686. $scope.condition.agreed = agreed;
  18687. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18688. $scope.condition.$agreedOpen = false;
  18689. };
  18690. $scope.changeDateZone = function (zone) {
  18691. $scope.condition.dateZone = zone;
  18692. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18693. $scope.condition.$dateZoneOpen = false;
  18694. getDateCondition(zone, $scope.condition);
  18695. $scope.tableParams.reload();
  18696. };
  18697. $scope.setActive = function (state) {
  18698. if ($scope.active != state) {
  18699. $scope.active = state;
  18700. if ($scope.tableParams.page() == 1)
  18701. $scope.tableParams.reload();
  18702. else
  18703. $scope.tableParams.page(1);
  18704. }
  18705. };
  18706. var getService = function () {
  18707. return getAccountUserSpace;
  18708. };
  18709. $scope.tableParams = new ngTableParams({
  18710. page: 1,
  18711. count: 20,
  18712. sorting: {}
  18713. }, {
  18714. total: 0,
  18715. counts: [],
  18716. getData: function ($defer, params) {
  18717. $scope.loading = true;
  18718. var pageParams = params.url();
  18719. pageParams.keyword = $scope.keyword;
  18720. $scope.tip = $scope.keyword;
  18721. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18722. $scope.loading = false;
  18723. if (page) {
  18724. params.total(page.totalElement);
  18725. $defer.resolve(page.content);
  18726. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18727. }
  18728. }, function (response) {
  18729. $scope.loading = false;
  18730. toaster.pop('error', '数据加载失败', response.data);
  18731. });
  18732. }
  18733. });
  18734. // 搜索框回车
  18735. $scope.onSearch = function (keyword) {
  18736. if (keyword === '') {
  18737. keyword = null;
  18738. $rootScope.searchKeyword = keyword;
  18739. $scope.keyword = keyword;
  18740. $scope.tableParams.page(1);
  18741. $scope.tableParams.reload();
  18742. } else {
  18743. $rootScope.searchKeyword = keyword;
  18744. $scope.keyword = keyword;
  18745. $scope.tableParams.page(1);
  18746. $scope.tableParams.reload();
  18747. }
  18748. };
  18749. // 添加合作关系
  18750. $scope.addPartner = function (name, businessCode) {
  18751. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  18752. if (data.success) {
  18753. toaster.pop("success", '添加成功', data.success);
  18754. $scope.tableParams.reload();
  18755. }
  18756. if (data.error) {
  18757. toaster.pop("error", '添加失败', data.error);
  18758. }
  18759. }, function (response) {
  18760. toaster.pop('error', '失败', response.data);
  18761. });
  18762. }
  18763. /**
  18764. * 邀请注册商务平台
  18765. */
  18766. $scope.invite = function (name) {
  18767. var modalInstance = $modal.open({
  18768. animation: true,
  18769. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  18770. controller: 'InviteCtrl',
  18771. resolve: {
  18772. enname: function () {
  18773. return name
  18774. }
  18775. }
  18776. });
  18777. modalInstance.result.then(function (data) {
  18778. InvitationRecord.invite({formStore: data}, {}, function (data) {
  18779. if (data.success) {
  18780. toaster.pop('success', '提示', data.success);
  18781. $scope.tableParams.reload();
  18782. }
  18783. if (data.error) {
  18784. toaster.pop('error', '提示', data.error);
  18785. }
  18786. }, function (response) {
  18787. toaster.pop('error', '提示', response.data);
  18788. });
  18789. });
  18790. }
  18791. /**
  18792. * 立即查看
  18793. */
  18794. $scope.view = function (name) {
  18795. $rootScope.vendName = name;
  18796. window.location.hash = "#/baseInfo/newPartner";
  18797. }
  18798. }]);
  18799. // 平台新增的询价单(指定一个供应商)
  18800. 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) {
  18801. $scope.active = 'all';
  18802. // 供应商信息
  18803. var loadData = function () {
  18804. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function (data) {
  18805. $scope.vendor = data;
  18806. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  18807. $scope.vendorContacts = data;
  18808. });
  18809. // 物料信息
  18810. $scope.tableParams = new ngTableParams({
  18811. page: 1,
  18812. count: 20
  18813. }, {
  18814. total: 0,
  18815. counts: [5, 10, 25, 50],
  18816. getData: function ($defer, params) {
  18817. $scope.loading = true;
  18818. var pageParams = params.url();
  18819. pageParams.keyword = $scope.keyword;
  18820. $scope.tip = $scope.keyword;
  18821. pageParams.custUU = $scope.vendor.uu;
  18822. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18823. $scope.loading = false;
  18824. if (page) {
  18825. params.total(page.totalElement);
  18826. $scope.total = page.totalElement;
  18827. $defer.resolve(page.content);
  18828. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  18829. }
  18830. }, function (response) {
  18831. $scope.loading = false;
  18832. toaster.pop('error', '数据加载失败', response.data);
  18833. });
  18834. }
  18835. });
  18836. });
  18837. };
  18838. loadData();
  18839. $rootScope.tenderVendor = null;// 清除掉已选择的
  18840. var getService = function () {
  18841. return GetProductInfo;
  18842. };
  18843. $scope.inquiry = {
  18844. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  18845. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  18846. priceType: '采购',
  18847. isOpen: 0,
  18848. invoice: 0,
  18849. ifTax: 1,
  18850. currency: 'RMB'
  18851. };
  18852. $scope.changeCurrency = function (inquiry) {
  18853. if (inquiry.currency !== 'RMB') {
  18854. $scope.notRMB = true;
  18855. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  18856. inquiry.invoice = 0;
  18857. } else {
  18858. $scope.notRMB = false;
  18859. }
  18860. };
  18861. // 获取收货地址列表
  18862. var loadShipAddress = function () {
  18863. ShipAddress.shipAddList({}, function (data) {
  18864. $scope.ships = data;
  18865. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  18866. });
  18867. };
  18868. loadShipAddress();
  18869. // 获取地址信息
  18870. $http.get('resources/citydata/city.json', {
  18871. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  18872. }).then(function (response) {
  18873. $scope.provinces = response.data;
  18874. });
  18875. // 新增收货地址保存
  18876. $scope.saveShipAddress = function (ship) {
  18877. ship.address = ship.province + ship.city + ship.district;
  18878. ShipAddress.saveAddress({}, ship, function (data) {
  18879. if (data.success) {
  18880. // 获取收货地址列表
  18881. loadShipAddress();
  18882. toaster.pop('success', '提示', data.success);
  18883. }
  18884. if (data.error) {
  18885. toaster.pop('error', '提示', data.error);
  18886. }
  18887. });
  18888. };
  18889. $scope.currentDay = function () {
  18890. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18891. };
  18892. // 搜索框回车
  18893. $scope.onSearch = function (keyword) {
  18894. $scope.tableParams.page(1);
  18895. $scope.tableParams.reload();
  18896. };
  18897. $scope.inquiry.inquiryItems = [];
  18898. var prod = {
  18899. prodCode: null,
  18900. prodTitle: null,
  18901. inbrand: null,
  18902. currency: 'RMB',
  18903. toDate: null,
  18904. unit: 'PCS'
  18905. };
  18906. $scope.inquiry.inquiryItems.push(prod);
  18907. // 联想词start
  18908. // 获取品牌联想词
  18909. $scope.getSimilarBrands = function (value) {
  18910. if (value) {
  18911. // 获取品牌联想词
  18912. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  18913. return data.map(function (item) {
  18914. return item;
  18915. });
  18916. });
  18917. }
  18918. };
  18919. // 获取产品型号联想词
  18920. $scope.getSimilarCodes = function (value) {
  18921. if (value) {
  18922. // 获取产品型号联想词
  18923. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  18924. return data.map(function (item) {
  18925. return item;
  18926. })
  18927. });
  18928. }
  18929. };
  18930. $scope.selectKind = function (prod) {
  18931. var submit = [];
  18932. $modal.open({
  18933. animation: true,
  18934. size: 'lg',
  18935. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  18936. controller: 'ProdKindChooseCtrl',
  18937. resolve: {
  18938. actives: function () {
  18939. return $scope.actives;
  18940. }
  18941. }
  18942. }).result.then(function (data) {
  18943. $scope.actives = data.actives;
  18944. var size = data.actives.length;
  18945. submit.gradeOneKiName = '';
  18946. submit.gradeTwoKiName = '';
  18947. submit.gradeThreeKiName = '';
  18948. if (size > 0) {
  18949. submit.gradeOneKiName = $scope.actives[0].nameCn;
  18950. prod.prodTitle = submit.gradeOneKiName;
  18951. if (size > 1) {
  18952. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  18953. prod.prodTitle = submit.gradeTwoKiName;
  18954. if (size > 2) {
  18955. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  18956. prod.prodTitle = submit.gradeThreeKiName;
  18957. }
  18958. }
  18959. }
  18960. }, function () {
  18961. });
  18962. };
  18963. // 点击联想词获取品牌信息
  18964. $scope.onAssociateBrandClick = function (brand, prod) {
  18965. if (brand instanceof String) {
  18966. prod.inbrand = brand;
  18967. } else if (brand instanceof Object) {
  18968. prod.inbrand = brand.brandCn;
  18969. }
  18970. };
  18971. // 打开品牌选择的模态框
  18972. $scope.selectBrand = function (prod) { //打开模态
  18973. var modalInstance = $modal.open({
  18974. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  18975. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  18976. });
  18977. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  18978. });
  18979. modalInstance.result.then(function (brand) {
  18980. prod.inbrand = brand.nameCn;
  18981. }, function (reason) {
  18982. });
  18983. };
  18984. // 点击联想词获取器件信息 带入产品分类和品牌
  18985. $scope.onAssociateCmpClick = function (cmp, prod) {
  18986. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  18987. $scope.component = data;
  18988. prod.prodCode = data.code;
  18989. prod.prodTitle = data.kind.nameCn;
  18990. prod.inbrand = data.brand.nameCn;
  18991. }, function (res) {
  18992. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  18993. })
  18994. };
  18995. //联想词end
  18996. // 导入商品信息
  18997. $scope.uplodaByBatch = function () {
  18998. var modalInstance = $modal.open({
  18999. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  19000. controller: 'PurcInquiryUploadCtrl',
  19001. size: 'lg',
  19002. resolve: {}
  19003. });
  19004. modalInstance.result.then(function (data) {
  19005. angular.forEach(data, function (prod) {
  19006. $scope.inquiry.inquiryItems.push(prod);
  19007. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19008. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19009. $scope.inquiry.inquiryItems.splice(i, 1);
  19010. }
  19011. }
  19012. })
  19013. }, function () {
  19014. });
  19015. }
  19016. //增加商品
  19017. $scope.add = function () {
  19018. $scope.inquiry.inquiryItems.push(
  19019. {
  19020. prodCode: null,
  19021. prodTitle: null,
  19022. unit: 'PCS',
  19023. ibrand: null,
  19024. currency: 'RMB',
  19025. toDate: null
  19026. });
  19027. };
  19028. //删除商品
  19029. $scope.del = function (index) {
  19030. $scope.inquiry.inquiryItems.splice(index, 1);
  19031. };
  19032. // 搜索结果询价
  19033. if ($rootScope.prodId) {
  19034. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  19035. prod.prodCode = data.code;
  19036. prod.prodTitle = data.title;
  19037. prod.spec = data.spec;
  19038. prod.unit = data.unit;
  19039. prod.productId = data.id;
  19040. prod.inbrand = data.brand;
  19041. $scope.inquiry.inquiryItems.push(prod);
  19042. $rootScope.prodId = null;// 清除掉prodId
  19043. }, function (response) {
  19044. });
  19045. }
  19046. $scope.check = function (product) {
  19047. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19048. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19049. $scope.inquiry.inquiryItems.splice(i, 1);
  19050. }
  19051. }
  19052. $scope.inquiry.inquiryItems.push({
  19053. prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  19054. currency: null, toDate: null, productId: product.id, inbrand: product.brand
  19055. });
  19056. }
  19057. $scope.getMinDate = function (item) {
  19058. return $filter('date')(new Date, 'yyyy-MM-dd');
  19059. };
  19060. $scope.openDatePicker = function ($event, openParam, index) {
  19061. $event.preventDefault();
  19062. $event.stopPropagation();
  19063. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  19064. };
  19065. $scope.openEndDatePicker = function ($event, item, openParam) {
  19066. $event.preventDefault();
  19067. $event.stopPropagation();
  19068. item[openParam] = !item[openParam];
  19069. };
  19070. $scope.ifrepeat = false;
  19071. // 保存并提交
  19072. $scope.submit = function () {
  19073. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19074. $scope.item = $scope.inquiry.inquiryItems[i];
  19075. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  19076. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  19077. if (i != j) {
  19078. if ($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  19079. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  19080. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  19081. $scope.ifrepeat = true;
  19082. }
  19083. }
  19084. }
  19085. }
  19086. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  19087. $scope.vendors = [];
  19088. $scope.vendors.push({
  19089. enName: $scope.vendor.enName,
  19090. enuu: $scope.vendor.uu,
  19091. currency: $scope.vendor.currency,
  19092. rate: $scope.vendor.rate
  19093. });
  19094. if (!$scope.ifrepeat) {
  19095. $upload.upload({
  19096. url: 'purc/inquiry/submit/withVendor',
  19097. file: file,
  19098. method: 'POST',
  19099. data: {
  19100. inquiry: $scope.inquiry,
  19101. contacts: $scope.vendors
  19102. },
  19103. }).success(function (data) {
  19104. if (data.success) {
  19105. toaster.pop('success', '提示', data.success);
  19106. $timeout(function () {
  19107. window.location.hash = "#/purc/purchaseinquiry";
  19108. }, 500);
  19109. }
  19110. if (data.error) {
  19111. toaster.pop('error', '提示', data.error);
  19112. }
  19113. }).error(function (data) {
  19114. $scope.loadingShow = false;
  19115. toaster.pop('error', '操作失败', data.error);
  19116. });
  19117. } else {
  19118. toaster.pop('error', '提示', '存在条件相同的物料');
  19119. }
  19120. }
  19121. }]);
  19122. // 企业圈查询收到待处理的数目
  19123. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', function ($scope, AddPartnerMyRequest) {
  19124. AddPartnerMyRequest.requestAmount({}, function (data) {
  19125. $scope.requestTodo = data;
  19126. });
  19127. }]);
  19128. // 当前企业所有的物料信息
  19129. 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) {
  19130. BaseService.scrollBackToTop();
  19131. $rootScope.ids = [];// 用来记录已经选择的物料
  19132. $scope.active = 'all';
  19133. $scope.agreedText = '全部';
  19134. $scope.dateZoneText = '一个月内';
  19135. $scope.condition = {dateZone: 1};
  19136. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19137. $scope.changeAgreed = function (agreed) {
  19138. $scope.condition.agreed = agreed;
  19139. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19140. $scope.condition.$agreedOpen = false;
  19141. };
  19142. $scope.changeDateZone = function (zone) {
  19143. $scope.condition.dateZone = zone;
  19144. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19145. $scope.condition.$dateZoneOpen = false;
  19146. getDateCondition(zone, $scope.condition);
  19147. $scope.tableParams.reload();
  19148. };
  19149. $scope.setActive = function (state) {
  19150. if ($scope.active != state) {
  19151. $scope.active = state;
  19152. if ($scope.tableParams.page() == 1)
  19153. $scope.tableParams.reload();
  19154. else
  19155. $scope.tableParams.page(1);
  19156. }
  19157. };
  19158. $scope.searchMethod = false;
  19159. var getService = function () {
  19160. return $scope.searchMethod ? ProductAll : ProductAllNewest;
  19161. };
  19162. $scope.tableParams = new ngTableParams({
  19163. page: 1,
  19164. count: 20,
  19165. sorting: {
  19166. standard: 'desc',
  19167. id: 'desc',
  19168. }
  19169. }, {
  19170. total: 0,
  19171. counts: [5, 10, 25, 50],
  19172. getData: function ($defer, params) {
  19173. $scope.loading = true;
  19174. var pageParams = params.url();
  19175. pageParams.keyword = $scope.keyword;
  19176. pageParams.searchFilter = $scope.searchFilter;
  19177. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19178. $scope.loading = false;
  19179. if (page) {
  19180. params.total(page.totalElement);
  19181. $defer.resolve(page.content);
  19182. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19183. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19184. $scope.checkall = true;
  19185. angular.forEach(page.content, function (prod) {
  19186. if ($rootScope.ids.indexOf(prod.id) > -1) {
  19187. prod.$selected = true;
  19188. } else {
  19189. $scope.checkall = false;
  19190. }
  19191. });
  19192. $scope.checkboxes = {
  19193. checked: $scope.checkall
  19194. };
  19195. }
  19196. }, function (response) {
  19197. $scope.loading = false;
  19198. toaster.pop('error', '数据加载失败', response.data);
  19199. });
  19200. }
  19201. });
  19202. // 搜索框回车
  19203. $scope.onSearch = function (keyword) {
  19204. // 每次搜索重置获取数据方法
  19205. $scope.searchMethod = false;
  19206. if(keyword != null && keyword != '') {
  19207. $scope.searchMethod = true;
  19208. }
  19209. $scope.tableParams.page(1);
  19210. $scope.tableParams.reload();
  19211. };
  19212. // 开启销售
  19213. $scope.unlock = function (id) {
  19214. Products.unlock({id: id}, {}, function (data) {
  19215. toaster.pop('success', '提示', '操作成功');
  19216. $scope.tableParams.reload();
  19217. }, function (response) {
  19218. toaster.pop('error', '提示', response.data);
  19219. })
  19220. }
  19221. // 关闭销售
  19222. $scope.lock = function (id) {
  19223. Products.lock({id: id}, {}, function (data) {
  19224. toaster.pop('success', '提示', '操作成功');
  19225. $scope.tableParams.reload();
  19226. }, function (response) {
  19227. toaster.pop('error', '提示', response.data);
  19228. })
  19229. }
  19230. // 开启购买
  19231. $scope.unlockPurc = function (id) {
  19232. Products.unlockPurc({id: id}, {}, function (data) {
  19233. toaster.pop('success', '提示', '操作成功');
  19234. $scope.tableParams.reload();
  19235. }, function (response) {
  19236. toaster.pop('error', '提示', response.data);
  19237. })
  19238. }
  19239. // 关闭购买
  19240. $scope.lockPurc = function (id) {
  19241. Products.lockPurc({id: id}, {}, function (data) {
  19242. toaster.pop('success', '提示', '操作成功');
  19243. $scope.tableParams.reload();
  19244. }, function (response) {
  19245. toaster.pop('error', '提示', response.data);
  19246. })
  19247. }
  19248. // 一键匹配
  19249. $scope.matchall = function () {
  19250. $scope.type = "all";
  19251. $scope.loading = true;
  19252. Products.matchbytype({type: $scope.type}, {}, function (data) {
  19253. if (data.error) {
  19254. $scope.loading = false;
  19255. toaster.pop('error', '提示', data.error);
  19256. } else {
  19257. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  19258. window.location.href = "#/approvalFlow/productmatches";
  19259. }
  19260. }, function (response) {
  19261. toaster.pop('error', '提示', response.data);
  19262. });
  19263. }
  19264. $scope.checkboxes = {
  19265. checked: false
  19266. };
  19267. angular.forEach($scope.tableParams.data, function (item) {
  19268. $scope.checkboxes.checked = false;
  19269. if($rootScope.ids.in_array(item.id)) {
  19270. $rootScope.ids.remove(item.id);
  19271. $scope.checkboxes.checked = true;
  19272. }
  19273. });
  19274. // 点击勾选全部的复选框
  19275. $scope.checkAll = function () {
  19276. angular.forEach($scope.tableParams.data, function (item) {
  19277. if (!item.waiting) {
  19278. item.$selected = $scope.checkboxes.checked;
  19279. if(item.$selected) {
  19280. if(!$rootScope.ids.in_array(item.id)) {
  19281. $rootScope.ids.push(item.id);
  19282. }
  19283. } else {
  19284. if($rootScope.ids.in_array(item.id)) {
  19285. $rootScope.ids.remove(item.id);
  19286. }
  19287. }
  19288. }
  19289. });
  19290. };
  19291. // 判断数组中是否存在某个对象
  19292. Array.prototype.S = String.fromCharCode(2);
  19293. Array.prototype.in_array = function(e) {
  19294. var r = new RegExp(this.S + e + this.S);
  19295. return (r.test(this.S + this.join(this.S) + this.S));
  19296. }
  19297. // 从数组中移除某个对象
  19298. Array.prototype.remove = function(val) {
  19299. var index = this.indexOf(val);
  19300. if (index > -1) {
  19301. this.splice(index, 1);
  19302. }
  19303. };
  19304. // 点击其中一个明细的复选框
  19305. $scope.checkOne = function (product) {
  19306. var result = true;
  19307. angular.forEach($scope.tableParams.data, function (item) {
  19308. if (item.$selected != true) {
  19309. result = false;
  19310. return;
  19311. }
  19312. });
  19313. if(product.$selected) {
  19314. if(!$rootScope.ids.in_array(product.id)) {
  19315. $rootScope.ids.push(product.id);
  19316. }
  19317. } else {
  19318. if($rootScope.ids.in_array(product.id)) {
  19319. $rootScope.ids.remove(product.id);
  19320. }
  19321. }
  19322. $scope.checkboxes = {
  19323. checked: result
  19324. };
  19325. };
  19326. // 批量转入我的产品库
  19327. $scope.addtoUserByCheck = function() {
  19328. var ids = angular.toJson($rootScope.ids);
  19329. ids = ids.replace(/\[|]/g,'');
  19330. prodUser.coverToUserByIds({ids: ids}, {}, function(data) {
  19331. toaster.pop('success', '成功转入' + data.count);
  19332. }, function(res) {
  19333. toaster.pop('error', '转入失败');
  19334. });
  19335. }
  19336. // 转入我的产品库
  19337. $scope.addtoUser = function(id) {
  19338. prodUser.coverToUser({id: id}, {}, function(data) {
  19339. toaster.pop('success', '转入成功');
  19340. }, function(res) {
  19341. toaster.pop('error', '转入失败');
  19342. });
  19343. }
  19344. }]);
  19345. // 当前企业匹配的标准物料信息
  19346. 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) {
  19347. BaseService.scrollBackToTop();
  19348. $scope.active = 'all';
  19349. $scope.agreedText = '全部';
  19350. $scope.dateZoneText = '一个月内';
  19351. $scope.condition = {dateZone: 1};
  19352. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19353. $scope.changeAgreed = function (agreed) {
  19354. $scope.condition.agreed = agreed;
  19355. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19356. $scope.condition.$agreedOpen = false;
  19357. };
  19358. $scope.changeDateZone = function (zone) {
  19359. $scope.condition.dateZone = zone;
  19360. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19361. $scope.condition.$dateZoneOpen = false;
  19362. getDateCondition(zone, $scope.condition);
  19363. $scope.tableParams.reload();
  19364. };
  19365. $scope.setActive = function (state) {
  19366. if ($scope.active != state) {
  19367. $scope.active = state;
  19368. if ($scope.tableParams.page() == 1)
  19369. $scope.tableParams.reload();
  19370. else
  19371. $scope.tableParams.page(1);
  19372. }
  19373. };
  19374. $scope.searchMethod = false;
  19375. var getService = function () {
  19376. if ($rootScope.productMatchStatus === 'sale') {
  19377. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19378. } else if ($rootScope.productMatchStatus === 'purc') {
  19379. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19380. } else {
  19381. return $scope.searchMethod ? Products.matchResult : Products.newestMatchResult;
  19382. }
  19383. };
  19384. $scope.tableParams = new ngTableParams({
  19385. page: 1,
  19386. count: 20,
  19387. sorting: {
  19388. matchsize: 'asc',
  19389. id: 'desc'
  19390. }
  19391. }, {
  19392. total: 0,
  19393. counts: [5, 10, 25, 50],
  19394. getData: function ($defer, params) {
  19395. $scope.loading = true;
  19396. var pageParams = params.url();
  19397. pageParams.keyword = $scope.keyword;
  19398. pageParams.searchFilter = $scope.searchFilter;
  19399. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19400. if (page) {
  19401. $scope.loading = false;
  19402. params.total(page.totalElement);
  19403. $defer.resolve(page.content);
  19404. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19405. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19406. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19407. ids = [];
  19408. if (product.matchresults.length == 1) {
  19409. product.checked = $scope.checks.checked;
  19410. }
  19411. });
  19412. // $scope.total = page.totalElement;
  19413. // Products.matchsize({type: 'all'}, {}, function(data) {
  19414. // $scope.size = data.size;
  19415. // if($scope.total < $scope.size) {
  19416. // $timeout(function() {
  19417. // $scope.tableParams.reload();
  19418. // }, 500);
  19419. // } else {
  19420. // $scope.loading = false;
  19421. // }
  19422. // }, function(response) {
  19423. // toaster.pop('error', '提示', response.data);
  19424. // });
  19425. }
  19426. }, function (response) {
  19427. $scope.loading = false;
  19428. toaster.pop('error', '数据加载失败', response.data);
  19429. });
  19430. }
  19431. });
  19432. // 搜索框回车
  19433. $scope.onSearch = function (keyword) {
  19434. $scope.searchMethod = false;
  19435. if(keyword != null && keyword != '') {
  19436. $scope.searchMethod = true;
  19437. }
  19438. $scope.tableParams.page(1);
  19439. $scope.tableParams.reload();
  19440. };
  19441. var ids = [];
  19442. $scope.checks = {
  19443. checked: false
  19444. };
  19445. // 全选框
  19446. $scope.checkAll = function () {
  19447. ids = [];// 每次选择时先清空,防止重复
  19448. angular.forEach($scope.tableParams.data, function (product) {
  19449. if (product.matchresults.length == 1) {
  19450. product.checked = $scope.checks.checked;
  19451. }
  19452. });
  19453. };
  19454. // 单选
  19455. $scope.checkOne = function (product) {
  19456. ids = [];// 每次选择时先清空,防止重复
  19457. product.checked = !product.checked;
  19458. var result = true;
  19459. angular.forEach($scope.tableParams.data, function (item) {
  19460. if (item.$selected != true) {
  19461. result = false;
  19462. return;
  19463. }
  19464. });
  19465. $scope.checks.checked = result;
  19466. var checked = true;
  19467. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19468. if (!message.checked) {
  19469. checked = false;
  19470. }
  19471. });
  19472. $scope.checks.checked = checked;
  19473. };
  19474. $scope.product = {
  19475. checked: false
  19476. };
  19477. var checkResults = function (result) {
  19478. angular.forEach($scope.tableParams.data, function (product) {
  19479. if (product.id == result.prid) {
  19480. product.checked = false;
  19481. angular.forEach(product.matchresults, function (item) {
  19482. if (result.id == item.id) {
  19483. if (item.checked) {
  19484. product.checked = true;
  19485. return;
  19486. }
  19487. } else {
  19488. item.checked = false;
  19489. }
  19490. });
  19491. }
  19492. });
  19493. // checkProductCheck();
  19494. };
  19495. var checkProductCheck = function () {
  19496. var checked = true;
  19497. angular.forEach($scope.tableParams.data, function (product) {
  19498. if (!product.checked) {
  19499. checked = false;
  19500. }
  19501. });
  19502. $scope.product.checked = checked;
  19503. }
  19504. // 单选明细
  19505. $scope.checkItem = function (result) {
  19506. ids = [];
  19507. result.checked = !result.checked;
  19508. checkResults(result);
  19509. }
  19510. // 一键更新
  19511. $scope.updateAll = function () {
  19512. $scope.loading = true;
  19513. angular.forEach($scope.tableParams.data, function (product) {
  19514. if (product.checked) {
  19515. if (product.matchresults.length == 1) {
  19516. ids.push(product.matchresults[0].id);
  19517. }
  19518. if (product.matchresults.length > 1) {
  19519. angular.forEach(product.matchresults, function (item) {
  19520. if (item.checked) {
  19521. ids.push(item.id);
  19522. }
  19523. });
  19524. }
  19525. }
  19526. });
  19527. Products.updateall({status: $scope.checks.checked, type: 'all'}, ids, function (data) {
  19528. if (data.success) {
  19529. toaster.pop('success', '提示', data.success);
  19530. $timeout(function () {
  19531. $scope.tableParams.page(1);
  19532. $scope.tableParams.reload();
  19533. $scope.loading = false;
  19534. }, 500);
  19535. }
  19536. ids = []; // 清空ids,防止重复点击出现多余的数据
  19537. }, function (response) {
  19538. $scope.loading = false;
  19539. toaster.pop('error', '提示', response.data);
  19540. });
  19541. }
  19542. }]);
  19543. // 当前企业匹配的标准物料信息(销售)
  19544. 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) {
  19545. BaseService.scrollBackToTop();
  19546. $scope.active = 'all';
  19547. $scope.agreedText = '全部';
  19548. $scope.dateZoneText = '一个月内';
  19549. $scope.condition = {dateZone: 1};
  19550. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19551. $scope.changeAgreed = function (agreed) {
  19552. $scope.condition.agreed = agreed;
  19553. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19554. $scope.condition.$agreedOpen = false;
  19555. };
  19556. $scope.changeDateZone = function (zone) {
  19557. $scope.condition.dateZone = zone;
  19558. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19559. $scope.condition.$dateZoneOpen = false;
  19560. getDateCondition(zone, $scope.condition);
  19561. $scope.tableParams.reload();
  19562. };
  19563. $scope.setActive = function (state) {
  19564. if ($scope.active != state) {
  19565. $scope.active = state;
  19566. if ($scope.tableParams.page() == 1)
  19567. $scope.tableParams.reload();
  19568. else
  19569. $scope.tableParams.page(1);
  19570. }
  19571. };
  19572. $scope.searchMethod = false;
  19573. var getService = function () {
  19574. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19575. };
  19576. $scope.tableParams = new ngTableParams({
  19577. page: 1,
  19578. count: 20,
  19579. sorting: {
  19580. matchsize: 'asc',
  19581. id: 'desc'
  19582. }
  19583. }, {
  19584. total: 0,
  19585. counts: [5, 10, 25, 50],
  19586. getData: function ($defer, params) {
  19587. $scope.loading = true;
  19588. var pageParams = params.url();
  19589. pageParams.keyword = $scope.keyword;
  19590. pageParams.searchFilter = $scope.searchFilter;
  19591. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19592. if (page) {
  19593. $scope.loading = false;
  19594. params.total(page.totalElement);
  19595. $defer.resolve(page.content);
  19596. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19597. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19598. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19599. ids = [];
  19600. if (product.matchresults.length == 1) {
  19601. product.checked = $scope.checks.checked;
  19602. }
  19603. });
  19604. }
  19605. }, function (response) {
  19606. $scope.loading = false;
  19607. toaster.pop('error', '数据加载失败', response.data);
  19608. });
  19609. }
  19610. });
  19611. // 搜索框回车
  19612. $scope.onSearch = function (keyword) {
  19613. $scope.searchMethod = false;
  19614. if(keyword != null && keyword != '') {
  19615. $scope.searchMethod = true;
  19616. }
  19617. $scope.tableParams.page(1);
  19618. $scope.tableParams.reload();
  19619. };
  19620. var ids = [];
  19621. $scope.checks = {
  19622. checked: false
  19623. };
  19624. // 全选框
  19625. $scope.checkAll = function () {
  19626. ids = [];// 每次选择时先清空,防止重复
  19627. angular.forEach($scope.tableParams.data, function (product) {
  19628. if (product.matchresults.length == 1) {
  19629. product.checked = $scope.checks.checked;
  19630. }
  19631. });
  19632. };
  19633. // 单选
  19634. $scope.checkOne = function (product) {
  19635. ids = [];// 每次选择时先清空,防止重复
  19636. product.checked = !product.checked;
  19637. var result = true;
  19638. angular.forEach($scope.tableParams.data, function (item) {
  19639. if (item.$selected != true) {
  19640. result = false;
  19641. return;
  19642. }
  19643. });
  19644. $scope.checks.checked = result;
  19645. var checked = true;
  19646. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19647. if (!message.checked) {
  19648. checked = false;
  19649. }
  19650. });
  19651. $scope.checks.checked = checked;
  19652. };
  19653. $scope.product = {
  19654. checked: false
  19655. };
  19656. var checkResults = function (result) {
  19657. angular.forEach($scope.tableParams.data, function (product) {
  19658. if (product.id == result.prid) {
  19659. product.checked = false;
  19660. angular.forEach(product.matchresults, function (item) {
  19661. if (result.id == item.id) {
  19662. if (item.checked) {
  19663. product.checked = true;
  19664. return;
  19665. }
  19666. } else {
  19667. item.checked = false;
  19668. }
  19669. });
  19670. }
  19671. });
  19672. // checkProductCheck();
  19673. };
  19674. var checkProductCheck = function () {
  19675. var checked = true;
  19676. angular.forEach($scope.tableParams.data, function (product) {
  19677. if (!product.checked) {
  19678. checked = false;
  19679. }
  19680. });
  19681. $scope.product.checked = checked;
  19682. }
  19683. // 单选明细
  19684. $scope.checkItem = function (result) {
  19685. ids = [];
  19686. result.checked = !result.checked;
  19687. checkResults(result);
  19688. }
  19689. // 一键更新
  19690. $scope.updateAll = function () {
  19691. $scope.loading = true;
  19692. angular.forEach($scope.tableParams.data, function (product) {
  19693. if (product.checked) {
  19694. if (product.matchresults.length == 1) {
  19695. ids.push(product.matchresults[0].id);
  19696. }
  19697. if (product.matchresults.length > 1) {
  19698. angular.forEach(product.matchresults, function (item) {
  19699. if (item.checked) {
  19700. ids.push(item.id);
  19701. }
  19702. });
  19703. }
  19704. }
  19705. });
  19706. Products.updateall({status: $scope.checks.checked, type: 'sale'}, ids, function (data) {
  19707. if (data.success) {
  19708. toaster.pop('success', '提示', data.success);
  19709. $timeout(function () {
  19710. $scope.tableParams.page(1);
  19711. $scope.tableParams.reload();
  19712. $scope.loading = false;
  19713. }, 500);
  19714. }
  19715. ids = []; // 清空ids,防止重复点击出现多余的数据
  19716. }, function (response) {
  19717. $scope.loading = true;
  19718. toaster.pop('error', '提示', response.data);
  19719. });
  19720. }
  19721. }]);
  19722. // 当前企业匹配的标准物料信息(采购)
  19723. 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) {
  19724. BaseService.scrollBackToTop();
  19725. $scope.active = 'all';
  19726. $scope.agreedText = '全部';
  19727. $scope.dateZoneText = '一个月内';
  19728. $scope.condition = {dateZone: 1};
  19729. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19730. $scope.changeAgreed = function (agreed) {
  19731. $scope.condition.agreed = agreed;
  19732. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19733. $scope.condition.$agreedOpen = false;
  19734. };
  19735. $scope.changeDateZone = function (zone) {
  19736. $scope.condition.dateZone = zone;
  19737. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19738. $scope.condition.$dateZoneOpen = false;
  19739. getDateCondition(zone, $scope.condition);
  19740. $scope.tableParams.reload();
  19741. };
  19742. $scope.setActive = function (state) {
  19743. if ($scope.active != state) {
  19744. $scope.active = state;
  19745. if ($scope.tableParams.page() == 1)
  19746. $scope.tableParams.reload();
  19747. else
  19748. $scope.tableParams.page(1);
  19749. }
  19750. };
  19751. $scope.searchMethod = false;
  19752. var getService = function () {
  19753. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19754. };
  19755. $scope.tableParams = new ngTableParams({
  19756. page: 1,
  19757. count: 20,
  19758. sorting: {
  19759. matchsize: 'asc',
  19760. id: 'desc'
  19761. }
  19762. }, {
  19763. total: 0,
  19764. counts: [5, 10, 25, 50],
  19765. getData: function ($defer, params) {
  19766. $scope.loading = true;
  19767. var pageParams = params.url();
  19768. pageParams.keyword = $scope.keyword;
  19769. pageParams.searchFilter = $scope.searchFilter;
  19770. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19771. if (page) {
  19772. $scope.loading = false;
  19773. params.total(page.totalElement);
  19774. $defer.resolve(page.content);
  19775. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19776. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19777. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19778. ids = [];
  19779. if (product.matchresults.length == 1) {
  19780. product.checked = $scope.checks.checked;
  19781. }
  19782. });
  19783. $scope.total = page.totalElement;
  19784. // Products.matchsize({type: 'purc'}, {}, function(data) {
  19785. // $scope.size = data.size;
  19786. // if($scope.total < $scope.size) {
  19787. // $timeout(function() {
  19788. // $scope.tableParams.reload();
  19789. // }, 500);
  19790. // } else {
  19791. // $scope.loading = false;
  19792. // }
  19793. // }, function(response) {
  19794. // toaster.pop('error', '提示', response.data);
  19795. // });
  19796. }
  19797. }, function (response) {
  19798. $scope.loading = false;
  19799. toaster.pop('error', '数据加载失败', response.data);
  19800. });
  19801. }
  19802. });
  19803. // 搜索框回车
  19804. $scope.onSearch = function (keyword) {
  19805. $scope.searchMethod = false;
  19806. if(keyword != null && keyword != '') {
  19807. $scope.searchMethod = true;
  19808. }
  19809. $scope.tableParams.page(1);
  19810. $scope.tableParams.reload();
  19811. };
  19812. var ids = [];
  19813. $scope.checks = {
  19814. checked: false
  19815. };
  19816. // 全选框
  19817. $scope.checkAll = function () {
  19818. ids = [];// 每次选择时先清空,防止重复
  19819. angular.forEach($scope.tableParams.data, function (product) {
  19820. if (product.matchresults.length == 1) {
  19821. product.checked = $scope.checks.checked;
  19822. }
  19823. });
  19824. };
  19825. // 单选
  19826. $scope.checkOne = function (product) {
  19827. ids = [];// 每次选择时先清空,防止重复
  19828. product.checked = !product.checked;
  19829. var result = true;
  19830. angular.forEach($scope.tableParams.data, function (item) {
  19831. if (item.$selected != true) {
  19832. result = false;
  19833. return;
  19834. }
  19835. });
  19836. $scope.checks.checked = result;
  19837. var checked = true;
  19838. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19839. if (!message.checked) {
  19840. checked = false;
  19841. }
  19842. });
  19843. $scope.checks.checked = checked;
  19844. };
  19845. $scope.product = {
  19846. checked: false
  19847. };
  19848. var checkResults = function (result) {
  19849. angular.forEach($scope.tableParams.data, function (product) {
  19850. if (product.id == result.prid) {
  19851. product.checked = false;
  19852. angular.forEach(product.matchresults, function (item) {
  19853. if (result.id == item.id) {
  19854. if (item.checked) {
  19855. product.checked = true;
  19856. return;
  19857. }
  19858. } else {
  19859. item.checked = false;
  19860. }
  19861. });
  19862. }
  19863. });
  19864. // checkProductCheck();
  19865. };
  19866. var checkProductCheck = function () {
  19867. var checked = true;
  19868. angular.forEach($scope.tableParams.data, function (product) {
  19869. if (!product.checked) {
  19870. checked = false;
  19871. }
  19872. });
  19873. $scope.product.checked = checked;
  19874. }
  19875. // 单选明细
  19876. $scope.checkItem = function (result) {
  19877. ids = [];
  19878. result.checked = !result.checked;
  19879. checkResults(result);
  19880. }
  19881. // 一键更新
  19882. $scope.updateAll = function () {
  19883. $scope.loading = true;
  19884. angular.forEach($scope.tableParams.data, function (product) {
  19885. if (product.checked) {
  19886. if (product.matchresults.length == 1) {
  19887. ids.push(product.matchresults[0].id);
  19888. }
  19889. if (product.matchresults.length > 1) {
  19890. angular.forEach(product.matchresults, function (item) {
  19891. if (item.checked) {
  19892. ids.push(item.id);
  19893. }
  19894. });
  19895. }
  19896. }
  19897. });
  19898. Products.updateall({status: $scope.checks.checked, type: 'purc'}, ids, function (data) {
  19899. if (data.success) {
  19900. toaster.pop('success', '提示', data.success);
  19901. $timeout(function () {
  19902. $scope.tableParams.page(1);
  19903. $scope.tableParams.reload();
  19904. $scope.loading = false;
  19905. }, 500);
  19906. }
  19907. ids = []; // 清空ids,防止重复点击出现多余的数据
  19908. }, function (response) {
  19909. $scope.loading = false;
  19910. toaster.pop('error', '提示', response.data);
  19911. });
  19912. }
  19913. }]);
  19914. /**
  19915. * 采购物料资料
  19916. */
  19917. 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) {
  19918. BaseService.scrollBackToTop();
  19919. // 用来记录已经选择的id
  19920. $rootScope.ids = [];
  19921. var loadAccount = function () {
  19922. AccountEnterprise.get({}, function (data) {
  19923. $scope.enterprise = data;
  19924. $scope.purcStatus = $scope.enterprise.prodpurc;
  19925. });
  19926. }
  19927. loadAccount();
  19928. $scope.active = 'all';
  19929. $scope.agreedText = '全部';
  19930. $scope.dateZoneText = '一个月内';
  19931. $scope.condition = {dateZone: 1};
  19932. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19933. $scope.changeAgreed = function (agreed) {
  19934. $scope.condition.agreed = agreed;
  19935. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19936. $scope.condition.$agreedOpen = false;
  19937. };
  19938. $scope.changeDateZone = function (zone) {
  19939. $scope.condition.dateZone = zone;
  19940. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19941. $scope.condition.$dateZoneOpen = false;
  19942. getDateCondition(zone, $scope.condition);
  19943. $scope.tableParams.reload();
  19944. };
  19945. $scope.setActive = function (state) {
  19946. if ($scope.active != state) {
  19947. $scope.active = state;
  19948. if ($scope.tableParams.page() == 1)
  19949. $scope.tableParams.reload();
  19950. else
  19951. $scope.tableParams.page(1);
  19952. }
  19953. };
  19954. $scope.searchMethod = false;
  19955. var getService = function () {
  19956. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  19957. };
  19958. $scope.tableParams = new ngTableParams({
  19959. page: 1,
  19960. count: 20,
  19961. sorting: {
  19962. id: 'desc'
  19963. }
  19964. }, {
  19965. total: 0,
  19966. counts: [5, 10, 25, 50],
  19967. getData: function ($defer, params) {
  19968. $scope.loading = true;
  19969. var pageParams = params.url();
  19970. pageParams.keyword = $scope.keyword;
  19971. pageParams.searchFilter = $scope.searchFilter;
  19972. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19973. $scope.loading = false;
  19974. if (page) {
  19975. params.total(page.totalElement);
  19976. $defer.resolve(page.content);
  19977. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19978. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19979. }
  19980. }, function (response) {
  19981. $scope.loading = false;
  19982. toaster.pop('error', '数据加载失败', response.data);
  19983. });
  19984. }
  19985. });
  19986. // //设置单据已读
  19987. // var setOrdersRead = function () {
  19988. // var ids = [];
  19989. // PurcProduct.setRead({}, ids, function (message) {
  19990. // // $scope.getUnreadIds();
  19991. // });
  19992. // };
  19993. // setOrdersRead();
  19994. // 搜索框回车
  19995. $scope.onSearch = function (keyword) {
  19996. $scope.searchMethod = false;
  19997. if(keyword != null && keyword != '') {
  19998. $scope.searchMethod = true;
  19999. }
  20000. $scope.tableParams.page(1);
  20001. $scope.tableParams.reload();
  20002. };
  20003. //删除
  20004. $scope.deleteById = function (id) {
  20005. GetProductInfo.deletePurcById({}, id, function (data) {
  20006. if (data.error) {
  20007. toaster.pop("error", "提示", data.error);
  20008. } else {
  20009. toaster.pop("success", "提示", "删除成功");
  20010. $timeout(function () {
  20011. $scope.tableParams.reload();
  20012. }, 500);
  20013. }
  20014. }), function (response) {
  20015. toaster.pop("error", "删除失败", response.data);
  20016. };
  20017. }
  20018. // 一键开启关闭
  20019. $scope.toggle = function (status) {
  20020. $scope.loading = true;
  20021. Products.toggle({status: status}, {}, function (data) {
  20022. $scope.loading = false;
  20023. toaster.pop('success', '提示', '操作成功');
  20024. loadAccount();
  20025. $scope.tableParams.reload();
  20026. if ($scope.purcStatus == 0) {
  20027. $scope.purcStatus = 1;
  20028. } else {
  20029. $scope.purcStatus = 0;
  20030. }
  20031. }, function (response) {
  20032. $scope.loading = false;
  20033. toaster.pop('error', '提示', response.data);
  20034. })
  20035. }
  20036. var products = [];
  20037. $scope.checks = {
  20038. checked: false
  20039. };
  20040. // 全选框
  20041. $scope.checkAll = function () {
  20042. products = [];// 每次选择时先清空,防止重复
  20043. angular.forEach($scope.tableParams.data, function (product) {
  20044. if (product.cmpUuId == null) {
  20045. product.checked = $scope.checks.checked;
  20046. }
  20047. });
  20048. };
  20049. // 单选
  20050. $scope.checkOne = function (product) {
  20051. products = [];// 每次选择时先清空,防止重复
  20052. var result = true;
  20053. angular.forEach($scope.tableParams.data, function (item) {
  20054. if (item.$selected != true) {
  20055. result = false;
  20056. return;
  20057. }
  20058. });
  20059. $scope.checks.checked = result;
  20060. var checked = true;
  20061. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  20062. if (!message.checked) {
  20063. checked = false;
  20064. }
  20065. });
  20066. $scope.checks.checked = checked;
  20067. };
  20068. $scope.updateByBatch = function (updatetype) {
  20069. var modalInstance = $modal.open({
  20070. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  20071. controller: 'UpdateByBatchCtrl',
  20072. size: 'md',
  20073. resolve: {
  20074. updatetype: function () {
  20075. return updatetype;
  20076. },
  20077. active: function () {
  20078. return $scope.active;
  20079. },
  20080. type: function () {
  20081. return 'purchase';
  20082. }
  20083. }
  20084. });
  20085. modalInstance.result.then(function (data) {
  20086. toaster.pop('success', '提示', data.success);
  20087. $scope.tableParams.reload();
  20088. }, function () {
  20089. });
  20090. }
  20091. // 一键匹配
  20092. $scope.matchall = function () {
  20093. $scope.type = "purc";
  20094. $scope.loading = true;
  20095. PurcProduct.matchbytype({type: $scope.type}, {}, function (data) {
  20096. if (data.error) {
  20097. $scope.loading = false;
  20098. toaster.pop('error', '提示', data.error);
  20099. } else {
  20100. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  20101. window.location.href = "#/purc/productmatches";
  20102. }
  20103. }, function (response) {
  20104. $scope.loading = false;
  20105. toaster.pop('error', '提示', response.data);
  20106. });
  20107. }
  20108. // 导出
  20109. $scope.exportXls = function () {
  20110. PurcProduct.exportXls({}, {}, function (data) {
  20111. if (data.success){
  20112. window.location.href = 'purcProduct/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  20113. }
  20114. }, function (response) {
  20115. toaster.pop('error', '数据加载失败', response.data);
  20116. });
  20117. }
  20118. }]);
  20119. /**
  20120. * 采购物料批量上传
  20121. */
  20122. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  20123. BaseService.scrollBackToTop();
  20124. $scope.$watch('myFiles', function () {
  20125. if ($scope.myFiles) {
  20126. var file = $scope.myFiles[0];
  20127. $scope.fileName = file.name;
  20128. }
  20129. })
  20130. // 通过excel批量上传物料
  20131. $scope.upload = function () {
  20132. $scope.loading = true;
  20133. if ($scope.myFiles) {
  20134. var file = $scope.myFiles[0];
  20135. if (file.name) {
  20136. $scope.loading = true;
  20137. $upload.upload({
  20138. url: 'purcProduct/edit/release/excel',
  20139. file: file,
  20140. method: 'POST'
  20141. }).success(function (data) {
  20142. $scope.loading = false;
  20143. if (data.error) {
  20144. toaster.pop('error', '提示', data.error);
  20145. }
  20146. $scope.result = data;
  20147. $scope.products = $scope.result.products;
  20148. $scope.success = $scope.result.success;
  20149. $scope.total = $scope.result.total;
  20150. $scope.alters = $scope.result.alters;
  20151. $scope.infos = $scope.result.infos;
  20152. $scope.myFiles[0] = "";
  20153. $scope.fileName = "";
  20154. }).error(function (response) {
  20155. $scope.loading = false;
  20156. toaster.pop('error', response.data || response);
  20157. });
  20158. } else {
  20159. $scope.loading = false;
  20160. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20161. }
  20162. } else {
  20163. $scope.loading = false;
  20164. }
  20165. };
  20166. // 查看范例
  20167. $scope.showImg = function () {
  20168. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  20169. box.show();
  20170. box.find('img').attr('src', src);
  20171. box.find('a').click(function () {
  20172. box.hide();
  20173. });
  20174. box.dblclick(function () {
  20175. box.hide();
  20176. });
  20177. };
  20178. // 下载模板
  20179. $scope.download = function () {
  20180. window.location.href = 'product/baseInfo/upload/template';
  20181. };
  20182. }]);
  20183. /**
  20184. * 新增物料(采购)
  20185. */
  20186. 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) {
  20187. BaseService.scrollBackToTop();
  20188. // 录入人
  20189. AuthenticationService.getAuthentication().success(function (data) {
  20190. $scope.loading = false;
  20191. $scope.user = data;
  20192. });
  20193. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20194. $scope.prodInfo = {};
  20195. // 选择类目
  20196. $scope.selectKind = function () {
  20197. $modal.open({
  20198. animation: true,
  20199. size: 'lg',
  20200. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20201. controller: 'KindChooseCtrl',
  20202. }).result.then(function (data) {
  20203. $scope.kindId = data;
  20204. var modalInstance = $modal.open({
  20205. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20206. controller: 'FindComponentCtrl',
  20207. size: 'lg',
  20208. resolve: {
  20209. KindId: function () {
  20210. return $scope.kindId;
  20211. }
  20212. }
  20213. });
  20214. modalInstance.result.then(function (data) {
  20215. $scope.prodInfo.cmpUuId = data.uuid;
  20216. $scope.prodInfo.pcmpcode = data.code;
  20217. $scope.prodInfo.pbranden = data.brand.nameEn;
  20218. $scope.prodInfo.pbrand = data.brand.nameCn;
  20219. }, function () {
  20220. });
  20221. }, function () {
  20222. });
  20223. };
  20224. // 联想词 start
  20225. // 获取类目
  20226. $scope.getSimilarKinds = function (value) {
  20227. if (value) {
  20228. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20229. return data.map(function (item) {
  20230. return item;
  20231. });
  20232. });
  20233. }
  20234. };
  20235. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20236. $scope.prodInfo.title = kind.kindName;
  20237. }
  20238. $scope.getSimilarBrands = function (value) {
  20239. if (value) {
  20240. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20241. return data.map(function (item) {
  20242. return item;
  20243. });
  20244. });
  20245. }
  20246. }
  20247. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20248. $scope.prodInfo.brand = brand.brandName;
  20249. }
  20250. $scope.getSimilarComponents = function (value) {
  20251. if (value) {
  20252. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20253. return data.map(function (item) {
  20254. return item;
  20255. });
  20256. });
  20257. }
  20258. }
  20259. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20260. $scope.prodInfo.cmpCode = cmp.code;
  20261. }
  20262. // 联想词 end
  20263. // 删除
  20264. $scope.clearfile = function () {
  20265. $scope.myFiles = null;
  20266. $scope.previewShow = false;
  20267. }
  20268. //提交
  20269. $scope.submit = function (prodInfo) {
  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. if (data.success) {
  20281. toaster.pop('success', '提示', data.success);
  20282. $timeout(function () {
  20283. //提交后跳转到详情页面,防止重复提交
  20284. window.location.href = "#/purc/prodList/" + data.id;
  20285. // window.location.href="#/purc/product";
  20286. }, 500);
  20287. }
  20288. if (data.error) {
  20289. toaster.pop('error', '提示', data.error);
  20290. $timeout(function () {
  20291. //提交后跳转到详情页面,防止重复提交
  20292. window.location.href = "#/purc/prodList/" + data.id;
  20293. // window.location.href="#/purc/product";
  20294. }, 500);
  20295. }
  20296. }).error(function (data, status, headers, config) {
  20297. $scope.loadingShow = false;
  20298. if (status == 403) {
  20299. toaster.pop('error', '操作失败', data);
  20300. } else {
  20301. toaster.pop('error', '操作失败', data.error);
  20302. }
  20303. });
  20304. };
  20305. $scope.previewShow = false;
  20306. $scope.pdfShow = false;
  20307. $scope.noneFileShow = true;
  20308. $scope.$watch('myFiles', function () {
  20309. if ($scope.myFiles) {
  20310. $scope.noneFileShow = false;
  20311. var file = $scope.myFiles[0];
  20312. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20313. $scope.pdfShow = true;
  20314. $scope.previewShow = false;
  20315. $scope.imgPreviewName = file.name;
  20316. } else {
  20317. if (typeof(Worker) !== "undefined") {//支持HTML5
  20318. $scope.imgPreview = getObjectURL(file);
  20319. $scope.imgPreviewName = file.name;
  20320. } else {//不支持HTML5
  20321. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20322. $scope.imgPreviewName = file.name;
  20323. }
  20324. $scope.previewShow = true;
  20325. $scope.pdfShow = false;
  20326. }
  20327. } else {
  20328. $scope.noneFileShow = true;
  20329. $scope.previewShow = false;
  20330. $scope.pdfShow = false;
  20331. }
  20332. });
  20333. //建立一个可存取到该file的url
  20334. var imgurl = null;
  20335. var getObjectURL = function (file) {
  20336. var url = null;
  20337. if (window.createObjectURL != undefined) { // basic
  20338. url = window.createObjectURL(file);
  20339. } else if (window.URL != undefined) { // mozilla(firefox)
  20340. url = window.URL.createObjectURL(file);
  20341. } else if (window.webkitURL != undefined) { // webkit or chrome
  20342. url = window.webkitURL.createObjectURL(file);
  20343. }
  20344. imgurl = url;
  20345. return url;
  20346. };
  20347. // 取消
  20348. $scope.cancel = function () {
  20349. $scope.prodInfo = angular.copy($scope.prodInfo);
  20350. };
  20351. // 查看大图
  20352. $scope.showImg = function () {
  20353. var src = imgurl, box = $('#image-box');
  20354. box.show();
  20355. box.find('img').attr('src', src);
  20356. box.find('a').click(function () {
  20357. box.hide();
  20358. });
  20359. box.dblclick(function () {
  20360. box.hide();
  20361. });
  20362. };
  20363. }]);
  20364. /**
  20365. * 物料详情(采购)
  20366. */
  20367. 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) {
  20368. BaseService.scrollBackToTop();
  20369. // 录入人
  20370. AuthenticationService.getAuthentication().success(function (data) {
  20371. $scope.loading = false;
  20372. $scope.user = data;
  20373. });
  20374. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20375. $scope.editstatus = false;
  20376. var loadData = function () {
  20377. GetProductInfo.getPurcProduct({id: $stateParams.id}, function (data) {
  20378. if (data.attach) {
  20379. GetProductInfo.getAttach({id: data.attach.id}, function (data) {
  20380. $scope.imgPreview = data.url;
  20381. $scope.previewShow = true;
  20382. })
  20383. }
  20384. $scope.prodInfo = data;
  20385. if ($scope.prodInfo.isbusiness == 0) {
  20386. $scope.editstatus = true;
  20387. }
  20388. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  20389. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  20390. $scope.matchresults = data;
  20391. }, function (response) {
  20392. toaster.pop('error', '提示', response.data);
  20393. });
  20394. }
  20395. $scope.loading = false;
  20396. }, function (response) {
  20397. toaster.pop('error', '数据加载失败', response.data);
  20398. });
  20399. };
  20400. loadData();
  20401. // 联想词 start
  20402. // 获取类目
  20403. $scope.getSimilarKinds = function (value) {
  20404. if (value) {
  20405. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20406. return data.map(function (item) {
  20407. return item;
  20408. });
  20409. });
  20410. }
  20411. };
  20412. // 设置类目
  20413. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20414. $scope.prodInfo.kind = kind.kindName;
  20415. }
  20416. // 设置名称
  20417. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  20418. $scope.prodInfo.title = kind.kindName;
  20419. }
  20420. $scope.getSimilarBrands = function (value) {
  20421. if (value) {
  20422. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20423. return data.map(function (item) {
  20424. return item;
  20425. });
  20426. });
  20427. }
  20428. }
  20429. // 设置导入品牌
  20430. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20431. $scope.prodInfo.brand = brand.brandName;
  20432. }
  20433. // 设置标准品牌
  20434. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  20435. $scope.prodInfo.pbranden = brand.brandName;
  20436. }
  20437. $scope.getSimilarComponents = function (value) {
  20438. if (value) {
  20439. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20440. return data.map(function (item) {
  20441. return item;
  20442. });
  20443. });
  20444. }
  20445. }
  20446. // 设置标准型号
  20447. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20448. $scope.prodInfo.pcmpcode = cmp.code;
  20449. }
  20450. // 设置导入的型号
  20451. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  20452. $scope.prodInfo.cmpCode = cmp.code;
  20453. }
  20454. // 联想词 end
  20455. //更新为标准器件
  20456. $scope.updateone = function (id) {
  20457. Products.updateone({id: id}, {}, function (data) {
  20458. if (data.success) {
  20459. toaster.pop('success', '提示', data.success);
  20460. window.location.reload();
  20461. }
  20462. }, function (response) {
  20463. toaster.pop('error', '提示', response.data);
  20464. });
  20465. }
  20466. // 选择类目
  20467. $scope.selectKind = function (cmpcode) {
  20468. if (cmpcode == null) {
  20469. $modal.open({
  20470. animation: true,
  20471. size: 'lg',
  20472. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20473. controller: 'KindChooseCtrl',
  20474. }).result.then(function (data) {
  20475. $scope.kindId = data;
  20476. var modalInstance = $modal.open({
  20477. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20478. controller: 'FindComponentCtrl',
  20479. size: 'lg',
  20480. resolve: {
  20481. KindId: function () {
  20482. return $scope.kindId;
  20483. }
  20484. }
  20485. });
  20486. modalInstance.result.then(function (data) {
  20487. $scope.prodInfo.cmpUuId = data.uuid;
  20488. $scope.prodInfo.pcmpcode = data.code;
  20489. $scope.prodInfo.pbranden = data.brand.nameEn;
  20490. $scope.prodInfo.pbrand = data.brand.nameCn;
  20491. }, function () {
  20492. });
  20493. }, function () {
  20494. });
  20495. }
  20496. };
  20497. $scope.isShow = true;
  20498. // 更新
  20499. $scope.update = function () {
  20500. $scope.prodInfo.$editing = true;
  20501. $scope.isShow = true;
  20502. };
  20503. // 取消
  20504. $scope.cancel = function () {
  20505. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  20506. $scope.prodInfo = data;
  20507. $scope.prodInfo.$editing = false;
  20508. $scope.isShow = false;
  20509. $scope.loading = false;
  20510. });
  20511. };
  20512. // 删除
  20513. $scope.clearfile = function () {
  20514. $scope.prodInfo.attach = null;
  20515. $scope.myFiles = null;
  20516. $scope.previewShow = false;
  20517. }
  20518. //删除
  20519. $scope.deleteById = function (id) {
  20520. GetProductInfo.deletePurcById({}, id, function (data) {
  20521. if (data.error) {
  20522. toaster.pop("error", "提示", data.error);
  20523. } else {
  20524. toaster.pop("success", "提示", "删除成功");
  20525. window.location.href = "#/purc/product";
  20526. }
  20527. }, function (response) {
  20528. toaster.pop("error", "删除失败", response.data);
  20529. });
  20530. }
  20531. $scope.submit = function (prodInfo) {
  20532. $scope.prodInfo.isPurchase = 1;
  20533. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20534. $upload.upload({
  20535. url: 'purcProduct/edit/updateProdInfo',
  20536. file: file,
  20537. method: 'POST',
  20538. data: {
  20539. prodInfo: $scope.prodInfo
  20540. },
  20541. }).success(function (data) {
  20542. if (data.success) {
  20543. toaster.pop('success', '提示', data.success);
  20544. loadData();
  20545. // window.location.href="#/sale/prodList";
  20546. }
  20547. if (data.error) {
  20548. toaster.pop('error', '提示', data.error);
  20549. }
  20550. }).error(function (data, status) {
  20551. $scope.loadingShow = false;
  20552. if (status == 403) {
  20553. toaster.pop('error', '操作失败', data);
  20554. } else {
  20555. toaster.pop('error', '操作失败', data.error);
  20556. }
  20557. });
  20558. }
  20559. $scope.previewShow = false;
  20560. $scope.pdfShow = false;
  20561. $scope.noneFileShow = true;
  20562. $scope.$watch('myFiles', function () {
  20563. if ($scope.myFiles) {
  20564. $scope.noneFileShow = false;
  20565. var file = $scope.myFiles[0];
  20566. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20567. $scope.pdfShow = true;
  20568. $scope.previewShow = false;
  20569. $scope.imgPreviewName = file.name;
  20570. } else {
  20571. if (typeof(Worker) !== "undefined") {//支持HTML5
  20572. $scope.imgPreview = getObjectURL(file);
  20573. $scope.imgPreviewName = file.name;
  20574. } else {//不支持HTML5
  20575. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20576. $scope.imgPreviewName = file.name;
  20577. }
  20578. $scope.previewShow = true;
  20579. $scope.pdfShow = false;
  20580. }
  20581. } else {
  20582. $scope.noneFileShow = true;
  20583. $scope.previewShow = false;
  20584. $scope.pdfShow = false;
  20585. }
  20586. });
  20587. //建立一个可存取到该file的url
  20588. var imgurl = null;
  20589. var getObjectURL = function (file) {
  20590. var url = null;
  20591. if (window.createObjectURL != undefined) { // basic
  20592. url = window.createObjectURL(file);
  20593. } else if (window.URL != undefined) { // mozilla(firefox)
  20594. url = window.URL.createObjectURL(file);
  20595. } else if (window.webkitURL != undefined) { // webkit or chrome
  20596. url = window.webkitURL.createObjectURL(file);
  20597. }
  20598. imgurl = url;
  20599. return url;
  20600. };
  20601. // 查看范例
  20602. $scope.showImg = function () {
  20603. if ($scope.prodInfo.attach) {
  20604. GetProductInfo.getAttach({id: $scope.prodInfo.attach.id}, function (data) {
  20605. var src = data.url, box = $('#image-box');
  20606. box.show();
  20607. box.find('img').attr('src', src);
  20608. box.find('a').click(function () {
  20609. box.hide();
  20610. });
  20611. box.dblclick(function () {
  20612. box.hide();
  20613. });
  20614. })
  20615. } else if (imgurl != null) {
  20616. var src = imgurl, box = $('#image-box');
  20617. box.show();
  20618. box.find('img').attr('src', src);
  20619. box.find('a').click(function () {
  20620. box.hide();
  20621. });
  20622. box.dblclick(function () {
  20623. box.hide();
  20624. });
  20625. }
  20626. };
  20627. }]);
  20628. // 供应商绩效考核
  20629. app.controller('VendorPerformanceAssessCtrl', ['$scope', 'VendorPerformanceAssessService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorPerformanceAssessService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  20630. BaseService.scrollBackToTop();
  20631. $scope.vendorPerformanceAssessParams = new ngTableParams({
  20632. page: 1,
  20633. count: 20
  20634. }, {
  20635. total: 0,
  20636. counts: [5, 10, 25, 50],
  20637. getData: function ($defer, params) {
  20638. $scope.loading = true;
  20639. var pageParams = params.url();
  20640. pageParams.keyword = $scope.keyword;
  20641. VendorPerformanceAssessService.get(BaseService.parseParams(pageParams), function (page) {
  20642. $scope.loading = false;
  20643. if (page) {
  20644. params.total(page.totalElement);
  20645. $defer.resolve(page.content);
  20646. $scope.keywordXls = pageParams.keyword;
  20647. }
  20648. $scope.totalCount = page.totalElement;
  20649. }, function (response) {
  20650. $scope.loading = false;
  20651. toaster.pop('error', '数据加载失败', response.data);
  20652. });
  20653. }
  20654. });
  20655. //设置消息已读
  20656. var setOrdersRead = function () {
  20657. var sourceId = [];
  20658. VendorPerformanceAssessService.setRead({}, sourceId, function (message) {
  20659. // $scope.getUnreadIds();
  20660. });
  20661. };
  20662. setOrdersRead();
  20663. // 搜索框回车
  20664. $scope.onSearch = function (keyword) {
  20665. $scope.vendorPerformanceAssessParams.page(1);
  20666. $scope.vendorPerformanceAssessParams.reload();
  20667. $scope.tip = keyword;
  20668. };
  20669. // 查看详情
  20670. $scope.viewDetail = function (id) {
  20671. window.location.hash = "#/sale/vendorPerformanceAssess/" + id;
  20672. }
  20673. }]);
  20674. // 客户详情
  20675. app.controller('VendorPerformanceAssessDetailCtrl', ['$scope', 'toaster', '$stateParams', 'VendorPerformanceAssessService', '$modal', 'ngTableParams', 'BaseService', '$rootScope', 'AuthenticationService', function ($scope, toaster, $stateParams, VendorPerformanceAssessService, $modal, ngTableParams, BaseService, $rootScope, AuthenticationService) {
  20676. BaseService.scrollBackToTop();
  20677. var loadData = function () {
  20678. VendorPerformanceAssessService.getDetail({id: $stateParams.id}, {}, function (data) {
  20679. $scope.vendorPerformanceAssess = data;
  20680. }, function (response) {
  20681. $scope.loading = false;
  20682. toaster.pop('error', '数据加载失败', response.data);
  20683. });
  20684. };
  20685. loadData();
  20686. }]);
  20687. /**
  20688. * 个人产库
  20689. */
  20690. app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal) {
  20691. BaseService.scrollBackToTop();
  20692. $scope.searchMethod = false;
  20693. var getService = function () {
  20694. return $scope.searchMethod ? prodUser.getInfo : prodUser.info;
  20695. };
  20696. $scope.tableParams = new ngTableParams({ // ng-Table参数
  20697. page: 1,
  20698. count: 20,
  20699. sorting: {
  20700. 'date': 'desc',
  20701. 'id': 'desc'
  20702. }
  20703. }, {
  20704. total: 0,
  20705. counts: [],
  20706. getData: function ($defer, params) { // 获取数据的方法
  20707. $scope.loading = true;
  20708. var pageParams = params.url();
  20709. pageParams.keyword = $scope.keyword;
  20710. $scope.tip = $scope.keyword;
  20711. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  20712. $scope.loading = false;
  20713. if (page) {
  20714. params.total(page.totalElement);
  20715. $defer.resolve(page.content);
  20716. }
  20717. }, function (response) {
  20718. $scope.loading = false;
  20719. toaster.pop('error', '数据加载失败', response.data);
  20720. });
  20721. }
  20722. });
  20723. // 搜索框回车
  20724. $scope.onSearch = function (keyword) {
  20725. // 每次搜索重置获取数据方法
  20726. $scope.searchMethod = false;
  20727. if(keyword != null && keyword != '') {
  20728. $scope.searchMethod = true;
  20729. $scope.tip = keyword;
  20730. }
  20731. $scope.tableParams.page(1);
  20732. $scope.tableParams.reload();
  20733. };
  20734. // 新增产品信息
  20735. $scope.addProduct = function() {
  20736. $modal.open({
  20737. animation: true,
  20738. size: 'lg',
  20739. templateUrl: 'static/tpl/index/approvalFlow/modal/userprod_new_modal.html',
  20740. controller: 'UserProductNewCtrl',
  20741. }).result.then(function (data) {
  20742. $scope.tableParams.page(1);
  20743. $scope.tableParams.reload();
  20744. }, function () {
  20745. });
  20746. }
  20747. // 导入商品信息
  20748. $scope.uploadByBatch = function () {
  20749. var modalInstance = $modal.open({
  20750. templateUrl: 'static/tpl/index/approvalFlow/modal/uplodaByBatch.html',
  20751. controller: 'UserProdUploadCtrl',
  20752. size: 'lg',
  20753. resolve: {}
  20754. });
  20755. modalInstance.result.then(function (data) {
  20756. $scope.tableParams.page(1);
  20757. $scope.tableParams.reload();
  20758. }, function () {
  20759. });
  20760. }
  20761. // 删除
  20762. $scope.deleteById = function(id) {
  20763. prodUser.deleteById({}, id, function(data) {
  20764. toaster.pop('success', '提示', '删除成功');
  20765. $scope.tableParams.page(1);
  20766. $scope.tableParams.reload();
  20767. }, function(res) {
  20768. toaster.pop('error', '提示', '删除失败');
  20769. });
  20770. }
  20771. }]);
  20772. /**
  20773. * 用户产品新增产品
  20774. */
  20775. app.controller('UserProductNewCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', function($scope, toaster, prodUser, $modalInstance) {
  20776. // 确定
  20777. $scope.submit = function(prodInfo) {
  20778. prodUser.addProduct({}, prodInfo, function(data) {
  20779. toaster.pop('success', '提示', '添加成功');
  20780. $modalInstance.close('success');
  20781. }, function(res) {
  20782. toaster.pop('error', '提示', '添加失败');
  20783. });
  20784. }
  20785. // 取消
  20786. $scope.cancel = function() {
  20787. $modalInstance.dismiss();
  20788. }
  20789. }]);
  20790. /**
  20791. * 用户产品批量导入产品
  20792. */
  20793. app.controller('UserProdUploadCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', '$upload', function($scope, toaster, prodUser, $modalInstance, $upload) {
  20794. // 通过excel批量上传物料
  20795. $scope.upload = function () {
  20796. $scope.loading = true;
  20797. if ($scope.myFiles) {
  20798. var file = $scope.myFiles[0];
  20799. if (file.name) {
  20800. $upload.upload({
  20801. url: 'productuser/edit/release/excel',
  20802. file: file,
  20803. method: 'POST'
  20804. }).success(function (data) {
  20805. $scope.loading = false;
  20806. if (data.error) {
  20807. toaster.pop('error', '提示', data.error);
  20808. }
  20809. $scope.result = data;
  20810. $scope.success = $scope.result.success;
  20811. $scope.total = $scope.result.total;
  20812. $scope.myFiles[0] = "";
  20813. $scope.fileName = "";
  20814. }).error(function (response) {
  20815. $scope.loading = false;
  20816. toaster.pop('error', response.data || response);
  20817. });
  20818. } else {
  20819. $scope.loading = false;
  20820. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20821. }
  20822. } else {
  20823. $scope.loading = false;
  20824. }
  20825. };
  20826. // 取消
  20827. $scope.cancel = function() {
  20828. $modalInstance.dismiss();
  20829. }
  20830. // 下载模板
  20831. $scope.download = function () {
  20832. window.location.href = 'productuser/upload/template';
  20833. };
  20834. // 确定
  20835. $scope.enSure = function() {
  20836. $modalInstance.close('success');
  20837. }
  20838. }]);
  20839. return app;
  20840. });