app.js 970 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868
  1. define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives', 'service/Purc', 'service/Make', 'service/Fa', 'service/Account', 'service/Alert', 'service/CheckTel', 'ui.router', 'ui.bootstrap', 'file-upload', 'ngSanitize', 'service/BaseInfo', 'service/Cart', 'service/ApprovalFlow', 'service/DeputyOrder', 'service/Product', 'service/Token', 'service/ProductUsers', 'service/File', 'service/PublicInquiry', 'service/Customer', 'service/PurcChange', 'angularTreeview'], function () {
  2. 'use strict';
  3. var app = angular.module('myApp', ['toaster', 'angularCharts', 'ngTable', 'ui.router', 'common.services', 'common.directives', 'PurcServices', 'MakeServices', 'FaServices', 'AccountServices', 'AlertServices', 'ui.bootstrap', 'angularFileUpload', 'ngSanitize', 'CheckTelModule', 'ProductServices', 'CartServices', 'ApprvoalFlowService', 'DeputyOrderService', 'ProductInfoServices', 'TokenService', 'ProductUserService', 'ui.tour', 'FileService', 'publicInquiryService', 'CustomerService', 'changeService', 'angularTreeview']);
  4. app.init = function () {
  5. angular.bootstrap(document, ['myApp']);
  6. };
  7. app.config(['$httpProvider', function ($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', function ($window, $q) {
  12. var httpInterceptor = {
  13. responseError: function (response) {
  14. console.log('res' + response);
  15. console.log('status' + response.status);
  16. if (response.status == 401) {// UNAUTHORIZED
  17. // window.location.href = window.location.origin + window.location.pathname + '/login';
  18. // window.location.reload();
  19. window.location.href = response.data.loginUrl || 'index';
  20. return $q.reject(response);
  21. }
  22. return $q.reject(response);
  23. }
  24. }
  25. return httpInterceptor;
  26. }]);
  27. app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
  28. $stateProvider.state('index', {
  29. url: "/index",
  30. views: {
  31. "left-view": {
  32. templateUrl: "static/tpl/index/common/leftAll.html",
  33. controller: 'LeftCtrl'
  34. },
  35. "right-view": {
  36. templateUrl: "static/tpl/index/home/right.html",
  37. controller: 'RightCtrl'
  38. }
  39. }
  40. }).state('home', {
  41. url: "/",
  42. views: {
  43. "left-view": {
  44. templateUrl: "static/tpl/index/common/leftAll.html",
  45. controller: 'LeftCtrl'
  46. },
  47. "right-view": {
  48. templateUrl: "static/tpl/index/home/right.html",
  49. controller: 'RightCtrl'
  50. }
  51. }
  52. }).state('sale', {
  53. url: "/sale",
  54. views: {
  55. "left-view": {
  56. templateUrl: "static/tpl/index/common/leftAll.html",
  57. controller: 'LeftCtrl'
  58. },
  59. "right-view": {
  60. templateUrl: "static/tpl/index/sale/right.html"
  61. }
  62. },
  63. controller: function ($scope) {
  64. $scope.truck = [];
  65. $scope.dataChanged = false;
  66. }
  67. }).state('sale.index', {
  68. url: "",
  69. templateUrl: "static/tpl/index/sale/index.html"
  70. }).state('sale.home', {
  71. url: "/",
  72. templateUrl: "static/tpl/index/sale/index.html"
  73. }).state('purc', {
  74. url: "/purc",
  75. views: {
  76. "left-view": {
  77. templateUrl: "static/tpl/index/common/leftAll.html",
  78. controller: 'LeftCtrl'
  79. },
  80. "right-view": {
  81. templateUrl: "static/tpl/index/purc/right.html"
  82. }
  83. },
  84. controller: function ($scope) {
  85. $scope.truck = [];
  86. $scope.dataChanged = false;
  87. }
  88. }).state('purc.index', {
  89. url: "",
  90. templateUrl: "static/tpl/index/purc/index.html"
  91. }).state('purc.home', {
  92. url: "/",
  93. templateUrl: "static/tpl/index/purc/index.html"
  94. }).state('purc.introduce', {
  95. url: "/introduce",
  96. templateUrl: "static/tpl/index/purc/introduce.html"
  97. }).state('purc.order', {
  98. url: "/order",
  99. templateUrl: "static/tpl/index/purc/order.html",
  100. controller: 'PurcOrderCtrl'
  101. }).state('purc.order_detail', {
  102. url: "/order/:id",
  103. templateUrl: "static/tpl/index/purc/order_detail.html",
  104. controller: 'PurcOrderDetailCtrl'
  105. }).state('purc.newOrder', {
  106. url: "/addOrder",
  107. templateUrl: "static/tpl/index/purc/addOrder.html",
  108. controller: 'PurcNewOrderCtrl'
  109. }).state('purc.cart', {
  110. url: "/cart",
  111. templateUrl: "static/tpl/index/purc/cart.html",
  112. controller: 'CartController'
  113. }).state('purc.cartDetail', {
  114. url: "/cart/:id",
  115. templateUrl: "static/tpl/index/purc/cart_detail.html",
  116. controller: 'CartDetailController'
  117. }).state('purc.deputy', {
  118. url: "/deputy",
  119. templateUrl: "static/tpl/index/purc/deputyOrder.html",
  120. controller: 'DeputyOrderCtrl'
  121. }).state('purc.deputylog', {
  122. url: "/deputylog",
  123. templateUrl: "static/tpl/index/purc/deputyorders_log.html",
  124. controller: 'DeputyOrderLogCtrl'
  125. }).state('purc.newdeputy', {
  126. url: "/deputy/add",
  127. templateUrl: "static/tpl/index/purc/deputyOrder_new.html",
  128. controller: 'NewDeputyOrderCtrl'
  129. }).state('purc.deputydetail', {
  130. url: "/deputy/:id",
  131. templateUrl: "static/tpl/index/purc/deputyOrder_detail.html",
  132. controller: 'DeputyOrderDetailCtrl'
  133. }).state('purc.changeList', {// 新增采购变更单
  134. url: "/change",
  135. templateUrl: "static/tpl/index/purc/changeList.html",
  136. controller: 'PurcChangeListCtrl'
  137. /* 采购变更单详情 */
  138. }).state('purc.change_detail', {
  139. url: "/change/:id",
  140. templateUrl: "static/tpl/index/purc/change_detail.html",
  141. controller: 'PurcChangeDetailCtrl'
  142. }).state('purc.changeNew', {// 新增采购变更单
  143. url: "/change_new",
  144. templateUrl: "static/tpl/index/purc/change_new.html",
  145. controller: 'PurcChangeNewCtrl'
  146. /* 招标列表 */
  147. }).state('purc.tenderlist', {
  148. url: "/tender",
  149. templateUrl: "static/tpl/index/purc/tenderlist.html",
  150. controller: 'PurcTenderCtrl'
  151. /* 招标答疑列表 */
  152. }).state('purc.tenderanswerlist', {
  153. url: "/tender/answer",
  154. templateUrl: "static/tpl/index/purc/tender_answer_list.html",
  155. controller: 'PurcTenderAnswerListCtrl'
  156. /* 招标答疑详情 */
  157. }).state('purc.tenderanswerdetail', {
  158. url: "/tender/answer/:id",
  159. templateUrl: "static/tpl/index/purc/tender_answer_detail.html",
  160. controller: 'PurcTenderAnswerDetailCtrl'
  161. }).state('purc.waiting.tenderlist', {
  162. url: "/tender",
  163. templateUrl: "static/tpl/index/purc/tenderlist.html",
  164. controller: 'PurcTenderCtrl'
  165. }).state('purc.todo.tenderlist', {
  166. url: "/tender/todo",
  167. templateUrl: "static/tpl/index/purc/tenderlist.html",
  168. controller: 'PurcTenderCtrl'
  169. /* 招标 */
  170. }).state('purc.tender', {
  171. url: "/addTender",
  172. templateUrl: "static/tpl/index/purc/tender.html",
  173. controller: 'PurcNewTenderCtrl'
  174. }).state('purc.savedtender', {
  175. url: "/tender/:id",
  176. templateUrl: "static/tpl/index/purc/tender.html",
  177. controller: 'PurcNewTenderCtrl'
  178. /* 评标 */
  179. }).state('purc.evaluation', {
  180. url: "/evaluation/:id",
  181. templateUrl: "static/tpl/index/purc/tender_evaluation.html",
  182. controller: 'PurcEvaluationCtrl'
  183. /* 采购供应商资料 */
  184. }).state('purc.vendor', {
  185. url: "/vendor",
  186. templateUrl: "static/tpl/index/purc/vendor.html",
  187. controller: 'PurcVendorCtrl'
  188. /* 采购供应商资料 详情*/
  189. }).state('purc.vendorserve', {
  190. url: "/vendor/serve",
  191. templateUrl: "static/tpl/index/cs/right.html",
  192. controller: 'CustServeCtrl'
  193. }).state('purc.vendordetail', {
  194. url: "/vendor/:id",
  195. templateUrl: "static/tpl/index/purc/vendor_detail.html",
  196. controller: 'PurcVendorDetailCtrl'
  197. /* 客户指定招标列表 */
  198. }).state('purc.makeoutorder', {
  199. url: "/makeoutorder",
  200. templateUrl: "static/tpl/index/make/outorder.html",
  201. controller: 'MakeOutOrderCtrl'
  202. }).state('purc.outorder_detail', {
  203. url: "/makeoutorder/:id",
  204. templateUrl: "static/tpl/index/make/outorder_detail.html",
  205. controller: 'MakeOutOrderDetailCtrl'
  206. /*平台新增询价单*/
  207. }).state('purc.inquiry_new', {
  208. url: "/purcinquiry",
  209. templateUrl: "static/tpl/index/purc/inquiry_new.html",
  210. controller: 'PurcInquiryCtrl'
  211. /*新增公共询价*/
  212. }).state('purc.pubinquiry_new', {
  213. url: "/pubinquiry/new",
  214. templateUrl: "static/tpl/index/purc/pubInquiry_new.html",
  215. controller: 'PurcInquiryCtrl'
  216. }).state('purc.purcinquiry_new', {
  217. url: "/purcinquiry/:bussinessCode",
  218. templateUrl: "static/tpl/index/purc/purcinquiry_new.html",
  219. controller: 'PurcInquiryNewCtrl'
  220. }).state('purc.inquiry', {
  221. url: "/purchaseinquiry",
  222. templateUrl: "static/tpl/index/purc/inquiry.html",
  223. controller: 'PurchaseInquiryCtrl'
  224. }).state('purc.inquiry_detail', {
  225. url: "/purcinquirydetail",
  226. templateUrl: "static/tpl/index/purc/inquiry_detail.html",
  227. controller: 'PurcInquiryDetailCtrl'
  228. }).state('purc.inquiryInfo_detail', {
  229. url: "/purcinquirydetail/:id",
  230. templateUrl: "static/tpl/index/purc/inquiryInfo_detail.html",
  231. controller: 'PurcInquiryInfoDetailCtrl'
  232. }).state('purc.inquiry_unapply', {
  233. url: "/inquiry_unapply",
  234. templateUrl: "static/tpl/index/purc/inquiry_unapply.html",
  235. controller: 'UnapplyInquiryCtrl'
  236. }).state('purc.pubInquiry', {
  237. /**
  238. * 针对客户,查询已转报价的公共询价单列表
  239. */
  240. url: "/publicInquiry",
  241. templateUrl: "static/tpl/index/purc/pubInquiry.html",
  242. controller: 'PurcPubInquiryCtrl'
  243. }).state('purc.pubInquiry_detail', {
  244. /**
  245. * 针对客户,查询已转报价单的公共询价详情
  246. */
  247. url: "/publicInquiry/:id",
  248. templateUrl: "static/tpl/index/purc/pubInquiry_detail.html",
  249. controller: 'PurcPubInquiryDetailCtrl'
  250. }).state('purc.product', {
  251. url: "/product",
  252. templateUrl: "static/tpl/index/purc/prodList.html",
  253. controller: 'PurcProductCtrl'
  254. }).state('purc.newProduct', {
  255. url: "/newProduct",
  256. templateUrl: "static/tpl/index/purc/newProdInfo.html",
  257. controller: 'PurcNewProdInfoCtrl'
  258. }).state('purc.productDetail', {
  259. url: "/prodList/:id",
  260. templateUrl: "static/tpl/index/purc/productDetail.html",
  261. controller: 'PurcProdDetailCtrl'
  262. }).state('purc.productmatches', {
  263. url: "/productmatches",
  264. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  265. controller: 'ProductmatchesForPurcCtrl'
  266. }).state('purc.uploadProduct', {
  267. url: "/uploadProduct",
  268. templateUrl: "static/tpl/index/purc/uploadByBatch.html",
  269. controller: 'UploadProductCtrl'
  270. }).state('sale.tenderlist', {
  271. url: "/tender",
  272. templateUrl: "static/tpl/index/sale/tenderlist.html",
  273. controller: 'SaleTenderCtrl'
  274. /* 招标提问列表 */
  275. }).state('sale.tenderquestionlist', {
  276. url: "/tender/question",
  277. templateUrl: "static/tpl/index/sale/tender_question_list.html",
  278. controller: 'SaleTenderQuestionListCtrl'
  279. /* 招标提问详情 */
  280. }).state('sale.tenderquestiondetail', {
  281. url: "/tender/question/:id",
  282. templateUrl: "static/tpl/index/sale/tender_question_detail.html",
  283. controller: 'SaleTenderQuestionDetailCtrl'
  284. }).state('sale.todo.tenderlist', {
  285. url: "/tender",
  286. templateUrl: "static/tpl/index/sale/tenderlist.html",
  287. controller: 'SaleTenderCtrl'
  288. /* 平台公开招标列表 */
  289. }).state('baseInfo.openTenderList', {
  290. url: "/openTenderList",
  291. templateUrl: "static/tpl/index/sale/open_tender_list.html",
  292. controller: 'SaleOpenTenderCtrl'
  293. /* 查看公开招标详情 */
  294. }).state('baseInfo.open_tender_detail', {
  295. url: "/openTenderDetail/:id",
  296. templateUrl: "static/tpl/index/sale/open_tender_detail.html",
  297. controller: 'OpenSaleTenderDetailCtrl'
  298. /* 投标 */
  299. }).state('sale.tender', {
  300. url: "/tender/:id",
  301. templateUrl: "static/tpl/index/sale/tender.html",
  302. controller: 'SaleTenderDetailCtrl'
  303. /* 采购方查看供应商投标 */
  304. }).state('sale.vendortender', {
  305. url: "/tender/:vendUU/:id",
  306. templateUrl: "static/tpl/index/sale/vendor_tender.html",
  307. controller: 'SaleVendorTenderDetailCtrl'
  308. }).state('sale.todo', {
  309. url: "/todo",
  310. templateUrl: "static/tpl/index/sale/todo.html"
  311. }).state('sale.todo.inquiry', {
  312. url: "/inquiry",
  313. templateUrl: "static/tpl/index/sale/inquiry.html",
  314. controller: 'SaleInquiryCtrl'
  315. }).state('sale.todo.order', {
  316. url: "/order",
  317. templateUrl: "static/tpl/index/sale/order.html",
  318. controller: 'SaleOrderCtrl'
  319. }).state('sale.todo.change', {
  320. url: "/change",
  321. templateUrl: "static/tpl/index/sale/change.html",
  322. controller: 'SaleChangeCtrl'
  323. }).state('sale.todo.notice', {
  324. url: "/notice",
  325. templateUrl: "static/tpl/index/sale/notice.html",
  326. controller: 'SaleNoticeCtrl'
  327. }).state('sale.customer', {
  328. url: "/customer",
  329. templateUrl: "static/tpl/index/sale/customer.html",
  330. controller: 'CustomerCtrl'
  331. }).state('sale.customer_detail', {
  332. url: "/customer/:id",
  333. templateUrl: "static/tpl/index/sale/customer_detail.html",
  334. controller: 'CustomerDetailCtrl'
  335. }).state('sale.customerProduct', {
  336. url: "/customerProduct",
  337. templateUrl: "static/tpl/index/sale/customer.html",
  338. controller: 'CustomerCtrl'
  339. }).state('sale.inquiry', {
  340. url: "/inquiry",
  341. templateUrl: "static/tpl/index/sale/inquiry.html",
  342. controller: 'SaleInquiryCtrl'
  343. }).state('sale.pubinquiry', {
  344. /**
  345. * 针对卖家,展示已转询价报价的公共询价单列表
  346. */
  347. url: "/pubinquiry",
  348. templateUrl: "static/tpl/index/sale/pubinquiry.html",
  349. controller: 'SalePubInquiryCtrl',
  350. params: {
  351. 'saleInquiryActive': null
  352. }
  353. }).state('sale.pubinquiry_detail', {
  354. /**
  355. * 针对卖家,已转询价报价单的公共询价单详情
  356. */
  357. url: "/pubinquiry/:id",
  358. templateUrl: "static/tpl/index/sale/pubinquiry_detail.html",
  359. controller: 'SalePubInquiryDetailCtrl'
  360. }).state('sale.inquiryRemind', {
  361. /**
  362. * 针对卖家,查询推荐的询价列表
  363. */
  364. url: "/inquiryRemind",
  365. templateUrl: "static/tpl/index/sale/inquiryRemind.html",
  366. controller: 'SaleInquiryRemindCtrl'
  367. }).state('sale.inquirymould', {
  368. url: "/mould",
  369. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  370. controller: 'SaleInquiryMouldCtrl'
  371. }).state('sale.todo.inquirymould', {
  372. url: "/mould",
  373. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  374. controller: 'SaleInquiryMouldCtrl'
  375. }).state('sale.inquiry_mould_detail', {
  376. url: "/mould/:id",
  377. templateUrl: "static/tpl/index/sale/inquiry_mould_detail.html",
  378. controller: 'SaleInquiryMouldDetailCtrl'
  379. }).state('sale.inquiry_detail', {
  380. url: "/inquiry/:id",
  381. templateUrl: "static/tpl/index/sale/inquiry_detail.html",
  382. controller: 'SaleInquiryDetailCtrl'
  383. }).state('sale.quotation', {
  384. url: "/quotation",
  385. templateUrl: "static/tpl/index/sale/quotation.html"
  386. }).state('sale.quotation.new', {
  387. url: "/new",
  388. templateUrl: "static/tpl/index/sale/quotation_new.html",
  389. controller: 'SaleQuotationNewCtrl',
  390. params: {
  391. 'inquiryItem': null
  392. }
  393. }).state('sale.quotation.list', {
  394. url: "/list",
  395. templateUrl: "static/tpl/index/sale/quotation_list.html",
  396. controller: 'SaleQuotationListCtrl'
  397. }).state('sale.quotation.item', {
  398. url: "/:id",
  399. templateUrl: "static/tpl/index/sale/quotation_new.html",
  400. controller: 'SaleQuotationNewCtrl'
  401. }).state('sale.order', {
  402. url: "/order",
  403. templateUrl: "static/tpl/index/sale/order.html",
  404. controller: 'SaleOrderCtrl'
  405. }).state('sale.order_detail', {
  406. url: "/order/:id",
  407. templateUrl: "static/tpl/index/sale/order_detail.html",
  408. controller: 'SaleOrderDetailCtrl'
  409. }).state('sale.change', {
  410. url: "/change",
  411. templateUrl: "static/tpl/index/sale/change.html",
  412. controller: 'SaleChangeCtrl'
  413. }).state('sale.change_detail', {
  414. url: "/change/:id",
  415. templateUrl: "static/tpl/index/sale/change_detail.html",
  416. controller: 'SaleChangeDetailCtrl'
  417. }).state('sale.notice', {
  418. url: "/notice",
  419. templateUrl: "static/tpl/index/sale/notice.html",
  420. controller: 'SaleNoticeCtrl'
  421. }).state('sale.send', {
  422. url: "/send",
  423. templateUrl: "static/tpl/index/sale/send.html",
  424. controller: 'SaleSendCtrl'
  425. }).state('sale.send_detail', {
  426. url: "/send/:id",
  427. templateUrl: "static/tpl/index/sale/send_detail.html",
  428. controller: 'SaleSendDetailCtrl'
  429. }).state('sale.forecast', {
  430. url: "/forecast",
  431. templateUrl: "static/tpl/index/sale/forecast.html",
  432. controller: 'SaleForecastCtrl'
  433. }).state('sale.accept', {
  434. url: "/accept",
  435. templateUrl: "static/tpl/index/sale/accept.html",
  436. controller: 'SaleAcceptCtrl'
  437. }).state('sale.accept_detail', {
  438. url: "/accept/:id",
  439. templateUrl: "static/tpl/index/sale/accept_detail.html",
  440. controller: 'SaleAcceptDetailCtrl'
  441. }).state('sale.returns', {
  442. url: "/returns",
  443. templateUrl: "static/tpl/index/sale/returns.html",
  444. controller: 'SaleReturnsCtrl'
  445. }).state('sale.return_detail', {
  446. url: "/return/:id",
  447. templateUrl: "static/tpl/index/sale/return_detail.html",
  448. controller: 'SaleReturnsDetailCtrl'
  449. }).state('sale.sample', {
  450. url: "/sample",
  451. templateUrl: "static/tpl/index/sale/sample.html",
  452. controller: 'SaleSampleCtrl'
  453. }).state('sale.sample_detail', {
  454. url: "/sample/:id",
  455. templateUrl: "static/tpl/index/sale/sample_detail.html",
  456. controller: 'SaleSampleDetailCtrl'
  457. }).state('sale.approval', {
  458. url: "/approval",
  459. templateUrl: "static/tpl/index/sale/approval.html",
  460. controller: 'SaleApprovalCtrl'
  461. }).state('sale.prodList', {
  462. url: "/prodList",
  463. templateUrl: "static/tpl/index/baseInfo/prodList.html",
  464. controller: 'ProductListCtrl'
  465. }).state('sale.newProdInfo', {
  466. url: "/newProdInfo",
  467. templateUrl: "static/tpl/index/baseInfo/newProdInfo.html",
  468. controller: 'NewProdInfoCtrl'
  469. }).state('sale.uploadByBatch', {
  470. url: "/uploadByBatch",
  471. templateUrl: "static/tpl/index/baseInfo/uploadByBatch.html",
  472. controller: 'UploadByBatchCtrl'
  473. }).state('sale.productDetail', {
  474. url: "/prodList/:id",
  475. templateUrl: "static/tpl/index/baseInfo/productDetail.html",
  476. controller: 'ProductDetailCtrl'
  477. }).state('sale.productmatches', {
  478. url: "/productmatches",
  479. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  480. controller: 'ProductmatchesForSaleCtrl'
  481. }).state('sale.maketodo', {
  482. url: "/maketodo",
  483. templateUrl: "static/tpl/index/make/todo.html"
  484. }).state('sale.maketodo.order', {
  485. url: "/makeorder",
  486. templateUrl: "static/tpl/index/make/order.html",
  487. controller: 'MakeOrderCtrl'
  488. }).state('sale.makeorder', {
  489. url: "/makeorder",
  490. templateUrl: "static/tpl/index/make/order.html",
  491. controller: 'MakeOrderCtrl'
  492. }).state('sale.makeorder_detail', {
  493. url: "/makeorder/:id",
  494. templateUrl: "static/tpl/index/make/order_detail.html",
  495. controller: 'MakeOrderDetailCtrl'
  496. }).state('sale.badOut', {
  497. url: "/badOut",
  498. templateUrl: "static/tpl/index/qc/badOut.html",
  499. controller: 'SaleBadOutCtrl'
  500. }).state('sale.MRB', {
  501. url: "/MRB",
  502. templateUrl: "static/tpl/index/qc/MRB.html",
  503. controller: 'SaleMRBCtrl'
  504. }).state('sale.badIn', {
  505. url: "/badIn",
  506. templateUrl: "static/tpl/index/qc/badIn.html",
  507. controller: 'SaleBadInCtrl'
  508. }).state('sale.makeaccept', {
  509. url: "/makeaccept",
  510. templateUrl: "static/tpl/index/make/accept.html",
  511. controller: 'MakeAcceptCtrl'
  512. }).state('sale.makereturns', {
  513. url: "/makereturns",
  514. templateUrl: "static/tpl/index/make/returns.html",
  515. controller: 'MakeReturnCtrl'
  516. }).state('sale.makechange', {
  517. url: "/makechange",
  518. templateUrl: "static/tpl/index/make/change.html",
  519. controller: 'MakeChangeCtrl'
  520. }).state('sale.makechange_detail', {
  521. url: "/makechange/:id",
  522. templateUrl: "static/tpl/index/make/change_detail.html",
  523. controller: 'MakeChangeDetailCtrl'
  524. }).state('account', {
  525. url: "/account",
  526. views: {
  527. "left-view": {
  528. templateUrl: "static/tpl/index/account/left.html",
  529. controller: 'LeftCtrl'
  530. },
  531. "right-view": {
  532. templateUrl: "static/tpl/index/account/right.html"
  533. }
  534. }
  535. }).state('account.index', {
  536. url: "",
  537. templateUrl: "static/tpl/index/account/index.html",
  538. controller: 'RightCtrl'
  539. }).state('account.home', {
  540. url: "/",
  541. templateUrl: "static/tpl/index/account/index.html",
  542. controller: 'RightCtrl'
  543. }).state('baseInfo', {//基础资料
  544. url: "/baseInfo",
  545. views: {
  546. "left-view": {
  547. templateUrl: "static/tpl/index/common/leftAll.html"
  548. },
  549. "right-view": {
  550. templateUrl: "static/tpl/index/baseInfo/right.html"
  551. }
  552. }
  553. }).state('baseInfo.index', {
  554. url: "/enterpriseList",
  555. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  556. controller: 'EnterpriseListCtrl'
  557. }).state('baseInfo.home', {
  558. url: "/enterpriseList",
  559. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  560. controller: 'EnterpriseListCtrl'
  561. }).state('baseInfo.enterpriseList', {
  562. url: "/enterpriseList",
  563. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  564. controller: 'EnterpriseListCtrl'
  565. }).state('baseInfo.myClient', {
  566. url: "/myClient",
  567. templateUrl: "static/tpl/index/baseInfo/myClient.html",
  568. controller: 'MyClientCtrl'
  569. }).state('baseInfo.mySupplier', {
  570. url: "/mySupplier",
  571. templateUrl: "static/tpl/index/baseInfo/mySupplier.html",
  572. controller: 'MySupplierCtrl'
  573. }).state('baseInfo.myRequest', {
  574. url: "/myRequest",
  575. templateUrl: "static/tpl/index/baseInfo/myRequest.html",
  576. controller: 'AddPartnerRequestCtrl'
  577. }).state('baseInfo.newPartner', {
  578. url: "/newPartner",
  579. templateUrl: "static/tpl/index/baseInfo/newPartner.html",
  580. controller: 'NewPartnerCtrl'
  581. }).state('baseInfo.myMessage', {
  582. url: "/myMessage",
  583. templateUrl: "static/tpl/index/baseInfo/myMessage.html",
  584. controller: 'AddPartnerMessageCtrl'
  585. }).state('baseInfo.myPartners', {
  586. url: '/myPartners',
  587. templateUrl: "static/tpl/index/baseInfo/myPartners.html",
  588. controller: 'MyPartnersCtrl'
  589. }).state('baseInfo.businessGroups', {
  590. url: '/businessGroups',
  591. controller: 'BusinessGroupsCtrl'
  592. }).state('baseInfo.inquiryList', {
  593. url: '/inquiryList',
  594. templateUrl: "static/tpl/index/baseInfo/inquiry_list.html",
  595. controller: 'PublicInquiryListCtrl'
  596. }).state('baseInfo.inquiryListDetail', {
  597. url: '/inquiryList/:id',
  598. templateUrl: "static/tpl/index/baseInfo/inquiryItem_detail.html",
  599. controller: 'PublicInquiryListDetailCtrl'
  600. }).state('baseInfo.vendorInfo', {
  601. url: '/enume/vendorInfo',
  602. templateUrl: "static/tpl/index/baseInfo/vendorsInfo.html",
  603. controller: 'VendorsInfoCtrl'
  604. }).state('baseInfo.servicerInfo', {
  605. url: '/enume/servicerInfo',
  606. templateUrl: "static/tpl/index/baseInfo/servicerInfo.html",
  607. controller: 'ServicerInfoCtrl'
  608. }).state('baseInfo.customerInfo', {
  609. url: '/enume/customerInfo',
  610. templateUrl: "static/tpl/index/baseInfo/customersInfo.html",
  611. controller: 'CustomersInfoCtrl'
  612. }).state('baseInfo.enume', {
  613. url: '/enume',
  614. templateUrl: "static/tpl/index/baseInfo/vendorAndCustomer.html"
  615. }).state('baseInfo.partner', {
  616. url: '/partner',
  617. templateUrl: "static/tpl/index/baseInfo/addPartners.html",
  618. controller: 'AddPartnersCtrl'
  619. }).state('baseInfo.partner_searchresult', {
  620. url: '/search',
  621. templateUrl: "static/tpl/index/baseInfo/searchresult.html",
  622. controller: 'EnterpriseSearchCtrl'
  623. }).state('baseInfo.invitation', {
  624. url: '/invitation',
  625. templateUrl: "static/tpl/index/baseInfo/invitation.html",
  626. controller: 'InvitationCtrl'
  627. }).state('qc', {
  628. url: "/qc",
  629. views: {
  630. "left-view": {
  631. templateUrl: "static/tpl/index/qc/left.html"
  632. },
  633. "right-view": {
  634. templateUrl: "static/tpl/index/qc/right.html"
  635. }
  636. }
  637. }).state('qc.index', {
  638. url: "",
  639. templateUrl: "static/tpl/index/qc/index.html"
  640. }).state('qc.home', {
  641. url: "/",
  642. templateUrl: "static/tpl/index/qc/index.html"
  643. }).state('fa', {
  644. url: "/fa",
  645. views: {
  646. "left-view": {
  647. templateUrl: "static/tpl/index/common/leftAll.html"
  648. },
  649. "right-view": {
  650. templateUrl: "static/tpl/index/fa/right.html"
  651. }
  652. }
  653. }).state('fa.index', {
  654. url: "",
  655. templateUrl: "static/tpl/index/fa/index.html"
  656. }).state('fa.home', {
  657. url: "/",
  658. templateUrl: "static/tpl/index/fa/index.html"
  659. }).state('fa.apBill', {
  660. url: "/apBill",
  661. templateUrl: "static/tpl/index/fa/apBill.html",
  662. controller: 'SaleApBillCtrl'
  663. }).state('fa.apBill_detail', {
  664. url: "/apBill/:id",
  665. templateUrl: "static/tpl/index/fa/apBill_detail.html",
  666. controller: 'SaleApBillDetailCtrl'
  667. }).state('fa.arCheck', {
  668. url: "/arCheck",
  669. templateUrl: "static/tpl/index/fa/arCheck.html",
  670. controller: 'SaleArCheckCtrl'
  671. }).state('fa.arCheck_detail', {
  672. url: "/arCheck/:id",
  673. templateUrl: "static/tpl/index/fa/arCheck_detail.html",
  674. controller: 'SaleArCheckDetailCtrl'
  675. }).state('fa.apCheck', {
  676. url: "/apCheck",
  677. params: {
  678. 'id': null
  679. },
  680. templateUrl: "static/tpl/index/fa/apCheck.html",
  681. controller: 'PurchaseApCheckCtrl'
  682. }).state('fa.apCheck_detail', {
  683. url: "/apCheck/:id",
  684. templateUrl: "static/tpl/index/fa/apCheck_detail.html",
  685. controller: 'PurchaseApCheckDetailCtrl'
  686. }).state('fa.apCheckList', {
  687. url: "/apCheckList",
  688. templateUrl: "static/tpl/index/fa/apCheckList.html",
  689. controller: 'PurchaseApCheckListCtrl'
  690. }).state('fa.apBillOut', {
  691. url: "/apBillOut",
  692. params:{
  693. 'id':null
  694. },
  695. templateUrl: "static/tpl/index/fa/apBillOut.html",
  696. controller: 'PurchaseApBillOutCtrl'
  697. }).state('fa.apBillOut_detail', {
  698. url: "/apBillOut/:id",
  699. templateUrl: "static/tpl/index/fa/apBillOut_detail.html",
  700. controller: 'PurchaseApBillOutDetailCtrl'
  701. }).state('fa.apBillOutList', {
  702. url: "/apBillOutList",
  703. templateUrl: "static/tpl/index/fa/apBillOutList.html",
  704. controller: 'PurchaseApBillOutListCtrl'
  705. }).state('fa.adjustList', {
  706. url: "/adjustList",
  707. templateUrl: "static/tpl/index/fa/adjustList.html",
  708. controller: 'PurchaseAdjustListCtrl'
  709. }).state('make', {
  710. url: "/make",
  711. views: {
  712. "left-view": {
  713. templateUrl: "static/tpl/index/make/left.html"
  714. },
  715. "right-view": {
  716. templateUrl: "static/tpl/index/make/right.html"
  717. }
  718. }
  719. }).state('make.index', {
  720. url: "",
  721. templateUrl: "static/tpl/index/make/index.html"
  722. }).state('make.home', {
  723. url: "/",
  724. templateUrl: "static/tpl/index/make/index.html"
  725. }).state('cs', {// 客户服务
  726. url: "/cs",
  727. views: {
  728. "left-view": {
  729. templateUrl: "static/tpl/index/cs/left.html"
  730. },
  731. "right-view": {
  732. templateUrl: "static/tpl/index/cs/right.html"
  733. }
  734. }
  735. }).state('cs.index', {
  736. url: "",
  737. templateUrl: "static/tpl/index/cs/index.html"
  738. }).state('cs.home', {
  739. url: "/",
  740. templateUrl: "static/tpl/index/cs/index.html"
  741. }).state('search', { //顶部搜索
  742. url: "/search?keyword=",
  743. views: {
  744. "left-view": {
  745. templateUrl: "static/tpl/index/search/left.html"
  746. },
  747. "right-view": {
  748. templateUrl: "static/tpl/index/search/search_result.html",
  749. controller: 'TopSearchCtrl'
  750. }
  751. }
  752. }).state('approvalflow', { //审批流
  753. url: "/approvalFlow",
  754. views: {
  755. "left-view": {
  756. templateUrl: "static/tpl/index/common/leftAll.html"
  757. },
  758. "right-view": {
  759. templateUrl: "static/tpl/index/approvalFlow/right.html",
  760. }
  761. }
  762. }).state('approvalflow.flow', {
  763. url: "/flow",
  764. templateUrl: "static/tpl/index/approvalFlow/home.html",
  765. controller: 'approvalFlowCtrl'
  766. }).state('approvalflow.enterprise', {
  767. url: "/enterprise",
  768. templateUrl: "static/tpl/index/approvalFlow/enterprise.html",
  769. controller: 'EnterpriseCtrl'
  770. }).state('approvalflow.user', {
  771. url: "/user",
  772. templateUrl: "static/tpl/index/approvalFlow/user.html",
  773. controller: 'UserCtrl'
  774. }).state('approvalflow.log', {
  775. url: "/log",
  776. templateUrl: "static/tpl/index/approvalFlow/log.html",
  777. controller: 'LogCtrl'
  778. }).state('approvalflow.resource', {
  779. url: "/resource",
  780. templateUrl: "static/tpl/index/approvalFlow/resource.html",
  781. controller: 'ResourceCtrl'
  782. }).state('approvalflow.role', {
  783. url: "/role",
  784. templateUrl: "static/tpl/index/approvalFlow/role.html",
  785. controller: 'RoleCtrl'
  786. }).state('approvalflow.product', {
  787. url: "/product",
  788. templateUrl: "static/tpl/index/approvalFlow/prodList.html",
  789. controller: 'ProductAllCtrl'
  790. }).state('approvalflow.userProduct', {
  791. url: "/userProduct",
  792. templateUrl: "static/tpl/index/approvalFlow/userProduct.html",
  793. controller: 'UserProductCtrl'
  794. }).state('approvalflow.productmatches', {
  795. url: "/productmatches",
  796. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  797. controller: 'ProductmatchesCtrl'
  798. }).state('sale.vendorPerformanceAssess', {
  799. url: "/vendorPerformanceAssess",
  800. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess.html",
  801. controller: 'VendorPerformanceAssessCtrl'
  802. }).state('sale.vendorPerformanceAssess_detail', {
  803. url: "/vendorPerformanceAssess/:id",
  804. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess_detail.html",
  805. controller: 'VendorPerformanceAssessDetailCtrl'
  806. });
  807. $urlRouterProvider.otherwise('/index');
  808. }]);
  809. /**
  810. * 表示符号
  811. */
  812. app.factory('Symbol', function () {
  813. return {
  814. currency: function (cur) {
  815. if (cur == 'RMB') return '¥';
  816. else if (cur == 'USD') return '$';
  817. else if (cur == 'EUR') return '€';
  818. else if (cur == null || cur == '') return '¥';
  819. else return cur;
  820. }
  821. };
  822. }).factory('Lodop', function () {
  823. return {
  824. getLodop: function (oOBJECT, oEMBED) {
  825. var CreatedOKLodop7766 = null;
  826. /**************************
  827. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  828. IE系列、IE内核系列的浏览器采用oOBJECT,
  829. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  830. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  831. 64位浏览器指向64位的安装程序install_lodop64.exe。
  832. **************************/
  833. var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  834. var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  835. var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  836. var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  837. var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  838. var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  839. var LODOP;
  840. try {
  841. //=====判断浏览器类型:===============
  842. var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
  843. var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
  844. //=====如果页面有Lodop就直接使用,没有则新建:==========
  845. if (oOBJECT != undefined || oEMBED != undefined) {
  846. if (isIE)
  847. LODOP = oOBJECT;
  848. else
  849. LODOP = oEMBED;
  850. } else {
  851. if (CreatedOKLodop7766 == null) {
  852. LODOP = document.createElement("object");
  853. LODOP.setAttribute("width", 0);
  854. LODOP.setAttribute("height", 0);
  855. LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  856. if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  857. else LODOP.setAttribute("type", "application/x-print-lodop");
  858. document.documentElement.appendChild(LODOP);
  859. CreatedOKLodop7766 = LODOP;
  860. } else
  861. LODOP = CreatedOKLodop7766;
  862. }
  863. ;
  864. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  865. if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
  866. if (navigator.userAgent.indexOf('Chrome') >= 0)
  867. document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
  868. if (navigator.userAgent.indexOf('Firefox') >= 0)
  869. document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
  870. if (is64IE) document.write(strHtm64_Install); else if (isIE) document.write(strHtmInstall); else
  871. document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
  872. return LODOP;
  873. } else if (LODOP.VERSION < "6.1.9.8") {
  874. if (is64IE) document.write(strHtm64_Update); else if (isIE) document.write(strHtmUpdate); else
  875. document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
  876. return LODOP;
  877. }
  878. ;
  879. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  880. LODOP.SET_LICENSES("深圳市优软科技有限公司", "BBF53BD5AB0D522B3207D05CDE381F65", "", "");
  881. //============================================================
  882. return LODOP;
  883. } catch (err) {
  884. if (is64IE)
  885. document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML; else
  886. document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML;
  887. return LODOP;
  888. }
  889. ;
  890. }
  891. }
  892. });
  893. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', 'toaster', 'AccountEnterprise', function ($scope, $rootScope, $modal, toaster, AccountEnterprise) {
  894. $rootScope.$on('$locationChangeSuccess', function (evt, newUrl) {
  895. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  896. if (routeState.indexOf('/') > -1)
  897. routeState = routeState.substring(0, routeState.indexOf('/'));
  898. if (routeState.indexOf('.') > -1)
  899. routeState = routeState.substring(0, routeState.indexOf('.'));
  900. $scope.routeState = routeState || 'home';
  901. });
  902. $scope.search = function (keyword) {
  903. if (keyword != null && keyword != '') {
  904. $rootScope.searchKeyword = keyword;
  905. window.location.hash = '#/search?keyword=' + keyword;
  906. } else {
  907. $rootScope.searchKeyword = null;
  908. window.location.hash = '#/search';
  909. }
  910. };
  911. $scope.showMessage = function () {
  912. var modalInstance = $modal.open({
  913. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  914. controller: 'PagingReleaseCtrl'
  915. });
  916. };
  917. // 连接到询价
  918. $scope.linktoInquiry = function (active) {
  919. $rootScope.active = active;
  920. window.location.href = "#/sale/inquiry";
  921. }
  922. // 连接到招标
  923. $scope.linktoSaleTender = function (active) {
  924. $rootScope.active = active;
  925. window.location.href = "#/sale/tender";
  926. }
  927. // 链接到打样申请
  928. $scope.linktoSample = function (active) {
  929. $rootScope.active = active;
  930. window.location.href = "#/sale/sample";
  931. }
  932. // 链接到采购招标
  933. $scope.linktoPurcTender = function (active) {
  934. $rootScope.tenderActive = active;
  935. window.location.href = "#/purc/tender";
  936. }
  937. $scope.linktoPurcInquiry = function (active) {
  938. $rootScope.active = active;
  939. window.location.href = "#/purc/purchaseinquiry";
  940. }
  941. // 跳转到B2C
  942. $scope.b2cLink = function (url) {
  943. AccountEnterprise.getB2cUrl({}, function(data) {
  944. if (url == '/help/home') {
  945. window.open(data.url + url, '_target')
  946. } else {
  947. window.location.href = data.url + url;
  948. }
  949. });
  950. }
  951. }]);
  952. app.controller('AdController', ['$scope', '$modal', '$interval', function($scope, $modal, $interval) {
  953. // 广告操作
  954. $scope.count = 5;
  955. $scope.bannerShow = true;
  956. $scope.imgAnmiation = false;
  957. $scope.jingKongAnmiation = true;
  958. $scope.imgShow = true;
  959. $scope.Times = $interval(function () {
  960. $scope.count--;
  961. if ($scope.count <= 0) {
  962. $scope.count = 5;
  963. $scope.jingKongAnmiation = false;
  964. $interval.cancel($scope.Times);
  965. $scope.closeClick();
  966. }
  967. }, 1000);
  968. // 金控广告动画设置
  969. $scope.closeClick = function () {
  970. $scope.jingKongAnmiation = false;
  971. if ($scope.bannerShow === false) {
  972. $scope.imgAnmiation = false;
  973. $scope.imgShow = false;
  974. } else {
  975. $scope.bannerShow = false;
  976. $scope.imgAnmiation = true;
  977. }
  978. }
  979. }]);
  980. /**
  981. * 新消息提醒(调用公共服务接口) -2018-01-22 19:36:50
  982. * @author dongbw
  983. */
  984. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'PagingReleaseInfo',
  985. function ($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance, PagingReleaseInfo) {
  986. $scope.active = "todo";
  987. $scope.setActive = function (state) {
  988. if ($scope.active != state) {
  989. $scope.active = state;
  990. if ($scope.tableParams.page() == 1)
  991. $scope.tableParams.reload();
  992. else
  993. $scope.tableParams.page(1);
  994. }
  995. };
  996. /**
  997. * 页面状态按钮过滤
  998. */
  999. var getMessageState = function (active) {
  1000. var fn = 'get';
  1001. switch (active) {
  1002. case 'done':
  1003. fn = 'getDone';
  1004. break;
  1005. case 'todo':
  1006. fn = 'getTodo';
  1007. break;
  1008. }
  1009. return fn;
  1010. };
  1011. $scope.tableParams = new ngTableParams({
  1012. page: 1,
  1013. count: 5,
  1014. sorting: {
  1015. 'createTime': 'desc'
  1016. }
  1017. }, {
  1018. total: 0,
  1019. counts: [],
  1020. getData: function ($defer, params) {
  1021. $scope.loading = true;
  1022. var pageParams = params.url();
  1023. var realActive = {};
  1024. pageParams.searchFilter = { // 筛选条件
  1025. keyword: $scope.keyword
  1026. // fromDate: getDateTime($scope.condition.dateFrom),
  1027. // endDate: getDateTime($scope.condition.dateTo)
  1028. };
  1029. PagingRelease[getMessageState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1030. $scope.loading = false;
  1031. if (page) {
  1032. params.total(page.totalElements);
  1033. $defer.resolve(page.content);
  1034. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  1035. }
  1036. }, function (response) {
  1037. $scope.loading = false;
  1038. toaster.pop('error', '数据加载失败', response.data);
  1039. });
  1040. }
  1041. });
  1042. $scope.close = function () {
  1043. $modalInstance.close();
  1044. window.location.reload();
  1045. };
  1046. $scope.checks = {
  1047. checked: false
  1048. };// 全选框
  1049. $scope.checkAll = function () {
  1050. angular.forEach($scope.tableParams.data, function (message) {
  1051. message.checked = $scope.checks.checked;
  1052. });
  1053. };
  1054. // 单选
  1055. $scope.checkOne = function (vendor) {
  1056. vendor.checked = true;
  1057. var checked = true;
  1058. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  1059. if (!message.checked) {
  1060. checked = false;
  1061. }
  1062. });
  1063. $scope.checks.checked = checked;
  1064. };
  1065. // 单反选
  1066. $scope.unCheckOne = function (vendor) {
  1067. vendor.checked = false;
  1068. $scope.checks.checked = false;
  1069. };
  1070. /**
  1071. * 当前页标为已读
  1072. */
  1073. $scope.setRead = function () {
  1074. $scope.loading = true;
  1075. var messageIds = [];
  1076. angular.forEach($scope.tableParams.data, function(message) {
  1077. messageIds.push(message.id);
  1078. });
  1079. PagingRelease.setPageRead({}, messageIds, function (data) {
  1080. $scope.loading = false;
  1081. if (data.success) {
  1082. toaster.pop("success", "设置已读成功");
  1083. }
  1084. if (data.error) {
  1085. toaster.pop("error", "设置已读失败");
  1086. }
  1087. $scope.tableParams.page(1);
  1088. $scope.tableParams.reload();
  1089. });
  1090. };
  1091. // 点击内容连接之后,信息标为已读
  1092. $scope.setOneRead = function (id) {
  1093. $scope.loading = true;
  1094. $modalInstance.close();
  1095. PagingRelease.setMessageRead({id: id}, {}, function (data) {
  1096. $scope.loading = false;
  1097. }, function (response) {
  1098. $scope.loading = false;
  1099. toaster.pop('error', '提示', response.data);
  1100. });
  1101. };
  1102. // 搜索框回车
  1103. $scope.onSearch = function () {
  1104. $scope.tableParams.page(1);
  1105. $scope.tableParams.reload();
  1106. };
  1107. }]);
  1108. // 高亮显示关键词
  1109. app.filter('getkey', ['$sce', '$rootScope', function ($sce, $rootScope) {
  1110. var search = $rootScope.searchKeyword;
  1111. return function (content, search) {
  1112. content = encodeURI(content);
  1113. search = encodeURI(search);
  1114. var reg = new RegExp(search, 'gim');
  1115. var result = content.replace(reg, '<font color="red">$&</font>');
  1116. result = decodeURIComponent(result);
  1117. return $sce.trustAsHtml(result);
  1118. };
  1119. $rootScope.searchKeyword = null;// 清除缓存的关键字
  1120. }]);
  1121. /**
  1122. * 顶部搜索
  1123. */
  1124. 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) {
  1125. BaseService.scrollBackToTop();
  1126. $scope.active = 'all';
  1127. $scope.tip = $rootScope.searchKeyword;
  1128. // 企业搜索
  1129. var getService = function () {
  1130. return getAccountUserSpace;
  1131. };
  1132. $scope.tableParams = new ngTableParams({
  1133. page: 1,
  1134. count: 20,
  1135. sorting: {}
  1136. }, {
  1137. total: 0,
  1138. counts: [5, 10, 25, 50],
  1139. getData: function ($defer, params) {
  1140. $scope.loading = true;
  1141. var pageParams = params.url();
  1142. pageParams.keyword = $rootScope.searchKeyword;
  1143. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1144. $scope.loading = false;
  1145. if (page) {
  1146. $scope.total = page.totalElement;
  1147. params.total(page.totalElement);
  1148. $defer.resolve(page.content);
  1149. }
  1150. }, function (response) {
  1151. $scope.loading = false;
  1152. toaster.pop('error', '数据加载失败', response.data);
  1153. });
  1154. }
  1155. });
  1156. // 添加合作关系
  1157. $scope.addPartner = function (name, businessCode) {
  1158. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  1159. if (data.success) {
  1160. toaster.pop("success", '添加成功', data.success);
  1161. $scope.tableParams.reload();
  1162. }
  1163. if (data.error) {
  1164. toaster.pop("error", '添加失败', data.error);
  1165. }
  1166. }, function (response) {
  1167. toaster.pop('error', '失败', response.data);
  1168. });
  1169. }
  1170. // 物料搜索
  1171. var getProdService = function () {
  1172. return SearchProd;
  1173. };
  1174. $scope.prodTableParams = new ngTableParams({
  1175. page: 1,
  1176. count: 20,
  1177. sorting: {}
  1178. }, {
  1179. total: 0,
  1180. counts: [5, 10, 25, 50],
  1181. getData: function ($defer, params) {
  1182. $scope.loading = true;
  1183. var pageParams = params.url();
  1184. pageParams.keyword = $rootScope.searchKeyword;
  1185. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1186. $scope.loading = false;
  1187. if (page) {
  1188. $scope.prodtotal = page.totalElement;
  1189. params.total(page.totalElement);
  1190. $defer.resolve(page.content);
  1191. }
  1192. }, function (response) {
  1193. $scope.loading = false;
  1194. toaster.pop('error', '数据加载失败', response.data);
  1195. });
  1196. }
  1197. });
  1198. /**
  1199. * 向企业购买
  1200. */
  1201. $scope.PurcByEn = function (businessCode) {
  1202. $rootScope.businessCode = businessCode;
  1203. window.location.hash = "#/purc/addOrder";
  1204. }
  1205. /**
  1206. * 选中单个物料购买
  1207. * @param businessCode
  1208. * @param id
  1209. */
  1210. $scope.PurcByEnAndProd = function (businessCode, id) {
  1211. $rootScope.businessCode = businessCode;
  1212. $rootScope.prodId = id;
  1213. window.location.hash = "#/purc/addOrder";
  1214. }
  1215. /**
  1216. * 询价
  1217. */
  1218. $scope.PurcInquiry = function (businessCode, id) {
  1219. $rootScope.prodId = id;
  1220. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1221. }
  1222. /**
  1223. * 邀请注册商务平台
  1224. */
  1225. $scope.invite = function (name) {
  1226. var modalInstance = $modal.open({
  1227. animation: true,
  1228. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1229. controller: 'InviteCtrl',
  1230. resolve: {
  1231. enname: function () {
  1232. return name
  1233. }
  1234. }
  1235. });
  1236. modalInstance.result.then(function (data) {
  1237. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1238. if (data.success) {
  1239. toaster.pop('success', '提示', data.success);
  1240. }
  1241. if (data.error) {
  1242. toaster.pop('error', '提示', data.error);
  1243. }
  1244. }, function (response) {
  1245. toaster.pop('error', '提示', response.data);
  1246. });
  1247. });
  1248. }
  1249. /**
  1250. * 立即查看
  1251. */
  1252. $scope.view = function (name) {
  1253. $rootScope.vendName = name;
  1254. window.location.hash = "#/baseInfo/newPartner";
  1255. }
  1256. }]);
  1257. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', 'InvitationRecord', '$modal', function ($scope, toaster, $modalInstance, enname, InvitationRecord, $modal) {
  1258. $scope.enter = {
  1259. vendname: enname
  1260. };
  1261. $scope.save = function (enter) {
  1262. // 先检验是否已注册
  1263. InvitationRecord.enterpriseList({name: enter.vendname}, {}, function(data) {
  1264. $scope.existEn = data;
  1265. if ($scope.existEn.length == 0) {
  1266. $modalInstance.close(enter);
  1267. var modalInstance = $modal.open({
  1268. animation: true,
  1269. templateUrl: 'static/tpl/index/baseInfo/modal/QQshare_modal.html',
  1270. controller: 'QQShareCtrl',
  1271. });
  1272. } else {
  1273. $scope.enterprise = $scope.existEn[0];
  1274. }
  1275. });
  1276. }
  1277. $scope.viewDetail = function() {
  1278. $scope.exist = 1;
  1279. }
  1280. $scope.cancel = function () {
  1281. $modalInstance.dismiss();
  1282. }
  1283. $scope.closeDetail = function() {
  1284. $scope.exist = 0;
  1285. }
  1286. /**
  1287. * 添加合作伙伴
  1288. * @param enterprise
  1289. */
  1290. $scope.addPartner = function(en) {
  1291. InvitationRecord.addPart({inviteEnUU: $scope.enterprise.uu, inviteUserName: en.vendusername, inviteUserTel: en.vendusertel}, {}, function(data) {
  1292. if (data.success) {
  1293. toaster.pop('success', data.success);
  1294. $modalInstance.dismiss();
  1295. } else if (data.error) {
  1296. toaster.pop('error', data.error);
  1297. }
  1298. }, function(response) {
  1299. toaster.pop('error', response.data);
  1300. });
  1301. }
  1302. }]);
  1303. /**
  1304. * QQ分享
  1305. */
  1306. app.controller('QQShareCtrl', ['$scope', 'InvitationRecord', '$modalInstance', function($scope, InvitationRecord, $modalInstance) {
  1307. InvitationRecord.getInviteUrl({}, function(data) {
  1308. $scope.inviteUrl = data.url;
  1309. var p = {
  1310. url: $scope.inviteUrl, /*获取URL,可加上来自分享到QQ标识,方便统计*/
  1311. // desc: 'hejq', /*分享理由(风格应模拟用户对话),支持多分享语随机展现(使用|分隔)*/
  1312. // title: '', /*分享标题(可选)*/
  1313. // summary: '', /*分享摘要(可选)*/
  1314. // pics: '', /*分享图片(可选)*/
  1315. // flash: '', /*视频地址(可选)*/
  1316. // site: '', /*分享来源(可选) 如:QQ分享*/
  1317. // style: '201',
  1318. // width: 32,
  1319. // height: 32
  1320. };
  1321. var s = [];
  1322. for(var i in p){
  1323. s.push(i + '=' + encodeURIComponent(p[i]||''));
  1324. }
  1325. s.join('&');
  1326. $scope.QQshare = function() {
  1327. window.open("http://connect.qq.com/widget/shareqq/index.html?" + s)
  1328. }
  1329. });
  1330. $scope.close = function() {
  1331. $modalInstance.dismiss();
  1332. }
  1333. }]);
  1334. /**
  1335. * 再次邀请
  1336. */
  1337. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function ($scope, toaster, $modalInstance, id, InvitationRecord) {
  1338. var loadData = function (id) {
  1339. InvitationRecord.getRecordById({id: id}, {}, function (data) {
  1340. if (data.user !== null) {
  1341. data.user = {};
  1342. }
  1343. $scope.enter = data;
  1344. });
  1345. };
  1346. loadData(id);
  1347. $scope.save = function (enter) {
  1348. if (!enter.vendusertel && !enter.venduseremail) {
  1349. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1350. } else {
  1351. $modalInstance.close(enter);
  1352. }
  1353. };
  1354. $scope.cancel = function () {
  1355. $modalInstance.dismiss();
  1356. }
  1357. }]);
  1358. /**
  1359. * 邀请记录
  1360. */
  1361. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function ($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1362. BaseService.scrollBackToTop();
  1363. $scope.status = "invitation";
  1364. $scope.active = "invitation";
  1365. var getService = function () {
  1366. if ($scope.active === "invitation") {
  1367. return InvitationRecord.records;
  1368. } else if ($scope.active === "invitationTeam") {
  1369. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1370. }
  1371. };
  1372. $scope.setActive = function (state) {
  1373. if ($scope.active !== state) {
  1374. $scope.active = state;
  1375. if ($scope.tableParams.page() === 1)
  1376. $scope.tableParams.reload();
  1377. else
  1378. $scope.tableParams.page(1);
  1379. }
  1380. };
  1381. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1382. page: 1,
  1383. count: 20,
  1384. sorting: {}
  1385. }, {
  1386. total: 0,
  1387. counts: [],
  1388. getData: function ($defer, params) { // 获取数据的方法
  1389. $scope.loading = true;
  1390. var pageParams = params.url();
  1391. pageParams.keyword = $scope.keyword;
  1392. $scope.tip = $scope.keyword;
  1393. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  1394. $scope.loading = false;
  1395. if (page) {
  1396. params.total(page.totalElement);
  1397. $defer.resolve(page.content);
  1398. }
  1399. }, function (response) {
  1400. $scope.loading = false;
  1401. toaster.pop('error', '数据加载失败', response.data);
  1402. });
  1403. }
  1404. });
  1405. $scope.onSearch = function (keyword) {
  1406. $scope.tableParams.page(1);
  1407. $scope.tableParams.reload();
  1408. $scope.tip = keyword;
  1409. }
  1410. $scope.search = function (name) {
  1411. $modal.open({
  1412. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1413. controller: 'FuzzySearchCtrl',
  1414. resolve: {
  1415. name: function () {
  1416. return name
  1417. }
  1418. }
  1419. }).result.then(function (data) {
  1420. });
  1421. };
  1422. // 再次邀请
  1423. $scope.reInvite = function (id) {
  1424. var modalInstance = $modal.open({
  1425. animation: true,
  1426. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1427. controller: 'ReInviteCtrl',
  1428. resolve: {
  1429. id: function () {
  1430. return id
  1431. }
  1432. }
  1433. });
  1434. modalInstance.result.then(function (data) {
  1435. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1436. if (data.success) {
  1437. toaster.pop('success', '提示', data.success);
  1438. $scope.tableParams.reload();
  1439. }
  1440. if (data.error) {
  1441. toaster.pop('error', '提示', data.error);
  1442. }
  1443. }, function (response) {
  1444. toaster.pop('error', '提示', response.data);
  1445. });
  1446. });
  1447. }
  1448. }]);
  1449. /**
  1450. * 模糊查询相似的企业名称
  1451. */
  1452. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function ($scope, name, InvitationRecord, toaster, BaseService) {
  1453. $scope.name = name;
  1454. if ($scope.name != null) {
  1455. InvitationRecord.enterpriseList({name: $scope.name}, {}, function (data) {
  1456. $scope.enterprises = data;
  1457. }, function (response) {
  1458. toaster.pop('error', '提示', response.data);
  1459. });
  1460. }
  1461. }]);
  1462. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function ($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1463. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1464. AuthenticationService.getAuthentication().success(function (data) {
  1465. if (data.enterprises) {
  1466. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1467. if (data.enterprises.length > 1) {
  1468. var enSelect = [];
  1469. angular.forEach(data.enterprises, function (e) {
  1470. if (e.current)
  1471. data.enterprise = e;
  1472. else
  1473. enSelect.push(e);
  1474. });
  1475. data.enSelect = enSelect;
  1476. }
  1477. }
  1478. $scope.userInfo = data;
  1479. if (data == null || !data.userUU) {
  1480. $scope.isAuthed = false;
  1481. AuthenticationService.redirectSignin();
  1482. } else {
  1483. }
  1484. });
  1485. $scope.logout = function () {
  1486. $modal.open({
  1487. templateUrl: 'static/tpl/index/account/logout.html',
  1488. controller: 'LogOutCtrl'
  1489. }).result.then(function (s) {
  1490. if (s) {
  1491. AuthenticationService.logout();
  1492. }
  1493. });
  1494. };
  1495. // 打开登录模态框
  1496. $scope.signinModal = function() {
  1497. // 跳转账户中心
  1498. AuthenticationService.redirectSignin();
  1499. };
  1500. // 注册
  1501. $scope.registerModal = function() {
  1502. // 跳转账户中心
  1503. AuthenticationService.redirectRegister();
  1504. };
  1505. $scope.switchto = function (enUU) {// 切换企业
  1506. AuthenticationService.reSignin(enUU).success(function (response) {
  1507. console.log(response);
  1508. if (!response) $window.location.reload();
  1509. $.ajax({
  1510. url:response.url,
  1511. data:response.data,
  1512. type:"get",
  1513. cache:false,
  1514. dataType:"jsonp",
  1515. jsonp:"callback",
  1516. jsonpCallback:"successCallback",
  1517. success:function(data){
  1518. console.log(data);
  1519. $window.location.reload();
  1520. },
  1521. error:function(data){
  1522. console.log(data);
  1523. $window.location.reload();
  1524. }
  1525. });
  1526. });
  1527. };
  1528. $scope.addFavorite = function () {
  1529. var url = encodeURI(window.location.href);
  1530. try {
  1531. //ie浏览器收藏方式
  1532. window.external.addFavorite(url, "优软商务平台");
  1533. } catch (e) {
  1534. try {
  1535. //火狐浏览器收藏方式
  1536. window.sidebar.addPanel("优软商务平台", url);
  1537. } catch (e) {
  1538. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加," +
  1539. "或手动在浏览器里进行设置。");
  1540. }
  1541. }
  1542. };
  1543. }]);
  1544. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1545. $scope.close = function (confirm) {
  1546. $modalInstance.close(confirm);
  1547. };
  1548. }]);
  1549. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1550. $scope.image = {src: null};
  1551. // 图片上传成功之后
  1552. $scope.onUploadSuccess = function (data) {
  1553. var path = data.path;
  1554. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1555. $scope.$apply(function () {
  1556. $scope.image.src = data.path;
  1557. $scope.image.thumb = path;
  1558. });
  1559. };
  1560. $scope.close = function () {
  1561. $modalInstance.dismiss();
  1562. };
  1563. $scope.confirm = function () {
  1564. $modalInstance.close($scope.image);
  1565. $scope.imageUrl = null;
  1566. };
  1567. }]);
  1568. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', '$modal',
  1569. function ($scope, SnapshotService, BaseService, $rootScope, $modal) {
  1570. BaseService.scrollBackToTop();
  1571. SnapshotService.getTodo(function (data) {
  1572. $scope.todo = data;
  1573. });
  1574. var getUnread = function () {
  1575. SnapshotService.getUnread('all', function (data) {
  1576. $scope.unread = data;
  1577. });
  1578. };
  1579. getUnread();
  1580. //去除红点
  1581. $scope.setOrdersRead = function (type) {
  1582. switch (type){
  1583. case 'product':
  1584. $scope.unread.product = 0;
  1585. break;
  1586. case 'vendorPerformanceAssess':
  1587. $scope.unread.vendorPerformanceAssess = 0;
  1588. break;
  1589. case 'customer':
  1590. $scope.unread.customer = 0;
  1591. break;
  1592. case 'purcProduct':
  1593. $scope.unread.purcProduct = 0;
  1594. break;
  1595. case 'vendor':
  1596. $scope.unread.purcVendor = 0;
  1597. break;
  1598. }
  1599. };
  1600. $scope.setTenderActive = function (active) {
  1601. $rootScope.tenderActive = active;
  1602. window.location.hash = '#/purc/tender';
  1603. }
  1604. }]);
  1605. // header
  1606. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1607. SnapshotService.getMessage(function (data) {
  1608. $scope.message = data;
  1609. });
  1610. }]);
  1611. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function ($scope, $rootScope, $modal, SaleTruck) {
  1612. SaleTruck.query({}, function (data) {
  1613. $rootScope.truck = data;
  1614. $scope.truckCount = data ? data.length : 0;
  1615. });
  1616. $scope.$watch(function () {
  1617. return $rootScope.truck;
  1618. }, function (data) {
  1619. $scope.truckCount = data ? data.length : 0;
  1620. }, true);
  1621. $scope.clearAll = function () {
  1622. SaleTruck.remove({}, function () {
  1623. $rootScope.truck = [];
  1624. });
  1625. };
  1626. $scope.openTrack = function () {
  1627. $modal.open({
  1628. templateUrl: 'static/tpl/index/sale/track.html',
  1629. controller: 'TruckModalCtrl',
  1630. size: 'lg'
  1631. }).result.then(function (s) {
  1632. if (s) {
  1633. $scope.clearAll();
  1634. $rootScope.dataChanged = true;
  1635. }
  1636. });
  1637. };
  1638. }]);
  1639. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', 'token', function ($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout, token) {
  1640. $scope.loading = false;
  1641. $scope.saleSend = {sendItems: []};
  1642. SaleTruck.detail({}, function (data) {
  1643. // 按物料编号排序
  1644. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1645. });
  1646. $scope.remove = function (index, notice) {
  1647. SaleTruck.remove({noticeId: notice.id}, function (data) {
  1648. $rootScope.truck = data;
  1649. $scope.notices.splice(index, 1);
  1650. });
  1651. };
  1652. $scope.$watch(function () {
  1653. return $scope.notices;
  1654. }, function (data) {
  1655. var q = 0, t = 0;
  1656. if (data) {
  1657. angular.forEach(data, function (d) {
  1658. q += d.thisSendQty;
  1659. t += d.thisSendQty * d.orderItem.price;
  1660. });
  1661. }
  1662. $scope.totalQty = q;
  1663. $scope.total = t;
  1664. }, true);
  1665. $scope.cancel = function () {
  1666. $modalInstance.close();
  1667. };
  1668. $scope.lockstatus = false;
  1669. // 锁定时间按钮5秒
  1670. $scope.lockClick = function () {
  1671. $scope.lockstatus = true;
  1672. $timeout(function () {
  1673. $scope.lockstatus = false;
  1674. }, 5000);
  1675. }
  1676. var getToken = function() {
  1677. token.info({userType: 'salenotice'}, {}, function(data) {
  1678. $scope.token = data.token;
  1679. }, function(response) {
  1680. toaster.pop('error', '提示', response.data);
  1681. });
  1682. }
  1683. getToken();
  1684. $scope.send = function () {// 发货
  1685. $scope.loading = true;
  1686. if (!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1687. toaster.pop('error', '错误', '请输入送货单号');
  1688. $scope.loading = false;
  1689. return;
  1690. }
  1691. var currency = $scope.notices[0].orderItem.order.currency,
  1692. custUU = $scope.notices[0].enUU,
  1693. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1694. var num = 1;
  1695. for (var i in $scope.notices) {
  1696. var item = $scope.notices[i];
  1697. if (item.id) {
  1698. if (item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1699. valid = false;
  1700. break;
  1701. }
  1702. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++};
  1703. }
  1704. }
  1705. if (!valid) {
  1706. $scope.loading = false;
  1707. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  1708. } else {
  1709. var send = angular.extend(angular.copy($scope.saleSend), {
  1710. currency: currency,
  1711. custUU: custUU,
  1712. payments: payments,
  1713. sendItems: items
  1714. });
  1715. if($scope.token != null) {
  1716. PurcNotice.sendByBatch({token: $scope.token}, send, function (data) {
  1717. $scope.loading = false;
  1718. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1719. $modalInstance.close(true);
  1720. $state.go('sale.send_detail', {id: data.id});
  1721. }, function (response) {
  1722. $scope.loading = false;
  1723. toaster.pop('error', '错误', response.data);
  1724. });
  1725. }
  1726. }
  1727. $scope.setCheckedNoticeRead = function () {
  1728. var ids = [];
  1729. for (var i in $scope.notices) {
  1730. var item = $scope.notices[i];
  1731. if (item.id) {
  1732. ids.push(item.id);
  1733. }
  1734. }
  1735. PurcNotice.setRead({}, ids, function (message) {
  1736. });
  1737. }
  1738. };
  1739. }]);
  1740. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1741. SaleStat.cust({}, function (data) {
  1742. var p = [], q = [];
  1743. angular.forEach(data.month, function (d) {
  1744. p.push({
  1745. x: (d.enterprise.enShortname || d.enterprise.enName),
  1746. y: [(d.total || 0)],
  1747. tooltip: (d.total || 0)
  1748. });
  1749. });
  1750. angular.forEach(data.year, function (d) {
  1751. q.push({
  1752. x: (d.enterprise.enShortname || d.enterprise.enName),
  1753. y: [(d.total || 0)],
  1754. tooltip: (d.total || 0)
  1755. });
  1756. });
  1757. $scope.custCharts = {
  1758. month: {
  1759. chartType: 'pie',
  1760. datas: {
  1761. data: p
  1762. },
  1763. config: {
  1764. labels: false,
  1765. title: "客户月采购量排行榜",
  1766. legend: {
  1767. display: true,
  1768. position: 'right'
  1769. },
  1770. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1771. click: function (d) {
  1772. },
  1773. mouseover: function (d) {
  1774. },
  1775. mouseout: function (d) {
  1776. },
  1777. innerRadius: 0,
  1778. lineLegend: 'lineEnd'
  1779. }
  1780. },
  1781. year: {
  1782. chartType: 'pie',
  1783. datas: {
  1784. data: q
  1785. },
  1786. config: {
  1787. labels: false,
  1788. title: "客户年采购量排行榜",
  1789. legend: {
  1790. display: true,
  1791. position: 'right'
  1792. },
  1793. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1794. click: function (d) {
  1795. },
  1796. mouseover: function (d) {
  1797. },
  1798. mouseout: function (d) {
  1799. },
  1800. innerRadius: 0,
  1801. lineLegend: 'lineEnd'
  1802. }
  1803. }
  1804. };
  1805. });
  1806. SaleStat.seller({}, function (data) {
  1807. var p = [], q = [];
  1808. angular.forEach(data.month, function (d) {
  1809. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1810. });
  1811. angular.forEach(data.year, function (d) {
  1812. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1813. });
  1814. $scope.sellerCharts = {
  1815. month: {
  1816. chartType: 'pie',
  1817. datas: {
  1818. data: p
  1819. },
  1820. config: {
  1821. labels: false,
  1822. title: "业务员月销量排行榜",
  1823. legend: {
  1824. display: true,
  1825. position: 'right'
  1826. },
  1827. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1828. click: function (d) {
  1829. },
  1830. mouseover: function (d) {
  1831. },
  1832. mouseout: function (d) {
  1833. },
  1834. innerRadius: 0,
  1835. lineLegend: 'lineEnd'
  1836. }
  1837. },
  1838. year: {
  1839. chartType: 'pie',
  1840. datas: {
  1841. data: q
  1842. },
  1843. config: {
  1844. labels: false,
  1845. title: "业务员年销量排行榜",
  1846. legend: {
  1847. display: true,
  1848. position: 'right'
  1849. },
  1850. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1851. click: function (d) {
  1852. },
  1853. mouseover: function (d) {
  1854. },
  1855. mouseout: function (d) {
  1856. },
  1857. innerRadius: 0,
  1858. lineLegend: 'lineEnd'
  1859. }
  1860. }
  1861. };
  1862. });
  1863. }]);
  1864. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1865. SaleStat.get({}, function (data) {
  1866. var p = [], q = [], r = [];
  1867. angular.forEach(data.day, function (d) {
  1868. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1869. });
  1870. angular.forEach(data.month, function (d) {
  1871. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1872. });
  1873. angular.forEach(data.year, function (d) {
  1874. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1875. });
  1876. $scope.charts = {
  1877. day: {
  1878. chartType: "line",
  1879. datas: {
  1880. series: ['销售额'],
  1881. data: p
  1882. },
  1883. config: {
  1884. "labels": false,
  1885. "title": "销售额统计(近15日线)",
  1886. "legend": {
  1887. "display": true,
  1888. "position": "right"
  1889. },
  1890. colors: ['#4D9934'],
  1891. "innerRadius": 0,
  1892. "lineLegend": "lineEnd"
  1893. }
  1894. },
  1895. month: {
  1896. chartType: "line",
  1897. datas: {
  1898. series: ['销售额'],
  1899. data: q
  1900. },
  1901. config: {
  1902. "labels": false,
  1903. "title": "销售额统计(近12月线)",
  1904. "legend": {
  1905. "display": true,
  1906. "position": "right"
  1907. },
  1908. colors: ['#4D9934'],
  1909. "innerRadius": 0,
  1910. "lineLegend": "lineEnd"
  1911. }
  1912. },
  1913. year: {
  1914. chartType: "line",
  1915. datas: {
  1916. series: ['销售额'],
  1917. data: r
  1918. },
  1919. config: {
  1920. "labels": false,
  1921. "title": "销售额统计(近10年线)",
  1922. "legend": {
  1923. "display": true,
  1924. "position": "right"
  1925. },
  1926. colors: ['#4D9934'],
  1927. "innerRadius": 0,
  1928. "lineLegend": "lineEnd"
  1929. }
  1930. }
  1931. };
  1932. });
  1933. }]);
  1934. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', 'AuthenticationService', function ($scope, SnapshotService, AuthenticationService) {
  1935. AuthenticationService.getAuthentication().success(function (data) {
  1936. $scope.loading = false;
  1937. $scope.useruu = data.userUU;
  1938. SnapshotService.getNotice(7, $scope.useruu, function (data) { //5表示首页显示的公告条数
  1939. $scope.notices = data;
  1940. });
  1941. /**
  1942. * 设置单据阅读状态
  1943. * @param id
  1944. */
  1945. $scope.setReadStatus = function(id) {
  1946. SnapshotService.setNoticeStatusAfterRead(id, $scope.useruu);
  1947. }
  1948. /**
  1949. * 判断是否当天时间
  1950. * @param date
  1951. * @param time
  1952. * @returns {boolean}
  1953. */
  1954. $scope.isCurrentTime = function(date, time) {
  1955. var date1 = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
  1956. var date2 = new Date(time).getFullYear() + '-' + new Date(time).getMonth() + 1 + '-' + new Date(time).getDate();
  1957. return date1 == date2;
  1958. }
  1959. });
  1960. $scope.dateTime = new Date();
  1961. $scope.time = new Date().getTime();
  1962. /**
  1963. * 收起展开公告
  1964. */
  1965. $scope.show = false;
  1966. $scope.showGongGao = function () {
  1967. $scope.show = !$scope.show
  1968. }
  1969. }]);
  1970. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1971. SnapshotService.getOpenTender(5, function (data) {
  1972. $scope.openTenders = data;
  1973. var newDate = new Date();
  1974. newDate = newDate.getTime() - 3 * 24 * 60 * 60 * 1000;
  1975. angular.forEach($scope.openTenders, function (tender) {
  1976. if (tender.date - newDate > 0) {
  1977. tender.isNew = true;
  1978. } else {
  1979. tender.isNew = false;
  1980. }
  1981. });
  1982. });
  1983. $scope.dateTime = new Date();
  1984. }]);
  1985. app.controller('VendCountCtrl', ['$scope', 'VendorService', function ($scope, VendorService) {
  1986. VendorService.getCount(function (date) {
  1987. $scope.count = date;
  1988. });
  1989. }]);
  1990. // 客户
  1991. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  1992. BaseService.scrollBackToTop();
  1993. $scope.userInfoResult = true;
  1994. AuthenticationService.getAuthentication().success(function (data) {
  1995. $scope.loading = false;
  1996. $scope.thisUser = data;
  1997. });
  1998. // 获取当前用户分配客户的操作权限
  1999. CurrentRole.roles({}, function (data) {
  2000. // 存在权限或者user表sys字段为1时
  2001. $scope.enabled = data.count > 0 || $scope.thisUser.sys;
  2002. }, function (response) {
  2003. });
  2004. var getCustInfos = function (custuu) {
  2005. if (custuu) {
  2006. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  2007. $scope.custInfos = data;
  2008. var getPage = function (page, size) {
  2009. if ($scope.custInfos) {
  2010. var result = {};
  2011. result.totalCount = $scope.custInfos.length;
  2012. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  2013. if ($scope.custInfos.length % size == 0) {
  2014. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2015. } else {
  2016. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2017. }
  2018. result.first = page == 1;
  2019. result.last = page == result.totalPage;
  2020. result.page = page;
  2021. result.next = page - 0 + 1;
  2022. result.pre = page - 1;
  2023. return result;
  2024. }
  2025. }
  2026. $scope.userdata = getPage(1, 4);
  2027. $scope.first = function () {
  2028. $scope.userdata = getPage($scope.userdata.pre, 4);
  2029. }
  2030. $scope.last = function () {
  2031. $scope.userdata = getPage($scope.userdata.next, 4);
  2032. }
  2033. }, function (response) {
  2034. $scope.loading = false;
  2035. toaster.pop('error', '数据加载失败', response.data);
  2036. });
  2037. }
  2038. }
  2039. // 分配用户
  2040. $scope.addUserInfo = function (customer) {
  2041. // if (!$scope.enabled) {
  2042. // toaster.pop('error', '您没有为当前客户分配用户的权限!');
  2043. // return;
  2044. // }
  2045. // 获取当前用户在当前企业是否被转移权限
  2046. AccountUser.getEnTransfer ({custUU: customer.myEnterprise.uu}, function(data) {
  2047. customer.enTransfer = data.result;
  2048. //是管理员,或者被转移了权限时
  2049. if ($scope.enabled || customer.enTransfer) {
  2050. var modalInstance = $modal.open({
  2051. animation: true,
  2052. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2053. controller: 'AddUserInfoCtrl',
  2054. resolve: {
  2055. customer: function () {
  2056. return customer;
  2057. }
  2058. }
  2059. });
  2060. modalInstance.result.then(function (changed, checked) {
  2061. if (changed) {
  2062. if (checked)
  2063. $scope.newUser.roles = checked;
  2064. else
  2065. loadUsers();
  2066. }
  2067. $scope.customerParams.reload();
  2068. });
  2069. } else {
  2070. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  2071. }
  2072. });
  2073. };
  2074. // 转移权限
  2075. $scope.transferUserInfo = function (customer) {
  2076. customer.enDistribute = null;
  2077. // if (!$scope.enabled) {
  2078. // toaster.pop('error', '您没有转移当前客户权限的权限!');
  2079. // return;
  2080. // }
  2081. // 获取当前用户在当前企业是否被转移权限
  2082. AccountUser.getDistribute ({custUU: customer.myEnterprise.uu}, function(data) {
  2083. customer.enDistribute = data.result;
  2084. //是管理员,或者被分配时
  2085. if ($scope.enabled || customer.enDistribute) {
  2086. var modalInstance = $modal.open({
  2087. animation: true,
  2088. templateUrl: 'static/tpl/index/account/transfer_userInfo.html',
  2089. controller: 'TransferUserInfoCtrl',
  2090. resolve: {
  2091. customer: function () {
  2092. return customer;
  2093. }
  2094. }
  2095. });
  2096. modalInstance.result.then(function (changed, checked) {
  2097. if (changed) {
  2098. if (checked)
  2099. $scope.newUser.roles = checked;
  2100. else
  2101. loadUsers();
  2102. }
  2103. $scope.customerParams.reload();
  2104. });
  2105. } else {
  2106. toaster.pop('error', '您没有转移当前客户权限的权限!');
  2107. }
  2108. });
  2109. };
  2110. $scope.showUserInfo = function (customer, boo) {
  2111. $scope.custInfo = customer;
  2112. if (boo) {
  2113. getCustInfos(customer.myEnterprise.uu);
  2114. $scope.userInfoResult = true;
  2115. }
  2116. };
  2117. var getService = function () {
  2118. return VendorService;
  2119. };
  2120. $scope.customerParams = new ngTableParams({
  2121. page: 1,
  2122. count: 20
  2123. }, {
  2124. total: 0,
  2125. counts: [5, 10, 25, 50],
  2126. getData: function ($defer, params) {
  2127. $scope.loading = true;
  2128. var pageParams = params.url();
  2129. pageParams.keyword = $scope.keyword;
  2130. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  2131. $scope.loading = false;
  2132. if (page) {
  2133. params.total(page.totalElement);
  2134. $defer.resolve(page.content);
  2135. $scope.keywordXls = pageParams.keyword;
  2136. }
  2137. $scope.totalCount = page.totalElement;
  2138. }, function (response) {
  2139. $scope.loading = false;
  2140. toaster.pop('error', '数据加载失败', response.data);
  2141. });
  2142. }
  2143. });
  2144. //设置消息已读
  2145. var setOrdersRead = function () {
  2146. var sourceId = [];
  2147. Vendor.setRead({}, sourceId, function (message) {
  2148. });
  2149. };
  2150. setOrdersRead();
  2151. // 搜索框回车
  2152. $scope.onSearch = function (keyword) {
  2153. $scope.customerParams.page(1);
  2154. $scope.customerParams.reload();
  2155. $scope.tip = keyword;
  2156. };
  2157. // 查看详情
  2158. $scope.viewDetail = function (id) {
  2159. window.location.hash = "#/sale/customer/" + id;
  2160. }
  2161. // 导出客户资料列表
  2162. $scope.exportXls = function () {
  2163. VendorService.exportXls.get({}, {}, function (data) {
  2164. if (data.success){
  2165. window.location.href = 'vendor/customer/xls?keyword='+ ($scope.keywordXls || '');
  2166. }
  2167. }, function (response) {
  2168. toaster.pop('error', '数据加载失败', response.data);
  2169. });
  2170. }
  2171. }]);
  2172. // 客户详情
  2173. 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) {
  2174. BaseService.scrollBackToTop();
  2175. $scope.userInfoResult = true;
  2176. AuthenticationService.getAuthentication().success(function (data) {
  2177. $scope.loading = false;
  2178. $scope.thisUser = data;
  2179. });
  2180. $scope.vendorContacts = [];
  2181. var loadData = function () {
  2182. Vendor.getCustomerDetail({id: $stateParams.id}, {}, function (data) {
  2183. $scope.customer = data.myEnterprise;
  2184. $scope.customerInfo = data;
  2185. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function (data) {
  2186. $scope.Contacts = data;
  2187. });
  2188. // 查看已分配人员
  2189. VendorService.userInfo.query({uu: $scope.customer.uu}, null, function (data) {
  2190. $scope.custInfos = data;
  2191. var getPage = function (page, size) {
  2192. if ($scope.custInfos) {
  2193. var result = {};
  2194. result.totalCount = $scope.custInfos.length;
  2195. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  2196. if ($scope.custInfos.length % size == 0) {
  2197. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2198. } else {
  2199. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2200. }
  2201. result.first = page == 1;
  2202. result.last = page == result.totalPage;
  2203. result.page = page;
  2204. result.next = page - 0 + 1;
  2205. result.pre = page - 1;
  2206. return result;
  2207. }
  2208. }
  2209. $scope.userdata = getPage(1, 4);
  2210. $scope.first = function () {
  2211. $scope.userdata = getPage($scope.userdata.pre, 4);
  2212. }
  2213. $scope.last = function () {
  2214. $scope.userdata = getPage($scope.userdata.next, 4);
  2215. }
  2216. }, function (response) {
  2217. $scope.loading = false;
  2218. toaster.pop('error', '数据加载失败', response.data);
  2219. });
  2220. }, function (response) {
  2221. $scope.loading = false;
  2222. toaster.pop('error', '数据加载失败', response.data);
  2223. });
  2224. };
  2225. loadData();
  2226. // 新增客户联系人
  2227. $scope.addContact = function (uu) {
  2228. var modalInstance = $modal.open({
  2229. animation: true,
  2230. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2231. controller: 'AddContacCtrl',
  2232. resolve: {}
  2233. });
  2234. modalInstance.result.then(function (data) {
  2235. $scope.contact = data;
  2236. $scope.contact.myenuu = uu;
  2237. Vendor.saveCustContact({}, $scope.contact, function (data) {
  2238. toaster.pop('success', '提示', '联系人保存成功');
  2239. $scope.Contacts.push(data);
  2240. }, function (response) {
  2241. toaster.pop('error', '失败', response.data);
  2242. });
  2243. });
  2244. }
  2245. // 编辑客户联系人
  2246. $scope.edit = function (contact) {
  2247. var modalInstance = $modal.open({
  2248. animation: true,
  2249. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2250. controller: 'EditContacCtrl',
  2251. resolve: {
  2252. contact: function () {
  2253. return contact;
  2254. }
  2255. }
  2256. });
  2257. modalInstance.result.then(function (data) {
  2258. Vendor.saveContact({}, data, function (data) {
  2259. loadData();
  2260. toaster.pop('success', '提示', '联系人修改成功');
  2261. }, function (response) {
  2262. toaster.pop('error', '失败', response.data);
  2263. });
  2264. });
  2265. }
  2266. // 删除客户联系人
  2267. $scope.deleteById = function (id, index) {
  2268. $scope.Contacts.splice(index, 1);
  2269. Vendor.deleteContact({id: id}, {}, function (data) {
  2270. toaster.pop('success', '提示', '客户联系人删除成功');
  2271. loadData();
  2272. }, function (response) {
  2273. toaster.pop('error', '提示', response.data);
  2274. });
  2275. }
  2276. // 供应商物料信息
  2277. $scope.viewProdList = function (uu) {
  2278. $scope.uu = uu;
  2279. $scope.tableParams.page(1);
  2280. $scope.tableParams.reload();
  2281. };
  2282. // 搜索框回车
  2283. $scope.onSearch = function (keyword) {
  2284. $scope.keyword = keyword;
  2285. $scope.tableParams.page(1);
  2286. $scope.tableParams.reload();
  2287. };
  2288. // 供应商物料信息
  2289. $scope.tableParams = new ngTableParams({
  2290. page: 1,
  2291. count: 20
  2292. }, {
  2293. total: 0,
  2294. counts: [5, 10, 25, 50],
  2295. getData: function ($defer, params) {
  2296. $scope.loading = true;
  2297. var pageParams = params.url();
  2298. pageParams.custUU = $scope.uu;
  2299. pageParams.keyword = $scope.keyword;
  2300. $scope.tip = $scope.keyword;
  2301. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  2302. $scope.loading = false;
  2303. if (page) {
  2304. params.total(page.totalElement);
  2305. $scope.total = page.totalElement;
  2306. $defer.resolve(page.content);
  2307. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2308. }
  2309. }, function (response) {
  2310. $scope.loading = false;
  2311. toaster.pop('error', '数据加载失败', response.data);
  2312. });
  2313. }
  2314. });
  2315. $scope.addUserInfo = function () {
  2316. //TODO
  2317. if ($scope.thisUser.sys) {
  2318. var modalInstance = $modal.open({
  2319. animation: true,
  2320. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2321. controller: 'AddUserInfoCtrl',
  2322. resolve: {
  2323. customer: function () {
  2324. return $scope.customerInfo;
  2325. }
  2326. }
  2327. });
  2328. modalInstance.result.then(function (changed, checked) {
  2329. loadData();
  2330. if (changed) {
  2331. if (checked) {
  2332. $scope.newUser.roles = checked;
  2333. } else {
  2334. loadUsers();
  2335. }
  2336. }
  2337. });
  2338. } else {
  2339. toaster.pop('error', '您不是管理员,无权限分配用户!');
  2340. }
  2341. }
  2342. $scope.Quotation = function (uu, id) {
  2343. $rootScope.custuu = uu;
  2344. $rootScope.prodId = id;
  2345. window.location.hash = "#/sale/quotation/new";
  2346. }
  2347. }]);
  2348. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', 'AuthenticationService',
  2349. function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
  2350. AuthenticationService.getAuthentication().success(function (data) {
  2351. $scope.thisUser = data;
  2352. });
  2353. $scope.checkboxes = {
  2354. checked: false
  2355. };
  2356. $scope.loading = true;
  2357. $scope.distribute = [];
  2358. AccountUser.findUsers({uu: customer.myEnterprise.uu}, null, function (data) {
  2359. $scope.userinfos = data;
  2360. var distribute = [];
  2361. angular.forEach($scope.userinfos, function (user, index) {
  2362. if (user.distribute) {
  2363. distribute.push({num: index});
  2364. }
  2365. });
  2366. $scope.distribute = distribute;
  2367. $scope.havedone = angular.copy($scope.distribute);
  2368. $scope.loading = false;
  2369. });
  2370. var checkStatus = function (userinfos) {
  2371. var distribute = [];
  2372. angular.forEach(userinfos, function (user, index) {
  2373. if (user.distribute) {
  2374. distribute.push({num: index});
  2375. }
  2376. });
  2377. $scope.distribute = distribute;
  2378. $scope.isChanged = !angular.equals($scope.havedone, $scope.distribute);
  2379. };
  2380. $scope.isChanged = false;
  2381. $scope.isChangedAll = false;
  2382. $scope.changes = [];
  2383. // 点击勾选全部的复选框
  2384. $scope.checkAll = function () {
  2385. angular.forEach($scope.userinfos, function (item, index) {
  2386. item.distribute = $scope.checkboxes.checked;
  2387. });
  2388. checkStatus($scope.userinfos);
  2389. };
  2390. // 点击其中一个明细的复选框
  2391. $scope.checkOne = function () {
  2392. var result = true;
  2393. angular.forEach($scope.userinfos, function (item) {
  2394. if (item.distribute != true) {
  2395. result = false;
  2396. return;
  2397. }
  2398. });
  2399. $scope.checkboxes.checked = result;
  2400. checkStatus($scope.userinfos);
  2401. };
  2402. $scope.close = function (save) {
  2403. var chooseResult = [];
  2404. if (save) {
  2405. if (customer.myEnterprise.uu) {
  2406. angular.forEach($scope.userinfos, function (item, i) {
  2407. chooseResult.push(item);
  2408. });
  2409. if (chooseResult.length > 0) {
  2410. $scope.loading = true;
  2411. AccountUser.addUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2412. $scope.loading = false;
  2413. toaster.pop('success', '提示', '保存成功');
  2414. $modalInstance.close(false);
  2415. }, function (response) {
  2416. $scope.loading = false;
  2417. toaster.pop('error', '保存失败', response.data);
  2418. $modalInstance.close(false);
  2419. })
  2420. } else {
  2421. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2422. }
  2423. } else {
  2424. $modalInstance.close(true, $scope.checkboxes.checked);
  2425. }
  2426. } else {
  2427. $modalInstance.close(false);
  2428. }
  2429. };
  2430. }]);
  2431. // 转移权限
  2432. app.controller('TransferUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', 'AuthenticationService', function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
  2433. AuthenticationService.getAuthentication().success(function (data) {
  2434. $scope.loading = false;
  2435. $scope.thisUser = data;
  2436. });
  2437. $scope.checkboxes = {
  2438. checked: false
  2439. };
  2440. $scope.loading = true;
  2441. $scope.transfer = [];
  2442. AccountUser.findUsers({uu: customer.myEnterprise.uu}, {}, function (data) {
  2443. $scope.userinfos = data;
  2444. var transfer = [];
  2445. angular.forEach($scope.userinfos, function (user, index) {
  2446. // 当前用户是被管理员转移权限时,转移的是被管理员转移的权限。
  2447. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2448. $scope.thisUser.transfer = true;
  2449. }
  2450. });
  2451. angular.forEach($scope.userinfos, function (user, index) {
  2452. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2453. if (user.transfer) {
  2454. transfer.push({num: index});
  2455. user.checked = true;
  2456. }
  2457. } else {
  2458. if (user.distribute) {
  2459. transfer.push({num: index});
  2460. user.checked = true;
  2461. }
  2462. }
  2463. });
  2464. $scope.transfer = transfer;
  2465. $scope.havedone = angular.copy($scope.transfer);
  2466. $scope.loading = false;
  2467. });
  2468. var checkStatus = function (userinfos) {
  2469. var transfer = [];
  2470. angular.forEach(userinfos, function (user, index) {
  2471. if (user.transfer) {
  2472. transfer.push({num: index});
  2473. }
  2474. });
  2475. $scope.transfer = transfer;
  2476. $scope.isChanged = !angular.equals($scope.havedone, $scope.transfer);
  2477. };
  2478. $scope.isChanged = false;
  2479. $scope.isChangedAll = false;
  2480. $scope.changes = [];
  2481. // 点击其中一个明细的复选框
  2482. $scope.checkOne = function (user) {
  2483. $scope.changes = [];
  2484. if ($scope.thisUser.sys) { // 管理员操作
  2485. user.$checked = !user.$checked;
  2486. angular.forEach($scope.userinfos, function (userInfo) {
  2487. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2488. $scope.thisUser.transfer = true;
  2489. }
  2490. if (user.userUU !== userInfo.userUU) {
  2491. userInfo.transfer = false;
  2492. }
  2493. });
  2494. } else if ($scope.thisUser.transfer) { // 被管理员转移权限的非管理员操作
  2495. user.$checked = !user.$checked;
  2496. angular.forEach($scope.userinfos, function (userInfo) {
  2497. if (user.userUU !== userInfo.userUU) {
  2498. userInfo.transfer = false;
  2499. } else {
  2500. userInfo.transfer = true;
  2501. }
  2502. });
  2503. } else { // 被分配客户的用户
  2504. user.$checked = !user.$checked;
  2505. angular.forEach($scope.userinfos, function (userInfo) {
  2506. if (user.userUU !== userInfo.userUU) {
  2507. userInfo.transfer = false;
  2508. } else {
  2509. userInfo.transfer = true;
  2510. }
  2511. });
  2512. }
  2513. checkStatus($scope.userinfos);
  2514. };
  2515. $scope.close = function (save) {
  2516. var chooseResult = [];
  2517. if (save) {
  2518. if (customer.myEnterprise.uu) {
  2519. // 当前用户是管理员时
  2520. if ($scope.thisUser.sys) {
  2521. angular.forEach($scope.userinfos, function (item, i) {
  2522. chooseResult.push(item);
  2523. });
  2524. if (chooseResult.length > 0) {
  2525. $scope.loading = true;
  2526. AccountUser.transferUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2527. $scope.loading = false;
  2528. toaster.pop('success', '提示', '保存成功');
  2529. $modalInstance.close(false);
  2530. }, function (response) {
  2531. $scope.loading = false;
  2532. toaster.pop('error', '保存失败', response.data);
  2533. $modalInstance.close(false);
  2534. })
  2535. } else {
  2536. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2537. }
  2538. } else {
  2539. // 非管理员转移自己的权限时
  2540. angular.forEach($scope.userinfos, function (item, i) {
  2541. if (item.transfer && item.userUU !== $scope.thisUser.userUU) {
  2542. $scope.target = item;
  2543. }
  2544. });
  2545. if (!$scope.target) {
  2546. toaster.pop('error', '保存失败', "您未选择权限转移对象");
  2547. } else {
  2548. $scope.loading = true;
  2549. AccountUser.transferMyDistribute({custUU: customer.myEnterprise.uu, userUU: $scope.target.userUU}, {} ,function (data) {
  2550. $scope.loading = false;
  2551. toaster.pop('success', '提示', '保存成功');
  2552. $modalInstance.close(false);
  2553. }, function (response) {
  2554. $scope.loading = false;
  2555. toaster.pop('error', '保存失败', response.data);
  2556. $modalInstance.close(false);
  2557. });
  2558. }
  2559. }
  2560. } else {
  2561. $modalInstance.close(true, $scope.checkboxes.checked);
  2562. }
  2563. } else {
  2564. $modalInstance.close(false);
  2565. }
  2566. };
  2567. }]);
  2568. /**
  2569. * 页面状态按钮过滤
  2570. */
  2571. var getState = function (active) {
  2572. var fn = 'get';
  2573. switch (active) {
  2574. case 'done':
  2575. fn = 'getDone';
  2576. break;
  2577. case 'todo':
  2578. fn = 'getTodo';
  2579. break;
  2580. case 'end':
  2581. fn = 'getEnd';
  2582. break;
  2583. case 'waiting':
  2584. fn = 'getWaiting';
  2585. break;
  2586. case 'received':
  2587. fn = 'getReceived';
  2588. break;
  2589. case 'invalid':
  2590. fn = 'getInvalid';
  2591. break;
  2592. // 已采纳
  2593. case 'agreed':
  2594. fn = 'getAgreed';
  2595. break;
  2596. // 未采纳
  2597. case 'refused':
  2598. fn = 'getRefused';
  2599. break;
  2600. // 个人
  2601. case 'personal':
  2602. fn = 'getPersonal';
  2603. break;
  2604. // 集体
  2605. case 'teams':
  2606. fn = 'getTeams';
  2607. break;
  2608. // 非标准
  2609. case 'nonstandard':
  2610. fn = 'getNonstandard';
  2611. break;
  2612. // 标准
  2613. case 'standard':
  2614. fn = 'getStandard';
  2615. break;
  2616. // 变更单无需确认
  2617. case 'unread':
  2618. fn = 'getUnread';
  2619. break;
  2620. }
  2621. return fn;
  2622. };
  2623. /**
  2624. * 改变单据日期范围
  2625. */
  2626. var getDateCondition = function (zone, condition) {
  2627. var fromDate = new Date();
  2628. var toDate = new Date();
  2629. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  2630. fromDate.setHours(0, 0, 0, 0);
  2631. toDate.setHours(23, 59, 59, 999);
  2632. if (zone == -1) { // 自定义时间,什么都不做
  2633. } else if (zone == 1) {
  2634. fromDate.setMonth(fromDate.getMonth() - 1);
  2635. condition.dateFrom = fromDate;
  2636. condition.dateTo = toDate;
  2637. } else if (zone == 3) {
  2638. fromDate.setMonth(fromDate.getMonth() - 3);
  2639. condition.dateFrom = fromDate;
  2640. condition.dateTo = toDate;
  2641. } else if (zone == 6) {
  2642. fromDate.setMonth(fromDate.getMonth() - 6);
  2643. condition.dateFrom = fromDate;
  2644. condition.dateTo = toDate;
  2645. } else {
  2646. condition.dateFrom = null;
  2647. condition.dateTo = null;
  2648. }
  2649. };
  2650. /**
  2651. * 改变单据交货日期范围
  2652. */
  2653. var getDelveryCondition = function (zone, condition) {
  2654. var date = new Date();
  2655. if (zone == -1) {
  2656. condition.deliveryFrom = null;
  2657. condition.deliveryTo = null;
  2658. } else if (zone == 1) {
  2659. date.setMonth(date.getMonth() + 1);
  2660. condition.deliveryTo = date;
  2661. condition.deliveryFrom = new Date();
  2662. } else if (zone == 2) {
  2663. date.setMonth(date.getMonth() + 2);
  2664. condition.deliveryTo = date;
  2665. condition.deliveryFrom = new Date();
  2666. }
  2667. };
  2668. /**
  2669. * 将日期转化为整数日期
  2670. */
  2671. var getDateTime = function (date) {
  2672. if (angular.isDate(date)) {
  2673. return date.getTime();
  2674. } else {
  2675. return null;
  2676. }
  2677. };
  2678. /**
  2679. * 删除数组里某个特定的值
  2680. */
  2681. var removeByValue = function (arr, val) {
  2682. for(var i=0; i<arr.length; i++) {
  2683. if(arr[i] == val) {
  2684. arr.splice(i, 1);
  2685. break;
  2686. }
  2687. }
  2688. };
  2689. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrders', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope', 'PurchaseOrder', 'PurcOrdersInfo', 'PurcOrderItem', 'CurrentRole',
  2690. function ($scope, $filter, PurcOrders, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope, PurchaseOrder, PurcOrdersInfo, PurcOrderItem, CurrentRole) {
  2691. BaseService.scrollBackToTop();
  2692. // 获取当前用户是否为普通用户
  2693. CurrentRole.isUser({}, {}, function (data) {
  2694. $scope.isUser = data.isUser;
  2695. });
  2696. if ($rootScope.active) {
  2697. $scope.active = $rootScope.active;
  2698. $rootScope.active = null;
  2699. } else {
  2700. $scope.active = 'all';
  2701. }
  2702. $scope.dateZoneText = '不限';
  2703. $scope.deliveryZoneText = '不限';
  2704. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2705. /* 时间筛选初始化*/
  2706. var fromDate = new Date();
  2707. var toDate = new Date();
  2708. fromDate.setMonth(fromDate.getMonth() - 1);
  2709. fromDate.setHours(0, 0, 0, 0);
  2710. toDate.setHours(23, 59, 59, 999);
  2711. $scope.condition.dateFrom = fromDate;
  2712. $scope.condition.dateTo = toDate;
  2713. $scope.changeDateZone = function (zone) {
  2714. $scope.condition.dateZone = zone;
  2715. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2716. $scope.condition.$dateZoneOpen = false;
  2717. getDateCondition(zone, $scope.condition);
  2718. $scope.tableParams.page(1);
  2719. $scope.tableParams.reload();
  2720. };
  2721. $scope.changeDeliveryZone = function (zone) {
  2722. $scope.condition.deliveryZoneText = zone;
  2723. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2724. $scope.condition.$delievryZoneOpen = false;
  2725. getDelveryCondition(zone, $scope.condition);
  2726. $scope.tableParams.reload();
  2727. };
  2728. $scope.searchMethod = false;
  2729. var getService = function () {
  2730. return $scope.searchMethod ? PurcOrders : PurcOrdersInfo;
  2731. };
  2732. // 切换单据类型
  2733. $scope.setActive = function (state) {
  2734. if ($scope.active != state) {
  2735. $scope.active = state;
  2736. if ($scope.tableParams.page() == 1)
  2737. $scope.tableParams.reload();
  2738. else
  2739. $scope.tableParams.page(1);
  2740. }
  2741. };
  2742. var getPurcStatus = function (active) {
  2743. var fn = 'getPurcAll';
  2744. switch (active) {
  2745. case 'done':
  2746. fn = 'getPurcDone';
  2747. break;
  2748. case 'todo':
  2749. fn = 'getPurcTodo';
  2750. break;
  2751. case 'end':
  2752. fn = 'getPurcEnd';
  2753. break;
  2754. case 'waiting':
  2755. fn = 'getPurcWaiting';
  2756. break;
  2757. }
  2758. return fn;
  2759. };
  2760. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2761. page: 1,
  2762. count: 20,
  2763. sorting: {
  2764. display: 'desc',
  2765. date: 'desc'
  2766. }
  2767. }, {
  2768. total: 0,
  2769. counts: [5, 10, 15, 25, 50],
  2770. getData: function ($defer, params) {// 获取数据的方法
  2771. $scope.loading = true;
  2772. var pageParams = params.url();
  2773. pageParams.searchFilter = { // 筛选条件
  2774. keyword: $scope.keyword,
  2775. fromDate: getDateTime($scope.condition.dateFrom),
  2776. endDate: getDateTime($scope.condition.dateTo)
  2777. };
  2778. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2779. $scope.loading = false;
  2780. if (page) {
  2781. $defer.resolve(page.content);
  2782. $scope.total = page.totalElement;
  2783. params.total(page.totalElement);
  2784. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2785. }
  2786. }, function (response) {
  2787. $scope.loading = false;
  2788. toaster.pop('error', '数据加载失败', response.data);
  2789. });
  2790. }
  2791. });
  2792. //获得各分类未阅读数量
  2793. var getUnreadCount = function () {
  2794. PurcOrders.getUnreadCount(null, function (data) {
  2795. $scope.unread = data;
  2796. });
  2797. };
  2798. getUnreadCount();
  2799. //设置单据已读
  2800. $scope.setOrdersRead = function (id) {
  2801. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  2802. return;
  2803. }
  2804. PurcOrders.setRead({}, function () {
  2805. getUnreadCount();
  2806. });
  2807. };
  2808. //获取未读单据id
  2809. var getUnreadIds = function () {
  2810. PurcOrders.getUnreadIds({}, "", function (message) {
  2811. $scope.unreadCode = message.content;
  2812. });
  2813. };
  2814. getUnreadIds();
  2815. //判断单据是否未读
  2816. $scope.isUnread = function (id) {
  2817. for (var i in $scope.unreadCode) {
  2818. if (id == $scope.unreadCode[i]) {
  2819. return true;
  2820. }
  2821. }
  2822. };
  2823. $scope.getReply = function (item) {
  2824. if (!item.replies) {
  2825. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2826. item.replies = replies;
  2827. });
  2828. }
  2829. };
  2830. $scope.getOrderTotal = function (items) {
  2831. var sum = 0;
  2832. angular.forEach(items, function (item) {
  2833. sum += item.qty * item.price;
  2834. });
  2835. return sum;
  2836. };
  2837. // 需方 打印 采购单
  2838. $scope.custPrint = function (order) {
  2839. var newPage = window.open("about:blank");
  2840. PurcOrder.printPermission({}, function () {
  2841. PurcOrder.custPrintCount({id: order.id}, {});//增加打印此次
  2842. ReportService.print(order.enUU, 'PURCLIST_CUST', "where purc$orders.pu_id=" + order.id, newPage);
  2843. }, function (response) {
  2844. newPage.close();
  2845. toaster.pop('error', '打印失败', response.data);
  2846. });
  2847. };
  2848. $scope.openDatePicker = function ($event, item, openParam) {
  2849. $event.preventDefault();
  2850. $event.stopPropagation();
  2851. item[openParam] = !item[openParam];
  2852. };
  2853. $scope.openFilterDatePicker = function ($event, item, openParam) {
  2854. $event.preventDefault();
  2855. $event.stopPropagation();
  2856. item[openParam] = !item[openParam];
  2857. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  2858. $scope.tableParams.reload();
  2859. }
  2860. };
  2861. $scope.parseDate = function (dateStr) {
  2862. if (dateStr)
  2863. return Date.parse(dateStr, 'yyyy-MM-dd');
  2864. return new Date();
  2865. };
  2866. $scope.checkboxes = {
  2867. checked: false
  2868. };
  2869. // 点击勾选全部的复选框
  2870. $scope.checkAll = function () {
  2871. angular.forEach($scope.tableParams.data, function (item) {
  2872. item.$selected = $scope.checkboxes.checked;
  2873. });
  2874. };
  2875. // 点击其中一个明细的复选框
  2876. $scope.checkOne = function (order) {
  2877. var result = true;
  2878. angular.forEach($scope.tableParams.data, function (item) {
  2879. if (item.$selected != true) {
  2880. result = false;
  2881. return;
  2882. }
  2883. });
  2884. $scope.checkboxes.checked = result;
  2885. };
  2886. // 搜索框回车
  2887. $scope.onSearch = function (keyword) {
  2888. // 每次搜索重置获取数据方法
  2889. $scope.searchMethod = false;
  2890. if(keyword != null && keyword != '') {
  2891. $scope.searchMethod = true;
  2892. }
  2893. $scope.tableParams.page(1);
  2894. $scope.tableParams.reload();
  2895. $scope.tip = keyword;
  2896. };
  2897. // 选择查找日期
  2898. $scope.onDateCondition = function () {
  2899. $scope.tableParams.page(1);
  2900. $scope.tableParams.reload();
  2901. };
  2902. // 复制订单
  2903. $scope.copyorder = function (id) {
  2904. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  2905. if (data.id) {
  2906. toaster.pop('success', '提示', '单据复制成功');
  2907. window.location.hash = "#purc/cart/" + data.id;
  2908. }
  2909. }, function (response) {
  2910. toaster.pop('error', '提示', response.data);
  2911. });
  2912. }
  2913. // 导出
  2914. $scope.exportXls = function () {
  2915. PurcOrders.exportXls({}, {}, function (data) {
  2916. if (data.success){
  2917. window.location.href = 'sale/orders/purc/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  2918. }
  2919. }, function (response) {
  2920. toaster.pop('error', '数据加载失败', response.data);
  2921. });
  2922. }
  2923. }]);
  2924. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'PurcOrdersInfo', 'CurrentRole', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, PurcOrdersInfo, CurrentRole) {
  2925. // 获取当前用户是否为普通用户
  2926. CurrentRole.isUser({}, {}, function (data) {
  2927. $scope.isUser = data.isUser;
  2928. });
  2929. var loadData = function () {
  2930. $scope.loading = true;
  2931. PurcOrdersInfo.getAll({id: $stateParams.id},{}, function (data) {
  2932. $scope.order = data;
  2933. var sum = 0;
  2934. angular.forEach($scope.order.orderItems, function (item) {
  2935. sum += item.qty * item.price;
  2936. });
  2937. $scope.order.total = sum;
  2938. // if($scope.order.display == 1) {//未查看的设为已查看
  2939. // $scope.setDisplay('setRead', $scope.order.id);
  2940. // }
  2941. //$scope.loading = false;
  2942. }, function (response) {
  2943. toaster.pop('error', '提示', response.data);
  2944. });
  2945. };
  2946. loadData();
  2947. $scope.getReply = function (item) {
  2948. if (!item.replies) {
  2949. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2950. item.replies = replies;
  2951. });
  2952. }
  2953. };
  2954. $scope.openDatePicker = function ($event, item, openParam) {
  2955. $event.preventDefault();
  2956. $event.stopPropagation();
  2957. item[openParam] = !item[openParam];
  2958. };
  2959. $scope.onReplyClick = function (item, inverse) {
  2960. if (item.reply) {
  2961. if (!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2962. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2963. return;
  2964. }
  2965. var reply = angular.copy(item.reply);
  2966. if (reply.delivery) {
  2967. if (typeof reply.delivery == 'object')
  2968. reply.delivery = reply.delivery.getTime();
  2969. } else {
  2970. reply.delivery = item.delivery;
  2971. }
  2972. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2973. $scope.loading = true;
  2974. PurcOrderItem.reply({orderItemId: item.id}, reply, function () {
  2975. $scope.loading = false;
  2976. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  2977. loadData();
  2978. }, function (response) {
  2979. $scope.loading = false;
  2980. toaster.pop('error', '回复失败', response.data);
  2981. });
  2982. }
  2983. };
  2984. //设置为已查看
  2985. $scope.setDisplay = function (state, orderId) {
  2986. if (orderId) {//设置单个
  2987. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  2988. // $scope.tableParams.reload();
  2989. }, function () {
  2990. toaster.pop('error', '错误', "设置失败");
  2991. });
  2992. } else {//设置已勾选的
  2993. var str = null;
  2994. angular.forEach($scope.tableParams.data, function (order) {
  2995. if (order.$selected == true) {
  2996. if (str != null && str != '') str += ',';
  2997. str += order.id;
  2998. }
  2999. });
  3000. if (str != null && str != '') {
  3001. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3002. $scope.tableParams.reload();
  3003. }, function () {
  3004. toaster.pop('error', '错误', "设置失败");
  3005. });
  3006. }
  3007. }
  3008. };
  3009. }]);
  3010. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PagingRelease', 'SnapshotService', 'PurcOrderItemInfo', 'token', 'CurrentRole', '$timeout', '$modal', function ($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PagingRelease, SnapshotService, PurcOrderItemInfo, token, CurrentRole, $timeout, $modal) {
  3011. BaseService.scrollBackToTop();
  3012. // 判断是否为普通用户
  3013. CurrentRole.isUser({}, {}, function (data) {
  3014. $scope.isUser = data.isUser;
  3015. });
  3016. $scope.active = 'todo';
  3017. $scope.dateZoneText = '不限';
  3018. $scope.deliveryZoneText = '不限';
  3019. $scope.condition = {dateZone: 1, deliveryZone: -1};
  3020. /* 时间筛选初始化*/
  3021. var fromDate = new Date();
  3022. var toDate = new Date();
  3023. fromDate.setMonth(fromDate.getMonth() - 1);
  3024. fromDate.setHours(0, 0, 0, 0);
  3025. toDate.setHours(23, 59, 59, 999);
  3026. $scope.condition.dateFrom = fromDate;
  3027. $scope.condition.dateTo = toDate;
  3028. $scope.changeDateZone = function (zone) {
  3029. $scope.condition.dateZone = zone;
  3030. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3031. $scope.condition.$dateZoneOpen = false;
  3032. getDateCondition(zone, $scope.condition);
  3033. $scope.tableParams.page(1);
  3034. $scope.tableParams.reload();
  3035. };
  3036. $scope.changeDeliveryZone = function (zone) {
  3037. $scope.condition.deliveryZoneText = zone;
  3038. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  3039. $scope.condition.$delievryZoneOpen = false;
  3040. getDelveryCondition(zone, $scope.condition);
  3041. $scope.tableParams.reload();
  3042. };
  3043. $scope.nowdate = new Date();
  3044. // 切换单据类型
  3045. $scope.setActive = function (state) {
  3046. if ($scope.active != state) {
  3047. $scope.active = state;
  3048. if ($scope.tableParams.page() == 1)
  3049. $scope.tableParams.reload();
  3050. else
  3051. $scope.tableParams.page(1);
  3052. }
  3053. };
  3054. $scope.searchMethod = false;
  3055. // 切换数据来源(正常数据 or 历史数据)
  3056. var getService = function () {
  3057. return $scope.searchMethod ? PurcOrderItem : PurcOrderItemInfo;
  3058. };
  3059. $scope.tableParams = new ngTableParams({ // ng-Table参数
  3060. page: 1,
  3061. count: 20,
  3062. sorting: {
  3063. date: 'desc',
  3064. id: 'desc'
  3065. }
  3066. }, {
  3067. total: 0,
  3068. counts: [5, 10, 15, 25, 50],
  3069. getData: function ($defer, params) { // 获取数据的方法
  3070. $scope.loading = true;
  3071. var pageParams = params.url();
  3072. pageParams.searchFilter = { // 筛选条件
  3073. keyword: $scope.keyword,
  3074. fromDate: getDateTime($scope.condition.dateFrom),
  3075. endDate: getDateTime($scope.condition.dateTo)
  3076. };
  3077. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3078. $scope.loading = false;
  3079. if (page) {
  3080. $defer.resolve(page.content);
  3081. params.total(page.totalElement);
  3082. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  3083. }
  3084. }, function (response) {
  3085. $scope.loading = false;
  3086. toaster.pop('error', '数据加载失败', response.data);
  3087. });
  3088. }
  3089. });
  3090. //获得各分类未阅读数量
  3091. var getUnreadCount = function () {
  3092. PurcOrderItem.getUnreadCount(null, function (data) {
  3093. $scope.unread = data;
  3094. });
  3095. };
  3096. getUnreadCount();
  3097. //设置单据已读
  3098. $scope.setOrdersRead = function (id) {
  3099. // 如果单据本身已读,则不发送请求修改数据
  3100. if (!$scope.isUnread(id)){
  3101. return;
  3102. }
  3103. var sourceId = [];
  3104. sourceId.push(id);
  3105. PurcOrderItem.setRead({}, sourceId, function (message) {
  3106. getUnreadCount();
  3107. });
  3108. };
  3109. //批量设置单据已读
  3110. $scope.setOrdersReadByBatch = function () {
  3111. var sourceId = [];
  3112. angular.forEach($scope.tableParams.data, function (order) {
  3113. if (order.$selected == true) {
  3114. sourceId.push(order.id);
  3115. }
  3116. });
  3117. PurcOrderItem.setRead({}, sourceId, function (message) {
  3118. getUnreadCount();
  3119. });
  3120. };
  3121. $scope.setOrdersReadByState = function () {
  3122. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3123. return;
  3124. }
  3125. PurcOrderItem.setReadByState({}, function () {
  3126. getUnreadIds();
  3127. getUnreadCount();
  3128. });
  3129. };
  3130. var getUnreadIds = function () {
  3131. PurcOrderItem.getUnreadIds({}, "", function (message) {
  3132. $scope.unreadCode = message.content;
  3133. });
  3134. };
  3135. getUnreadIds();
  3136. $scope.isUnread = function (id) {
  3137. for (var i in $scope.unreadCode) {
  3138. if (id == $scope.unreadCode[i]) {
  3139. return true;
  3140. }
  3141. }
  3142. };
  3143. $scope.getOrderTotal = function (items) {
  3144. var sum = 0;
  3145. angular.forEach(items, function (item) {
  3146. sum += item.qty * item.price;
  3147. });
  3148. return sum;
  3149. };
  3150. $scope.openDatePicker = function ($event, item, openParam) {
  3151. $event.preventDefault();
  3152. $event.stopPropagation();
  3153. item[openParam] = !item[openParam];
  3154. };
  3155. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3156. $event.preventDefault();
  3157. $event.stopPropagation();
  3158. item[openParam] = !item[openParam];
  3159. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3160. $scope.tableParams.reload();
  3161. }
  3162. };
  3163. $scope.parseDate = function (dateStr) {
  3164. if (dateStr)
  3165. return Date.parse(dateStr, 'yyyy-MM-dd');
  3166. return new Date();
  3167. };
  3168. // 获取token信息
  3169. $scope.getToken = function() {
  3170. token.info({userType: 'sale'}, {}, function(data) {
  3171. $scope.token = data.token;
  3172. }, function(response) {
  3173. toaster.pop('error', '提示', response.data);
  3174. });
  3175. }
  3176. $scope.onReplyClick = function (item, inverse) {
  3177. if (item.reply) {
  3178. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3179. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3180. return;
  3181. }
  3182. var reply = angular.copy(item.reply);
  3183. if (reply.delivery) {
  3184. if (typeof reply.delivery == 'object')
  3185. reply.delivery = reply.delivery.getTime();
  3186. } else {
  3187. reply.delivery = item.delivery;
  3188. }
  3189. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3190. $scope.loading = true;
  3191. if($scope.token != null) {
  3192. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3193. $scope.loading = false;
  3194. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3195. $scope.tableParams.reload();
  3196. }, function (response) {
  3197. $scope.loading = false;
  3198. toaster.pop('error', '回复失败', response.data);
  3199. });
  3200. }
  3201. }
  3202. };
  3203. //打印 采购单
  3204. $scope.print = function (order) {
  3205. var newPage = window.open("about:blank");
  3206. PurcOrder.printPermission({}, function () {
  3207. PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
  3208. if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  3209. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
  3210. $scope.tableParams.reload();
  3211. },function (response) {
  3212. newPage.close();
  3213. toaster.pop('error', '打印失败', response.data);
  3214. });
  3215. };
  3216. $scope.getReply = function (item) {
  3217. if (!item.replies) {
  3218. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3219. item.replies = replies;
  3220. });
  3221. }
  3222. };
  3223. $scope.checkboxes = {
  3224. checked: false
  3225. };
  3226. // 点击勾选全部的复选框
  3227. $scope.checkAll = function () {
  3228. angular.forEach($scope.tableParams.data, function (item) {
  3229. item.$selected = $scope.checkboxes.checked;
  3230. });
  3231. };
  3232. // 点击其中一个明细的复选框
  3233. $scope.checkOne = function (order) {
  3234. var result = true;
  3235. angular.forEach($scope.tableParams.data, function (item) {
  3236. if (item.$selected != true) {
  3237. result = false;
  3238. return;
  3239. }
  3240. });
  3241. $scope.checkboxes.checked = result;
  3242. };
  3243. //批量回复采购订单
  3244. $scope.replyByBatch = function () {
  3245. $scope.loading = true;
  3246. var str = '';
  3247. angular.forEach($scope.tableParams.data, function (order) {
  3248. if (order.$selected == true) {
  3249. str += order.id;
  3250. str += ',';
  3251. }
  3252. });
  3253. if (!(str == '')) {
  3254. $scope.loading = false;
  3255. str = str.substr(0, str.length - 1);
  3256. var modalInstance = $modal.open({
  3257. animation: true,
  3258. templateUrl: 'static/tpl/index/sale/modal/reply_bybatch.html',
  3259. controller: 'ReplyByBatchCtrl',
  3260. resolve: {}
  3261. });
  3262. modalInstance.result.then(function(data) {
  3263. $scope.loading = true;
  3264. var reply = data;
  3265. var date = null;
  3266. if (reply.date && reply.method == 1) {
  3267. date = reply.date.getTime();
  3268. }
  3269. PurcOrderItem.replyByBatch({date: date}, str, function () {
  3270. $scope.loading = false;
  3271. $scope.tableParams.reload();
  3272. toaster.pop('success', '提示', '批量回复成功');
  3273. }, function (response) {
  3274. $scope.loading = false;
  3275. toaster.pop('error', '提示', '批量回复失败');
  3276. });
  3277. });
  3278. } else {//没有勾选其中的明细
  3279. toaster.pop('error', '提示', '请先选择需要回复的单据');
  3280. $scope.loading = false;
  3281. }
  3282. };
  3283. // 搜索框回车
  3284. $scope.onSearch = function (keyword) {
  3285. // 每次搜索重置获取数据方法
  3286. $scope.searchMethod = false;
  3287. if(keyword != null && keyword != '') {
  3288. $scope.searchMethod = true;
  3289. }
  3290. $scope.tableParams.page(1);
  3291. $scope.tableParams.reload();
  3292. };
  3293. // 选择查找日期
  3294. $scope.onDateCondition = function () {
  3295. $scope.tableParams.page(1);
  3296. $scope.tableParams.reload();
  3297. };
  3298. //设置为已查看
  3299. $scope.setDisplay = function (state, orderId) {
  3300. if (orderId) {//设置单个
  3301. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3302. $scope.tableParams.reload();
  3303. }, function () {
  3304. toaster.pop('error', '错误', "设置失败");
  3305. });
  3306. } else {//设置已勾选的
  3307. var str = null;
  3308. angular.forEach($scope.tableParams.data, function (order) {
  3309. if (order.$selected == true) {
  3310. if (str != null && str != '') str += ',';
  3311. str += order.id;
  3312. }
  3313. });
  3314. if (str != null && str != '') {
  3315. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3316. $scope.tableParams.reload();
  3317. }, function () {
  3318. toaster.pop('error', '错误', "设置失败");
  3319. });
  3320. }
  3321. }
  3322. };
  3323. // 导出
  3324. $scope.exportXls = function () {
  3325. PurcOrderItem.exportXls({}, {}, function (data) {
  3326. if (data.success){
  3327. window.location.href = 'sale/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3328. }
  3329. }, function (response) {
  3330. toaster.pop('error', '数据加载失败', response.data);
  3331. });
  3332. }
  3333. }]);
  3334. /**
  3335. * 批量回复模态框
  3336. */
  3337. app.controller('ReplyByBatchCtrl', ['$scope', '$modalInstance', '$filter', 'toaster', function($scope, $modalInstance, $filter, toaster) {
  3338. $scope.activeTab = 'custom';
  3339. $scope.reply = {
  3340. method: 1
  3341. };
  3342. $scope.getMinDate = function () {
  3343. return $filter('date')(new Date, 'yyyy-MM-dd');
  3344. };
  3345. $scope.openDatePicker = function ($event, openParam) {
  3346. $event.preventDefault();
  3347. $event.stopPropagation();
  3348. $scope.$dateOpen = !openParam;
  3349. };
  3350. // 取消
  3351. $scope.cancel = function () {
  3352. $modalInstance.dismiss();
  3353. }
  3354. // 提交
  3355. $scope.submit = function () {
  3356. if ($scope.reply.method == 0) {
  3357. $modalInstance.close($scope.reply);
  3358. } else if ($scope.reply.method == 1) {
  3359. if (angular.isUndefined($scope.reply.date)) {
  3360. toaster.pop('error', '提示', '请先选择日期')
  3361. } else {
  3362. $modalInstance.close($scope.reply);
  3363. }
  3364. }
  3365. }
  3366. }]);
  3367. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token', 'file', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token, file) {
  3368. // 获取当前用户是否为普通用户
  3369. CurrentRole.isUser({}, {}, function (data) {
  3370. $scope.isUser = data.isUser;
  3371. });
  3372. var existFile = false;
  3373. var loadData = function () {
  3374. PurcOrder.get({id: $stateParams.id}, function (data) {
  3375. $scope.order = data;
  3376. var sum = 0;
  3377. angular.forEach($scope.order.orderItems, function (item) {
  3378. sum += item.qty * item.price;
  3379. if (item.attachs.length > 0) {
  3380. existFile = true;
  3381. }
  3382. });
  3383. $scope.order.total = sum;
  3384. if ($scope.order.display == 1) {//未查看的设为已查看
  3385. $scope.setDisplay('setRead', $scope.order.id);
  3386. }
  3387. $scope.loading = false;
  3388. }, function (response) {
  3389. toaster.pop('error', '', response.data);
  3390. });
  3391. };
  3392. loadData();
  3393. $scope.getReply = function (item) {
  3394. if (!item.replies) {
  3395. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3396. item.replies = replies;
  3397. });
  3398. }
  3399. };
  3400. $scope.openDatePicker = function ($event, item, openParam) {
  3401. $event.preventDefault();
  3402. $event.stopPropagation();
  3403. item[openParam] = !item[openParam];
  3404. };
  3405. // 获取token信息
  3406. var getToken = function() {
  3407. token.info({userType: 'sale'}, {}, function(data) {
  3408. $scope.token = data.token;
  3409. }, function(response) {
  3410. toaster.pop('error', '提示', response.data);
  3411. });
  3412. };
  3413. getToken();
  3414. $scope.onReplyClick = function (item, inverse) {
  3415. if (item.reply) {
  3416. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3417. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3418. return;
  3419. }
  3420. var reply = angular.copy(item.reply);
  3421. if (reply.delivery) {
  3422. if (typeof reply.delivery == 'object')
  3423. reply.delivery = reply.delivery.getTime();
  3424. } else {
  3425. reply.delivery = item.delivery;
  3426. }
  3427. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3428. $scope.loading = true;
  3429. if($scope.token != null) {
  3430. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3431. $scope.loading = false;
  3432. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3433. $scope.tableParams.reload();
  3434. }, function (response) {
  3435. $scope.loading = false;
  3436. toaster.pop('error', '回复失败', response.data);
  3437. });
  3438. }
  3439. }
  3440. };
  3441. // 采购单
  3442. $scope.print = function (order) {
  3443. var newPage = window.open("about:blank");
  3444. PurcOrder.printPermission({}, function () {
  3445. PurcOrder.printCount({id: order.id}, {});//增加打印此次
  3446. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id, newPage);
  3447. },function (response) {
  3448. newPage.close();
  3449. toaster.pop('error', '打印失败', response.data);
  3450. });
  3451. };
  3452. //设置为已查看
  3453. $scope.setDisplay = function (state, orderId) {
  3454. if (orderId) {//设置单个
  3455. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3456. $scope.tableParams.reload();
  3457. }, function () {
  3458. toaster.pop('error', '错误', "设置失败");
  3459. });
  3460. } else {//设置已勾选的
  3461. var str = null;
  3462. angular.forEach($scope.tableParams.data, function (order) {
  3463. if (order.$selected == true) {
  3464. if (str != null && str != '') str += ',';
  3465. str += order.id;
  3466. }
  3467. });
  3468. if (str != null && str != '') {
  3469. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3470. $scope.tableParams.reload();
  3471. }, function () {
  3472. toaster.pop('error', '错误', "设置失败");
  3473. });
  3474. }
  3475. }
  3476. };
  3477. // 下载附件
  3478. $scope.fileDownload = function (id) {
  3479. if (!existFile) {
  3480. toaster.pop('error', '提示', "当前采购单不存在附件信息");
  3481. } else {
  3482. window.open("file/batch/" + id);
  3483. }
  3484. }
  3485. }]);
  3486. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, CurrentRole) {
  3487. BaseService.scrollBackToTop();
  3488. // 获取当前用户是否为普通用户
  3489. CurrentRole.isUser({}, {}, function (data) {
  3490. $scope.isUser = data.isUser;
  3491. });
  3492. $scope.active = 'todo';
  3493. $scope.agreedText = '全部';
  3494. $scope.dateZoneText = '一个月内';
  3495. $scope.condition = {dateZone: 1};
  3496. /* 时间筛选初始化*/
  3497. var fromDate = new Date();
  3498. var toDate = new Date();
  3499. fromDate.setMonth(fromDate.getMonth() - 1);
  3500. fromDate.setHours(0, 0, 0, 0);
  3501. toDate.setHours(23, 59, 59, 999);
  3502. $scope.condition.dateFrom = fromDate;
  3503. $scope.condition.dateTo = toDate;
  3504. $scope.changeAgreed = function (agreed) {
  3505. $scope.condition.agreed = agreed;
  3506. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3507. $scope.condition.$agreedOpen = false;
  3508. };
  3509. $scope.changeDateZone = function (zone) {
  3510. $scope.condition.dateZone = zone;
  3511. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3512. $scope.condition.$dateZoneOpen = false;
  3513. getDateCondition(zone, $scope.condition);
  3514. $scope.tableParams.page(1);
  3515. $scope.tableParams.reload();
  3516. };
  3517. $scope.setActive = function (state) {
  3518. if ($scope.active != state) {
  3519. $scope.active = state;
  3520. if ($scope.tableParams.page() == 1)
  3521. $scope.tableParams.reload();
  3522. else
  3523. $scope.tableParams.page(1);
  3524. }
  3525. };
  3526. $scope.searchMethod = false;
  3527. var getService = function () {
  3528. return $scope.searchMethod ? PurcChange : PurcChanges;
  3529. };
  3530. $scope.tableParams = new ngTableParams({
  3531. page: 1,
  3532. count: 20,
  3533. sorting: {
  3534. date: 'desc'
  3535. }
  3536. }, {
  3537. total: 0,
  3538. counts: [5, 10, 25, 50],
  3539. getData: function ($defer, params) {
  3540. $scope.loading = true;
  3541. var pageParams = params.url();
  3542. pageParams.searchFilter = {
  3543. keyword: $scope.keyword,
  3544. fromDate: getDateTime($scope.condition.dateFrom),
  3545. endDate: getDateTime($scope.condition.dateTo)
  3546. };
  3547. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3548. $scope.loading = false;
  3549. if (page) {
  3550. params.total(page.totalElement);
  3551. $defer.resolve(page.content);
  3552. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3553. }
  3554. }, function (response) {
  3555. $scope.loading = false;
  3556. toaster.pop('error', '数据加载失败', response.data);
  3557. });
  3558. }
  3559. });
  3560. //获得各分类未阅读数量
  3561. var getUnreadCount = function () {
  3562. PurcChange.getUnreadCount(null, function(data){
  3563. $scope.unread = data;
  3564. });
  3565. };
  3566. getUnreadCount();
  3567. //设置单据已读
  3568. $scope.setOrdersRead = function (id) {
  3569. // 如果单据本身已读,则不发送请求修改数据
  3570. if (!$scope.isUnread(id)){
  3571. return;
  3572. }
  3573. var sourceId = [];
  3574. sourceId.push(id);
  3575. PurcChange.setRead({}, sourceId, function (message) {
  3576. // $scope.getUnreadIds();
  3577. getUnreadCount();
  3578. });
  3579. };
  3580. $scope.setOrdersReadByState = function () {
  3581. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3582. return;
  3583. }
  3584. PurcChange.setReadByState({}, function () {
  3585. getUnreadIds();
  3586. getUnreadCount();
  3587. });
  3588. };
  3589. //获取未读单据id
  3590. var getUnreadIds = function (){
  3591. PurcChange.getUnreadIds({}, "", function (message) {
  3592. $scope.unreadCode = message.content;
  3593. });
  3594. };
  3595. getUnreadIds();
  3596. //判断单据是否未读
  3597. $scope.isUnread = function (id){
  3598. for (var i in $scope.unreadCode) {
  3599. if (id == $scope.unreadCode[i]) {
  3600. return true;
  3601. }
  3602. }
  3603. };
  3604. $scope.openDatePicker = function ($event, item, openParam) {
  3605. $event.preventDefault();
  3606. $event.stopPropagation();
  3607. item[openParam] = !item[openParam];
  3608. };
  3609. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3610. $event.preventDefault();
  3611. $event.stopPropagation();
  3612. item[openParam] = !item[openParam];
  3613. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3614. $scope.tableParams.reload();
  3615. }
  3616. };
  3617. $scope.onReplyClick = function (change) {
  3618. if (change.$agreed) {
  3619. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3620. $scope.loading = true;
  3621. PurcChange.reply({changeId: change.id}, reply, function () {
  3622. $scope.loading = false;
  3623. toaster.pop('info', '提示', '回复成功');
  3624. $scope.tableParams.reload();
  3625. }, function (response) {
  3626. $scope.loading = false;
  3627. toaster.pop('error', '回复失败', response.data);
  3628. });
  3629. }
  3630. };
  3631. // 搜索框回车
  3632. $scope.onSearch = function (keyword) {
  3633. // 每次搜索重置获取数据方法
  3634. $scope.searchMethod = false;
  3635. if(keyword != null && keyword != '') {
  3636. $scope.searchMethod = true;
  3637. }
  3638. $scope.tableParams.page(1);
  3639. $scope.tableParams.reload();
  3640. };
  3641. // 导出
  3642. $scope.exportXls = function () {
  3643. PurcChange.exportXls({}, {}, function (data) {
  3644. if (data.success){
  3645. window.location.href = 'sale/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3646. }
  3647. }, function (response) {
  3648. toaster.pop('error', '数据加载失败', response.data);
  3649. });
  3650. }
  3651. }]);
  3652. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcChange, toaster, CurrentRole) {
  3653. // 获取当前用户是否为普通用户
  3654. CurrentRole.isUser({}, {}, function (data) {
  3655. $scope.isUser = data.isUser;
  3656. });
  3657. var loadData = function () {
  3658. PurcChange.getItem({id: $stateParams.id}, function (data) {
  3659. $scope.change = data;
  3660. }, function (response) {
  3661. toaster.pop('error', '', response.data);
  3662. });
  3663. };
  3664. loadData();
  3665. $scope.openDatePicker = function ($event, item, openParam) {
  3666. $event.preventDefault();
  3667. $event.stopPropagation();
  3668. item[openParam] = !item[openParam];
  3669. };
  3670. $scope.onReplyClick = function (change) {
  3671. if (change.$agreed) {
  3672. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3673. PurcChange.reply({changeId: change.id}, reply, function () {
  3674. toaster.pop('info', '提示', '回复成功');
  3675. loadData();
  3676. }, function (response) {
  3677. toaster.pop('error', '回复失败', response.data);
  3678. });
  3679. }
  3680. };
  3681. }]);
  3682. //客户采购询价
  3683. 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) {
  3684. BaseService.scrollBackToTop();
  3685. // 获取当前用户是否为普通用户
  3686. CurrentRole.isUser({}, {}, function (data) {
  3687. $scope.isUser = data.isUser;
  3688. });
  3689. if ($rootScope.active) {
  3690. $scope.active = $rootScope.active;
  3691. $rootScope.active = null;
  3692. } else {
  3693. $scope.active = 'todo';
  3694. }
  3695. $scope.agreedText = '全部';
  3696. $scope.dateZoneText = '最近一个月';
  3697. $scope.condition = {dateZone: 1};
  3698. /* 时间筛选初始化*/
  3699. var fromDate = new Date();
  3700. var toDate = new Date();
  3701. fromDate.setMonth(fromDate.getMonth() - 1);
  3702. fromDate.setHours(0, 0, 0, 0);
  3703. toDate.setHours(23, 59, 59, 999);
  3704. $scope.condition.dateFrom = fromDate;
  3705. $scope.condition.dateTo = toDate;
  3706. $scope.changeAgreed = function (agreed) {
  3707. $scope.condition.agreed = agreed;
  3708. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3709. $scope.condition.$agreedOpen = false;
  3710. };
  3711. $scope.changeDateZone = function (zone) {
  3712. $scope.condition.dateZone = zone;
  3713. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  3714. $scope.condition.$dateZoneOpen = false;
  3715. getDateCondition(zone, $scope.condition);
  3716. $scope.tableParams.page(1);
  3717. $scope.tableParams.reload();
  3718. };
  3719. $scope.setActive = function (state) {
  3720. if ($scope.active != state) {
  3721. $scope.active = state;
  3722. if ($scope.tableParams.page() == 1)
  3723. $scope.tableParams.reload();
  3724. else
  3725. $scope.tableParams.page(1);
  3726. }
  3727. };
  3728. // 设置阅读状态
  3729. $scope.setReadStatus = function(msg) {
  3730. if(!msg.read) {
  3731. PurcInquiry.setStatus({id: msg.inid}, {}, function(data) {
  3732. });
  3733. }
  3734. }
  3735. $scope.searchMethod = false;
  3736. var getService = function () {
  3737. return $scope.searchMethod ? PurcInquiry : PurcInquiryInfo;
  3738. };
  3739. $scope.tableParams = new ngTableParams({
  3740. page: 1,
  3741. count: 20,
  3742. sorting: {
  3743. 'inquiry.date': 'desc',
  3744. 'inquiry.enterprise.enName': 'asc',
  3745. 'inquiry.code': 'asc'
  3746. }
  3747. }, {
  3748. total: 0,
  3749. counts: [5, 10, 25, 50],
  3750. getData: function ($defer, params) {
  3751. $scope.loading = true;
  3752. var pageParams = params.url();
  3753. var realActive = {};
  3754. pageParams.searchFilter = { // 筛选条件
  3755. keyword: $scope.keyword,
  3756. fromDate: getDateTime($scope.condition.dateFrom),
  3757. endDate: getDateTime($scope.condition.dateTo)
  3758. };
  3759. if ($scope.active == 'overdue') {
  3760. $scope.active = 'end';
  3761. }
  3762. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3763. $scope.loading = false;
  3764. if (page) {
  3765. params.total(page.totalElement);
  3766. $defer.resolve(page.content);
  3767. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3768. }
  3769. }, function (response) {
  3770. $scope.loading = false;
  3771. toaster.pop('error', '数据加载失败', response.data);
  3772. });
  3773. }
  3774. });
  3775. //获得各分类未阅读数量
  3776. var getUnreadCount = function () {
  3777. PurcInquiry.getUnreadCount(null, function (data) {
  3778. $scope.unread = data;
  3779. });
  3780. };
  3781. getUnreadCount();
  3782. //设置单据已读
  3783. $scope.setOrdersRead = function (id) {
  3784. // 如果单据本身已读,则不发送请求修改数据
  3785. if (!$scope.isUnread(id)){
  3786. return;
  3787. }
  3788. var sourceId = [];
  3789. sourceId.push(id);
  3790. PurcInquiry.setRead({}, sourceId, function (message) {
  3791. getUnreadCount();
  3792. removeByValue($scope.unreadCode, id);
  3793. });
  3794. };
  3795. $scope.setOrdersReadByState = function () {
  3796. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3797. return;
  3798. }
  3799. PurcInquiry.setReadByState({}, function () {
  3800. getUnreadIds();
  3801. getUnreadCount();
  3802. });
  3803. };
  3804. var getUnreadIds = function () {
  3805. PurcInquiry.getUnreadIds({}, "", function (message) {
  3806. $scope.unreadCode = message.content;
  3807. });
  3808. };
  3809. getUnreadIds();
  3810. $scope.isUnread = function (id) {
  3811. for (var i in $scope.unreadCode) {
  3812. if (id == $scope.unreadCode[i]) {
  3813. return true;
  3814. }
  3815. }
  3816. };
  3817. $scope.getMinDate = function (item) {
  3818. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3819. };
  3820. $scope.replyPrices = [];
  3821. $scope.replylapQtys = [];
  3822. $scope.replyPrices.push(true);
  3823. $scope.replylapQtys.push(true);
  3824. $scope.addStep = function (inquiryItem) {
  3825. $scope.replyPrices.push(true);
  3826. if (inquiryItem.replies.length >= 10) {
  3827. toaster.pop('warning', '提示', '最多支持10个分段!');
  3828. } else {
  3829. inquiryItem.replies.push({});
  3830. if (inquiryItem.replies.length != 1) {
  3831. $scope.replyPrices.push(true);
  3832. $scope.replylapQtys.push(true);
  3833. }
  3834. }
  3835. };
  3836. $scope.removeStep = function (inquiryItem, stepIndex) {
  3837. inquiryItem.replies.splice(stepIndex, 1);
  3838. $scope.replyPrices.splice(stepIndex, 1);
  3839. $scope.replylapQtys.splice(stepIndex, 1);
  3840. };
  3841. $scope.openDatePicker = function ($event, item, openParam) {
  3842. $event.preventDefault();
  3843. $event.stopPropagation();
  3844. item[openParam] = !item[openParam];
  3845. };
  3846. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3847. $event.preventDefault();
  3848. $event.stopPropagation();
  3849. item[openParam] = !item[openParam];
  3850. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3851. $scope.tableParams.reload();
  3852. }
  3853. };
  3854. $scope.getHistory = function (item) {
  3855. if (!item.history) {
  3856. PurcInquiry.getHistory({itemId: item.id},function (data) {
  3857. $scope.historyShow = true;
  3858. item.history = data;
  3859. }, function (response) {
  3860. $scope.historyShow = false;
  3861. //toaster.pop('error', '数据加载失败', response.data);
  3862. });
  3863. }
  3864. };
  3865. // 获取token信息
  3866. $scope.getToken = function() {
  3867. token.info({userType: 'saleinquiry'}, {}, function(data) {
  3868. $scope.token = data.token;
  3869. }, function(response) {
  3870. toaster.pop('error', '提示', response.data);
  3871. });
  3872. };
  3873. $scope.deleteAttach = function (attaches, index) {
  3874. attaches.splice(index, 1);
  3875. };
  3876. $scope.onReplyClick = function (item, withSteps) {
  3877. if (item.vendFromDate instanceof Date) {
  3878. item.vendFromDate = item.vendFromDate.getTime();
  3879. }
  3880. if (item.vendToDate instanceof Date) {
  3881. item.vendToDate = item.vendToDate.getTime();
  3882. }
  3883. if (item.vendFromDate > item.vendToDate) {
  3884. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3885. return;
  3886. }
  3887. var replies = [];
  3888. // 判断分段数是否合法
  3889. var valid = true;
  3890. var validLapQty = 0;
  3891. angular.forEach(item.replies, function (r, i) {
  3892. if ((i > 0 ? r.lapQty : 1) || r.price) {
  3893. replies.push(r);
  3894. }
  3895. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  3896. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  3897. valid = false;
  3898. validLapQty = r.lapQty;
  3899. }
  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. if (withSteps) { // 保存并报价
  3913. if(null != file) {
  3914. $upload.upload({
  3915. url: 'sale/inquiry/addAttach',
  3916. file: file,
  3917. method: 'POST',
  3918. data: {
  3919. item: item,
  3920. method: 'reply'
  3921. }
  3922. }).success(function (data) {
  3923. if (data.item) {
  3924. item = data.item;
  3925. }
  3926. $scope.loading = false;
  3927. toaster.pop('info', '提示', '报价成功');
  3928. $scope.tableParams.reload();
  3929. }).error(function (data) {
  3930. $scope.loading = false;
  3931. toaster.pop('error', '附件上传失败');
  3932. });
  3933. } else {
  3934. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function (data) {
  3935. $scope.loading = false;
  3936. toaster.pop('info', '提示', '报价成功');
  3937. $scope.tableParams.reload();
  3938. }, function (response) {
  3939. $scope.loading = false;
  3940. toaster.pop('error', '询价失效', response.data);
  3941. });
  3942. }
  3943. } else { // 保存
  3944. if(null != file) {
  3945. $upload.upload({
  3946. url: 'sale/inquiry/addAttach',
  3947. file: file,
  3948. method: 'POST',
  3949. data: {
  3950. item: item,
  3951. method: 'save'
  3952. }
  3953. }).success(function (data) {
  3954. if (data.item) {
  3955. item = data.item;
  3956. }
  3957. $scope.loading = false;
  3958. toaster.pop('info', '提示', '保存成功');
  3959. $scope.tableParams.reload();
  3960. }).error(function (data) {
  3961. $scope.loading = false;
  3962. toaster.pop('error', '附件上传失败');
  3963. });
  3964. } else {
  3965. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function (data) {
  3966. $scope.loading = false;
  3967. toaster.pop('info', '提示', '保存成功');
  3968. $scope.tableParams.reload();
  3969. }, function (response) {
  3970. $scope.loading = false;
  3971. toaster.pop('error', '保存失败', response.data);
  3972. });
  3973. }
  3974. }
  3975. }
  3976. };
  3977. $scope.isValid = function (item, withSteps) {
  3978. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3979. if (!withSteps || !bool)
  3980. return bool;
  3981. angular.forEach(item.replies, function (r, i) {
  3982. $scope.verifylapQty(r.lapQty, i, item);
  3983. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  3984. });
  3985. return bool;
  3986. };
  3987. $scope.verifylapQty = function (value, index, inquiryItem) {
  3988. value = parseInt(value);
  3989. var regex = /^\d+(.\d{1,6})?$/;
  3990. var valid = true;
  3991. angular.forEach(inquiryItem.replies, function(reply, $index) {
  3992. if ($index < index && reply.lapQty >= value) {
  3993. valid = false;
  3994. }
  3995. });
  3996. $scope.replylapQtys[index] = regex.test(value) && valid;
  3997. };
  3998. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  3999. $scope.verify = function (value, type) {
  4000. var regex = /^\d+(.\d{1,6})?$/;//
  4001. switch (type) {
  4002. case 'minOrderQty':
  4003. $scope.minOrderQtyVerify = regex.test(value);
  4004. break;
  4005. case 'minPackQty':
  4006. $scope.minPackQtyVerify = regex.test(value);
  4007. break;
  4008. case 'leadtime':
  4009. $scope.leadtimeVerify = regex.test(value);
  4010. break;
  4011. default:
  4012. $scope.replyPrices[type] = regex.test(value);
  4013. break;
  4014. }
  4015. }
  4016. // 搜索框回车
  4017. $scope.onSearch = function (keyword) {
  4018. // 每次搜索重置获取数据方法
  4019. $scope.searchMethod = false;
  4020. if(keyword != null && keyword != '') {
  4021. $scope.searchMethod = true;
  4022. }
  4023. $scope.tableParams.page(1);
  4024. $scope.tableParams.reload();
  4025. };
  4026. // 取消
  4027. $scope.cancel = function () {
  4028. $scope.tableParams.reload();
  4029. }
  4030. // 导出
  4031. $scope.exportXls = function () {
  4032. PurcInquiry.exportXls({}, {}, function (data) {
  4033. if (data.success) {
  4034. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4035. }
  4036. }, function (response) {
  4037. toaster.pop('error', '数据加载失败', response.data);
  4038. })
  4039. }
  4040. }]);
  4041. // 询价单明细
  4042. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole) {
  4043. // 获取当前用户是否为普通用户
  4044. CurrentRole.isUser({}, {}, function (data) {
  4045. $scope.isUser = data.isUser;
  4046. });
  4047. var loadData = function () {
  4048. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  4049. $scope.newinquiryItems = data;
  4050. var inquiry = data[0].inquiry;
  4051. //inquiry.inquiryItems = data;
  4052. angular.forEach(inquiry.attachs, function (attach) {
  4053. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  4054. });
  4055. $scope.inquiry = inquiry;
  4056. }, function (response) {
  4057. $scope.loading = false;
  4058. toaster.pop('error', '', response.data);
  4059. });
  4060. };
  4061. loadData();
  4062. $scope.getMinDate = function (item) {
  4063. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  4064. };
  4065. $scope.replyPrices = [];
  4066. $scope.replylapQtys = [];
  4067. $scope.replyPrices.push(true);
  4068. $scope.replylapQtys.push(true);
  4069. $scope.addStep = function (inquiryItem) {
  4070. if (inquiryItem.replies.length >= 10) {
  4071. toaster.pop('warning', '提示', '最多支持10个分段!');
  4072. } else
  4073. inquiryItem.replies.push({});
  4074. };
  4075. $scope.removeStep = function (inquiryItem, stepIndex) {
  4076. inquiryItem.replies.splice(stepIndex, 1);
  4077. };
  4078. $scope.openDatePicker = function ($event, item, openParam) {
  4079. $event.preventDefault();
  4080. $event.stopPropagation();
  4081. item[openParam] = !item[openParam];
  4082. };
  4083. $scope.getHistory = function (item) {
  4084. if (!item.history) {
  4085. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  4086. item.history = data;
  4087. });
  4088. }
  4089. };
  4090. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  4091. $scope.verify = function (value, type) {
  4092. var regex = /^\d+(.\d{1,6})?$/;//
  4093. switch (type) {
  4094. case 'minOrderQty':
  4095. $scope.minOrderQtyVerify = regex.test(value);
  4096. break;
  4097. case 'minPackQty':
  4098. $scope.minPackQtyVerify = regex.test(value);
  4099. break;
  4100. case 'leadtime':
  4101. $scope.leadtimeVerify = regex.test(value);
  4102. break;
  4103. default:
  4104. $scope.replyPrices[type] = regex.test(value);
  4105. break;
  4106. }
  4107. }
  4108. $scope.verifylapQty = function (value, index, inquiryItem) {
  4109. value = parseInt(value);
  4110. var regex = /^\d+(.\d{1,6})?$/;
  4111. var valid = true;
  4112. angular.forEach(inquiryItem.replies, function(reply, $index) {
  4113. if ($index < index && reply.lapQty >= value) {
  4114. valid = false;
  4115. }
  4116. });
  4117. $scope.replylapQtys[index] = regex.test(value) && valid;
  4118. };
  4119. $scope.isValid = function (item, withSteps) {
  4120. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4121. if (!withSteps || !bool)
  4122. return bool;
  4123. angular.forEach(item.replies, function (r, i) {
  4124. $scope.verifylapQty(r.lapQty, i, item);
  4125. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  4126. });
  4127. return bool;
  4128. };
  4129. // 获取token信息
  4130. $scope.getToken = function() {
  4131. token.info({userType: 'saleinquiry'}, {}, function(data) {
  4132. $scope.token = data.token;
  4133. }, function(response) {
  4134. toaster.pop('error', '提示', response.data);
  4135. });
  4136. };
  4137. $scope.deleteAttach = function (attaches, index) {
  4138. attaches.splice(index, 1);
  4139. };
  4140. $scope.onReplyClick = function (item, withSteps) {
  4141. if (item.vendFromDate instanceof Date) {
  4142. item.vendFromDate = item.vendFromDate.getTime();
  4143. }
  4144. if (item.vendToDate instanceof Date) {
  4145. item.vendToDate = item.vendToDate.getTime();
  4146. }
  4147. if (item.vendFromDate > item.vendToDate) {
  4148. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4149. return;
  4150. }
  4151. var replies = [];
  4152. var valid = true;
  4153. var validLapQty = 0;
  4154. angular.forEach(item.replies, function (r, i) {
  4155. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  4156. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  4157. valid = false;
  4158. validLapQty = r.lapQty;
  4159. }
  4160. if ((i > 0 ? r.lapQty : 1) || r.price)
  4161. replies.push(r);
  4162. });
  4163. item.replies = replies;
  4164. $scope.loading = true;
  4165. if (!valid) { // 不合法时给出提示
  4166. if (validLapQty) {
  4167. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  4168. } else {
  4169. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  4170. }
  4171. $scope.loading = false;
  4172. } else {
  4173. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  4174. if (withSteps) {
  4175. if(null != file) {
  4176. $upload.upload({
  4177. url: 'sale/inquiry/addAttach',
  4178. file: file,
  4179. method: 'POST',
  4180. data: {
  4181. item: item,
  4182. method: 'reply'
  4183. }
  4184. }).success(function (data) {
  4185. if (data.item) {
  4186. item = data.item;
  4187. }
  4188. window.location.reload();
  4189. });
  4190. } else {
  4191. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  4192. $scope.loading = false;
  4193. toaster.pop('info', '提示', '报价成功');
  4194. // loadData();
  4195. window.location.reload();
  4196. }, function (response) {
  4197. $scope.loading = false;
  4198. toaster.pop('error', '询价失效', response.data);
  4199. });
  4200. }
  4201. } else {
  4202. if(null != file) {
  4203. $upload.upload({
  4204. url: 'sale/inquiry/addAttach',
  4205. file: file,
  4206. method: 'POST',
  4207. data: {
  4208. item: item,
  4209. method: 'save'
  4210. }
  4211. }).success(function (data) {
  4212. if (data.item) {
  4213. item = data.item;
  4214. }
  4215. window.location.reload();
  4216. });
  4217. } else {
  4218. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  4219. $scope.loading = false;
  4220. toaster.pop('info', '提示', '保存成功');
  4221. // loadData();
  4222. window.location.reload();
  4223. }, function (response) {
  4224. $scope.loading = false;
  4225. toaster.pop('error', '保存失败', response.data);
  4226. });
  4227. }
  4228. }
  4229. }
  4230. };
  4231. // 取消
  4232. $scope.cancel = function () {
  4233. $scope.tableParams.reload();
  4234. }
  4235. }]);
  4236. // 平台新增的询价单
  4237. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'PurcProduct', 'PurcProductNewest', '$timeout', '$http', 'ShipAddress', 'Search', 'ComponentActiveAPI', '$state',
  4238. function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, PurcProduct, PurcProductNewest, $timeout, $http, ShipAddress, Search, ComponentActiveAPI, $state) {
  4239. $scope.status = 'InquiryNew';
  4240. $scope.active = 'all';
  4241. $rootScope.tenderVendor = null;// 清除掉已选择的
  4242. $scope.searchMethod = false;
  4243. var getService = function () {
  4244. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  4245. };
  4246. $scope.inquiry = {
  4247. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  4248. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  4249. priceType: '采购',
  4250. isOpen: 1,
  4251. invoice: 0,
  4252. ifTax: 1,
  4253. currency: 'RMB',
  4254. inquirytype: '询价'
  4255. };
  4256. $scope.changeCurrency = function (inquiry) {
  4257. if (inquiry.currency !== 'RMB') {
  4258. $scope.notRMB = true;
  4259. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  4260. inquiry.invoice = 0;
  4261. } else {
  4262. $scope.notRMB = false;
  4263. }
  4264. };
  4265. // 获取收货地址列表
  4266. var loadShipAddress = function () {
  4267. ShipAddress.shipAddList({}, function (data) {
  4268. $scope.ships = data;
  4269. if (angular.isDefined($scope.ships)) {
  4270. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  4271. }
  4272. });
  4273. };
  4274. loadShipAddress();
  4275. // 获取地址信息
  4276. $http.get('resources/citydata/city.json', {
  4277. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  4278. }).then(function (response) {
  4279. $scope.provinces = response.data;
  4280. });
  4281. // 新增收货地址保存
  4282. $scope.saveShipAddress = function (ship) {
  4283. ship.address = ship.province + ship.city + ship.district;
  4284. ShipAddress.saveAddress({}, ship, function (data) {
  4285. if (data.success) {
  4286. // 获取收货地址列表
  4287. loadShipAddress();
  4288. toaster.pop('success', '提示', data.success);
  4289. }
  4290. if (data.error) {
  4291. toaster.pop('error', '提示', data.error);
  4292. }
  4293. });
  4294. };
  4295. $scope.currentDay = function () {
  4296. return $filter('date')(new Date(), 'yyyy-MM-dd');
  4297. };
  4298. $scope.vendors = [];
  4299. // 查找供应商
  4300. $scope.dbfindVendor = function () {
  4301. var modalInstance = $modal.open({
  4302. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  4303. controller: 'DbfindVendorCtrl',
  4304. size: 'lg',
  4305. resolve: {}
  4306. });
  4307. modalInstance.result.then(function (data) {
  4308. var ifPush = true;
  4309. modalInstance.result.then(function (data) {
  4310. angular.forEach(data, function (vendor) {
  4311. if (!$scope.vendors) {// 不存在就先创建
  4312. $scope.vendors = [{}];
  4313. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  4314. } else {
  4315. for (var i = 0; i < $scope.vendors.length; i++) {
  4316. ifPush = true;
  4317. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  4318. ifPush = false;
  4319. break; // 判定到已存在供应商,就终止循环。
  4320. }
  4321. }
  4322. if (ifPush) {
  4323. $scope.vendors.push({
  4324. enName: vendor.vendorEnterprise.enName,
  4325. enuu: vendor.vendorEnterprise.uu
  4326. });
  4327. }
  4328. }
  4329. });
  4330. $rootScope.tenderVendor = $scope.vendors;
  4331. }, function () {
  4332. });
  4333. }, function () {
  4334. });
  4335. };
  4336. // 删除一个供应商
  4337. $scope.removeVendor = function (index) {
  4338. $scope.vendors.splice(index, 1);
  4339. };
  4340. $scope.removeChecked = function () {
  4341. if ($scope.vendors.length > 0) {
  4342. $scope.vendors = [];
  4343. $rootScope.tenderVendor = '';
  4344. }
  4345. }
  4346. // 物料信息
  4347. $scope.tableParams = new ngTableParams({
  4348. page: 1,
  4349. count: 20,
  4350. sorting: {
  4351. id: 'desc'
  4352. }
  4353. }, {
  4354. total: 0,
  4355. counts: [5, 10, 25, 50],
  4356. getData: function ($defer, params) {
  4357. $scope.loading = true;
  4358. var pageParams = params.url();
  4359. pageParams.keyword = $scope.keyword;
  4360. $scope.tip = $scope.keyword;
  4361. pageParams.searchFilter = $scope.searchFilter;
  4362. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4363. $scope.loading = false;
  4364. if (page) {
  4365. params.total(page.totalElement);
  4366. $scope.total = page.totalElement;
  4367. $defer.resolve(page.content);
  4368. }
  4369. }, function (response) {
  4370. $scope.loading = false;
  4371. toaster.pop('error', '数据加载失败', response.data);
  4372. });
  4373. }
  4374. });
  4375. // 搜索框回车
  4376. $scope.onSearch = function (keyword) {
  4377. // 每次搜索重置获取数据方法
  4378. $scope.searchMethod = false;
  4379. if(keyword != null && keyword != '') {
  4380. $scope.searchMethod = true;
  4381. }
  4382. $scope.tableParams.page(1);
  4383. $scope.tableParams.reload();
  4384. };
  4385. $scope.inquiry.inquiryItems = [];
  4386. var prod = {
  4387. cmpCode: null,
  4388. prodTitle: null,
  4389. inbrand: null,
  4390. toDate: null,
  4391. unit: 'PCS',
  4392. needquantity: null
  4393. };
  4394. $scope.inquiry.inquiryItems.push(prod);
  4395. // 联想词start
  4396. // 获取品牌联想词
  4397. $scope.getSimilarBrands = function (value) {
  4398. if (value) {
  4399. // 获取品牌联想词
  4400. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  4401. return data.map(function (item) {
  4402. return item;
  4403. });
  4404. });
  4405. }
  4406. };
  4407. // 获取产品型号联想词
  4408. $scope.getSimilarCodes = function (value) {
  4409. if (value) {
  4410. // 获取产品型号联想词
  4411. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  4412. return data.map(function (item) {
  4413. return item;
  4414. })
  4415. });
  4416. }
  4417. };
  4418. $scope.selectKind = function (prod) {
  4419. var submit = [];
  4420. $modal.open({
  4421. animation: true,
  4422. size: 'lg',
  4423. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  4424. controller: 'ProdKindChooseCtrl',
  4425. resolve: {
  4426. actives: function () {
  4427. return $scope.actives;
  4428. }
  4429. }
  4430. }).result.then(function (data) {
  4431. $scope.actives = data.actives;
  4432. var size = data.actives.length;
  4433. submit.gradeOneKiName = '';
  4434. submit.gradeTwoKiName = '';
  4435. submit.gradeThreeKiName = '';
  4436. if (size > 0) {
  4437. submit.gradeOneKiName = $scope.actives[0].nameCn;
  4438. prod.prodTitle = submit.gradeOneKiName;
  4439. if (size > 1) {
  4440. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  4441. prod.prodTitle = submit.gradeTwoKiName;
  4442. if (size > 2) {
  4443. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  4444. prod.prodTitle = submit.gradeThreeKiName;
  4445. }
  4446. }
  4447. }
  4448. }, function () {
  4449. });
  4450. };
  4451. // 点击联想词获取品牌信息
  4452. $scope.onAssociateBrandClick = function (brand, prod) {
  4453. if (brand instanceof String) {
  4454. prod.inbrand = brand;
  4455. } else if (brand instanceof Object) {
  4456. prod.inbrand = brand.brandCn;
  4457. }
  4458. };
  4459. // 打开品牌选择的模态框
  4460. $scope.selectBrand = function (prod) { //打开模态
  4461. var modalInstance = $modal.open({
  4462. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  4463. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  4464. });
  4465. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  4466. });
  4467. modalInstance.result.then(function (brand) {
  4468. prod.inbrand = brand.nameCn;
  4469. }, function (reason) {
  4470. });
  4471. };
  4472. // 点击联想词获取器件信息 带入产品分类和品牌
  4473. $scope.onAssociateCmpClick = function (cmp, prod) {
  4474. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  4475. $scope.component = data;
  4476. prod.cmpCode = data.code;
  4477. prod.prodTitle = data.kind.nameCn;
  4478. prod.inbrand = data.brand.nameCn;
  4479. }, function (res) {
  4480. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  4481. })
  4482. };
  4483. //联想词end
  4484. // 导入商品信息
  4485. $scope.uplodaByBatch = function () {
  4486. var modalInstance = $modal.open({
  4487. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  4488. controller: 'PurcInquiryUploadCtrl',
  4489. size: 'lg',
  4490. resolve: {}
  4491. });
  4492. modalInstance.result.then(function (data) {
  4493. angular.forEach(data, function (prod) {
  4494. $scope.inquiry.inquiryItems.push(prod);
  4495. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4496. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4497. $scope.inquiry.inquiryItems.splice(i, 1);
  4498. }
  4499. }
  4500. })
  4501. }, function () {
  4502. });
  4503. }
  4504. //增加商品
  4505. $scope.add = function () {
  4506. $scope.inquiry.inquiryItems.push(
  4507. {
  4508. cmpCode: null,
  4509. prodTitle: null,
  4510. unit: 'PCS',
  4511. ibrand: null,
  4512. toDate: null,
  4513. needquantity: null
  4514. });
  4515. };
  4516. //删除商品
  4517. $scope.del = function (index) {
  4518. $scope.inquiry.inquiryItems.splice(index, 1);
  4519. };
  4520. $scope.check = function (product) {
  4521. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4522. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4523. $scope.inquiry.inquiryItems.splice(i, 1);
  4524. }
  4525. }
  4526. $scope.inquiry.inquiryItems.push({
  4527. cmpCode: product.cmpCode, prodTitle: product.title, spec: product.spec, unit: product.unit,
  4528. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand
  4529. });
  4530. }
  4531. $scope.getMinDate = function (item) {
  4532. return $filter('date')(new Date, 'yyyy-MM-dd');
  4533. };
  4534. $scope.openDatePicker = function ($event, openParam, index) {
  4535. $event.preventDefault();
  4536. $event.stopPropagation();
  4537. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  4538. };
  4539. $scope.openEndDatePicker = function ($event, item, openParam) {
  4540. $event.preventDefault();
  4541. $event.stopPropagation();
  4542. item[openParam] = !item[openParam];
  4543. };
  4544. $scope.ifrepeat = false;
  4545. // 保存
  4546. $scope.save = function () {
  4547. $scope.loading = true;
  4548. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4549. $scope.item = $scope.inquiry.inquiryItems[i];
  4550. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4551. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4552. if (i != j) {
  4553. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4554. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4555. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4556. $scope.ifrepeat = true;
  4557. }
  4558. }
  4559. }
  4560. }
  4561. if (!$scope.ifrepeat) {
  4562. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4563. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4564. if ($scope.vendors.length > 0) {
  4565. $upload.upload({
  4566. url: 'purc/inquiry/save/withVendor',
  4567. file: file,
  4568. method: 'POST',
  4569. data: {
  4570. inquiry: $scope.inquiry,
  4571. contacts: $scope.vendors
  4572. },
  4573. }).success(function (data) {
  4574. $scope.loading = false;
  4575. if (data.success) {
  4576. toaster.pop('success', '提示', data.success);
  4577. $timeout(function () {
  4578. $rootScope.active = 'todo';
  4579. window.location.hash = "#/purc/inquiry_unapply";
  4580. }, 500);
  4581. }
  4582. if (data.error) {
  4583. toaster.pop('error', '提示', data.error);
  4584. }
  4585. }).error(function (data, status, headers, config) {
  4586. $scope.loadingShow = false;
  4587. if (status == 403) { // 抛异常专用
  4588. toaster.pop('error', '操作失败', data);
  4589. } else {
  4590. toaster.pop('error', '操作失败', data.error);
  4591. }
  4592. });
  4593. } else {
  4594. toaster.pop('info', '提示', '请先选择供应商');
  4595. }
  4596. } else {
  4597. $upload.upload({
  4598. url: 'purc/inquiry/save/withoutVendor',
  4599. file: file,
  4600. method: 'POST',
  4601. data: {
  4602. inquiry: $scope.inquiry,
  4603. },
  4604. }).success(function (data) {
  4605. $scope.loading = false;
  4606. if (data.success) {
  4607. toaster.pop('success', '提示', data.success);
  4608. }
  4609. if (data.error) {
  4610. toaster.pop('error', '提示', data.error);
  4611. }
  4612. }).error(function (data, status, headers, config) {
  4613. $scope.loadingShow = false;
  4614. if (status == 403) { // 抛异常专用
  4615. toaster.pop('error', '操作失败', data);
  4616. } else {
  4617. toaster.pop('error', '操作失败', data.error);
  4618. }
  4619. });
  4620. }
  4621. } else {
  4622. $scope.loading = false;
  4623. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4624. }
  4625. }
  4626. // 保存并提交
  4627. $scope.submit = function () {
  4628. $scope.loading = true;
  4629. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4630. $scope.item = $scope.inquiry.inquiryItems[i];
  4631. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4632. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4633. if (i != j) {
  4634. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4635. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4636. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4637. $scope.ifrepeat = true;
  4638. }
  4639. }
  4640. }
  4641. }
  4642. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4643. if (!$scope.ifrepeat) {
  4644. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4645. if ($scope.vendors.length > 0) {
  4646. $upload.upload({
  4647. url: 'purc/inquiry/submit/withVendor',
  4648. file: file,
  4649. method: 'POST',
  4650. data: {
  4651. inquiry: $scope.inquiry,
  4652. contacts: $scope.vendors
  4653. },
  4654. }).success(function (data) {
  4655. $scope.loading = false;
  4656. if (data.success) {
  4657. toaster.pop('success', '提示', data.success);
  4658. $timeout(function () {
  4659. window.location.hash = "#/purc/purchaseinquiry";
  4660. }, 500);
  4661. }
  4662. if (data.error) {
  4663. toaster.pop('error', '提示', data.error);
  4664. }
  4665. }).error(function (data, status, headers, config) {
  4666. $scope.loadingShow = false;
  4667. if (status == 403) { // 抛异常专用
  4668. toaster.pop('error', '操作失败', data);
  4669. } else {
  4670. toaster.pop('error', '操作失败', data.error);
  4671. }
  4672. });
  4673. } else {
  4674. toaster.pop('info', '提示', '请先选择供应商');
  4675. }
  4676. } else {
  4677. $upload.upload({
  4678. url: 'purc/inquiry/submit/withoutVendor',
  4679. file: file,
  4680. method: 'POST',
  4681. data: {
  4682. inquiry: $scope.inquiry,
  4683. },
  4684. }).success(function (data) {
  4685. $scope.loading = false;
  4686. if (data.success) {
  4687. toaster.pop('success', '提示', data.success);
  4688. }
  4689. if (data.error) {
  4690. toaster.pop('error', '提示', data.error);
  4691. }
  4692. }).error(function (data, status, headers, config) {
  4693. $scope.loadingShow = false;
  4694. if (status == 403) { // 抛异常专用
  4695. toaster.pop('error', '操作失败', data);
  4696. } else {
  4697. toaster.pop('error', '操作失败', data.error);
  4698. }
  4699. });
  4700. }
  4701. } else {
  4702. $scope.loading = false;
  4703. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4704. }
  4705. }
  4706. $scope.previewShow = false;
  4707. $scope.pdfShow = false;
  4708. $scope.noneFileShow = true;
  4709. $scope.$watch('myFiles', function () {
  4710. if ($scope.myFiles) {
  4711. $scope.noneFileShow = false;
  4712. var file = $scope.myFiles[0];
  4713. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  4714. $scope.pdfShow = true;
  4715. $scope.previewShow = false;
  4716. $scope.imgPreviewName = file.name;
  4717. } else {
  4718. if (typeof(Worker) !== "undefined") {//支持HTML5
  4719. $scope.imgPreview = getObjectURL(file);
  4720. $scope.imgPreviewName = file.name;
  4721. } else {//不支持HTML5
  4722. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  4723. $scope.imgPreviewName = file.name;
  4724. }
  4725. $scope.previewShow = true;
  4726. $scope.pdfShow = false;
  4727. }
  4728. } else {
  4729. $scope.noneFileShow = true;
  4730. $scope.previewShow = false;
  4731. $scope.pdfShow = false;
  4732. }
  4733. });
  4734. //建立一个可存取到该file的url
  4735. var getObjectURL = function (file) {
  4736. var url = null;
  4737. if (window.createObjectURL != undefined) { // basic
  4738. url = window.createObjectURL(file);
  4739. } else if (window.URL != undefined) { // mozilla(firefox)
  4740. url = window.URL.createObjectURL(file);
  4741. } else if (window.webkitURL != undefined) { // webkit or chrome
  4742. url = window.webkitURL.createObjectURL(file);
  4743. }
  4744. return url;
  4745. };
  4746. }]);
  4747. /**
  4748. * 代采订单批量导入
  4749. */
  4750. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  4751. // 通过excel批量上传物料
  4752. $scope.result = null;
  4753. $scope.upload = function () {
  4754. var file = $scope.myFiles[0];
  4755. $upload.upload({
  4756. url: 'purc/inquiry/release/excel',
  4757. file: file,
  4758. method: 'POST'
  4759. }).success(function (data) {
  4760. $scope.result = data;
  4761. $scope.success = $scope.result.success;
  4762. $scope.total = $scope.result.total;
  4763. $scope.alters = $scope.result.alters;
  4764. }).error(function (response) {
  4765. toaster.pop('error', response.data || response);
  4766. });
  4767. };
  4768. // 查看范例
  4769. $scope.showImg = function () {
  4770. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  4771. box.show();
  4772. box.find('img').attr('src', src);
  4773. box.find('a').click(function () {
  4774. box.hide();
  4775. });
  4776. box.dblclick(function () {
  4777. box.hide();
  4778. });
  4779. };
  4780. // 下载模板
  4781. $scope.download = function () {
  4782. window.location.href = 'purc/inquiry/upload/template';
  4783. };
  4784. $scope.enSure = function () {
  4785. $modalInstance.close($scope.result.items);
  4786. }
  4787. $scope.cancel = function () {
  4788. $modalInstance.dismiss();
  4789. }
  4790. }]);
  4791. // 平台询价单(已提交)
  4792. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', 'CurrentRole', function ($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope, CurrentRole) {
  4793. $scope.status = 'InquirySubmit';
  4794. BaseService.scrollBackToTop();
  4795. // 获取当前用户是否为普通用户
  4796. CurrentRole.isUser({}, {}, function (data) {
  4797. $scope.isUser = data.isUser;
  4798. });
  4799. if ($rootScope.active) {
  4800. $scope.active = $rootScope.active;
  4801. $rootScope.active = null;
  4802. } else {
  4803. $scope.active = 'todo';
  4804. }
  4805. $scope.agreedText = '全部';
  4806. $scope.dateZoneText = '一个月内';
  4807. $scope.condition = {dateZone: 1};
  4808. /* 时间筛选初始化*/
  4809. var fromDate = new Date();
  4810. var toDate = new Date();
  4811. fromDate.setMonth(fromDate.getMonth() - 1);
  4812. fromDate.setHours(0, 0, 0, 0);
  4813. toDate.setHours(23, 59, 59, 999);
  4814. $scope.condition.dateFrom = fromDate;
  4815. $scope.condition.dateTo = toDate;
  4816. $scope.changeAgreed = function (agreed) {
  4817. $scope.condition.agreed = agreed;
  4818. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4819. $scope.condition.$agreedOpen = false;
  4820. };
  4821. $scope.changeDateZone = function (zone) {
  4822. $scope.condition.dateZone = zone;
  4823. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4824. $scope.condition.$dateZoneOpen = false;
  4825. getDateCondition(zone, $scope.condition);
  4826. $scope.tableParams.page(1);
  4827. $scope.tableParams.reload();
  4828. };
  4829. $scope.setActive = function (state) {
  4830. if ($scope.active != state) {
  4831. $scope.active = state;
  4832. if ($scope.tableParams.page() == 1) {
  4833. $scope.tableParams.reload();
  4834. } else {
  4835. $scope.tableParams.page(1);
  4836. }
  4837. }
  4838. }
  4839. var getService = function () {
  4840. return PurchaseInquiry;
  4841. };
  4842. $scope.tableParams = new ngTableParams({
  4843. page: 1,
  4844. count: 20,
  4845. sorting: {
  4846. 'inquiry.date': 'desc',
  4847. 'inquiry.enterprise.enName': 'asc',
  4848. 'inquiry.code': 'asc'
  4849. }
  4850. }, {
  4851. total: 0,
  4852. counts: [5, 10, 25, 50],
  4853. getData: function ($defer, params) {
  4854. $scope.loading = true;
  4855. var pageParams = params.url();
  4856. var realActive = {};
  4857. pageParams.searchFilter = {
  4858. keyword: $scope.keyword,
  4859. fromDate: getDateTime($scope.condition.dateFrom),
  4860. endDate: getDateTime($scope.condition.dateTo)
  4861. };
  4862. if ($scope.active == 'overdue') {
  4863. $scope.active = 'end';
  4864. }
  4865. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4866. $scope.loading = false;
  4867. if (page) {
  4868. params.total(page.totalElement);
  4869. $defer.resolve(page.content);
  4870. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4871. }
  4872. }, function (response) {
  4873. $scope.loading = false;
  4874. toaster.pop('error', '数据加载失败', response.data);
  4875. });
  4876. }
  4877. });
  4878. //获得各分类未阅读数量
  4879. var getUnreadCount = function () {
  4880. PurchaseInquiry.getUnreadCount(null, function(data){
  4881. $scope.unread = data;
  4882. });
  4883. };
  4884. getUnreadCount();
  4885. //设置单据已读
  4886. $scope.setOrdersRead = function (id) {
  4887. // 如果单据本身已读,则不发送请求修改数据
  4888. if (!$scope.isUnread(id)){
  4889. return;
  4890. }
  4891. var sourceId = [];
  4892. sourceId.push(id);
  4893. PurchaseInquiry.setRead({}, sourceId, function (message) {
  4894. getUnreadIds();
  4895. getUnreadCount();
  4896. });
  4897. };
  4898. //获得未读单据id
  4899. var getUnreadIds = function (){
  4900. PurchaseInquiry.getUnreadIds({}, "", function (message) {
  4901. $scope.unreadCode = message.content;
  4902. });
  4903. };
  4904. getUnreadIds();
  4905. //判断单据是否未读
  4906. $scope.isUnread = function (id){
  4907. for (var i in $scope.unreadCode) {
  4908. if (id == $scope.unreadCode[i]) {
  4909. return true;
  4910. }
  4911. }
  4912. };
  4913. $scope.openDatePicker = function ($event, item, openParam) {
  4914. $event.preventDefault();
  4915. $event.stopPropagation();
  4916. item[openParam] = !item[openParam];
  4917. };
  4918. $scope.openFilterDatePicker = function ($event, item, openParam) {
  4919. $event.preventDefault();
  4920. $event.stopPropagation();
  4921. item[openParam] = !item[openParam];
  4922. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  4923. $scope.tableParams.reload();
  4924. }
  4925. };
  4926. // 搜索框回车
  4927. $scope.onSearch = function () {
  4928. $scope.tableParams.page(1);
  4929. $scope.tableParams.reload();
  4930. };
  4931. // 采纳
  4932. $scope.accept = function (id) {
  4933. PurchaseInquiry.accept({id: id}, {}, function (data) {
  4934. if (data.success) {
  4935. toaster.pop('success', '提示', data.success);
  4936. $scope.tableParams.reload();
  4937. }
  4938. if (data.error) {
  4939. toaster.pop('error', '提示', data.error);
  4940. }
  4941. }, function (response) {
  4942. toaster.pop('error', '提示', response.data);
  4943. })
  4944. };
  4945. // 拒绝
  4946. $scope.refuse = function (id) {
  4947. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  4948. if (data.success) {
  4949. toaster.pop('success', '提示', data.success);
  4950. $scope.tableParams.reload();
  4951. }
  4952. if (data.error) {
  4953. toaster.pop('error', '提示', data.error);
  4954. }
  4955. }, function (response) {
  4956. toaster.pop('error', '提示', response.data);
  4957. })
  4958. }
  4959. // 导出
  4960. $scope.exportXls = function () {
  4961. PurchaseInquiry.exportXls({}, {}, function (data) {
  4962. if (data.success){
  4963. window.location.href = 'purc/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4964. }
  4965. }, function (response) {
  4966. toaster.pop('error', '数据加载失败', response.data);
  4967. });
  4968. }
  4969. }]);
  4970. // 平台询价单(未提交)
  4971. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function ($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  4972. BaseService.scrollBackToTop();
  4973. if ($rootScope.active = 'done') {
  4974. $scope.active = 'done';
  4975. $rootScope.active = '';
  4976. }
  4977. if ($rootScope.active = 'todo') {
  4978. $scope.active = 'todo';
  4979. $rootScope.active = '';
  4980. }
  4981. var getService = function () {
  4982. if ($scope.active == 'todo') {
  4983. return PurchaseInquiry.getUnapply;
  4984. }
  4985. if ($scope.active == 'done') {
  4986. return PurchaseInquiry.getSubmit;
  4987. }
  4988. }
  4989. $scope.setActive = function (state) {
  4990. if ($scope.active != state) {
  4991. $scope.active = state;
  4992. if ($scope.tableParams.page() == 1) {
  4993. $scope.tableParams.reload();
  4994. } else {
  4995. $scope.tableParams.page(1);
  4996. }
  4997. }
  4998. }
  4999. $scope.tableParams = new ngTableParams({
  5000. page: 1,
  5001. count: 20,
  5002. sorting: {
  5003. 'date': 'desc',
  5004. 'enterprise.enName': 'asc',
  5005. 'code': 'asc'
  5006. }
  5007. }, {
  5008. total: 0,
  5009. counts: [5, 10, 25, 50],
  5010. getData: function ($defer, params) {
  5011. $scope.loading = true;
  5012. var pageParams = params.url();
  5013. var realActive = {};
  5014. if ($scope.active == 'overdue') {
  5015. $scope.active = 'end';
  5016. }
  5017. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  5018. $scope.loading = false;
  5019. if (page) {
  5020. params.total(page.totalElements);
  5021. $defer.resolve(page.content);
  5022. }
  5023. }, function (response) {
  5024. $scope.loading = false;
  5025. toaster.pop('error', '数据加载失败', response.data);
  5026. });
  5027. }
  5028. });
  5029. // 删除明细
  5030. $scope.deleteById = function (id) {
  5031. PurchaseInquiry.deleteById({id: id}, {}, function (data) {
  5032. toaster.pop('success', '提示', '删除成功');
  5033. $scope.tableParams.reload();
  5034. }, function (response) {
  5035. toaster.pop('error', '提示', response.data);
  5036. });
  5037. }
  5038. // 删除主表
  5039. $scope.clearOrder = function (id) {
  5040. PurchaseInquiry.clearOrder({id: id}, {}, function (data) {
  5041. toaster.pop('success', '提示', '删除成功');
  5042. $scope.tableParams.reload();
  5043. }, function (response) {
  5044. toaster.pop('error', '提示', response.data);
  5045. });
  5046. }
  5047. // 提交
  5048. $scope.submit = function (id) {
  5049. PurchaseInquiry.submitUnapply({id: id}, {}, function (data) {
  5050. toaster.pop('success', '提示', '单据提交成功');
  5051. $scope.active = 'done';
  5052. $scope.tableParams.reload();
  5053. }, function (response) {
  5054. toaster.pop('error', '提示', response.data);
  5055. })
  5056. }
  5057. // 发布公共询价
  5058. $scope.publish = function (id) {
  5059. PurchaseInquiry.publishInquiry({id: id}, {}, function (data) {
  5060. toaster.pop('success', '提示', data.success);
  5061. $scope.active = 'done';
  5062. $scope.tableParams.reload();
  5063. }, function (response) {
  5064. toaster.pop('error', '提示', response.data);
  5065. })
  5066. }
  5067. }]);
  5068. // 公共询价列表
  5069. app.controller('PublicInquiryListCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'PurcInquiry', 'publicInquiry', 'publicInquiryList', '$modal', '$http', 'AccountEnterprise', 'customer', 'AuthenticationService', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, PurcInquiry, publicInquiry, publicInquiryList, $modal, $http, AccountEnterprise, customer, AuthenticationService) {
  5070. BaseService.scrollBackToTop();
  5071. }]);
  5072. /**
  5073. * 报价操作
  5074. */
  5075. app.controller('QuoteCtrl', ['$scope', 'inquiryItem', 'toaster', 'publicInquiry', '$modalInstance', '$upload', function($scope, inquiryItem, toaster, publicInquiry, $modalInstance, $upload) {
  5076. $scope.inquiryItem = inquiryItem;
  5077. if ($scope.inquiryItem.replies == null || $scope.inquiryItem.replies.length == 0) {
  5078. $scope.inquiryItem.replies = [];
  5079. var reply = {
  5080. lapQty: 0,
  5081. price: null
  5082. };
  5083. $scope.inquiryItem.replies.push(reply);
  5084. }
  5085. $scope.replyPrices = [];
  5086. $scope.replylapQtys = [];
  5087. $scope.replyPrices.push(true);
  5088. $scope.replylapQtys.push(true);
  5089. // 获取默认币别
  5090. publicInquiry.getCurrency({}, function(data) {
  5091. $scope.currencies = data;
  5092. });
  5093. // 增加一列分段报价
  5094. $scope.addStep = function (inquiryItem) {
  5095. var check = true;
  5096. angular.forEach(inquiryItem.replies, function(reply) {
  5097. if (reply.lapQty == null) {
  5098. toaster.pop('error', '提示', '存在未填写分段数量的分段,请先填写分段数量');
  5099. check = false;
  5100. }
  5101. if (check && reply.price == null) {
  5102. toaster.pop('error', '提示', '存在未填写价格的分段,请先填写价格');
  5103. check = false;
  5104. }
  5105. });
  5106. if (check) {
  5107. $scope.replyPrices.push(true);
  5108. if (inquiryItem.replies.length >= 5) {
  5109. toaster.pop('warning', '提示', '最多支持5个分段!');
  5110. } else {
  5111. inquiryItem.replies.push({});
  5112. if (inquiryItem.replies.length != 1) {
  5113. $scope.replyPrices.push(true);
  5114. $scope.replylapQtys.push(true);
  5115. }
  5116. }
  5117. }
  5118. };
  5119. // 删除一列分段报价
  5120. $scope.removeStep = function (inquiryItem, stepIndex) {
  5121. inquiryItem.replies.splice(stepIndex, 1);
  5122. $scope.replyPrices.splice(stepIndex, 1);
  5123. $scope.replylapQtys.splice(stepIndex, 1);
  5124. };
  5125. // 取消,关闭弹出框
  5126. $scope.cancel = function() {
  5127. $modalInstance.dismiss();
  5128. }
  5129. // 保存报价信息
  5130. $scope.save = function(inquiryItem, method) {
  5131. var replies = [];
  5132. // 判断分段数是否合法
  5133. var valid = true;
  5134. var validLapQty = 0;
  5135. angular.forEach(inquiryItem.replies, function (r, i) {
  5136. if ((i > 0 ? r.lapQty : 1) || r.price) {
  5137. replies.push(r);
  5138. }
  5139. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  5140. if (i > 0 && parseInt(r.lapQty) <= parseInt(inquiryItem.replies[i - 1].lapQty) || r.lapQty == null) {
  5141. valid = false;
  5142. validLapQty = r.lapQty;
  5143. }
  5144. });
  5145. inquiryItem.replies = replies;
  5146. $scope.loading = true;
  5147. if (!valid) {
  5148. if (validLapQty) {
  5149. toaster.pop('error', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  5150. } else {
  5151. toaster.pop('error', '提示', '分段数量不合法,不能报价!');
  5152. }
  5153. } else {
  5154. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  5155. $upload.upload({
  5156. url: 'pubInquiry/turnToQuotation',
  5157. file: file,
  5158. method: 'POST',
  5159. data: {
  5160. item: inquiryItem,
  5161. method: method
  5162. }
  5163. }).success(function (data) {
  5164. if (data.item) {
  5165. item = data.item;
  5166. }
  5167. $scope.loading = false;
  5168. toaster.pop('info', '提示', '报价成功');
  5169. $modalInstance.close();
  5170. }).error(function (data) {
  5171. $scope.loading = false;
  5172. toaster.pop('error', '报价失败');
  5173. });
  5174. }
  5175. }
  5176. $scope.previewShow = false;
  5177. $scope.pdfShow = false;
  5178. $scope.noneFileShow = true;
  5179. $scope.$watch('myFiles', function () {
  5180. if ($scope.myFiles) {
  5181. $scope.noneFileShow = false;
  5182. var file = $scope.myFiles[0];
  5183. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  5184. $scope.pdfShow = true;
  5185. $scope.previewShow = false;
  5186. $scope.imgPreviewName = file.name;
  5187. } else {
  5188. if (typeof(Worker) !== "undefined") {//支持HTML5
  5189. $scope.imgPreview = getObjectURL(file);
  5190. $scope.imgPreviewName = file.name;
  5191. } else {//不支持HTML5
  5192. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  5193. $scope.imgPreviewName = file.name;
  5194. }
  5195. $scope.previewShow = true;
  5196. $scope.pdfShow = false;
  5197. }
  5198. } else {
  5199. $scope.noneFileShow = true;
  5200. $scope.previewShow = false;
  5201. $scope.pdfShow = false;
  5202. }
  5203. });
  5204. //建立一个可存取到该file的url
  5205. var imgurl = null;
  5206. var getObjectURL = function (file) {
  5207. var url = null;
  5208. if (window.createObjectURL != undefined) { // basic
  5209. url = window.createObjectURL(file);
  5210. } else if (window.URL != undefined) { // mozilla(firefox)
  5211. url = window.URL.createObjectURL(file);
  5212. } else if (window.webkitURL != undefined) { // webkit or chrome
  5213. url = window.webkitURL.createObjectURL(file);
  5214. }
  5215. imgurl = url;
  5216. return url;
  5217. };
  5218. }]);
  5219. /**
  5220. * 公共询价详情
  5221. */
  5222. app.controller('PublicInquiryListDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'BaseService', 'ngTableParams', 'AccountEnterprise', 'publicInquiry', 'publicInquiryList', '$modal', '$http', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, BaseService, ngTableParams, AccountEnterprise, publicInquiry, publicInquiryList, $modal, $http) {
  5223. BaseService.scrollBackToTop();
  5224. $scope.currentHasBid = false;
  5225. var loadData = function () {
  5226. // 当前企业
  5227. AccountEnterprise.get({}, function (data) {
  5228. $scope.enterprise = data
  5229. publicInquiry.getUrl({}, function(data) {
  5230. var url = data.url;
  5231. $http({
  5232. method: 'get',
  5233. dataType: 'json',
  5234. url: url + '/inquiry/sale/publicInquiry/detail',
  5235. params: {id: $stateParams.id, enuu: $scope.enterprise.uu}
  5236. }).success(function (response) {
  5237. if (response) {
  5238. $scope.inquiryItem = response.inquiryItem;
  5239. }
  5240. }).error(function (err) {
  5241. toaster.pop('error', '数据加载失败', err);
  5242. });
  5243. });
  5244. });
  5245. };
  5246. loadData();
  5247. // 当前时间
  5248. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  5249. // 当前企业
  5250. AccountEnterprise.get({}, function (data) {
  5251. $scope.enterprise = data;
  5252. });
  5253. $scope.isOverDue = function (date) {
  5254. if (date) {
  5255. var ndate = new Date();
  5256. ndate.setHours(23, 59, 59 ,999);
  5257. ndate.setDate(ndate.getDate());
  5258. var timestamp = Date.parse(ndate);
  5259. if (date > timestamp) {
  5260. return true;
  5261. } else {
  5262. return false;
  5263. }
  5264. } else {
  5265. return true;
  5266. }
  5267. }
  5268. // 转客户询价
  5269. $scope.transtoInquiry = function (inquiryItem) {
  5270. publicInquiry.quotationInfo({id: inquiryItem.id}, function(data) {
  5271. if (data.inquiryItem) { //存在已报价的就不进行报价操作
  5272. toaster.pop('error', '该询价单已已经报价');
  5273. } else {
  5274. var modalInstance = $modal.open({
  5275. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5276. controller: 'QuoteCtrl',
  5277. size: 'lg',
  5278. resolve: {
  5279. inquiryItem: function () {
  5280. return inquiryItem
  5281. }
  5282. }
  5283. });
  5284. modalInstance.result.then(function (data) {
  5285. $scope.tableParams.reload();
  5286. }, function () {
  5287. });
  5288. }
  5289. });
  5290. }
  5291. }]);
  5292. // 询价单明细
  5293. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, CurrentRole) {
  5294. // 获取当前用户是否为普通用户
  5295. CurrentRole.isUser({}, {}, function (data) {
  5296. $scope.isUser = !data.isUser;
  5297. });
  5298. var loadData = function () {
  5299. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  5300. $scope.newinquiryItems = data;
  5301. var inquiry = data[0].inquiry;
  5302. //inquiry.inquiryItems = data;
  5303. angular.forEach(inquiry.attachs, function (attach) {
  5304. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5305. });
  5306. $scope.inquiry = inquiry;
  5307. });
  5308. };
  5309. loadData();
  5310. $scope.getMinDate = function (item) {
  5311. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5312. };
  5313. $scope.addStep = function (inquiryItem) {
  5314. if (inquiryItem.replies.length >= 10) {
  5315. toaster.pop('warning', '提示', '最多支持10个分段!');
  5316. } else
  5317. inquiryItem.replies.push({});
  5318. };
  5319. $scope.removeStep = function (inquiryItem, stepIndex) {
  5320. inquiryItem.replies.splice(stepIndex, 1);
  5321. };
  5322. $scope.openDatePicker = function ($event, item, openParam) {
  5323. $event.preventDefault();
  5324. $event.stopPropagation();
  5325. item[openParam] = !item[openParam];
  5326. };
  5327. $scope.getHistory = function (item) {
  5328. if (!item.history) {
  5329. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5330. item.history = data;
  5331. });
  5332. }
  5333. };
  5334. $scope.isValid = function (item, withSteps) {
  5335. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5336. if (!withSteps || !bool)
  5337. return bool;
  5338. angular.forEach(item.replies, function (r, i) {
  5339. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5340. });
  5341. return bool;
  5342. };
  5343. $scope.onReplyClick = function (item, withSteps) {
  5344. if (item.vendFromDate instanceof Date) {
  5345. item.vendFromDate = item.vendFromDate.getTime();
  5346. }
  5347. if (item.vendToDate instanceof Date) {
  5348. item.vendToDate = item.vendToDate.getTime();
  5349. }
  5350. if (item.vendFromDate > item.vendToDate) {
  5351. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5352. return;
  5353. }
  5354. var replies = [];
  5355. angular.forEach(item.replies, function (r, i) {
  5356. if ((i > 0 ? r.lapQty : 1) || r.price)
  5357. replies.push(r);
  5358. });
  5359. item.replies = replies;
  5360. if (withSteps) {
  5361. PurcInquiry.reply({itemId: item.id}, item, function () {
  5362. toaster.pop('info', '提示', '报价成功');
  5363. loadData();
  5364. }, function (response) {
  5365. toaster.pop('error', '报价失败', response.data);
  5366. });
  5367. }
  5368. };
  5369. }]);
  5370. // 询价单明细(发出)
  5371. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, CurrentRole) {
  5372. // 获取当前用户是否为普通用户
  5373. CurrentRole.isUser({}, {}, function (data) {
  5374. $scope.isUser = data.isUser;
  5375. });
  5376. var loadData = function () {
  5377. PurchaseInquiry.detail({id: $stateParams.id}, {},function (data) {
  5378. $scope.inquiry = data;
  5379. },function (response) {
  5380. toaster.pop('error', '提示', response.data);
  5381. });
  5382. };
  5383. loadData();
  5384. $scope.getMinDate = function (item) {
  5385. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5386. };
  5387. $scope.nowDate = new Date().getTime();
  5388. $scope.addStep = function (inquiryItem) {
  5389. if (inquiryItem.replies.length >= 10) {
  5390. toaster.pop('warning', '提示', '最多支持10个分段!');
  5391. } else
  5392. inquiryItem.replies.push({});
  5393. };
  5394. $scope.removeStep = function (inquiryItem, stepIndex) {
  5395. inquiryItem.replies.splice(stepIndex, 1);
  5396. };
  5397. $scope.openDatePicker = function ($event, item, openParam) {
  5398. $event.preventDefault();
  5399. $event.stopPropagation();
  5400. item[openParam] = !item[openParam];
  5401. };
  5402. $scope.getHistory = function (item) {
  5403. if (!item.history) {
  5404. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5405. item.history = data;
  5406. });
  5407. }
  5408. };
  5409. $scope.isValid = function (item, withSteps) {
  5410. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5411. if (!withSteps || !bool)
  5412. return bool;
  5413. angular.forEach(item.replies, function (r, i) {
  5414. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5415. });
  5416. return bool;
  5417. };
  5418. $scope.onReplyClick = function (item, withSteps) {
  5419. if (item.vendFromDate instanceof Date) {
  5420. item.vendFromDate = item.vendFromDate.getTime();
  5421. }
  5422. if (item.vendToDate instanceof Date) {
  5423. item.vendToDate = item.vendToDate.getTime();
  5424. }
  5425. if (item.vendFromDate > item.vendToDate) {
  5426. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5427. return;
  5428. }
  5429. var replies = [];
  5430. angular.forEach(item.replies, function (r, i) {
  5431. if ((i > 0 ? r.lapQty : 1) || r.price)
  5432. replies.push(r);
  5433. });
  5434. item.replies = replies;
  5435. if (withSteps) {
  5436. PurcInquiry.reply({itemId: item.id}, item, function () {
  5437. toaster.pop('info', '提示', '报价成功');
  5438. loadData();
  5439. }, function (response) {
  5440. toaster.pop('error', '报价失败', response.data);
  5441. });
  5442. }
  5443. };
  5444. // 采纳
  5445. $scope.accept = function (id) {
  5446. PurchaseInquiry.accept({id: id}, {}, function (data) {
  5447. if (data.success) {
  5448. toaster.pop('success', '提示', data.success);
  5449. loadData();
  5450. }
  5451. if (data.error) {
  5452. toaster.pop('error', '提示', data.error);
  5453. }
  5454. }, function (response) {
  5455. toaster.pop('error', '提示', response.data);
  5456. })
  5457. };
  5458. // 拒绝
  5459. $scope.refuse = function (id) {
  5460. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  5461. if (data.success) {
  5462. toaster.pop('success', '提示', data.success);
  5463. loadData();
  5464. }
  5465. if (data.error) {
  5466. toaster.pop('error', '提示', data.error);
  5467. }
  5468. }, function (response) {
  5469. toaster.pop('error', '提示', response.data);
  5470. })
  5471. }
  5472. }]);
  5473. // 模具询价管理
  5474. app.controller('SaleInquiryMouldCtrl', ['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', 'PurcInquiryMouldSql', 'CurrentRole', function ($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload, PurcInquiryMouldSql, CurrentRole) {
  5475. BaseService.scrollBackToTop();
  5476. // 获取当前用户是否为普通用户
  5477. CurrentRole.isUser({}, {}, function (data) {
  5478. $scope.isUser = data.isUser;
  5479. });
  5480. $scope.active = 'todo';
  5481. $scope.agreedText = '全部';
  5482. $scope.dateZoneText = '不限';
  5483. $scope.condition = {dateZone: 1};
  5484. /* 时间筛选初始化*/
  5485. var fromDate = new Date();
  5486. var toDate = new Date();
  5487. fromDate.setMonth(fromDate.getMonth() - 1);
  5488. fromDate.setHours(0, 0, 0, 0);
  5489. toDate.setHours(23, 59, 59, 999);
  5490. $scope.condition.dateFrom = fromDate;
  5491. $scope.condition.dateTo = toDate;
  5492. var inquiryMould_copy = {};
  5493. $scope.changeAgreed = function (agreed) {
  5494. $scope.condition.agreed = agreed;
  5495. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  5496. $scope.condition.$agreedOpen = false;
  5497. };
  5498. $scope.changeDateZone = function (zone) {
  5499. $scope.condition.dateZone = zone;
  5500. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5501. $scope.condition.$dateZoneOpen = false;
  5502. getDateCondition(zone, $scope.condition);
  5503. $scope.tableParams.page(1);
  5504. $scope.tableParams.reload();
  5505. };
  5506. $scope.setActive = function (state) {
  5507. if ($scope.active != state) {
  5508. $scope.active = state;
  5509. if ($scope.tableParams.page() == 1) {
  5510. $scope.tableParams.reload();
  5511. } else {
  5512. $scope.tableParams.page(1);
  5513. }
  5514. }
  5515. };
  5516. var getService = function () {
  5517. if ($scope.keyword) {
  5518. return PurcInquiryMould;
  5519. } else {
  5520. return PurcInquiryMouldSql;
  5521. }
  5522. };
  5523. $scope.tableParams = new ngTableParams({
  5524. page: 1,
  5525. count: 5
  5526. }, {
  5527. total: 0,
  5528. counts: [5, 10, 25, 50],
  5529. getData: function ($defer, params) {
  5530. $scope.loading = true;
  5531. var pageParams = params.url();
  5532. var realActive = {};
  5533. pageParams.searchFilter = {
  5534. keyword: $scope.keyword,
  5535. fromDate: getDateTime($scope.condition.dateFrom),
  5536. endDate: getDateTime($scope.condition.dateTo)
  5537. };
  5538. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  5539. $scope.loading = false;
  5540. // 用来验证价格修改
  5541. var mould = page.content;
  5542. inquiryMould_copy = angular.copy(mould);
  5543. if (page) {
  5544. params.total(page.totalElement);
  5545. $defer.resolve(page.content);
  5546. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词 $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5547. }
  5548. }, function (response) {
  5549. $scope.loading = false;
  5550. toaster.pop('error', '数据加载失败', response.data);
  5551. });
  5552. }
  5553. });
  5554. //获得各分类未阅读数量
  5555. var getUnreadCount = function () {
  5556. PurcInquiryMould.getUnreadCount(null, function(data){
  5557. $scope.unread = data;
  5558. });
  5559. };
  5560. getUnreadCount();
  5561. //设置单据已读
  5562. $scope.setOrdersRead = function (id) {
  5563. // 如果单据本身已读,则不发送请求修改数据
  5564. if (!$scope.isUnread(id)){
  5565. return;
  5566. }
  5567. var sourceId = [];
  5568. sourceId.push(id);
  5569. PurcInquiryMould.setRead({}, sourceId, function (message) {
  5570. // $scope.getUnreadIds();
  5571. getUnreadCount();
  5572. });
  5573. };
  5574. $scope.setOrdersReadByState = function () {
  5575. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  5576. return;
  5577. }
  5578. PurcInquiryMould.setReadByState({}, function () {
  5579. getUnreadIds();
  5580. getUnreadCount();
  5581. });
  5582. };
  5583. //获取未读单据id
  5584. var getUnreadIds = function (){
  5585. PurcInquiryMould.getUnreadIds({}, "", function (message) {
  5586. $scope.unreadCode = message.content;
  5587. });
  5588. };
  5589. getUnreadIds();
  5590. //判断单据是否未读
  5591. $scope.isUnread = function (id){
  5592. for (var i in $scope.unreadCode) {
  5593. if (id == $scope.unreadCode[i]) {
  5594. return true;
  5595. }
  5596. }
  5597. };
  5598. $scope.getMinDate = function (item) {
  5599. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  5600. };
  5601. $scope.replyPrices = [];
  5602. $scope.replyPrices.push(true);
  5603. // 取消
  5604. $scope.reload = function () {
  5605. $scope.tableParams.reload();
  5606. $scope.canSave = false;
  5607. }
  5608. // 能否保存设置
  5609. $scope.canSave = false;
  5610. // items价格验证
  5611. $scope.verifyItems = function (price, reply) {
  5612. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  5613. if (regex.test(price) && price != 0) {
  5614. if (price != reply) {
  5615. $scope.canSave = true;
  5616. } else {
  5617. $scope.canSave = false;
  5618. }
  5619. } else {
  5620. $scope.canSave = false;
  5621. }
  5622. }
  5623. // prod下prods价格验证
  5624. $scope.verifyProds = function (price, reply) {
  5625. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5626. if (regex.test(price) && price != 0) {
  5627. if (price != reply) {
  5628. $scope.canSave = true;
  5629. } else {
  5630. $scope.canSave = false;
  5631. }
  5632. } else {
  5633. $scope.canSave = false;
  5634. }
  5635. }
  5636. //有价格为0或者不符合正则式,则不能报价
  5637. $scope.notZero = function (mould) {
  5638. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5639. angular.forEach(mould.inquiryMouldItems, function (item) {
  5640. if (item.price == 0 || !regex.test(item.price)) {
  5641. $scope.canSave = false;
  5642. }
  5643. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5644. if (detail.price == 0 || !regex.test(detail.price)) {
  5645. $scope.canSave = false;
  5646. }
  5647. })
  5648. });
  5649. }
  5650. $scope.blurPrice = function (price) {
  5651. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5652. if (!regex.test(price)) {
  5653. toaster.pop('warning', '格式错误', '请输入有效价格');
  5654. }
  5655. }
  5656. // 获取历史报价
  5657. $scope.getHistory = function (mould) {
  5658. if (!mould.history) {
  5659. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  5660. $scope.historyShow = true;
  5661. mould.history = data;
  5662. },function (response) {
  5663. $scope.historyShow = false;
  5664. });
  5665. }
  5666. };
  5667. var uploadAttach = function (mould, file) {
  5668. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5669. $scope.mould = mould;
  5670. $upload.upload({
  5671. url: 'sale/mould/' + mould.id + '/send',
  5672. method: 'POST',
  5673. file: file,
  5674. data: {
  5675. json: $scope.mould
  5676. }
  5677. }).success(function (res) {
  5678. $scope.mould.sellAttachs.push(res);
  5679. }).error(function (res) {
  5680. });
  5681. }
  5682. $scope.pushFile = function(mould, file) {
  5683. // var file = $scope.myFiles;
  5684. if (file.length > 0) {
  5685. for (var i = 0; i < file.length; i++) {
  5686. console.log(file[i].name);
  5687. var flag = true;
  5688. if (mould.sellAttachs.length > 0) {
  5689. for (var j = 0; j < mould.sellAttachs.length; j++) {
  5690. if (mould.sellAttachs[j].name == file[i].name
  5691. && mould.sellAttachs[j].size == file[i].size) {
  5692. flag = false;
  5693. break;
  5694. }
  5695. }
  5696. }
  5697. if (flag) {
  5698. uploadAttach(mould, file[i]);
  5699. $scope.canSave = true;
  5700. }
  5701. }
  5702. }
  5703. document.getElementById("inquiryMould.sellAttachs").value = "";
  5704. };
  5705. $scope.removeFile = function(mould, file) {
  5706. $scope.inquiryMould = mould;
  5707. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5708. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5709. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5710. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5711. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5712. }
  5713. }
  5714. }
  5715. };
  5716. // 保存并确认报价
  5717. $scope.onReplyClick = function (mould, withSteps) {
  5718. $scope.loading = true;
  5719. if (withSteps) {
  5720. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5721. $scope.loading = false;
  5722. toaster.pop('info', '提示', '报价成功');
  5723. $scope.tableParams.reload();
  5724. $scope.canSave = false;
  5725. }, function (response) {
  5726. $scope.loading = false;
  5727. toaster.pop('error', '报价失败', response.data);
  5728. });
  5729. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5730. }, function (response) {
  5731. });
  5732. } else {
  5733. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5734. $scope.loading = false;
  5735. toaster.pop('info', '提示', '保存成功');
  5736. $scope.tableParams.reload();
  5737. }, function (response) {
  5738. $scope.loading = false;
  5739. toaster.pop('error', '保存失败', response.data);
  5740. });
  5741. }
  5742. };
  5743. // 搜索框回车
  5744. $scope.onSearch = function () {
  5745. $scope.tableParams.page(1);
  5746. $scope.tableParams.reload();
  5747. };
  5748. $scope.openDatePicker = function ($event, item, openParam) {
  5749. $event.preventDefault();
  5750. $event.stopPropagation();
  5751. item[openParam] = !item[openParam];
  5752. };
  5753. $scope.openFilterDatePicker = function ($event, item, openParam) {
  5754. $event.preventDefault();
  5755. $event.stopPropagation();
  5756. item[openParam] = !item[openParam];
  5757. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  5758. $scope.tableParams.reload();
  5759. }
  5760. };
  5761. $scope.parseDate = function (dateStr) {
  5762. if (dateStr)
  5763. return Date.parse(dateStr, 'yyyy-MM-dd');
  5764. return new Date();
  5765. };
  5766. // 导出客户资料列表
  5767. $scope.exportXls = function () {
  5768. PurcInquiryMould.exportXls({}, {}, function (data) {
  5769. if (data.success){
  5770. window.location.href = 'sale/mould/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  5771. }
  5772. }, function (response) {
  5773. toaster.pop('error', '数据加载失败', response.data);
  5774. });
  5775. }
  5776. }]);
  5777. // 模具询价单明细
  5778. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould', '$filter', 'toaster', '$upload', 'CurrentRole', function ($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload, CurrentRole) {
  5779. // 获取当前用户是否为普通用户
  5780. CurrentRole.isUser({}, {}, function (data) {
  5781. $scope.isUser = data.isUser;
  5782. });
  5783. var inquiryMould_copy = {};
  5784. var loadData = function () {
  5785. PurcInquiryMould.getAll({id: $stateParams.id}, function (data) {
  5786. // 用来验证价格修改
  5787. inquiryMould_copy = angular.copy(data);
  5788. $scope.inquiryMould_copy = inquiryMould_copy;
  5789. $scope.newinquirymould = data;
  5790. var mould = data;
  5791. angular.forEach(mould.attachs, function (attach) {
  5792. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5793. });
  5794. $scope.inquiryMould = mould;
  5795. }, function (response) {
  5796. toaster.pop('error', '数据加载失败', response.data);
  5797. });
  5798. };
  5799. loadData();
  5800. $scope.getMinDate = function (item) {
  5801. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5802. };
  5803. // 取消
  5804. $scope.reload = function () {
  5805. loadData();
  5806. $scope.canSave = false;
  5807. }
  5808. //有价格为0,则不能报价
  5809. $scope.notZero = function (mould) {
  5810. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5811. angular.forEach(mould.inquiryMouldItems, function (item) {
  5812. if (item.price == 0 || !regex.test(item.price)) {
  5813. $scope.canSave = false;
  5814. }
  5815. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5816. if (detail.price == 0 || !regex.test(detail.price)) {
  5817. $scope.canSave = false;
  5818. }
  5819. })
  5820. });
  5821. }
  5822. $scope.blurPrice = function (price) {
  5823. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5824. if (!regex.test(price)) {
  5825. toaster.pop('warning', '格式错误', '请输入有效价格');
  5826. }
  5827. }
  5828. // 获取历史报价
  5829. $scope.getHistory = function (mould) {
  5830. if (!mould.history) {
  5831. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  5832. $scope.historyShow = true;
  5833. mould.history = data;
  5834. },function (response) {
  5835. $scope.historyShow = false;
  5836. //toaster.pop('error', '提示', response.data);
  5837. });
  5838. }
  5839. };
  5840. $scope.canSave = false;
  5841. // items价格验证
  5842. $scope.verifyItems = function (price, index) {
  5843. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5844. if (regex.test(price) && price != 0) {
  5845. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  5846. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  5847. $scope.canSave = true;
  5848. } else {
  5849. $scope.canSave = false;
  5850. }
  5851. } else {
  5852. $scope.canSave = false;
  5853. }
  5854. }
  5855. // prod下prods价格验证
  5856. $scope.verifyProds = function (price, index, parentIndex) {
  5857. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5858. if (regex.test(price) && price != 0) {
  5859. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  5860. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  5861. $scope.canSave = true;
  5862. } else {
  5863. $scope.canSave = false;
  5864. }
  5865. } else {
  5866. $scope.canSave = false;
  5867. }
  5868. }
  5869. // 上传附件
  5870. var uploadAttach = function(file) {
  5871. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5872. $scope.mould = $scope.inquiryMould;
  5873. $upload.upload({
  5874. url: 'sale/mould/' + $scope.mould.id + '/send',
  5875. method: 'POST',
  5876. file: file,
  5877. data: {
  5878. json: $scope.mould
  5879. }
  5880. }).success(function(attach){
  5881. if (attach){
  5882. $scope.inquiryMould.sellAttachs.push(attach);
  5883. }
  5884. }).error(function(res){
  5885. console.log("failure");
  5886. console.log(res);
  5887. });
  5888. }
  5889. $scope.pushFile = function(file) {
  5890. // var file = $scope.myFiles;
  5891. if (file.length > 0) {
  5892. for (var i = 0; i < file.length; i++) {
  5893. console.log(file[i].name);
  5894. var flag = true;
  5895. if ($scope.inquiryMould.sellAttachs.length > 0) {
  5896. for (var j = 0; j < $scope.inquiryMould.sellAttachs.length; j++) {
  5897. if ($scope.inquiryMould.sellAttachs[j].name == file[i].name
  5898. && $scope.inquiryMould.sellAttachs[j].size == file[i].size) {
  5899. flag = false;
  5900. break;
  5901. }
  5902. }
  5903. }
  5904. if (flag) {
  5905. uploadAttach(file[i]);
  5906. }
  5907. }
  5908. }
  5909. };
  5910. $scope.removeFile = function(file) {
  5911. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5912. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5913. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5914. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5915. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5916. document.getElementById("file").value = "";
  5917. }
  5918. }
  5919. }
  5920. };
  5921. $scope.onReplyClick = function (mould, withSteps) {
  5922. $scope.loading = true;
  5923. if (withSteps) {
  5924. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5925. $scope.loading = false;
  5926. toaster.pop('info', '提示', '报价成功');
  5927. loadData();
  5928. $scope.canSave = false;
  5929. }, function (response) {
  5930. $scope.loading = false;
  5931. toaster.pop('error', '报价失败', response.data);
  5932. });
  5933. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5934. }, function (response) {
  5935. });
  5936. } else {
  5937. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5938. $scope.loading = false;
  5939. toaster.pop('info', '提示', '保存成功');
  5940. loadData();
  5941. }, function (response) {
  5942. $scope.loading = false;
  5943. toaster.pop('error', '保存失败', response.data);
  5944. });
  5945. }
  5946. };
  5947. }]);
  5948. // 主动报价 - 列表
  5949. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', 'QuotationInfo', 'CurrentRole', function ($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope, QuotationInfo, CurrentRole) {
  5950. BaseService.scrollBackToTop();
  5951. // 获取当前用户是否为普通用户
  5952. CurrentRole.isUser({}, {}, function (data) {
  5953. $scope.isUser = data.isUser;
  5954. });
  5955. $rootScope.enteryStatus = false;
  5956. $scope.active = 'todo';
  5957. $scope.agreedText = '全部';
  5958. $scope.dateZoneText = '一个月内';
  5959. $scope.condition = {dateZone: 1};
  5960. /* 时间筛选初始化*/
  5961. var fromDate = new Date();
  5962. var toDate = new Date();
  5963. fromDate.setMonth(fromDate.getMonth() - 1);
  5964. fromDate.setHours(0, 0, 0, 0);
  5965. toDate.setHours(23, 59, 59, 999);
  5966. $scope.condition.dateFrom = fromDate;
  5967. $scope.condition.dateTo = toDate;
  5968. $scope.changeDateZone = function (zone) {
  5969. $scope.condition.dateZone = zone;
  5970. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5971. $scope.condition.$dateZoneOpen = false;
  5972. getDateCondition(zone, $scope.condition);
  5973. $scope.tableParams.page(1);
  5974. $scope.tableParams.reload();
  5975. };
  5976. $scope.setActive = function (state) {
  5977. if ($scope.active != state) {
  5978. $scope.active = state;
  5979. if ($scope.tableParams.page() == 1)
  5980. $scope.tableParams.reload();
  5981. else
  5982. $scope.tableParams.page(1);
  5983. }
  5984. };
  5985. $scope.searchMethod = false;
  5986. var getService = function () {
  5987. return $scope.searchMethod ? Quotation : QuotationInfo;
  5988. };
  5989. $scope.tableParams = new ngTableParams({
  5990. page: 1,
  5991. count: 20,
  5992. sorting: {
  5993. 'date': 'desc'
  5994. }
  5995. }, {
  5996. total: 0,
  5997. counts: [5, 10, 25, 50],
  5998. getData: function ($defer, params) {
  5999. $scope.loading = true;
  6000. var pageParams = params.url();
  6001. pageParams.searchFilter = {
  6002. keyword: $scope.keyword,
  6003. fromDate: getDateTime($scope.condition.dateFrom),
  6004. endDate: getDateTime($scope.condition.dateTo)
  6005. };
  6006. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6007. $scope.loading = false;
  6008. if (page) {
  6009. params.total(page.totalElement);
  6010. $defer.resolve(page.content);
  6011. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6012. }
  6013. }, function (response) {
  6014. $scope.loading = false;
  6015. toaster.pop('error', '数据加载失败', response.data);
  6016. });
  6017. }
  6018. });
  6019. $scope.openDatePicker = function ($event, item, openParam) {
  6020. $event.preventDefault();
  6021. $event.stopPropagation();
  6022. item[openParam] = !item[openParam];
  6023. };
  6024. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6025. $event.preventDefault();
  6026. $event.stopPropagation();
  6027. item[openParam] = !item[openParam];
  6028. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6029. $scope.tableParams.reload();
  6030. }
  6031. };
  6032. $scope.getHistory = function (item) {
  6033. if (!item.history) {
  6034. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  6035. item.history = data;
  6036. });
  6037. }
  6038. };
  6039. $scope.isValid = function (item, withSteps) {
  6040. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  6041. if (!withSteps || !bool)
  6042. return bool;
  6043. angular.forEach(item.replies, function (r, i) {
  6044. bool = (i > 0 ? r.lapQty : 1) && r.price;
  6045. });
  6046. return bool;
  6047. };
  6048. // 搜索框回车
  6049. $scope.onSearch = function (keyword) {
  6050. // 每次搜索重置获取数据方法
  6051. $scope.searchMethod = false;
  6052. if(keyword != null && keyword != '') {
  6053. $scope.searchMethod = true;
  6054. }
  6055. $scope.tableParams.page(1);
  6056. $scope.tableParams.reload();
  6057. };
  6058. // 导出
  6059. $scope.exportXls = function () {
  6060. Quotation.exportXls({}, {}, function (data) {
  6061. if (data.success){
  6062. window.location.href = 'sale/quotation/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  6063. }
  6064. }, function (response) {
  6065. toaster.pop('error', '数据加载失败', response.data);
  6066. });
  6067. }
  6068. }]);
  6069. // Controller 主动报价 - 新增
  6070. 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) {
  6071. BaseService.scrollBackToTop();
  6072. // 获取当前用户是否为普通用户
  6073. CurrentRole.isUser({}, {}, function (data) {
  6074. $scope.isUser = data.isUser;
  6075. });
  6076. var staticItem = null;
  6077. if (!angular.isUndefined($stateParams.id)) {// 查看模式
  6078. $scope.loading = true;
  6079. $rootScope.enteryStatus = true;
  6080. Quotation.getItem({id: $stateParams.id}, function (data) {
  6081. // data.$editing = false;
  6082. $scope.item = data;
  6083. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  6084. staticItem = angular.copy(data);
  6085. $scope.loading = false;
  6086. }, function (response) {
  6087. $scope.loading = false;
  6088. toaster.pop('error', '数据加载失败', response.data);
  6089. });
  6090. } else {// 新增模式
  6091. $rootScope.enteryStatus = false;
  6092. $scope.item = {
  6093. quotation: {
  6094. currency: 'RMB',
  6095. taxrate: 17,
  6096. },
  6097. product: {},
  6098. prices: [{lapQty: 0}],
  6099. minOrderQty: 1,
  6100. minPackQty: 1,
  6101. $endDateOpen: false,
  6102. $editing: true
  6103. };
  6104. }
  6105. $scope.getMinDate = function (item) {
  6106. return $filter('date')(new Date, 'yyyy-MM-dd');
  6107. };
  6108. //是否不能被点击
  6109. $scope.isDisabled = function () {
  6110. return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
  6111. }
  6112. $scope.openDatePicker = function ($event, openParam) {
  6113. $event.preventDefault();
  6114. $event.stopPropagation();
  6115. $scope.item.$endDateOpen = !openParam;
  6116. };
  6117. // 增加一个分段
  6118. $scope.addPrice = function () {
  6119. if ($scope.item.prices.length >= 10) {
  6120. toaster.pop('warning', '提示', '最多支持10个分段!');
  6121. } else
  6122. $scope.item.prices.push({});
  6123. };
  6124. // 删除一个分段
  6125. $scope.removePrice = function (index) {
  6126. $scope.item.prices.splice(index, 1);
  6127. };
  6128. // 查找客户
  6129. $scope.dbfindCust = function () {
  6130. if ($scope.item.$editing) {
  6131. var modalInstance = $modal.open({
  6132. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  6133. controller: 'DbfindCustCtrl',
  6134. size: 'lg',
  6135. resolve: {}
  6136. });
  6137. modalInstance.result.then(function (data) {
  6138. $scope.item.quotation.cust = data.myEnterprise;
  6139. $scope.item.quotation.custUser = data.myUser;
  6140. $scope.item.product = null;
  6141. }, function () {
  6142. });
  6143. }
  6144. };
  6145. // 赋值客户信息
  6146. if ($rootScope.custuu) {
  6147. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function (data) {
  6148. $scope.item.quotation.cust = data.myEnterprise;
  6149. $scope.item.quotation.custUser = data.myUser;
  6150. })
  6151. }
  6152. // 赋值物料信息
  6153. if ($rootScope.prodId) {
  6154. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  6155. $scope.item.product.code = data.code;
  6156. $scope.item.product.title = data.title;
  6157. $scope.item.product.spec = data.spec;
  6158. $scope.item.product.unit = data.unit;
  6159. $scope.item.product.id = data.id;
  6160. }, function (response) {
  6161. });
  6162. }
  6163. // 查找客户物料
  6164. $scope.dbfindCustProd = function () {
  6165. if ($scope.item.$editing) {
  6166. if ($scope.item.quotation.cust) {
  6167. var modalInstance = $modal.open({
  6168. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  6169. controller: 'DbfindCustProdCtrl',
  6170. size: 'lg',
  6171. resolve: {
  6172. custUU: function () {
  6173. return $scope.item.quotation.cust.uu
  6174. }
  6175. }
  6176. });
  6177. modalInstance.result.then(function (data) {
  6178. $scope.item.product = data;
  6179. }, function () {
  6180. });
  6181. } else {
  6182. toaster.pop('error', '错误', '请先选择客户');
  6183. }
  6184. }
  6185. };
  6186. // 根据传入的询价相关的信息封装成报价需要的信息
  6187. if ($stateParams.inquiryItem != null) {
  6188. var item = $stateParams.inquiryItem;
  6189. $scope.item.quotation.cust = item.inquiry.enterprise;
  6190. $scope.item.quotation.custUser = item.inquiry.recorderUser;
  6191. $scope.item.quotation.custUserUU = item.inquiry.recorderUU;
  6192. if (item.product == null || item.product.id == null) {
  6193. toaster.pop('info', '暂未匹配到物料信息,请手动选择');
  6194. } else {
  6195. $scope.item.product = item.product;
  6196. if (item.replies.length > 0) {
  6197. $scope.item.prices = item.replies;
  6198. angular.forEach($scope.item.prices, function(price) {
  6199. price.id = null;
  6200. });
  6201. }
  6202. $scope.item.quotation.taxrate = item.taxrate;
  6203. $scope.item.minPackQty = item.minPackQty;
  6204. $scope.item.minOrderQty = item.minOrderQty;
  6205. $scope.item.leadtime = item.leadtime;
  6206. $scope.item.quotation.currency = item.currency;
  6207. }
  6208. }
  6209. // 保存
  6210. $scope.save = function () {
  6211. var valid = true;
  6212. angular.forEach($scope.item.prices, function(price, $index) {
  6213. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6214. valid = false;
  6215. }
  6216. });
  6217. if (!valid) {
  6218. toaster.pop('info', '提示', '分段数量请保持递增!');
  6219. } else {
  6220. $scope.loading = true;
  6221. if (!$scope.item.quotation.code) //新增,设单号
  6222. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6223. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6224. if ($scope.item.quotation.custUserUU == null) {
  6225. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6226. }
  6227. $scope.item.productId = $scope.item.product.id;
  6228. Quotation.save({}, $scope.item, function (data) {
  6229. $scope.loading = false;
  6230. $scope.item = data;
  6231. toaster.pop('success', '成功', '保存成功');
  6232. if ($stateParams.id)
  6233. window.location.reload();
  6234. else
  6235. window.location.hash = '#/sale/quotation/list';
  6236. }, function (response) {
  6237. $scope.loading = false;
  6238. toaster.pop('error', '保存失败', response.data);
  6239. });
  6240. }
  6241. };
  6242. // 更新
  6243. $scope.update = function () {
  6244. $scope.item.$editing = true;
  6245. };
  6246. // 取消
  6247. $scope.cancel = function () {
  6248. $scope.item.$editing = false;
  6249. $scope.item = angular.copy(staticItem);
  6250. };
  6251. // 提交
  6252. $scope.submit = function () {
  6253. var valid = true;
  6254. angular.forEach($scope.item.prices, function(price, $index) {
  6255. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6256. valid = false;
  6257. }
  6258. });
  6259. if (!valid) {
  6260. toaster.pop('info', '提示', '分段数量请保持递增!');
  6261. } else {
  6262. $scope.loading = true;
  6263. if (!$scope.item.quotation.code) //新增,设单号
  6264. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6265. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6266. if ($scope.item.quotation.custUserUU == null) {
  6267. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6268. }
  6269. $scope.item.productId = $scope.item.product.id;
  6270. // $scope.item.quotation.status = 101;//已提交
  6271. if ($scope.item.quotation.date instanceof Date) {
  6272. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  6273. }
  6274. if ($scope.item.quotation.endDate instanceof Date) {
  6275. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  6276. }
  6277. Quotation.submit({}, $scope.item, function (data) {
  6278. $scope.loading = false;
  6279. $scope.item = data;
  6280. toaster.pop('success', '成功', '提交成功');
  6281. // window.location.hash = '#/sale/quotation/' + data.id;
  6282. window.location.hash = '#/sale/quotation/list';
  6283. }, function (response) {
  6284. $scope.loading = false;
  6285. toaster.pop('error', '保存失败', response.data);
  6286. });
  6287. }
  6288. };
  6289. $scope.deleteById = function (id) {
  6290. Quotation.deleteById({id: id}, {}, function (data) {
  6291. window.location.href = "#/sale/quotation/list";
  6292. }, function (response) {
  6293. toaster.pop('error', '提示', response.data);
  6294. })
  6295. }
  6296. }]);
  6297. // 查找客户
  6298. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function ($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance) {
  6299. BaseService.scrollBackToTop();
  6300. $scope.tableParams = new ngTableParams({
  6301. page: 1,
  6302. count: 20
  6303. }, {
  6304. total: 0,
  6305. counts: [5, 10, 25, 50],
  6306. getData: function ($defer, params) {
  6307. $scope.loading = true;
  6308. var pageParams = params.url();
  6309. pageParams.keyword = $scope.keyword;
  6310. Customer.get(BaseService.parseParams(pageParams), function (page) {
  6311. $scope.loading = false;
  6312. if (page) {
  6313. params.total(page.totalElement);
  6314. $defer.resolve(page.content);
  6315. }
  6316. $scope.totalCount = page.totalElement;
  6317. }, function (response) {
  6318. $scope.loading = false;
  6319. toaster.pop('error', '数据加载失败', response.data);
  6320. });
  6321. }
  6322. });
  6323. $scope.onSearch = function () {
  6324. $scope.tableParams.page(1);
  6325. $scope.tableParams.reload();
  6326. };
  6327. $scope.cancel = function () {
  6328. $modalInstance.dismiss();
  6329. };
  6330. $scope.check = function (cust) {
  6331. $modalInstance.close(cust);
  6332. };
  6333. }]);
  6334. // 查找客户物料
  6335. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function ($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU) {
  6336. BaseService.scrollBackToTop();
  6337. $scope.tableParams = new ngTableParams({
  6338. page: 1,
  6339. count: 20
  6340. }, {
  6341. total: 0,
  6342. counts: [5, 10, 25, 50],
  6343. getData: function ($defer, params) {
  6344. $scope.loading = true;
  6345. var pageParams = params.url();
  6346. pageParams.keyword = $scope.keyword;
  6347. pageParams.custUU = custUU;
  6348. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  6349. $scope.loading = false;
  6350. if (page) {
  6351. params.total(page.totalElement);
  6352. $defer.resolve(page.content);
  6353. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6354. }
  6355. }, function (response) {
  6356. $scope.loading = false;
  6357. toaster.pop('error', '数据加载失败', response.data);
  6358. });
  6359. }
  6360. });
  6361. // 取消
  6362. $scope.cancel = function () {
  6363. $modalInstance.dismiss();
  6364. };
  6365. // 选择
  6366. $scope.check = function (cust) {
  6367. $modalInstance.close(cust);
  6368. };
  6369. // 搜索框回车
  6370. $scope.onSearch = function () {
  6371. $scope.tableParams.page(1);
  6372. $scope.tableParams.reload();
  6373. };
  6374. }]);
  6375. // 查找供应商
  6376. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', '$rootScope', function ($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope) {
  6377. BaseService.scrollBackToTop();
  6378. // 搜索框回车
  6379. $scope.onSearch = function (keyword) {
  6380. $scope.keyword = keyword;
  6381. $scope.tableParams.page(1);
  6382. $scope.tableParams.reload();
  6383. };
  6384. $scope.tableParams = new ngTableParams({
  6385. page: 1,
  6386. count: 20
  6387. }, {
  6388. total: 0,
  6389. counts: [10, 25, 50, 100],
  6390. getData: function ($defer, params) {
  6391. $scope.loading = true;
  6392. var pageParams = params.url();
  6393. pageParams.keyword = $scope.keyword;
  6394. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  6395. $scope.loading = false;
  6396. if (page) {
  6397. params.total(page.totalElement);
  6398. $defer.resolve(page.content);
  6399. // 添加供应商时,将已存在的选中
  6400. if ($rootScope.tenderVendor) {
  6401. angular.forEach(page.content, function (vendor) {
  6402. for (var i = 0; i < $rootScope.tenderVendor.length; i++) {
  6403. vendor.checked = false;
  6404. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  6405. vendor.checked = true;
  6406. break;
  6407. }
  6408. }
  6409. });
  6410. }
  6411. }
  6412. $scope.totalCount = page.totalElement;
  6413. }, function (response) {
  6414. $scope.loading = false;
  6415. toaster.pop('error', '数据加载失败', response.data);
  6416. });
  6417. }
  6418. });
  6419. $scope.cancel = function () {
  6420. $modalInstance.dismiss();
  6421. };
  6422. $scope.checks = {
  6423. checked: false
  6424. };// 全选框
  6425. $scope.checkAll = function () {
  6426. angular.forEach($scope.tableParams.data, function (vendor) {
  6427. vendor.checked = $scope.checks.checked;
  6428. });
  6429. };
  6430. // 单选
  6431. $scope.checkOne = function (vendor) {
  6432. vendor.checked = true;
  6433. var checked = true;
  6434. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  6435. if (!message.checked) {
  6436. checked = false;
  6437. }
  6438. });
  6439. $scope.checks.checked = checked;
  6440. };
  6441. // 单反选
  6442. $scope.unCheckOne = function (vendor) {
  6443. vendor.checked = false;
  6444. $scope.checks.checked = false;
  6445. };
  6446. $scope.close = function () {
  6447. var vendors = [];
  6448. angular.forEach($scope.tableParams.data, function (vendor) {
  6449. if (vendor.checked) {
  6450. vendors.push(vendor);
  6451. $modalInstance.close(vendors);
  6452. }
  6453. });
  6454. };
  6455. }]);
  6456. // 发货提醒
  6457. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', '$modal', 'SaleTruck', 'Symbol', '$state', '$timeout', 'PurcNoticeInfo', 'token', 'CurrentRole', function ($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, $modal, SaleTruck, Symbol, $state, $timeout, PurcNoticeInfo, token, CurrentRole) {
  6458. BaseService.scrollBackToTop();
  6459. // 获取当前用户是否为普通用户
  6460. CurrentRole.isUser({}, {}, function (data) {
  6461. $scope.isUser = data.isUser;
  6462. });
  6463. // 用来记录已经选择的id
  6464. $rootScope.ids = [];
  6465. $scope.active = 'todo';
  6466. $scope.currency = Symbol.currency;
  6467. $scope.dateZoneText = '不限';
  6468. $scope.condition = {dateZone: 6};
  6469. $scope.searchStatus = false;
  6470. /* 时间筛选初始化*/
  6471. var fromDate = new Date();
  6472. var toDate = new Date();
  6473. fromDate.setMonth(fromDate.getMonth() - 6);
  6474. fromDate.setHours(0, 0, 0, 0);
  6475. toDate.setHours(23, 59, 59, 999);
  6476. $scope.condition.dateFrom = fromDate;
  6477. $scope.condition.dateTo = toDate;
  6478. $scope.changeDateZone = function (zone) {
  6479. $scope.condition.dateZone = zone;
  6480. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6481. $scope.condition.$dateZoneOpen = false;
  6482. getDateCondition(zone, $scope.condition);
  6483. $scope.tableParams.page(1);
  6484. $scope.tableParams.reload();
  6485. };
  6486. $scope.setActive = function (state) {
  6487. if ($scope.active != state) {
  6488. $scope.active = state;
  6489. if ($scope.tableParams.page() == 1)
  6490. $scope.tableParams.reload();
  6491. else
  6492. $scope.tableParams.page(1);
  6493. }
  6494. };
  6495. var getService = function () {
  6496. if ($scope.searchStatus) {
  6497. return PurcNotice;
  6498. }
  6499. return PurcNoticeInfo;
  6500. };
  6501. $scope.tableParams = new ngTableParams({
  6502. page: 1,
  6503. count: 20,
  6504. sorting: {
  6505. 'id': 'desc'
  6506. }
  6507. }, {
  6508. total: 0,
  6509. counts: [5, 10, 25, 50],
  6510. getData: function ($defer, params) {
  6511. $scope.loading = true;
  6512. var pageParams = params.url();
  6513. pageParams.keyword = $scope.keyword;
  6514. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6515. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6516. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6517. $scope.loading = false;
  6518. if (page) {
  6519. params.total(page.totalElement);
  6520. $defer.resolve(page.content);
  6521. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6522. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6523. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6524. $scope.checkall = true;
  6525. angular.forEach(page.content, function (notice) {
  6526. if ($rootScope.ids.indexOf(notice.id) > -1) {
  6527. notice.$selected = true;
  6528. } else {
  6529. $scope.checkall = false;
  6530. }
  6531. });
  6532. $scope.checkboxes = {
  6533. checked: $scope.checkall
  6534. };
  6535. }
  6536. }, function (response) {
  6537. $scope.loading = false;
  6538. toaster.pop('error', '数据加载失败', response.data);
  6539. });
  6540. }
  6541. });
  6542. //获得各分类未阅读数量
  6543. var getUnreadCount = function () {
  6544. PurcNotice.getUnreadCount(null, function (data) {
  6545. $scope.unread = data;
  6546. });
  6547. };
  6548. getUnreadCount();
  6549. //设置单据已读
  6550. $scope.setOrdersRead = function (id) {
  6551. // 如果单据本身已读,则不发送请求修改数据
  6552. if (!$scope.isUnread(id)){
  6553. return;
  6554. }
  6555. var sourceId = [];
  6556. sourceId.push(id);
  6557. PurcNotice.setRead({}, sourceId, function (message) {
  6558. // $scope.getUnreadIds();
  6559. getUnreadCount();
  6560. });
  6561. };
  6562. $scope.setOrdersReadByState = function () {
  6563. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  6564. return;
  6565. }
  6566. PurcNotice.setReadByState({}, function () {
  6567. getUnreadIds();
  6568. getUnreadCount();
  6569. });
  6570. };
  6571. var getUnreadIds = function () {
  6572. PurcNotice.getUnreadIds({}, "", function (message) {
  6573. $scope.unreadCode = message.content;
  6574. });
  6575. };
  6576. getUnreadIds();
  6577. $scope.isUnread = function (id) {
  6578. for (var i in $scope.unreadCode) {
  6579. if (id == $scope.unreadCode[i]) {
  6580. return true;
  6581. }
  6582. }
  6583. };
  6584. $scope.openDatePicker = function ($event, item, openParam) {
  6585. $event.preventDefault();
  6586. $event.stopPropagation();
  6587. item[openParam] = !item[openParam];
  6588. };
  6589. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6590. $event.preventDefault();
  6591. $event.stopPropagation();
  6592. item[openParam] = !item[openParam];
  6593. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6594. $scope.tableParams.reload();
  6595. }
  6596. };
  6597. //生成随机单号
  6598. $scope.autoCode = function (notice) {
  6599. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  6600. };
  6601. // 获取token信息 并打开询价模态框
  6602. $scope.getToken = function() {
  6603. token.info({userType: 'salenotice'}, {}, function(data) {
  6604. $scope.token = data.token;
  6605. }, function(response) {
  6606. toaster.pop('error', '提示', response.data);
  6607. });
  6608. }
  6609. //可送货日期
  6610. $scope.sendDate = function (notice) {
  6611. var stock = notice.orderItem.product.ltinstock || 0;
  6612. var de = new Date(notice.delivery);
  6613. if (stock == -1) {
  6614. de.setMonth(de.getMonth() - 1);
  6615. de.setDate(26);
  6616. } else if (stock >= 0) {
  6617. de.setDate(de.getDate() - stock - 1);
  6618. }
  6619. return de;
  6620. };
  6621. $scope.lockstatus = false;
  6622. // 锁定时间按钮5秒
  6623. $scope.lockClick = function (notice) {
  6624. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6625. } else if (!notice.send.code) {
  6626. } else {
  6627. $scope.lockstatus = true;
  6628. $timeout(function () {
  6629. $scope.lockstatus = false;
  6630. }, 5000);
  6631. }
  6632. };
  6633. var isSumbit = false;
  6634. $scope.onReplyClick = function (notice) {
  6635. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6636. toaster.pop('warning', '警告', '数量填写错误!');
  6637. } else if (!notice.send.code) {
  6638. toaster.pop('warning', '警告', '请填写发货单号!');
  6639. } else {
  6640. if (!isSumbit) {
  6641. var send = {
  6642. code: notice.send.code,
  6643. remark: notice.send.remark,
  6644. sendItems: [{qty: notice.send.qty}]
  6645. };
  6646. $scope.loading = true;
  6647. PurcNotice.save({id: notice.id, token: $scope.token}, send, function (data) {
  6648. $scope.loading = false;
  6649. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  6650. $state.go('sale.send_detail', {id: data.id});
  6651. }, function (response) {
  6652. $scope.loading = false;
  6653. toaster.pop('error', '发货失败', response.data);
  6654. });
  6655. isSumbit = true;
  6656. return true;
  6657. } else {
  6658. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6659. return false;
  6660. }
  6661. }
  6662. }
  6663. $scope.checkboxes = {
  6664. checked: false
  6665. };
  6666. angular.forEach($scope.tableParams.data, function (item) {
  6667. $scope.checkboxes.checked = false;
  6668. if($rootScope.ids.in_array(item.id)) {
  6669. $rootScope.ids.remove(item.id);
  6670. $scope.checkboxes.checked = true;
  6671. }
  6672. });
  6673. // 点击勾选全部的复选框
  6674. $scope.checkAll = function () {
  6675. angular.forEach($scope.tableParams.data, function (item) {
  6676. if (!item.waiting) {
  6677. item.$selected = $scope.checkboxes.checked;
  6678. if(item.$selected) {
  6679. if(!$rootScope.ids.in_array(item.id)) {
  6680. $rootScope.ids.push(item.id);
  6681. }
  6682. } else {
  6683. if($rootScope.ids.in_array(item.id)) {
  6684. $rootScope.ids.remove(item.id);
  6685. }
  6686. }
  6687. }
  6688. });
  6689. };
  6690. // 判断数组中是否存在某个对象
  6691. Array.prototype.S = String.fromCharCode(2);
  6692. Array.prototype.in_array = function(e) {
  6693. var r = new RegExp(this.S + e + this.S);
  6694. return (r.test(this.S + this.join(this.S) + this.S));
  6695. }
  6696. // 从数组中移除某个对象
  6697. Array.prototype.remove = function(val) {
  6698. var index = this.indexOf(val);
  6699. if (index > -1) {
  6700. this.splice(index, 1);
  6701. }
  6702. };
  6703. // 点击其中一个明细的复选框
  6704. $scope.checkOne = function (order) {
  6705. var result = true;
  6706. angular.forEach($scope.tableParams.data, function (item) {
  6707. if (item.$selected != true) {
  6708. result = false;
  6709. return;
  6710. }
  6711. });
  6712. if(order.$selected) {
  6713. if(!$rootScope.ids.in_array(order.id)) {
  6714. $rootScope.ids.push(order.id);
  6715. }
  6716. } else {
  6717. if($rootScope.ids.in_array(order.id)) {
  6718. $rootScope.ids.remove(order.id);
  6719. }
  6720. }
  6721. $scope.checkboxes = {
  6722. checked: result
  6723. };
  6724. };
  6725. // 打开批量发货模态框
  6726. var sendByBatch = function() {
  6727. var modalInstance = $modal.open({
  6728. animation: true,
  6729. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  6730. controller: 'SaleNoticeSendByBatchCtrl',
  6731. size: 'lg',
  6732. resolve: {
  6733. selectedNotices: function () {
  6734. return $scope.tableParams.data;
  6735. },
  6736. token: function() {
  6737. return $scope.token;
  6738. },
  6739. ids: function() {
  6740. return $rootScope.ids;
  6741. }
  6742. }
  6743. });
  6744. modalInstance.result.then(function () {
  6745. $scope.tableParams.reload();
  6746. }, function () {
  6747. });
  6748. }
  6749. $scope.sendByBatch = function () {
  6750. if($scope.token == null) {
  6751. token.info({userType: 'salenotice'}, {}, function(data) {
  6752. $scope.token = data.token;
  6753. sendByBatch();
  6754. }, function(response) {
  6755. toaster.pop('error', '提示', response.data);
  6756. });
  6757. } else {
  6758. sendByBatch();
  6759. }
  6760. };
  6761. $scope.getSends = function (notice) {
  6762. if (!notice.sends && notice.endQty > 0) {
  6763. notice.getSendsing = true;
  6764. notice.getSendsError = false;
  6765. PurcNotice.getSends({id: notice.id}, function (data) {
  6766. notice.getSendsing = false;
  6767. notice.getSendsError = false;
  6768. notice.sends = data;
  6769. }, function (response) {
  6770. notice.getSendsing = false;
  6771. notice.getSendsError = true;
  6772. notice.getErrorMessage = response.data;
  6773. });
  6774. }
  6775. };
  6776. // 搜索框回车
  6777. $scope.onSearch = function () {
  6778. $scope.searchStatus = true;
  6779. $scope.tableParams.page(1);
  6780. $scope.tableParams.reload();
  6781. };
  6782. // 选择查找日期
  6783. $scope.onDateCondition = function () {
  6784. $scope.tableParams.page(1);
  6785. $scope.tableParams.reload();
  6786. };
  6787. //货车功能
  6788. var truck = $rootScope.truck;
  6789. if (!truck) {
  6790. SaleTruck.query({}, function (data) {
  6791. $rootScope.truck = data;
  6792. });
  6793. }
  6794. $scope.isInTruck = function (noticeId) {
  6795. return truck.indexOf(noticeId) > -1;
  6796. };
  6797. $scope.addtoTruck = function (notice) {
  6798. SaleTruck.save({noticeId: notice.id}, {}, function (data) {
  6799. $rootScope.truck = data;
  6800. });
  6801. };
  6802. $scope.delFromTruck = function (notice) {
  6803. SaleTruck.remove({noticeId: notice.id}, {}, function (data) {
  6804. $rootScope.truck = data;
  6805. });
  6806. };
  6807. $scope.$watch(function () {
  6808. return $rootScope.truck;
  6809. }, function (data) {
  6810. truck = $rootScope.truck;
  6811. }, true);
  6812. $scope.$watch(function () {
  6813. return $rootScope.dataChanged;
  6814. }, function (data) {
  6815. data && ($scope.tableParams.reload());
  6816. }, true);
  6817. // 导出
  6818. $scope.exportXls = function () {
  6819. PurcNotice.exportXls({}, {}, function (data) {
  6820. if (data.success){
  6821. window.location.href = 'sale/notice/xls?_state='+$scope.active+
  6822. '&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  6823. }
  6824. }, function (response) {
  6825. toaster.pop('error', '数据加载失败', response.data);
  6826. });
  6827. }
  6828. }]);
  6829. 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) {
  6830. // $scope.notices = angular.copy(selectedNotices);
  6831. PurcNotice.findByIds({ids : angular.toJson(ids)}, function(data) {
  6832. $scope.notices = angular.copy(data);
  6833. }, function(res) {
  6834. toaster.pop('error', '提示', '发货提醒查询失败');
  6835. });
  6836. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  6837. $scope.saleSend = {
  6838. code: '',
  6839. payments: '',
  6840. currency: '',
  6841. custUU: null,
  6842. custUserUU: null,
  6843. remark: '批量发货',
  6844. sendItems: []
  6845. };
  6846. // 计算总数、总额
  6847. $scope.$watch(function () {
  6848. return $scope.notices;
  6849. }, function (data) {
  6850. var q = 0, t = 0;
  6851. if (data) {
  6852. angular.forEach(data, function (d) {
  6853. q += (d.thisSendQty || 0);
  6854. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  6855. });
  6856. }
  6857. $scope.totalQty = q;
  6858. $scope.total = t;
  6859. }, true);
  6860. /**
  6861. * 删除一个已选中的送货提醒
  6862. */
  6863. $scope.removeOne = function (index) {
  6864. $scope.notices.splice(index, 1);
  6865. };
  6866. $scope.lockstatus = false;
  6867. // 锁定时间按钮5秒
  6868. $scope.lockClick = function () {
  6869. $scope.lockstatus = true;
  6870. $timeout(function () {
  6871. $scope.lockstatus = false;
  6872. }, 5000);
  6873. }
  6874. $scope.lockstatus = false;
  6875. // 锁定时间按钮5秒
  6876. $scope.lockClick = function (notice) {
  6877. if ($scope.saleSend.code == '') {//送货单号为空
  6878. return;
  6879. } else {
  6880. $scope.lockstatus = true;
  6881. $timeout(function () {
  6882. $scope.lockstatus = false;
  6883. }, 5000);
  6884. }
  6885. };
  6886. var isSumbit = false;
  6887. //确认送货
  6888. $scope.sendByBatch = function () {
  6889. $scope.saleSend.sendItems = [];
  6890. if ($scope.saleSend.code == '') {//送货单号为空
  6891. toaster.pop('error', '错误', '请输入送货单号');
  6892. return;
  6893. }
  6894. var a = 0;
  6895. var num = 1;
  6896. var valid = true;
  6897. angular.forEach($scope.notices, function (item, key) {
  6898. if (a == 0) {//第一次
  6899. $scope.saleSend.currency = item.orderItem.order.currency;
  6900. $scope.saleSend.custUU = item.enUU;
  6901. $scope.saleSend.payments = item.orderItem.order.payments;
  6902. a = 1;
  6903. } else {//其他
  6904. if ($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  6905. if ($scope.saleSend.custUU != item.enUU) valid = false;
  6906. if ($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  6907. }
  6908. $scope.saleSend.sendItems.push({
  6909. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++
  6910. });
  6911. });
  6912. if (!valid) {
  6913. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  6914. } else {
  6915. if (!isSumbit) {
  6916. PurcNotice.sendByBatch({token: token}, $scope.saleSend, function (data) {
  6917. if(data.id) {
  6918. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  6919. $modalInstance.close('success');
  6920. $state.go('sale.send_detail', {id: data.id});
  6921. } else {
  6922. toaster.pop('error', '提示', '发货失败,请刷新页面重试');
  6923. }
  6924. }, function (response) {
  6925. toaster.pop('error', '错误', response.data);
  6926. });
  6927. isSumbit = true;
  6928. return true;
  6929. } else {
  6930. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6931. return false;
  6932. }
  6933. }
  6934. };
  6935. $scope.cancel = function () {
  6936. $modalInstance.dismiss();
  6937. };
  6938. }]);
  6939. /**
  6940. * 发货单
  6941. */
  6942. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'ReportService', function ($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService) {
  6943. BaseService.scrollBackToTop();
  6944. $scope.active = 'all';
  6945. $scope.currency = Symbol.currency;
  6946. $scope.dateZoneText = '不限';
  6947. $scope.condition = {dateZone: 1};
  6948. /* 时间筛选初始化*/
  6949. var fromDate = new Date();
  6950. var toDate = new Date();
  6951. fromDate.setMonth(fromDate.getMonth() - 1);
  6952. fromDate.setHours(0, 0, 0, 0);
  6953. toDate.setHours(23, 59, 59, 999);
  6954. $scope.condition.dateFrom = fromDate;
  6955. $scope.condition.dateTo = toDate;
  6956. $scope.changeDateZone = function (zone) {
  6957. $scope.condition.dateZone = zone;
  6958. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  6959. $scope.condition.$dateZoneOpen = false;
  6960. getDateCondition(zone, $scope.condition);
  6961. $scope.tableParams.page(1);
  6962. $scope.tableParams.reload();
  6963. };
  6964. $scope.setActive = function (state) {
  6965. if ($scope.active != state) {
  6966. $scope.active = state;
  6967. if ($scope.tableParams.page() == 1)
  6968. $scope.tableParams.reload();
  6969. else
  6970. $scope.tableParams.page(1);
  6971. }
  6972. };
  6973. var getService = function () {
  6974. return SaleSend;
  6975. };
  6976. $scope.tableParams = new ngTableParams({
  6977. page: 1,
  6978. count: 20,
  6979. sorting: {
  6980. date: 'desc'
  6981. }
  6982. }, {
  6983. total: 0,
  6984. counts: [5, 10, 25, 50],
  6985. getData: function ($defer, params) {
  6986. $scope.loading = true;
  6987. var pageParams = params.url();
  6988. pageParams.keyword = $scope.keyword;
  6989. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6990. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6991. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6992. $scope.loading = false;
  6993. if (page) {
  6994. params.total(page.totalElement);
  6995. $defer.resolve(page.content);
  6996. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6997. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6998. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6999. }
  7000. }, function (response) {
  7001. $scope.loading = false;
  7002. toaster.pop('error', '数据加载失败', response.data);
  7003. });
  7004. }
  7005. });
  7006. //打印 发货单
  7007. $scope.print = function (send) {
  7008. var newPage = window.open("about:blank");
  7009. SaleSend.printPermission({}, function () {
  7010. SaleSend.printCount({id: send.id}, {}); //增加打印此次
  7011. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id, newPage);
  7012. $scope.tableParams.reload();
  7013. }, function (response) {
  7014. newPage.close();
  7015. toaster.pop('error', '打印失败', response.data);
  7016. });
  7017. };
  7018. $scope.openDatePicker = function ($event, item, openParam) {
  7019. $event.preventDefault();
  7020. $event.stopPropagation();
  7021. item[openParam] = !item[openParam];
  7022. };
  7023. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7024. $event.preventDefault();
  7025. $event.stopPropagation();
  7026. item[openParam] = !item[openParam];
  7027. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7028. $scope.tableParams.reload();
  7029. }
  7030. };
  7031. // 搜索框回车
  7032. $scope.onSearch = function () {
  7033. $scope.tableParams.page(1);
  7034. $scope.tableParams.reload();
  7035. };
  7036. // 选择查找日期
  7037. $scope.onDateCondition = function () {
  7038. $scope.tableParams.page(1);
  7039. $scope.tableParams.reload();
  7040. };
  7041. $scope.exportXls = function () {
  7042. SaleSend.exportXls({}, {}, function (data) {
  7043. if (data.success){
  7044. window.location.href = 'sale/notice/sends/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7045. }
  7046. }, function (response) {
  7047. toaster.pop('error', '数据加载失败', response.data);
  7048. });
  7049. }
  7050. }]);
  7051. /**
  7052. * 发货单(包括发货条码维护)
  7053. */
  7054. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService', 'ngTableParams', 'Lodop', '$modal', 'CurrentRole', function ($scope, $stateParams, SaleSend, toaster, ReportService, ngTableParams, Lodop, $modal, CurrentRole) {
  7055. // 获取当前用户是否为普通用户
  7056. CurrentRole.isUser({}, {}, function (data) {
  7057. $scope.isUser = data.isUser;
  7058. });
  7059. var loading = true;
  7060. $scope.checkBarCode = [];
  7061. $scope.checkBoxCode = [];
  7062. var vm = $scope.vm = {};
  7063. $scope.getCheckedItems = {};
  7064. vm.editBar = false;
  7065. vm.showBarCode = [];
  7066. $scope.barCode = function () {
  7067. vm.editBar = !vm.editBar;
  7068. }
  7069. $scope.checkboxes = {
  7070. checked: false
  7071. };
  7072. $scope.checkbars = {
  7073. checked: false
  7074. };
  7075. // 点击勾选barCode全部的复选框
  7076. $scope.checkBarAll = function () {
  7077. angular.forEach($scope.checkBarCode, function (item, key) {
  7078. $scope.checkBarCode[key] = $scope.checkbars.checked;
  7079. });
  7080. };
  7081. //点击barCode单选
  7082. $scope.checkBarOne = function () {
  7083. var result = true;
  7084. angular.forEach($scope.checkBarCode, function (item, key) {
  7085. if (item != true) {
  7086. result = false;
  7087. return;
  7088. }
  7089. });
  7090. $scope.checkbars.checked = result;
  7091. }
  7092. // 点击boxCode全部的复选框
  7093. $scope.checkBoxAll = function () {
  7094. angular.forEach($scope.checkBoxCode, function (item, key) {
  7095. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  7096. });
  7097. };
  7098. //点击boxCode单选
  7099. $scope.checkBoxOne = function () {
  7100. var result = true;
  7101. angular.forEach($scope.checkBoxCode, function (item) {
  7102. if (item != true) {
  7103. result = false;
  7104. return;
  7105. }
  7106. });
  7107. $scope.checkboxes.checked = result;
  7108. }
  7109. /**
  7110. * 生成条码和箱号
  7111. */
  7112. $scope.generateBarCode = function (item) {
  7113. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  7114. $scope.getCheckedItems = [];
  7115. var warningdata = '';
  7116. angular.forEach($scope.checkBarCode, function (item, key) {
  7117. $scope.getCheckedItem = {};
  7118. if (item == true) {
  7119. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7120. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  7121. $scope.getCheckedItems.push($scope.getCheckedItem);
  7122. //判断是否生成过条码
  7123. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7124. warningdata += $scope.order.sendItems[key].number + ","
  7125. }
  7126. }
  7127. });
  7128. if ($scope.getCheckedItems.length == 0) {
  7129. toaster.pop('warning', '提示', '请勾选需要生成条码的明细行!');
  7130. return;
  7131. }
  7132. if (warningdata != '') {
  7133. if (!confirm('明细行序号:' + warningdata + "已经生成了条码,继续生成将清空原有条码?")) {
  7134. return;
  7135. }
  7136. }
  7137. SaleSend.generateBarcodes({id: $scope.order.id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7138. toaster.pop('success', '提示', '生成成功!');
  7139. loadData();
  7140. }, function (response) {
  7141. $scope.loading = false;
  7142. toaster.pop('error', '生成失败', response.data);
  7143. });
  7144. }
  7145. /**
  7146. * 打印条码和箱号
  7147. */
  7148. $scope.printCode = function (type) {
  7149. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7150. //勾选需要打印的行
  7151. $scope.getCheckedItems = [];
  7152. var warningdata = ''
  7153. angular.forEach($scope.checkBarCode, function (item, key) {
  7154. $scope.getCheckedItem = {};
  7155. if (item == true) {
  7156. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7157. $scope.getCheckedItems.push($scope.getCheckedItem);
  7158. //判断是否生成过条码
  7159. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7160. warningdata += $scope.order.sendItems[key].number + ","
  7161. }
  7162. }
  7163. });
  7164. if ($scope.getCheckedItems.length == 0) {
  7165. toaster.pop('warning', '提示', '请勾选需要打印的明细行!');
  7166. return;
  7167. }
  7168. if (warningdata == '') {
  7169. toaster.pop('warning', '提示', '明细行序号:' + warningdata + '未生成条码无法打印');
  7170. return;
  7171. }
  7172. //选择打印模板
  7173. var modalInstance = $modal.open({
  7174. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7175. controller: 'BarPrintModalCtrl',
  7176. resolve: {
  7177. typeItem: function () {
  7178. return {'type': type, 'id': $scope.order.id};
  7179. }
  7180. }
  7181. });
  7182. modalInstance.result.then(function (s) {
  7183. if (s) {
  7184. //获取打印数据
  7185. SaleSend.getPrintBarcodes({lpsId: s.tp_id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7186. if (s.type == 'print') {//判断选择是打印还是打印预览
  7187. lodopPrint(data.message, LODOP, type);
  7188. } else if (s.type == 'printPreview') {
  7189. lodopPrintPreview(data.message, LODOP, type);
  7190. }
  7191. }, function (response) {
  7192. toaster.pop('error', '获取打印数据失败', response.data);
  7193. });
  7194. }
  7195. });
  7196. };
  7197. //打印单个条码
  7198. $scope.printSingleCode = function (id) {
  7199. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7200. //选择打印模板
  7201. var modalInstance = $modal.open({
  7202. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7203. controller: 'BarPrintModalCtrl',
  7204. resolve: {
  7205. typeItem: function () {
  7206. return {'type': 'Bar', 'id': $scope.order.id};
  7207. }
  7208. }
  7209. });
  7210. modalInstance.result.then(function (s) {
  7211. if (s) {
  7212. //获取打印数据
  7213. SaleSend.getSPrintBarcode({lpsId: s.tp_id, bsnId: id}, function (data) {
  7214. if (s.type == 'print') {//判断选择是打印还是打印预览
  7215. lodopSPrint(data.message, LODOP);
  7216. } else if (s.type == 'printPreview') {
  7217. lodopSPrintPreview(data.message, LODOP);
  7218. }
  7219. }, function (response) {
  7220. toaster.pop('error', '获取打印数据失败', response.data);
  7221. });
  7222. }
  7223. });
  7224. }
  7225. var lodopSPrint = function (printStore, LODOP) {//单个条码打印
  7226. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7227. if (selectOrNot != -1) {
  7228. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7229. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7230. var strs = pagesize.split("*"); //字符分割
  7231. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7232. angular.forEach(printStore, function (data, index) {
  7233. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7234. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7235. if (data['LP_VALUETYPE'] == 'barcode') {
  7236. 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']);
  7237. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7238. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7239. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7240. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7241. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7242. } else if (data['LP_VALUETYPE'] == 'text') {
  7243. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7244. }
  7245. });
  7246. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7247. LODOP.PRINT();
  7248. }
  7249. };
  7250. var lodopSPrintPreview = function (printStore, LODOP) {//单个条码打印预览
  7251. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7252. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7253. var strs = pagesize.split("*"); //字符分割
  7254. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7255. angular.forEach(printStore, function (data, index) {
  7256. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7257. if (data['LP_VALUETYPE'] == 'barcode') {
  7258. 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']);
  7259. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7260. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7261. } else if (data['LP_VALUETYPE'] == 'text') {
  7262. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7263. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7264. }
  7265. });
  7266. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7267. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7268. LODOP.PREVIEW();//打印预览
  7269. };
  7270. var lodopPrint = function (printStore, LODOP, type) {//勾选发货单明细进行打印
  7271. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7272. if (selectOrNot != -1) {
  7273. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7274. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  7275. var strs = new Array(); //定义一数组
  7276. strs = pagesize.split("*"); //字符分割
  7277. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7278. var ids = new Array();
  7279. angular.forEach(printStore, function (value, key) {
  7280. //LODOP.NewPage();
  7281. angular.forEach(value['data'], function (record, key) {
  7282. angular.forEach(record['store'], function (data, index) {
  7283. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7284. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7285. if (data['LP_VALUETYPE'] == 'barcode') {
  7286. 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']);
  7287. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7288. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7289. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7290. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7291. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7292. } else if (data['LP_VALUETYPE'] == 'text') {
  7293. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7294. }
  7295. });
  7296. });
  7297. var o = new Object();
  7298. o['id'] = record['si_id']
  7299. ids.push(o);
  7300. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7301. LODOP.PRINT();
  7302. });
  7303. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7304. if (type == 'Bar') {
  7305. //更新打印状态
  7306. SaleSend.updatePrintStatus({}, ids, function (data) {
  7307. }, function (res) {
  7308. });
  7309. }
  7310. }
  7311. };
  7312. var lodopPrintPreview = function (printData, LODOP, type) {//打印预览
  7313. var ids = new Array();
  7314. angular.forEach(printData, function (record, index) {
  7315. angular.forEach(record['data'], function (value, index) {
  7316. LODOP.NewPage();
  7317. angular.forEach(value['store'], function (data, index) {
  7318. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7319. if (data['LP_VALUETYPE'] == 'barcode') {
  7320. 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']);
  7321. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7322. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7323. } else if (data['LP_VALUETYPE'] == 'text') {
  7324. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7325. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7326. }
  7327. });
  7328. });
  7329. var o = new Object();
  7330. o['id'] = record['si_id']
  7331. ids.push(o);
  7332. });
  7333. var pagesize = printData[0]['pagesize'];//获取标签的大小
  7334. var strs = new Array(); //定义一数组
  7335. strs = pagesize.split("*"); //字符分割
  7336. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7337. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7338. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7339. var times = LODOP.PREVIEW();//打印预览
  7340. if (times > 0) {//点击了打印预览内的打印按钮
  7341. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7342. if (type == 'Bar') {
  7343. //更新打印状态
  7344. SaleSend.updatePrintStatus({}, ids, function (data) {
  7345. loadData();
  7346. }, function (res) {
  7347. });
  7348. }
  7349. }
  7350. };
  7351. /**
  7352. * 查看条码按钮
  7353. */
  7354. $scope.showBarCode = function (number) {
  7355. $scope.keys = number;
  7356. for (var i = 0; i < vm.showBarCode.length; i++) {
  7357. if (i != number) {
  7358. vm.showBarCode[i] = false;
  7359. }
  7360. }
  7361. vm.showBarCode[number] = !vm.showBarCode[number];
  7362. $scope.barcodes = [];
  7363. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  7364. var getPage = function (page, size) {
  7365. if ($scope.barcodes) {
  7366. var result = {};
  7367. result.totalCount = $scope.barcodes.length;
  7368. result.content = $scope.barcodes.slice((page - 1) * size, page * size);
  7369. if ($scope.barcodes.length % size == 0) {
  7370. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  7371. } else {
  7372. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  7373. }
  7374. result.first = page == 1;
  7375. result.last = page == result.totalPage;
  7376. result.page = page;
  7377. result.next = page - 0 + 1;
  7378. result.pre = page - 1;
  7379. return result;
  7380. }
  7381. }
  7382. $scope.barData = getPage(1, 5);
  7383. $scope.first = function () {
  7384. $scope.barData = getPage($scope.barData.pre, 5);
  7385. }
  7386. $scope.last = function () {
  7387. $scope.barData = getPage($scope.barData.next, 5);
  7388. }
  7389. };
  7390. /**
  7391. * 更新外箱号
  7392. */
  7393. $scope.updateOutBox = function (item, number) {
  7394. if ($scope.oldoutBoxQty[number] == item.outBoxQty) {
  7395. } else {
  7396. if (item.outBoxQty > 0) {
  7397. if (!(item.outBoxQty % item.packageQty)) {
  7398. SaleSend.update({id: item.id}, item, function () {
  7399. toaster.pop('success', '提示', '保存成功!');
  7400. loadData();
  7401. }, function (response) {
  7402. $scope.loading = false;
  7403. toaster.pop('error', '回复失败', response.data);
  7404. })
  7405. } else {
  7406. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  7407. }
  7408. } else {
  7409. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7410. }
  7411. }
  7412. loadData();
  7413. };
  7414. /**
  7415. * 更新最小包数
  7416. */
  7417. $scope.updatePackage = function (item, number) {
  7418. if (item.packageQty == $scope.oldpackageQty[number]) {
  7419. } else {
  7420. if (item.orderItem.product.minPack != 0) {
  7421. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7422. if (!(item.packageQty % item.orderItem.product.minPack)) {
  7423. SaleSend.update({id: item.id}, item, function () {
  7424. toaster.pop('success', '提示', '保存成功!');
  7425. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7426. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7427. }
  7428. loadData();
  7429. }, function (response) {
  7430. $scope.loading = false;
  7431. toaster.pop('error', '回复失败', response.data);
  7432. })
  7433. } else {
  7434. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  7435. }
  7436. } else {
  7437. toaster.pop('warning', '提示', '请填写有效的数量!');
  7438. }
  7439. } else {
  7440. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7441. SaleSend.update({id: item.id}, item, function () {
  7442. toaster.pop('success', '提示', '保存成功!');
  7443. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7444. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7445. }
  7446. loadData();
  7447. }, function (response) {
  7448. $scope.loading = false;
  7449. toaster.pop('error', '回复失败', response.data);
  7450. })
  7451. } else {
  7452. toaster.pop('warning', '提示', '请填写有效的数量!');
  7453. }
  7454. }
  7455. }
  7456. loadData();
  7457. };
  7458. var loadData = function () {
  7459. SaleSend.getItem({id: $stateParams.id}, function (data) {
  7460. $scope.order = data;
  7461. var orderCount = $scope.order.sendItems.length;
  7462. $scope.oldpackageQty = [];
  7463. $scope.oldoutBoxQty = [];
  7464. var sum = 0;
  7465. vm.oldpackageQty = [];
  7466. angular.forEach(data.sendItems, function (value, key) {
  7467. //给showBarCode数组赋初值
  7468. if (vm.showBarCode.length < orderCount) {
  7469. vm.showBarCode.push(false);
  7470. }
  7471. if ($scope.checkBarCode.length < orderCount) {
  7472. $scope.checkBarCode.push(false);
  7473. }
  7474. if ($scope.checkBoxCode.length < orderCount) {
  7475. $scope.checkBoxCode.push(false);
  7476. }
  7477. //给个初值
  7478. if (!value.packageQty) {
  7479. value.packageQty = value.orderItem.product.minPack;
  7480. }
  7481. $scope.oldpackageQty.push(value.packageQty);
  7482. if (value.outBoxQty) {
  7483. $scope.oldoutBoxQty.push(value.outBoxQty);
  7484. }
  7485. sum += value.price * value.qty;
  7486. });
  7487. data.total = sum;
  7488. $scope.loading = false;
  7489. }, function (response) {
  7490. loading = false;
  7491. toaster.pop('error', '获取数据失败', response.data);
  7492. });
  7493. };
  7494. loadData();
  7495. }]);
  7496. app.controller('BarPrintModalCtrl', ['$scope', 'typeItem', 'SaleSend', 'toaster', '$modalInstance', function ($scope, typeItem, SaleSend, toaster, $modalInstance) {
  7497. $scope.typeItem = typeItem;
  7498. $scope.template = [];
  7499. $scope.choose = {};
  7500. //获取打印模板
  7501. SaleSend.getPrintTemplate({id: $scope.typeItem.id, type: $scope.typeItem.type}, function (data) {
  7502. if (data.message) {
  7503. $scope.template = data.message;
  7504. $scope.choose.tp_id = $scope.template[0].id;
  7505. }
  7506. }, function (res) {
  7507. toaster.pop('error', '获取模板错误', res.data);
  7508. });
  7509. $scope.print = function () {
  7510. $scope.choose.type = 'print';
  7511. $modalInstance.close($scope.choose);
  7512. };
  7513. $scope.printPreview = function () {
  7514. $scope.choose.type = 'printPreview';
  7515. $modalInstance.close($scope.choose);
  7516. }
  7517. $scope.cancel = function () {
  7518. $modalInstance.close();
  7519. }
  7520. }]);
  7521. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', 'CurrentRole', function ($scope, $stateParams, PurcSample, toaster, $modal, BaseService, CurrentRole) {
  7522. BaseService.scrollBackToTop();
  7523. // 获取当前用户是否为普通用户
  7524. CurrentRole.isUser({}, {}, function (data) {
  7525. $scope.isUser = data.isUser;
  7526. });
  7527. var loading = true;
  7528. var loadData = function () {
  7529. PurcSample.getItem({id: $stateParams.id}, function (data) {
  7530. $scope.sample = data;
  7531. if (!$scope.sample.sends) {
  7532. $scope.sample.getSendInfo = '加载中...';
  7533. PurcSample.getSend({id: $stateParams.id}, function (sendData) {
  7534. if (sendData) {
  7535. $scope.sample.getSendInfo = null;
  7536. $scope.sample.sends = sendData;
  7537. } else {
  7538. $scope.sample.getSendInfo = '无送样信息';
  7539. $scope.sample.sends = '无送样信息';
  7540. }
  7541. }, function (response) {
  7542. $scope.sample.getSendInfo = '加载失败!';
  7543. toaster.pop('error', '', response.data);
  7544. });
  7545. }
  7546. $scope.loading = false;
  7547. }, function (response) {
  7548. loading = false;
  7549. toaster.pop('error', '获取数据失败', response.data);
  7550. });
  7551. };
  7552. loadData();
  7553. $scope.openSend = function (index, sample) {
  7554. var modalInstance = $modal.open({
  7555. animation: true,
  7556. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7557. controller: 'SampleSendCtrl',
  7558. resolve: {
  7559. sampleItem: function () {
  7560. return sample;
  7561. }
  7562. }
  7563. });
  7564. modalInstance.result.then(function () {
  7565. toaster.pop('info', '提示', '送样成功');
  7566. $scope.tableParams.reload();
  7567. }, function () {
  7568. });
  7569. };
  7570. }]);
  7571. /**
  7572. * 客户打样申请
  7573. */
  7574. 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) {
  7575. BaseService.scrollBackToTop();
  7576. // 获取当前用户是否为普通用户
  7577. CurrentRole.isUser({}, {}, function (data) {
  7578. $scope.isUser = data.isUser;
  7579. });
  7580. if ($rootScope.active) {
  7581. $scope.active = $rootScope.active;
  7582. $rootScope.active = null;
  7583. } else {
  7584. $scope.active = 'todo';
  7585. }
  7586. $scope.agreedText = '全部';
  7587. $scope.dateZoneText = '一个月内';
  7588. $scope.condition = {dateZone: 1};
  7589. /*初始化筛选时间*/
  7590. var fromDate = new Date();
  7591. var toDate = new Date();
  7592. fromDate.setMonth(fromDate.getMonth() - 1);
  7593. fromDate.setHours(0, 0, 0, 0);
  7594. toDate.setHours(23, 59, 59, 999);
  7595. $scope.condition.dateFrom = fromDate;
  7596. $scope.condition.dateTo = toDate;
  7597. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7598. $scope.changeAgreed = function (agreed) {
  7599. $scope.condition.agreed = agreed;
  7600. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7601. $scope.condition.$agreedOpen = false;
  7602. };
  7603. $scope.changeDateZone = function (zone) {
  7604. $scope.condition.dateZone = zone;
  7605. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7606. $scope.condition.$dateZoneOpen = false;
  7607. getDateCondition(zone, $scope.condition);
  7608. $scope.tableParams.page(1);
  7609. $scope.tableParams.reload();
  7610. };
  7611. $scope.setActive = function (state) {
  7612. if ($scope.active != state) {
  7613. $scope.active = state;
  7614. if ($scope.tableParams.page() == 1)
  7615. $scope.tableParams.reload();
  7616. else
  7617. $scope.tableParams.page(1);
  7618. }
  7619. };
  7620. $scope.searchMethod = false;
  7621. var getService = function () {
  7622. return $scope.searchMethod ? PurcSample : PurcSampleInfo;
  7623. };
  7624. $scope.tableParams = new ngTableParams({
  7625. page: 1,
  7626. count: 20,
  7627. sorting: {
  7628. proofingDate: 'desc'
  7629. }
  7630. }, {
  7631. total: 0,
  7632. counts: [5, 10, 25, 50],
  7633. getData: function ($defer, params) {
  7634. $scope.loading = true;
  7635. var pageParams = params.url();
  7636. pageParams.searchFilter = {
  7637. keyword: $scope.keyword,
  7638. fromDate: getDateTime($scope.condition.dateFrom),
  7639. endDate: getDateTime($scope.condition.dateTo)
  7640. };
  7641. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7642. $scope.loading = false;
  7643. if (page) {
  7644. params.total(page.totalElement);
  7645. $defer.resolve(page.content);
  7646. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7647. }
  7648. getUnreadCount();
  7649. }, function (response) {
  7650. $scope.loading = false;
  7651. toaster.pop('error', '数据加载失败', response.data);
  7652. });
  7653. }
  7654. });
  7655. //获得各分类未阅读数量
  7656. var getUnreadCount = function () {
  7657. PurcSample.getUnreadCount(null, function(data){
  7658. $scope.unread = data;
  7659. });
  7660. };
  7661. getUnreadCount();
  7662. //设置单个单据已读
  7663. $scope.setOrdersRead = function (id) {
  7664. if (!$scope.isUnread(id)) {
  7665. return;
  7666. }
  7667. var sourceId = [];
  7668. sourceId.push(id);
  7669. PurcSample.setRead({}, sourceId, function (message) {
  7670. getUnreadIds();
  7671. getUnreadCount();
  7672. });
  7673. };
  7674. //获取未读单据id
  7675. var getUnreadIds = function (){
  7676. PurcSample.getUnreadIds({}, "", function (message) {
  7677. $scope.unreadCode = message.content;
  7678. });
  7679. };
  7680. getUnreadIds();
  7681. //判断单据是否未读
  7682. $scope.isUnread = function (id){
  7683. for (var i in $scope.unreadCode) {
  7684. if (id == $scope.unreadCode[i]) {
  7685. return true;
  7686. }
  7687. }
  7688. };
  7689. $scope.openDatePicker = function ($event, item, openParam) {
  7690. $event.preventDefault();
  7691. $event.stopPropagation();
  7692. item[openParam] = !item[openParam];
  7693. };
  7694. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7695. $event.preventDefault();
  7696. $event.stopPropagation();
  7697. item[openParam] = !item[openParam];
  7698. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7699. $scope.tableParams.reload();
  7700. }
  7701. };
  7702. $scope.openSend = function (index, sample) {
  7703. var modalInstance = $modal.open({
  7704. animation: true,
  7705. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7706. controller: 'SampleSendCtrl',
  7707. resolve: {
  7708. sampleItem: function () {
  7709. return sample;
  7710. }
  7711. }
  7712. });
  7713. modalInstance.result.then(function () {
  7714. toaster.pop('info', '提示', '送样成功');
  7715. $scope.tableParams.reload();
  7716. }, function () {
  7717. });
  7718. };
  7719. //打印 样品采购单
  7720. $scope.print = function (sample) {
  7721. var newPage = window.open("about:blank");
  7722. PurcSample.printPermission({}, function () {
  7723. PurcSample.printCount({id: sample.id}, {});//增加打印此次
  7724. ReportService.print(sample.proofing.enUU, 'PURCPROOFING', "where purc$proofingitems.ppi_id =" + sample.id, newPage);
  7725. }, function (response) {
  7726. newPage.close();
  7727. toaster.pop('error', '打印失败', response.data);
  7728. });
  7729. };
  7730. $scope.getSend = function (proofing) {
  7731. if (!proofing.sends) {
  7732. proofing.getSendInfo = '加载中...';
  7733. PurcSample.getSend({id: proofing.id}, function (data) {
  7734. if (data) {
  7735. proofing.getSendInfo = null;
  7736. proofing.sends = data;
  7737. } else {
  7738. proofing.getSendInfo = '无送样信息';
  7739. proofing.sends = '无送样信息';
  7740. }
  7741. }, function (response) {
  7742. proofing.getSendInfo = '加载失败!';
  7743. });
  7744. }
  7745. };
  7746. // 搜索框回车
  7747. $scope.onSearch = function (keyword) {
  7748. // 每次搜索重置获取数据方法
  7749. $scope.searchMethod = false;
  7750. if(keyword != null && keyword != '') {
  7751. $scope.searchMethod = true;
  7752. }
  7753. $scope.tableParams.page(1);
  7754. $scope.tableParams.reload();
  7755. };
  7756. // 导出
  7757. $scope.exportXls = function () {
  7758. PurcSample.exportXls({}, {}, function (data) {
  7759. if (data.success){
  7760. window.location.href = 'sale/sample/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  7761. }
  7762. }, function (response) {
  7763. toaster.pop('error', '数据加载失败', response.data);
  7764. });
  7765. }
  7766. }]);
  7767. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function ($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster) {
  7768. if (!sampleItem.sends) {
  7769. PurcSample.getSend({id: sampleItem.id}, function (data) {
  7770. if (data) {
  7771. sampleItem.sends = data; // 获取送样信息
  7772. angular.forEach(data, function (send) {
  7773. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  7774. });
  7775. }
  7776. }, function (response) {
  7777. });
  7778. }
  7779. $scope.sampleItem = sampleItem;
  7780. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  7781. //确认送样
  7782. $scope.ok = function (form) {
  7783. $scope.loading = true;
  7784. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  7785. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  7786. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  7787. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  7788. $upload.upload({
  7789. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  7790. method: 'POST',
  7791. file: file,
  7792. data: {
  7793. json: $scope.sampleItem.sampleSend
  7794. }
  7795. }).success(function (data) {
  7796. $scope.loading = false;
  7797. $modalInstance.close('success');
  7798. }).error(function (data) {
  7799. $scope.loading = false;
  7800. toaster.pop('error', '错误', data);
  7801. });
  7802. };
  7803. $scope.cancel = function () {
  7804. $modalInstance.dismiss(sampleItem);
  7805. };
  7806. //设置单个单据已读
  7807. $scope.setOrdersRead = function (id) {
  7808. var sourceId = [];
  7809. sourceId.push(id);
  7810. PurcSample.setRead({}, sourceId, function (message) {
  7811. // $scope.getUnreadIds();
  7812. });
  7813. };
  7814. }]);
  7815. /**
  7816. * 客户认定单
  7817. */
  7818. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol) {
  7819. BaseService.scrollBackToTop();
  7820. $scope.active = 'all';
  7821. $scope.agreedText = '全部';
  7822. $scope.dateZoneText = '一个月内';
  7823. $scope.condition = {dateZone: 1};
  7824. /* 时间筛选初始化*/
  7825. var fromDate = new Date();
  7826. var toDate = new Date();
  7827. fromDate.setMonth(fromDate.getMonth() - 1);
  7828. fromDate.setHours(0, 0, 0, 0);
  7829. toDate.setHours(23, 59, 59, 999);
  7830. $scope.condition.dateFrom = fromDate;
  7831. $scope.condition.dateTo = toDate;
  7832. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7833. $scope.changeDateZone = function (zone) {
  7834. $scope.condition.dateZone = zone;
  7835. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7836. $scope.condition.$dateZoneOpen = false;
  7837. getDateCondition(zone, $scope.condition);
  7838. $scope.tableParams.page(1);
  7839. $scope.tableParams.reload();
  7840. };
  7841. $scope.setActive = function (state) {
  7842. if ($scope.active != state) {
  7843. $scope.active = state;
  7844. if ($scope.tableParams.page() == 1)
  7845. $scope.tableParams.reload();
  7846. else
  7847. $scope.tableParams.page(1);
  7848. }
  7849. };
  7850. var getService = function () {
  7851. return PurcApproval;
  7852. };
  7853. $scope.tableParams = new ngTableParams({
  7854. page: 1,
  7855. count: 20,
  7856. sorting: {
  7857. inDate: 'desc'
  7858. }
  7859. }, {
  7860. total: 0,
  7861. counts: [5, 10, 25, 50],
  7862. getData: function ($defer, params) {
  7863. $scope.loading = true;
  7864. var pageParams = params.url();
  7865. pageParams.keyword = $scope.keyword;
  7866. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7867. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7868. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7869. $scope.loading = false;
  7870. if (page) {
  7871. params.total(page.totalElement);
  7872. $defer.resolve(page.content);
  7873. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7874. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7875. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7876. }
  7877. }, function (response) {
  7878. $scope.loading = false;
  7879. toaster.pop('error', '数据加载失败', response.data);
  7880. });
  7881. }
  7882. });
  7883. $scope.openDatePicker = function ($event, item, openParam) {
  7884. $event.preventDefault();
  7885. $event.stopPropagation();
  7886. item[openParam] = !item[openParam];
  7887. };
  7888. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7889. $event.preventDefault();
  7890. $event.stopPropagation();
  7891. item[openParam] = !item[openParam];
  7892. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7893. $scope.tableParams.reload();
  7894. }
  7895. };
  7896. $scope.parseDate = function (dateStr) {
  7897. if (dateStr)
  7898. return Date.parse(dateStr, 'yyyy-MM-dd');
  7899. return new Date();
  7900. };
  7901. // 搜索框回车
  7902. $scope.onSearch = function () {
  7903. $scope.tableParams.page(1);
  7904. $scope.tableParams.reload();
  7905. };
  7906. // 选择查找日期
  7907. $scope.onDateCondition = function () {
  7908. $scope.tableParams.page(1);
  7909. $scope.tableParams.reload();
  7910. };
  7911. // 导出
  7912. $scope.exportXls = function () {
  7913. PurcApproval.exportXls({}, {}, function (data) {
  7914. if (data.success){
  7915. window.location.href = 'sale/sample/approval/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7916. }
  7917. }, function (response) {
  7918. toaster.pop('error', '数据加载失败', response.data);
  7919. });
  7920. }
  7921. }]);
  7922. /**
  7923. * 客户采购预测
  7924. */
  7925. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol) {
  7926. BaseService.scrollBackToTop();
  7927. $scope.active = 'all';
  7928. $scope.agreedText = '全部';
  7929. $scope.dateZoneText = '一个月内';
  7930. $scope.condition = {dateZone: 1};
  7931. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7932. $scope.changeAgreed = function (agreed) {
  7933. $scope.condition.agreed = agreed;
  7934. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7935. $scope.condition.$agreedOpen = false;
  7936. };
  7937. $scope.changeDateZone = function (zone) {
  7938. $scope.condition.dateZone = zone;
  7939. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  7940. $scope.condition.$dateZoneOpen = false;
  7941. };
  7942. $scope.setActive = function (state) {
  7943. if ($scope.active != state) {
  7944. $scope.active = state;
  7945. if ($scope.tableParams.page() == 1)
  7946. $scope.tableParams.reload();
  7947. else
  7948. $scope.tableParams.page(1);
  7949. }
  7950. };
  7951. var getService = function () {
  7952. return PurcForecast;
  7953. };
  7954. $scope.tableParams = new ngTableParams({
  7955. page: 1,
  7956. count: 20,
  7957. sorting: {
  7958. orderDate: 'desc'
  7959. }
  7960. }, {
  7961. total: 0,
  7962. counts: [5, 10, 25, 50],
  7963. getData: function ($defer, params) {
  7964. $scope.loading = true;
  7965. var pageParams = params.url();
  7966. pageParams.keyword = $scope.keyword;
  7967. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7968. $scope.loading = false;
  7969. if (page) {
  7970. params.total(page.totalElement);
  7971. $defer.resolve(page.content);
  7972. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7973. }
  7974. }, function (response) {
  7975. $scope.loading = false;
  7976. toaster.pop('error', '数据加载失败', response.data);
  7977. });
  7978. }
  7979. });
  7980. $scope.openDatePicker = function ($event, item, openParam) {
  7981. $event.preventDefault();
  7982. $event.stopPropagation();
  7983. item[openParam] = !item[openParam];
  7984. };
  7985. // 搜索框回车
  7986. $scope.onSearch = function () {
  7987. $scope.tableParams.page(1);
  7988. $scope.tableParams.reload();
  7989. };
  7990. }]);
  7991. /**
  7992. * 客户采购验收
  7993. */
  7994. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  7995. BaseService.scrollBackToTop();
  7996. // 获取当前用户是否为普通用户
  7997. CurrentRole.isUser({}, {}, function (data) {
  7998. $scope.isUser = data.isUser;
  7999. });
  8000. $scope.active = 'all';
  8001. $scope.dateZoneText = '不限';
  8002. $scope.deliveryZoneText = '不限';
  8003. $scope.condition = {dateZone: 1, deliveryZone: -1};
  8004. /* 时间筛选初始化*/
  8005. var fromDate = new Date();
  8006. var toDate = new Date();
  8007. fromDate.setMonth(fromDate.getMonth() - 1);
  8008. fromDate.setHours(0, 0, 0, 0);
  8009. toDate.setHours(23, 59, 59, 999);
  8010. $scope.condition.dateFrom = fromDate;
  8011. $scope.condition.dateTo = toDate;
  8012. $scope.changeDateZone = function (zone) {
  8013. $scope.condition.dateZone = zone;
  8014. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8015. $scope.condition.$dateZoneOpen = false;
  8016. getDateCondition(zone, $scope.condition);
  8017. $scope.tableParams.page(1);
  8018. $scope.tableParams.reload();
  8019. };
  8020. $scope.changeDeliveryZone = function (zone) {
  8021. $scope.condition.deliveryZoneText = zone;
  8022. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  8023. $scope.condition.$delievryZoneOpen = false;
  8024. getDelveryCondition(zone, $scope.condition);
  8025. $scope.tableParams.reload();
  8026. };
  8027. $scope.setActive = function (state) {
  8028. if ($scope.active != state) {
  8029. $scope.active = state;
  8030. if ($scope.tableParams.page() == 1)
  8031. $scope.tableParams.reload();
  8032. else
  8033. $scope.tableParams.page(1);
  8034. }
  8035. };
  8036. var getService = function () {
  8037. return PurcAccept;
  8038. };
  8039. $scope.tableParams = new ngTableParams({
  8040. page: 1,
  8041. count: 20,
  8042. sorting: {
  8043. date: 'desc'
  8044. }
  8045. }, {
  8046. total: 0,
  8047. counts: [5, 10, 25, 50],
  8048. getData: function ($defer, params) {
  8049. $scope.loading = true;
  8050. var pageParams = params.url();
  8051. pageParams.searchFilter = { // 筛选条件
  8052. keyword: $scope.keyword,
  8053. fromDate: getDateTime($scope.condition.dateFrom),
  8054. endDate: getDateTime($scope.condition.dateTo)
  8055. };
  8056. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8057. $scope.loading = false;
  8058. if (page) {
  8059. params.total(page.totalElement);
  8060. $defer.resolve(page.content);
  8061. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8062. }
  8063. }, function (response) {
  8064. $scope.loading = false;
  8065. toaster.pop('error', '数据加载失败', response.data);
  8066. });
  8067. }
  8068. });
  8069. $scope.openDatePicker = function ($event, item, openParam) {
  8070. $event.preventDefault();
  8071. $event.stopPropagation();
  8072. item[openParam] = !item[openParam];
  8073. };
  8074. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8075. $event.preventDefault();
  8076. $event.stopPropagation();
  8077. item[openParam] = !item[openParam];
  8078. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8079. $scope.tableParams.reload();
  8080. }
  8081. };
  8082. $scope.parseDate = function (dateStr) {
  8083. if (dateStr)
  8084. return Date.parse(dateStr, 'yyyy-MM-dd');
  8085. return new Date();
  8086. };
  8087. // 选择查找日期
  8088. $scope.onDateCondition = function () {
  8089. $scope.tableParams.page(1);
  8090. $scope.tableParams.reload();
  8091. };
  8092. // 搜索框回车
  8093. $scope.onSearch = function () {
  8094. $scope.tableParams.page(1);
  8095. $scope.tableParams.reload();
  8096. };
  8097. // 导出
  8098. $scope.exportXls = function () {
  8099. PurcAccept.exportXls({}, {}, function (data) {
  8100. if (data.success){
  8101. window.location.href = 'sale/accept/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8102. }
  8103. }, function (response) {
  8104. toaster.pop('error', '数据加载失败', response.data);
  8105. });
  8106. }
  8107. }]);
  8108. /**
  8109. * 客户采购验收详情
  8110. */
  8111. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcAccept, toaster, BaseService, $stateParams, CurrentRole) {
  8112. BaseService.scrollBackToTop();
  8113. // 获取当前用户是否为普通用户
  8114. CurrentRole.isUser({}, {}, function (data) {
  8115. $scope.isUser = data.isUser;
  8116. });
  8117. if ($stateParams.id) {
  8118. PurcAccept.getDetail({id: $stateParams.id}, {}, function (data) {
  8119. $scope.accept = data;
  8120. if ($scope.accept.acceptItems != null) {
  8121. var sum = 0;
  8122. angular.forEach($scope.accept.acceptItems, function (item) {
  8123. if (item.orderPrice == null) {
  8124. item.orderPrice = 0;
  8125. }
  8126. sum += item.orderPrice * item.qty;
  8127. });
  8128. $scope.totalPrice = sum;
  8129. }
  8130. }, function (response) {
  8131. toaster.pop('error', '提示', response.data);
  8132. });
  8133. }
  8134. }]);
  8135. /**
  8136. * 客户采购验退
  8137. */
  8138. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8139. BaseService.scrollBackToTop();
  8140. // 获取当前用户是否为普通用户
  8141. CurrentRole.isUser({}, {}, function (data) {
  8142. $scope.isUser = data.isUser;
  8143. });
  8144. $scope.active = 'all';
  8145. $scope.agreedText = '全部';
  8146. $scope.dateZoneText = '一个月内';
  8147. $scope.condition = {dateZone: 1};
  8148. /* 时间筛选初始化*/
  8149. var fromDate = new Date();
  8150. var toDate = new Date();
  8151. fromDate.setMonth(fromDate.getMonth() - 1);
  8152. fromDate.setHours(0, 0, 0, 0);
  8153. toDate.setHours(23, 59, 59, 999);
  8154. $scope.condition.dateFrom = fromDate;
  8155. $scope.condition.dateTo = toDate;
  8156. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8157. $scope.changeAgreed = function (agreed) {
  8158. $scope.condition.agreed = agreed;
  8159. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8160. $scope.condition.$agreedOpen = false;
  8161. };
  8162. $scope.changeDateZone = function (zone) {
  8163. $scope.condition.dateZone = zone;
  8164. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8165. $scope.condition.$dateZoneOpen = false;
  8166. getDateCondition(zone, $scope.condition);
  8167. $scope.tableParams.page(1);
  8168. $scope.tableParams.reload();
  8169. };
  8170. $scope.setActive = function (state) {
  8171. if ($scope.active != state) {
  8172. $scope.active = state;
  8173. if ($scope.tableParams.page() == 1)
  8174. $scope.tableParams.reload();
  8175. else
  8176. $scope.tableParams.page(1);
  8177. }
  8178. };
  8179. var getService = function () {
  8180. return PurcReturn;
  8181. };
  8182. $scope.tableParams = new ngTableParams({
  8183. page: 1,
  8184. count: 20,
  8185. sorting: {
  8186. date: 'desc'
  8187. }
  8188. }, {
  8189. total: 0,
  8190. counts: [5, 10, 25, 50],
  8191. getData: function ($defer, params) {
  8192. $scope.loading = true;
  8193. var pageParams = params.url();
  8194. pageParams.searchFilter = {
  8195. keyword: $scope.keyword,
  8196. fromDate: getDateTime($scope.condition.dateFrom),
  8197. endDate: getDateTime($scope.condition.dateTo)
  8198. };
  8199. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8200. $scope.loading = false;
  8201. if (page) {
  8202. params.total(page.totalElement);
  8203. $defer.resolve(page.content);
  8204. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8205. angular.forEach(page.content, function (data) {
  8206. if (!data.returnItems[0].orderItem) {
  8207. PurcReturn.getEnterpriseName({id: data.id, enuu: data.enUU}, function (enterprise) {
  8208. data.enName = enterprise.enName;
  8209. });
  8210. }
  8211. });
  8212. }
  8213. }, function (response) {
  8214. $scope.loading = false;
  8215. toaster.pop('error', '数据加载失败', response.data);
  8216. });
  8217. }
  8218. });
  8219. $scope.openDatePicker = function ($event, item, openParam) {
  8220. $event.preventDefault();
  8221. $event.stopPropagation();
  8222. item[openParam] = !item[openParam];
  8223. };
  8224. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8225. $event.preventDefault();
  8226. $event.stopPropagation();
  8227. item[openParam] = !item[openParam];
  8228. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8229. $scope.tableParams.reload();
  8230. }
  8231. };
  8232. // 搜索框回车
  8233. $scope.onSearch = function () {
  8234. $scope.tableParams.page(1);
  8235. $scope.tableParams.reload();
  8236. };
  8237. // 导出
  8238. $scope.exportXls = function () {
  8239. PurcReturn.exportXls({}, {}, function (data) {
  8240. if (data.success){
  8241. window.location.href = 'sale/return/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8242. }
  8243. }, function (response) {
  8244. toaster.pop('error', '数据加载失败', response.data);
  8245. });
  8246. }
  8247. }]);
  8248. /**
  8249. * 客户采购验退详情
  8250. */
  8251. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcReturn, toaster, BaseService, $stateParams, CurrentRole) {
  8252. BaseService.scrollBackToTop();'' +
  8253. // 获取当前用户是否为普通用户
  8254. CurrentRole.isUser({}, {}, function (data) {
  8255. $scope.isUser = data.isUser;
  8256. });
  8257. if ($stateParams.id != null) {
  8258. PurcReturn.getDetail({id: $stateParams.id}, {}, function (data) {
  8259. $scope.returns = data;
  8260. if ($scope.returns.returnItems != null) {
  8261. var sum = 0;
  8262. angular.forEach($scope.returns.returnItems, function (item) {
  8263. if (null != item.orderPrice) {
  8264. sum += item.orderPrice * item.qty;
  8265. }
  8266. });
  8267. $scope.totalPrice = sum;
  8268. }
  8269. }, function (response) {
  8270. toaster.pop('error', '提示', response.data);
  8271. });
  8272. }
  8273. }]);
  8274. /**
  8275. * 客户不良品入库
  8276. */
  8277. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8278. BaseService.scrollBackToTop();
  8279. // 获取当前用户是否为普通用户
  8280. CurrentRole.isUser({}, {}, function (data) {
  8281. $scope.isUser = data.isUser;
  8282. });
  8283. $scope.active = 'all';
  8284. $scope.agreedText = '全部';
  8285. $scope.dateZoneText = '一个月内';
  8286. $scope.condition = {dateZone: 1};
  8287. /* 时间筛选初始化*/
  8288. var fromDate = new Date();
  8289. var toDate = new Date();
  8290. fromDate.setMonth(fromDate.getMonth() - 1);
  8291. fromDate.setHours(0, 0, 0, 0);
  8292. toDate.setHours(23, 59, 59, 999);
  8293. $scope.condition.dateFrom = fromDate;
  8294. $scope.condition.dateTo = toDate;
  8295. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8296. $scope.changeAgreed = function (agreed) {
  8297. $scope.condition.agreed = agreed;
  8298. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8299. $scope.condition.$agreedOpen = false;
  8300. };
  8301. $scope.changeDateZone = function (zone) {
  8302. $scope.condition.dateZone = zone;
  8303. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8304. $scope.condition.$dateZoneOpen = false;
  8305. getDateCondition(zone, $scope.condition);
  8306. $scope.tableParams.page(1);
  8307. $scope.tableParams.reload();
  8308. };
  8309. $scope.setActive = function (state) {
  8310. if ($scope.active != state) {
  8311. $scope.active = state;
  8312. if ($scope.tableParams.page() == 1)
  8313. $scope.tableParams.reload();
  8314. else
  8315. $scope.tableParams.page(1);
  8316. }
  8317. };
  8318. var getService = function () {
  8319. return PurcBadIn;
  8320. };
  8321. $scope.tableParams = new ngTableParams({
  8322. page: 1,
  8323. count: 20,
  8324. sorting: {
  8325. date: 'desc'
  8326. }
  8327. }, {
  8328. total: 0,
  8329. counts: [5, 10, 25, 50],
  8330. getData: function ($defer, params) {
  8331. $scope.loading = true;
  8332. var pageParams = params.url();
  8333. pageParams.searchFilter = {
  8334. keyword: $scope.keyword,
  8335. fromDate: getDateTime($scope.condition.dateFrom),
  8336. endDate: getDateTime($scope.condition.dateTo)
  8337. };
  8338. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8339. $scope.loading = false;
  8340. if (page) {
  8341. params.total(page.totalElement);
  8342. $defer.resolve(page.content);
  8343. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8344. }
  8345. }, function (response) {
  8346. $scope.loading = false;
  8347. toaster.pop('error', '数据加载失败', response.data);
  8348. });
  8349. }
  8350. });
  8351. $scope.openDatePicker = function ($event, item, openParam) {
  8352. $event.preventDefault();
  8353. $event.stopPropagation();
  8354. item[openParam] = !item[openParam];
  8355. };
  8356. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8357. $event.preventDefault();
  8358. $event.stopPropagation();
  8359. item[openParam] = !item[openParam];
  8360. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8361. $scope.tableParams.reload();
  8362. }
  8363. };
  8364. // 搜索框回车
  8365. $scope.onSearch = function (keyword) {
  8366. $scope.keyword = keyword;
  8367. $scope.tableParams.page(1);
  8368. $scope.tableParams.reload();
  8369. };
  8370. // 导出
  8371. $scope.exportXls = function () {
  8372. PurcBadIn.exportXls({}, {}, function (data) {
  8373. if (data.success){
  8374. window.location.href = 'sale/badIn/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8375. }
  8376. }, function (response) {
  8377. toaster.pop('error', '数据加载失败', response.data);
  8378. });
  8379. }
  8380. }]);
  8381. /**
  8382. * 客户不良品出库
  8383. */
  8384. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8385. BaseService.scrollBackToTop();
  8386. // 获取当前用户是否为普通用户
  8387. CurrentRole.isUser({}, {}, function (data) {
  8388. $scope.isUser = data.isUser;
  8389. });
  8390. $scope.active = 'all';
  8391. $scope.agreedText = '全部';
  8392. $scope.dateZoneText = '一个月内';
  8393. $scope.condition = {dateZone: 1};
  8394. /* 时间筛选初始化*/
  8395. var fromDate = new Date();
  8396. var toDate = new Date();
  8397. fromDate.setMonth(fromDate.getMonth() - 1);
  8398. fromDate.setHours(0, 0, 0, 0);
  8399. toDate.setHours(23, 59, 59, 999);
  8400. $scope.condition.dateFrom = fromDate;
  8401. $scope.condition.dateTo = toDate;
  8402. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8403. $scope.changeAgreed = function (agreed) {
  8404. $scope.condition.agreed = agreed;
  8405. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8406. $scope.condition.$agreedOpen = false;
  8407. };
  8408. $scope.changeDateZone = function (zone) {
  8409. $scope.condition.dateZone = zone;
  8410. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8411. $scope.condition.$dateZoneOpen = false;
  8412. getDateCondition(zone, $scope.condition);
  8413. $scope.tableParams.page(1);
  8414. $scope.tableParams.reload();
  8415. };
  8416. $scope.setActive = function (state) {
  8417. if ($scope.active != state) {
  8418. $scope.active = state;
  8419. if ($scope.tableParams.page() == 1)
  8420. $scope.tableParams.reload();
  8421. else
  8422. $scope.tableParams.page(1);
  8423. }
  8424. };
  8425. var getService = function () {
  8426. return PurcBadOut;
  8427. };
  8428. $scope.tableParams = new ngTableParams({
  8429. page: 1,
  8430. count: 20,
  8431. sorting: {
  8432. date: 'desc'
  8433. }
  8434. }, {
  8435. total: 0,
  8436. counts: [5, 10, 25, 50],
  8437. getData: function ($defer, params) {
  8438. $scope.loading = true;
  8439. var pageParams = params.url();
  8440. pageParams.searchFilter = {
  8441. keyword: $scope.keyword,
  8442. fromDate: getDateTime($scope.condition.dateFrom),
  8443. endDate: getDateTime($scope.condition.dateTo)
  8444. };
  8445. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8446. $scope.loading = false;
  8447. if (page) {
  8448. params.total(page.totalElement);
  8449. $defer.resolve(page.content);
  8450. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8451. }
  8452. }, function (response) {
  8453. $scope.loading = false;
  8454. toaster.pop('error', '数据加载失败', response.data);
  8455. });
  8456. }
  8457. });
  8458. $scope.openDatePicker = function ($event, item, openParam) {
  8459. $event.preventDefault();
  8460. $event.stopPropagation();
  8461. item[openParam] = !item[openParam];
  8462. };
  8463. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8464. $event.preventDefault();
  8465. $event.stopPropagation();
  8466. item[openParam] = !item[openParam];
  8467. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8468. $scope.tableParams.reload();
  8469. }
  8470. };
  8471. // 搜索框回车
  8472. $scope.onSearch = function () {
  8473. $scope.tableParams.page(1);
  8474. $scope.tableParams.reload();
  8475. };
  8476. // 导出
  8477. $scope.exportXls = function () {
  8478. PurcBadOut.exportXls({}, {}, function (data) {
  8479. if (data.success){
  8480. window.location.href = 'sale/badOut/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8481. }
  8482. }, function (response) {
  8483. toaster.pop('error', '数据加载失败', response.data);
  8484. });
  8485. }
  8486. }]);
  8487. /**
  8488. * 客户MRB
  8489. */
  8490. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol) {
  8491. BaseService.scrollBackToTop();
  8492. $scope.active = 'all';
  8493. $scope.agreedText = '全部';
  8494. $scope.dateZoneText = '一个月内';
  8495. $scope.condition = {dateZone: 1};
  8496. /* 时间筛选初始化*/
  8497. var fromDate = new Date();
  8498. var toDate = new Date();
  8499. fromDate.setMonth(fromDate.getMonth() - 1);
  8500. fromDate.setHours(0, 0, 0, 0);
  8501. toDate.setHours(23, 59, 59, 999);
  8502. $scope.condition.dateFrom = fromDate;
  8503. $scope.condition.dateTo = toDate;
  8504. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8505. $scope.changeAgreed = function (agreed) {
  8506. $scope.condition.agreed = agreed;
  8507. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8508. $scope.condition.$agreedOpen = false;
  8509. };
  8510. $scope.changeDateZone = function (zone) {
  8511. $scope.condition.dateZone = zone;
  8512. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8513. $scope.condition.$dateZoneOpen = false;
  8514. getDateCondition(zone, $scope.condition);
  8515. $scope.tableParams.page(1);
  8516. $scope.tableParams.reload();
  8517. };
  8518. $scope.setActive = function (state) {
  8519. if ($scope.active != state) {
  8520. $scope.active = state;
  8521. if ($scope.tableParams.page() == 1)
  8522. $scope.tableParams.reload();
  8523. else
  8524. $scope.tableParams.page(1);
  8525. }
  8526. };
  8527. var getService = function () {
  8528. return PurcMRB;
  8529. };
  8530. $scope.tableParams = new ngTableParams({
  8531. page: 1,
  8532. count: 20,
  8533. sorting: {
  8534. date: 'desc'
  8535. }
  8536. }, {
  8537. total: 0,
  8538. counts: [5, 10, 25, 50],
  8539. getData: function ($defer, params) {
  8540. $scope.loading = true;
  8541. var pageParams = params.url();
  8542. pageParams.searchFilter = {
  8543. keyword: $scope.keyword,
  8544. fromDate: getDateTime($scope.condition.dateFrom),
  8545. endDate: getDateTime($scope.condition.dateTo)
  8546. };
  8547. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8548. $scope.loading = false;
  8549. if (page) {
  8550. params.total(page.totalElement);
  8551. $defer.resolve(page.content);
  8552. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8553. }
  8554. }, function (response) {
  8555. $scope.loading = false;
  8556. toaster.pop('error', '数据加载失败', response.data);
  8557. });
  8558. }
  8559. });
  8560. $scope.openDatePicker = function ($event, item, openParam) {
  8561. $event.preventDefault();
  8562. $event.stopPropagation();
  8563. item[openParam] = !item[openParam];
  8564. };
  8565. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8566. $event.preventDefault();
  8567. $event.stopPropagation();
  8568. item[openParam] = !item[openParam];
  8569. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8570. $scope.tableParams.reload();
  8571. }
  8572. };
  8573. // 搜索框回车
  8574. $scope.onSearch = function () {
  8575. $scope.tableParams.page(1);
  8576. $scope.tableParams.reload();
  8577. };
  8578. // 导出
  8579. $scope.exportXls = function () {
  8580. PurcMRB.exportXls({}, {}, function (data) {
  8581. if (data.success){
  8582. window.location.href = 'sale/MRB/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8583. }
  8584. }, function (response) {
  8585. toaster.pop('error', '数据加载失败', response.data);
  8586. });
  8587. }
  8588. }]);
  8589. /**
  8590. * 客户应付发票
  8591. */
  8592. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8593. BaseService.scrollBackToTop();
  8594. // 获取当前用户是否为普通用户
  8595. CurrentRole.isUser({}, {}, function (data) {
  8596. $scope.isUser = data.isUser;
  8597. });
  8598. $scope.active = 'all';
  8599. $scope.dateZoneText = '不限';
  8600. $scope.condition = {dateZone: 1};
  8601. /* 时间筛选初始化*/
  8602. var fromDate = new Date();
  8603. var toDate = new Date();
  8604. fromDate.setMonth(fromDate.getMonth() - 1);
  8605. fromDate.setHours(0, 0, 0, 0);
  8606. toDate.setHours(23, 59, 59, 999);
  8607. $scope.condition.dateFrom = fromDate;
  8608. $scope.condition.dateTo = toDate;
  8609. $scope.changeDateZone = function (zone) {
  8610. $scope.condition.dateZone = zone;
  8611. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8612. $scope.condition.$dateZoneOpen = false;
  8613. getDateCondition(zone, $scope.condition);
  8614. $scope.tableParams.page(1);
  8615. $scope.tableParams.reload();
  8616. };
  8617. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8618. $scope.setActive = function (state) {
  8619. if ($scope.active != state) {
  8620. $scope.active = state;
  8621. if ($scope.tableParams.page() == 1)
  8622. $scope.tableParams.reload();
  8623. else
  8624. $scope.tableParams.page(1);
  8625. }
  8626. };
  8627. var getService = function () {
  8628. return FaApBill;
  8629. };
  8630. $scope.tableParams = new ngTableParams({
  8631. page: 1,
  8632. count: 20,
  8633. sorting: {
  8634. date: 'desc'
  8635. }
  8636. }, {
  8637. total: 0,
  8638. counts: [5, 10, 25, 50],
  8639. getData: function ($defer, params) {
  8640. $scope.loading = true;
  8641. var pageParams = params.url();
  8642. pageParams.searchFilter = { // 筛选条件
  8643. keyword: $scope.keyword,
  8644. fromDate: getDateTime($scope.condition.dateFrom),
  8645. endDate: getDateTime($scope.condition.dateTo)
  8646. };
  8647. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8648. $scope.loading = false;
  8649. if (page) {
  8650. params.total(page.totalElement);
  8651. $defer.resolve(page.content);
  8652. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  8653. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8654. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8655. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  8656. }
  8657. }, function (response) {
  8658. $scope.loading = false;
  8659. toaster.pop('error', '数据加载失败', response.data);
  8660. });
  8661. }
  8662. });
  8663. $scope.openDatePicker = function ($event, item, openParam) {
  8664. $event.preventDefault();
  8665. $event.stopPropagation();
  8666. item[openParam] = !item[openParam];
  8667. };
  8668. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8669. $event.preventDefault();
  8670. $event.stopPropagation();
  8671. item[openParam] = !item[openParam];
  8672. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8673. $scope.tableParams.reload();
  8674. }
  8675. };
  8676. $scope.parseDate = function (dateStr) {
  8677. if (dateStr)
  8678. return Date.parse(dateStr, 'yyyy-MM-dd');
  8679. return new Date();
  8680. };
  8681. // 搜索框回车
  8682. $scope.onSearch = function () {
  8683. $scope.tableParams.page(1);
  8684. $scope.tableParams.reload();
  8685. };
  8686. // 选择查找日期
  8687. $scope.onDateCondition = function () {
  8688. $scope.tableParams.page(1);
  8689. $scope.tableParams.reload();
  8690. };
  8691. // 导出
  8692. $scope.exportXls = function () {
  8693. FaApBill.exportXls({}, {}, function (data) {
  8694. if (data.success){
  8695. window.location.href = 'sale/apBill/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  8696. }
  8697. }, function (response) {
  8698. toaster.pop('error', '数据加载失败', response.data);
  8699. });
  8700. }
  8701. }]);
  8702. /**
  8703. * 客户应付发票详情
  8704. */
  8705. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, $filter, FaApBill, toaster, $stateParams, BaseService, CurrentRole) {
  8706. BaseService.scrollBackToTop();
  8707. // 获取当前用户是否为普通用户
  8708. CurrentRole.isUser({}, {}, function (data) {
  8709. $scope.isUser = data.isUser;
  8710. });
  8711. var loadData = function () {
  8712. FaApBill.getAll({id: $stateParams.id}, function (data) {
  8713. $scope.bill = data;
  8714. $scope.loading = false;
  8715. }, function (response) {
  8716. toaster.pop('error', '', response.data);
  8717. });
  8718. };
  8719. loadData(); // 初始获取单据数据
  8720. }]);
  8721. /**
  8722. * 应付对账单
  8723. */
  8724. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol) {
  8725. BaseService.scrollBackToTop();
  8726. $scope.active = 'all';
  8727. $scope.dateZoneText = '不限';
  8728. $scope.condition = {dateZone: 1};
  8729. /* 时间筛选初始化*/
  8730. var fromDate = new Date();
  8731. var toDate = new Date();
  8732. fromDate.setMonth(fromDate.getMonth() - 1);
  8733. fromDate.setHours(0, 0, 0, 0);
  8734. toDate.setHours(23, 59, 59, 999);
  8735. $scope.condition.dateFrom = fromDate;
  8736. $scope.condition.dateTo = toDate;
  8737. $scope.changeDateZone = function (zone) {
  8738. $scope.condition.dateZone = zone;
  8739. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8740. $scope.condition.$dateZoneOpen = false;
  8741. getDateCondition(zone, $scope.condition);
  8742. $scope.tableParams.page(1);
  8743. $scope.tableParams.reload();
  8744. };
  8745. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8746. $scope.setActive = function (state) {
  8747. if ($scope.active != state) {
  8748. $scope.active = state;
  8749. if ($scope.tableParams.page() == 1)
  8750. $scope.tableParams.reload();
  8751. else
  8752. $scope.tableParams.page(1);
  8753. }
  8754. };
  8755. var getService = function () {
  8756. return FaArCheck;
  8757. };
  8758. $scope.tableParams = new ngTableParams({
  8759. page: 1,
  8760. count: 20,
  8761. sorting: {
  8762. date: 'desc'
  8763. }
  8764. }, {
  8765. total: 0,
  8766. counts: [5, 10, 25, 50],
  8767. getData: function ($defer, params) {
  8768. $scope.loading = true;
  8769. var pageParams = params.url();
  8770. pageParams.searchFilter = {};
  8771. pageParams.searchFilter.keyword = $scope.keyword;
  8772. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8773. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8774. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8775. $scope.loading = false;
  8776. if (page) {
  8777. params.total(page.totalElement);
  8778. $defer.resolve(page.content);
  8779. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8780. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8781. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  8782. }
  8783. }, function (response) {
  8784. $scope.loading = false;
  8785. toaster.pop('error', '数据加载失败', response.data);
  8786. });
  8787. }
  8788. });
  8789. $scope.openDatePicker = function ($event, item, openParam) {
  8790. $event.preventDefault();
  8791. $event.stopPropagation();
  8792. item[openParam] = !item[openParam];
  8793. };
  8794. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8795. $event.preventDefault();
  8796. $event.stopPropagation();
  8797. item[openParam] = !item[openParam];
  8798. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8799. $scope.tableParams.reload();
  8800. }
  8801. };
  8802. // 计算单据的商品总数
  8803. $scope.getTotalProd = function (check) {
  8804. var total = 0;
  8805. if (check.items) {
  8806. angular.forEach(check.items, function (value) {
  8807. total += value.qty;
  8808. });
  8809. }
  8810. return total;
  8811. };
  8812. // 搜索框回车
  8813. $scope.onSearch = function () {
  8814. $scope.tableParams.page(1);
  8815. $scope.tableParams.reload();
  8816. };
  8817. // 选择查找日期
  8818. $scope.onDateCondition = function () {
  8819. $scope.tableParams.page(1);
  8820. $scope.tableParams.reload();
  8821. };
  8822. }]);
  8823. // 应付对账单详情页
  8824. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function ($scope, $stateParams, FaArCheck, toaster, $state, BaseService) {
  8825. BaseService.scrollBackToTop();
  8826. var loadData = function () {
  8827. FaArCheck.get({id: $stateParams.id}, function (data) {
  8828. $scope.order = data;
  8829. $scope.loading = false;
  8830. });
  8831. };
  8832. loadData(); // 初始获取单据数据
  8833. $scope.onReplyClick = function (item, isAgreed) {
  8834. if (isAgreed) {// 同意确认
  8835. FaArCheck.agree({itemId: item.id}, {}, function (data) {
  8836. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  8837. }, function (response) {
  8838. toaster.pop('danger', '确认失败', response.data);
  8839. });
  8840. } else {// 不同意回复
  8841. FaArCheck.disagree({itemId: item.id}, {
  8842. qty: item.$replyQty,
  8843. remark: item.$replyRemark
  8844. }, function (data) {
  8845. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  8846. }, function (response) {
  8847. toaster.pop('danger', '确认失败', response.data);
  8848. });
  8849. }
  8850. };
  8851. // 获取明细的回复记录
  8852. $scope.getReplies = function (item) {
  8853. if (!item.replies) {
  8854. FaArCheck.getReplies({itemId: item.id}, function (data) {
  8855. item.replies = data;
  8856. }, function (response) {
  8857. toaster.pop('danger', '获取对账记录失败', response.data);
  8858. });
  8859. }
  8860. };
  8861. }]);
  8862. //应收对账单列表
  8863. app.controller('PurchaseApCheckCtrl', ['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster', 'ReportService', 'Symbol', 'CurrentRole', function ($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService, Symbol, CurrentRole) {
  8864. BaseService.scrollBackToTop();
  8865. // 获取当前用户是否为普通用户
  8866. CurrentRole.isUser({}, {}, function (data) {
  8867. $scope.isUser = data.isUser;
  8868. });
  8869. $scope.dateZoneText = '不限';
  8870. $scope.condition = {dateZone: 1};
  8871. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8872. $scope.active = 'todo';
  8873. /* 时间筛选初始化*/
  8874. var fromDate = new Date();
  8875. var toDate = new Date();
  8876. fromDate.setMonth(fromDate.getMonth() - 1);
  8877. fromDate.setHours(0, 0, 0, 0);
  8878. toDate.setHours(23, 59, 59, 999);
  8879. $scope.condition.dateFrom = fromDate;
  8880. $scope.condition.dateTo = toDate;
  8881. //打印 对账单
  8882. $scope.print = function (check) {
  8883. var newPage = window.open("about:blank");
  8884. FaApCheck.printPermission({}, function () {
  8885. FaApCheck.printCount({id: check.id}, {});//增加打印此次
  8886. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id, newPage);
  8887. }, function (response) {
  8888. newPage.close();
  8889. toaster.pop('error', '打印失败', response.data);
  8890. });
  8891. };
  8892. //状态
  8893. $scope.setActive = function (state) {
  8894. if ($scope.active != state) {
  8895. $scope.active = state;
  8896. if ($scope.tableParams.page() == 1)
  8897. $scope.tableParams.reload();
  8898. else
  8899. $scope.tableParams.page(1);
  8900. }
  8901. };
  8902. $scope.changeDateZone = function (zone) {
  8903. $scope.condition.dateZone = zone;
  8904. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8905. $scope.condition.$dateZoneOpen = false;
  8906. getDateCondition(zone, $scope.condition);
  8907. $scope.tableParams.page(1);
  8908. $scope.tableParams.reload();
  8909. };
  8910. //获取应收对账单全部
  8911. $scope.tableParams = new ngTableParams({
  8912. page: 1,
  8913. count: 20,
  8914. sorting: {
  8915. recordDate: 'desc'
  8916. }
  8917. }, {
  8918. total: 0,
  8919. counts: [5, 10, 25, 50],
  8920. getData: function ($defer, params) {
  8921. $scope.loading = true;
  8922. var pageParams = params.url();
  8923. pageParams.searchFilter = { // 筛选条件
  8924. keyword: $scope.keyword,
  8925. fromDate: getDateTime($scope.condition.dateFrom),
  8926. endDate: getDateTime($scope.condition.dateTo)
  8927. };
  8928. FaApCheck[getState($scope.active)](BaseService.parseParams(pageParams), function (page) {
  8929. $scope.loading = false;
  8930. if (page) {
  8931. params.total(page.totalElement);
  8932. $scope.data = $defer.resolve(page.content);
  8933. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  8934. }
  8935. }, function (response) {
  8936. $scope.loading = false;
  8937. toaster.pop('error', '数据加载失败', response.data);
  8938. });
  8939. }
  8940. });
  8941. //获得各分类未阅读数量
  8942. var getUnreadCount = function () {
  8943. FaApCheck.getUnreadCount(null, function(data){
  8944. $scope.unread = data;
  8945. });
  8946. };
  8947. getUnreadCount();
  8948. //设置单据已读
  8949. $scope.setOrdersRead = function (id) {
  8950. // 如果单据本身已读,则不发送请求修改数据
  8951. if (!$scope.isUnread(id)){
  8952. return;
  8953. }
  8954. var sourceId = [];
  8955. sourceId.push(id);
  8956. FaApCheck.setRead({}, sourceId, function (message) {
  8957. getUnreadCount();
  8958. });
  8959. };
  8960. //获取未读单据id
  8961. var getUnreadIds = function (){
  8962. FaApCheck.getUnreadIds({}, "", function (message) {
  8963. $scope.unreadCode = message.content;
  8964. });
  8965. };
  8966. getUnreadIds();
  8967. //判断单据是否未读
  8968. $scope.isUnread = function (id){
  8969. for (var i in $scope.unreadCode) {
  8970. if (id == $scope.unreadCode[i]) {
  8971. return true;
  8972. }
  8973. }
  8974. };
  8975. $scope.openDatePicker = function ($event, item, openParam) {
  8976. $event.preventDefault();
  8977. $event.stopPropagation();
  8978. item[openParam] = !item[openParam];
  8979. };
  8980. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8981. $event.preventDefault();
  8982. $event.stopPropagation();
  8983. item[openParam] = !item[openParam];
  8984. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8985. $scope.tableParams.reload();
  8986. }
  8987. };
  8988. // 计算单据的商品总数
  8989. $scope.getTotalProd = function (check) {
  8990. var total = 0;
  8991. if (check.items) {
  8992. angular.forEach(check.items, function (value) {
  8993. total += value.checkQty;
  8994. });
  8995. }
  8996. return total;
  8997. };
  8998. // 搜索框回车
  8999. $scope.onSearch = function () {
  9000. $scope.tableParams.page(1);
  9001. $scope.tableParams.reload();
  9002. };
  9003. // 选择查找日期
  9004. $scope.onDateCondition = function () {
  9005. $scope.tableParams.page(1);
  9006. $scope.tableParams.reload();
  9007. };
  9008. // 导出
  9009. $scope.exportXls = function () {
  9010. FaApCheck.exportXls({}, {}, function (data) {
  9011. if (data.success){
  9012. window.location.href = 'sale/apCheck/xls/list?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  9013. }
  9014. }, function (response) {
  9015. toaster.pop('error', '数据加载失败', response.data);
  9016. });
  9017. }
  9018. }]);
  9019. //应收对账单详情
  9020. app.controller('PurchaseApCheckDetailCtrl', ['$scope', 'toaster', 'FaApCheck', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, toaster, FaApCheck, $stateParams, BaseService, CurrentRole) {
  9021. BaseService.scrollBackToTop();
  9022. // 获取当前用户是否为普通用户
  9023. CurrentRole.isUser({}, {}, function (data) {
  9024. $scope.isUser = data.isUser;
  9025. });
  9026. $scope.haveSelected = true;
  9027. $scope.data = {};
  9028. //控制提交和删除按钮的显示
  9029. $scope.ifShow = true;
  9030. var loadData = function () {
  9031. FaApCheck.getItem({id: $stateParams.id}, function (data) {
  9032. $scope.data = data;
  9033. if ($scope.data.status) {
  9034. } else {
  9035. $scope.ifShow = true;
  9036. }
  9037. }, function (response) {
  9038. toaster.pop('error', '', response.data);
  9039. })
  9040. };
  9041. if ($stateParams.id) {
  9042. loadData();
  9043. }
  9044. $scope.haveSource = false;
  9045. //提交应收对账单
  9046. $scope.submitApCheck = function () {
  9047. FaApCheck.updateStatus({id: $stateParams.id}, {}, function (data) {
  9048. if (data.result) {
  9049. toaster.pop('success', '提示', '提交成功');
  9050. $scope.haveSelected = false;
  9051. window.location.href = '#/fa/apCheck';
  9052. } else {
  9053. $scope.haveSource = true;
  9054. loadData();
  9055. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  9056. $scope.haveSelected = true;
  9057. }
  9058. }, function (response) {
  9059. $scope.loading = false;
  9060. toaster.pop('error', '更新已转数失败', response.data);
  9061. });
  9062. }
  9063. //删除应收对账单的同时更新来源表已转数
  9064. var updateYCheckQty = function () {
  9065. var sourceInfos = [];
  9066. angular.forEach($scope.data.items, function (item) {
  9067. $scope.sourceInfo = {
  9068. sourceId: '',
  9069. sourceTable: '',
  9070. newYCheckQty: ''
  9071. };
  9072. $scope.sourceInfo.sourceId = item.sourceId;
  9073. $scope.sourceInfo.sourceTable = item.sourceTable;
  9074. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  9075. sourceInfos.push($scope.sourceInfo);
  9076. });
  9077. FaApCheck.update({}, sourceInfos, function () {
  9078. }, function (response) {
  9079. $scope.loading = false;
  9080. toaster.pop('error', '更新已转数失败', response.data);
  9081. });
  9082. }
  9083. //删除应收对账单
  9084. $scope.deleteApCheck = function () {
  9085. FaApCheck.deleteApCheck({id: $stateParams.id}, {}, function (data) {
  9086. updateYCheckQty();
  9087. toaster.pop('success', '提示', '删除成功');
  9088. }, function (response) {
  9089. toaster.pop('error', '删除失败', response.data);
  9090. });
  9091. $scope.haveSelected = false;
  9092. }
  9093. //作废应收对账单
  9094. $scope.cancelApCheck = function (check) {
  9095. FaApCheck.cancel({id: check.id}, {}, function (data) {
  9096. $scope.checkResult = false;
  9097. if (data.result) {
  9098. $scope.checkResult = true;
  9099. toaster.pop('success', '提示', '作废成功');
  9100. $scope.tableParams.reload();
  9101. } else {
  9102. toaster.pop('error', '提示', '作废失败');
  9103. }
  9104. }, function (response) {
  9105. $scope.loading = false;
  9106. toaster.pop('error', '作废失败', response.data);
  9107. });
  9108. }
  9109. }]);
  9110. //未对账单据列表
  9111. app.controller('PurchaseApCheckListCtrl', ['$scope', 'FaApCheck', 'toaster', '$state', '$filter', '$modal', 'Vendor', 'DecimalNumber', function ($scope, FaApCheck, toaster, $state, $filter, $modal, Vendor, DecimalNumber) {
  9112. $scope.data = [];// 列表数据
  9113. $scope.condition = {
  9114. $fromOpened: false
  9115. }
  9116. $scope.openDatePicker = function ($event, item, openParam) {
  9117. $event.preventDefault();
  9118. $event.stopPropagation();
  9119. item[openParam] = !item[openParam];
  9120. }
  9121. // 客户联想词
  9122. $scope.getSimilarCustomers = function (value) {
  9123. if (value) {
  9124. return Vendor.getSimilarCustomers({keyword: value}).$promise.then(function (data) {
  9125. return data.map(function (item) {
  9126. return item;
  9127. });
  9128. });
  9129. }
  9130. };
  9131. $scope.onAssociateCustomerClick = function (vendor) {
  9132. if (vendor.apcheck == 0) {
  9133. toaster.pop('info', '提示', '该客户暂未启用平台对账功能');
  9134. $scope.suuorname = '';
  9135. } else {
  9136. $scope.suuorname = vendor.custName;
  9137. }
  9138. }
  9139. //查找客户
  9140. $scope.searchCust = function (suuorname) {
  9141. var modalInstance = $modal.open({
  9142. animation: true,
  9143. templateUrl: 'static/tpl/index/fa/apcheck_customer.html',
  9144. controller: 'SearchCustInfoCtrl',
  9145. size: 'lg',
  9146. resolve: {
  9147. suuorname: function () {
  9148. return suuorname;
  9149. }
  9150. }
  9151. });
  9152. modalInstance.result.then(function (customer) {
  9153. $scope.suuorname = customer.myEnterprise.enName;
  9154. });
  9155. }
  9156. // 点击筛选根据条件选择数据
  9157. // 默认本月
  9158. $scope.sdateTo = new Date();
  9159. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  9160. $scope.condition.uuorname = '';
  9161. $scope.condition.dateFrom = '';
  9162. $scope.condition.dateTo = '';
  9163. $scope.condition.venduuorname = '';
  9164. $scope.condition.factory = '';
  9165. $scope.condition.prodtitle = '';
  9166. $scope.condition.prodspec = '';
  9167. $scope.searchOrder = function (check) {
  9168. $scope.data = [];
  9169. $scope.checkboxes.checked = false;
  9170. $scope.totalMoney = 0;
  9171. $scope.condition.uuorname = $scope.suuorname;
  9172. $scope.condition.factory = $scope.factory
  9173. $scope.condition.prodtitle = $scope.prodtitle;
  9174. $scope.condition.prodspec = $scope.prodspec;
  9175. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9176. $scope.thisdatato = ($scope.sdateTo || 0);
  9177. if ($scope.thisdatato != 0) {
  9178. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9179. } else {
  9180. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9181. }
  9182. $scope.condition.venduuorname = $scope.vuuorname;
  9183. if ($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9184. $scope.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9185. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9186. $scope.searchKeyWord = {
  9187. receiveName: $scope.receiveName,
  9188. factory: $scope.factory,
  9189. prodTitle: $scope.prodTitle,
  9190. prodSpec: $scope.prodSpec,
  9191. taxRate: $scope.taxRate,
  9192. suuorname: $scope.suuorname
  9193. }
  9194. $scope.exportKeywords = encodeURIComponent($scope.searchKeyWord);
  9195. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9196. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9197. if (!$scope.suuorname) {
  9198. toaster.pop('warning', '提示', '请先选择客户');
  9199. document.getElementById('suuorname').focus();//光标默认在客户
  9200. } else {
  9201. $scope.loading = true;
  9202. FaApCheck.getAllByKeywords({
  9203. fromDate: $scope.fromDate,
  9204. endDate: $scope.endDate,
  9205. receiveName: $scope.receiveName,
  9206. factory: $scope.factory,
  9207. prodTitle: $scope.prodTitle,
  9208. prodSpec: $scope.prodSpec,
  9209. taxRate: $scope.taxRate,
  9210. suuorname: $scope.suuorname
  9211. }, function (data) {
  9212. if (data.length > 0) {
  9213. angular.forEach(data, function (item) {
  9214. item.$selected = true;
  9215. });
  9216. $scope.data = data;
  9217. $scope.checkboxes.checked = true;
  9218. $scope.getTotalMoney();
  9219. } else {
  9220. toaster.pop('info', '提示', '当前没有需要对账记录');
  9221. }
  9222. $scope.loading = false;
  9223. }, function (response) {
  9224. $scope.loading = false;
  9225. toaster.pop('error', '提示', response.data);
  9226. });
  9227. }
  9228. }
  9229. }
  9230. $scope.exportApcheckList = function() {
  9231. var url = 'sale/apCheck/xls?fromDate=' + $scope.fromDate + '&endDate=' + $scope.endDate;
  9232. if (angular.isDefined($scope.receiveName)) {
  9233. url = url + '&receiveName=' + $scope.receiveName;
  9234. }
  9235. if (angular.isDefined($scope.factory)) {
  9236. url = url + '&factory=' + $scope.factory;
  9237. }
  9238. if (angular.isDefined($scope.prodTitle)) {
  9239. url = url + '&prodTitle=' + $scope.prodTitle;
  9240. }
  9241. if (angular.isDefined($scope.prodSpec)) {
  9242. url = url + '&prodSpec=' + $scope.prodSpec;
  9243. }
  9244. if (angular.isDefined($scope.suuorname)) {
  9245. url = url + '&suuorname=' + $scope.suuorname;
  9246. }
  9247. if (angular.isDefined($scope.taxRate)) {
  9248. url = url + '&receiveName=' + $scope.taxRate;
  9249. }
  9250. window.location.href = url;
  9251. }
  9252. /**
  9253. * 点击勾选框,选中要转应收对账单的订单
  9254. * */
  9255. $scope.totalMoney = 0;
  9256. $scope.checkboxes = {
  9257. checked: false
  9258. };
  9259. // 点击勾选全部的复选框
  9260. $scope.checkAll = function () {
  9261. $scope.totalMoney = 0;
  9262. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodtitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodspec || $scope.condition.factory);
  9263. var dateFrom = $scope.condition.dateFrom;
  9264. var dateTo = $scope.condition.dateTo;
  9265. angular.forEach($scope.filteredData, function (item) {
  9266. if ((item.pidate >= dateFrom || dateFrom == '') && (item.pidate < dateTo || dateTo == '')) {
  9267. item.$selected = $scope.checkboxes.checked;
  9268. }
  9269. });
  9270. $scope.getTotalMoney();
  9271. };
  9272. //获取已选单据总金额
  9273. $scope.getTotalMoney = function () {
  9274. $scope.totalMoney = 0;
  9275. angular.forEach($scope.data, function (check) {
  9276. if (check.$selected) {
  9277. var price = DecimalNumber.accMul((check.thischeckqty || 0), (check.orderprice || 0));
  9278. $scope.totalMoney += Math.round(price * 100) / 100;
  9279. } else {
  9280. $scope.totalMoney += 0;
  9281. }
  9282. });
  9283. }
  9284. // 点击其中一个明细的复选框
  9285. $scope.checkOne = function (check) {
  9286. var result = true;
  9287. angular.forEach($scope.data, function (item) {
  9288. if (item.$selected != true) {
  9289. result = false;
  9290. return;
  9291. }
  9292. });
  9293. $scope.checkboxes.checked = result;
  9294. };
  9295. $scope.haveSelected = false;
  9296. //生成应收对账单
  9297. $scope.createApCheck = function () {
  9298. //保存应收对账单主记录字段
  9299. $scope.apCheck = {
  9300. custUu: '',
  9301. custName: '',
  9302. enUu: '',
  9303. apDate: '',
  9304. beginDate: '',
  9305. endDate: '',
  9306. checkStatus: '未对账',
  9307. checkAmount: 0,
  9308. currency: '',
  9309. rate: '',
  9310. items: [],
  9311. taxrate: ''
  9312. };
  9313. //保存来源单据相关信息
  9314. var sourceInfos = [];
  9315. //所允许的本次对账最大最小数量
  9316. $scope.data.maxThisCheckQty = 0;
  9317. $scope.data.minThisCheckQty = 0;
  9318. $scope.sameCust = true;
  9319. $scope.validQty = true;
  9320. $scope.loading = true;
  9321. angular.forEach($scope.data, function (check) {
  9322. //保存应收对账单明细行数据
  9323. $scope.item = {
  9324. inoutno: '',
  9325. inoutnodetno: '',
  9326. orderCode: '',
  9327. orderClass: '',
  9328. orderDetno: '',
  9329. price: '',
  9330. checkQty: '',
  9331. amount: '',
  9332. sourceId: '',
  9333. sourceTable: '',
  9334. oldYCheckQty: '',
  9335. status: 0,
  9336. receiveCode: '',
  9337. receiveName: '',
  9338. prodCode: '',
  9339. prodTitle: '',
  9340. prodUnit: '',
  9341. prodSpec: '',
  9342. taxrate: '',
  9343. sendcode: '',
  9344. whname: '',
  9345. custUserUU: ''
  9346. };
  9347. //应收对账单明细行来源表信息
  9348. $scope.sourceInfo = {
  9349. sourceId: '',
  9350. sourceTable: '',
  9351. newYCheckQty: ''
  9352. };
  9353. //此次对账后新的已转数
  9354. $scope.newYCheckQty = 0;
  9355. if (check.$selected == true) {
  9356. $scope.apCheck.custName = check.custname;
  9357. $scope.apCheck.enUu = check.enuu;
  9358. $scope.apCheck.checkAmount += (check.thischeckqty || 0) * (check.orderprice || 0);
  9359. $scope.apCheck.apDate = check.pidate;
  9360. $scope.apCheck.rate = check.rate;
  9361. //必须是同一家客户才能生成对账单,否则提示错误
  9362. if ($scope.apCheck.custUu == '') {
  9363. $scope.apCheck.custUu = check.custuu;
  9364. } else if ($scope.apCheck.custUu !== check.custuu) {
  9365. $scope.sameCust = false;
  9366. $scope.loading = false;
  9367. toaster.pop('error', '请选择同一家客户');
  9368. }
  9369. //必须是相同币别才能生成对账单,否则提示错误
  9370. if ($scope.apCheck.currency == '') {
  9371. $scope.apCheck.currency = check.currency;
  9372. } else if ($scope.apCheck.currency !== check.currency) {
  9373. $scope.sameCust = false;
  9374. $scope.loading = false;
  9375. toaster.pop('error', '请选择同一种币别');
  9376. }
  9377. //必须是相同税率才能生成对账单,否则提示错误
  9378. if (!angular.isNumber($scope.apCheck.taxrate)) {
  9379. $scope.apCheck.taxrate = check.taxrate;
  9380. } else if ($scope.apCheck.taxrate != check.taxrate) {
  9381. $scope.sameCust = false;
  9382. $scope.loading = false;
  9383. toaster.pop('error', '请选择相同的税率');
  9384. }
  9385. //本次对账数量必须小于总对账数量
  9386. if (check.qty > 0) {
  9387. $scope.data.maxThisCheckQty = check.qty;
  9388. $scope.data.minThisCheckQty = 0;
  9389. if (check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0) {
  9390. $scope.validQty = false;
  9391. $scope.loading = false;
  9392. toaster.pop('error', '本次对账数量,填写有误!');
  9393. }
  9394. } else if (check.qty < 0) {
  9395. $scope.data.maxThisCheckQty = 0;
  9396. $scope.data.minThisCheckQty = check.qty;
  9397. if (((-check.qty) - (-check.ycheckqty) < (-check.thischeckqty)) || check.thischeckqty > 0 || check.thischeckqty == 0) {
  9398. $scope.validQty = false;
  9399. $scope.loading = false;
  9400. toaster.pop('error', '本次对账数量,填写有误!');
  9401. }
  9402. }
  9403. //获取筛选时间的开始时间为对账的开始时间
  9404. $scope.apCheck.beginDate = $scope.fromDate;
  9405. //获取筛选的截止时间为对账的截止时间
  9406. $scope.apCheck.endDate = $scope.endDate;
  9407. //应收对账单明细行数据
  9408. $scope.item.orderCode = check.ordercode;
  9409. $scope.item.orderClass = check.piclass;
  9410. $scope.item.orderDetno = check.orderdetno;
  9411. $scope.item.price = check.orderprice;
  9412. $scope.item.checkQty = check.thischeckqty;
  9413. $scope.item.amount = (check.thischeckqty || 0) * (check.orderprice || 0);
  9414. $scope.item.sourceId = check.sourceid;
  9415. $scope.item.sourceTable = check.sourcetable;
  9416. $scope.item.oldYCheckQty = check.ycheckqty;
  9417. $scope.item.prodCode = check.prodcode;
  9418. $scope.item.prodTitle = check.prodtitle;
  9419. $scope.item.prodSpec = check.prodspec;
  9420. $scope.item.prodUnit = check.produnit;
  9421. $scope.item.inoutno = check.inoutno;
  9422. $scope.item.inoutnodetno = check.detno;
  9423. $scope.item.taxrate = check.taxrate;
  9424. $scope.item.receiveCode = check.receivecode;
  9425. $scope.item.receiveName = check.receivename;
  9426. $scope.item.sendcode = check.sendcode;
  9427. $scope.item.whname = check.whname;
  9428. $scope.item.custUserUU = check.custuseruu;
  9429. //来源表相关信息
  9430. $scope.sourceInfo.sourceid = check.sourceid;
  9431. $scope.sourceInfo.sourcetable = check.sourcetable;
  9432. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  9433. sourceInfos.push($scope.sourceInfo);
  9434. $scope.apCheck.items.push($scope.item);
  9435. $scope.haveSelected = true;
  9436. }
  9437. });
  9438. //保存生成的应收对账单
  9439. $scope.saveApCheck = function () {
  9440. if ($scope.apCheck.items.length == 0) {
  9441. $scope.loading = false;
  9442. toaster.pop('error', '请先选择需要对账的数据');
  9443. } else {
  9444. FaApCheck.saveApCheck({}, $scope.apCheck, function (data) {
  9445. $scope.loading = false;
  9446. toaster.pop('success', '成功', '生成应收对账成功');
  9447. $state.go('fa.apCheck_detail', {id: data.id}, {reload: true});
  9448. }, function (response) {
  9449. $scope.loading = false;
  9450. toaster.pop('error', '生成对账单失败', response.data);
  9451. })
  9452. }
  9453. };
  9454. //如果是同一家客户,生成对账单的同时,关闭模态框
  9455. if ($scope.sameCust && $scope.validQty) {
  9456. $scope.saveApCheck();
  9457. }
  9458. }
  9459. }]);
  9460. // 企业信息设置
  9461. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function ($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder) {
  9462. BaseService.scrollBackToTop();
  9463. $scope.loading = true;
  9464. AccountEnterprise.get({}, function (data) {
  9465. $scope.loading = false;
  9466. $scope.enterprise = data;
  9467. if (data.tags) {
  9468. $scope.tags = data.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  9469. } else {
  9470. $scope.tags = [];
  9471. }
  9472. // 获取付款企业信息
  9473. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  9474. $scope.pays = data;
  9475. }, function (response) {
  9476. toaster.pop('error', '提示', response.data);
  9477. });
  9478. });
  9479. // 更新企业信息
  9480. $scope.updateDetailInfo = function () {
  9481. $scope.loading = true;
  9482. $scope.enterprise = $scope.copyEnterprise;
  9483. $scope.enterprise.tags = $scope.tags.join(','); // 将标签数组转换成逗号分隔的字符串,便于储存
  9484. AccountEnterprise.save($scope.enterprise, function () {
  9485. $scope.loading = false;
  9486. $scope.connectionEditing = false;
  9487. toaster.pop('success', '提示', '修改企业信息成功');
  9488. $state.reload();
  9489. }, function (response) {
  9490. $scope.loading = false;
  9491. toaster.pop('error', '修改信息失败', response.data);
  9492. });
  9493. };
  9494. // 申请Saas
  9495. $scope.applySaas = function () {
  9496. if ($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  9497. var modalInstance = $modal.open({
  9498. animation: true,
  9499. templateUrl: 'static/tpl/index/account/applySaas.html',
  9500. controller: 'ApplySaasCtrl',
  9501. resolve: {
  9502. enterprise: function () {
  9503. return angular.copy($scope.enterprise);
  9504. }
  9505. }
  9506. });
  9507. modalInstance.result.then(function () {
  9508. $state.reload();
  9509. }, function () {
  9510. });
  9511. } else {
  9512. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  9513. }
  9514. };
  9515. // 获取收货地址列表
  9516. ShipAddress.shipAddList({}, function (data) {
  9517. $scope.ships = data;
  9518. });
  9519. // 判断是否是代采企业
  9520. DeputyOrder.isDeputyEnterprise({}, function (data) {
  9521. $scope.deputyEnter = data;
  9522. });
  9523. // 获取地址信息
  9524. $http.get('resources/citydata/city.json', {
  9525. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9526. }).then(function (response) {
  9527. $scope.provinces = response.data;
  9528. });
  9529. // 新增收货地址保存
  9530. $scope.saveShipAddress = function (ship) {
  9531. ship.address = ship.province + ship.city + ship.district;
  9532. ShipAddress.saveAddress({}, ship, function (data) {
  9533. if (data.success) {
  9534. ShipAddress.shipAddList({}, function (data) {
  9535. $scope.ships = data;
  9536. });
  9537. toaster.pop('success', '提示', data.success);
  9538. $scope.ship = {receiver: null, usertel: null, phone: null, email: null, province: null, city: null, district: null, addressdet: null, addalias: null, address: null};
  9539. }
  9540. if (data.error) {
  9541. toaster.pop('error', '提示', data.error);
  9542. }
  9543. });
  9544. }
  9545. // 删除收货地址
  9546. $scope.removeShip = function (id, index) {
  9547. ShipAddress.removeShipAddress({id: id}, {}, function (data) {
  9548. $scope.ships.splice(index, 1);
  9549. toaster.pop('success', '提示', '收货地址删除成功');
  9550. }, function (response) {
  9551. toaster.pop('error', '提示', response.data);
  9552. });
  9553. };
  9554. // 编辑收货地址
  9555. $scope.editShip = function (ship) {
  9556. var modalInstance = $modal.open({
  9557. animation: true,
  9558. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  9559. controller: 'ShipAddressCtrl',
  9560. resolve: {
  9561. ship: function () {
  9562. return ship;
  9563. }
  9564. }
  9565. });
  9566. modalInstance.result.then(function () {
  9567. ShipAddress.shipAddList({}, function (data) {
  9568. $scope.ships = data;
  9569. });
  9570. }, function () {
  9571. });
  9572. };
  9573. // 新增付款企业
  9574. $scope.addPayCompany = function () {
  9575. var modalInstance = $modal.open({
  9576. animation: true,
  9577. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  9578. controller: 'PayCompanyCtrl',
  9579. resolve: {
  9580. pay: function () {
  9581. return null;
  9582. }
  9583. }
  9584. });
  9585. modalInstance.result.then(function () {
  9586. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  9587. $scope.pays = data;
  9588. // 获取付款企业信息
  9589. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  9590. $scope.pays = data;
  9591. }, function (response) {
  9592. toaster.pop('error', '提示', response.data);
  9593. });
  9594. }, function (response) {
  9595. toaster.pop('error', '提示', response.data);
  9596. });
  9597. }, function () {
  9598. });
  9599. }
  9600. // 删除付款企业
  9601. $scope.removePay = function (id, index) {
  9602. DeputyOrder.removePayCompany({id: id}, {}, function (data) {
  9603. $scope.pays.splice(index, 1);
  9604. toaster.pop('success', '提示', '付款企业信息删除成功');
  9605. }, function (response) {
  9606. toaster.pop('error', '提示', response.data);
  9607. });
  9608. };
  9609. // 编辑付款企业
  9610. $scope.editPay = function (pay, uu) {
  9611. var modalInstance = $modal.open({
  9612. animation: true,
  9613. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  9614. controller: 'PayCompanyCtrl',
  9615. resolve: {
  9616. pay: function () {
  9617. return pay;
  9618. }
  9619. }
  9620. });
  9621. modalInstance.result.then(function () {
  9622. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  9623. $scope.pays = data;
  9624. }, function (response) {
  9625. toaster.pop('error', '提示', response.data);
  9626. });
  9627. }, function () {
  9628. });
  9629. };
  9630. // 设置logo
  9631. $scope.showImageDialog = function (modal) {
  9632. require(['jquery-uploadify'], function () {
  9633. $modal.open({
  9634. templateUrl: 'static/tpl/index/home/insert.html',
  9635. controller: 'ImageInsertCtrl',
  9636. backdrop: 'static'
  9637. }).result.then(function (image) {
  9638. $scope.imageUrl = image.thumb;
  9639. User.postImageUrl(null, angular.toJson($scope.imageUrl), function (data) {
  9640. $scope.user = data;
  9641. }, function (response) {
  9642. toaster.pop('error', '设置图像失败,' + response.data);
  9643. });
  9644. });
  9645. });
  9646. }
  9647. // 添加经营范围标签
  9648. $scope.addTag = function () {
  9649. if ($scope.tags.indexOf($scope.tag) == -1){
  9650. if (null != $scope.tag && '' != $scope.tag) {
  9651. $scope.tags.push($scope.tag);
  9652. }
  9653. }
  9654. $scope.tag = '';
  9655. }
  9656. // 移除经营范围标签
  9657. $scope.removeTag = function (tag) {
  9658. removeByValue($scope.tags, tag);
  9659. }
  9660. // 获取行业信息
  9661. $http.get('static/data/profession.json').success(function (data) {
  9662. $scope.list = data;
  9663. });
  9664. // 选择行业
  9665. $scope.profession = new Array();
  9666. $scope.showProfession = false;
  9667. $scope.selectProfession = function () {
  9668. $scope.professionArray = [];
  9669. $scope.active = [];
  9670. $scope.showProfession = !$scope.showProfession;
  9671. $scope.profession[0] = $scope.list;
  9672. }
  9673. $scope.isInList = false;
  9674. $scope.isInInput = false;
  9675. $scope.hideList = function () {
  9676. if (!$scope.isInList && !$scope.isInInput && $scope.showProfession) {
  9677. $scope.showProfession = false;
  9678. }
  9679. }
  9680. // 行业子菜单点击
  9681. $scope.onItemClick = function (key, index, value) {
  9682. $scope.active[index] = key;
  9683. if (angular.isString(value)){ // 值为字符串说明点击的是最后一级
  9684. $scope.copyEnterprise.profession = value;
  9685. $scope.showProfession = false;
  9686. return;
  9687. }
  9688. $scope.professionArray = [];
  9689. $scope.profession.splice(index+1);
  9690. if (angular.isArray(value)){ // 值为数组说明下一级是最后一级
  9691. $scope.professionArray = value;
  9692. } else if (angular.isObject(value)) {
  9693. $scope.profession[index+1] = value;
  9694. }
  9695. }
  9696. // 判断值是否为字符串
  9697. $scope.isString = function (value) {
  9698. return angular.isString(value);
  9699. }
  9700. // 拷贝企业数据,在编辑企业数据是使用拷贝数据
  9701. $scope.copyData = function () {
  9702. $scope.copyEnterprise = angular.copy($scope.enterprise);
  9703. if ($scope.enterprise.tags) {
  9704. $scope.tags = $scope.enterprise.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  9705. } else {
  9706. $scope.tags = [];
  9707. }
  9708. }
  9709. }]);
  9710. // 编辑收货地址
  9711. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function ($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  9712. $scope.ship = ship;
  9713. // 获取地址信息
  9714. $http.get('resources/citydata/city.json', {
  9715. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9716. }).then(function (response) {
  9717. $scope.provinces = response.data;
  9718. });
  9719. // 新增收货地址保存
  9720. $scope.saveShipAddress = function (ship) {
  9721. ship.address = ship.province + ship.city + ship.district;
  9722. ShipAddress.saveAddress({}, ship, function (data) {
  9723. if (data.success) {
  9724. toaster.pop('success', '提示', data.success);
  9725. $modalInstance.close();
  9726. }
  9727. if (data.error) {
  9728. toaster.pop('error', '提示', data.error);
  9729. }
  9730. });
  9731. }
  9732. $scope.cancel = function () {
  9733. $modalInstance.dismiss();
  9734. }
  9735. }]);
  9736. // 编辑付款企业信息
  9737. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function ($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  9738. $scope.pay = pay;
  9739. // 获取地址信息
  9740. $http.get('resources/citydata/city.json', {
  9741. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  9742. }).then(function (response) {
  9743. $scope.provinces = response.data;
  9744. });
  9745. // 新增收货地址保存
  9746. $scope.savePayCompany = function (pay) {
  9747. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  9748. DeputyOrder.savePaycompany({}, pay, function (data) {
  9749. toaster.pop('success', '提示', '保存成功');
  9750. $modalInstance.dismiss();
  9751. }, function (response) {
  9752. toaster.pop('error', '提示', response.data);
  9753. });
  9754. }
  9755. $scope.cancel = function () {
  9756. $modalInstance.dismiss();
  9757. }
  9758. }]);
  9759. // 申请Saas Controller
  9760. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function ($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http) {
  9761. $scope.enterprise = enterprise;
  9762. $scope.checking = false;
  9763. $scope.$watch('enterprise.enSaasUrl', function () {
  9764. if ($scope.enterprise.enSaasUrl) {
  9765. $http.get('signup/saasUrlEnable', {
  9766. params: {
  9767. enSaasUrl: $scope.enterprise.enSaasUrl
  9768. }
  9769. }).success(function (data) {
  9770. if (data && data == 'true') {
  9771. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  9772. } else {
  9773. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  9774. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  9775. }
  9776. }).error(function () {
  9777. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  9778. $scope.enSaasUrlErrorInfo = '验证出错';
  9779. });
  9780. } else {
  9781. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  9782. }
  9783. });
  9784. var setSaasUrl = function (url) {
  9785. var index = url.indexOf('www.');
  9786. if (index != -1) {//包含www.
  9787. var substr = url.substring(index + 4, url.length);
  9788. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  9789. } else {
  9790. $scope.enterprise.enSaasUrl = getHost(url);
  9791. }
  9792. };
  9793. // 解析获取网址的一级域名
  9794. var getHost = function (host) {
  9795. var newhost;
  9796. var domain;
  9797. var ArrDomain = new Array('.com.cn', '.net.cn', '.org.cn', '.gov.cn', '.com', '.cn', '.tel', '.mobi', '.net', '.org', '.asia', '.me', '.cc', '.name', '.info');//枚举所有后缀
  9798. for (var k in ArrDomain) {
  9799. var re = eval('/\\' + ArrDomain[k] + '$/g');
  9800. newhost = host.replace(re, '');
  9801. if (newhost != host) {
  9802. domain = ArrDomain[k];
  9803. break;
  9804. }
  9805. }
  9806. var hostar = newhost.split('.');
  9807. var s = hostar[hostar.length - 1];
  9808. return s;
  9809. };
  9810. // 设置优企云服域名为官网网址一级域名
  9811. if ($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  9812. $scope.apply = function () {
  9813. $scope.loading = true;
  9814. AccountEnterprise.applySaas({
  9815. enUU: $scope.enterprise.uu,
  9816. enSaasUrl: $scope.enterprise.enSaasUrl,
  9817. enAdminPassword: $scope.enterprise.enAdminPassword
  9818. }, {}, function () {
  9819. $scope.loading = false;
  9820. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  9821. $modalInstance.close();
  9822. }, function (response) {
  9823. $scope.loading = false;
  9824. toaster.pop('error', '申请失败', response.data);
  9825. });
  9826. };
  9827. $scope.cancel = function () {
  9828. $modalInstance.dismiss();
  9829. };
  9830. }]);
  9831. 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) {
  9832. BaseService.scrollBackToTop();
  9833. $scope.editing = false;
  9834. $scope.loading = true;
  9835. $scope.enterprise = null;
  9836. $scope.searchMthod = false;
  9837. $scope.keyword = null;
  9838. AccountUser.findDistribute({}, function (data) {
  9839. $scope.distributes = data;
  9840. }, function (response) {
  9841. toaster.pop('error', '系统错误', response.data);
  9842. });
  9843. AuthenticationService.getAuthentication().success(function (data) {
  9844. $scope.loading = false;
  9845. $scope.user = data;
  9846. });
  9847. var users = [];
  9848. var getMangagerInfo = function() {
  9849. CurrentRole.isManager({}, function(data) {
  9850. $scope.isManager = data.isManager || $scope.user.sys;
  9851. });
  9852. CurrentRole.roles({}, function(data) {
  9853. $scope.roles = data.count || $scope.user.sys;
  9854. });
  9855. };
  9856. getMangagerInfo();
  9857. $scope.tableParams = new ngTableParams({
  9858. page: 1,
  9859. count: 20,
  9860. sorting: {
  9861. userName: 'asc'
  9862. }
  9863. }, {
  9864. total: 0,
  9865. counts: [15, 25, 50, 100],
  9866. getData: function ($defer, params) {
  9867. $scope.loading = true;
  9868. var pageParams = params.url();
  9869. pageParams.keyword = $scope.keyword;
  9870. $scope.tip = $scope.keyword;
  9871. AccountUser.getAll.call(null, BaseService.parseParams(pageParams), function (page) {
  9872. $scope.loading = false;
  9873. if (page) {
  9874. params.total(page.totalElement);
  9875. $defer.resolve(page.content);
  9876. users = page.content;
  9877. if(users.length > 0) {
  9878. if(users.length > 0) {
  9879. angular.forEach(users, function (user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  9880. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  9881. $scope.user.userIdcode = user.userIdcode;
  9882. }
  9883. });
  9884. }
  9885. }
  9886. }
  9887. }, function (response) {
  9888. $scope.loading = false;
  9889. toaster.pop('error', '数据加载失败', response.data);
  9890. });
  9891. }
  9892. });
  9893. $scope.onSearch = function(keyword) {
  9894. $scope.keyword = keyword;
  9895. $scope.tableParams.reload();
  9896. $scope.tableParams.page(1);
  9897. }
  9898. $scope.saveUser = function () {
  9899. $scope.loading = true;
  9900. AccountUser.update({}, $scope.user, function (data) {
  9901. $scope.loading = false;
  9902. toaster.pop('success', '提示', '修改用户信息成功');
  9903. AuthenticationService.getAuthentication().success(function (data) {
  9904. $scope.user = data;
  9905. });
  9906. loadUsers();
  9907. $scope.editing = false;
  9908. }, function (reponse) {
  9909. $scope.loading = false;
  9910. toaster.pop('error', '失败', reponse.data);
  9911. });
  9912. };
  9913. $scope.updatePassword = function () {
  9914. var newPage = window.open("about:black");
  9915. AccountUser.getUpdatePasswordUrl({returnUrl: window.location.href}, function (data) {
  9916. newPage.location.href = data.url;
  9917. });
  9918. };
  9919. $scope.updateDetail = function () {
  9920. var newPage = window.open("about:black");
  9921. AccountUser.getCloudCenterUrl({}, function (data) {
  9922. newPage.location.href = data.url;
  9923. });
  9924. }
  9925. $scope.newUser = {};
  9926. //弹出添加用户模态框
  9927. $scope.addExistUser = function () {
  9928. var modalInstance = $modal.open({
  9929. animation: true,
  9930. templateUrl: 'static/tpl/index/account/addExistUser.html',
  9931. controller: 'AddExistUserCtrl'
  9932. });
  9933. modalInstance.result.then(function () {
  9934. $scope.userTelSuccess = false;
  9935. $scope.userTelError = false;
  9936. $scope.tableParams.reload();
  9937. }, function () {
  9938. });
  9939. };
  9940. /**
  9941. * 添加未注册用户
  9942. */
  9943. $scope.submit = false;
  9944. $scope.addUser = function () {
  9945. $scope.submit = true;
  9946. $scope.adding = true;
  9947. $scope.loading = true;
  9948. AccountUser.save({}, $scope.newUser, function (data) {
  9949. $scope.loading = false;
  9950. $scope.submit = false;
  9951. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  9952. $scope.newUser = {userSex: 'M'};
  9953. $scope.tableParams.reload();
  9954. $scope.adding = false;
  9955. $scope.newUserForm.newUserTel.$setValidity('available', false);
  9956. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  9957. $scope.userTelSuccess = false;
  9958. $scope.userTelError = false;
  9959. $scope.userEmailSuccess = false;
  9960. $scope.userEmailError = false;
  9961. }, function (response) {
  9962. $scope.submit = false;
  9963. $scope.loading = false;
  9964. toaster.pop('error', '错误', response.data);
  9965. });
  9966. };
  9967. /**
  9968. * 验证手机号是否可用
  9969. */
  9970. $scope.telValid = function (tel) {
  9971. if (tel) {
  9972. $http.get('account/user/telEnable', {
  9973. params: {
  9974. tel: tel
  9975. }
  9976. }).success(function (data) {
  9977. data = eval(data);
  9978. if (data == true) {
  9979. $scope.newUserForm.newUserTel.$setValidity('available', true);
  9980. $scope.userTelSuccess = true;
  9981. $scope.userTelError = false;
  9982. } else {
  9983. $scope.newUserForm.newUserTel.$setValidity('available', false);
  9984. $scope.userTelError = true;
  9985. $scope.userTelSuccess = false;
  9986. if (tel.length == 11)
  9987. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  9988. }
  9989. }).error(function () {
  9990. $scope.userTelSuccess = false;
  9991. $scope.userTelError = true;
  9992. });
  9993. } else {
  9994. $scope.userTelSuccess = false;
  9995. $scope.userTelError = false;
  9996. }
  9997. };
  9998. /**
  9999. * 验证邮箱是否可用
  10000. */
  10001. $scope.emailValid = function (email) {
  10002. if (email) {
  10003. $http.get('account/user/emailEnable', {
  10004. params: {
  10005. email: email
  10006. }
  10007. }).success(function (data) {
  10008. data = eval(data);
  10009. if (data == true) {
  10010. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  10011. $scope.userEmailSuccess = true;
  10012. $scope.userEmailError = false;
  10013. } else {
  10014. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10015. $scope.userEmailError = true;
  10016. $scope.userEmailSuccess = false;
  10017. }
  10018. }).error(function () {
  10019. $scope.userEmailError = true;
  10020. $scope.userEmailSuccess = false;
  10021. });
  10022. } else {
  10023. $scope.userEmailError = false;
  10024. $scope.userEmailSuccess = false;
  10025. }
  10026. };
  10027. /**
  10028. * 删除用户
  10029. */
  10030. $scope.removeUser = function (user) {
  10031. new ngAlert({
  10032. title: '提示',
  10033. content: '确定删除用户(' + user.userName + ')吗?'
  10034. }, function () {
  10035. AccountUser.remove({uu: user.userUU}, function () {
  10036. toaster.pop('success', '提示', '用户删除成功。');
  10037. loadUsers();
  10038. }, function (response) {
  10039. toaster.pop('error', '删除失败', response.data);
  10040. });
  10041. });
  10042. };
  10043. // 编辑用户的角色
  10044. $scope.editUserRole = function (user) {
  10045. var modalInstance = $modal.open({
  10046. animation: true,
  10047. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  10048. controller: 'UserRoleCtrl',
  10049. resolve: {
  10050. user: function () {
  10051. return user;
  10052. }
  10053. }
  10054. });
  10055. modalInstance.result.then(function (changed, checked) {
  10056. if (changed) {
  10057. if (checked)
  10058. $scope.newUser.roles = checked;
  10059. else
  10060. loadUsers();
  10061. }
  10062. });
  10063. };
  10064. // 为用户分配角色(删除企业)
  10065. $scope.removeVendor = function (user) {
  10066. var resultRole = true;
  10067. angular.forEach(user.roles, function (role) {
  10068. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10069. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10070. resultRole = false;
  10071. return;
  10072. }
  10073. });
  10074. if (resultRole) {
  10075. var modalInstance = $modal.open({
  10076. animation: true,
  10077. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  10078. controller: 'RemoveVendorCtrl',
  10079. resolve: {
  10080. user: function () {
  10081. return user;
  10082. }
  10083. }
  10084. });
  10085. }
  10086. };
  10087. // 为用户分配角色(添加企业)
  10088. $scope.addVendor = function (user, isIssy) {
  10089. if (!$scope.roles) {
  10090. toaster.pop('error', '提示', '你不是管理员或销售经理,无权限分配!请立即联系管理员');
  10091. return;
  10092. }
  10093. var resultRole = true;
  10094. angular.forEach(user.roles, function (role) {
  10095. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10096. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10097. resultRole = false;
  10098. return;
  10099. }
  10100. })
  10101. if (resultRole) {
  10102. var modalInstance = $modal.open({
  10103. animation: true,
  10104. templateUrl: 'static/tpl/index/account/add_vendor.html',
  10105. controller: 'AddVendorCtrl',
  10106. resolve: {
  10107. user: function () {
  10108. return user;
  10109. }
  10110. }
  10111. });
  10112. modalInstance.result.then(function (changed, checked) {
  10113. if (changed) {
  10114. if (checked)
  10115. $scope.newUser.roles = checked;
  10116. else
  10117. loadUsers();
  10118. }
  10119. });
  10120. }
  10121. };
  10122. }]);
  10123. // 登录手机号码验证
  10124. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function ($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout) {
  10125. $scope.user = user;
  10126. $scope.cancel = function () {
  10127. $modalInstance.close();
  10128. }
  10129. }]);
  10130. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10131. $scope.checkboxes = {
  10132. checked: false
  10133. };
  10134. $scope.loading = true;
  10135. AccountUser.findChooseVendor({uu: user.userUU}, function (data) {
  10136. $scope.enters = data;
  10137. $scope.loading = false;
  10138. angular.forEach($scope.enters, function (item) {
  10139. item:{
  10140. $selected:true;
  10141. }
  10142. });
  10143. })
  10144. // 点击勾选全部的复选框
  10145. $scope.checkAll = function () {
  10146. angular.forEach($scope.enters, function (item) {
  10147. item.$selected = $scope.checkboxes.checked;
  10148. });
  10149. };
  10150. // 点击其中一个明细的复选框
  10151. $scope.checkOne = function (vendor) {
  10152. var result = true;
  10153. angular.forEach($scope.enters, function (item) {
  10154. if (item.$selected != true) {
  10155. result = false;
  10156. return;
  10157. }
  10158. });
  10159. $scope.checkboxes.checked = result;
  10160. };
  10161. $scope.close = function (save) {
  10162. var chooseResult = [];
  10163. if (save) {
  10164. if (user.userUU) {
  10165. angular.forEach($scope.enters, function (item, i) {
  10166. if (item.$selected) {
  10167. chooseResult.push(item.id);
  10168. }
  10169. });
  10170. if (chooseResult.length > 0) {
  10171. $scope.loading = true;
  10172. AccountUser.removeChooseVendor({uu: user.userUU}, chooseResult, function (data) {
  10173. $scope.loading = false;
  10174. toaster.pop('success', '提示', '删除成功');
  10175. $modalInstance.close(false);
  10176. }, function (response) {
  10177. $scope.loading = false;
  10178. toaster.pop('error', '删除失败', response.data);
  10179. $modalInstance.close(false);
  10180. })
  10181. } else {
  10182. toaster.pop('error', '删除失败', "您未勾选任何记录");
  10183. }
  10184. } else {
  10185. $modalInstance.close(true, $scope.checkboxes.checked);
  10186. }
  10187. } else {
  10188. $modalInstance.close(false);
  10189. }
  10190. };
  10191. }]);
  10192. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10193. $scope.checkboxes = {
  10194. checked: false
  10195. };
  10196. $scope.loading = true;
  10197. AccountUser.findVendor({uu: user.userUU}, function (data) {
  10198. $scope.enters = data;
  10199. $scope.loading = false;
  10200. })
  10201. // 点击勾选全部的复选框
  10202. $scope.checkAll = function () {
  10203. angular.forEach($scope.enters, function (item) {
  10204. item.distribute = $scope.checkboxes.checked;
  10205. });
  10206. };
  10207. // 点击其中一个明细的复选框
  10208. $scope.checkOne = function (vendor) {
  10209. var result = true;
  10210. angular.forEach($scope.enters, function (item) {
  10211. if (item.distribute != true) {
  10212. result = false;
  10213. return;
  10214. }
  10215. });
  10216. $scope.checkboxes.checked = result;
  10217. };
  10218. $scope.close = function (save) {
  10219. var chooseResult = [];
  10220. if (save) {
  10221. if (user.userUU) {
  10222. angular.forEach($scope.enters, function (item, i) {
  10223. chooseResult.push(item);
  10224. });
  10225. if (chooseResult.length > 0) {
  10226. $scope.loading = true;
  10227. AccountUser.addVendor({uu: user.userUU}, chooseResult, function (data) {
  10228. $scope.loading = false;
  10229. toaster.pop('success', '提示', '保存成功');
  10230. $modalInstance.close(false);
  10231. }, function (response) {
  10232. $scope.loading = false;
  10233. toaster.pop('error', '保存失败', response.data);
  10234. $modalInstance.close(false);
  10235. })
  10236. } else {
  10237. toaster.pop('error', '保存失败', "您未勾选任何记录");
  10238. }
  10239. } else {
  10240. $modalInstance.close(true, $scope.checkboxes.checked);
  10241. }
  10242. } else {
  10243. $modalInstance.close(false);
  10244. }
  10245. };
  10246. }]);
  10247. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountRole, AccountUser, toaster) {
  10248. $scope.checked = [];
  10249. $scope.master = [];
  10250. AccountRole.query({}, function (data) {
  10251. if (user && data) {
  10252. var rs = [], checked = [];
  10253. angular.forEach(user.roles, function (r) {
  10254. rs.push(r.id);
  10255. });
  10256. angular.forEach(data, function (d) {
  10257. if (rs.indexOf(d.id) > -1) {
  10258. d.$checked = true;
  10259. checked.push(d);
  10260. }
  10261. });
  10262. }
  10263. $scope.roles = data;
  10264. $scope.checked = checked;
  10265. $scope.master = angular.copy($scope.checked);
  10266. });
  10267. $scope.select = function (role) {
  10268. role.$checked = !role.$checked;
  10269. if (role.$checked) {
  10270. if (role.desc === '管理员' || role.desc === '普通用户') {
  10271. $scope.checked = [];
  10272. angular.forEach($scope.roles, function (r) {
  10273. r.$checked = false;
  10274. });
  10275. role.$checked = true;
  10276. $scope.checked.push(role);
  10277. } else {
  10278. angular.forEach( $scope.checked, function (r, i) {
  10279. if (r.desc === '管理员' || r.desc === '普通用户') {
  10280. $scope.checked.splice(i, 1);
  10281. }
  10282. });
  10283. angular.forEach($scope.roles, function (r) {
  10284. if (r.desc === '管理员' || r.desc === '普通用户') {
  10285. r.$checked = false;
  10286. }
  10287. });
  10288. $scope.checked.push(role);
  10289. }
  10290. } else {
  10291. angular.forEach($scope.checked, function (c, i) {
  10292. if (c.id == role.id)
  10293. $scope.checked.splice(i, 1);
  10294. });
  10295. }
  10296. };
  10297. $scope.isChanged = function () {
  10298. return !angular.equals($scope.master, $scope.checked);
  10299. };
  10300. $scope.close = function (save) {
  10301. if (save) {
  10302. if (user.userUU) {
  10303. user.roles = $scope.checked;
  10304. AccountUser.updateRole({}, user, function () {
  10305. toaster.pop('success', '提示', '保存成功');
  10306. $modalInstance.close(true);
  10307. }, function (response) {
  10308. toaster.pop('error', '保存失败', response.data);
  10309. });
  10310. } else {
  10311. $modalInstance.close(true, $scope.checked);
  10312. }
  10313. } else {
  10314. $modalInstance.close(false);
  10315. }
  10316. };
  10317. }]);
  10318. // 修改密码Controller
  10319. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10320. $scope.user = user;
  10321. $scope.checking = false;
  10322. //输入原密码后验证原密码是否正确
  10323. $scope.checkPassword = function (password) {
  10324. $scope.checking = true;
  10325. $scope.checkSuccess = false;
  10326. $scope.checkFailed = false;
  10327. AccountUser.checkPassword({password: password}, function (data) {
  10328. $scope.checkSuccess = true;
  10329. $scope.checking = false;
  10330. $scope.checkFailed = false;
  10331. }, function (response) {
  10332. $scope.checkFailed = true;
  10333. $scope.checking = false;
  10334. $scope.checkSuccess = false;
  10335. });
  10336. };
  10337. //修改密码
  10338. $scope.ok = function () {
  10339. if ($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  10340. AccountUser.updatePassword({
  10341. password: $scope.user.password,
  10342. newPassword: $scope.user.newPassword
  10343. }, {}, function (data) {
  10344. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  10345. toaster.pop('success', '成功', tip);
  10346. $scope.user.password = null;
  10347. $scope.user.newPassword = null;
  10348. $scope.user.newPassword1 = null;
  10349. $scope.checking = false;
  10350. $scope.checkSuccess = false;
  10351. $scope.checkFailed = false;
  10352. $modalInstance.close();
  10353. }, function (response) {
  10354. toaster.pop('error', '错误', response.data);
  10355. });
  10356. } else {
  10357. toaster.pop('error', '错误', '重复密码不一致');
  10358. }
  10359. };
  10360. $scope.cancel = function () {
  10361. $modalInstance.dismiss();
  10362. };
  10363. }]);
  10364. /*
  10365. * 绑定用户到企业
  10366. */
  10367. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function ($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster) {
  10368. $scope.searching = false;
  10369. //根据输入的内容查找用户
  10370. $scope.searchUser = function (keyWord) {
  10371. $scope.searching = true;
  10372. $scope.searchSuccess = false;
  10373. $scope.searchFailed = false;
  10374. $scope.illegalError = false;
  10375. $scope.reBindError = false;
  10376. $scope.okDisabled = false;
  10377. FuzzySearch.searchUser({keyWord: keyWord}, function (data) {
  10378. $scope.searchSuccess = true;
  10379. $scope.searchFailed = false;
  10380. $scope.user = data; //查询到的用户
  10381. }, function (response) {
  10382. $scope.searchSuccess = false;
  10383. $scope.searchFailed = true;
  10384. });
  10385. };
  10386. //确认绑定
  10387. $scope.ok = function (keyWord) {
  10388. AuthenticationService.getAuthentication().success(function (data) {
  10389. $scope.currentUser = data; //当前登录的用户(管理员)
  10390. //不可自己绑定自己
  10391. if ($scope.currentUser.userUU == $scope.user.userUU) {
  10392. $scope.illegalError = true;
  10393. $scope.okDisabled = true;
  10394. return false;
  10395. }
  10396. //用户未绑定到任何企业时
  10397. if (!$scope.user.enterprises) {
  10398. //正常绑定
  10399. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  10400. $scope.okDisabled = true;
  10401. toaster.pop("success", "提示", "用户绑定成功");
  10402. $modalInstance.close(true);
  10403. }, function (response) {
  10404. });
  10405. return true;
  10406. }
  10407. //用户已绑定到某些企业时
  10408. for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
  10409. if ($scope.currentUser.enterprises[i].current) {
  10410. for (var j = 0; j < $scope.user.enterprises.length; j++) {
  10411. //该用户已绑定到当前企业,不可重复绑定
  10412. if ($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu) {
  10413. $scope.reBindError = true;
  10414. $scope.okDisabled = true;
  10415. return false;
  10416. }
  10417. }
  10418. //该用户未绑定到当前企业,可以进行绑定
  10419. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  10420. $scope.okDisabled = true;
  10421. toaster.pop("success", "提示", "用户绑定成功");
  10422. $modalInstance.close(true);
  10423. }, function (response) {
  10424. console.log("绑定失败!");
  10425. });
  10426. }
  10427. }
  10428. });
  10429. };
  10430. $scope.cancel = function () {
  10431. $modalInstance.dismiss();
  10432. };
  10433. }]);
  10434. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function ($scope, BaseService, ngTableParams, ErpLog, UsageLog) {
  10435. $scope.erpParams = new ngTableParams({
  10436. page: 1,
  10437. count: 20,
  10438. sorting: {
  10439. time: 'desc'
  10440. }
  10441. }, {
  10442. total: 0,
  10443. counts: [5, 10, 25, 50],
  10444. getData: function ($defer, params) {
  10445. $scope.loading = true;
  10446. ErpLog.get(BaseService.parseParams(params.url()), function (page) {
  10447. $scope.loading = false;
  10448. if (page) {
  10449. params.total(page.totalElements);
  10450. $defer.resolve(page.content);
  10451. }
  10452. }, function (response) {
  10453. $scope.loading = false;
  10454. toaster.pop('error', '数据加载失败', response.data);
  10455. });
  10456. }
  10457. });
  10458. $scope.usageParams = new ngTableParams({
  10459. page: 1,
  10460. count: 20,
  10461. sorting: {
  10462. time: 'desc'
  10463. }
  10464. }, {
  10465. total: 0,
  10466. counts: [5, 10, 25, 50],
  10467. getData: function ($defer, params) {
  10468. $scope.loading = true;
  10469. UsageLog.get(BaseService.parseParams(params.url()), function (page) {
  10470. $scope.loading = false;
  10471. if (page) {
  10472. params.total(page.totalElements);
  10473. $defer.resolve(page.content);
  10474. }
  10475. }, function (response) {
  10476. $scope.loading = false;
  10477. toaster.pop('error', '数据加载失败', response.data);
  10478. });
  10479. }
  10480. });
  10481. }]);
  10482. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function ($scope, AccountResource) {
  10483. AccountResource.query({}, function (data) {
  10484. if (data && data.length > 0) {
  10485. data[0].$open = true;
  10486. }
  10487. $scope.resources = data;
  10488. });
  10489. }]);
  10490. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function ($scope, $modal, AccountRole) {
  10491. $scope.roles = {};
  10492. var getData = function () {
  10493. AccountRole.query({}, function (data) {
  10494. var defaults = [], custom = [];
  10495. angular.forEach(data, function (d) {
  10496. if (d.isdefault == 1)
  10497. defaults.push(d);
  10498. else
  10499. custom.push(d);
  10500. });
  10501. $scope.roles = {defaults: defaults, custom: custom};
  10502. });
  10503. };
  10504. getData();
  10505. $scope.editRole = function (role) {
  10506. var modalInstance = $modal.open({
  10507. animation: true,
  10508. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  10509. controller: 'RoleEditCtrl',
  10510. resolve: {
  10511. role: function () {
  10512. return role;
  10513. }
  10514. }
  10515. });
  10516. modalInstance.result.then(function (added) {
  10517. added && (getData());
  10518. });
  10519. };
  10520. }]);
  10521. app.controller('RoleEditCtrl', ['$scope', '$modalInstance', '$timeout', 'AccountResource', 'AccountRole', 'toaster', 'role', 'ngAlert', 'BaseService', 'CurrentRole', 'AuthenticationService', function ($scope, $modalInstance, $timeout, AccountResource, AccountRole, toaster, role, ngAlert, BaseService, CurrentRole, AuthenticationService) {
  10522. BaseService.scrollBackToTop();
  10523. // 获取当前用户是否为管理员
  10524. AuthenticationService.getAuthentication().success(function (data) {
  10525. $scope.loading = false;
  10526. $scope.user = data;
  10527. });
  10528. CurrentRole.isManager({}, {}, function (data) {
  10529. $scope.isManager = data.isManager || $scope.user.sys;
  10530. });
  10531. $scope.role = role;
  10532. $scope.master = angular.copy($scope.role);
  10533. var isNew = role == null;
  10534. $scope.cancel = function () {
  10535. $modalInstance.close(false);
  10536. };
  10537. AccountResource.query({}, function (data) {
  10538. if (data && data.length > 0) {
  10539. if (role && role.resourceItems) {
  10540. var rs = [];// 已分配的资源的id
  10541. angular.forEach(role.resourceItems, function (item) {
  10542. rs.push(item.id);
  10543. });
  10544. angular.forEach(data, function (resource) {
  10545. var c = 0;
  10546. angular.forEach(resource.items, function (item) {
  10547. if (rs.indexOf(item.id) > -1) {
  10548. item.$checked = true;
  10549. c += 1;
  10550. }
  10551. });
  10552. resource.$checked = c == resource.items.length;
  10553. });
  10554. }
  10555. $scope.resourceItems = data[0].items;
  10556. data[0].$active = true;
  10557. }
  10558. $scope.resources = data;
  10559. $timeout(function () {
  10560. angular.forEach($scope.resources, function (resource) {
  10561. var c = 0;
  10562. angular.forEach(resource.items, function (item) {
  10563. item.$checked && (c += 1);
  10564. });
  10565. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  10566. });
  10567. }, 100);
  10568. });
  10569. $scope.onItemClick = function (resource) {
  10570. $scope.resourceItems = resource.items;
  10571. angular.forEach($scope.resources, function (r) {
  10572. r.$active = false;
  10573. });
  10574. resource.$active = true;
  10575. };
  10576. var getChecked = function () {
  10577. var items = [];
  10578. angular.forEach($scope.resources, function (resource) {
  10579. angular.forEach(resource.items, function (item) {
  10580. item.$checked && (items.push(item));
  10581. });
  10582. });
  10583. $scope.role.resourceItems = items;
  10584. };
  10585. $scope.onResourceChange = function (resource) {
  10586. angular.forEach(resource.items, function (item) {
  10587. item.$checked = resource.$checked;
  10588. });
  10589. getChecked();
  10590. };
  10591. $scope.onItemChange = function () {
  10592. angular.forEach($scope.resources, function (resource) {
  10593. if (resource.$active) {
  10594. var c = 0;
  10595. angular.forEach(resource.items, function (item) {
  10596. item.$checked && (c += 1);
  10597. });
  10598. resource.$checked = (c == resource.items.length);
  10599. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  10600. }
  10601. });
  10602. getChecked();
  10603. };
  10604. $scope.isChanged = function (formData) {
  10605. if (!$scope.master)
  10606. return true;
  10607. return !angular.equals(formData, $scope.master);
  10608. };
  10609. $scope.save = function () {
  10610. $scope.master = angular.copy($scope.role);
  10611. AccountRole.save($scope.master, function () {
  10612. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
  10613. $modalInstance.close(true);
  10614. }, function (response) {
  10615. toaster.pop('error', '错误', response.data);
  10616. });
  10617. };
  10618. $scope.del = function () {
  10619. new ngAlert({
  10620. title: '提示',
  10621. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  10622. }, function () {
  10623. AccountRole.remove({id: role.id}, {}, function () {
  10624. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  10625. $modalInstance.close(true);
  10626. }, function (response) {
  10627. toaster.pop('error', '错误', response.data);
  10628. });
  10629. })
  10630. };
  10631. $scope.updateDefault = function () {
  10632. new ngAlert({
  10633. title: '提示',
  10634. content: '确定把(' + $scope.role.desc + ')信息更新到标准库吗?'
  10635. }, function () {
  10636. AccountRole.updateDefault({desc: $scope.role.desc}, $scope.role.resourceItems, function () {
  10637. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 更新成功');
  10638. $modalInstance.close(true);
  10639. }, function (response) {
  10640. toaster.pop('error', '错误', response.data);
  10641. });
  10642. })
  10643. }
  10644. $scope.recover = function () {
  10645. new ngAlert({
  10646. title: '提示',
  10647. content: '确定将“' + $scope.role.desc + '”恢复默认权限吗?'
  10648. }, function () {
  10649. AccountRole.recover({roleId: role.id}, {}, function () {
  10650. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 恢复默认权限成功');
  10651. $modalInstance.close(true);
  10652. }, function (response) {
  10653. toaster.pop('error', '错误', response.data);
  10654. });
  10655. })
  10656. };
  10657. }]);
  10658. /**
  10659. * 委外订单
  10660. */
  10661. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole',
  10662. function ($scope, $filter, MakeOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  10663. BaseService.scrollBackToTop();
  10664. // 获取当前用户是否为普通用户
  10665. CurrentRole.isUser({}, {}, function (data) {
  10666. $scope.isUser = data.isUser;
  10667. });
  10668. $scope.active = 'todo';
  10669. $scope.dateZoneText = '不限';
  10670. $scope.condition = {dateZone: 1};
  10671. /* 时间筛选初始化*/
  10672. var fromDate = new Date();
  10673. var toDate = new Date();
  10674. fromDate.setMonth(fromDate.getMonth() - 1);
  10675. fromDate.setHours(0, 0, 0, 0);
  10676. toDate.setHours(23, 59, 59, 999);
  10677. $scope.condition.dateFrom = fromDate;
  10678. $scope.condition.dateTo = toDate;
  10679. $scope.changeDateZone = function (zone) {
  10680. $scope.condition.dateZone = zone;
  10681. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  10682. $scope.condition.$dateZoneOpen = false;
  10683. getDateCondition(zone, $scope.condition);
  10684. $scope.tableParams.page(1);
  10685. $scope.tableParams.reload();
  10686. };
  10687. $scope.setActive = function (state) {
  10688. if ($scope.active != state) {
  10689. $scope.active = state;
  10690. if ($scope.tableParams.page() == 1)
  10691. $scope.tableParams.reload();
  10692. else
  10693. $scope.tableParams.page(1);
  10694. }
  10695. };
  10696. var getService = function () {
  10697. return MakeOrder;
  10698. };
  10699. $scope.tableParams = new ngTableParams({
  10700. page: 1,
  10701. count: 20,
  10702. sorting: {
  10703. date: 'desc'
  10704. }
  10705. }, {
  10706. total: 0,
  10707. counts: [5, 10, 25, 50],
  10708. getData: function ($defer, params) {
  10709. $scope.loading = true;
  10710. var pageParams = params.url();
  10711. pageParams.searchFilter = {
  10712. keyword: $scope.keyword,
  10713. fromDate: getDateTime($scope.condition.dateFrom),
  10714. endDate: getDateTime($scope.condition.dateTo)
  10715. };
  10716. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  10717. $scope.loading = false;
  10718. if (page) {
  10719. params.total(page.totalElement);
  10720. $defer.resolve(page.content);
  10721. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  10722. }
  10723. }, function (response) {
  10724. $scope.loading = false;
  10725. toaster.pop('error', '数据加载失败', response.data);
  10726. });
  10727. }
  10728. });
  10729. //获得各分类未阅读数量
  10730. var getUnreadCount = function () {
  10731. MakeOrder.getUnreadCount(null, function (data) {
  10732. $scope.unread = data;
  10733. });
  10734. };
  10735. getUnreadCount();
  10736. //设置单据已读
  10737. $scope.setOrdersRead = function (id) {
  10738. // 如果单据本身已读,则不发送请求修改数据
  10739. if (!$scope.isUnread(id)){
  10740. return;
  10741. }
  10742. var sourceId = [];
  10743. sourceId.push(id);
  10744. MakeOrder.setRead({}, sourceId, function (message) {
  10745. // $scope.getUnreadIds();
  10746. getUnreadCount();
  10747. });
  10748. };
  10749. $scope.setOrdersReadByState = function () {
  10750. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  10751. return;
  10752. }
  10753. MakeOrder.setReadByState({}, function () {
  10754. getUnreadIds();
  10755. getUnreadCount();
  10756. });
  10757. };
  10758. var getUnreadIds = function () {
  10759. MakeOrder.getUnreadIds({}, "", function (message) {
  10760. $scope.unreadCode = message.content;
  10761. });
  10762. };
  10763. getUnreadIds();
  10764. $scope.isUnread = function (id) {
  10765. for (var i in $scope.unreadCode) {
  10766. if (id == $scope.unreadCode[i]) {
  10767. return true;
  10768. }
  10769. }
  10770. };
  10771. $scope.getOrderTotal = function (items) {
  10772. var sum = 0;
  10773. angular.forEach(items, function (item) {
  10774. sum += item.qty * item.price;
  10775. });
  10776. return sum;
  10777. };
  10778. $scope.openDatePicker = function ($event, item, openParam) {
  10779. $event.preventDefault();
  10780. $event.stopPropagation();
  10781. item[openParam] = !item[openParam];
  10782. };
  10783. $scope.openFilterDatePicker = function ($event, item, openParam) {
  10784. $event.preventDefault();
  10785. $event.stopPropagation();
  10786. item[openParam] = !item[openParam];
  10787. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  10788. $scope.tableParams.reload();
  10789. }
  10790. };
  10791. $scope.parseDate = function (dateStr) {
  10792. if (dateStr)
  10793. return Date.parse(dateStr, 'yyyy-MM-dd');
  10794. return new Date();
  10795. };
  10796. // 打开回复
  10797. $scope.openReply = function (order) {
  10798. if (!order.reply) {
  10799. order.reply = {
  10800. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  10801. delivery: order.delivery
  10802. }
  10803. }
  10804. order.$editing = true;
  10805. };
  10806. // 关闭回复
  10807. $scope.closeReply = function (order) {
  10808. order.$editing = false;
  10809. }
  10810. // 搜索框回车
  10811. $scope.onSearch = function () {
  10812. $scope.tableParams.page(1);
  10813. $scope.tableParams.reload();
  10814. };
  10815. // 选择查找日期
  10816. $scope.onDateCondition = function () {
  10817. $scope.tableParams.page(1);
  10818. $scope.tableParams.reload();
  10819. };
  10820. // 点击回复
  10821. $scope.onReplyClick = function (order, inverse) {
  10822. if (order.reply) {
  10823. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  10824. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  10825. return;
  10826. }
  10827. var reply = angular.copy(order.reply);
  10828. if (reply.delivery) {
  10829. if (typeof reply.delivery == 'object')
  10830. reply.delivery = reply.delivery.getTime();
  10831. } else {
  10832. reply.delivery = order.delivery;
  10833. }
  10834. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  10835. $scope.loading = true;
  10836. MakeOrder.reply({orderId: order.id}, reply, function () {
  10837. $scope.loading = false;
  10838. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  10839. $scope.tableParams.reload();
  10840. }, function (response) {
  10841. $scope.loading = false;
  10842. toaster.pop('error', '回复失败', response.data);
  10843. });
  10844. }
  10845. };
  10846. //委外加工单
  10847. $scope.print = function (order) {
  10848. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  10849. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  10850. };
  10851. // 获取回复记录
  10852. $scope.getReply = function (order) {
  10853. if (!order.replies) {
  10854. MakeOrder.getReply({orderId: order.id}, function (replies) {
  10855. order.replies = replies;
  10856. });
  10857. }
  10858. };
  10859. // 导出
  10860. $scope.exportXls = function () {
  10861. MakeOrder.exportXls({}, {}, function (data) {
  10862. if (data.success){
  10863. window.location.href = 'make/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  10864. }
  10865. }, function (response) {
  10866. toaster.pop('error', '数据加载失败', response.data);
  10867. });
  10868. }
  10869. }]);
  10870. /**
  10871. * 委外加工单详细
  10872. */
  10873. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService, CurrentRole) {
  10874. BaseService.scrollBackToTop();
  10875. // 获取当前用户是否为普通用户
  10876. CurrentRole.isUser({}, {}, function (data) {
  10877. $scope.isUser = data.isUser;
  10878. });
  10879. var loadData = function () {
  10880. MakeOrder.getItem({id: $stateParams.id}, function (data) {
  10881. $scope.order = data;
  10882. var sum = $scope.order.qty * $scope.order.price;
  10883. $scope.order.total = sum;
  10884. $scope.loading = false;
  10885. }, function (response) {
  10886. toaster.pop('error', '', response.data);
  10887. });
  10888. };
  10889. loadData();
  10890. // 获取回复记录
  10891. $scope.getReply = function (item) {
  10892. if (!item.replies) {
  10893. MakeOrder.getReply({orderId: item.id}, function (replies) {
  10894. item.replies = replies;
  10895. });
  10896. }
  10897. };
  10898. $scope.openDatePicker = function ($event, item, openParam) {
  10899. $event.preventDefault();
  10900. $event.stopPropagation();
  10901. item[openParam] = !item[openParam];
  10902. };
  10903. // 点击回复
  10904. $scope.onReplyClick = function (order, inverse) {
  10905. if (order.reply) {
  10906. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  10907. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  10908. return;
  10909. }
  10910. var reply = angular.copy(order.reply);
  10911. if (reply.delivery) {
  10912. if (typeof reply.delivery == 'object')
  10913. reply.delivery = reply.delivery.getTime();
  10914. } else {
  10915. reply.delivery = order.delivery;
  10916. }
  10917. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  10918. $scope.loading = true;
  10919. MakeOrder.reply({orderId: order.id}, reply, function () {
  10920. $scope.loading = false;
  10921. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  10922. loadData();
  10923. }, function (response) {
  10924. $scope.loading = false;
  10925. toaster.pop('error', '回复失败', response.data);
  10926. });
  10927. }
  10928. };
  10929. // 打开回复
  10930. $scope.openReply = function (order) {
  10931. if (!order.reply) {
  10932. order.reply = {
  10933. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  10934. delivery: order.delivery
  10935. }
  10936. }
  10937. order.$editing = true;
  10938. };
  10939. // 关闭回复
  10940. $scope.closeReply = function (order) {
  10941. order.$editing = false;
  10942. }
  10943. // 委外订单
  10944. $scope.print = function (order) {
  10945. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  10946. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  10947. };
  10948. }]);
  10949. /**
  10950. * 客户委外验收
  10951. */
  10952. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  10953. BaseService.scrollBackToTop();
  10954. // 获取当前用户是否为普通用户
  10955. CurrentRole.isUser({}, {}, function (data) {
  10956. $scope.isUser = data.isUser;
  10957. });
  10958. $scope.active = 'all';
  10959. $scope.agreedText = '全部';
  10960. $scope.dateZoneText = '一个月内';
  10961. $scope.condition = {dateZone: 1};
  10962. /* 时间筛选初始化*/
  10963. var fromDate = new Date();
  10964. var toDate = new Date();
  10965. fromDate.setMonth(fromDate.getMonth() - 1);
  10966. fromDate.setHours(0, 0, 0, 0);
  10967. toDate.setHours(23, 59, 59, 999);
  10968. $scope.condition.dateFrom = fromDate;
  10969. $scope.condition.dateTo = toDate;
  10970. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  10971. $scope.changeAgreed = function (agreed) {
  10972. $scope.condition.agreed = agreed;
  10973. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  10974. $scope.condition.$agreedOpen = false;
  10975. };
  10976. $scope.changeDateZone = function (zone) {
  10977. $scope.condition.dateZone = zone;
  10978. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  10979. $scope.condition.$dateZoneOpen = false;
  10980. getDateCondition(zone, $scope.condition);
  10981. $scope.tableParams.page(1);
  10982. $scope.tableParams.reload();
  10983. };
  10984. $scope.setActive = function (state) {
  10985. if ($scope.active != state) {
  10986. $scope.active = state;
  10987. if ($scope.tableParams.page() == 1)
  10988. $scope.tableParams.reload();
  10989. else
  10990. $scope.tableParams.page(1);
  10991. }
  10992. };
  10993. var getService = function () {
  10994. return MakeAccept;
  10995. };
  10996. $scope.tableParams = new ngTableParams({
  10997. page: 1,
  10998. count: 20,
  10999. sorting: {
  11000. date: 'desc'
  11001. }
  11002. }, {
  11003. total: 0,
  11004. counts: [5, 10, 25, 50],
  11005. getData: function ($defer, params) {
  11006. $scope.loading = true;
  11007. var pageParams = params.url();
  11008. pageParams.searchFilter = {};
  11009. pageParams.searchFilter.keyword = $scope.keyword;
  11010. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11011. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11012. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11013. $scope.loading = false;
  11014. if (page) {
  11015. params.total(page.totalElement);
  11016. $defer.resolve(page.content);
  11017. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11018. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11019. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11020. }
  11021. }, function (response) {
  11022. $scope.loading = false;
  11023. toaster.pop('error', '数据加载失败', response.data);
  11024. });
  11025. }
  11026. });
  11027. $scope.openDatePicker = function ($event, item, openParam) {
  11028. $event.preventDefault();
  11029. $event.stopPropagation();
  11030. item[openParam] = !item[openParam];
  11031. };
  11032. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11033. $event.preventDefault();
  11034. $event.stopPropagation();
  11035. item[openParam] = !item[openParam];
  11036. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11037. $scope.tableParams.reload();
  11038. }
  11039. };
  11040. // 搜索框回车
  11041. $scope.onSearch = function () {
  11042. $scope.tableParams.page(1);
  11043. $scope.tableParams.reload();
  11044. };
  11045. // 选择查找日期
  11046. $scope.onDateCondition = function () {
  11047. $scope.tableParams.page(1);
  11048. $scope.tableParams.reload();
  11049. };
  11050. // 导出
  11051. $scope.exportXls = function () {
  11052. MakeAccept.exportXls({}, {}, function (data) {
  11053. if (data.success){
  11054. window.location.href = 'make/accept/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11055. }
  11056. }, function (response) {
  11057. toaster.pop('error', '数据加载失败', response.data);
  11058. });
  11059. }
  11060. }]);
  11061. /**
  11062. * 客户委外验退
  11063. */
  11064. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11065. BaseService.scrollBackToTop();
  11066. // 获取当前用户是否为普通用户
  11067. CurrentRole.isUser({}, {}, function (data) {
  11068. $scope.isUser = data.isUser;
  11069. });
  11070. $scope.active = 'all';
  11071. $scope.agreedText = '全部';
  11072. $scope.dateZoneText = '一个月内';
  11073. $scope.condition = {dateZone: 1};
  11074. /* 时间筛选初始化*/
  11075. var fromDate = new Date();
  11076. var toDate = new Date();
  11077. fromDate.setMonth(fromDate.getMonth() - 1);
  11078. fromDate.setHours(0, 0, 0, 0);
  11079. toDate.setHours(23, 59, 59, 999);
  11080. $scope.condition.dateFrom = fromDate;
  11081. $scope.condition.dateTo = toDate;
  11082. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11083. $scope.changeAgreed = function (agreed) {
  11084. $scope.condition.agreed = agreed;
  11085. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11086. $scope.condition.$agreedOpen = false;
  11087. };
  11088. $scope.changeDateZone = function (zone) {
  11089. $scope.condition.dateZone = zone;
  11090. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11091. $scope.condition.$dateZoneOpen = false;
  11092. getDateCondition(zone, $scope.condition);
  11093. $scope.tableParams.page(1);
  11094. $scope.tableParams.reload();
  11095. };
  11096. $scope.setActive = function (state) {
  11097. if ($scope.active != state) {
  11098. $scope.active = state;
  11099. if ($scope.tableParams.page() == 1)
  11100. $scope.tableParams.reload();
  11101. else
  11102. $scope.tableParams.page(1);
  11103. }
  11104. };
  11105. var getService = function () {
  11106. return MakeReturn;
  11107. };
  11108. $scope.tableParams = new ngTableParams({
  11109. page: 1,
  11110. count: 20,
  11111. sorting: {
  11112. date: 'desc'
  11113. }
  11114. }, {
  11115. total: 0,
  11116. counts: [5, 10, 25, 50],
  11117. getData: function ($defer, params) {
  11118. $scope.loading = true;
  11119. var pageParams = params.url();
  11120. pageParams.searchFilter = {};
  11121. pageParams.searchFilter.keyword = $scope.keyword;
  11122. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11123. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11124. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11125. $scope.loading = false;
  11126. if (page) {
  11127. params.total(page.totalElement);
  11128. $defer.resolve(page.content);
  11129. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11130. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11131. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11132. }
  11133. }, function (response) {
  11134. $scope.loading = false;
  11135. toaster.pop('error', '数据加载失败', response.data);
  11136. });
  11137. }
  11138. });
  11139. $scope.openDatePicker = function ($event, item, openParam) {
  11140. $event.preventDefault();
  11141. $event.stopPropagation();
  11142. item[openParam] = !item[openParam];
  11143. };
  11144. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11145. $event.preventDefault();
  11146. $event.stopPropagation();
  11147. item[openParam] = !item[openParam];
  11148. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11149. $scope.tableParams.reload();
  11150. }
  11151. };
  11152. // 搜索框回车
  11153. $scope.onSearch = function () {
  11154. $scope.tableParams.page(1);
  11155. $scope.tableParams.reload();
  11156. };
  11157. // 选择查找日期
  11158. $scope.onDateCondition = function () {
  11159. $scope.tableParams.page(1);
  11160. $scope.tableParams.reload();
  11161. };
  11162. // 导出
  11163. $scope.exportXls = function () {
  11164. MakeReturn.exportXls({}, {}, function (data) {
  11165. if (data.success){
  11166. window.location.href = 'make/return/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11167. }
  11168. }, function (response) {
  11169. toaster.pop('error', '数据加载失败', response.data);
  11170. });
  11171. }
  11172. }]);
  11173. /**
  11174. * 委外加工变更
  11175. */
  11176. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeChange, ngTableParams, toaster, BaseService, CurrentRole) {
  11177. BaseService.scrollBackToTop();
  11178. // 获取当前用户是否为普通用户
  11179. CurrentRole.isUser({}, {}, function (data) {
  11180. $scope.isUser = data.isUser;
  11181. });
  11182. $scope.active = 'all';
  11183. $scope.agreedText = '全部';
  11184. $scope.dateZoneText = '一个月内';
  11185. $scope.condition = {dateZone: 1};
  11186. /* 时间筛选初始化*/
  11187. var fromDate = new Date();
  11188. var toDate = new Date();
  11189. fromDate.setMonth(fromDate.getMonth() - 1);
  11190. fromDate.setHours(0, 0, 0, 0);
  11191. toDate.setHours(23, 59, 59, 999);
  11192. $scope.condition.dateFrom = fromDate;
  11193. $scope.condition.dateTo = toDate;
  11194. $scope.changeAgreed = function (agreed) {
  11195. $scope.condition.agreed = agreed;
  11196. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11197. $scope.condition.$agreedOpen = false;
  11198. };
  11199. $scope.changeDateZone = function (zone) {
  11200. $scope.condition.dateZone = zone;
  11201. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11202. $scope.condition.$dateZoneOpen = false;
  11203. getDateCondition(zone, $scope.condition);
  11204. $scope.tableParams.page(1);
  11205. $scope.tableParams.reload();
  11206. };
  11207. $scope.setActive = function (state) {
  11208. if ($scope.active != state) {
  11209. $scope.active = state;
  11210. if ($scope.tableParams.page() == 1)
  11211. $scope.tableParams.reload();
  11212. else
  11213. $scope.tableParams.page(1);
  11214. }
  11215. };
  11216. var getService = function () {
  11217. return MakeChange;
  11218. };
  11219. $scope.tableParams = new ngTableParams({
  11220. page: 1,
  11221. count: 20,
  11222. sorting: {
  11223. orderChangeDate: 'desc'
  11224. }
  11225. }, {
  11226. total: 0,
  11227. counts: [5, 10, 25, 50],
  11228. getData: function ($defer, params) {
  11229. $scope.loading = true;
  11230. var pageParams = params.url();
  11231. pageParams.searchFilter = {
  11232. keyword: $scope.keyword,
  11233. fromDate: getDateTime($scope.condition.dateFrom),
  11234. endDate: getDateTime($scope.condition.dateTo)
  11235. };
  11236. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11237. $scope.loading = false;
  11238. if (page) {
  11239. params.total(page.totalElement);
  11240. $defer.resolve(page.content);
  11241. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11242. }
  11243. }, function (response) {
  11244. $scope.loading = false;
  11245. toaster.pop('error', '数据加载失败', response.data);
  11246. });
  11247. }
  11248. });
  11249. $scope.openDatePicker = function ($event, item, openParam) {
  11250. $event.preventDefault();
  11251. $event.stopPropagation();
  11252. item[openParam] = !item[openParam];
  11253. };
  11254. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11255. $event.preventDefault();
  11256. $event.stopPropagation();
  11257. item[openParam] = !item[openParam];
  11258. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11259. $scope.tableParams.reload();
  11260. }
  11261. };
  11262. // 打开回复
  11263. $scope.openReply = function (change) {
  11264. change.$editing = true;
  11265. };
  11266. // 关闭回复
  11267. $scope.closeReply = function (change) {
  11268. change.$editing = false;
  11269. }
  11270. // 确定回复
  11271. $scope.onReplyClick = function (change) {
  11272. if (change.$agreed) {
  11273. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11274. $scope.loading = true;
  11275. MakeChange.reply({itemId: change.id}, reply, function () {
  11276. $scope.loading = false;
  11277. toaster.pop('info', '提示', '回复成功');
  11278. $scope.tableParams.reload();
  11279. }, function (response) {
  11280. $scope.loading = false;
  11281. toaster.pop('error', '回复失败', response.data);
  11282. });
  11283. }
  11284. };
  11285. // 搜索框回车
  11286. $scope.onSearch = function () {
  11287. $scope.tableParams.page(1);
  11288. $scope.tableParams.reload();
  11289. };
  11290. // 选择查找日期
  11291. $scope.onDateCondition = function () {
  11292. $scope.tableParams.page(1);
  11293. $scope.tableParams.reload();
  11294. };
  11295. // 导出
  11296. $scope.exportXls = function () {
  11297. MakeChange.exportXls({}, {}, function (data) {
  11298. if (data.success){
  11299. window.location.href = 'make/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11300. }
  11301. }, function (response) {
  11302. toaster.pop('error', '数据加载失败', response.data);
  11303. });
  11304. }
  11305. }]);
  11306. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeChange, toaster, BaseService, CurrentRole) {
  11307. BaseService.scrollBackToTop();
  11308. CurrentRole.isUser({}, {}, function (data) {
  11309. $scope.isUser = data.isUser;
  11310. });
  11311. var loadData = function () {
  11312. MakeChange.getItem({id: $stateParams.id}, function (data) {
  11313. $scope.change = data;
  11314. }, function (response) {
  11315. toaster.pop('error', '数据加载失败', response.data);
  11316. });
  11317. };
  11318. loadData();
  11319. $scope.openDatePicker = function ($event, item, openParam) {
  11320. $event.preventDefault();
  11321. $event.stopPropagation();
  11322. item[openParam] = !item[openParam];
  11323. };
  11324. $scope.onReplyClick = function (change) {
  11325. if (change.$agreed) {
  11326. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11327. MakeChange.reply({itemId: change.id}, reply, function () {
  11328. toaster.pop('info', '提示', '回复成功');
  11329. loadData();
  11330. }, function (response) {
  11331. toaster.pop('error', '回复失败', response.data);
  11332. });
  11333. }
  11334. };
  11335. }]);
  11336. /**
  11337. * 委外加工
  11338. */
  11339. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeOutOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  11340. BaseService.scrollBackToTop();
  11341. // 获取当前用户是否为普通用户
  11342. CurrentRole.isUser({}, {}, function (data) {
  11343. $scope.isUser = data.isUser;
  11344. });
  11345. $scope.active = 'all';
  11346. $scope.agreedText = '全部';
  11347. $scope.dateZoneText = '一个月内';
  11348. $scope.condition = {dateZone: 1};
  11349. /* 时间筛选初始化*/
  11350. var fromDate = new Date();
  11351. var toDate = new Date();
  11352. fromDate.setMonth(fromDate.getMonth() - 1);
  11353. fromDate.setHours(0, 0, 0, 0);
  11354. toDate.setHours(23, 59, 59, 999);
  11355. $scope.condition.dateFrom = fromDate;
  11356. $scope.condition.dateTo = toDate;
  11357. $scope.changeAgreed = function (agreed) {
  11358. $scope.condition.agreed = agreed;
  11359. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11360. $scope.condition.$agreedOpen = false;
  11361. };
  11362. $scope.changeDateZone = function (zone) {
  11363. $scope.condition.dateZone = zone;
  11364. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11365. $scope.condition.$dateZoneOpen = false;
  11366. getDateCondition(zone, $scope.condition);
  11367. $scope.tableParams.page(1);
  11368. $scope.tableParams.reload();
  11369. };
  11370. $scope.setActive = function (state) {
  11371. if ($scope.active != state) {
  11372. $scope.active = state;
  11373. if ($scope.tableParams.page() == 1)
  11374. $scope.tableParams.reload();
  11375. else
  11376. $scope.tableParams.page(1);
  11377. }
  11378. };
  11379. var getService = function () {
  11380. return MakeOutOrder;
  11381. };
  11382. $scope.tableParams = new ngTableParams({
  11383. page: 1,
  11384. count: 20,
  11385. sorting: {
  11386. date: 'desc'
  11387. }
  11388. }, {
  11389. total: 0,
  11390. counts: [5, 10, 25, 50],
  11391. getData: function ($defer, params) {
  11392. $scope.loading = true;
  11393. var pageParams = params.url();
  11394. pageParams.searchFilter = {};
  11395. pageParams.searchFilter.keyword = $scope.keyword;
  11396. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11397. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11398. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11399. $scope.loading = false;
  11400. if (page) {
  11401. params.total(page.totalElement);
  11402. $defer.resolve(page.content);
  11403. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11404. }
  11405. }, function (response) {
  11406. $scope.loading = false;
  11407. toaster.pop('error', '数据加载失败', response.data);
  11408. });
  11409. }
  11410. });
  11411. $scope.openDatePicker = function ($event, item, openParam) {
  11412. $event.preventDefault();
  11413. $event.stopPropagation();
  11414. item[openParam] = !item[openParam];
  11415. };
  11416. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11417. $event.preventDefault();
  11418. $event.stopPropagation();
  11419. item[openParam] = !item[openParam];
  11420. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11421. $scope.tableParams.reload();
  11422. }
  11423. };
  11424. // 获取回复记录
  11425. $scope.getReply = function (item) {
  11426. if (!item.replies) {
  11427. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  11428. item.replies = replies;
  11429. });
  11430. }
  11431. };
  11432. // 打开回复
  11433. $scope.openReply = function (change) {
  11434. change.$editing = true;
  11435. };
  11436. // 关闭回复
  11437. $scope.closeReply = function (change) {
  11438. change.$editing = false;
  11439. }
  11440. // 确定回复
  11441. $scope.onReplyClick = function (change) {
  11442. if (change.$agreed) {
  11443. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11444. $scope.loading = true;
  11445. MakeOutOrder.reply({itemId: change.id}, reply, function () {
  11446. $scope.loading = false;
  11447. toaster.pop('info', '提示', '回复成功');
  11448. $scope.tableParams.reload();
  11449. }, function (response) {
  11450. $scope.loading = false;
  11451. toaster.pop('error', '回复失败', response.data);
  11452. });
  11453. }
  11454. };
  11455. // 搜索框回车
  11456. $scope.onSearch = function () {
  11457. $scope.tableParams.page(1);
  11458. $scope.tableParams.reload();
  11459. };
  11460. // 选择查找日期
  11461. $scope.onDateCondition = function () {
  11462. $scope.tableParams.page(1);
  11463. $scope.tableParams.reload();
  11464. };
  11465. // 导出
  11466. $scope.exportXls = function () {
  11467. MakeOutOrder.exportXls({}, {}, function (data) {
  11468. if (data.success){
  11469. window.location.href = 'make/outorders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11470. }
  11471. }, function (response) {
  11472. toaster.pop('error', '数据加载失败', response.data);
  11473. });
  11474. }
  11475. }]);
  11476. /**
  11477. * 委外加工详细
  11478. */
  11479. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService, CurrentRole) {
  11480. BaseService.scrollBackToTop();
  11481. // 获取当前用户是否为普通用户
  11482. CurrentRole.isUser({}, {}, function (data) {
  11483. $scope.isUser = data.isUser;
  11484. });
  11485. var loadData = function () {
  11486. MakeOutOrder.getItem({id: $stateParams.id},{}, function (data) {
  11487. $scope.order = data;
  11488. var sum = $scope.order.qty * $scope.order.price;
  11489. $scope.order.total = sum;
  11490. $scope.loading = false;
  11491. }, function (response) {
  11492. toaster.pop('error', '提示', response.data);
  11493. });
  11494. };
  11495. loadData();
  11496. // 获取回复记录
  11497. $scope.getReply = function (item) {
  11498. if (!item.replies) {
  11499. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  11500. item.replies = replies;
  11501. });
  11502. }
  11503. };
  11504. $scope.openDatePicker = function ($event, item, openParam) {
  11505. $event.preventDefault();
  11506. $event.stopPropagation();
  11507. item[openParam] = !item[openParam];
  11508. };
  11509. // 点击回复
  11510. $scope.onReplyClick = function (order, inverse) {
  11511. if (order.reply) {
  11512. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11513. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11514. return;
  11515. }
  11516. var reply = angular.copy(order.reply);
  11517. if (reply.delivery) {
  11518. if (typeof reply.delivery == 'object')
  11519. reply.delivery = reply.delivery.getTime();
  11520. } else {
  11521. reply.delivery = order.delivery;
  11522. }
  11523. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11524. $scope.loading = true;
  11525. MakeOutOrder.reply({orderId: order.id}, reply, function () {
  11526. $scope.loading = false;
  11527. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11528. loadData();
  11529. }, function (response) {
  11530. $scope.loading = false;
  11531. toaster.pop('error', '回复失败', response.data);
  11532. });
  11533. }
  11534. };
  11535. // 打开回复
  11536. $scope.openReply = function (order) {
  11537. if (!order.reply) {
  11538. order.reply = {
  11539. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11540. delivery: order.delivery
  11541. }
  11542. }
  11543. order.$editing = true;
  11544. };
  11545. // 关闭回复
  11546. $scope.closeReply = function (order) {
  11547. order.$editing = false;
  11548. }
  11549. // 自己委外加工订单
  11550. $scope.print = function (order) {
  11551. MakeOutOrder.printCount({id: order.id}, {});//增加打印此次
  11552. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  11553. };
  11554. }]);
  11555. /**
  11556. * 计算时间差
  11557. */
  11558. app.filter('timespan', function () {
  11559. return function (time) {
  11560. if (time == null)
  11561. return '9999年';
  11562. var now = new Date().getTime(), span = time - now,
  11563. d = Math.ceil(span / 86400000), h = Math.ceil(span / 3600000),
  11564. m = Math.ceil(span / 60000);
  11565. if (span < 0)
  11566. return '1天';
  11567. if (d > 0)
  11568. return d + 1 + '天';
  11569. if (h > 0)
  11570. return h + '小时';
  11571. if (m > 0)
  11572. return m + '分钟';
  11573. return '0天';
  11574. };
  11575. });
  11576. /**
  11577. * 公共询价计算时间差
  11578. */
  11579. app.filter('datespan', function () {
  11580. return function (time) {
  11581. if (time == null) {
  11582. return '剩余9999年';
  11583. }
  11584. var now = new Date().getTime(), span = time - now,
  11585. d = Math.floor(span / 86400000), h = Math.floor(span / 3600000),
  11586. m = Math.floor(span / 60000);
  11587. if (d > 0) {
  11588. var day = d + 1;
  11589. return '剩余' + day + '天';
  11590. }
  11591. if (h > 0) {
  11592. return '<span class="text-inverse">剩余' + h + '小时</span>';
  11593. }
  11594. if (m > 0) {
  11595. return '<span class="text-inverse">剩余' + m + '分钟</span>';
  11596. }
  11597. return '已结束';
  11598. };
  11599. });
  11600. app.filter('firstchar', function () {
  11601. return function (str) {
  11602. if (str == null)
  11603. return null;
  11604. return str.substring(0, 1);
  11605. };
  11606. });
  11607. app.filter('summary', function () {
  11608. return function (data, field) {
  11609. var sum = 0;
  11610. if (data) {
  11611. angular.forEach(data, function (d) {
  11612. sum += d[field];
  11613. });
  11614. }
  11615. return sum;
  11616. };
  11617. });
  11618. /**
  11619. * 搜索框,回车触发
  11620. */
  11621. app.directive('ngSearch', ['$parse', function ($parse) {
  11622. return {
  11623. require: '?ngModel',
  11624. restrict: 'A',
  11625. link: function (scope, element, attrs, ngModel) {
  11626. var searchFn = $parse(attrs.ngSearch);
  11627. element.bind('keypress', function (event) {
  11628. if (event.keyCode == '13') {
  11629. event.preventDefault();
  11630. event.stopPropagation();
  11631. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  11632. }
  11633. });
  11634. }
  11635. };
  11636. }]);
  11637. /**
  11638. * 状态码 -> 描述
  11639. */
  11640. app.filter('status', function () {
  11641. return function (data) {
  11642. var statusConfig = {
  11643. '101': '已提交',
  11644. '102': '已审核',
  11645. '103': '未通过',
  11646. '200': '未回复',
  11647. '201': '已回复',
  11648. '313': '已激活',
  11649. '316': '已过账',
  11650. '311': '申请中',
  11651. '312': '未激活'
  11652. };
  11653. return statusConfig[data];
  11654. }
  11655. });
  11656. //弹出问题反馈模态框
  11657. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function ($scope, $modal, AuthenticationService) {
  11658. //获取当前用户
  11659. AuthenticationService.getAuthentication().success(function (data) {
  11660. $scope.user = data;
  11661. });
  11662. $scope.showModal = function () {
  11663. var modalInstance = $modal.open({
  11664. animation: true,
  11665. templateUrl: 'static/tpl/serve/feedback.html',
  11666. controller: 'FeedbackCtrl',
  11667. resolve: {
  11668. user: function () {
  11669. return $scope.user;
  11670. } //传递当前用户到模态框Controller
  11671. }
  11672. });
  11673. modalInstance.result.then(function () {
  11674. }, function () {
  11675. });
  11676. }
  11677. }]);
  11678. /*
  11679. * 提交我的反馈
  11680. */
  11681. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function ($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user) {
  11682. $scope.isPublic = 1; //默认公开
  11683. $scope.classId = 1; //默认类别
  11684. $scope.user = user;
  11685. $scope.ok = function () {
  11686. if (!$scope.user) { //用户未登录
  11687. $scope.uu = null;
  11688. } else { //用户已登录
  11689. $scope.uu = $scope.user.userUU;
  11690. }
  11691. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  11692. FeedBackService.feedBackQuestion({
  11693. classId: $scope.classId,
  11694. isPublic: $scope.isPublic,
  11695. title: $scope.title,
  11696. userUU: $scope.uu
  11697. }, {},
  11698. function (data) {
  11699. toaster.pop('success', '成功', '您的问题反馈成功!');
  11700. $scope.cancel();
  11701. }, function (response) {
  11702. toaster.pop('error', '错误', response.data);
  11703. });
  11704. }
  11705. $scope.cancel = function () {
  11706. $modalInstance.dismiss();
  11707. };
  11708. }]);
  11709. //“我的问题反馈”跳转控制
  11710. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function ($scope, AuthenticationService, toaster, $rootScope) {
  11711. $scope.myFeedback = function () {
  11712. AuthenticationService.getAuthentication().success(function (data) {
  11713. $scope.user = data;
  11714. if (!$scope.user) {
  11715. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  11716. return false;
  11717. } else {
  11718. window.location.href = "./serve#/question/myFeedback";
  11719. }
  11720. });
  11721. };
  11722. $scope.getSaleOrderCount = function (unread) {
  11723. if (unread != undefined) {
  11724. return unread.order;
  11725. }
  11726. };
  11727. $scope.getSaleInquiryCount = function (unread) {
  11728. if (unread != undefined) {
  11729. return unread.inquiry;
  11730. }
  11731. };
  11732. $scope.setActive = function (active) {
  11733. $rootScope.active = active;
  11734. }
  11735. }]);
  11736. //客户服务
  11737. app.controller('CustServeCtrl', ['$scope', 'Vendor', function ($scope, Vendor) {
  11738. Vendor.getServe(function (datas) {
  11739. $scope.vendors = datas;
  11740. // 自动跳转
  11741. if (datas && datas.length == 1)
  11742. $scope.redirect(datas[0]);
  11743. });
  11744. $scope.redirect = function (vendor) {
  11745. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  11746. };
  11747. }]);
  11748. /**
  11749. * 物料资料
  11750. */
  11751. 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) {
  11752. BaseService.scrollBackToTop();
  11753. var loadAccount = function () {
  11754. AccountEnterprise.get({}, function (data) {
  11755. $scope.enterprise = data;
  11756. $scope.saleStatus = $scope.enterprise.prodsale;
  11757. });
  11758. }
  11759. loadAccount();
  11760. $scope.active = 'all';
  11761. $scope.agreedText = '全部';
  11762. $scope.dateZoneText = '一个月内';
  11763. $scope.condition = {dateZone: 1};
  11764. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11765. $scope.changeAgreed = function (agreed) {
  11766. $scope.condition.agreed = agreed;
  11767. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11768. $scope.condition.$agreedOpen = false;
  11769. };
  11770. $scope.changeDateZone = function (zone) {
  11771. $scope.condition.dateZone = zone;
  11772. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11773. $scope.condition.$dateZoneOpen = false;
  11774. getDateCondition(zone, $scope.condition);
  11775. $scope.tableParams.reload();
  11776. };
  11777. $scope.setActive = function (state) {
  11778. if ($scope.active != state) {
  11779. $scope.active = state;
  11780. if ($scope.tableParams.page() == 1)
  11781. $scope.tableParams.reload();
  11782. else
  11783. $scope.tableParams.page(1);
  11784. }
  11785. };
  11786. $scope.searchMethod = false;
  11787. var getService = function () {
  11788. return $scope.searchMethod ? GetProductInfo : GetProductInfoNewest;
  11789. };
  11790. $scope.tableParams = new ngTableParams({
  11791. page: 1,
  11792. count: 20,
  11793. sorting: {
  11794. id: 'desc',
  11795. }
  11796. }, {
  11797. total: 0,
  11798. counts: [5, 10, 25, 50],
  11799. getData: function ($defer, params) {
  11800. $scope.loading = true;
  11801. var pageParams = params.url();
  11802. pageParams.keyword = $scope.keyword;
  11803. pageParams.searchFilter = $scope.searchFilter;
  11804. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11805. $scope.loading = false;
  11806. if (page) {
  11807. params.total(page.totalElement);
  11808. $defer.resolve(page.content);
  11809. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  11810. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  11811. }
  11812. }, function (response) {
  11813. $scope.loading = false;
  11814. toaster.pop('error', '数据加载失败', response.data);
  11815. });
  11816. }
  11817. });
  11818. // 搜索框回车
  11819. $scope.onSearch = function (keyword) {
  11820. // 每次搜索重置获取数据方法
  11821. $scope.searchMethod = false;
  11822. if(keyword != null && keyword != '') {
  11823. $scope.searchMethod = true;
  11824. }
  11825. $scope.tableParams.page(1);
  11826. $scope.tableParams.reload();
  11827. };
  11828. //删除
  11829. $scope.deleteById = function (id) {
  11830. $scope.loading = true;
  11831. GetProductInfo.deleteById({}, id, function (data) {
  11832. if (data.error) {
  11833. toaster.pop("error", "提示", data.error);
  11834. } else {
  11835. toaster.pop("success", "提示", "删除成功");
  11836. $timeout(function () {
  11837. $scope.tableParams.reload();
  11838. }, 500);
  11839. }
  11840. $scope.loading = false;
  11841. }, function (response) {
  11842. $scope.loading = false;
  11843. toaster.pop("error", "删除失败", response.data);
  11844. });
  11845. };
  11846. $rootScope.isProductEdit = false;
  11847. // 编辑
  11848. $scope.isProductEdit = function () {
  11849. $rootScope.isProductEdit = true;
  11850. };
  11851. // 一键开启关闭
  11852. $scope.toggle = function (status) {
  11853. if ($scope.saleStatus == 0) {
  11854. $scope.saleStatus = 1;
  11855. } else {
  11856. $scope.saleStatus = 0;
  11857. }
  11858. $scope.loading = true;
  11859. GetProductInfo.toggle({status: status}, {}, function (data) {
  11860. $scope.loading = false;
  11861. toaster.pop('success', '提示', '操作成功');
  11862. loadAccount();
  11863. $scope.tableParams.reload();
  11864. }, function (response) {
  11865. $scope.loading = false;
  11866. toaster.pop('error', '提示', response.data);
  11867. })
  11868. }
  11869. var products = [];
  11870. $scope.checks = {
  11871. checked: false
  11872. };
  11873. // 全选框
  11874. $scope.checkAll = function () {
  11875. products = [];// 每次选择时先清空,防止重复
  11876. angular.forEach($scope.tableParams.data, function (product) {
  11877. if (product.cmpUuId == null) {
  11878. product.checked = $scope.checks.checked;
  11879. }
  11880. });
  11881. };
  11882. // 单选
  11883. $scope.checkOne = function (product) {
  11884. products = [];// 每次选择时先清空,防止重复
  11885. var result = true;
  11886. angular.forEach($scope.tableParams.data, function (item) {
  11887. if (item.$selected != true) {
  11888. result = false;
  11889. return;
  11890. }
  11891. });
  11892. $scope.checks.checked = result;
  11893. var checked = true;
  11894. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  11895. if (!message.checked) {
  11896. checked = false;
  11897. }
  11898. });
  11899. $scope.checks.checked = checked;
  11900. };
  11901. $scope.updateByBatch = function (updatetype) {
  11902. var modalInstance = $modal.open({
  11903. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  11904. controller: 'UpdateByBatchCtrl',
  11905. size: 'md',
  11906. resolve: {
  11907. updatetype: function () {
  11908. return updatetype;
  11909. },
  11910. active: function () {
  11911. return $scope.active;
  11912. },
  11913. type: function () {
  11914. return 'sale';
  11915. }
  11916. }
  11917. });
  11918. modalInstance.result.then(function (data) {
  11919. toaster.pop('success', '提示', data.success);
  11920. $scope.tableParams.reload();
  11921. }, function () {
  11922. });
  11923. }
  11924. // 一键匹配
  11925. $scope.matchall = function () {
  11926. $scope.loading = true;
  11927. $scope.type = "sale";
  11928. GetProductInfo.matchbytype({type: $scope.type}, {}, function (data) {
  11929. if (data.error) {
  11930. $scope.loading = false;
  11931. toaster.pop('error', '提示', data.error);
  11932. } else {
  11933. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  11934. window.location.href = "#/sale/productmatches";
  11935. }
  11936. }, function (response) {
  11937. $scope.loading = false;
  11938. toaster.pop('error', '提示', response.data);
  11939. });
  11940. }
  11941. $scope.exportXls = function () {
  11942. GetProductInfo.exportXls({},{}, function (data) {
  11943. if (data.success) {
  11944. window.location.href = 'product/baseInfo/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  11945. }
  11946. }, function (response) {
  11947. toaster.pop('error', '数据加载失败', response.data);
  11948. })
  11949. }
  11950. }]);
  11951. /**
  11952. * 批量修改
  11953. */
  11954. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function ($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  11955. $scope.updatetype = updatetype;
  11956. $scope.changed = false;
  11957. $scope.parameter = {
  11958. updatetype: updatetype,
  11959. standard: active,
  11960. type: type,
  11961. oldvalue: null,
  11962. newvalue: null
  11963. };
  11964. $scope.cancel = function () {
  11965. $modalInstance.dismiss();
  11966. }
  11967. if (updatetype === '品牌')
  11968. var loadData = function () {
  11969. Products.getBrands({parameter: $scope.parameter}, {}, function (data) {
  11970. $scope.products = data;
  11971. }, function (response) {
  11972. toaster.pop('error', '提示', response.data);
  11973. })
  11974. }
  11975. if (updatetype === '名称(类目)')
  11976. var loadData = function () {
  11977. Products.getTitles({parameter: $scope.parameter}, {}, function (data) {
  11978. $scope.products = data;
  11979. }, function (response) {
  11980. toaster.pop('error', '提示', response.data);
  11981. })
  11982. }
  11983. loadData();
  11984. $scope.okay = function (newvalue) {
  11985. if (newvalue == '' || newvalue == null) {
  11986. toaster.pop('error', '提示', '修改的值不能为空');
  11987. } else {
  11988. $scope.loading = true;
  11989. Products.alterByBatch({parameter: $scope.parameter}, {}, function (data) {
  11990. $scope.loading = false;
  11991. $modalInstance.close(data);
  11992. }, function (response) {
  11993. $scope.loading = false;
  11994. toaster.pop('error', '提示', response.data);
  11995. });
  11996. }
  11997. }
  11998. }]);
  11999. /**
  12000. * 物料批量上传
  12001. */
  12002. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  12003. BaseService.scrollBackToTop();
  12004. $scope.$watch('myFiles', function () {
  12005. if ($scope.myFiles) {
  12006. var file = $scope.myFiles[0];
  12007. $scope.fileName = file.name;
  12008. }
  12009. })
  12010. // 通过excel批量上传物料
  12011. $scope.upload = function () {
  12012. $scope.loading = true;
  12013. if ($scope.myFiles) {
  12014. var file = $scope.myFiles[0];
  12015. if (file.name) {
  12016. $upload.upload({
  12017. url: 'product/baseInfo/edit/release/excel',
  12018. file: file,
  12019. method: 'POST'
  12020. }).success(function (data) {
  12021. $scope.loading = false;
  12022. if (data.error) {
  12023. toaster.pop('error', '提示', data.error);
  12024. }
  12025. $scope.result = data;
  12026. // $scope.products = $scope.result.products;
  12027. $scope.success = $scope.result.success;
  12028. $scope.total = $scope.result.total;
  12029. $scope.alters = $scope.result.alters;
  12030. $scope.infos = $scope.result.infos;
  12031. $scope.myFiles[0] = "";
  12032. $scope.fileName = "";
  12033. }).error(function (response) {
  12034. $scope.loading = false;
  12035. toaster.pop('error', response.data || response);
  12036. });
  12037. } else {
  12038. $scope.loading = false;
  12039. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  12040. }
  12041. } else {
  12042. $scope.loading = false;
  12043. }
  12044. };
  12045. // 查看范例
  12046. $scope.showImg = function () {
  12047. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  12048. box.show();
  12049. box.find('img').attr('src', src);
  12050. box.find('a').click(function () {
  12051. box.hide();
  12052. });
  12053. box.dblclick(function () {
  12054. box.hide();
  12055. });
  12056. };
  12057. // 下载模板
  12058. $scope.download = function () {
  12059. window.location.href = 'product/baseInfo/upload/template';
  12060. };
  12061. }]);
  12062. /**
  12063. * 物料详情
  12064. */
  12065. 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) {
  12066. BaseService.scrollBackToTop();
  12067. // 录入人
  12068. AuthenticationService.getAuthentication().success(function (data) {
  12069. $scope.loading = false;
  12070. $scope.user = data;
  12071. });
  12072. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12073. $scope.editstatus = false;
  12074. var loadData = function () {
  12075. GetProductInfo.getSaleProduct({id: $stateParams.id}, function (data) {
  12076. if (data.attachment) {
  12077. $scope.imgPreview = data.attachment;
  12078. $scope.previewShow = true;
  12079. }
  12080. $scope.prodInfo = data;
  12081. if ($scope.prodInfo.isbusiness == 0) {
  12082. $scope.editstatus = true;
  12083. }
  12084. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  12085. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  12086. $scope.matchresults = data;
  12087. }, function (response) {
  12088. toaster.pop('error', '提示', response.data);
  12089. });
  12090. }
  12091. $scope.loading = false;
  12092. }, function (response) {
  12093. $scope.loading = false;
  12094. toaster.pop('error', '数据加载失败', response.data);
  12095. });
  12096. };
  12097. loadData();
  12098. // 联想词 start
  12099. // 获取类目
  12100. $scope.getSimilarKinds = function (value) {
  12101. if (value) {
  12102. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12103. return data.map(function (item) {
  12104. return item;
  12105. });
  12106. });
  12107. }
  12108. };
  12109. // 设置类目
  12110. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12111. $scope.prodInfo.kind = kind.kindName;
  12112. }
  12113. // 设置名称
  12114. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  12115. $scope.prodInfo.title = kind.kindName;
  12116. }
  12117. $scope.getSimilarBrands = function (value) {
  12118. if (value) {
  12119. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12120. return data.map(function (item) {
  12121. return item;
  12122. });
  12123. });
  12124. }
  12125. }
  12126. // 设置导入品牌
  12127. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12128. $scope.prodInfo.brand = brand.brandName;
  12129. }
  12130. // 设置标准品牌
  12131. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  12132. $scope.prodInfo.pbranden = brand.brandName;
  12133. }
  12134. $scope.getSimilarComponents = function (value) {
  12135. if (value) {
  12136. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12137. return data.map(function (item) {
  12138. return item;
  12139. });
  12140. });
  12141. }
  12142. }
  12143. // 设置标准型号
  12144. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12145. $scope.prodInfo.pcmpcode = cmp.code;
  12146. }
  12147. // 设置导入的型号
  12148. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  12149. $scope.prodInfo.cmpCode = cmp.code;
  12150. }
  12151. // 联想词 end
  12152. // 选择类目
  12153. $scope.selectKind = function (cmpcode) {
  12154. if (cmpcode == null) {
  12155. $modal.open({
  12156. animation: true,
  12157. size: 'lg',
  12158. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12159. controller: 'KindChooseCtrl',
  12160. }).result.then(function (data) {
  12161. $scope.kindId = data;
  12162. var modalInstance = $modal.open({
  12163. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12164. controller: 'FindComponentCtrl',
  12165. size: 'lg',
  12166. resolve: {
  12167. KindId: function () {
  12168. return $scope.kindId;
  12169. }
  12170. }
  12171. });
  12172. modalInstance.result.then(function (data) {
  12173. $scope.prodInfo.cmpUuId = data.uuid;
  12174. $scope.prodInfo.pcmpcode = data.code;
  12175. $scope.prodInfo.pbranden = data.brand.nameEn;
  12176. $scope.prodInfo.pbrand = data.brand.nameCn;
  12177. }, function () {
  12178. });
  12179. }, function () {
  12180. });
  12181. }
  12182. };
  12183. $scope.isShow = true;
  12184. // 更新
  12185. $scope.update = function () {
  12186. $scope.prodInfo.$editing = true;
  12187. $scope.isShow = true;
  12188. };
  12189. // 取消
  12190. $scope.cancel = function () {
  12191. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  12192. $scope.prodInfo = data;
  12193. $scope.prodInfo.$editing = false;
  12194. $scope.isShow = false;
  12195. $scope.loading = false;
  12196. });
  12197. };
  12198. // 删除
  12199. $scope.clearfile = function () {
  12200. $scope.prodInfo.attachment = null;
  12201. $scope.myFiles = null;
  12202. $scope.previewShow = false;
  12203. }
  12204. //删除
  12205. $scope.deleteById = function (id) {
  12206. $scope.loading = true;
  12207. GetProductInfo.deleteById({}, id, function (data) {
  12208. $scope.loading = false;
  12209. if (data.error) {
  12210. toaster.pop("error", "提示", data.error);
  12211. } else {
  12212. toaster.pop("success", "提示", "删除成功");
  12213. window.location.href = "#/sale/prodList";
  12214. }
  12215. }, function (response) {
  12216. $scope.loading = false;
  12217. toaster.pop("error", "删除失败", response.data);
  12218. });
  12219. };
  12220. $scope.submit = function (prodInfo) {
  12221. $scope.prodInfo.isSale = 1;
  12222. $scope.loading = true;
  12223. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12224. $upload.upload({
  12225. url: 'product/baseInfo/edit/updateProdInfo',
  12226. file: file,
  12227. method: 'POST',
  12228. data: {
  12229. prodInfo: $scope.prodInfo
  12230. },
  12231. }).success(function (data) {
  12232. $scope.loading = false;
  12233. if (data.success) {
  12234. toaster.pop('success', '提示', data.success);
  12235. $rootScope.isProductEdit = false;
  12236. loadData();
  12237. // window.location.href="#/sale/prodList";
  12238. }
  12239. if (data.error) {
  12240. toaster.pop('error', '提示', data.error);
  12241. }
  12242. }).error(function (data, status) {
  12243. $scope.loading = false;
  12244. $scope.loadingShow = false;
  12245. if (status == 403){
  12246. toaster.pop('error', '操作失败', data);
  12247. } else {
  12248. toaster.pop('error', '操作失败', data.error);
  12249. }
  12250. });
  12251. }
  12252. $scope.previewShow = false;
  12253. $scope.pdfShow = false;
  12254. $scope.noneFileShow = true;
  12255. $scope.$watch('myFiles', function () {
  12256. if ($scope.myFiles) {
  12257. $scope.noneFileShow = false;
  12258. var file = $scope.myFiles[0];
  12259. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12260. $scope.pdfShow = true;
  12261. $scope.previewShow = false;
  12262. $scope.imgPreviewName = file.name;
  12263. } else {
  12264. if (typeof(Worker) !== "undefined") {//支持HTML5
  12265. $scope.imgPreview = getObjectURL(file);
  12266. $scope.imgPreviewName = file.name;
  12267. } else {//不支持HTML5
  12268. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12269. $scope.imgPreviewName = file.name;
  12270. }
  12271. $scope.previewShow = true;
  12272. $scope.pdfShow = false;
  12273. }
  12274. } else {
  12275. $scope.noneFileShow = true;
  12276. $scope.previewShow = false;
  12277. $scope.pdfShow = false;
  12278. }
  12279. });
  12280. //建立一个可存取到该file的url
  12281. var imgurl = null;
  12282. var getObjectURL = function (file) {
  12283. var url = null;
  12284. if (window.createObjectURL != undefined) { // basic
  12285. url = window.createObjectURL(file);
  12286. } else if (window.URL != undefined) { // mozilla(firefox)
  12287. url = window.URL.createObjectURL(file);
  12288. } else if (window.webkitURL != undefined) { // webkit or chrome
  12289. url = window.webkitURL.createObjectURL(file);
  12290. }
  12291. imgurl = url;
  12292. return url;
  12293. };
  12294. // 查看范例
  12295. $scope.showImg = function () {
  12296. if ($scope.prodInfo.attachment) {
  12297. $scope.imgPreview = $scope.prodInfo.attachment;
  12298. var src = $scope.prodInfo.attachment, box = $('#image-box');
  12299. box.show();
  12300. box.find('img').attr('src', src);
  12301. box.find('a').click(function () {
  12302. box.hide();
  12303. });
  12304. box.dblclick(function () {
  12305. box.hide();
  12306. });
  12307. $scope.previewShow = true;
  12308. } else if (imgurl != null) {
  12309. var src = imgurl, box = $('#image-box');
  12310. box.show();
  12311. box.find('img').attr('src', src);
  12312. box.find('a').click(function () {
  12313. box.hide();
  12314. });
  12315. box.dblclick(function () {
  12316. box.hide();
  12317. });
  12318. }
  12319. };
  12320. }]);
  12321. /**
  12322. * 新增物料(销售)
  12323. */
  12324. 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) {
  12325. BaseService.scrollBackToTop();
  12326. // 录入人
  12327. AuthenticationService.getAuthentication().success(function (data) {
  12328. $scope.loading = false;
  12329. $scope.user = data;
  12330. });
  12331. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12332. $scope.prodInfo = {};
  12333. // 选择类目
  12334. $scope.selectKind = function () {
  12335. $modal.open({
  12336. animation: true,
  12337. size: 'lg',
  12338. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12339. controller: 'KindChooseCtrl',
  12340. }).result.then(function (data) {
  12341. $scope.kindId = data;
  12342. var modalInstance = $modal.open({
  12343. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12344. controller: 'FindComponentCtrl',
  12345. size: 'lg',
  12346. resolve: {
  12347. KindId: function () {
  12348. return $scope.kindId;
  12349. }
  12350. }
  12351. });
  12352. modalInstance.result.then(function (data) {
  12353. $scope.prodInfo.cmpUuId = data.uuid;
  12354. $scope.prodInfo.pcmpcode = data.code;
  12355. $scope.prodInfo.pbranden = data.brand.nameEn;
  12356. $scope.prodInfo.pbrand = data.brand.nameCn;
  12357. }, function () {
  12358. });
  12359. }, function () {
  12360. });
  12361. };
  12362. // 联想词 start
  12363. // 获取类目
  12364. $scope.getSimilarKinds = function (value) {
  12365. if (value) {
  12366. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12367. return data.map(function (item) {
  12368. return item;
  12369. });
  12370. });
  12371. }
  12372. };
  12373. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12374. $scope.prodInfo.title = kind.kindName;
  12375. }
  12376. $scope.getSimilarBrands = function (value) {
  12377. if (value) {
  12378. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12379. return data.map(function (item) {
  12380. return item;
  12381. });
  12382. });
  12383. }
  12384. }
  12385. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12386. $scope.prodInfo.brand = brand.brandName;
  12387. }
  12388. $scope.getSimilarComponents = function (value) {
  12389. if (value) {
  12390. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12391. return data.map(function (item) {
  12392. return item;
  12393. });
  12394. });
  12395. }
  12396. }
  12397. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12398. $scope.prodInfo.cmpCode = cmp.code;
  12399. }
  12400. // 联想词 end
  12401. // 删除
  12402. $scope.clearfile = function () {
  12403. $scope.myFiles = null;
  12404. $scope.previewShow = false;
  12405. }
  12406. //提交
  12407. $scope.submit = function (prodInfo) {
  12408. $scope.loading = true;
  12409. $scope.prodInfo.isSale = 1;
  12410. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12411. $upload.upload({
  12412. url: 'product/baseInfo/edit/addNewProduct',
  12413. file: file,
  12414. method: 'POST',
  12415. data: {
  12416. prodInfo: prodInfo
  12417. },
  12418. }).success(function (data) {
  12419. $scope.loading = false;
  12420. if (data.success) {
  12421. toaster.pop('success', '提示', '产品添加成功');
  12422. $timeout(function () {
  12423. //提交后跳转到详情页面,防止重复提交
  12424. window.location.href = "#/sale/prodList/" + data.id;
  12425. // window.location.href="#/sale/prodList";
  12426. }, 500);
  12427. }
  12428. if (data.error) {
  12429. toaster.pop('error', '提示', data.error);
  12430. $timeout(function () {
  12431. //提交后跳转到详情页面,防止重复提交
  12432. window.location.href = "#/sale/prodList/" + data.id;
  12433. // window.location.href="#/sale/prodList";
  12434. }, 500);
  12435. }
  12436. }).error(function (data, status) {
  12437. $scope.loading = false;
  12438. $scope.loadingShow = false;
  12439. if (status == 403) {
  12440. toaster.pop('error', '操作失败', data);
  12441. } else {
  12442. toaster.pop('error', '操作失败', data.error);
  12443. }
  12444. });
  12445. };
  12446. $scope.previewShow = false;
  12447. $scope.pdfShow = false;
  12448. $scope.noneFileShow = true;
  12449. $scope.$watch('myFiles', function () {
  12450. if ($scope.myFiles) {
  12451. $scope.noneFileShow = false;
  12452. var file = $scope.myFiles[0];
  12453. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12454. $scope.pdfShow = true;
  12455. $scope.previewShow = false;
  12456. $scope.imgPreviewName = file.name;
  12457. } else {
  12458. if (typeof(Worker) !== "undefined") {//支持HTML5
  12459. $scope.imgPreview = getObjectURL(file);
  12460. $scope.imgPreviewName = file.name;
  12461. } else {//不支持HTML5
  12462. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12463. $scope.imgPreviewName = file.name;
  12464. }
  12465. $scope.previewShow = true;
  12466. $scope.pdfShow = false;
  12467. }
  12468. } else {
  12469. $scope.noneFileShow = true;
  12470. $scope.previewShow = false;
  12471. $scope.pdfShow = false;
  12472. }
  12473. });
  12474. //建立一个可存取到该file的url
  12475. var imgUrl = null
  12476. var getObjectURL = function (file) {
  12477. var url = null;
  12478. if (window.createObjectURL != undefined) { // basic
  12479. url = window.createObjectURL(file);
  12480. } else if (window.URL != undefined) { // mozilla(firefox)
  12481. url = window.URL.createObjectURL(file);
  12482. } else if (window.webkitURL != undefined) { // webkit or chrome
  12483. url = window.webkitURL.createObjectURL(file);
  12484. }
  12485. imgUrl = url;
  12486. return url;
  12487. };
  12488. // 查看范例
  12489. $scope.showImg = function () {
  12490. var src = imgUrl, box = $('#image-box');
  12491. box.show();
  12492. box.find('img').attr('src', src);
  12493. box.find('a').click(function () {
  12494. box.hide();
  12495. });
  12496. box.dblclick(function () {
  12497. box.hide();
  12498. });
  12499. };
  12500. // 取消
  12501. $scope.cancel = function () {
  12502. $scope.prodInfo = angular.copy($scope.prodInfo);
  12503. };
  12504. }]);
  12505. /**
  12506. * 类目选择模态框
  12507. */
  12508. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function ($scope, KindAPI, toaster, $modalInstance, $modal) {
  12509. $scope.kindId = null;
  12510. $scope.kinds = [[], [], [], []];
  12511. // 获取子类目
  12512. var getChildren = function (pid, deep) {
  12513. KindAPI.getChildren({parentId: pid}, function (data) {
  12514. $scope.kinds[deep] = data;
  12515. }, function (response) {
  12516. toaster.pop('error', '获取子类目失败', response.data);
  12517. });
  12518. };
  12519. // 改变节点选中状态
  12520. var changeStatus = function (item, deep) {
  12521. var kindId = null, level = 0;
  12522. angular.forEach($scope.kinds, function (ks, i) {
  12523. if (i > deep) {
  12524. $scope.kinds[i] = [];
  12525. } else {
  12526. angular.forEach(ks, function (k, j) {
  12527. if (i == deep) {
  12528. if (k.id == item.id) {
  12529. $scope.kinds[i][j].$active = true;
  12530. kindId = k.id;
  12531. } else {
  12532. k.$active = null;
  12533. }
  12534. }
  12535. });
  12536. }
  12537. });
  12538. // 选择的节点
  12539. $scope.kindId = kindId;
  12540. $scope.active = item;
  12541. // 当前可操作的层级
  12542. if (deep < 3) {
  12543. $scope.activeDeep = deep + 1;
  12544. }
  12545. };
  12546. // 节点点击后获取子类目,节点被选中
  12547. $scope.onItemClick = function (item, deep) {
  12548. changeStatus(item, deep);
  12549. if (!item.isLeaf) {
  12550. getChildren(item.id, deep + 1);
  12551. }
  12552. };
  12553. // 重新加载数据
  12554. function reload(deep) {
  12555. var pid;
  12556. if (deep) {
  12557. pid = $scope.actives[deep - 1].id;
  12558. } else {
  12559. pid = 0;
  12560. deep = 0;
  12561. }
  12562. getChildren(pid, deep);
  12563. }
  12564. // 初始加载数据,获取第一层的类目
  12565. if ($scope.actives) {
  12566. angular.forEach($scope.actives, function (v, k) {
  12567. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  12568. $scope.kinds[k] = data;
  12569. angular.forEach($scope.kinds[k], function (kind, i) {
  12570. if (kind.id == v.id) {
  12571. $scope.kinds[k][i].$active = true;
  12572. $scope.actives[k] = $scope.kinds[k][i];
  12573. }
  12574. })
  12575. }, function (response) {
  12576. toaster.pop('error', '获取子类目失败', response.data);
  12577. });
  12578. });
  12579. } else {
  12580. reload();
  12581. }
  12582. // 取消
  12583. $scope.cancel = function () {
  12584. $modalInstance.dismiss();
  12585. };
  12586. // 确认选择
  12587. $scope.check = function () {
  12588. $modalInstance.close($scope.kindId);
  12589. };
  12590. }]);
  12591. /**
  12592. * 器件筛选
  12593. */
  12594. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  12595. //状态
  12596. $scope.setActive = function (state) {
  12597. if ($scope.active != state) {
  12598. $scope.active = state;
  12599. if ($scope.tableParams.page() == 1)
  12600. $scope.tableParams.reload();
  12601. else
  12602. $scope.tableParams.page(1);
  12603. }
  12604. };
  12605. $scope.tableParams = new ngTableParams({
  12606. page: 1,
  12607. count: 20
  12608. }, {
  12609. total: 0,
  12610. counts: [5, 10, 25, 50],
  12611. getData: function ($defer, params) {
  12612. $scope.loading = true;
  12613. var pageParams = params.url();
  12614. pageParams.keyword = $scope.keyword;
  12615. pageParams.kindId = KindId;
  12616. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function (page) {
  12617. $scope.loading = false;
  12618. if (page) {
  12619. params.total(page.totalElement);
  12620. $defer.resolve(page.content);
  12621. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  12622. }
  12623. }, function (response) {
  12624. $scope.loading = false;
  12625. toaster.pop('error', '数据加载失败', response.data);
  12626. });
  12627. }
  12628. });
  12629. // 取消
  12630. $scope.cancel = function () {
  12631. $modalInstance.dismiss();
  12632. };
  12633. // 选择
  12634. $scope.check = function (data) {
  12635. $modalInstance.close(data);
  12636. };
  12637. // 搜索框回车
  12638. $scope.onSearch = function () {
  12639. $scope.tableParams.page(1);
  12640. $scope.tableParams.reload();
  12641. };
  12642. }]);
  12643. /**
  12644. * 企业列表
  12645. */
  12646. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  12647. BaseService.scrollBackToTop();
  12648. $scope.active = 'all';
  12649. $scope.agreedText = '全部';
  12650. $scope.dateZoneText = '一个月内';
  12651. $scope.condition = {dateZone: 1};
  12652. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12653. $scope.changeAgreed = function (agreed) {
  12654. $scope.condition.agreed = agreed;
  12655. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12656. $scope.condition.$agreedOpen = false;
  12657. };
  12658. $scope.changeDateZone = function (zone) {
  12659. $scope.condition.dateZone = zone;
  12660. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12661. $scope.condition.$dateZoneOpen = false;
  12662. getDateCondition(zone, $scope.condition);
  12663. $scope.tableParams.reload();
  12664. };
  12665. $scope.setActive = function (state) {
  12666. if ($scope.active != state) {
  12667. $scope.active = state;
  12668. if ($scope.tableParams.page() == 1)
  12669. $scope.tableParams.reload();
  12670. else
  12671. $scope.tableParams.page(1);
  12672. }
  12673. };
  12674. var getService = function () {
  12675. return getAccountUserSpace;
  12676. };
  12677. $scope.tableParams = new ngTableParams({
  12678. page: 1,
  12679. count: 20,
  12680. sorting: {}
  12681. }, {
  12682. total: 0,
  12683. counts: [5, 10, 25, 50],
  12684. getData: function ($defer, params) {
  12685. $scope.loading = true;
  12686. var pageParams = params.url();
  12687. pageParams.keyword = $scope.keyword;
  12688. $scope.tip = $scope.keyword;
  12689. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12690. $scope.loading = false;
  12691. if (page) {
  12692. params.total(page.totalElement);
  12693. $defer.resolve(page.content);
  12694. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12695. }
  12696. }, function (response) {
  12697. $scope.loading = false;
  12698. toaster.pop('error', '数据加载失败', response.data);
  12699. });
  12700. }
  12701. });
  12702. // 搜索框回车
  12703. $scope.onSearch = function () {
  12704. $scope.tableParams.page(1);
  12705. $scope.tableParams.reload();
  12706. };
  12707. // 添加合作关系
  12708. $scope.addPartner = function (name, businessCode) {
  12709. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  12710. if (data.success) {
  12711. toaster.pop("success", '添加成功', data.success);
  12712. $scope.tableParams.reload();
  12713. }
  12714. if (data.error) {
  12715. toaster.pop("error", '添加失败', data.error);
  12716. }
  12717. }, function (response) {
  12718. toaster.pop('error', '失败', response.data);
  12719. });
  12720. }
  12721. $scope.status = 'enList';
  12722. }]);
  12723. /**
  12724. * 新增采购单
  12725. */
  12726. app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', 'recentPrice',
  12727. function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token, recentPrice) {
  12728. BaseService.scrollBackToTop();
  12729. // 每次进入时先清除掉rootScope下的venduu
  12730. $rootScope.venduu = null;
  12731. // 获取收货地址列表
  12732. ShipAddress.shipAddList({}, function (data) {
  12733. $scope.ships = data;
  12734. $scope.order.shipadd = $scope.ships[0];
  12735. });
  12736. // 获取地址信息
  12737. $http.get('resources/citydata/city.json', {
  12738. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  12739. }).then(function (response) {
  12740. $scope.provinces = response.data;
  12741. });
  12742. var getToken = function() {
  12743. if($scope.token == null) {
  12744. token.info({userType: 'purcorder'}, {}, function(data) {
  12745. $scope.token = data.token;
  12746. }, function(response) {
  12747. toaster.pop('error', '提示', response.data);
  12748. });
  12749. }
  12750. }
  12751. getToken();
  12752. $scope.order = {
  12753. date: new Date(),
  12754. vend: {
  12755. uu: '',
  12756. },
  12757. vendUser: {},
  12758. code: $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  12759. orderItems: {
  12760. product: {},
  12761. },
  12762. rate: 17
  12763. };
  12764. //商品信息
  12765. $scope.order.orderItems = [];
  12766. var item = {
  12767. code: null,
  12768. title: null,
  12769. spec: null,
  12770. unit: null,
  12771. qty: null,
  12772. price: null,
  12773. remark: null,
  12774. delivery: null,
  12775. prid: null,
  12776. taxrate: null
  12777. };
  12778. if ($rootScope.businessCode) {
  12779. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function (data) {
  12780. $scope.id = data.id;
  12781. $scope.order.vend.enName = data.vendorEnterprise.enName;
  12782. $scope.order.vend.enAddress = data.vendorEnterprise.enAddress;
  12783. $scope.order.vend.uu = data.vendorEnterprise.uu;
  12784. $scope.order.paymethods = data.paymethod;
  12785. $rootScope.venduu = data.vendorEnterprise.uu;
  12786. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  12787. $scope.contacts = data;
  12788. $scope.order.vendor = $scope.contacts[0];
  12789. });
  12790. }, function (response) {
  12791. });
  12792. }
  12793. ;
  12794. // 查找供应商
  12795. $scope.dbfindVend = function () {
  12796. var modalInstance = $modal.open({
  12797. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  12798. controller: 'DbfindVendorInfoCtrl',
  12799. size: 'lg',
  12800. resolve: {
  12801. orderItems: function () {
  12802. return $scope.order.orderItems;
  12803. }
  12804. }
  12805. });
  12806. modalInstance.result.then(function (data) {
  12807. $rootScope.venduu = data.vendorEnterprise.uu;
  12808. $scope.id = data.id;
  12809. $scope.order.vend = data.vendorEnterprise;
  12810. $scope.order.vend.enName = data.vendorEnterprise.enName;
  12811. $scope.order.vendUser = data.vendorUser;
  12812. $scope.order.payments = data.paymethod;
  12813. $scope.order.orderItems = [];
  12814. var item = {
  12815. code: null,
  12816. title: null,
  12817. spec: null,
  12818. unit: null,
  12819. qty: null,
  12820. price: null,
  12821. remark: null,
  12822. delivery: null,
  12823. taxrate: null
  12824. };
  12825. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  12826. $scope.contacts = data;
  12827. $scope.order.vendor = $scope.contacts[0];
  12828. });
  12829. }, function () {
  12830. });
  12831. };
  12832. // 联想词 start
  12833. // 获取供应商
  12834. $scope.getSimilarVendors = function (value) {
  12835. if (value) {
  12836. return Vendor.getSimilarVendors({keyword: value}).$promise.then(function (data) {
  12837. return data.map(function (item) {
  12838. return item;
  12839. });
  12840. });
  12841. }
  12842. };
  12843. $scope.onAssociateCmpClick = function (vendor, order) {
  12844. $scope.order.vend.uu = vendor.venduu;
  12845. $scope.id = vendor.id;
  12846. $scope.order.payments = vendor.paymethod;
  12847. $rootScope.venduu = $scope.order.vend.uu;
  12848. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  12849. $scope.contacts = data;
  12850. $scope.order.vendor = $scope.contacts[0];
  12851. });
  12852. }
  12853. // 联想词 end
  12854. // $scope.order.orderItems.push(item);
  12855. if ($rootScope.prodId) {
  12856. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  12857. item.code = data.code;
  12858. item.title = data.title;
  12859. item.spec = data.spec;
  12860. item.unit = data.unit;
  12861. item.id = data.id;
  12862. $scope.order.orderItems.push(item);
  12863. $rootScope.prodId = null;// 清除掉prodId
  12864. }, function (response) {
  12865. });
  12866. }
  12867. //增加商品
  12868. $scope.addProduct = function (index) {
  12869. if ($scope.order.orderItems[index].code == null) {
  12870. toaster.pop('info', '提示', '请先选择商品');
  12871. } else {
  12872. $scope.order.orderItems.push({
  12873. code: null,
  12874. title: null,
  12875. spec: null,
  12876. unit: null,
  12877. qty: null,
  12878. price: null,
  12879. remark: null,
  12880. delivery: null,
  12881. $endDateOpen: false,
  12882. taxrate: $scope.order.rate,
  12883. prodsource: 'seller'
  12884. });
  12885. }
  12886. };
  12887. //删除商品
  12888. $scope.deleteProduct = function (index) {
  12889. $scope.order.orderItems.splice(index, 1);
  12890. };
  12891. // 搜索框回车
  12892. $scope.onSearch = function (keyword) {
  12893. $scope.keyword = keyword;
  12894. $scope.tableParams.page(1);
  12895. $scope.tableParams.reload();
  12896. };
  12897. $scope.tableParams = new ngTableParams({
  12898. page: 1,
  12899. count: 20
  12900. }, {
  12901. total: 0,
  12902. counts: [5, 10, 25, 50],
  12903. getData: function ($defer, params) {
  12904. $scope.loading = true;
  12905. var pageParams = params.url();
  12906. pageParams.keyword = $scope.keyword;
  12907. $scope.tip = $scope.keyword;
  12908. pageParams.vendUU = $scope.order.vend.uu;
  12909. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  12910. $scope.loading = false;
  12911. if (page) {
  12912. params.total(page.totalElement);
  12913. $scope.total = page.totalElement;
  12914. $defer.resolve(page.content);
  12915. }
  12916. }, function (response) {
  12917. $scope.loading = false;
  12918. toaster.pop('error', '数据加载失败', response.data);
  12919. });
  12920. }
  12921. });
  12922. // 选择
  12923. $scope.check = function (data) {
  12924. var price = null;
  12925. var qty = null;
  12926. var taxRate = null;
  12927. if (data.id) {
  12928. recentPrice.agreed({prId: data.id}, {}, function(response) {
  12929. price = response.price;
  12930. qty = response.qty;
  12931. taxRate = response.taxRate;
  12932. $scope.order.orderItems.push({
  12933. code: data.code,
  12934. title: data.title,
  12935. spec: data.spec,
  12936. unit: data.unit,
  12937. qty: qty,
  12938. price: price,
  12939. remark: null,
  12940. delivery: null,
  12941. prid: data.id,
  12942. taxrate: taxRate,
  12943. prodsource: 'seller',
  12944. });
  12945. });
  12946. }
  12947. };
  12948. // 导入商品信息
  12949. $scope.uplodaByBatch = function () {
  12950. var modalInstance = $modal.open({
  12951. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  12952. controller: 'PurcUploadByBatchCtrl',
  12953. size: 'lg',
  12954. resolve: {}
  12955. });
  12956. modalInstance.result.then(function (data) {
  12957. angular.forEach(data, function (prod) {
  12958. $scope.order.orderItems.push({
  12959. code: prod.code,
  12960. title: prod.title,
  12961. unit: 'PCS',
  12962. spec: prod.spec,
  12963. qty: prod.amount,
  12964. price: prod.rateprice,
  12965. remark: prod.remark,
  12966. delivery: prod.date,
  12967. prid: prod.id,
  12968. taxrate: prod.rate,
  12969. prodsource: 'purchaser'
  12970. });
  12971. })
  12972. }, function () {
  12973. });
  12974. };
  12975. // 监听venduu发生变化,重新加载物料信息
  12976. $scope.$watch('order.vend.uu', function (n, o) {
  12977. if (n == o) {
  12978. return;
  12979. } else {
  12980. $scope.tableParams.page(1);
  12981. $scope.tableParams.reload();
  12982. }
  12983. }, true);
  12984. $scope.getMinDate = function (item) {
  12985. return $filter('date')(new Date, 'yyyy-MM-dd');
  12986. };
  12987. $scope.openDatePicker = function ($event, openParam, index) {
  12988. $event.preventDefault();
  12989. $event.stopPropagation();
  12990. $scope.order.orderItems[index].$endDateOpen = !openParam;
  12991. };
  12992. // 添加到购物车
  12993. $scope.addToCart = function (order) {
  12994. $scope.loading = true;
  12995. $scope.order.status = 311;
  12996. $scope.order.vendusertel = order.vendor.tel;
  12997. $scope.order.venduser = order.vendor.venduser;
  12998. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  12999. $scope.order.vendUU = $scope.order.vend.uu;
  13000. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13001. if ($scope.order.date instanceof Date) {
  13002. $scope.order.date = $scope.order.date.getTime();
  13003. }
  13004. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13005. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13006. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13007. }
  13008. if ($scope.order.currency != 'RMB') {
  13009. $scope.order.orderItems[i].rate = 0;
  13010. }
  13011. }
  13012. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13013. $scope.loading = false;
  13014. toaster.pop('success', '成功', '保存成功');
  13015. window.location.hash = '#/purc/cart/' + data.id;
  13016. $window.location.reload();
  13017. }, function (response) {
  13018. $scope.loading = false;
  13019. toaster.pop('error', '保存失败', response.data);
  13020. });
  13021. };
  13022. // 立即购买
  13023. $scope.addToOrder = function (order) {
  13024. $scope.loading = true;
  13025. $scope.order.status = 200;
  13026. $scope.order.vendusertel = order.vendor.tel;
  13027. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  13028. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13029. $scope.order.vendUU = $scope.order.vend.uu;
  13030. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13031. if ($scope.order.date instanceof Date) {
  13032. $scope.order.date = $scope.order.date.getTime();
  13033. }
  13034. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13035. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13036. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13037. }
  13038. if ($scope.order.currency != 'RMB') {
  13039. $scope.order.orderItems[i].rate = 0;
  13040. }
  13041. }
  13042. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13043. $scope.loading = false;
  13044. toaster.pop('success', '成功', '保存成功');
  13045. window.location.hash = '#/purc/order/' + data.id;
  13046. }, function (response) {
  13047. $scope.loading = false;
  13048. toaster.pop('error', '保存失败', response.data);
  13049. });
  13050. };
  13051. // 新增收货地址保存
  13052. $scope.saveShipAddress = function (ship) {
  13053. ship.address = ship.province + ship.city + ship.district;
  13054. ShipAddress.saveAddress({}, ship, function (data) {
  13055. if (data.success) {
  13056. ShipAddress.shipAddList({}, function (data) {
  13057. $scope.ships = data;
  13058. $scope.order.shipadd = $scope.ships[0];
  13059. });
  13060. toaster.pop('success', '提示', data.success);
  13061. }
  13062. if (data.error) {
  13063. toaster.pop('error', '提示', data.error);
  13064. }
  13065. });
  13066. }
  13067. // 新增供应商联系人
  13068. $scope.addContact = function (uu) {
  13069. var modalInstance = $modal.open({
  13070. animation: true,
  13071. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13072. controller: 'AddContacCtrl',
  13073. resolve: {}
  13074. });
  13075. modalInstance.result.then(function (data) {
  13076. $scope.contact = data;
  13077. $scope.contact.venduu = uu;
  13078. Vendor.saveContact({}, $scope.contact, function (data) {
  13079. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13080. $scope.contacts = data;
  13081. $scope.order.vendor = $scope.contacts[0];
  13082. });
  13083. toaster.pop('success', '提示', '联系人保存成功');
  13084. }, function (response) {
  13085. toaster.pop('error', '失败', response.data);
  13086. });
  13087. });
  13088. }
  13089. }]);
  13090. /**
  13091. * 采购批量导入
  13092. */
  13093. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  13094. // 通过excel批量上传物料
  13095. $scope.result = null;
  13096. $scope.loading = false;
  13097. $scope.upload = function () {
  13098. $scope.loading = true;
  13099. var file = $scope.myFiles[0];
  13100. $upload.upload({
  13101. url: 'purchase/release/excel',
  13102. file: file,
  13103. method: 'POST'
  13104. }).success(function (data) {
  13105. $scope.loading = false;
  13106. $scope.result = data;
  13107. $scope.success = $scope.result.success;
  13108. $scope.total = $scope.result.total;
  13109. $scope.alters = $scope.result.alters;
  13110. }).error(function (response) {
  13111. $scope.loading = false;
  13112. toaster.pop('error', response.data || response);
  13113. });
  13114. };
  13115. // 下载模板
  13116. $scope.download = function () {
  13117. window.location.href = 'purchase/upload/template';
  13118. };
  13119. $scope.enSure = function () {
  13120. $scope.loading = true;
  13121. $modalInstance.close($scope.result.products);
  13122. }
  13123. $scope.cancel = function () {
  13124. $modalInstance.dismiss();
  13125. }
  13126. }]);
  13127. // 查找供应商
  13128. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems) {
  13129. $scope.prod = false;
  13130. if (orderItems.length != 0) {
  13131. $scope.prod = true;
  13132. }
  13133. BaseService.scrollBackToTop();
  13134. if ($rootScope.venduu != null) {
  13135. $scope.venduu = $rootScope.venduu;
  13136. }
  13137. // 搜索框回车
  13138. $scope.onSearch = function (keyword) {
  13139. $scope.keyword = keyword;
  13140. $scope.customerParams.page(1);
  13141. $scope.customerParams.reload();
  13142. };
  13143. $scope.customerParams = new ngTableParams({
  13144. page: 1,
  13145. count: 20
  13146. }, {
  13147. total: 0,
  13148. counts: [5, 10, 25, 50],
  13149. getData: function ($defer, params) {
  13150. $scope.loading = true;
  13151. var pageParams = params.url();
  13152. pageParams.keyword = $scope.keyword;
  13153. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13154. $scope.loading = false;
  13155. if (page) {
  13156. params.total(page.totalElement);
  13157. $defer.resolve(page.content);
  13158. }
  13159. $scope.totalCount = page.totalElement;
  13160. }, function (response) {
  13161. $scope.loading = false;
  13162. toaster.pop('error', '数据加载失败', response.data);
  13163. });
  13164. }
  13165. });
  13166. $scope.cancel = function () {
  13167. $modalInstance.dismiss();
  13168. };
  13169. $scope.ensure = false;
  13170. $scope.check = function (vendor) { // 需要进行判断的选择
  13171. $scope.vendorInfo = vendor;
  13172. $scope.ensure = true;
  13173. };
  13174. $scope.checkVendor = function (vendor) { // 直接选择
  13175. $modalInstance.close(vendor);
  13176. }
  13177. }]);
  13178. /**
  13179. * 我的客户
  13180. */
  13181. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster) {
  13182. $scope.userInfoResult = true;
  13183. AuthenticationService.getAuthentication().success(function (data) {
  13184. $scope.loading = false;
  13185. $scope.thisUser = data;
  13186. });
  13187. var getCustInfos = function (custuu) {
  13188. if (custuu) {
  13189. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  13190. $scope.custInfos = data;
  13191. var getPage = function (page, size) {
  13192. if ($scope.custInfos) {
  13193. var result = {};
  13194. result.totalCount = $scope.custInfos.length;
  13195. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  13196. if ($scope.custInfos.length % size == 0) {
  13197. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  13198. } else {
  13199. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  13200. }
  13201. result.first = page == 1;
  13202. result.last = page == result.totalPage;
  13203. result.page = page;
  13204. result.next = page - 0 + 1;
  13205. result.pre = page - 1;
  13206. return result;
  13207. }
  13208. }
  13209. $scope.userdata = getPage(1, 4);
  13210. $scope.first = function () {
  13211. $scope.userdata = getPage($scope.userdata.pre, 4);
  13212. }
  13213. $scope.last = function () {
  13214. $scope.userdata = getPage($scope.userdata.next, 4);
  13215. }
  13216. }, function (response) {
  13217. $scope.loading = false;
  13218. toaster.pop('error', '数据加载失败', response.data);
  13219. });
  13220. }
  13221. }
  13222. // 分配权限
  13223. $scope.addUserInfo = function (customer) {
  13224. //TODO
  13225. if ($scope.thisUser.sys) {
  13226. var modalInstance = $modal.open({
  13227. animation: true,
  13228. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  13229. controller: 'AddUserInfoCtrl',
  13230. resolve: {
  13231. customer: function () {
  13232. return customer;
  13233. }
  13234. }
  13235. });
  13236. modalInstance.result.then(function (changed, checked) {
  13237. if (changed) {
  13238. if (checked)
  13239. $scope.newUser.roles = checked;
  13240. else
  13241. loadUsers();
  13242. }
  13243. });
  13244. } else {
  13245. toaster.pop('error', '您没有分配用户的权限!');
  13246. }
  13247. };
  13248. $scope.showUserInfo = function (customer, boo) {
  13249. $scope.custInfo = customer;
  13250. if (boo) {
  13251. getCustInfos(customer.myEnterprise.uu);
  13252. $scope.userInfoResult = true;
  13253. }
  13254. }
  13255. $scope.customerParams = new ngTableParams({
  13256. page: 1,
  13257. count: 20
  13258. }, {
  13259. total: 0,
  13260. counts: [5, 10, 25, 50],
  13261. getData: function ($defer, params) {
  13262. $scope.loading = true;
  13263. VendorService.customer.get(BaseService.parseParams(params.url()), function (page) {
  13264. $scope.loading = false;
  13265. if (page) {
  13266. params.total(page.totalElement);
  13267. $defer.resolve(page.content);
  13268. }
  13269. $scope.totalCount = page.totalElement;
  13270. }, function (response) {
  13271. $scope.loading = false;
  13272. toaster.pop('error', '数据加载失败', response.data);
  13273. });
  13274. }
  13275. });
  13276. }]);
  13277. /**
  13278. * 我的供应商
  13279. */
  13280. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  13281. BaseService.scrollBackToTop();
  13282. // 搜索框回车
  13283. $scope.onSearch = function (keyword) {
  13284. $scope.keyword = keyword;
  13285. $scope.customerParams.page(1);
  13286. $scope.customerParams.reload();
  13287. };
  13288. $scope.customerParams = new ngTableParams({
  13289. page: 1,
  13290. count: 20
  13291. }, {
  13292. total: 0,
  13293. counts: [5, 10, 25, 50],
  13294. getData: function ($defer, params) {
  13295. $scope.loading = true;
  13296. var pageParams = params.url();
  13297. pageParams.keyword = $scope.keyword;
  13298. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13299. $scope.loading = false;
  13300. if (page) {
  13301. params.total(page.totalElement);
  13302. $scope.total = page.totalElement;
  13303. $defer.resolve(page.content);
  13304. }
  13305. $scope.totalCount = page.totalElement;
  13306. }, function (response) {
  13307. $scope.loading = false;
  13308. toaster.pop('error', '数据加载失败', response.data);
  13309. });
  13310. }
  13311. });
  13312. //设置消息已读
  13313. var setOrdersRead = function () {
  13314. var ids=[];
  13315. Vendor.setVendorRead({}, ids, function (message) {
  13316. });
  13317. };
  13318. setOrdersRead();
  13319. // 查看供应商详情
  13320. $scope.VendorDetail = function (id, uu) {
  13321. $rootScope.vendorId = id;
  13322. $rootScope.vendoruu = uu;
  13323. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  13324. }
  13325. // 向企业购买
  13326. $scope.purcByEn = function (businessCode) {
  13327. $rootScope.businessCode = businessCode;
  13328. window.location.hash = "#/purc/addOrder";
  13329. }
  13330. }]);
  13331. /**
  13332. * 供应商详情
  13333. */
  13334. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  13335. BaseService.scrollBackToTop();
  13336. $scope.vendorContacts = [];
  13337. var loadData = function () {
  13338. Vendor.getVendorDetail({id: $stateParams.id}, {}, function (data) {
  13339. $scope.vendor = data.vendorEnterprise;
  13340. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  13341. $scope.vendorContacts = data;
  13342. });
  13343. }, function (response) {
  13344. toaster.pop('error', '提示', response.data);
  13345. });
  13346. };
  13347. loadData();
  13348. // 新增供应商联系人
  13349. $scope.addContact = function (uu) {
  13350. var modalInstance = $modal.open({
  13351. animation: true,
  13352. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13353. controller: 'AddContacCtrl',
  13354. resolve: {}
  13355. });
  13356. modalInstance.result.then(function (data) {
  13357. $scope.contact = data;
  13358. $scope.contact.venduu = uu;
  13359. Vendor.saveContact({}, $scope.contact, function (data) {
  13360. toaster.pop('success', '提示', '联系人保存成功');
  13361. $scope.vendorContacts.push(data);
  13362. }, function (response) {
  13363. toaster.pop('error', '失败', response.data);
  13364. });
  13365. });
  13366. };
  13367. // 编辑供应商联系人
  13368. $scope.edit = function (contact) {
  13369. var modalInstance = $modal.open({
  13370. animation: true,
  13371. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13372. controller: 'EditContacCtrl',
  13373. resolve: {
  13374. contact: function () {
  13375. return contact;
  13376. }
  13377. }
  13378. });
  13379. modalInstance.result.then(function (data) {
  13380. Vendor.saveContact({}, data, function (data) {
  13381. loadData();
  13382. toaster.pop('success', '提示', '联系人修改成功');
  13383. }, function (response) {
  13384. toaster.pop('error', '失败', response.data);
  13385. });
  13386. });
  13387. }
  13388. // 删除供应商联系人
  13389. $scope.deleteById = function (id, index) {
  13390. $scope.vendorContacts.splice(index, 1);
  13391. Vendor.deleteContact({id: id}, {}, function (data) {
  13392. toaster.pop('success', '提示', '供应商联系人删除成功');
  13393. loadData();
  13394. }, function (response) {
  13395. toaster.pop('error', '提示', response.data);
  13396. });
  13397. }
  13398. // 供应商物料信息
  13399. $scope.viewProdList = function (uu) {
  13400. $scope.uu = uu;
  13401. $scope.tableParams.page(1);
  13402. $scope.tableParams.reload();
  13403. };
  13404. // 搜索框回车
  13405. $scope.onSearch = function (keyword) {
  13406. $scope.keyword = keyword;
  13407. $scope.tableParams.page(1);
  13408. $scope.tableParams.reload();
  13409. };
  13410. // 供应商物料信息
  13411. $scope.tableParams = new ngTableParams({
  13412. page: 1,
  13413. count: 20
  13414. }, {
  13415. total: 0,
  13416. counts: [5, 10, 25, 50],
  13417. getData: function ($defer, params) {
  13418. $scope.loading = true;
  13419. var pageParams = params.url();
  13420. pageParams.custUU = $scope.uu;
  13421. pageParams.keyword = $scope.keyword;
  13422. $scope.tip = $scope.keyword;
  13423. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  13424. $scope.loading = false;
  13425. if (page) {
  13426. params.total(page.totalElement);
  13427. $scope.total = page.totalElement;
  13428. $defer.resolve(page.content);
  13429. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13430. }
  13431. }, function (response) {
  13432. $scope.loading = false;
  13433. toaster.pop('error', '数据加载失败', response.data);
  13434. });
  13435. }
  13436. });
  13437. /**
  13438. * 选中单个物料购买
  13439. * @param businessCode
  13440. * @param id
  13441. */
  13442. $scope.PurcByEnAndProd = function (businessCode, id) {
  13443. $rootScope.businessCode = businessCode;
  13444. $rootScope.prodId = id;
  13445. window.location.hash = "#/purc/addOrder";
  13446. }
  13447. /**
  13448. * 询价
  13449. */
  13450. $scope.PurcInquiry = function (businessCode, id) {
  13451. $rootScope.prodId = id;
  13452. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  13453. }
  13454. }]);
  13455. /**
  13456. * 编辑供应商联系人
  13457. */
  13458. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function ($scope, toaster, $modalInstance, contact) {
  13459. $scope.contact = angular.copy(contact);
  13460. $scope.save = function (contact) {
  13461. $modalInstance.close(contact);
  13462. };
  13463. $scope.cancel = function () {
  13464. $modalInstance.dismiss();
  13465. }
  13466. }]);
  13467. /**
  13468. * 新增供应商联系人
  13469. */
  13470. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function ($scope, toaster, $modalInstance) {
  13471. $scope.save = function (contact) {
  13472. $modalInstance.close(contact);
  13473. };
  13474. $scope.cancel = function () {
  13475. $modalInstance.dismiss();
  13476. }
  13477. }]);
  13478. /**
  13479. * 建立合作关系申请 (我的合作伙伴)
  13480. */
  13481. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  13482. BaseService.scrollBackToTop();
  13483. $scope.status = "partner";
  13484. $scope.active = 'done';
  13485. var getRequestStatus = function (active) {
  13486. var fn = 'getAllRequest';
  13487. switch (active) {
  13488. case 'done':
  13489. fn = 'getRequestDone';
  13490. break;
  13491. case 'todo':
  13492. fn = 'getRequestTodo';
  13493. break;
  13494. case 'end':
  13495. fn = 'getRequestEnd';
  13496. break;
  13497. }
  13498. return fn;
  13499. }
  13500. // 切换单据类型
  13501. $scope.setActive = function (state) {
  13502. if ($scope.active != state) {
  13503. $scope.active = state;
  13504. if ($scope.tableParams.page() == 1)
  13505. $scope.tableParams.reload();
  13506. else
  13507. $scope.tableParams.page(1);
  13508. }
  13509. };
  13510. // 切换数据来源(正常数据 or 历史数据)
  13511. var getService = function () {
  13512. return AddPartnerMyRequest;
  13513. };
  13514. $scope.tableParams = new ngTableParams({ // ng-Table参数
  13515. page: 1,
  13516. count: 20,
  13517. sorting: {}
  13518. }, {
  13519. total: 0,
  13520. counts: [],
  13521. getData: function ($defer, params) { // 获取数据的方法
  13522. $scope.loading = true;
  13523. var pageParams = params.url();
  13524. pageParams.keyword = $scope.keyword;
  13525. if ($rootScope.vendName) {
  13526. pageParams.keyword = $rootScope.vendName;
  13527. $scope.keyword = $rootScope.vendName;
  13528. $rootScope.vendName = null;
  13529. }
  13530. $scope.tip = $scope.keyword;
  13531. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  13532. $scope.loading = false;
  13533. if (page) {
  13534. params.total(page.totalElement);
  13535. $defer.resolve(page.content);
  13536. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13537. }
  13538. }, function (response) {
  13539. $scope.loading = false;
  13540. toaster.pop('error', '数据加载失败', response.data);
  13541. });
  13542. }
  13543. });
  13544. // 再次申请
  13545. $scope.addAgain = function (name, businessCode) {
  13546. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  13547. if (data.success) {
  13548. toaster.pop("success", '添加成功', data.success);
  13549. $scope.tableParams.reload();
  13550. }
  13551. if (data.error) {
  13552. toaster.pop("error", '添加失败', data.error);
  13553. }
  13554. }, function (response) {
  13555. toaster.pop('error', '失败', response.data);
  13556. });
  13557. }
  13558. // 添加为供应商
  13559. $scope.addSupplier = function (vendUID) {
  13560. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  13561. if (data.success) {
  13562. toaster.pop('success', '提示', data.success);
  13563. $scope.tableParams.reload();
  13564. }
  13565. if (data.error) {
  13566. toaster.pop('error', '提示', data.error);
  13567. }
  13568. }, function (response) {
  13569. toaster.pop('error', '失败', response.data);
  13570. })
  13571. };
  13572. // 添加为供应商
  13573. $scope.addServicer = function (vendUID) {
  13574. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  13575. if (data.success) {
  13576. toaster.pop('success', '提示', data.success);
  13577. $scope.tableParams.reload();
  13578. }
  13579. if (data.error) {
  13580. toaster.pop('error', '提示', data.error);
  13581. }
  13582. }, function (response) {
  13583. toaster.pop('error', '失败', response.data);
  13584. })
  13585. };
  13586. // 添加客户
  13587. $scope.addCust = function (vendUID) {
  13588. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  13589. if (data.success) {
  13590. toaster.pop('success', '提示', data.success);
  13591. $scope.tableParams.reload();
  13592. }
  13593. if (data.error) {
  13594. toaster.pop('error', '提示', data.error);
  13595. }
  13596. }, function (response) {
  13597. toaster.pop('error', '失败', response.data);
  13598. })
  13599. };
  13600. // 搜索框回车
  13601. $scope.onSearch = function () {
  13602. $scope.tableParams.page(1);
  13603. $scope.tableParams.reload();
  13604. };
  13605. // 同意申请
  13606. $scope.agree = function (id) {
  13607. AddPartner.agreeRequest({id: id}, {}, function (data) {
  13608. if (data.success) {
  13609. toaster.pop('success', '提示', '操作成功');
  13610. }
  13611. if (data.error) {
  13612. toaster.pop('error', '提示', '操作失败');
  13613. }
  13614. // $scope.tableParams.reload();
  13615. $window.location.reload();
  13616. }, function (response) {
  13617. toaster.pop('error', '提示', response.data);
  13618. });
  13619. };
  13620. // 拒绝申请
  13621. $scope.refuse = function (id, reason) {
  13622. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  13623. if (data.success) {
  13624. toaster.pop('success', '提示', '操作成功');
  13625. }
  13626. if (data.error) {
  13627. toaster.pop('error', '提示', '操作失败');
  13628. }
  13629. // $scope.tableParams.reload();
  13630. $window.location.reload();
  13631. }, function (response) {
  13632. toaster.pop('error', '提示', response.data);
  13633. });
  13634. };
  13635. // 取消供应商关系
  13636. $scope.relieve = function (id) {
  13637. VendorInfo.relieve({id: id}, {}, function (data) {
  13638. if (data.success) {
  13639. toaster.pop('success', '提示', data.success);
  13640. }
  13641. // $scope.tableParams.page(1);
  13642. $scope.tableParams.reload();
  13643. }, function (response) {
  13644. toaster.pop('error', '提示', response.data);
  13645. });
  13646. };
  13647. // 建立供应商关系
  13648. $scope.activeVend = function (id) {
  13649. VendorInfo.activeVend({id: id}, {}, function (data) {
  13650. if (data.success) {
  13651. toaster.pop('success', '提示', data.success);
  13652. }
  13653. // $scope.tableParams.page(1);
  13654. $scope.tableParams.reload();
  13655. }, function (response) {
  13656. toaster.pop('error', '提示', response.data);
  13657. });
  13658. };
  13659. // 取消服务商
  13660. $scope.relieveServicer = function (id) {
  13661. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  13662. if (data.success) {
  13663. toaster.pop('success', '提示', data.success);
  13664. }
  13665. $scope.tableParams.reload();
  13666. }, function (response) {
  13667. toaster.pop('error', '提示', response.data);
  13668. });
  13669. };
  13670. // 启用服务商
  13671. $scope.activeServicer = function (id) {
  13672. VendorInfo.activeServicer({id: id}, {}, function (data) {
  13673. if (data.success) {
  13674. toaster.pop('success', '提示', data.success);
  13675. }
  13676. $scope.tableParams.reload();
  13677. }, function (response) {
  13678. toaster.pop('error', '提示', response.data);
  13679. });
  13680. };
  13681. // 取消客户关系
  13682. $scope.disableCust = function (id) {
  13683. VendorInfo.disableCust({id: id}, {}, function (data) {
  13684. if (data.success) {
  13685. toaster.pop('success', '提示', data.success);
  13686. }
  13687. $scope.tableParams.page(1);
  13688. $scope.tableParams.reload();
  13689. }, function (response) {
  13690. toaster.pop('error', '提示', response.data);
  13691. });
  13692. };
  13693. // 激活客户关系
  13694. $scope.activeCust = function (id) {
  13695. VendorInfo.activeCust({id: id}, {}, function (data) {
  13696. if (data.success) {
  13697. toaster.pop('success', '提示', data.success);
  13698. }
  13699. $scope.tableParams.page(1);
  13700. $scope.tableParams.reload();
  13701. }, function (response) {
  13702. toaster.pop('error', '提示', response.data);
  13703. });
  13704. }
  13705. }]);
  13706. /**
  13707. * 建立合作关系申请 (新的合作伙伴)
  13708. */
  13709. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', '$modal',
  13710. function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window, $modal) {
  13711. BaseService.scrollBackToTop();
  13712. $scope.status = "partner";
  13713. $scope.active = 'all'; // 所有申请记录
  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. if (data.result) {
  13840. //选择打印模板
  13841. var modalInstance = $modal.open({
  13842. templateUrl: 'static/tpl/index/baseInfo/modal/partnership_modal.html',
  13843. controller: 'PartnerShipCtrl',
  13844. resolve: {
  13845. PartnerShipInfo: function () {
  13846. return data.result;
  13847. }
  13848. }
  13849. });
  13850. modalInstance.result.then(function () {
  13851. window.location.reload();
  13852. });
  13853. }
  13854. }
  13855. if (data.error) {
  13856. toaster.pop('error', '提示', '操作失败');
  13857. }
  13858. }, function (response) {
  13859. toaster.pop('error', '提示', response.data);
  13860. });
  13861. };
  13862. AddPartnerMyRequest.requestAmount({}, function (data) {
  13863. $scope.requestTodo = data;
  13864. });
  13865. // 拒绝申请
  13866. $scope.refuse = function (id, reason) {
  13867. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  13868. if (data.success) {
  13869. toaster.pop('success', '提示', '操作成功');
  13870. }
  13871. if (data.error) {
  13872. toaster.pop('error', '提示', '操作失败');
  13873. }
  13874. // $scope.tableParams.reload();
  13875. $window.location.reload();
  13876. }, function (response) {
  13877. toaster.pop('error', '提示', response.data);
  13878. });
  13879. };
  13880. // 取消供应商关系
  13881. $scope.relieve = function (id) {
  13882. VendorInfo.relieve({id: id}, {}, function (data) {
  13883. if (data.success) {
  13884. toaster.pop('success', '提示', data.success);
  13885. }
  13886. // $scope.tableParams.page(1);
  13887. $scope.tableParams.reload();
  13888. }, function (response) {
  13889. toaster.pop('error', '提示', response.data);
  13890. });
  13891. }
  13892. // 建立供应商关系
  13893. $scope.activeVend = function (id) {
  13894. VendorInfo.activeVend({id: id}, {}, function (data) {
  13895. if (data.success) {
  13896. toaster.pop('success', '提示', data.success);
  13897. }
  13898. // $scope.tableParams.page(1);
  13899. $scope.tableParams.reload();
  13900. }, function (response) {
  13901. toaster.pop('error', '提示', response.data);
  13902. });
  13903. }
  13904. // 取消服务商
  13905. $scope.relieveServicer = function (id) {
  13906. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  13907. if (data.success) {
  13908. toaster.pop('success', '提示', data.success);
  13909. }
  13910. $scope.tableParams.reload();
  13911. }, function (response) {
  13912. toaster.pop('error', '提示', response.data);
  13913. });
  13914. }
  13915. // 启用服务商
  13916. $scope.activeServicer = function (id) {
  13917. VendorInfo.activeServicer({id: id}, {}, function (data) {
  13918. if (data.success) {
  13919. toaster.pop('success', '提示', data.success);
  13920. }
  13921. $scope.tableParams.reload();
  13922. }, function (response) {
  13923. toaster.pop('error', '提示', response.data);
  13924. });
  13925. }
  13926. // 取消客户关系
  13927. $scope.disableCust = function (id) {
  13928. VendorInfo.disableCust({id: id}, {}, function (data) {
  13929. if (data.success) {
  13930. toaster.pop('success', '提示', data.success);
  13931. }
  13932. // $scope.tableParams.page(1);
  13933. $scope.tableParams.reload();
  13934. }, function (response) {
  13935. toaster.pop('error', '提示', response.data);
  13936. });
  13937. }
  13938. // 激活客户关系
  13939. $scope.activeCust = function (id) {
  13940. VendorInfo.activeCust({id: id}, {}, function (data) {
  13941. if (data.success) {
  13942. toaster.pop('success', '提示', data.success);
  13943. }
  13944. $scope.tableParams.reload();
  13945. }, function (response) {
  13946. toaster.pop('error', '提示', response.data);
  13947. });
  13948. }
  13949. }]);
  13950. /**
  13951. * 同意申请后续操作
  13952. */
  13953. app.controller('PartnerShipCtrl', ['$scope', 'PartnerShipInfo', '$modalInstance', 'AddPartner', 'toaster',
  13954. function($scope, PartnerShipInfo, $modalInstance, AddPartner, toaster) {
  13955. $scope.partInfo = PartnerShipInfo;
  13956. // 添加为服务商
  13957. $scope.addServicer = function (vendUID) {
  13958. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  13959. if (data.success) {
  13960. toaster.pop('success', '提示', data.success);
  13961. $scope.tableParams.reload();
  13962. }
  13963. if (data.error) {
  13964. toaster.pop('error', '提示', data.error);
  13965. }
  13966. }, function (response) {
  13967. toaster.pop('error', '失败', response.data);
  13968. })
  13969. };
  13970. // 添加客户
  13971. $scope.addCust = function (vendUID) {
  13972. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  13973. if (data.success) {
  13974. toaster.pop('success', '提示', data.success);
  13975. $scope.tableParams.reload();
  13976. }
  13977. if (data.error) {
  13978. toaster.pop('error', '提示', data.error);
  13979. }
  13980. }, function (response) {
  13981. toaster.pop('error', '失败', response.data);
  13982. })
  13983. };
  13984. // 添加为供应商
  13985. $scope.addSupplier = function (vendUID) {
  13986. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  13987. if (data.success) {
  13988. toaster.pop('success', '提示', data.success);
  13989. $scope.tableParams.reload();
  13990. }
  13991. if (data.error) {
  13992. toaster.pop('error', '提示', data.error);
  13993. }
  13994. }, function (response) {
  13995. toaster.pop('error', '失败', response.data);
  13996. })
  13997. };
  13998. // 关闭
  13999. $scope.close = function() {
  14000. $modalInstance.close();
  14001. }
  14002. }]);
  14003. /**
  14004. * 建立合作关系处理申请
  14005. */
  14006. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', '$window', function ($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest, $window) {
  14007. BaseService.scrollBackToTop();
  14008. $scope.active = 'todo';
  14009. var getMessagetStatus = function (active) {
  14010. var fn = 'getAllMessage';
  14011. switch (active) {
  14012. case 'done':
  14013. fn = 'getMessageDone';
  14014. break;
  14015. case 'todo':
  14016. fn = 'getMessageTodo';
  14017. break;
  14018. case 'end':
  14019. fn = 'getMessageEnd';
  14020. break;
  14021. }
  14022. return fn;
  14023. }
  14024. // 切换单据类型
  14025. $scope.setActive = function (state) {
  14026. if ($scope.active != state) {
  14027. $scope.active = state;
  14028. if ($scope.tableParams.page() == 1)
  14029. $scope.tableParams.reload();
  14030. else
  14031. $scope.tableParams.page(1);
  14032. }
  14033. };
  14034. var getService = function () {
  14035. return AddPartnerMyMessage;
  14036. };
  14037. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14038. page: 1,
  14039. count: 20,
  14040. sorting: {}
  14041. }, {
  14042. total: 0,
  14043. counts: [5, 10, 15, 25, 50],
  14044. getData: function ($defer, params) { // 获取数据的方法
  14045. $scope.loading = true;
  14046. var pageParams = params.url();
  14047. pageParams.searchFilter = { // 筛选条件
  14048. keyword: $scope.keyword,
  14049. };
  14050. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14051. $scope.loading = false;
  14052. if (page) {
  14053. params.total(page.totalElement);
  14054. $defer.resolve(page.content);
  14055. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14056. }
  14057. }, function (response) {
  14058. $scope.loading = false;
  14059. toaster.pop('error', '数据加载失败', response.data);
  14060. });
  14061. }
  14062. });
  14063. // 同意申请
  14064. $scope.agree = function (id) {
  14065. AddPartner.agreeReq
  14066. uest({id: id}, {}, function (data) {
  14067. if (data.success) {
  14068. toaster.pop('success', '提示', '操作成功');
  14069. }
  14070. if (data.error) {
  14071. toaster.pop('error', '提示', '操作失败');
  14072. }
  14073. // $scope.tableParams.reload();
  14074. $window.location.reload();
  14075. }, function (response) {
  14076. toaster.pop('error', '提示', response.data);
  14077. });
  14078. };
  14079. // 拒绝申请
  14080. $scope.refuse = function (id, reason) {
  14081. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14082. if (data.success) {
  14083. toaster.pop('success', '提示', '操作成功');
  14084. }
  14085. if (data.error) {
  14086. toaster.pop('error', '提示', '操作失败');
  14087. }
  14088. // $scope.tableParams.reload();
  14089. $window.location.reload();
  14090. }, function (response) {
  14091. toaster.pop('error', '提示', response.data);
  14092. });
  14093. };
  14094. $scope.status = 'get';
  14095. }]);
  14096. /**
  14097. * 我的合作伙伴
  14098. */
  14099. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function ($scope, toaster, GetProductInfo, BaseService) {
  14100. BaseService.scrollBackToTop();
  14101. // 默认显示合作伙伴
  14102. $scope.status = 'news';
  14103. // 获取所有的合作伙伴
  14104. GetProductInfo.getAllPartners({}, function (data) {
  14105. $scope.partners = data;
  14106. }, function (res) {
  14107. toaster.pop('error', '获取列表失败', res.data);
  14108. });
  14109. // 添加为客户
  14110. $scope.addCust = function (partner) {
  14111. GetProductInfo.addCust({}, partner, function (data) {
  14112. toaster.pop('success', '提示', '添加客户成功');
  14113. $scope.tableParams.reload();
  14114. }, function (response) {
  14115. toaster.pop('error', '添加客户失败', response.data);
  14116. });
  14117. }
  14118. // 添加为供应商
  14119. $scope.addSupplier = function (partner) {
  14120. GetProductInfo.addSupplier({}, partner, function (data) {
  14121. toaster.pop('success', '提示', '添加供应商成功');
  14122. $scope.tableParams.reload();
  14123. }, function (response) {
  14124. toaster.pop('error', '添加供应商失败', response.data);
  14125. });
  14126. }
  14127. }]);
  14128. /**
  14129. * 财务对账时,企业进行筛选操作
  14130. */
  14131. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', 'VendorService', 'ngTableParams', 'BaseService', function ($scope, $modalInstance, suuorname, FaApCheck, VendorService, ngTableParams, BaseService) {
  14132. var getData = function () {
  14133. $scope.loading = true;
  14134. FaApCheck.getAllCustomers(function (data) {
  14135. $scope.custs = data;
  14136. $scope.loading = false;
  14137. });
  14138. };
  14139. getData();
  14140. $scope.customerParams = new ngTableParams({
  14141. page: 1,
  14142. count: 20
  14143. }, {
  14144. total: 0,
  14145. counts: [5, 10, 25, 50],
  14146. getData: function ($defer, params) {
  14147. $scope.loading = true;
  14148. var pageParams = params.url();
  14149. pageParams.keyword = $scope.keyword;
  14150. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  14151. $scope.loading = false;
  14152. if (page) {
  14153. params.total(page.totalElement);
  14154. $defer.resolve(page.content);
  14155. }
  14156. $scope.totalCount = page.totalElement;
  14157. }, function (response) {
  14158. $scope.loading = false;
  14159. toaster.pop('error', '数据加载失败', response.data);
  14160. });
  14161. }
  14162. });
  14163. // 搜索框回车
  14164. $scope.onSearch = function (keyword) {
  14165. $scope.customerParams.page(1);
  14166. $scope.customerParams.reload();
  14167. $scope.tip = keyword;
  14168. };
  14169. $scope.select = function (customer) {
  14170. if (customer.apcheck != 0) {
  14171. $modalInstance.close(customer);
  14172. }
  14173. }
  14174. $scope.close = function () {
  14175. $modalInstance.dismiss();
  14176. }
  14177. }]);
  14178. /**
  14179. * 跳转到企业圈
  14180. */
  14181. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function ($scope, GetProductInfo, toaster) {
  14182. GetProductInfo.businessGroups({}, function (data) {
  14183. window.open(data.url);
  14184. }, function (response) {
  14185. toaster.pop('error', '提示', response.data);
  14186. });
  14187. }]);
  14188. /**
  14189. * 购物车
  14190. */
  14191. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', 'cartList', 'PurchaseOrder', function ($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout, cartList, PurchaseOrder) {
  14192. BaseService.scrollBackToTop();
  14193. $scope.active = 'all';
  14194. $scope.agreedText = '全部';
  14195. $scope.dateZoneText = '一个月内';
  14196. $scope.condition = {dateZone: 1};
  14197. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14198. $scope.hasClick = false;
  14199. /* 时间筛选初始化*/
  14200. var fromDate = new Date();
  14201. var toDate = new Date();
  14202. fromDate.setMonth(fromDate.getMonth() - 1);
  14203. fromDate.setHours(0, 0, 0, 0);
  14204. toDate.setHours(23, 59, 59, 999);
  14205. $scope.condition.dateFrom = fromDate;
  14206. $scope.condition.dateTo = toDate;
  14207. $scope.changeDateZone = function (zone) {
  14208. $scope.condition.dateZone = zone;
  14209. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14210. $scope.condition.$dateZoneOpen = false;
  14211. getDateCondition(zone, $scope.condition);
  14212. $scope.tableParams.page(1);
  14213. $scope.tableParams.reload();
  14214. };
  14215. $scope.changeDeliveryZone = function (zone) {
  14216. $scope.condition.deliveryZoneText = zone;
  14217. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  14218. $scope.condition.$delievryZoneOpen = false;
  14219. getDelveryCondition(zone, $scope.condition);
  14220. $scope.tableParams.reload();
  14221. };
  14222. $scope.openDatePicker = function ($event, item, openParam) {
  14223. $event.preventDefault();
  14224. $event.stopPropagation();
  14225. item[openParam] = !item[openParam];
  14226. };
  14227. $scope.openFilterDatePicker = function ($event, item, openParam) {
  14228. $event.preventDefault();
  14229. $event.stopPropagation();
  14230. item[openParam] = !item[openParam];
  14231. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  14232. $scope.tableParams.reload();
  14233. }
  14234. };
  14235. $scope.parseDate = function (dateStr) {
  14236. if (dateStr)
  14237. return Date.parse(dateStr, 'yyyy-MM-dd');
  14238. return new Date();
  14239. };
  14240. $scope.setActive = function (state) {
  14241. if ($scope.active != state) {
  14242. $scope.active = state;
  14243. if ($scope.tableParams.page() == 1)
  14244. $scope.tableParams.reload();
  14245. else
  14246. $scope.tableParams.page(1);
  14247. }
  14248. };
  14249. $scope.searchMethod = false;
  14250. var getService = function () {
  14251. return $scope.searchMethod ? cartList : getCartList;
  14252. };
  14253. var getTodoCartCount = function () {
  14254. cartOperation.getTodoCartCount({}, function (data) {
  14255. $scope.countTodo = data.cartTodo;
  14256. });
  14257. };
  14258. getTodoCartCount();
  14259. $scope.tableParams = new ngTableParams({
  14260. page: 1,
  14261. count: 20,
  14262. sorting: {
  14263. date: 'desc'
  14264. }
  14265. }, {
  14266. total: 0,
  14267. counts: [5, 10, 25, 50],
  14268. getData: function ($defer, params) {
  14269. $scope.loading = true;
  14270. var pageParams = params.url();
  14271. pageParams.searchFilter = { // 筛选条件
  14272. keyword: $scope.keyword,
  14273. fromDate: getDateTime($scope.condition.dateFrom),
  14274. endDate: getDateTime($scope.condition.dateTo)
  14275. };
  14276. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14277. $scope.loading = false;
  14278. if (page) {
  14279. params.total(page.totalElement);
  14280. $defer.resolve(page.content);
  14281. }
  14282. }, function (response) {
  14283. $scope.loading = false;
  14284. toaster.pop('error', '数据加载失败', response.data);
  14285. });
  14286. }
  14287. });
  14288. $scope.getCartTotal = function (items) {
  14289. var sum = 0;
  14290. angular.forEach(items, function (item) {
  14291. sum += item.qty * item.price;
  14292. });
  14293. return sum;
  14294. };
  14295. // 搜索框回车
  14296. $scope.onSearch = function (keyword) {
  14297. // 每次搜索重置获取数据方法
  14298. $scope.searchMethod = false;
  14299. if(keyword != null && keyword != '') {
  14300. $scope.searchMethod = true;
  14301. }
  14302. $scope.tableParams.page(1);
  14303. $scope.tableParams.reload();
  14304. };
  14305. var changeClickStatus = function () {
  14306. $scope.hasClick = true;
  14307. $timeout(function () {
  14308. $scope.hasClick = false;
  14309. }, 500);
  14310. }
  14311. // 提交
  14312. $scope.addtoOrder = function (id) {
  14313. cartOperation.addToOrder({id: id}, {}, function (data) {
  14314. if (data.success) {
  14315. toaster.pop('success', '提示', data.success);
  14316. getTodoCartCount();
  14317. $timeout(function () {
  14318. window.location.hash = '#/purc/order/' + data.id;
  14319. window.location.reload();
  14320. }, 500);
  14321. }
  14322. if (data.error) {
  14323. toaster.pop('error', '提示', data.error);
  14324. }
  14325. }, function (response) {
  14326. toaster.pop('erroer', '提示', response.data);
  14327. });
  14328. };
  14329. // 删除一条主记录
  14330. $scope.deleteCart = function (id) {
  14331. changeClickStatus();
  14332. $scope.loading = true;
  14333. cartOperation.deleteCart({id: id}, {}, function (data) {
  14334. if (data.success) {
  14335. toaster.pop('success', '提示', data.success);
  14336. getTodoCartCount();
  14337. getTodoCartCount();
  14338. $timeout(function () {
  14339. $scope.tableParams.page(1);
  14340. $scope.tableParams.reload();
  14341. }, 500);
  14342. }
  14343. if (data.error) {
  14344. toaster.pop('error', '提示', data.error);
  14345. }
  14346. $scope.loading = false;
  14347. }, function (response) {
  14348. $scope.loading = false;
  14349. toaster.pop('erroer', '提示', response.data);
  14350. });
  14351. };
  14352. // 删除一条明细
  14353. $scope.deleteDetail = function (id) {
  14354. changeClickStatus();
  14355. $scope.loading = true;
  14356. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14357. if (data.success) {
  14358. toaster.pop('success', '提示', data.success);
  14359. $timeout(function () {
  14360. $scope.tableParams.reload();
  14361. }, 500);
  14362. }
  14363. if (data.error) {
  14364. toaster.pop('error', '提示', data.error);
  14365. }
  14366. $scope.loading = false;
  14367. }, function (response) {
  14368. toaster.pop('erroer', '提示', response.data);
  14369. $scope.loading = false;
  14370. });
  14371. };
  14372. // 清空购物车
  14373. $scope.clearCart = function () {
  14374. changeClickStatus();
  14375. $scope.loading = true;
  14376. cartOperation.deleteCarts({}, function (data) {
  14377. if (data.success) {
  14378. toaster.pop('success', '提示', data.success);
  14379. getTodoCartCount();
  14380. $timeout(function () {
  14381. $scope.tableParams.reload();
  14382. }, 500);
  14383. }
  14384. if (data.error) {
  14385. toaster.pop('error', '提示', data.error);
  14386. }
  14387. $scope.loading = false;
  14388. }, function (response) {
  14389. toaster.pop('erroer', '提示', response.data);
  14390. $scope.loading = false;
  14391. });
  14392. }
  14393. // 复制订单
  14394. $scope.copyorder = function (id) {
  14395. changeClickStatus();
  14396. $scope.loading = true;
  14397. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  14398. if (data.id) {
  14399. toaster.pop('success', '提示', '单据复制成功');
  14400. getTodoCartCount();
  14401. $scope.loading = false;
  14402. window.location.hash = "#purc/cart/" + data.id;
  14403. }
  14404. }, function (response) {
  14405. toaster.pop('error', '提示', response.data);
  14406. $scope.loading = false;
  14407. });
  14408. }
  14409. }]);
  14410. /**
  14411. * 购物车详情
  14412. */
  14413. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', 'recentPrice',
  14414. function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token, recentPrice) {
  14415. BaseService.scrollBackToTop();
  14416. $scope.loading = true;
  14417. var loadData = function () {
  14418. cartOperation.getCartDetail({id: $stateParams.id}, function (data) {
  14419. if (data.code) {
  14420. $scope.order = data;
  14421. var sum = 0;
  14422. angular.forEach($scope.order.orderItems, function (item) {
  14423. sum += item.qty * item.price;
  14424. });
  14425. $scope.order.total = sum;
  14426. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  14427. $scope.contacts = data;
  14428. $scope.order.vendor = $scope.order.venduser;
  14429. });
  14430. $scope.loading = false;
  14431. } else {
  14432. window.location.hash = '#/purc/cart';
  14433. }
  14434. });
  14435. };
  14436. loadData();
  14437. var getToken = function() {
  14438. token.info({userType: 'cart'}, {}, function(data) {
  14439. $scope.token = data.token;
  14440. }, function(response) {
  14441. toaster.pop('error', '提示', response.data);
  14442. });
  14443. }
  14444. getToken();
  14445. // 获取地址信息
  14446. $http.get('resources/citydata/city.json', {
  14447. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  14448. }).then(function (response) {
  14449. $scope.provinces = response.data;
  14450. });
  14451. // 获取收货地址列表
  14452. ShipAddress.shipAddList({}, function (data) {
  14453. $scope.ships = data;
  14454. $scope.order.shipadd = $scope.ships[0];
  14455. });
  14456. //增加商品
  14457. $scope.addProduct = function (index) {
  14458. if ($scope.order.orderItems[index].code == null) {
  14459. toaster.pop('info', '提示', '请先选择商品');
  14460. } else {
  14461. $scope.order.orderItems.push({
  14462. code: null,
  14463. title: null,
  14464. spec: null,
  14465. unit: null,
  14466. qty: null,
  14467. price: null,
  14468. remark: null,
  14469. delivery: null,
  14470. $endDateOpen: false,
  14471. taxrate: $scope.order.rate
  14472. });
  14473. }
  14474. };
  14475. //删除商品
  14476. $scope.deleteProduct = function (index, id) {
  14477. $scope.order.orderItems.splice(index, 1);
  14478. if (id != null) {
  14479. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14480. if (data.success) {
  14481. loadData();
  14482. }
  14483. if (data.error) {
  14484. toaster.pop('error', '提示', data.error);
  14485. }
  14486. }, function (response) {
  14487. toaster.pop('erroer', '提示', response.data);
  14488. });
  14489. }
  14490. };
  14491. // 搜索框回车
  14492. $scope.onSearch = function (keyword) {
  14493. $scope.keyword = keyword;
  14494. $scope.tableParams.page(1);
  14495. $scope.tableParams.reload();
  14496. };
  14497. $scope.tableParams = new ngTableParams({
  14498. page: 1,
  14499. count: 20
  14500. }, {
  14501. total: 0,
  14502. counts: [5, 10, 25, 50],
  14503. getData: function ($defer, params) {
  14504. $scope.loading = true;
  14505. var pageParams = params.url();
  14506. pageParams.keyword = $scope.keyword;
  14507. $scope.tip = $scope.keyword;
  14508. pageParams.vendUU = $scope.order.receiveCode;
  14509. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  14510. $scope.loading = false;
  14511. if (page) {
  14512. params.total(page.totalElement);
  14513. $scope.total = page.totalElement;
  14514. $defer.resolve(page.content);
  14515. }
  14516. }, function (response) {
  14517. $scope.loading = false;
  14518. toaster.pop('error', '数据加载失败', response.data);
  14519. });
  14520. }
  14521. });
  14522. // 选择
  14523. $scope.check = function (data) {
  14524. var price = null;
  14525. var qty = null;
  14526. var taxRate = null;
  14527. if (data.id) {
  14528. recentPrice.agreed({prId: data.id}, {}, function(response) {
  14529. price = response.price;
  14530. qty = response.qty;
  14531. taxRate = response.taxRate;
  14532. $scope.order.orderItems.push({
  14533. code: data.code,
  14534. title: data.title,
  14535. spec: data.spec,
  14536. unit: data.unit,
  14537. qty: qty,
  14538. price: price,
  14539. remark: null,
  14540. delivery: null,
  14541. prid: data.id,
  14542. taxrate: taxRate,
  14543. prodsource: 'seller',
  14544. });
  14545. });
  14546. }
  14547. };
  14548. // 导入商品信息
  14549. $scope.uplodaByBatch = function () {
  14550. var modalInstance = $modal.open({
  14551. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  14552. controller: 'PurcUploadByBatchCtrl',
  14553. size: 'lg',
  14554. resolve: {}
  14555. });
  14556. modalInstance.result.then(function (data) {
  14557. angular.forEach(data, function (prod) {
  14558. $scope.order.orderItems.push({
  14559. code: prod.code,
  14560. title: data.title,
  14561. unit: 'PCS',
  14562. spec: prod.spec,
  14563. qty: prod.amount,
  14564. price: prod.rateprice,
  14565. remark: prod.remark,
  14566. delivery: prod.date,
  14567. prid: prod.id,
  14568. taxrate: prod.rate
  14569. });
  14570. })
  14571. }, function () {
  14572. });
  14573. }
  14574. // 删除一条主记录
  14575. $scope.deleteCart = function (id) {
  14576. cartOperation.deleteCart({id: id}, {}, function (data) {
  14577. if (data.success) {
  14578. toaster.pop('success', '提示', data.success);
  14579. $timeout(function () {
  14580. window.location.reload();
  14581. }, 500);
  14582. }
  14583. if (data.error) {
  14584. toaster.pop('error', '提示', data.error);
  14585. }
  14586. }, function (response) {
  14587. toaster.pop('erroer', '提示', response.data);
  14588. });
  14589. };
  14590. $scope.getMinDate = function (item) {
  14591. return $filter('date')(new Date, 'yyyy-MM-dd');
  14592. };
  14593. $scope.openDatePicker = function ($event, openParam, index) {
  14594. $event.preventDefault();
  14595. $event.stopPropagation();
  14596. $scope.order.orderItems[index].$endDateOpen = !openParam;
  14597. };
  14598. // 添加到购物车
  14599. $scope.addToCart = function (order) {
  14600. $scope.loading = true;
  14601. if (order.vendor.tel != null) {
  14602. $scope.order.vendusertel = order.vendor.tel;
  14603. }
  14604. if (order.vendor.venduser != null && order.vendor.tel != null) {
  14605. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  14606. }
  14607. if (order.shipadd != null) {
  14608. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  14609. }
  14610. if ($scope.order.date instanceof Date) {
  14611. $scope.order.date = $scope.order.date.getTime();
  14612. }
  14613. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  14614. if ($scope.order.orderItems[i].delivery instanceof Date) {
  14615. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  14616. }
  14617. if ($scope.order.currency != 'RMB') {
  14618. $scope.order.orderItems[i].rate = 0;
  14619. }
  14620. }
  14621. $scope.order.status = 311;
  14622. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  14623. $scope.loading = false;
  14624. toaster.pop('success', '成功', '保存成功');
  14625. loadData();
  14626. }, function (response) {
  14627. $scope.loading = false;
  14628. toaster.pop('error', '保存失败', response.data);
  14629. });
  14630. };
  14631. // 立即购买
  14632. $scope.addToOrder = function (order) {
  14633. $scope.loading = true;
  14634. if (order.vendor.tel != null) {
  14635. $scope.order.vendusertel = order.vendor.tel;
  14636. }
  14637. if (order.vendor.venduser != null && order.vendor.tel != null) {
  14638. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  14639. }
  14640. if (order.shipadd != null) {
  14641. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  14642. }
  14643. if ($scope.order.date instanceof Date) {
  14644. $scope.order.date = $scope.order.date.getTime();
  14645. }
  14646. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  14647. if ($scope.order.orderItems[i].delivery instanceof Date) {
  14648. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  14649. }
  14650. if ($scope.order.currency != 'RMB') {
  14651. $scope.order.orderItems[i].rate = 0;
  14652. }
  14653. }
  14654. $scope.order.status = 200;
  14655. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  14656. $scope.loading = false;
  14657. toaster.pop('success', '成功', '保存成功');
  14658. window.location.hash = '#/purc/order/' + data.id;
  14659. }, function (response) {
  14660. $scope.loading = false;
  14661. toaster.pop('error', '保存失败', response.data);
  14662. });
  14663. };
  14664. // 新增收货地址保存
  14665. $scope.saveShipAddress = function (ship) {
  14666. ship.address = ship.province + ship.city + ship.district;
  14667. ShipAddress.saveAddress({}, ship, function (data) {
  14668. if (data.success) {
  14669. ShipAddress.shipAddList({}, function (data) {
  14670. $scope.ships = data;
  14671. $scope.order.shipadd = $scope.ships[0];
  14672. });
  14673. toaster.pop('success', '提示', data.success);
  14674. }
  14675. if (data.error) {
  14676. toaster.pop('error', '提示', data.error);
  14677. }
  14678. });
  14679. }
  14680. // 新增供应商联系人
  14681. $scope.addContact = function (uu) {
  14682. var modalInstance = $modal.open({
  14683. animation: true,
  14684. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  14685. controller: 'AddContacCtrl',
  14686. resolve: {}
  14687. });
  14688. modalInstance.result.then(function (data) {
  14689. $scope.contact = data;
  14690. $scope.contact.venduu = $scope.order.receiveCode;
  14691. Vendor.saveContact({}, $scope.contact, function (data) {
  14692. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  14693. $scope.contacts = data;
  14694. });
  14695. toaster.pop('success', '提示', '联系人保存成功');
  14696. }, function (response) {
  14697. toaster.pop('error', '失败', response.data);
  14698. });
  14699. });
  14700. }
  14701. }]);
  14702. /**
  14703. * 审批流
  14704. */
  14705. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function ($scope, toaster, $modal, appFlow, BaseService) {
  14706. BaseService.scrollBackToTop();
  14707. $scope.vacation = false;
  14708. $scope.workovertime = false;
  14709. $scope.workdaily = false;
  14710. $scope.feeplease = false;
  14711. $scope.signapp = false;
  14712. appFlow.viewAppFlow({}, function (data) {// 获取已设置的列表
  14713. $scope.nodes = data;
  14714. angular.forEach($scope.nodes, function (node) {
  14715. if (node.appname = '请假单') {
  14716. $scope.vacation = true;
  14717. }
  14718. if (node.appname = '加班单') {
  14719. $scope.workovertime = true;
  14720. }
  14721. if (node.appname = '工作日报') {
  14722. $scope.workdaily = true;
  14723. }
  14724. if (node.appname = '出差单') {
  14725. $scope.feeplease = true;
  14726. }
  14727. if (node.appname = '申诉单') {
  14728. $scope.signapp = true;
  14729. }
  14730. });
  14731. }, function (response) {
  14732. });
  14733. $scope.NoteSet = function () {
  14734. var modalInstance = $modal.open({
  14735. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14736. controller: 'NoteStep1Ctrl',
  14737. size: 'lg',
  14738. resolve: {
  14739. AppName: function () {
  14740. return '请假单';
  14741. }
  14742. }
  14743. });
  14744. modalInstance.result.then(function (data) {
  14745. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14746. if (data.error) {
  14747. toaster.pop('error', '提示', data.error);
  14748. }
  14749. if (data.success) {
  14750. toaster.pop('success', '提示', data.success);
  14751. }
  14752. }, function (response) {
  14753. });
  14754. }, function () {
  14755. });
  14756. }
  14757. $scope.overTimeSet = function () {
  14758. var modalInstance = $modal.open({
  14759. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14760. controller: 'NoteStep1Ctrl',
  14761. size: 'lg',
  14762. resolve: {
  14763. AppName: function () {
  14764. return '加班单';
  14765. }
  14766. }
  14767. });
  14768. modalInstance.result.then(function (data) {
  14769. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14770. if (data.error) {
  14771. toaster.pop('error', '提示', data.error);
  14772. }
  14773. if (data.success) {
  14774. toaster.pop('success', '提示', data.success);
  14775. }
  14776. }, function (response) {
  14777. });
  14778. }, function () {
  14779. });
  14780. }
  14781. $scope.feePleaseSet = function () {
  14782. var modalInstance = $modal.open({
  14783. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14784. controller: 'NoteStep1Ctrl',
  14785. size: 'lg',
  14786. resolve: {
  14787. AppName: function () {
  14788. return '出差单';
  14789. }
  14790. }
  14791. });
  14792. modalInstance.result.then(function (data) {
  14793. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14794. if (data.error) {
  14795. toaster.pop('error', '提示', data.error);
  14796. }
  14797. if (data.success) {
  14798. toaster.pop('success', '提示', data.success);
  14799. }
  14800. }, function (response) {
  14801. });
  14802. }, function () {
  14803. });
  14804. }
  14805. $scope.workDailySet = function () {
  14806. var modalInstance = $modal.open({
  14807. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14808. controller: 'NoteStep1Ctrl',
  14809. size: 'lg',
  14810. resolve: {
  14811. AppName: function () {
  14812. return '工作日报';
  14813. }
  14814. }
  14815. });
  14816. modalInstance.result.then(function (data) {
  14817. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14818. if (data.error) {
  14819. toaster.pop('error', '提示', data.error);
  14820. }
  14821. if (data.success) {
  14822. toaster.pop('success', '提示', data.success);
  14823. }
  14824. }, function (response) {
  14825. });
  14826. }, function () {
  14827. });
  14828. }
  14829. $scope.signAppSet = function () {
  14830. var modalInstance = $modal.open({
  14831. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  14832. controller: 'NoteStep1Ctrl',
  14833. size: 'lg',
  14834. resolve: {
  14835. AppName: function () {
  14836. return '申诉单';
  14837. }
  14838. }
  14839. });
  14840. modalInstance.result.then(function (data) {
  14841. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  14842. if (data.error) {
  14843. toaster.pop('error', '提示', data.error);
  14844. }
  14845. if (data.success) {
  14846. toaster.pop('success', '提示', data.success);
  14847. }
  14848. }, function (response) {
  14849. });
  14850. }, function () {
  14851. });
  14852. }
  14853. }]);
  14854. /**
  14855. * 审核条件设置
  14856. */
  14857. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function ($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  14858. $scope.appName = AppName;// 标题名称
  14859. $scope.AppFlow = {
  14860. appName: $scope.appName,
  14861. appNodes: {}
  14862. };
  14863. $scope.AppFlow.appNodes = [];
  14864. appFlow.getNodeByName({name: AppName}, {}, function (data) {// 通过单据名称查询单个审批流
  14865. if (data.appNodes.length != 0) {
  14866. $scope.node = data;
  14867. $scope.AppFlow = data;
  14868. }
  14869. }, function () {
  14870. });
  14871. $scope.copy = function () {//复制
  14872. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  14873. toaster.pop('info', '提示', '复制成功');
  14874. $modalInstance.dismiss();
  14875. }
  14876. $scope.paste = function () {
  14877. $scope.AppFlow = {appName: $scope.appName, appNodes: {}};
  14878. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  14879. }
  14880. $scope.clear = function () {// 清空
  14881. $scope.AppFlow = {
  14882. appName: $scope.appName,
  14883. appNodes: {}
  14884. };
  14885. $scope.AppFlow.appNodes = [];
  14886. }
  14887. appFlow.getPositions({}, function (data) {// 获取人员信息
  14888. $scope.users = data;
  14889. }, function (response) {
  14890. });
  14891. appFlow.getPositionInfo({}, function (data) { // 获取职位信息
  14892. $scope.roles = data;
  14893. }, function (response) {
  14894. });
  14895. $scope.SelectUser = function (data) { // 添加人员
  14896. var item = {
  14897. useruu: null,
  14898. username: null,
  14899. level: null
  14900. };
  14901. item.useruu = data.useruu;
  14902. item.username = data.username;
  14903. $scope.AppFlow.appNodes.push(item);
  14904. }
  14905. $scope.SelectRole = function (data) {// 添加职位
  14906. var item = {
  14907. position: null,
  14908. level: null
  14909. };
  14910. item.position = data;
  14911. $scope.AppFlow.appNodes.push(item);
  14912. }
  14913. $scope.deleteNode = function (index) {// 删除节点
  14914. $scope.AppFlow.appNodes.splice(index, 1);
  14915. };
  14916. $scope.saveNode = function () { // 保存
  14917. angular.forEach($scope.AppFlow.appNodes, function (value, key) {
  14918. $scope.AppFlow.appNodes[key].level = key;
  14919. });
  14920. if ($scope.AppFlow.appNodes.length == 0) {
  14921. toaster.pop('info', '提示', '您还未设置审批人');
  14922. } else {
  14923. $modalInstance.close($scope.AppFlow);
  14924. }
  14925. ;
  14926. };
  14927. $scope.cancel = function () {// 取消
  14928. $modalInstance.dismiss();
  14929. }
  14930. }]);
  14931. /***
  14932. * 代采定单
  14933. */
  14934. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', 'getOrderInfo', '$modal', 'CurrentRole', function ($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService, getOrderInfo, $modal, CurrentRole) {
  14935. BaseService.scrollBackToTop();
  14936. // 获取当前用户是否为普通用户
  14937. CurrentRole.isUser({}, {}, function (data) {
  14938. $scope.isUser = data.isUser;
  14939. });
  14940. $scope.active = 'all';
  14941. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14942. $scope.total = null;
  14943. $scope.setActive = function (state) {
  14944. if ($scope.active != state) {
  14945. $scope.active = state;
  14946. if ($scope.tableParams.page() == 1)
  14947. $scope.tableParams.reload();
  14948. else
  14949. $scope.tableParams.page(1);
  14950. }
  14951. };
  14952. $scope.agreedText = '全部';
  14953. $scope.dateZoneText = '不限';
  14954. $scope.condition = {dateZone: 1};
  14955. /* 时间筛选初始化*/
  14956. var fromDate = new Date();
  14957. var toDate = new Date();
  14958. fromDate.setMonth(fromDate.getMonth() - 1);
  14959. fromDate.setHours(0, 0, 0, 0);
  14960. toDate.setHours(23, 59, 59, 999);
  14961. $scope.condition.dateFrom = fromDate;
  14962. $scope.condition.dateTo = toDate;
  14963. $scope.changeDateZone = function (zone) {
  14964. $scope.condition.dateZone = zone;
  14965. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14966. $scope.condition.$dateZoneOpen = false;
  14967. getDateCondition(zone, $scope.condition);
  14968. $scope.tableParams.page(1);
  14969. $scope.tableParams.reload();
  14970. };
  14971. $scope.openDatePicker = function ($event, item, openParam) {
  14972. $event.preventDefault();
  14973. $event.stopPropagation();
  14974. item[openParam] = !item[openParam];
  14975. };
  14976. $scope.openFilterDatePicker = function ($event, item, openParam) {
  14977. $event.preventDefault();
  14978. $event.stopPropagation();
  14979. item[openParam] = !item[openParam];
  14980. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  14981. $scope.tableParams.reload();
  14982. }
  14983. };
  14984. $scope.searchMethod = false;
  14985. var getSerivce = function() {
  14986. return $scope.searchMethod ? getDeOrder : getOrderInfo;
  14987. }
  14988. getSerivce();
  14989. // 获取订单总金额
  14990. var getOrdersAmount = function() {
  14991. DeputyOrder.odersAmount({}, function(data) {
  14992. $scope.odersAmount = data.amount;
  14993. });
  14994. }
  14995. getOrdersAmount();
  14996. $scope.tableParams = new ngTableParams({
  14997. page: 1,
  14998. count: 20,
  14999. sorting: {'date': 'desc', 'id': 'desc'}
  15000. }, {
  15001. total: 0,
  15002. counts: [5, 10, 25, 50],
  15003. getData: function ($defer, params) {
  15004. $scope.loading = true;
  15005. var pageParams = params.url();
  15006. pageParams.searchFilter = {
  15007. keyword: $scope.keyword,
  15008. fromDate: getDateTime($scope.condition.dateFrom),
  15009. endDate: getDateTime($scope.condition.dateTo)
  15010. };
  15011. getSerivce()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  15012. $scope.loading = false;
  15013. if (page) {
  15014. params.total(page.totalElement);
  15015. $scope.total = page.totalElement;
  15016. $defer.resolve(page.content);
  15017. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  15018. }
  15019. }, function (response) {
  15020. $scope.loading = false;
  15021. toaster.pop('error', '数据加载失败', response.data);
  15022. });
  15023. }
  15024. });
  15025. //打印
  15026. $scope.print = function (deputyOrder) {
  15027. DeputyOrder.printCount({id: deputyOrder.id}, {});//增加打印此次
  15028. $scope.tableParams.reload();
  15029. ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  15030. ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  15031. ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  15032. ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  15033. };
  15034. // 搜索框回车
  15035. $scope.onSearch = function (keyword) {
  15036. // 每次搜索重置获取数据方法
  15037. $scope.searchMethod = false;
  15038. if(keyword != null && keyword != '') {
  15039. $scope.searchMethod = true;
  15040. }
  15041. $scope.tableParams.page(1);
  15042. $scope.tableParams.reload();
  15043. };
  15044. // 复制采购单
  15045. $scope.copyorder = function (id) {
  15046. $scope.loading = true;
  15047. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  15048. $scope.loading = false;
  15049. if (data.id) {
  15050. toaster.pop('success', '提示', '复制生成单据成功');
  15051. window.location.hash = "#/purc/deputy/" + data.id;
  15052. }
  15053. if (data.error) {
  15054. toaster.pop('error', '提示', '保存失败');
  15055. }
  15056. }, function (response) {
  15057. $scope.loading = false;
  15058. toaster.pop('error', '提示', response.data);
  15059. });
  15060. }
  15061. // 删除代采订单
  15062. $scope.clear = function (id) {
  15063. $scope.loading = true;
  15064. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  15065. if (data.success) {
  15066. toaster.pop('success', '提示', data.success);
  15067. $scope.tableParams.reload();
  15068. }
  15069. $scope.loading = false;
  15070. }, function (response) {
  15071. $scope.loading = false;
  15072. toaster.pop('error', '提示', response.data);
  15073. });
  15074. }
  15075. $scope.viewApprove = function(salecode, uu) {
  15076. var modalInstance = $modal.open({
  15077. templateUrl: 'static/tpl/index/purc/modal/approval_detail.html',
  15078. controller: 'ViewApprovalDetailCtrl',
  15079. resolve: {
  15080. uu: function () {
  15081. return uu
  15082. },
  15083. salecode: function () {
  15084. return salecode
  15085. }
  15086. }
  15087. });
  15088. }
  15089. }]);
  15090. // 查询代采定单在信扬中的审批情况
  15091. app.controller('ViewApprovalDetailCtrl', ['$scope', 'toaster', '$modalInstance', 'DeputyOrder', 'BaseService', 'ngTableParams', 'uu', 'salecode', function ($scope, toaster, $modalInstance, DeputyOrder, BaseService, ngTableParams, uu, salecode) {
  15092. DeputyOrder.approve({uu: uu, code: salecode}, {}, function (data) {
  15093. $scope.nodes = data.nodes;
  15094. $scope.process = data.process;
  15095. if(data.error) {
  15096. toaster.pop('error', '提示', data.error);
  15097. }
  15098. }, function (response) {
  15099. toaster.pop('error', '提示', '暂未获取到相关单据的信息');
  15100. });
  15101. $scope.cancel = function () {
  15102. $modalInstance.dismiss();
  15103. };
  15104. $scope.select = function (company) { // 直接选择
  15105. $modalInstance.close(company);
  15106. }
  15107. }]);
  15108. /**
  15109. * 新增代采订单
  15110. */
  15111. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', 'DecimalNumber', 'DekeyValue', function ($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService, DecimalNumber, DekeyValue) {
  15112. BaseService.scrollBackToTop();
  15113. //默认采购单号不重复
  15114. $scope.orderCodeEnable = true;
  15115. $scope.deOrder = {
  15116. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  15117. entrydate: new Date(),
  15118. status: '在录入',
  15119. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  15120. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  15121. riskmethod: '甲方承担',
  15122. taxpaymentmethod: '甲方承担',
  15123. deliverymethod: '供应商送货到付款采购方指定仓库',
  15124. totalamount: 0,
  15125. totalpayament: 0,
  15126. orderamount: 0,
  15127. usdpayment: 0
  15128. };
  15129. $scope.deOrder.deputyOrderItems = [];
  15130. var item = {
  15131. prodname: null,
  15132. prodcode: null,
  15133. prodspec: null,
  15134. amount: null,
  15135. unitprice: null,
  15136. purcprice: null,
  15137. remark: null,
  15138. orderprice: null,
  15139. };
  15140. $scope.deOrder.deputyOrderItems.push(item);
  15141. // 代采企业列表
  15142. DeputyOrder.deputyEnterprise({}, function (data) {
  15143. $scope.deputyEnterprises = data;
  15144. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15145. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15146. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  15147. });
  15148. var getPayMethod = function(enuu, key) {
  15149. // 获取我方付款支付方式默认值
  15150. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  15151. $scope.methods = data.content;
  15152. });
  15153. }
  15154. // 更新名称时后台更改uu号
  15155. $scope.change = function (deputyname) {
  15156. DeputyOrder.deputyEnterprise({}, function (data) {
  15157. $scope.deputyEn = data;
  15158. angular.forEach($scope.deputyEn, function (en) {
  15159. if (deputyname == en.deputyenname) {
  15160. $scope.deputyuu = en.deputyenuu;
  15161. getPayMethod($scope.deputyuu, 'paymentmethod');
  15162. }
  15163. });
  15164. });
  15165. }
  15166. // 设置付款企业信息
  15167. $scope.setPayComName = function() {
  15168. // 针对信扬客户,如果是RMB赋值默认值
  15169. if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.deputyuu == 10044118) {
  15170. $scope.deOrder.paycomname = '深圳信扬国际经贸股份有限公司';
  15171. $scope.deOrder.paycomaddress= '深圳市前海深港合作区前湾一路1号A栋201室(入驻深圳市前海商务秘书有限公司)';
  15172. }
  15173. }
  15174. // 查找付款企业
  15175. $scope.dbfindPayCompany = function (deputyuu) {
  15176. var modalInstance = $modal.open({
  15177. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15178. controller: 'DbfindDeputyPayCompanyCtrl',
  15179. resolve: {
  15180. deputyuu: function () {
  15181. return deputyuu
  15182. }
  15183. }
  15184. });
  15185. modalInstance.result.then(function (data) {
  15186. $scope.deOrder.paycomname = data.enname;
  15187. $scope.deOrder.paycomaddress = data.address;
  15188. })
  15189. }
  15190. // 查询上次的关键词记录
  15191. $scope.getHisKeyword = function (tervendor) {
  15192. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function (data) {
  15193. $scope.deOrder.vendtel = data.vendtel;
  15194. $scope.deOrder.venduser = data.venduser;
  15195. $scope.deOrder.otherdata = data.otherdata;
  15196. $scope.deOrder.companyname = data.companyname;
  15197. $scope.deOrder.bankaccount = data.bankaccount;
  15198. $scope.deOrder.bankaddress = data.bankaddress;
  15199. $scope.deOrder.bankcode = data.bankcode;
  15200. $scope.deOrder.bankname = data.bankname;
  15201. $scope.deOrder.legalrepresent = data.legalrepresent;
  15202. $scope.deOrder.tervendaddress = data.tervendaddress;
  15203. $scope.deOrder.enfax = data.enfax;
  15204. $scope.deOrder.deliverymethod = data.deliverymethod;
  15205. }, function (response) {
  15206. toaster.pop('error', '提示', response.data);
  15207. });
  15208. }
  15209. // 查询历史供应商
  15210. DeputyOrder.hisvendors({}, function (data) {
  15211. $scope.hisvendors = data;
  15212. }, function (response) {
  15213. toaster.pop('error', '提示', response.data);
  15214. });
  15215. // 上次填写记录(不关联供应商)
  15216. DeputyOrder.lastKeywords({}, function (data) {
  15217. $scope.lastkeyowrds = data;
  15218. $scope.deOrder.madealdate = $scope.lastkeyowrds.madealdate;
  15219. $scope.deOrder.madealcode = $scope.lastkeyowrds.madealcode;
  15220. }, function (response) {
  15221. toaster.pop('error', '提示', response.data);
  15222. });
  15223. //增加商品
  15224. $scope.add = function (index) {
  15225. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15226. toaster.pop('info', '提示', '请先填写商品信息');
  15227. } else {
  15228. $scope.deOrder.deputyOrderItems.push(
  15229. {
  15230. prodname: null,
  15231. prodcode: null,
  15232. prodspec: null,
  15233. prodbrand: null,
  15234. amount: null,
  15235. unitprice: null,
  15236. purcprice: null,
  15237. remark: null,
  15238. orderprice: null
  15239. });
  15240. }
  15241. };
  15242. //删除商品
  15243. $scope.del = function (index) {
  15244. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15245. };
  15246. // 导入商品信息
  15247. $scope.uplodaByBatch = function () {
  15248. var modalInstance = $modal.open({
  15249. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15250. controller: 'DeputyOrderUploadCtrl',
  15251. size: 'lg',
  15252. resolve: {}
  15253. });
  15254. modalInstance.result.then(function (data) {
  15255. angular.forEach(data, function (data) {
  15256. $scope.deOrder.deputyOrderItems.push(data);
  15257. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15258. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15259. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15260. }
  15261. }
  15262. })
  15263. $scope.deOrder.totalamount = 0;
  15264. $scope.deOrder.usdpayment = 0;
  15265. $scope.deOrder.orderamount = 0;
  15266. $scope.deOrder.totalpayament = 0;
  15267. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15268. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15269. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15270. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15271. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15272. });
  15273. }, function () {
  15274. });
  15275. }
  15276. // 查找供应商
  15277. $scope.dbfindVendor = function (deputyuu) {
  15278. var modalInstance = $modal.open({
  15279. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  15280. controller: 'DbfindDeputyVendorInfoCtrl',
  15281. size: 'lg',
  15282. resolve: {
  15283. deputyuu: function () {
  15284. return deputyuu
  15285. }
  15286. }
  15287. });
  15288. modalInstance.result.then(function (data) {
  15289. $scope.deOrder.customer = data.vendorEnterprise.enName;
  15290. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  15291. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  15292. $scope.deOrder.usertel = data.vendorUser.userTel;
  15293. })
  15294. }
  15295. // 检验订单编号是否存在
  15296. $scope.checkOrder = function (salecode, deputyuu) {
  15297. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  15298. $scope.orderCodeEnable = true;
  15299. if (data.info) {
  15300. toaster.pop('error', '提示', data.info);
  15301. $scope.orderCodeEnable = false;
  15302. }
  15303. }, function (response) {
  15304. toaster.pop('error', '提示', response.data);
  15305. })
  15306. }
  15307. //计算采购单价
  15308. $scope.checkPrice = function (rate) {
  15309. $scope.deOrder.totalamount = 0;
  15310. $scope.deOrder.usdpayment = 0;
  15311. $scope.deOrder.orderamount = 0;
  15312. $scope.deOrder.totalpayament = 0;
  15313. if (rate == null) {
  15314. toaster.pop('info', '提示', '请先填入税率');
  15315. } else {
  15316. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15317. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  15318. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15319. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15320. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15321. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15322. });
  15323. }
  15324. }
  15325. // 获取订单总价
  15326. $scope.totalPrice = function () {
  15327. $scope.deOrder.totalamount = 0;
  15328. $scope.deOrder.usdpayment = 0;
  15329. $scope.deOrder.orderamount = 0;
  15330. $scope.deOrder.totalpayament = 0;
  15331. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15332. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  15333. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15334. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15335. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15336. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15337. }
  15338. });
  15339. }
  15340. $scope.checkresult = false;
  15341. var checkKeyword = function () {
  15342. if ($scope.deOrder.madealdate == null) {
  15343. toaster.pop('info', '提示', '主协议签订日期未选择');
  15344. } else if ($scope.deOrder.madealcode == null) {
  15345. toaster.pop('info', '提示', '主协议签订编号未填写');
  15346. } else if ($scope.deOrder.tervendor == null) {
  15347. toaster.pop('info', '提示', '终端供应商名称未填写');
  15348. } else if ($scope.deOrder.vendtel == null) {
  15349. toaster.pop('info', '提示', '电话号码未填写');
  15350. } else if ($scope.deOrder.venduser == null) {
  15351. toaster.pop('info', '提示', '联系人未填写');
  15352. } else if ($scope.deOrder.shipdate == null) {
  15353. toaster.pop('info', '提示', '供应商发货时间未选择');
  15354. } else if ($scope.deOrder.goodspacking == null) {
  15355. toaster.pop('info', '提示', '货物包装要求未填写');
  15356. } else if ($scope.deOrder.deliverymethod == null) {
  15357. toaster.pop('info', '提示', '供应商交货方式未填写');
  15358. } else if ($scope.deOrder.pickupmethod == null) {
  15359. toaster.pop('info', '提示', '我方提货方式未填写');
  15360. } else if ($scope.deOrder.paymentmethod == null) {
  15361. toaster.pop('info', '提示', '我方付款方式未填写');
  15362. } else if ($scope.deOrder.pickupdate == null) {
  15363. toaster.pop('info', '提示', '我方提货时间未选择');
  15364. } else if ($scope.deOrder.currency == null) {
  15365. toaster.pop('info', '提示', '交易币别未选择');
  15366. } else if ($scope.deOrder.deputyuu == null) {
  15367. toaster.pop('info', '提示', '代采企业未选择');
  15368. } else if ($scope.deOrder.salecode == null) {
  15369. toaster.pop('info', '提示', '订单编号未填写');
  15370. } else if ($scope.deOrder.paydeldate == null) {
  15371. toaster.pop('info', '提示', '我方付款提货时间未选择');
  15372. } else if ($scope.deOrder.riskmethod == null) {
  15373. toaster.pop('info', '提示', '风险承担方式未填写');
  15374. } else if ($scope.deOrder.taxpaymentmethod == null) {
  15375. toaster.pop('info', '提示', '运、税费承担方式');
  15376. } else if ($scope.deOrder.tervendaddress == null) {
  15377. toaster.pop('info', '提示', '终端供应商地址未填写');
  15378. } else if ($scope.deOrder.companyname == null) {
  15379. toaster.pop('info', '提示', '公司全称(英文)未填写');
  15380. } else if ($scope.deOrder.requirepaydate == null) {
  15381. toaster.pop('info', '提示', '要求付汇日期未选择');
  15382. } else if ($scope.deOrder.bankname == null) {
  15383. toaster.pop('info', '提示', '银行名称(英文)未填写');
  15384. } else if ($scope.deOrder.bankaccount == null) {
  15385. toaster.pop('info', '提示', '银行账号未填写');
  15386. } else if ($scope.deOrder.bankaddress == null) {
  15387. toaster.pop('info', '提示', '银行地址未填写');
  15388. } else if ($scope.deOrder.bankcode == null) {
  15389. toaster.pop('info', '提示', '银行代码未填写');
  15390. } else if ($scope.deOrder.salepocode == null) {
  15391. toaster.pop('info', '提示', '合同编号未填写');
  15392. } else if ($scope.deOrder.legalrepresent == null) {
  15393. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  15394. } else if ($scope.deOrder.paycomname == null) {
  15395. toaster.pop('info', '提示', '付款公司未填写');
  15396. } else if ($scope.deOrder.paycomaddress == null) {
  15397. toaster.pop('info', '提示', '付款公司地址未填写');
  15398. } else if ($scope.deOrder.enfax == null) {
  15399. toaster.pop('info', '提示', '供应商方法人电话未填写');
  15400. } else if ($scope.deOrder.paydate == null) {
  15401. toaster.pop('info', '提示', '货款支付时间未选择');
  15402. } else if ($scope.deOrder.paymethod == null) {
  15403. toaster.pop('info', '提示', '货款支付方式未填写');
  15404. } else if ($scope.deOrder.deliverydate == null) {
  15405. toaster.pop('info', '提示', '交货时间未选择');
  15406. } else if (!$scope.orderCodeEnable) {
  15407. toaster.pop('info', '提示', '采购单号重复');
  15408. } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
  15409. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
  15410. } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
  15411. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
  15412. } else {
  15413. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  15414. if (orderitem.prodname == null) {
  15415. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  15416. } else if (orderitem.prodcode == null) {
  15417. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  15418. } else if (orderitem.prodspec == null) {
  15419. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  15420. } else if (orderitem.prodbrand == null) {
  15421. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  15422. } else if (orderitem.amount == null) {
  15423. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  15424. } else if (orderitem.unitprice == null) {
  15425. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  15426. } else if (orderitem.purcprice == null) {
  15427. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  15428. } else {
  15429. $scope.checkresult = true;
  15430. $scope.isSave = true;
  15431. }
  15432. })
  15433. };
  15434. }
  15435. // 保存
  15436. $scope.isSave = false;
  15437. $scope.save = function (status) {
  15438. $scope.deOrder.entrystatus = status;
  15439. checkKeyword();
  15440. if ($scope.checkresult) {
  15441. $scope.deOrder.totalamount = 0;
  15442. $scope.deOrder.usdpayment = 0;
  15443. $scope.deOrder.orderamount = 0;
  15444. $scope.deOrder.totalpayament = 0;
  15445. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  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. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  15452. toaster.pop('info', '提示', '您还未填写任何商品信息');
  15453. } else {
  15454. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  15455. if (data.id) {
  15456. toaster.pop('success', '提示', status + '成功');
  15457. window.location.hash = "#/purc/deputy/" + data.id;
  15458. }
  15459. if (data.error) {
  15460. toaster.pop('error', '提示', status + '失败');
  15461. }
  15462. }, function (response) {
  15463. });
  15464. }
  15465. }
  15466. }
  15467. $scope.openDatePicker = function ($event, deOrder, openParam) {
  15468. $event.preventDefault();
  15469. $event.stopPropagation();
  15470. deOrder[openParam] = !deOrder[openParam];
  15471. };
  15472. }]);
  15473. // 代采企业供应商
  15474. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  15475. $scope.prod = false;
  15476. BaseService.scrollBackToTop();
  15477. // 搜索框回车
  15478. $scope.onSearch = function (keyword) {
  15479. $scope.keyword = keyword;
  15480. $scope.customerParams.page(1);
  15481. $scope.customerParams.reload();
  15482. };
  15483. $scope.customerParams = new ngTableParams({
  15484. page: 1,
  15485. count: 20
  15486. }, {
  15487. total: 0,
  15488. counts: [5, 10, 25, 50],
  15489. getData: function ($defer, params) {
  15490. $scope.loading = true;
  15491. var pageParams = params.url();
  15492. pageParams.keyword = $scope.keyword;
  15493. pageParams.enuu = deputyuu;
  15494. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function (page) {
  15495. $scope.loading = false;
  15496. if (page) {
  15497. params.total(page.totalElement);
  15498. $defer.resolve(page.content);
  15499. }
  15500. $scope.totalCount = page.totalElement;
  15501. }, function (response) {
  15502. $scope.loading = false;
  15503. toaster.pop('error', '数据加载失败', response.data);
  15504. });
  15505. }
  15506. });
  15507. $scope.cancel = function () {
  15508. $modalInstance.dismiss();
  15509. };
  15510. $scope.checkVendor = function (vendor) { // 直接选择
  15511. $modalInstance.close(vendor);
  15512. }
  15513. }]);
  15514. // 代采企业付款企业
  15515. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  15516. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function (data) {
  15517. $scope.paycompanies = data;
  15518. }, function (response) {
  15519. toaster.pop('error', '提示', response.data);
  15520. });
  15521. $scope.cancel = function () {
  15522. $modalInstance.dismiss();
  15523. };
  15524. $scope.select = function (company) { // 直接选择
  15525. $modalInstance.close(company);
  15526. }
  15527. }]);
  15528. /**
  15529. * 代采订单批量导入
  15530. */
  15531. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  15532. // 通过excel批量上传物料
  15533. $scope.result = null;
  15534. $scope.upload = function () {
  15535. var file = $scope.myFiles[0];
  15536. $upload.upload({
  15537. url: 'deputyOrder/release/excel',
  15538. file: file,
  15539. method: 'POST'
  15540. }).success(function (data) {
  15541. $scope.result = data;
  15542. $scope.success = $scope.result.success;
  15543. $scope.total = $scope.result.total;
  15544. $scope.alters = $scope.result.alters;
  15545. }).error(function (response) {
  15546. toaster.pop('error', response.data || response);
  15547. });
  15548. };
  15549. // 查看范例
  15550. $scope.showImg = function () {
  15551. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  15552. box.show();
  15553. box.find('img').attr('src', src);
  15554. box.find('a').click(function () {
  15555. box.hide();
  15556. });
  15557. box.dblclick(function () {
  15558. box.hide();
  15559. });
  15560. };
  15561. // 下载模板
  15562. $scope.download = function () {
  15563. window.location.href = 'deputyOrder/upload/template';
  15564. };
  15565. $scope.enSure = function () {
  15566. $modalInstance.close($scope.result.items);
  15567. }
  15568. $scope.cancel = function () {
  15569. $modalInstance.dismiss();
  15570. }
  15571. }]);
  15572. /**
  15573. * 代采详情
  15574. */
  15575. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', 'DecimalNumber', 'CurrentRole', 'DekeyValue', function ($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal, DecimalNumber, CurrentRole, DekeyValue) {
  15576. BaseService.scrollBackToTop();
  15577. // 获取当前用户是否为普通用户
  15578. CurrentRole.isUser({}, {}, function (data) {
  15579. $scope.isUser = data.isUser;
  15580. });
  15581. var loadData = function () {
  15582. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function (data) {
  15583. $scope.deOrder = data;
  15584. $scope.deOrder.$editing = true;
  15585. }, function (response) {
  15586. toaster.pop('error', '提示', response.data);
  15587. });
  15588. };
  15589. loadData();
  15590. //默认采购单号不重复
  15591. $scope.orderCodeEnable = true;
  15592. // 查询历史供应商
  15593. DeputyOrder.hisvendors({}, function (data) {
  15594. $scope.hisvendors = data;
  15595. }, function (response) {
  15596. toaster.pop('error', '提示', response.data);
  15597. });
  15598. // 代采企业列表
  15599. DeputyOrder.deputyEnterprise({}, function (data) {
  15600. $scope.deputyEnterprises = data;
  15601. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15602. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15603. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  15604. });
  15605. var getPayMethod = function(enuu, key) {
  15606. // 获取我方付款支付方式默认值
  15607. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  15608. $scope.methods = data.content;
  15609. });
  15610. }
  15611. // 更新代采企业时更新费率
  15612. $scope.change = function (deputyname) {
  15613. DeputyOrder.deputyEnterprise({}, function (data) {
  15614. $scope.deputyEn = data;
  15615. angular.forEach($scope.deputyEn, function (en) {
  15616. if (deputyname == en.deputyenname) {
  15617. $scope.deputyuu = en.deputyenuu;
  15618. getPayMethod($scope.deputyuu, 'paymentmethod');
  15619. }
  15620. });
  15621. });
  15622. }
  15623. // 设置付款企业信息
  15624. $scope.setPayComName = function() {
  15625. // 针对信扬客户,如果是RMB赋值默认值
  15626. if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.deputyuu == 10044118) {
  15627. $scope.deOrder.paycomname = '深圳信扬国际经贸股份有限公司';
  15628. $scope.deOrder.paycomaddress= '深圳市前海深港合作区前湾一路1号A栋201室(入驻深圳市前海商务秘书有限公司)';
  15629. }
  15630. }
  15631. // 查找付款企业
  15632. $scope.dbfindPayCompany = function (deputyuu) {
  15633. var modalInstance = $modal.open({
  15634. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15635. controller: 'DbfindDeputyPayCompanyCtrl',
  15636. resolve: {
  15637. deputyuu: function () {
  15638. return deputyuu
  15639. }
  15640. }
  15641. });
  15642. modalInstance.result.then(function (data) {
  15643. $scope.deOrder.paycomname = data.enname;
  15644. $scope.deOrder.paycomaddress = data.address;
  15645. })
  15646. }
  15647. // 删除明细
  15648. $scope.del = function (index, id) {
  15649. DeputyOrder.deleteProdById({id: id}, {}, function (data) {
  15650. if (data.success) {
  15651. toaster.pop('success', '提示', data.success);
  15652. $scope.deOrder.deputyOrderItems.splice(index, 1)
  15653. }
  15654. if (data.error) {
  15655. toaster.pop('error', '提示', data.error);
  15656. }
  15657. $scope.deOrder.totalamount = 0;
  15658. $scope.deOrder.usdpayment = 0;
  15659. $scope.deOrder.orderamount = 0;
  15660. $scope.deOrder.totalpayament = 0;
  15661. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15662. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15663. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15664. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15665. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15666. });
  15667. }, function (response) {
  15668. toaster.pop('error', '提示', response.data);
  15669. });
  15670. }
  15671. //增加商品
  15672. $scope.add = function (index) {
  15673. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15674. toaster.pop('info', '提示', '请先填写商品信息');
  15675. } else {
  15676. $scope.deOrder.deputyOrderItems.push(
  15677. {
  15678. prodname: null,
  15679. prodcode: null,
  15680. prodspec: null,
  15681. prodbrand: null,
  15682. amount: null,
  15683. unitprice: null,
  15684. remark: null,
  15685. orderprice: null
  15686. });
  15687. }
  15688. };
  15689. // 导入商品信息
  15690. $scope.uplodaByBatch = function () {
  15691. var modalInstance = $modal.open({
  15692. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15693. controller: 'DeputyOrderUploadCtrl',
  15694. size: 'lg',
  15695. resolve: {}
  15696. });
  15697. modalInstance.result.then(function (data) {
  15698. angular.forEach(data, function (data) {
  15699. $scope.deOrder.deputyOrderItems.push(data);
  15700. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15701. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15702. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15703. }
  15704. }
  15705. })
  15706. $scope.deOrder.totalamount = 0;
  15707. $scope.deOrder.usdpayment = 0;
  15708. $scope.deOrder.orderamount = 0;
  15709. $scope.deOrder.totalpayament = 0;
  15710. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15711. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15712. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15713. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15714. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15715. });
  15716. }, function () {
  15717. });
  15718. }
  15719. //删除商品
  15720. $scope.delItem = function (index) {
  15721. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15722. };
  15723. var getService = function () {
  15724. return DeputyOrder.getProdList;
  15725. };
  15726. $scope.update = function () {
  15727. $scope.deOrder.$editing = true;
  15728. }
  15729. $scope.cancel = function () {
  15730. $scope.deOrder.$editing = false;
  15731. }
  15732. // 检验订单编号是否存在
  15733. $scope.checkOrder = function (salecode, deputyuu) {
  15734. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  15735. $scope.orderCodeEnable = true;
  15736. if (data.info) {
  15737. toaster.pop('error', '提示', data.info);
  15738. $scope.orderCodeEnable = false;
  15739. }
  15740. }, function (response) {
  15741. toaster.pop('error', '提示', response.data);
  15742. })
  15743. }
  15744. //计算采购单价
  15745. $scope.checkPrice = function (rate) {
  15746. $scope.deOrder.totalamount = 0;
  15747. $scope.deOrder.usdpayment = 0;
  15748. $scope.deOrder.orderamount = 0;
  15749. $scope.deOrder.totalpayament = 0;
  15750. if (rate == null) {
  15751. toaster.pop('info', '提示', '请先填入税率');
  15752. } else {
  15753. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15754. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  15755. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15756. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15757. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15758. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15759. });
  15760. }
  15761. }
  15762. // 获取订单总价
  15763. $scope.totalPrice = function () {
  15764. $scope.deOrder.totalamount = 0;
  15765. $scope.deOrder.usdpayment = 0;
  15766. $scope.deOrder.orderamount = 0;
  15767. $scope.deOrder.totalpayament = 0;
  15768. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15769. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  15770. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15771. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15772. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15773. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15774. }
  15775. });
  15776. }
  15777. $scope.checkresult = false;
  15778. var checkKeyword = function () {
  15779. if ($scope.deOrder.madealdate == null) {
  15780. toaster.pop('info', '提示', '主协议签订日期未选择');
  15781. } else if ($scope.deOrder.madealcode == null) {
  15782. toaster.pop('info', '提示', '主协议签订编号未填写');
  15783. } else if ($scope.deOrder.tervendor == null) {
  15784. toaster.pop('info', '提示', '终端供应商名称未填写');
  15785. } else if ($scope.deOrder.vendtel == null) {
  15786. toaster.pop('info', '提示', '电话号码未填写');
  15787. } else if ($scope.deOrder.venduser == null) {
  15788. toaster.pop('info', '提示', '联系人未填写');
  15789. } else if ($scope.deOrder.shipdate == null) {
  15790. toaster.pop('info', '提示', '供应商发货时间未选择');
  15791. } else if ($scope.deOrder.goodspacking == null) {
  15792. toaster.pop('info', '提示', '货物包装要求未填写');
  15793. } else if ($scope.deOrder.deliverymethod == null) {
  15794. toaster.pop('info', '提示', '供应商交货方式未填写');
  15795. } else if ($scope.deOrder.pickupmethod == null) {
  15796. toaster.pop('info', '提示', '我方提货方式未填写');
  15797. } else if ($scope.deOrder.paymentmethod == null) {
  15798. toaster.pop('info', '提示', '我方付款方式未填写');
  15799. } else if ($scope.deOrder.pickupdate == null) {
  15800. toaster.pop('info', '提示', '我方提货时间未选择');
  15801. } else if ($scope.deOrder.currency == null) {
  15802. toaster.pop('info', '提示', '交易币别未选择');
  15803. } else if ($scope.deOrder.deputyuu == null) {
  15804. toaster.pop('info', '提示', '代采企业未选择');
  15805. } else if ($scope.deOrder.salecode == null) {
  15806. toaster.pop('info', '提示', '订单编号未填写');
  15807. } else if ($scope.deOrder.paydeldate == null) {
  15808. toaster.pop('info', '提示', '我方付款提货时间未选择');
  15809. } else if ($scope.deOrder.riskmethod == null) {
  15810. toaster.pop('info', '提示', '风险承担方式未填写');
  15811. } else if ($scope.deOrder.taxpaymentmethod == null) {
  15812. toaster.pop('info', '提示', '运、税费承担方式');
  15813. } else if ($scope.deOrder.tervendaddress == null) {
  15814. toaster.pop('info', '提示', '终端供应商地址未填写');
  15815. } else if ($scope.deOrder.companyname == null) {
  15816. toaster.pop('info', '提示', '公司全称(英文)未填写');
  15817. } else if ($scope.deOrder.requirepaydate == null) {
  15818. toaster.pop('info', '提示', '要求付汇日期未选择');
  15819. } else if ($scope.deOrder.bankname == null) {
  15820. toaster.pop('info', '提示', '银行名称(英文)未填写');
  15821. } else if ($scope.deOrder.bankaccount == null) {
  15822. toaster.pop('info', '提示', '银行账号未填写');
  15823. } else if ($scope.deOrder.bankaddress == null) {
  15824. toaster.pop('info', '提示', '银行地址未填写');
  15825. } else if ($scope.deOrder.bankcode == null) {
  15826. toaster.pop('info', '提示', '银行代码未填写');
  15827. } else if ($scope.deOrder.salepocode == null) {
  15828. toaster.pop('info', '提示', '合同编号未填写');
  15829. } else if ($scope.deOrder.legalrepresent == null) {
  15830. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  15831. } else if ($scope.deOrder.paycomname == null) {
  15832. toaster.pop('info', '提示', '付款公司未填写');
  15833. } else if ($scope.deOrder.paycomaddress == null) {
  15834. toaster.pop('info', '提示', '付款公司地址未填写');
  15835. } else if ($scope.deOrder.enfax == null) {
  15836. toaster.pop('info', '提示', '供应商方法人电话未填写');
  15837. } else if ($scope.deOrder.paydate == null) {
  15838. toaster.pop('info', '提示', '货款支付时间未选择');
  15839. } else if ($scope.deOrder.paymethod == null) {
  15840. toaster.pop('info', '提示', '货款支付方式未填写');
  15841. } else if ($scope.deOrder.deliverydate == null) {
  15842. toaster.pop('info', '提示', '交货时间未选择');
  15843. } else if (!$scope.orderCodeEnable) {
  15844. toaster.pop('info', '提示', '采购单号重复');
  15845. } else if ($scope.deOrder.currency == 'USD' && $scope.deOrder.totalpayament >= 300 * 10000) {
  15846. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金');
  15847. } else if ($scope.deOrder.currency == 'RMB' && $scope.deOrder.totalpayament >= 1000 * 10000) {
  15848. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过1000万人民币');
  15849. } else {
  15850. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  15851. if (orderitem.prodname == null) {
  15852. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  15853. } else if (orderitem.prodcode == null) {
  15854. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  15855. } else if (orderitem.prodspec == null) {
  15856. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  15857. } else if (orderitem.prodbrand == null) {
  15858. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  15859. } else if (orderitem.amount == null) {
  15860. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  15861. } else if (orderitem.unitprice == null) {
  15862. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  15863. } else if (orderitem.purcprice == null) {
  15864. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  15865. } else {
  15866. $scope.checkresult = true;
  15867. $scope.isSave = true;
  15868. }
  15869. });
  15870. }
  15871. }
  15872. // 保存
  15873. $scope.isSave = false;
  15874. $scope.save = function (status) {
  15875. checkKeyword();
  15876. if ($scope.checkresult) {
  15877. $scope.deOrder.totalamount = 0;
  15878. $scope.deOrder.usdpayment = 0;
  15879. $scope.deOrder.orderamount = 0;
  15880. $scope.deOrder.totalpayament = 0;
  15881. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15882. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15883. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15884. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15885. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15886. });
  15887. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  15888. toaster.pop('info', '提示', '您还未填写任何商品信息');
  15889. } else {
  15890. $scope.deOrder.entrystatus = status;
  15891. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  15892. if (data.id) {
  15893. toaster.pop('success', '提示', '保存成功');
  15894. loadData();
  15895. window.location.reload();
  15896. }
  15897. if (data.error) {
  15898. toaster.pop('error', '提示', '保存失败');
  15899. }
  15900. }, function (response) {
  15901. toaster.pop('error', '保存失败', response.data);
  15902. });
  15903. }
  15904. }
  15905. }
  15906. $scope.openDatePicker = function ($event, deOrder, openParam) {
  15907. $event.preventDefault();
  15908. $event.stopPropagation();
  15909. deOrder[openParam] = !deOrder[openParam];
  15910. };
  15911. //复制采购单
  15912. $scope.copyorder = function (id) {
  15913. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  15914. if (data.id) {
  15915. toaster.pop('success', '提示', '复制生成单据成功');
  15916. window.location.hash = "#/purc/deputy/" + data.id;
  15917. }
  15918. if (data.error) {
  15919. toaster.pop('error', '提示', '保存失败');
  15920. }
  15921. }, function (response) {
  15922. toaster.pop('error', '提示', response.data);
  15923. });
  15924. }
  15925. // 删除代采订单
  15926. $scope.clear = function (id) {
  15927. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  15928. if (data.success) {
  15929. toaster.pop('success', '提示', data.success);
  15930. window.location.hash = "#/purc/deputy";
  15931. }
  15932. }, function (response) {
  15933. toaster.pop('error', '提示', response.data);
  15934. });
  15935. }
  15936. }]);
  15937. /**
  15938. * 代采错误日志
  15939. */
  15940. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function ($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  15941. BaseService.scrollBackToTop();
  15942. var getService = function () {
  15943. return DeputyOrder.getRepetitions;
  15944. };
  15945. $scope.tableParams = new ngTableParams({
  15946. page: 1,
  15947. count: 20,
  15948. sorting: {}
  15949. }, {
  15950. total: 0,
  15951. counts: [5, 10, 25, 50],
  15952. getData: function ($defer, params) {
  15953. $scope.loading = true;
  15954. var pageParams = params.url();
  15955. pageParams.keyword = $scope.keyword;
  15956. pageParams.searchFilter = $scope.searchFilter;
  15957. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  15958. $scope.loading = false;
  15959. if (page) {
  15960. params.total(page.totalElement);
  15961. $defer.resolve(page.content);
  15962. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  15963. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  15964. }
  15965. }, function (response) {
  15966. $scope.loading = false;
  15967. toaster.pop('error', '数据加载失败', response.data);
  15968. });
  15969. }
  15970. });
  15971. // 搜索框回车
  15972. $scope.onSearch = function () {
  15973. $scope.tableParams.page(1);
  15974. $scope.tableParams.reload();
  15975. };
  15976. //删除
  15977. $scope.deleteById = function (id) {
  15978. GetProductInfo.deleteById({id: id}, function (data) {
  15979. if (data.error) {
  15980. toaster.pop("error", "提示", data.error);
  15981. } else {
  15982. toaster.pop("success", "提示", "删除成功");
  15983. $timeout(function () {
  15984. $scope.tableParams.reload();
  15985. }, 500);
  15986. }
  15987. }), function (response) {
  15988. toaster.pop("error", "删除失败", response.data);
  15989. };
  15990. }
  15991. }]);
  15992. /**
  15993. * 招标单
  15994. */
  15995. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams',
  15996. '$modal', '$rootScope', 'PurcTenderInfo', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, PurcTenderInfo) {
  15997. BaseService.scrollBackToTop();
  15998. $scope.searchStatus = false;
  15999. if ($rootScope.tenderActive) {
  16000. $scope.active = $rootScope.tenderActive;
  16001. $rootScope.tenderActive = null;
  16002. } else {
  16003. $scope.active = 'todo';
  16004. }
  16005. $scope.dateZoneText = '不限';
  16006. $scope.deliveryZoneText = '不限';
  16007. $scope.condition = {dateZone: 1, deliveryZone: -1};
  16008. /* 时间筛选初始化*/
  16009. var fromDate = new Date();
  16010. var toDate = new Date();
  16011. fromDate.setMonth(fromDate.getMonth() - 1);
  16012. fromDate.setHours(0, 0, 0, 0);
  16013. toDate.setHours(23, 59, 59, 999);
  16014. $scope.condition.dateFrom = fromDate;
  16015. $scope.condition.dateTo = toDate;
  16016. $scope.changeDateZone = function (zone) {
  16017. $scope.condition.dateZone = zone;
  16018. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  16019. $scope.condition.$dateZoneOpen = false;
  16020. getDateCondition(zone, $scope.condition);
  16021. $scope.tableParams.reload();
  16022. };
  16023. $scope.changeDeliveryZone = function (zone) {
  16024. $scope.condition.deliveryZoneText = zone;
  16025. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  16026. $scope.condition.$delievryZoneOpen = false;
  16027. getDelveryCondition(zone, $scope.condition);
  16028. $scope.tableParams.page(1);
  16029. $scope.tableParams.reload();
  16030. };
  16031. $scope.setActive = function (state) {
  16032. if ($scope.active != state) {
  16033. $scope.active = state;
  16034. if ($scope.tableParams.page() == 1)
  16035. $scope.tableParams.reload();
  16036. else
  16037. $scope.tableParams.page(1);
  16038. }
  16039. };
  16040. var getTenderStatus = function (active) {
  16041. var fn = 'getMyAll';
  16042. switch (active) {
  16043. case 'done':
  16044. fn = 'getMyDone';
  16045. break;
  16046. case 'todo':
  16047. fn = 'getMyTodo';
  16048. break;
  16049. // case 'end':
  16050. // fn = 'getMyEnd';break;
  16051. case 'waiting':
  16052. fn = 'getMyWaiting';
  16053. break;
  16054. }
  16055. return fn;
  16056. };
  16057. var getService = function () {
  16058. if ($scope.searchStatus) {
  16059. return PurcTender;
  16060. }
  16061. return PurcTenderInfo;
  16062. };
  16063. $scope.tableParams = new ngTableParams({
  16064. page: 1,
  16065. count: 20,
  16066. sorting: {
  16067. 'id': 'desc'
  16068. }
  16069. }, {
  16070. total: 0,
  16071. counts: [5, 10, 25, 50],
  16072. getData: function ($defer, params) {
  16073. $scope.loading = true;
  16074. var pageParams = params.url();
  16075. var realActive = {};
  16076. pageParams.searchFilter = { // 筛选条件
  16077. keyword: $scope.keyword,
  16078. fromDate: getDateTime($scope.condition.dateFrom),
  16079. endDate: getDateTime($scope.condition.dateTo)
  16080. };
  16081. getService()[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16082. $scope.loading = false;
  16083. if (page) {
  16084. params.total(page.totalElement);
  16085. $defer.resolve(page.content);
  16086. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  16087. }
  16088. }, function (response) {
  16089. $scope.loading = false;
  16090. toaster.pop('error', '数据加载失败', response.data);
  16091. });
  16092. }
  16093. });
  16094. //获得各分类未阅读数量
  16095. var getUnreadCount = function () {
  16096. PurcTender.getPurcUnreadCount(null, function(data){
  16097. $scope.unread = data;
  16098. });
  16099. };
  16100. getUnreadCount();
  16101. //设置单据已读
  16102. $scope.setOrdersRead = function (id) {
  16103. // 如果单据本身已读,则不发送请求修改数据
  16104. if (!$scope.isUnread(id)){
  16105. return;
  16106. }
  16107. var sourceId = [];
  16108. sourceId.push(id);
  16109. PurcTender.setPurcRead({}, sourceId, function (message) {
  16110. // $scope.getUnreadIds();
  16111. getUnreadCount();
  16112. });
  16113. };
  16114. //获取未读单据id
  16115. var getUnreadIds = function (){
  16116. PurcTender.getPurcUnreadIds({}, "", function (message) {
  16117. $scope.unreadCode = message.content;
  16118. });
  16119. };
  16120. getUnreadIds();
  16121. //判断单据是否未读
  16122. $scope.isUnread = function (tender){
  16123. for (var i in $scope.unreadCode) {
  16124. if (tender.id == $scope.unreadCode[i]) {
  16125. var flag = tender.status == '待评标' && tender.overdue == 1 && tender.result != 1;
  16126. if (!flag) {
  16127. $scope.unreadCode.splice(i,1);
  16128. return false;
  16129. }
  16130. return true;
  16131. }
  16132. }
  16133. };
  16134. $scope.openDatePicker = function ($event, item, openParam) {
  16135. $event.preventDefault();
  16136. $event.stopPropagation();
  16137. item[openParam] = !item[openParam];
  16138. };
  16139. $scope.openFilterDatePicker = function ($event, item, openParam) {
  16140. $event.preventDefault();
  16141. $event.stopPropagation();
  16142. item[openParam] = !item[openParam];
  16143. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  16144. $scope.tableParams.reload();
  16145. }
  16146. };
  16147. $scope.parseDate = function (dateStr) {
  16148. if (dateStr)
  16149. return Date.parse(dateStr, 'yyyy-MM-dd');
  16150. return new Date();
  16151. };
  16152. // 选择查找日期
  16153. $scope.onDateCondition = function () {
  16154. $scope.tableParams.page(1);
  16155. $scope.tableParams.reload();
  16156. };
  16157. // 搜索框回车
  16158. $scope.onSearch = function () {
  16159. $scope.searchStatus = true;
  16160. $scope.tableParams.page(1);
  16161. $scope.tableParams.reload();
  16162. };
  16163. }]);
  16164. /**
  16165. * 新增招标单
  16166. */
  16167. 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) {
  16168. // 录入人
  16169. AuthenticationService.getAuthentication().success(function (data) {
  16170. $scope.user = data;
  16171. });
  16172. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16173. $scope.searchMethod = false;
  16174. var getService = function () {
  16175. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  16176. };
  16177. // 物料信息
  16178. $scope.tableParams = new ngTableParams({
  16179. page: 1,
  16180. count: 20,
  16181. sorting: {}
  16182. }, {
  16183. total: 0,
  16184. counts: [5, 10, 25, 50],
  16185. getData: function ($defer, params) {
  16186. $scope.loading = true;
  16187. var pageParams = params.url();
  16188. pageParams.keyword = $scope.keyword;
  16189. $scope.tip = $scope.keyword;
  16190. pageParams.searchFilter = $scope.searchFilter;
  16191. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16192. $scope.loading = false;
  16193. if (page) {
  16194. params.total(page.totalElement);
  16195. $scope.total = page.totalElement;
  16196. $defer.resolve(page.content);
  16197. }
  16198. }, function (response) {
  16199. $scope.loading = false;
  16200. toaster.pop('error', '数据加载失败', response.data);
  16201. });
  16202. }
  16203. });
  16204. // 搜索框回车
  16205. $scope.onSearch = function (keyword) {
  16206. // 每次搜索重置获取数据方法
  16207. $scope.searchMethod = false;
  16208. if(keyword != null && keyword != '') {
  16209. $scope.searchMethod = true;
  16210. }
  16211. $scope.tableParams.page(1);
  16212. $scope.tableParams.reload();
  16213. };
  16214. //在产品列表添加商品
  16215. $scope.check = function (product) {
  16216. $scope.tenderProd.push({
  16217. prodTitle: product.title,
  16218. prodCode: product.code,
  16219. brand: product.brand,
  16220. unit: product.unit,
  16221. qty: null
  16222. // 供应商企业信息
  16223. // enterpriseBaseInfo: [{}]
  16224. });
  16225. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16226. if ($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  16227. $scope.tenderProd.splice(i, 1);
  16228. }
  16229. }
  16230. };
  16231. $scope.loading = false;
  16232. // 获取收货地址列表
  16233. var loadShipAddress = function () {
  16234. ShipAddress.shipAddList({}, function (data) {
  16235. $scope.ships = data;
  16236. $scope.tender.shipadd = $scope.ships[0];
  16237. });
  16238. };
  16239. loadShipAddress();
  16240. // 获取地址信息
  16241. $http.get('resources/citydata/city.json', {
  16242. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  16243. }).then(function (response) {
  16244. $scope.provinces = response.data;
  16245. });
  16246. // 新增收货地址保存
  16247. $scope.saveShipAddress = function (ship) {
  16248. ship.address = ship.province + ship.city + ship.district;
  16249. ShipAddress.saveAddress({}, ship, function (data) {
  16250. if (data.success) {
  16251. // 获取收货地址列表
  16252. loadShipAddress();
  16253. toaster.pop('success', '提示', data.success);
  16254. }
  16255. if (data.error) {
  16256. toaster.pop('error', '提示', data.error);
  16257. }
  16258. });
  16259. };
  16260. // 可选的证照要求
  16261. $scope.certificates = [{name: '三/五证合一'}, {name: '营业执照'}, {name: '组织机构代码证'}, {name: '一般纳税人证明材料'}, {name: '统计登记证'}, {name: '社会保险登记证'}];
  16262. // 处理证照要求
  16263. var parseCertificate = function (a) {
  16264. if (a) {
  16265. var arr = a.split(',');
  16266. angular.forEach(arr, function (app) {
  16267. var contained = false;
  16268. angular.forEach($scope.certificates, function ($app) {
  16269. if ($app.name == app) {
  16270. $app.checked = true;
  16271. contained = true;
  16272. }
  16273. });
  16274. if (!contained) {
  16275. $scope.certificates.push({name: app, checked: true});
  16276. }
  16277. });
  16278. }
  16279. };
  16280. // 联想词start
  16281. // 获取品牌联想词
  16282. $scope.getSimilarBrands = function (value) {
  16283. if (value) {
  16284. // 获取品牌联想词
  16285. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  16286. return data.map(function (item) {
  16287. return item;
  16288. });
  16289. });
  16290. }
  16291. };
  16292. // 获取产品型号联想词
  16293. $scope.getSimilarCodes = function (value) {
  16294. if (value) {
  16295. // 获取产品型号联想词
  16296. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  16297. return data.map(function (item) {
  16298. return item;
  16299. })
  16300. });
  16301. }
  16302. };
  16303. // 选择类目
  16304. $scope.selectKind = function (prod) {
  16305. var submit = [];
  16306. $modal.open({
  16307. animation: true,
  16308. size: 'lg',
  16309. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  16310. controller: 'ProdKindChooseCtrl',
  16311. resolve: {
  16312. actives: function () {
  16313. return $scope.actives;
  16314. }
  16315. }
  16316. }).result.then(function (data) {
  16317. $scope.actives = data.actives;
  16318. var size = data.actives.length;
  16319. submit.gradeOneKiName = '';
  16320. submit.gradeTwoKiName = '';
  16321. submit.gradeThreeKiName = '';
  16322. if (size > 0) {
  16323. submit.gradeOneKiName = $scope.actives[0].nameCn;
  16324. prod.prodTitle = submit.gradeOneKiName;
  16325. if (size > 1) {
  16326. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  16327. prod.prodTitle = submit.gradeTwoKiName;
  16328. if (size > 2) {
  16329. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  16330. prod.prodTitle = submit.gradeThreeKiName;
  16331. }
  16332. }
  16333. }
  16334. }, function () {
  16335. });
  16336. };
  16337. // 点击联想词获取品牌信息
  16338. $scope.onAssociateBrandClick = function (brand, prod) {
  16339. if (brand instanceof String) {
  16340. prod.brand = brand;
  16341. } else if (brand instanceof Object) {
  16342. prod.brand = brand.brandCn;
  16343. }
  16344. };
  16345. // 打开品牌选择的模态框
  16346. $scope.selectBrand = function (prod) { //打开模态
  16347. var modalInstance = $modal.open({
  16348. size: 'lg',
  16349. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  16350. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  16351. });
  16352. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  16353. });
  16354. modalInstance.result.then(function (brand) {
  16355. prod.brand = brand.nameCn;
  16356. }, function (reason) {
  16357. });
  16358. };
  16359. // 点击联想词获取器件信息 带入产品分类和品牌
  16360. $scope.onAssociateCmpClick = function (cmp, prod) {
  16361. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  16362. $scope.component = data;
  16363. prod.prodCode = data.code;
  16364. prod.prodTitle = data.kind.nameCn;
  16365. prod.brand = data.brand.nameCn;
  16366. }, function (res) {
  16367. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  16368. })
  16369. };
  16370. //联想词end
  16371. $scope.condition = {dateZone: 1};
  16372. $scope.tenderProd = [];
  16373. var prod = {
  16374. prodTitle: null,
  16375. prodCode: null,
  16376. brand: null,
  16377. unit: 'PCS',
  16378. qty: null
  16379. // 供应商企业信息
  16380. // enterpriseBaseInfo: [{}]
  16381. };
  16382. $scope.tender = {
  16383. date: new Date(),
  16384. unit: 'PCS',
  16385. currency: 'RMB',
  16386. ifOpen: 1,
  16387. ifTax: 1,
  16388. invoiceType: 2,
  16389. tenderAttachs: [{}]
  16390. };
  16391. //
  16392. $scope.tenderProd.push(prod);
  16393. //增加商品
  16394. $scope.add = function (index) {
  16395. $scope.tenderProd.push({
  16396. prodTitle: null,
  16397. prodCode: null,
  16398. brand: null,
  16399. unit: 'PCS',
  16400. qty: null
  16401. // 供应商企业信息
  16402. // enterpriseBaseInfo: [{}]
  16403. });
  16404. };
  16405. //删除商品
  16406. $scope.del = function (index) {
  16407. $scope.tenderProd.splice(index, 1);
  16408. };
  16409. // 批量导入
  16410. $scope.uplodaByBatch = function () {
  16411. var modalInstance = $modal.open({
  16412. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  16413. controller: 'PurcTenderUploadCtrl',
  16414. size: 'lg',
  16415. resolve: {}
  16416. });
  16417. modalInstance.result.then(function (data) {
  16418. // 获取上传的产品明细,前台展示
  16419. angular.forEach(data, function (data) {
  16420. $scope.tenderProd.push(data);
  16421. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16422. if ($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  16423. $scope.tenderProd.splice(i, 1);
  16424. }
  16425. }
  16426. });
  16427. }, function () {
  16428. });
  16429. };
  16430. $scope.isSave = false;
  16431. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  16432. if (!angular.isUndefined($stateParams.id)) {
  16433. $scope.isSave = true; // 用于判断是新增还是已保存
  16434. $scope.loading = true;
  16435. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  16436. data.$editing = false;
  16437. $scope.tender = data;
  16438. $scope.tenderProd = data.purchaseTenderProds;
  16439. parseCertificate($scope.tender.certificate);
  16440. $scope.firstProd = data.purchaseTenderProds[0];
  16441. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  16442. // 获取供应商联系人
  16443. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function (data) {
  16444. item.saleTender.enterpriseBaseInfo.contacts = data;
  16445. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  16446. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function (contact) {
  16447. if (item.saleTender.userTel === contact.tel) {
  16448. item.saleTender.enterpriseBaseInfo.contact = contact;
  16449. }
  16450. });
  16451. });
  16452. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  16453. $scope.tenderProd.enterpriseBaseInfo = [{}];
  16454. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  16455. } else {
  16456. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  16457. }
  16458. });
  16459. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  16460. $scope.loading = false;
  16461. $scope.attaches = $scope.tender.tenderAttaches;
  16462. }, function (response) {
  16463. $scope.loading = false;
  16464. toaster.pop('error', '数据加载失败', response.data);
  16465. });
  16466. }
  16467. if (angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  16468. $rootScope.tenderVendor = [{}];
  16469. }
  16470. $scope.changeShipAddress = false;
  16471. $scope.changeAddress = function () {
  16472. if ($scope.changeShipAddress) {
  16473. $scope.changeShipAddress = false;
  16474. } else {
  16475. $scope.changeShipAddress = true;
  16476. }
  16477. };
  16478. $scope.changeContactInfo = function (en) {
  16479. if (en.changeContact) {
  16480. en.changeContact = false;
  16481. } else {
  16482. en.changeContact = true;
  16483. }
  16484. };
  16485. $scope.changeCurrency = function (tender) {
  16486. if (tender.currency !== 'RMB') {
  16487. $scope.notRMB = true;
  16488. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  16489. tender.invoiceType = 0;
  16490. } else {
  16491. $scope.notRMB = false;
  16492. }
  16493. };
  16494. // 查找供应商
  16495. $scope.dbfindVendor = function () {
  16496. var modalInstance = $modal.open({
  16497. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  16498. controller: 'DbfindVendorCtrl',
  16499. size: 'lg',
  16500. resolve: {}
  16501. });
  16502. var ifPush = true;
  16503. modalInstance.result.then(function (data) {
  16504. angular.forEach(data, function (vendor) {
  16505. // 获取供应商联系人
  16506. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function (data) {
  16507. vendor.vendorEnterprise.contacts = data;
  16508. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  16509. });
  16510. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  16511. $scope.tenderProd.enterpriseBaseInfo = [{}];
  16512. // 获取供应商联系人
  16513. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  16514. } else {
  16515. for (var i = 0; i < $scope.tenderProd.enterpriseBaseInfo.length; i++) {
  16516. ifPush = true;
  16517. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  16518. ifPush = false;
  16519. break; // 判定到已存在供应商,就终止循环。
  16520. }
  16521. }
  16522. if (ifPush) {
  16523. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  16524. }
  16525. }
  16526. });
  16527. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  16528. }, function () {
  16529. });
  16530. };
  16531. // 新增供应商联系人
  16532. $scope.addContact = function (en) {
  16533. var modalInstance = $modal.open({
  16534. animation: true,
  16535. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  16536. controller: 'AddContacCtrl',
  16537. resolve: {}
  16538. });
  16539. modalInstance.result.then(function (data) {
  16540. en.contact = data;
  16541. en.contact.venduu = en.uu;
  16542. Vendor.saveContact({}, en.contact, function (data) {
  16543. Vendor.contacts({venduu: en.uu}, {}, function (data) {
  16544. en.contacts = data;
  16545. en.contact = data[0]; // 新增的作为联系人
  16546. });
  16547. toaster.pop('success', '提示', '联系人保存成功');
  16548. }, function (response) {
  16549. toaster.pop('error', '失败', response.data);
  16550. });
  16551. });
  16552. };
  16553. // 删除一个供应商
  16554. $scope.removeVendor = function (index) {
  16555. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  16556. };
  16557. // 删除供应商时,后台删除投标单
  16558. $scope.removeSaleTender = function (id, vendUU) {
  16559. var hasSaved = false;
  16560. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function (saleTenderItem) {
  16561. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  16562. hasSaved = true;
  16563. }
  16564. });
  16565. if (hasSaved) {
  16566. PurcTender.removeSaleTender({id: id, vendUU: vendUU}, {}, function (data) {
  16567. }, function (response) {
  16568. toaster.pop('error', '提示', response.data);
  16569. });
  16570. }
  16571. };
  16572. // 删除产品明细时,后台删除产品明细
  16573. $scope.deleteProd = function (tenderProd) {
  16574. if (tenderProd.id) {
  16575. PurcTender.deleteProd({tenderProdId: tenderProd.id}, {}, function (data) {
  16576. }, function (response) {
  16577. toaster.pop('error', '提示', response.data);
  16578. });
  16579. }
  16580. };
  16581. if (!$scope.attaches) {
  16582. $scope.attaches = []; // 存放上传了的附件
  16583. }
  16584. $scope.upload = function (myFile) { // 上传附件
  16585. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  16586. $upload.upload({
  16587. url: 'tender/addTenderAttach',
  16588. file: file,
  16589. method: 'POST'
  16590. }).success(function (attach) {
  16591. $scope.attaches.push(attach);
  16592. });
  16593. };
  16594. $scope.removeAttach = function (id, index) {
  16595. $scope.attaches.splice(index, 1);
  16596. };
  16597. var sleep = function (d) {
  16598. for (var t = Date.now(); Date.now() - t <= d;);
  16599. };
  16600. // 保存和发布招标单
  16601. $scope.save = function (isPublish) {
  16602. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  16603. toaster.pop('info', '提示', '请先指定供应商');
  16604. } else {
  16605. $scope.loading = true;
  16606. // --组装证照要求
  16607. var myCertificate = [];
  16608. angular.forEach($scope.certificates, function (certificate) {
  16609. if (certificate.checked) {
  16610. myCertificate.push(certificate.name);
  16611. }
  16612. });
  16613. $scope.tender.certificate = myCertificate.join(',');
  16614. if (!$scope.tender.code) { //新增,设单号
  16615. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  16616. }
  16617. if ($scope.tender.date instanceof Date) {
  16618. $scope.tender.date = $scope.tender.date.getTime();
  16619. }
  16620. if ($scope.tender.endDate instanceof Date) {
  16621. $scope.tender.endDate = $scope.tender.endDate.getTime();
  16622. }
  16623. if ($scope.tender.publishDate instanceof Date) {
  16624. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  16625. }
  16626. if ($scope.tender.questionEndDate instanceof Date) {
  16627. $scope.tender.questionEndDate = $scope.tender.questionEndDate.getTime();
  16628. }
  16629. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  16630. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  16631. $scope.tender.purchaseTenderProds[i].index = i + 1;
  16632. }
  16633. $scope.tender.tenderAttaches = $scope.attaches;
  16634. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  16635. var enInfos = [];
  16636. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  16637. var enInfo = {
  16638. uu: null,
  16639. contact: null,
  16640. contactTel: null
  16641. };
  16642. enInfo.uu = enterpriseBaseInfo.uu;
  16643. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  16644. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  16645. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  16646. }
  16647. enInfos.push(enInfo);
  16648. });
  16649. if (isPublish) { // 发布
  16650. toaster.pop('info', '提示', '正在发布,请稍候');
  16651. $scope.tender.isPublish = 1;
  16652. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  16653. // sleep(1500); //当前方法暂停1.5秒
  16654. $scope.loading = false;
  16655. toaster.pop('success', '成功', '发布成功');
  16656. window.location.hash = '#/purc/tender';
  16657. }, function (response) {
  16658. $scope.loading = false;
  16659. toaster.pop('error', '发布失败', response.data);
  16660. });
  16661. } else { // 保存
  16662. toaster.pop('info', '提示', '正在保存,请稍候');
  16663. $scope.tender.isPublish = 0;
  16664. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  16665. $scope.loading = false;
  16666. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  16667. toaster.pop('success', '成功', '保存成功');
  16668. window.location.hash = '#/purc/tender';
  16669. }, function (response) {
  16670. $scope.loading = false;
  16671. toaster.pop('error', '保存失败', response.data);
  16672. });
  16673. }
  16674. }
  16675. };
  16676. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  16677. $scope.removeChecked = function () {
  16678. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  16679. $scope.tenderProd.enterpriseBaseInfo = [];
  16680. }
  16681. };
  16682. // 删除(在录入状态)
  16683. $scope.deleteThis = function (id) {
  16684. PurcTender.deleteOne({id: id}, {}, function (data) {
  16685. toaster.pop('info', '提示', '删除成功');
  16686. window.location.hash = '#/purc/tender';
  16687. });
  16688. };
  16689. // 更新和发布(在录入状态)
  16690. $scope.updateSaved = function (isPublish) {
  16691. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  16692. toaster.pop('info', '提示', '请先指定供应商');
  16693. } else {
  16694. $scope.loading = true;
  16695. // --组装证照要求
  16696. var myCertificate = [];
  16697. angular.forEach($scope.certificates, function (certificate) {
  16698. if (certificate.checked) {
  16699. myCertificate.push(certificate.name);
  16700. }
  16701. });
  16702. $scope.tender.certificate = myCertificate.join(',');
  16703. if ($scope.tender.endDate instanceof Date) {
  16704. $scope.tender.endDate = $scope.tender.endDate.getTime();
  16705. }
  16706. if ($scope.tender.publishDate instanceof Date) {
  16707. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  16708. }
  16709. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  16710. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  16711. $scope.tender.purchaseTenderProds[i].index = i + 1;
  16712. }
  16713. $scope.tender.tenderAttaches = $scope.attaches;
  16714. if ($scope.tender.shipadd) {
  16715. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  16716. }
  16717. angular.forEach($scope.tender.purchaseTenderProds, function (tenderProd) {
  16718. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  16719. });
  16720. var enInfos = [];
  16721. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  16722. var enInfo = {
  16723. uu: null,
  16724. contact: null,
  16725. contactTel: null
  16726. };
  16727. enInfo.uu = enterpriseBaseInfo.uu;
  16728. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  16729. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  16730. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  16731. }
  16732. enInfos.push(enInfo);
  16733. });
  16734. if (isPublish) { // 发布
  16735. toaster.pop('info', '提示', '正在发布,请稍候');
  16736. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  16737. $scope.loading = false;
  16738. toaster.pop('success', '成功', '发布成功');
  16739. window.location.hash = '#/purc/tender';
  16740. }, function (response) {
  16741. $scope.loading = false;
  16742. toaster.pop('error', '发布失败', response.data);
  16743. });
  16744. } else { // 保存
  16745. toaster.pop('info', '提示', '正在保存,请稍候');
  16746. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  16747. $scope.loading = false;
  16748. toaster.pop('success', '成功', '保存成功');
  16749. window.location.reload();
  16750. }, function (response) {
  16751. $scope.loading = false;
  16752. toaster.pop('error', '保存失败', response.data);
  16753. });
  16754. }
  16755. }
  16756. };
  16757. $scope.currentDay = function () {
  16758. return $filter('date')(new Date(), 'yyyy-MM-dd');
  16759. };
  16760. $scope.getMinDate = function () {
  16761. if ($scope.tender.endDate instanceof Date) {
  16762. var minDate = new Date($scope.tender.endDate.getTime() + 2 * 24 * 60 * 60 * 1000 + 1); // 公布结果日期与截止报价日期至少隔一天
  16763. }
  16764. 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');
  16765. };
  16766. $scope.getMaxDate = function () {
  16767. // var maxDate = angular.copy($scope.tender.publishDate);
  16768. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  16769. if ($scope.tender.publishDate instanceof Date) {
  16770. var maxDate = new Date($scope.tender.publishDate.getTime() - 24 * 60 * 60 * 1000 - 1); // 至少提前两天
  16771. }
  16772. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd') : "";
  16773. };
  16774. $scope.openDatePicker = function ($event, item, openParam) {
  16775. $event.preventDefault();
  16776. $event.stopPropagation();
  16777. item[openParam] = !item[openParam];
  16778. };
  16779. }]);
  16780. //类目选择模态框(招标产品明细)
  16781. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function ($scope, KindAPI, actives, toaster, $modalInstance) {
  16782. $scope.actives = actives;
  16783. $scope.kinds = [[], [], [], []];
  16784. // 获取子类目
  16785. var getChildren = function (pid, deep) {
  16786. KindAPI.getChildren({parentId: pid}, function (data) {
  16787. $scope.kinds[deep] = data;
  16788. }, function (response) {
  16789. toaster.pop('error', '获取子类目失败', response.data);
  16790. });
  16791. };
  16792. // 改变节点选中状态
  16793. var changeStatus = function (item, deep) {
  16794. var actives = [], level = 0;
  16795. angular.forEach($scope.kinds, function (ks, i) {
  16796. if (i > deep) {
  16797. $scope.kinds[i] = [];
  16798. } else {
  16799. angular.forEach(ks, function (k, j) {
  16800. if (i == deep) {
  16801. if (k.id == item.id) {
  16802. $scope.kinds[i][j].$active = true;
  16803. actives.push(k);
  16804. } else {
  16805. k.$active = null;
  16806. }
  16807. } else {
  16808. if (k.$active) {
  16809. actives.push(k);
  16810. }
  16811. }
  16812. });
  16813. }
  16814. });
  16815. // 选择的节点
  16816. $scope.actives = actives;
  16817. $scope.active = item;
  16818. // 当前可操作的层级
  16819. if (deep < 3) {
  16820. $scope.activeDeep = deep + 1;
  16821. }
  16822. };
  16823. // 节点点击后获取子类目,节点被选中
  16824. $scope.onItemClick = function (item, deep) {
  16825. changeStatus(item, deep);
  16826. if (!item.isLeaf) {
  16827. getChildren(item.id, deep + 1);
  16828. }
  16829. };
  16830. // 重新加载数据
  16831. function reload(deep) {
  16832. var pid;
  16833. if (deep) {
  16834. pid = $scope.actives[deep - 1].id;
  16835. } else {
  16836. pid = 0;
  16837. deep = 0;
  16838. }
  16839. getChildren(pid, deep);
  16840. }
  16841. // 初始加载数据,获取第一层的类目
  16842. if ($scope.actives) {
  16843. angular.forEach($scope.actives, function (v, k) {
  16844. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  16845. $scope.kinds[k] = data;
  16846. angular.forEach($scope.kinds[k], function (kind, i) {
  16847. if (kind.id == v.id) {
  16848. $scope.kinds[k][i].$active = true;
  16849. $scope.actives[k] = $scope.kinds[k][i];
  16850. }
  16851. })
  16852. }, function (response) {
  16853. toaster.pop('error', '获取子类目失败', response.data);
  16854. });
  16855. });
  16856. } else {
  16857. reload();
  16858. }
  16859. // 取消
  16860. $scope.cancel = function () {
  16861. $modalInstance.dismiss();
  16862. };
  16863. // 确认选择
  16864. $scope.check = function () {
  16865. var a = {
  16866. active: $scope.active,
  16867. actives: $scope.actives
  16868. };
  16869. $modalInstance.close(a);
  16870. };
  16871. }]);
  16872. //品牌选择模态框的controller
  16873. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function ($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  16874. $scope.filter = {};
  16875. $scope.brandsTableParams = new ngTableParams({
  16876. page: 1,
  16877. count: 6,
  16878. sorting: {
  16879. nameCn: 'asc'
  16880. }
  16881. }, {
  16882. total: 0,
  16883. counts: [],
  16884. getData: function ($defer, params) {
  16885. var param = BaseService.parseParams(params.url());
  16886. param.keyword = $scope.filter.keyword;
  16887. var keyword = $scope.filter.keyword;
  16888. // param.keyword = $scope.filter.keyword;
  16889. BrandActiveAPI.getSimpleInfoPage(param, {}, function (page) {
  16890. if (page) {
  16891. params.total(page.totalElements);
  16892. $defer.resolve(page.content);
  16893. }
  16894. }, function () {
  16895. });
  16896. }
  16897. });
  16898. // 搜索
  16899. $scope.search = function () {
  16900. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  16901. $scope.brandsTableParams.page(1);
  16902. $scope.brandsTableParams.reload();
  16903. };
  16904. // 选择
  16905. $scope.select = function (brand) {
  16906. $modalInstance.close(brand);
  16907. };
  16908. // 关闭
  16909. $scope.cancel = function () {
  16910. $modalInstance.dismiss();
  16911. };
  16912. }]);
  16913. /**
  16914. * 招标单批量导入
  16915. */
  16916. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  16917. // 通过excel批量上传物料
  16918. $scope.result = null;
  16919. $scope.upload = function () {
  16920. var file = $scope.myFiles[0];
  16921. $upload.upload({
  16922. url: 'tender/release/excel',
  16923. file: file,
  16924. method: 'POST'
  16925. }).success(function (data) {
  16926. $scope.result = data;
  16927. $scope.success = $scope.result.success;
  16928. $scope.total = $scope.result.total;
  16929. $scope.alters = $scope.result.alters;
  16930. }).error(function (response) {
  16931. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  16932. });
  16933. };
  16934. // 查看范例
  16935. $scope.showImg = function () {
  16936. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  16937. box.show();
  16938. box.find('img').attr('src', src);
  16939. box.find('a').click(function () {
  16940. box.hide();
  16941. });
  16942. box.dblclick(function () {
  16943. box.hide();
  16944. });
  16945. };
  16946. // 下载模板
  16947. $scope.download = function () {
  16948. window.location.href = 'tender/upload/template';
  16949. };
  16950. $scope.enSure = function () {
  16951. $modalInstance.close($scope.result.items);
  16952. }
  16953. $scope.cancel = function () {
  16954. $modalInstance.dismiss();
  16955. }
  16956. }]);
  16957. /**
  16958. * 评标
  16959. */
  16960. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, CurrentRole) {
  16961. BaseService.scrollBackToTop();
  16962. // 获取当前用户是否为普通用户
  16963. CurrentRole.isUser({}, {}, function (data) {
  16964. $scope.isUser = data.isUser;
  16965. });
  16966. $scope.tenderItems = [];
  16967. // 采购方获取评标单
  16968. var evaluation = function () {
  16969. $scope.loading = true;
  16970. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  16971. data.$editing = false;
  16972. $scope.tender = data;
  16973. $scope.tableParams = new ngTableParams({}, {dataset: data});
  16974. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  16975. $scope.loading = false;
  16976. }, function (response) {
  16977. $scope.loading = false;
  16978. toaster.pop('error', '数据加载失败', response.data);
  16979. });
  16980. };
  16981. evaluation();
  16982. $scope.orderType = '';
  16983. // $scope.dir = '-';
  16984. // 改变排序顺序
  16985. $scope.changeOrder = function (type) {
  16986. $scope.orderType = type;
  16987. };
  16988. $scope.submit = function (tender) {
  16989. var canSubmit = false;
  16990. var hasDecide = false;
  16991. angular.forEach(tender.purchaseTenderProds, function (tenderProd) {
  16992. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  16993. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  16994. hasDecide = true;
  16995. }
  16996. });
  16997. if (hasDecide) {
  16998. canSubmit = true;
  16999. }
  17000. });
  17001. if (!canSubmit) {
  17002. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  17003. } else {
  17004. PurcTender.decide(tender, function () {
  17005. toaster.pop('success', '确认成功');
  17006. window.location.hash = '#/purc/tender';
  17007. }, function (response) {
  17008. toaster.pop('error', '确认失败', response.data);
  17009. });
  17010. }
  17011. }
  17012. }]);
  17013. /**
  17014. * 客户招标
  17015. *
  17016. */
  17017. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', 'PurcTenderInfo',
  17018. function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise, PurcTenderInfo) {
  17019. BaseService.scrollBackToTop();
  17020. if ($rootScope.active) {
  17021. $scope.active = $rootScope.active;
  17022. $rootScope.active = null;
  17023. } else {
  17024. $scope.active = 'todo';
  17025. }
  17026. $scope.searchStatus = false;
  17027. /**
  17028. * 改变类型
  17029. */
  17030. var getTypeCondition = function (zone, condition) {
  17031. if (zone == -1) {
  17032. condition.ifOpen = null;
  17033. } else if (zone == 1) {
  17034. condition.ifOpen = 1;
  17035. } else {
  17036. condition.ifOpen = 0;
  17037. }
  17038. };
  17039. $scope.dateZoneText = '不限';
  17040. $scope.typeText = '全部';
  17041. $scope.deliveryZoneText = '不限';
  17042. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17043. /* 时间筛选初始化*/
  17044. var fromDate = new Date();
  17045. var toDate = new Date();
  17046. fromDate.setMonth(fromDate.getMonth() - 1);
  17047. fromDate.setHours(0, 0, 0, 0);
  17048. toDate.setHours(23, 59, 59, 999);
  17049. $scope.condition.dateFrom = fromDate;
  17050. $scope.condition.dateTo = toDate;
  17051. $scope.changeDateZone = function (zone) {
  17052. $scope.condition.dateZone = zone;
  17053. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17054. $scope.condition.$dateZoneOpen = false;
  17055. getDateCondition(zone, $scope.condition);
  17056. $scope.tableParams.page(1);
  17057. $scope.tableParams.reload();
  17058. };
  17059. $scope.changeDeliveryZone = function (zone) {
  17060. $scope.condition.deliveryZoneText = zone;
  17061. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17062. $scope.condition.$delievryZoneOpen = false;
  17063. getDelveryCondition(zone, $scope.condition);
  17064. $scope.tableParams.page(1);
  17065. $scope.tableParams.reload();
  17066. };
  17067. $scope.changeType = function (type) {
  17068. $scope.condition.type = type;
  17069. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17070. getTypeCondition(type, $scope.condition);
  17071. $scope.tableParams.reload();
  17072. };
  17073. $scope.setActive = function (state) {
  17074. if ($scope.active != state) {
  17075. $scope.active = state;
  17076. if ($scope.tableParams.page() == 1)
  17077. $scope.tableParams.reload();
  17078. else
  17079. $scope.tableParams.page(1);
  17080. }
  17081. };
  17082. var getService = function () {
  17083. if ($scope.searchStatus) {
  17084. return PurcTender;
  17085. }
  17086. return PurcTenderInfo;
  17087. };
  17088. $scope.tableParams = new ngTableParams({
  17089. page: 1,
  17090. count: 20,
  17091. sorting: {
  17092. 'id': 'desc'
  17093. }
  17094. }, {
  17095. total: 0,
  17096. counts: [5, 10, 25, 50],
  17097. getData: function ($defer, params) {
  17098. $scope.loading = true;
  17099. var pageParams = params.url();
  17100. var realActive = {};
  17101. pageParams.searchFilter = { // 筛选条件
  17102. keyword: $scope.keyword,
  17103. pt_ifopen: $scope.condition.ifOpen,
  17104. fromDate: getDateTime($scope.condition.dateFrom),
  17105. endDate: getDateTime($scope.condition.dateTo)
  17106. };
  17107. AccountEnterprise.get({}, function (data) {
  17108. $scope.currentEn = data;
  17109. });
  17110. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17111. $scope.loading = false;
  17112. if (page) {
  17113. params.total(page.totalElement);
  17114. $defer.resolve(page.content);
  17115. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17116. angular.forEach(page.content, function (purcTender) {
  17117. purcTender.vendorHasBid = false;
  17118. angular.forEach(purcTender.purchaseTenderProds, function (tenderProd) {
  17119. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17120. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  17121. tenderProd.currentItem = saleTenderItem;
  17122. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  17123. purcTender.vendorHasBid = true;
  17124. }
  17125. }
  17126. });
  17127. });
  17128. });
  17129. }
  17130. }, function (response) {
  17131. $scope.loading = false;
  17132. toaster.pop('error', '数据加载失败', response.data);
  17133. });
  17134. }
  17135. });
  17136. //获得各分类未阅读数量
  17137. var getUnreadCount = function () {
  17138. PurcTender.getUnreadCount(null, function (data) {
  17139. $scope.unread = data;
  17140. });
  17141. };
  17142. getUnreadCount();
  17143. //设置单据已读
  17144. $scope.setOrdersRead = function (id) {
  17145. // 如果单据本身已读,则不发送请求修改数据
  17146. if (!$scope.isUnread(id)){
  17147. return;
  17148. }
  17149. var sourceId = [];
  17150. sourceId.push(id);
  17151. PurcTender.setRead({}, sourceId, function (message) {
  17152. // $scope.getUnreadIds();
  17153. getUnreadCount();
  17154. });
  17155. };
  17156. var getUnreadIds = function () {
  17157. PurcTender.getUnreadIds({}, "", function (message) {
  17158. $scope.unreadCode = message.content;
  17159. });
  17160. };
  17161. getUnreadIds();
  17162. $scope.isUnread = function (id) {
  17163. for (var i in $scope.unreadCode) {
  17164. if (id == $scope.unreadCode[i]) {
  17165. return true;
  17166. }
  17167. }
  17168. };
  17169. $scope.openDatePicker = function ($event, item, openParam) {
  17170. $event.preventDefault();
  17171. $event.stopPropagation();
  17172. item[openParam] = !item[openParam];
  17173. };
  17174. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17175. $event.preventDefault();
  17176. $event.stopPropagation();
  17177. item[openParam] = !item[openParam];
  17178. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17179. $scope.tableParams.reload();
  17180. }
  17181. };
  17182. $scope.parseDate = function (dateStr) {
  17183. if (dateStr)
  17184. return Date.parse(dateStr, 'yyyy-MM-dd');
  17185. return new Date();
  17186. };
  17187. // 选择查找日期
  17188. $scope.onDateCondition = function () {
  17189. $scope.tableParams.page(1);
  17190. $scope.tableParams.reload();
  17191. };
  17192. // 搜索框回车
  17193. $scope.onSearch = function () {
  17194. $scope.searchStatus = true;
  17195. $scope.tableParams.page(1);
  17196. $scope.tableParams.reload();
  17197. };
  17198. }]);
  17199. /**
  17200. * 招标提问列表
  17201. *
  17202. */
  17203. app.controller('SaleTenderQuestionListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17204. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17205. BaseService.scrollBackToTop();
  17206. if ($rootScope.active) {
  17207. $scope.active = $rootScope.active;
  17208. $rootScope.active = null;
  17209. } else {
  17210. $scope.active = 'todo';
  17211. }
  17212. $scope.searchStatus = false;
  17213. /**
  17214. * 改变类型
  17215. */
  17216. var getTypeCondition = function (zone, condition) {
  17217. if (zone == -1) {
  17218. condition.ifOpen = null;
  17219. } else if (zone == 1) {
  17220. condition.ifOpen = 1;
  17221. } else {
  17222. condition.ifOpen = 0;
  17223. }
  17224. };
  17225. $scope.dateZoneText = '不限';
  17226. $scope.typeText = '全部';
  17227. $scope.deliveryZoneText = '不限';
  17228. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17229. /* 时间筛选初始化*/
  17230. var fromDate = new Date();
  17231. var toDate = new Date();
  17232. fromDate.setMonth(fromDate.getMonth() - 1);
  17233. fromDate.setHours(0, 0, 0, 0);
  17234. toDate.setHours(23, 59, 59, 999);
  17235. $scope.condition.dateFrom = fromDate;
  17236. $scope.condition.dateTo = toDate;
  17237. $scope.changeDateZone = function (zone) {
  17238. $scope.condition.dateZone = zone;
  17239. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17240. $scope.condition.$dateZoneOpen = false;
  17241. getDateCondition(zone, $scope.condition);
  17242. $scope.tableParams.page(1);
  17243. $scope.tableParams.reload();
  17244. };
  17245. $scope.changeDeliveryZone = function (zone) {
  17246. $scope.condition.deliveryZoneText = zone;
  17247. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17248. $scope.condition.$delievryZoneOpen = false;
  17249. getDelveryCondition(zone, $scope.condition);
  17250. $scope.tableParams.page(1);
  17251. $scope.tableParams.reload();
  17252. };
  17253. $scope.changeType = function (type) {
  17254. $scope.condition.type = type;
  17255. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17256. getTypeCondition(type, $scope.condition);
  17257. $scope.tableParams.reload();
  17258. };
  17259. $scope.setActive = function (state) {
  17260. if ($scope.active != state) {
  17261. $scope.active = state;
  17262. if ($scope.tableParams.page() == 1)
  17263. $scope.tableParams.reload();
  17264. else
  17265. $scope.tableParams.page(1);
  17266. }
  17267. };
  17268. //TODO 增加直接从数据库取方法之后修改
  17269. var getService = function () {
  17270. if ($scope.searchStatus) {
  17271. return SaleTenderQuestion;
  17272. }
  17273. return SaleTenderQuestion;
  17274. };
  17275. $scope.tableParams = new ngTableParams({
  17276. page: 1,
  17277. count: 20,
  17278. sorting: {
  17279. 'id': 'desc'
  17280. }
  17281. }, {
  17282. total: 0,
  17283. counts: [5, 10, 25, 50],
  17284. getData: function ($defer, params) {
  17285. $scope.loading = true;
  17286. var pageParams = params.url();
  17287. var realActive = {};
  17288. pageParams.searchFilter = { // 筛选条件
  17289. keyword: $scope.keyword,
  17290. fromDate: getDateTime($scope.condition.dateFrom),
  17291. endDate: getDateTime($scope.condition.dateTo)
  17292. };
  17293. AccountEnterprise.get({}, function (data) {
  17294. $scope.currentEn = data;
  17295. });
  17296. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17297. $scope.loading = false;
  17298. params.total(page.totalElement);
  17299. $defer.resolve(page.content);
  17300. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17301. }, function (response) {
  17302. $scope.loading = false;
  17303. toaster.pop('error', '数据加载失败', response.data);
  17304. });
  17305. }
  17306. });
  17307. //TODO 获得各分类未阅读数量
  17308. //TODO 设置单据已读
  17309. $scope.openDatePicker = function ($event, item, openParam) {
  17310. $event.preventDefault();
  17311. $event.stopPropagation();
  17312. item[openParam] = !item[openParam];
  17313. };
  17314. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17315. $event.preventDefault();
  17316. $event.stopPropagation();
  17317. item[openParam] = !item[openParam];
  17318. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17319. $scope.tableParams.reload();
  17320. }
  17321. };
  17322. $scope.parseDate = function (dateStr) {
  17323. if (dateStr)
  17324. return Date.parse(dateStr, 'yyyy-MM-dd');
  17325. return new Date();
  17326. };
  17327. // 选择查找日期
  17328. $scope.onDateCondition = function () {
  17329. $scope.tableParams.page(1);
  17330. $scope.tableParams.reload();
  17331. };
  17332. // 搜索框回车
  17333. $scope.onSearch = function (keyword) {
  17334. // 每次搜索重置获取数据方法
  17335. $scope.searchMethod = false;
  17336. if(keyword != null && keyword != '') {
  17337. $scope.searchMethod = true;
  17338. }
  17339. $scope.tableParams.page(1);
  17340. $scope.tableParams.reload();
  17341. };
  17342. }]);
  17343. /**
  17344. * 投标单提问单详情
  17345. */
  17346. app.controller('SaleTenderQuestionDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams'
  17347. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams){
  17348. BaseService.scrollBackToTop();
  17349. $scope.loading = true;
  17350. var loadData = function () {
  17351. SaleTenderQuestion.getDetail({id: $stateParams.id}, function(data){
  17352. $scope.loading = false;
  17353. $scope.question = data;
  17354. } , function (response) {
  17355. $scope.loading = false;
  17356. toaster.pop('error', '数据加载失败');
  17357. });
  17358. };
  17359. loadData();
  17360. }]);
  17361. /**
  17362. * 招标答疑列表
  17363. *
  17364. */
  17365. app.controller('PurcTenderAnswerListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17366. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17367. BaseService.scrollBackToTop();
  17368. if ($rootScope.active) {
  17369. $scope.active = $rootScope.active;
  17370. $rootScope.active = null;
  17371. } else {
  17372. $scope.active = 'todo';
  17373. }
  17374. $scope.searchStatus = false;
  17375. /**
  17376. * 改变类型
  17377. */
  17378. var getTypeCondition = function (zone, condition) {
  17379. if (zone == -1) {
  17380. condition.ifOpen = null;
  17381. } else if (zone == 1) {
  17382. condition.ifOpen = 1;
  17383. } else {
  17384. condition.ifOpen = 0;
  17385. }
  17386. };
  17387. /**
  17388. * 当前页面状态按钮过滤
  17389. */
  17390. var getAnswer = function (active) {
  17391. var fn = 'getAllAnswer';
  17392. switch (active) {
  17393. case 'done':
  17394. fn = 'getDoneAnswer';
  17395. break;
  17396. case 'todo':
  17397. fn = 'getTodoAnswer';
  17398. break;
  17399. }
  17400. return fn;
  17401. };
  17402. $scope.dateZoneText = '不限';
  17403. $scope.typeText = '全部';
  17404. $scope.deliveryZoneText = '不限';
  17405. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17406. /* 时间筛选初始化*/
  17407. var fromDate = new Date();
  17408. var toDate = new Date();
  17409. fromDate.setMonth(fromDate.getMonth() - 1);
  17410. fromDate.setHours(0, 0, 0, 0);
  17411. toDate.setHours(23, 59, 59, 999);
  17412. $scope.condition.dateFrom = fromDate;
  17413. $scope.condition.dateTo = toDate;
  17414. $scope.changeDateZone = function (zone) {
  17415. $scope.condition.dateZone = zone;
  17416. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17417. $scope.condition.$dateZoneOpen = false;
  17418. getDateCondition(zone, $scope.condition);
  17419. $scope.tableParams.page(1);
  17420. $scope.tableParams.reload();
  17421. };
  17422. $scope.changeDeliveryZone = function (zone) {
  17423. $scope.condition.deliveryZoneText = zone;
  17424. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17425. $scope.condition.$delievryZoneOpen = false;
  17426. getDelveryCondition(zone, $scope.condition);
  17427. $scope.tableParams.page(1);
  17428. $scope.tableParams.reload();
  17429. };
  17430. $scope.changeType = function (type) {
  17431. $scope.condition.type = type;
  17432. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17433. getTypeCondition(type, $scope.condition);
  17434. $scope.tableParams.reload();
  17435. };
  17436. $scope.setActive = function (state) {
  17437. if ($scope.active != state) {
  17438. $scope.active = state;
  17439. if ($scope.tableParams.page() == 1)
  17440. $scope.tableParams.reload();
  17441. else
  17442. $scope.tableParams.page(1);
  17443. }
  17444. };
  17445. //TODO 增加直接从数据库取方法之后修改
  17446. var getService = function () {
  17447. if ($scope.searchStatus) {
  17448. return SaleTenderQuestion;
  17449. }
  17450. return SaleTenderQuestion;
  17451. };
  17452. $scope.tableParams = new ngTableParams({
  17453. page: 1,
  17454. count: 20,
  17455. sorting: {
  17456. 'id': 'desc'
  17457. }
  17458. }, {
  17459. total: 0,
  17460. counts: [5, 10, 25, 50],
  17461. getData: function ($defer, params) {
  17462. $scope.loading = true;
  17463. var pageParams = params.url();
  17464. var realActive = {};
  17465. pageParams.searchFilter = { // 筛选条件
  17466. keyword: $scope.keyword,
  17467. fromDate: getDateTime($scope.condition.dateFrom),
  17468. endDate: getDateTime($scope.condition.dateTo)
  17469. };
  17470. AccountEnterprise.get({}, function (data) {
  17471. $scope.currentEn = data;
  17472. });
  17473. getService()[getAnswer($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17474. $scope.loading = false;
  17475. params.total(page.totalElement);
  17476. $defer.resolve(page.content);
  17477. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17478. }, function (response) {
  17479. $scope.loading = false;
  17480. toaster.pop('error', '数据加载失败', response.data);
  17481. });
  17482. }
  17483. });
  17484. //TODO 获得各分类未阅读数量
  17485. //TODO 设置单据已读
  17486. $scope.openDatePicker = function ($event, item, openParam) {
  17487. $event.preventDefault();
  17488. $event.stopPropagation();
  17489. item[openParam] = !item[openParam];
  17490. };
  17491. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17492. $event.preventDefault();
  17493. $event.stopPropagation();
  17494. item[openParam] = !item[openParam];
  17495. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17496. $scope.tableParams.reload();
  17497. }
  17498. };
  17499. $scope.parseDate = function (dateStr) {
  17500. if (dateStr)
  17501. return Date.parse(dateStr, 'yyyy-MM-dd');
  17502. return new Date();
  17503. };
  17504. // 选择查找日期
  17505. $scope.onDateCondition = function () {
  17506. $scope.tableParams.page(1);
  17507. $scope.tableParams.reload();
  17508. };
  17509. // 搜索框回车
  17510. $scope.onSearch = function (keyword) {
  17511. // 每次搜索重置获取数据方法
  17512. $scope.searchMethod = false;
  17513. if(keyword != null && keyword != '') {
  17514. $scope.searchMethod = true;
  17515. }
  17516. $scope.tableParams.page(1);
  17517. $scope.tableParams.reload();
  17518. };
  17519. }]);
  17520. /**
  17521. * 招标答疑单详情
  17522. */
  17523. app.controller('PurcTenderAnswerDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams', '$modal'
  17524. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams, $modal){
  17525. BaseService.scrollBackToTop();
  17526. $scope.loading = true;
  17527. var loadData = function () {
  17528. SaleTenderQuestion.getAnswerDetail({id: $stateParams.id}, function(data){
  17529. $scope.loading = false;
  17530. $scope.answer = data;
  17531. var now = new Date();
  17532. if ($scope.answer.questionEndDate < now.getTime()) {
  17533. $scope.answer.questionEnd = 1;
  17534. } else {
  17535. $scope.answer.questionEnd = 0;
  17536. }
  17537. } , function (response) {
  17538. $scope.loading = false;
  17539. toaster.pop('error', '数据加载失败');
  17540. });
  17541. };
  17542. loadData();
  17543. // 回答
  17544. $scope.sendAnswer = function (){
  17545. var modalInstance = $modal.open({
  17546. animation: true,
  17547. templateUrl: 'static/tpl/index/purc/tender_answer.html',
  17548. controller: 'PurcTenderAnswerCtrl',
  17549. size: 'lg',
  17550. resolve: {
  17551. answer: function () {
  17552. return $scope.answer;
  17553. } //传递当前答疑单到模态框Controller
  17554. }
  17555. });
  17556. modalInstance.result.then(function () {
  17557. toaster.pop('success', '答疑成功');
  17558. }, function () {
  17559. });
  17560. };
  17561. }]);
  17562. /**
  17563. * 招标单答疑
  17564. */
  17565. app.controller('PurcTenderAnswerCtrl', ['$scope', 'answer','$modalInstance', '$upload', 'toaster', function($scope, answer, $modalInstance, $upload ,toaster){
  17566. $scope.answer = answer;
  17567. $scope.cancel = function() {
  17568. $modalInstance.dismiss();
  17569. };
  17570. //确认回答
  17571. $scope.ok = function (form) {
  17572. $scope.loading = true;
  17573. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  17574. $upload.upload({
  17575. url: 'tender/question/answer/send',
  17576. method: 'POST',
  17577. file: file,
  17578. data: {
  17579. json: $scope.answer
  17580. }
  17581. }).success(function (data) {
  17582. $scope.loading = false;
  17583. $modalInstance.close('success');
  17584. }).error(function (data) {
  17585. $scope.loading = false;
  17586. toaster.pop('error', '错误', '出现异常,答疑失败');
  17587. });
  17588. };
  17589. }]);
  17590. /**
  17591. * 平台公开招标
  17592. *
  17593. */
  17594. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17595. BaseService.scrollBackToTop();
  17596. /**
  17597. * 改变单据日期范围
  17598. */
  17599. var getTenderDateCondition = function (zone, condition) {
  17600. var date = new Date();
  17601. if (zone == -1) {
  17602. condition.dateFrom = null;
  17603. condition.dateTo = null;
  17604. } else if (zone == 7) { // 一星期内
  17605. date.setDate(date.getDate() - 7);
  17606. condition.dateFrom = date;
  17607. condition.dateTo = new Date();
  17608. } else if (zone == 1) { // 一个月内
  17609. date.setMonth(date.getMonth() - 1);
  17610. condition.dateFrom = date;
  17611. condition.dateTo = new Date();
  17612. } else if (zone == 3) { // 三个月内
  17613. date.setMonth(date.getMonth() - 3);
  17614. condition.dateFrom = date;
  17615. condition.dateTo = new Date();
  17616. } else if (zone == 6) { // 半年内
  17617. date.setMonth(date.getMonth() - 6);
  17618. condition.dateFrom = date;
  17619. condition.dateTo = new Date();
  17620. } else { // 一年内
  17621. date.setYear(date.getYear() - 1);
  17622. condition.dateFrom = date;
  17623. condition.dateTo = new Date();
  17624. }
  17625. };
  17626. $scope.active = 'all';
  17627. $scope.dateZoneText = '不限';
  17628. $scope.deliveryZoneText = '不限';
  17629. $scope.condition = {dateZone: -1};
  17630. $scope.changeDateZone = function (zone) {
  17631. $scope.condition.dateZone = zone;
  17632. $scope.condition.$dateZoneOpen = false;
  17633. getTenderDateCondition(zone, $scope.condition);
  17634. $scope.tableParams.page(1);
  17635. $scope.tableParams.reload();
  17636. };
  17637. $scope.openDatePicker = function ($event, item, openParam) {
  17638. $event.preventDefault();
  17639. $event.stopPropagation();
  17640. item[openParam] = !item[openParam];
  17641. };
  17642. $scope.parseDate = function (dateStr) {
  17643. if (dateStr)
  17644. return Date.parse(dateStr, 'yyyy-MM-dd');
  17645. return new Date();
  17646. };
  17647. // 选择查找日期
  17648. $scope.onDateCondition = function () {
  17649. $scope.tableParams.page(1);
  17650. $scope.tableParams.reload();
  17651. };
  17652. var getOpenState = function (active) {
  17653. var fn = 'getOpenAll';
  17654. switch (active) {
  17655. case 'all':
  17656. fn = 'getOpenAll';
  17657. break;
  17658. // case 'done':
  17659. // fn = 'getOpenDone';break;
  17660. case 'todo':
  17661. fn = 'getOpenTodo';
  17662. break;
  17663. case 'end':
  17664. fn = 'getOpenEnd';
  17665. break;
  17666. // case 'waiting':
  17667. // fn = 'getOpenWaiting';break;
  17668. }
  17669. return fn;
  17670. };
  17671. $scope.tableParams = new ngTableParams({
  17672. page: 1,
  17673. count: 20,
  17674. sorting: {
  17675. 'tender.endDate': 'desc',
  17676. 'tender.enterprise.enName': 'asc',
  17677. 'tender.code': 'asc'
  17678. }
  17679. }, {
  17680. total: 0,
  17681. counts: [],
  17682. getData: function ($defer, params) {
  17683. $scope.loading = true;
  17684. var pageParams = params.url();
  17685. var realActive = {};
  17686. pageParams.searchFilter = { // 筛选条件
  17687. keyword: $scope.keyword,
  17688. fromDate: getDateTime($scope.condition.dateFrom),
  17689. endDate: getDateTime($scope.condition.dateTo)
  17690. };
  17691. AccountEnterprise.get({}, function (data) {
  17692. $scope.currentEn = data;
  17693. });
  17694. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17695. $scope.loading = false;
  17696. if (page) {
  17697. params.total(page.totalElement);
  17698. $defer.resolve(page.content);
  17699. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17700. }
  17701. }, function (response) {
  17702. $scope.loading = false;
  17703. toaster.pop('error', '数据加载失败', response.data);
  17704. });
  17705. }
  17706. });
  17707. $scope.toDetail = function (id) {
  17708. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  17709. };
  17710. // 搜索框回车
  17711. $scope.onSearch = function () {
  17712. $scope.tableParams.page(1);
  17713. $scope.tableParams.reload();
  17714. };
  17715. }]);
  17716. /**
  17717. * 采购方查看供应商投标单
  17718. */
  17719. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  17720. $scope.loading = true;
  17721. PurcTender.getVendorSaleTenderDetail({tenderId: $stateParams.id, vendUU:$stateParams.vendUU}, function (data) {
  17722. $scope.saleTender = data.saleTender;
  17723. $scope.tender = data.tender;
  17724. $scope.loading = false;
  17725. }, function (response) {
  17726. $scope.loading = false;
  17727. toaster.pop('error', '数据加载失败', response.data);
  17728. });
  17729. }]);
  17730. /**
  17731. * 查看投标单详情
  17732. */
  17733. 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) {
  17734. BaseService.scrollBackToTop();
  17735. if (!$scope.attaches) {
  17736. $scope.attaches = []; // 存放上传了的附件
  17737. }
  17738. AccountEnterprise.get({}, function (data) {
  17739. $scope.currentEn = data;
  17740. });
  17741. // 获取当前用户是否为普通用户
  17742. CurrentRole.isUser({}, {}, function (data) {
  17743. $scope.isUser = data.isUser;
  17744. });
  17745. $scope.loading = true;
  17746. PurcTender.getSaleTenderDetail({tenderId: $stateParams.id}, function (data) {
  17747. $scope.saleTender = data.saleTender;
  17748. $scope.tender = data.tender;
  17749. $scope.loading = false;
  17750. }, function (response) {
  17751. $scope.loading = false;
  17752. toaster.pop('error', '数据加载失败', response.data);
  17753. });
  17754. // 提问
  17755. $scope.sendQuestion = function (){
  17756. var modalInstance = $modal.open({
  17757. animation: true,
  17758. templateUrl: 'static/tpl/index/sale/tender_question.html',
  17759. controller: 'SaleTenderQuestionCtrl',
  17760. size: 'lg',
  17761. resolve: {
  17762. saleTender: function () {
  17763. return $scope.saleTender;
  17764. } //传递当前投标单到模态框Controller
  17765. }
  17766. });
  17767. modalInstance.result.then(function () {
  17768. toaster.pop('success', '提问成功');
  17769. }, function () {
  17770. });
  17771. };
  17772. $scope.upload = function (myFile) { // 上传附件
  17773. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  17774. $upload.upload({
  17775. url: 'tender/addTenderItemAttach',
  17776. file: file,
  17777. method: 'POST'
  17778. }).success(function (attach) {
  17779. $scope.attaches.push(attach);
  17780. });
  17781. };
  17782. $scope.removeAttach = function (attachId, index) {
  17783. $scope.attaches.splice(index, 1);
  17784. };
  17785. var taxrateYes = false;
  17786. var cycleYes = false;
  17787. var priceYes = false;
  17788. $scope.canSave = false;
  17789. $scope.validateThis = function (value, type) {
  17790. if ("" != value) {
  17791. switch (type) {
  17792. case 'taxrate':
  17793. var regex = /^\+?[0-9][0-9]{0,1}$/;
  17794. if (regex.test(value)) {
  17795. taxrateYes = true;
  17796. } else {
  17797. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  17798. }
  17799. break;
  17800. case 'cycle':
  17801. regex = /^\+?[1-9][0-9]*$/;
  17802. if (regex.test(value)) {
  17803. cycleYes = true;
  17804. } else {
  17805. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  17806. }
  17807. break;
  17808. case 'price':
  17809. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  17810. if (regex.test(value) && value !== 0) {
  17811. priceYes = true;
  17812. } else {
  17813. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  17814. }
  17815. break;
  17816. }
  17817. }
  17818. };
  17819. $scope.emNumYes = true;
  17820. $scope.validEmNum = function (value) {
  17821. var regex = /^\+?[1-9][0-9]*$/;
  17822. if (!regex.test(value) || value === 0 || value !== null) {
  17823. $scope.emNumYes = false;
  17824. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  17825. }
  17826. };
  17827. $scope.validateProds = function (saleTender) {
  17828. $scope.canSave = true;
  17829. var cycleRegex = /^\+?[1-9][0-9]*$/;
  17830. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  17831. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  17832. if ($scope.tender.ifAll == 1) { // 全包时需要所有信息都填写并合法才可以投标
  17833. // 全包全部需要填写,且需要符合正则式
  17834. angular.forEach(saleTender.saleTenderItems, function(item) {
  17835. if ((!item.cycle || !item.price) || (!cycleRegex.test(item.cycle) || !priceRegex.test(item.price))) {
  17836. $scope.canSave = false;
  17837. }
  17838. });
  17839. if (!saleTender.cycle || !saleTender.taxrate || !cycleRegex.test(saleTender.cycle) || !taxrateRegex.test(saleTender.taxrate)) {
  17840. $scope.canSave = false;
  17841. }
  17842. } else { // 非全包模式
  17843. angular.forEach(saleTender.saleTenderItems, function(item) {
  17844. if (item.cycle || item.taxrate || item.price) {
  17845. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  17846. // 判断填写过的有为0或不符合正则式的,设置不能保存
  17847. if (!cycleRegex.test(item.cycle) || !taxrateRegex.test(item.taxrate) || !priceRegex.test(item.price)) {
  17848. $scope.canSave = false;
  17849. } else {
  17850. $scope.canSave = true;
  17851. }
  17852. }
  17853. });
  17854. }
  17855. };
  17856. // 投标
  17857. $scope.bidIt = function (saleTender) {
  17858. $scope.loading = true;
  17859. if (saleTender.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  17860. saleTender.enterpriseBaseInfo.enEstablishDate = saleTender.enterpriseBaseInfo.enEstablishDate.getTime();
  17861. }
  17862. saleTender.bidAttaches.push.apply(saleTender.bidAttaches, $scope.attaches);
  17863. angular.forEach(saleTender.saleTenderItems, function (item) {
  17864. item.tenderProd = {};
  17865. if ("" == item.price && "" == item.taxrate && "" == item.cycle) {
  17866. item.price = 0;
  17867. item.cycle = 0;
  17868. item.taxrate = 0;
  17869. }
  17870. });
  17871. PurcTender.reply({}, saleTender, function (data) {
  17872. $scope.loading = false;
  17873. toaster.pop('info', '成功', '投标成功');
  17874. window.location.hash = '#/sale/tender';
  17875. }, function (response) {
  17876. $scope.loading = false;
  17877. toaster.pop('error', '投标失败', response.data);
  17878. });
  17879. };
  17880. $scope.condition = {
  17881. $fromOpened: false
  17882. };
  17883. $scope.getMaxDate = function () {
  17884. return $filter('date')(new Date(), 'yyyy-MM-dd');
  17885. };
  17886. $scope.openDatePicker = function ($event, item, openParam) {
  17887. $event.preventDefault();
  17888. $event.stopPropagation();
  17889. item[openParam] = !item[openParam];
  17890. };
  17891. }]);
  17892. /**
  17893. * 投标单提问
  17894. */
  17895. app.controller('SaleTenderQuestionCtrl', ['$scope', 'saleTender','$modalInstance', '$upload', 'toaster', function($scope, saleTender, $modalInstance, $upload ,toaster){
  17896. $scope.saleTender = saleTender;
  17897. // 当前日期,用作新增提问
  17898. $scope.currentDay = new Date();
  17899. $scope.question = {
  17900. inDate : null,
  17901. replyDate : null,
  17902. topic : null,
  17903. status : null,
  17904. content : null,
  17905. questionAttaches : []
  17906. };
  17907. $scope.cancel = function() {
  17908. $modalInstance.dismiss();
  17909. };
  17910. //确认提问
  17911. $scope.ok = function (form) {
  17912. $scope.loading = true;
  17913. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  17914. $upload.upload({
  17915. url: 'tender/question/send/' + $scope.saleTender.id,
  17916. method: 'POST',
  17917. file: file,
  17918. data: {
  17919. json: $scope.question
  17920. }
  17921. }).success(function (data) {
  17922. $scope.loading = false;
  17923. $modalInstance.close('success');
  17924. }).error(function (data) {
  17925. $scope.loading = false;
  17926. toaster.pop('error', '错误', '出现异常,提问失败');
  17927. });
  17928. };
  17929. }]);
  17930. /**
  17931. * 公开招标转投标单
  17932. */
  17933. 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) {
  17934. BaseService.scrollBackToTop();
  17935. $scope.attaches = []; // 存放上传了的附件
  17936. var sleep = function (d) {
  17937. for (var t = Date.now(); Date.now() - t <= d;);
  17938. }
  17939. var getCurrentEn = function () {
  17940. AccountEnterprise.get({}, function (data) {
  17941. $scope.currentEn = data;
  17942. });
  17943. }
  17944. if (!angular.isUndefined($stateParams.id)) { // 获取招标单详情
  17945. $scope.loading = true;
  17946. getCurrentEn();
  17947. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17948. data.$editing = false;
  17949. $scope.tender = data;
  17950. $scope.tenderProd = data.purchaseTenderProds;
  17951. $scope.currentHasBid = false; // 默认当前企业未转投标单
  17952. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  17953. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  17954. $scope.currentHasBid = true;
  17955. }
  17956. });
  17957. $scope.loading = false;
  17958. $scope.attaches = $scope.tender.tenderAttaches;
  17959. }, function (response) {
  17960. $scope.loading = false;
  17961. toaster.pop('error', '数据加载失败', response.data);
  17962. });
  17963. }
  17964. $scope.hasClick = false;
  17965. $scope.iWantToBid = function (id) {
  17966. $scope.hasClick = true;
  17967. PurcTender.addItems({id: id}, {}, function (data) { // 添加明细
  17968. toaster.pop('success', '成功', '转投标单成功');
  17969. window.location.hash = "#/sale/tender/" + id;
  17970. }, function (response) {
  17971. toaster.pop('error', '操作失败', response.data);
  17972. });
  17973. };
  17974. }]);
  17975. // 基础资料客户详情
  17976. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'VendorInfo', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, VendorInfo) {
  17977. BaseService.scrollBackToTop();
  17978. $scope.status = 'customer';
  17979. $scope.userInfoResult = true;
  17980. AuthenticationService.getAuthentication().success(function (data) {
  17981. $scope.loading = false;
  17982. $scope.thisUser = data;
  17983. });
  17984. $scope.customerParams = new ngTableParams({
  17985. page: 1,
  17986. count: 20
  17987. }, {
  17988. total: 0,
  17989. counts: [],
  17990. getData: function ($defer, params) {
  17991. $scope.loading = true;
  17992. var pageParams = params.url();
  17993. pageParams.keyword = $scope.keyword;
  17994. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function (page) {
  17995. $scope.loading = false;
  17996. if (page) {
  17997. params.total(page.totalElement);
  17998. $scope.total = page.totalElement;
  17999. $defer.resolve(page.content);
  18000. }
  18001. $scope.totalCount = page.totalElement;
  18002. }, function (response) {
  18003. $scope.loading = false;
  18004. toaster.pop('error', '数据加载失败', response.data);
  18005. });
  18006. }
  18007. });
  18008. // 搜索框回车
  18009. $scope.onSearch = function (keyword) {
  18010. $scope.customerParams.page(1);
  18011. $scope.customerParams.reload();
  18012. $scope.tip = keyword;
  18013. };
  18014. // 查看详情
  18015. $scope.viewDetail = function (id) {
  18016. window.location.hash = "#/sale/customer/" + id;
  18017. }
  18018. // 取消合作关系
  18019. $scope.disableCust = function (id) {
  18020. VendorInfo.disableCust({id: id}, {}, function (data) {
  18021. if (data.success) {
  18022. toaster.pop('success', '提示', data.success);
  18023. }
  18024. // $scope.customerParams.page(1);
  18025. $scope.customerParams.reload();
  18026. }, function (response) {
  18027. toaster.pop('error', '提示', response.data);
  18028. });
  18029. }
  18030. // 解除禁用
  18031. $scope.activeCust = function (id) {
  18032. VendorInfo.activeCust({id: id}, {}, function (data) {
  18033. if (data.success) {
  18034. toaster.pop('success', '提示', data.success);
  18035. }
  18036. // $scope.customerParams.page(1);
  18037. $scope.customerParams.reload();
  18038. }, function (response) {
  18039. toaster.pop('error', '提示', response.data);
  18040. });
  18041. }
  18042. }]);
  18043. // 基础资料供应商
  18044. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18045. BaseService.scrollBackToTop();
  18046. $scope.status = 'vendor';
  18047. // 搜索框回车
  18048. $scope.onSearch = function () {
  18049. $scope.customerParams.page(1);
  18050. $scope.customerParams.reload();
  18051. };
  18052. $scope.customerParams = new ngTableParams({
  18053. page: 1,
  18054. count: 20
  18055. }, {
  18056. total: 0,
  18057. counts: [],
  18058. getData: function ($defer, params) {
  18059. $scope.loading = true;
  18060. var pageParams = params.url();
  18061. pageParams.keyword = $scope.keyword;
  18062. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  18063. $scope.loading = false;
  18064. if (page) {
  18065. params.total(page.totalElement);
  18066. $scope.total = page.totalElement;
  18067. $defer.resolve(page.content);
  18068. }
  18069. $scope.totalCount = page.totalElement;
  18070. }, function (response) {
  18071. $scope.loading = false;
  18072. toaster.pop('error', '数据加载失败', response.data);
  18073. });
  18074. }
  18075. });
  18076. // 查看供应商详情
  18077. $scope.VendorDetail = function (id, uu) {
  18078. $rootScope.vendorId = id;
  18079. $rootScope.vendoruu = uu;
  18080. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18081. }
  18082. // 向企业购买
  18083. $scope.purcByEn = function (businessCode) {
  18084. $rootScope.businessCode = businessCode;
  18085. window.location.hash = "#/purc/addOrder";
  18086. }
  18087. // 取消合作关系
  18088. $scope.relieve = function (id) {
  18089. VendorInfo.relieve({id: id}, {}, function (data) {
  18090. if (data.success) {
  18091. toaster.pop('success', '提示', data.success);
  18092. }
  18093. // $scope.customerParams.page(1);
  18094. $scope.customerParams.reload();
  18095. }, function (response) {
  18096. toaster.pop('error', '提示', response.data);
  18097. });
  18098. }
  18099. // 建立合作关系
  18100. $scope.activeVend = function (id) {
  18101. VendorInfo.activeVend({id: id}, {}, function (data) {
  18102. if (data.success) {
  18103. toaster.pop('success', '提示', data.success);
  18104. }
  18105. // $scope.customerParams.page(1);
  18106. $scope.customerParams.reload();
  18107. }, function (response) {
  18108. toaster.pop('error', '提示', response.data);
  18109. });
  18110. }
  18111. }]);
  18112. // 基础资料服务商
  18113. app.controller('ServicerInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18114. BaseService.scrollBackToTop();
  18115. $scope.status = 'servicer';
  18116. // 搜索框回车
  18117. $scope.onSearch = function () {
  18118. $scope.customerParams.page(1);
  18119. $scope.customerParams.reload();
  18120. };
  18121. $scope.customerParams = new ngTableParams({
  18122. page: 1,
  18123. count: 20
  18124. }, {
  18125. total: 0,
  18126. counts: [],
  18127. getData: function ($defer, params) {
  18128. $scope.loading = true;
  18129. var pageParams = params.url();
  18130. pageParams.keyword = $scope.keyword;
  18131. Vendor.getServicer.call(null, BaseService.parseParams(pageParams), function (page) {
  18132. $scope.loading = false;
  18133. if (page) {
  18134. params.total(page.totalElement);
  18135. $scope.total = page.totalElement;
  18136. $defer.resolve(page.content);
  18137. }
  18138. $scope.totalCount = page.totalElement;
  18139. }, function (response) {
  18140. $scope.loading = false;
  18141. toaster.pop('error', '数据加载失败', response.data);
  18142. });
  18143. }
  18144. });
  18145. // 查看服务商详情
  18146. $scope.VendorDetail = function (id, uu) {
  18147. $rootScope.vendorId = id;
  18148. $rootScope.vendoruu = uu;
  18149. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18150. };
  18151. // 取消合作关系
  18152. $scope.relieveServicer = function (id) {
  18153. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  18154. if (data.success) {
  18155. toaster.pop('success', '提示', data.success);
  18156. }
  18157. // $scope.customerParams.page(1);
  18158. $scope.customerParams.reload();
  18159. }, function (response) {
  18160. toaster.pop('error', '提示', response.data);
  18161. });
  18162. }
  18163. // 建立合作关系
  18164. $scope.activeServicer = function (id) {
  18165. VendorInfo.activeServicer({id: id}, {}, function (data) {
  18166. if (data.success) {
  18167. toaster.pop('success', '提示', data.success);
  18168. }
  18169. // $scope.customerParams.page(1);
  18170. $scope.customerParams.reload();
  18171. }, function (response) {
  18172. toaster.pop('error', '提示', response.data);
  18173. });
  18174. }
  18175. }]);
  18176. // 企业圈搜索界面
  18177. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
  18178. $scope.onSearch = function (keyword) {
  18179. $rootScope.enterpriseKeyword = keyword;
  18180. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  18181. }
  18182. }]);
  18183. // 企业圈搜索结果
  18184. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  18185. $scope.status = 'add';
  18186. BaseService.scrollBackToTop();
  18187. $scope.active = 'all';
  18188. $scope.agreedText = '全部';
  18189. $scope.dateZoneText = '一个月内';
  18190. $scope.condition = {dateZone: 1};
  18191. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18192. $scope.changeAgreed = function (agreed) {
  18193. $scope.condition.agreed = agreed;
  18194. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18195. $scope.condition.$agreedOpen = false;
  18196. };
  18197. $scope.changeDateZone = function (zone) {
  18198. $scope.condition.dateZone = zone;
  18199. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18200. $scope.condition.$dateZoneOpen = false;
  18201. getDateCondition(zone, $scope.condition);
  18202. $scope.tableParams.reload();
  18203. };
  18204. $scope.setActive = function (state) {
  18205. if ($scope.active != state) {
  18206. $scope.active = state;
  18207. if ($scope.tableParams.page() == 1)
  18208. $scope.tableParams.reload();
  18209. else
  18210. $scope.tableParams.page(1);
  18211. }
  18212. };
  18213. var getService = function () {
  18214. return getAccountUserSpace;
  18215. };
  18216. $scope.tableParams = new ngTableParams({
  18217. page: 1,
  18218. count: 20,
  18219. sorting: {}
  18220. }, {
  18221. total: 0,
  18222. counts: [],
  18223. getData: function ($defer, params) {
  18224. $scope.loading = true;
  18225. var pageParams = params.url();
  18226. pageParams.keyword = $scope.keyword;
  18227. $scope.tip = $scope.keyword;
  18228. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18229. $scope.loading = false;
  18230. if (page) {
  18231. params.total(page.totalElement);
  18232. $defer.resolve(page.content);
  18233. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18234. }
  18235. }, function (response) {
  18236. $scope.loading = false;
  18237. toaster.pop('error', '数据加载失败', response.data);
  18238. });
  18239. }
  18240. });
  18241. // 搜索框回车
  18242. $scope.onSearch = function (keyword) {
  18243. if (keyword === '') {
  18244. keyword = null;
  18245. $rootScope.searchKeyword = keyword;
  18246. $scope.keyword = keyword;
  18247. $scope.tableParams.page(1);
  18248. $scope.tableParams.reload();
  18249. } else {
  18250. $rootScope.searchKeyword = keyword;
  18251. $scope.keyword = keyword;
  18252. $scope.tableParams.page(1);
  18253. $scope.tableParams.reload();
  18254. }
  18255. };
  18256. // 添加合作关系
  18257. $scope.addPartner = function (name, businessCode) {
  18258. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  18259. if (data.success) {
  18260. toaster.pop("success", '添加成功', data.success);
  18261. $scope.tableParams.reload();
  18262. }
  18263. if (data.error) {
  18264. toaster.pop("error", '添加失败', data.error);
  18265. }
  18266. }, function (response) {
  18267. toaster.pop('error', '失败', response.data);
  18268. });
  18269. }
  18270. /**
  18271. * 邀请注册商务平台
  18272. */
  18273. $scope.invite = function (name) {
  18274. var modalInstance = $modal.open({
  18275. animation: true,
  18276. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  18277. controller: 'InviteCtrl',
  18278. resolve: {
  18279. enname: function () {
  18280. return name
  18281. }
  18282. }
  18283. });
  18284. modalInstance.result.then(function (data) {
  18285. InvitationRecord.invite({formStore: data}, {}, function (data) {
  18286. if (data.success) {
  18287. toaster.pop('success', '提示', data.success);
  18288. $scope.tableParams.reload();
  18289. }
  18290. if (data.error) {
  18291. toaster.pop('error', '提示', data.error);
  18292. }
  18293. }, function (response) {
  18294. toaster.pop('error', '提示', response.data);
  18295. });
  18296. });
  18297. }
  18298. /**
  18299. * 立即查看
  18300. */
  18301. $scope.view = function (name) {
  18302. $rootScope.vendName = name;
  18303. window.location.hash = "#/baseInfo/newPartner";
  18304. }
  18305. }]);
  18306. // 平台新增的询价单(指定一个供应商)
  18307. 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) {
  18308. $scope.active = 'all';
  18309. // 供应商信息
  18310. var loadData = function () {
  18311. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function (data) {
  18312. $scope.vendor = data;
  18313. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  18314. $scope.vendorContacts = data;
  18315. });
  18316. // 物料信息
  18317. $scope.tableParams = new ngTableParams({
  18318. page: 1,
  18319. count: 20
  18320. }, {
  18321. total: 0,
  18322. counts: [5, 10, 25, 50],
  18323. getData: function ($defer, params) {
  18324. $scope.loading = true;
  18325. var pageParams = params.url();
  18326. pageParams.keyword = $scope.keyword;
  18327. $scope.tip = $scope.keyword;
  18328. pageParams.custUU = $scope.vendor.uu;
  18329. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18330. $scope.loading = false;
  18331. if (page) {
  18332. params.total(page.totalElement);
  18333. $scope.total = page.totalElement;
  18334. $defer.resolve(page.content);
  18335. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  18336. }
  18337. }, function (response) {
  18338. $scope.loading = false;
  18339. toaster.pop('error', '数据加载失败', response.data);
  18340. });
  18341. }
  18342. });
  18343. });
  18344. };
  18345. loadData();
  18346. $rootScope.tenderVendor = null;// 清除掉已选择的
  18347. var getService = function () {
  18348. return GetProductInfo;
  18349. };
  18350. $scope.inquiry = {
  18351. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  18352. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  18353. priceType: '采购',
  18354. isOpen: 0,
  18355. invoice: 0,
  18356. ifTax: 1,
  18357. currency: 'RMB'
  18358. };
  18359. $scope.changeCurrency = function (inquiry) {
  18360. if (inquiry.currency !== 'RMB') {
  18361. $scope.notRMB = true;
  18362. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  18363. inquiry.invoice = 0;
  18364. } else {
  18365. $scope.notRMB = false;
  18366. }
  18367. };
  18368. // 获取收货地址列表
  18369. var loadShipAddress = function () {
  18370. ShipAddress.shipAddList({}, function (data) {
  18371. $scope.ships = data;
  18372. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  18373. });
  18374. };
  18375. loadShipAddress();
  18376. // 获取地址信息
  18377. $http.get('resources/citydata/city.json', {
  18378. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  18379. }).then(function (response) {
  18380. $scope.provinces = response.data;
  18381. });
  18382. // 新增收货地址保存
  18383. $scope.saveShipAddress = function (ship) {
  18384. ship.address = ship.province + ship.city + ship.district;
  18385. ShipAddress.saveAddress({}, ship, function (data) {
  18386. if (data.success) {
  18387. // 获取收货地址列表
  18388. loadShipAddress();
  18389. toaster.pop('success', '提示', data.success);
  18390. }
  18391. if (data.error) {
  18392. toaster.pop('error', '提示', data.error);
  18393. }
  18394. });
  18395. };
  18396. $scope.currentDay = function () {
  18397. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18398. };
  18399. // 搜索框回车
  18400. $scope.onSearch = function (keyword) {
  18401. $scope.tableParams.page(1);
  18402. $scope.tableParams.reload();
  18403. };
  18404. $scope.inquiry.inquiryItems = [];
  18405. var prod = {
  18406. prodCode: null,
  18407. prodTitle: null,
  18408. inbrand: null,
  18409. currency: 'RMB',
  18410. toDate: null,
  18411. unit: 'PCS'
  18412. };
  18413. $scope.inquiry.inquiryItems.push(prod);
  18414. // 联想词start
  18415. // 获取品牌联想词
  18416. $scope.getSimilarBrands = function (value) {
  18417. if (value) {
  18418. // 获取品牌联想词
  18419. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  18420. return data.map(function (item) {
  18421. return item;
  18422. });
  18423. });
  18424. }
  18425. };
  18426. // 获取产品型号联想词
  18427. $scope.getSimilarCodes = function (value) {
  18428. if (value) {
  18429. // 获取产品型号联想词
  18430. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  18431. return data.map(function (item) {
  18432. return item;
  18433. })
  18434. });
  18435. }
  18436. };
  18437. $scope.selectKind = function (prod) {
  18438. var submit = [];
  18439. $modal.open({
  18440. animation: true,
  18441. size: 'lg',
  18442. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  18443. controller: 'ProdKindChooseCtrl',
  18444. resolve: {
  18445. actives: function () {
  18446. return $scope.actives;
  18447. }
  18448. }
  18449. }).result.then(function (data) {
  18450. $scope.actives = data.actives;
  18451. var size = data.actives.length;
  18452. submit.gradeOneKiName = '';
  18453. submit.gradeTwoKiName = '';
  18454. submit.gradeThreeKiName = '';
  18455. if (size > 0) {
  18456. submit.gradeOneKiName = $scope.actives[0].nameCn;
  18457. prod.prodTitle = submit.gradeOneKiName;
  18458. if (size > 1) {
  18459. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  18460. prod.prodTitle = submit.gradeTwoKiName;
  18461. if (size > 2) {
  18462. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  18463. prod.prodTitle = submit.gradeThreeKiName;
  18464. }
  18465. }
  18466. }
  18467. }, function () {
  18468. });
  18469. };
  18470. // 点击联想词获取品牌信息
  18471. $scope.onAssociateBrandClick = function (brand, prod) {
  18472. if (brand instanceof String) {
  18473. prod.inbrand = brand;
  18474. } else if (brand instanceof Object) {
  18475. prod.inbrand = brand.brandCn;
  18476. }
  18477. };
  18478. // 打开品牌选择的模态框
  18479. $scope.selectBrand = function (prod) { //打开模态
  18480. var modalInstance = $modal.open({
  18481. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  18482. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  18483. });
  18484. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  18485. });
  18486. modalInstance.result.then(function (brand) {
  18487. prod.inbrand = brand.nameCn;
  18488. }, function (reason) {
  18489. });
  18490. };
  18491. // 点击联想词获取器件信息 带入产品分类和品牌
  18492. $scope.onAssociateCmpClick = function (cmp, prod) {
  18493. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  18494. $scope.component = data;
  18495. prod.prodCode = data.code;
  18496. prod.prodTitle = data.kind.nameCn;
  18497. prod.inbrand = data.brand.nameCn;
  18498. }, function (res) {
  18499. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  18500. })
  18501. };
  18502. //联想词end
  18503. // 导入商品信息
  18504. $scope.uplodaByBatch = function () {
  18505. var modalInstance = $modal.open({
  18506. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  18507. controller: 'PurcInquiryUploadCtrl',
  18508. size: 'lg',
  18509. resolve: {}
  18510. });
  18511. modalInstance.result.then(function (data) {
  18512. angular.forEach(data, function (prod) {
  18513. $scope.inquiry.inquiryItems.push(prod);
  18514. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  18515. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  18516. $scope.inquiry.inquiryItems.splice(i, 1);
  18517. }
  18518. }
  18519. })
  18520. }, function () {
  18521. });
  18522. }
  18523. //增加商品
  18524. $scope.add = function () {
  18525. $scope.inquiry.inquiryItems.push(
  18526. {
  18527. prodCode: null,
  18528. prodTitle: null,
  18529. unit: 'PCS',
  18530. ibrand: null,
  18531. currency: 'RMB',
  18532. toDate: null
  18533. });
  18534. };
  18535. //删除商品
  18536. $scope.del = function (index) {
  18537. $scope.inquiry.inquiryItems.splice(index, 1);
  18538. };
  18539. // 搜索结果询价
  18540. if ($rootScope.prodId) {
  18541. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  18542. prod.prodCode = data.code;
  18543. prod.prodTitle = data.title;
  18544. prod.spec = data.spec;
  18545. prod.unit = data.unit;
  18546. prod.productId = data.id;
  18547. prod.inbrand = data.brand;
  18548. $scope.inquiry.inquiryItems.push(prod);
  18549. $rootScope.prodId = null;// 清除掉prodId
  18550. }, function (response) {
  18551. });
  18552. }
  18553. $scope.check = function (product) {
  18554. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  18555. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  18556. $scope.inquiry.inquiryItems.splice(i, 1);
  18557. }
  18558. }
  18559. $scope.inquiry.inquiryItems.push({
  18560. prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  18561. currency: null, toDate: null, productId: product.id, inbrand: product.brand
  18562. });
  18563. }
  18564. $scope.getMinDate = function (item) {
  18565. return $filter('date')(new Date, 'yyyy-MM-dd');
  18566. };
  18567. $scope.openDatePicker = function ($event, openParam, index) {
  18568. $event.preventDefault();
  18569. $event.stopPropagation();
  18570. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  18571. };
  18572. $scope.openEndDatePicker = function ($event, item, openParam) {
  18573. $event.preventDefault();
  18574. $event.stopPropagation();
  18575. item[openParam] = !item[openParam];
  18576. };
  18577. $scope.ifrepeat = false;
  18578. // 保存并提交
  18579. $scope.submit = function () {
  18580. $scope.loading = true;
  18581. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  18582. $scope.item = $scope.inquiry.inquiryItems[i];
  18583. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  18584. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  18585. if (i != j) {
  18586. if ($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  18587. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  18588. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  18589. $scope.ifrepeat = true;
  18590. }
  18591. }
  18592. }
  18593. }
  18594. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  18595. $scope.vendors = [];
  18596. $scope.vendors.push({
  18597. enName: $scope.vendor.enName,
  18598. enuu: $scope.vendor.uu,
  18599. currency: $scope.vendor.currency,
  18600. rate: $scope.vendor.rate
  18601. });
  18602. if (!$scope.ifrepeat) {
  18603. $upload.upload({
  18604. url: 'purc/inquiry/submit/withVendor',
  18605. file: file,
  18606. method: 'POST',
  18607. data: {
  18608. inquiry: $scope.inquiry,
  18609. contacts: $scope.vendors
  18610. },
  18611. }).success(function (data) {
  18612. if (data.success) {
  18613. $scope.loading = false;
  18614. toaster.pop('success', '提示', data.success);
  18615. $timeout(function () {
  18616. window.location.hash = "#/purc/purchaseinquiry";
  18617. }, 500);
  18618. }
  18619. if (data.error) {
  18620. $scope.loading = false;
  18621. toaster.pop('error', '提示', data.error);
  18622. }
  18623. }).error(function (data) {
  18624. $scope.loadingShow = false;
  18625. toaster.pop('error', '操作失败', data.error);
  18626. });
  18627. } else {
  18628. $scope.loading = false;
  18629. toaster.pop('error', '提示', '存在条件相同的物料');
  18630. }
  18631. }
  18632. }]);
  18633. // 企业圈查询收到待处理的数目
  18634. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', '$modal', 'InvitationRecord', 'toaster', function ($scope, AddPartnerMyRequest, $modal, InvitationRecord, toaster) {
  18635. AddPartnerMyRequest.requestAmount({}, function (data) {
  18636. $scope.requestTodo = data;
  18637. });
  18638. /**
  18639. * 邀请注册商务平台
  18640. */
  18641. $scope.invite = function () {
  18642. var modalInstance = $modal.open({
  18643. animation: true,
  18644. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  18645. controller: 'InviteCtrl',
  18646. resolve: {
  18647. enname: function () {
  18648. return null
  18649. }
  18650. }
  18651. });
  18652. modalInstance.result.then(function (data) {
  18653. InvitationRecord.invite({formStore: data}, {}, function (data) {
  18654. if (data.success) {
  18655. toaster.pop('success', '提示', data.success);
  18656. $scope.tableParams.reload();
  18657. }
  18658. if (data.error) {
  18659. toaster.pop('error', '提示', data.error);
  18660. }
  18661. }, function (response) {
  18662. toaster.pop('error', '提示', response.data);
  18663. });
  18664. });
  18665. }
  18666. }]);
  18667. // 当前企业所有的物料信息
  18668. 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) {
  18669. BaseService.scrollBackToTop();
  18670. $rootScope.ids = [];// 用来记录已经选择的物料
  18671. $scope.active = 'all';
  18672. $scope.agreedText = '全部';
  18673. $scope.dateZoneText = '一个月内';
  18674. $scope.condition = {dateZone: 1};
  18675. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18676. $scope.changeAgreed = function (agreed) {
  18677. $scope.condition.agreed = agreed;
  18678. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18679. $scope.condition.$agreedOpen = false;
  18680. };
  18681. $scope.changeDateZone = function (zone) {
  18682. $scope.condition.dateZone = zone;
  18683. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18684. $scope.condition.$dateZoneOpen = false;
  18685. getDateCondition(zone, $scope.condition);
  18686. $scope.tableParams.reload();
  18687. };
  18688. $scope.setActive = function (state) {
  18689. if ($scope.active != state) {
  18690. $scope.active = state;
  18691. if ($scope.tableParams.page() == 1)
  18692. $scope.tableParams.reload();
  18693. else
  18694. $scope.tableParams.page(1);
  18695. }
  18696. };
  18697. $scope.searchMethod = false;
  18698. var getService = function () {
  18699. return $scope.searchMethod ? ProductAll : ProductAllNewest;
  18700. };
  18701. $scope.tableParams = new ngTableParams({
  18702. page: 1,
  18703. count: 20,
  18704. sorting: {
  18705. standard: 'desc',
  18706. id: 'desc',
  18707. }
  18708. }, {
  18709. total: 0,
  18710. counts: [5, 10, 25, 50],
  18711. getData: function ($defer, params) {
  18712. $scope.loading = true;
  18713. var pageParams = params.url();
  18714. pageParams.keyword = $scope.keyword;
  18715. pageParams.searchFilter = $scope.searchFilter;
  18716. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18717. $scope.loading = false;
  18718. if (page) {
  18719. params.total(page.totalElement);
  18720. $defer.resolve(page.content);
  18721. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18722. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  18723. $scope.checkall = true;
  18724. if(page.content.length <= 2) {
  18725. $scope.checkall = false;
  18726. } else {
  18727. angular.forEach(page.content, function (prod) {
  18728. if ($rootScope.ids.indexOf(prod.id) > -1) {
  18729. prod.$selected = true;
  18730. } else {
  18731. $scope.checkall = false;
  18732. }
  18733. });
  18734. }
  18735. $scope.checkboxes = {
  18736. checked: $scope.checkall
  18737. };
  18738. }
  18739. }, function (response) {
  18740. $scope.loading = false;
  18741. toaster.pop('error', '数据加载失败', response.data);
  18742. });
  18743. }
  18744. });
  18745. // 搜索框回车
  18746. $scope.onSearch = function (keyword) {
  18747. // 每次搜索重置获取数据方法
  18748. $scope.searchMethod = false;
  18749. if(keyword != null && keyword != '') {
  18750. $scope.searchMethod = true;
  18751. }
  18752. $scope.tableParams.page(1);
  18753. $scope.tableParams.reload();
  18754. };
  18755. // 开启销售
  18756. $scope.unlock = function (id) {
  18757. $scope.loading = true;
  18758. Products.unlock({id: id}, {}, function (data) {
  18759. $scope.loading = false;
  18760. toaster.pop('success', '提示', '操作成功');
  18761. $scope.tableParams.reload();
  18762. }, function (response) {
  18763. toaster.pop('error', '提示', response.data);
  18764. })
  18765. }
  18766. // 关闭销售
  18767. $scope.lock = function (id) {
  18768. $scope.loading = true;
  18769. Products.lock({id: id}, {}, function (data) {
  18770. $scope.loading = false;
  18771. toaster.pop('success', '提示', '操作成功');
  18772. $scope.tableParams.reload();
  18773. }, function (response) {
  18774. toaster.pop('error', '提示', response.data);
  18775. })
  18776. }
  18777. // 开启购买
  18778. $scope.unlockPurc = function (id) {
  18779. $scope.loading = true;
  18780. Products.unlockPurc({id: id}, {}, function (data) {
  18781. $scope.loading = false;
  18782. toaster.pop('success', '提示', '操作成功');
  18783. $scope.tableParams.reload();
  18784. }, function (response) {
  18785. toaster.pop('error', '提示', response.data);
  18786. })
  18787. }
  18788. // 关闭购买
  18789. $scope.lockPurc = function (id) {
  18790. $scope.loading = true;
  18791. Products.lockPurc({id: id}, {}, function (data) {
  18792. $scope.loading = false;
  18793. toaster.pop('success', '提示', '操作成功');
  18794. $scope.tableParams.reload();
  18795. }, function (response) {
  18796. toaster.pop('error', '提示', response.data);
  18797. })
  18798. }
  18799. // 一键匹配
  18800. $scope.matchall = function () {
  18801. $scope.type = "all";
  18802. $scope.loading = true;
  18803. Products.matchbytype({type: $scope.type}, {}, function (data) {
  18804. if (data.error) {
  18805. $scope.loading = false;
  18806. toaster.pop('error', '提示', data.error);
  18807. } else {
  18808. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  18809. window.location.href = "#/approvalFlow/productmatches";
  18810. }
  18811. }, function (response) {
  18812. toaster.pop('error', '提示', response.data);
  18813. });
  18814. }
  18815. $scope.checkboxes = {
  18816. checked: false
  18817. };
  18818. angular.forEach($scope.tableParams.data, function (item) {
  18819. $scope.checkboxes.checked = false;
  18820. if($rootScope.ids.in_array(item.id)) {
  18821. $rootScope.ids.remove(item.id);
  18822. $scope.checkboxes.checked = true;
  18823. }
  18824. });
  18825. // 点击勾选全部的复选框
  18826. $scope.checkAll = function () {
  18827. angular.forEach($scope.tableParams.data, function (item) {
  18828. if (!item.waiting) {
  18829. item.$selected = $scope.checkboxes.checked;
  18830. if(item.$selected) {
  18831. if(!$rootScope.ids.in_array(item.id)) {
  18832. $rootScope.ids.push(item.id);
  18833. }
  18834. } else {
  18835. if($rootScope.ids.in_array(item.id)) {
  18836. $rootScope.ids.remove(item.id);
  18837. }
  18838. }
  18839. }
  18840. });
  18841. };
  18842. // 判断数组中是否存在某个对象
  18843. Array.prototype.S = String.fromCharCode(2);
  18844. Array.prototype.in_array = function(e) {
  18845. var r = new RegExp(this.S + e + this.S);
  18846. return (r.test(this.S + this.join(this.S) + this.S));
  18847. }
  18848. // 从数组中移除某个对象
  18849. Array.prototype.remove = function(val) {
  18850. var index = this.indexOf(val);
  18851. if (index > -1) {
  18852. this.splice(index, 1);
  18853. }
  18854. };
  18855. // 点击其中一个明细的复选框
  18856. $scope.checkOne = function (product) {
  18857. var result = true;
  18858. angular.forEach($scope.tableParams.data, function (item) {
  18859. if (item.$selected != true) {
  18860. result = false;
  18861. return;
  18862. }
  18863. });
  18864. if(product.$selected) {
  18865. if(!$rootScope.ids.in_array(product.id)) {
  18866. $rootScope.ids.push(product.id);
  18867. }
  18868. } else {
  18869. if($rootScope.ids.in_array(product.id)) {
  18870. $rootScope.ids.remove(product.id);
  18871. }
  18872. }
  18873. $scope.checkboxes = {
  18874. checked: result
  18875. };
  18876. };
  18877. // 批量转入我的产品库
  18878. $scope.addtoUserByCheck = function() {
  18879. var ids = angular.copy($rootScope.ids);
  18880. if($rootScope.ids.length == 0) {
  18881. toaster.pop('error', '提示', '请先选择产品');
  18882. } else {
  18883. prodUser.coverToUserByIds({}, ids, function(data) {
  18884. toaster.pop('success', '提示', '选择' + $rootScope.ids.length + '个产品,成功转入' + data.count + '个产品');
  18885. $rootScope.ids = [];
  18886. $scope.tableParams.page(1);
  18887. $scope.tableParams.reload();
  18888. }, function(res) {
  18889. toaster.pop('error', '提示', '转入失败');
  18890. });
  18891. }
  18892. }
  18893. // 转入我的产品库
  18894. $scope.addtoUser = function(id) {
  18895. $scope.loading = true;
  18896. prodUser.coverToUser({id: id}, {}, function(data) {
  18897. $scope.loading = false;
  18898. toaster.pop('success', '提示', '转入成功');
  18899. }, function(res) {
  18900. $scope.loading = false;
  18901. toaster.pop('error', '提示', '转入失败');
  18902. });
  18903. }
  18904. }]);
  18905. // 当前企业匹配的标准物料信息
  18906. 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) {
  18907. BaseService.scrollBackToTop();
  18908. $scope.active = 'all';
  18909. $scope.agreedText = '全部';
  18910. $scope.dateZoneText = '一个月内';
  18911. $scope.condition = {dateZone: 1};
  18912. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18913. $scope.changeAgreed = function (agreed) {
  18914. $scope.condition.agreed = agreed;
  18915. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18916. $scope.condition.$agreedOpen = false;
  18917. };
  18918. $scope.changeDateZone = function (zone) {
  18919. $scope.condition.dateZone = zone;
  18920. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18921. $scope.condition.$dateZoneOpen = false;
  18922. getDateCondition(zone, $scope.condition);
  18923. $scope.tableParams.reload();
  18924. };
  18925. $scope.setActive = function (state) {
  18926. if ($scope.active != state) {
  18927. $scope.active = state;
  18928. if ($scope.tableParams.page() == 1)
  18929. $scope.tableParams.reload();
  18930. else
  18931. $scope.tableParams.page(1);
  18932. }
  18933. };
  18934. $scope.searchMethod = false;
  18935. var getService = function () {
  18936. if ($rootScope.productMatchStatus === 'sale') {
  18937. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  18938. } else if ($rootScope.productMatchStatus === 'purc') {
  18939. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  18940. } else {
  18941. return $scope.searchMethod ? Products.matchResult : Products.newestMatchResult;
  18942. }
  18943. };
  18944. $scope.tableParams = new ngTableParams({
  18945. page: 1,
  18946. count: 20,
  18947. sorting: {
  18948. matchsize: 'asc',
  18949. id: 'desc'
  18950. }
  18951. }, {
  18952. total: 0,
  18953. counts: [5, 10, 25, 50],
  18954. getData: function ($defer, params) {
  18955. $scope.loading = true;
  18956. var pageParams = params.url();
  18957. pageParams.keyword = $scope.keyword;
  18958. pageParams.searchFilter = $scope.searchFilter;
  18959. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  18960. if (page) {
  18961. $scope.loading = false;
  18962. params.total(page.totalElement);
  18963. $defer.resolve(page.content);
  18964. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18965. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  18966. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  18967. ids = [];
  18968. if (product.matchresults.length == 1) {
  18969. product.checked = $scope.checks.checked;
  18970. }
  18971. });
  18972. }
  18973. }, function (response) {
  18974. $scope.loading = false;
  18975. toaster.pop('error', '数据加载失败', response.data);
  18976. });
  18977. }
  18978. });
  18979. // 搜索框回车
  18980. $scope.onSearch = function (keyword) {
  18981. $scope.searchMethod = false;
  18982. if(keyword != null && keyword != '') {
  18983. $scope.searchMethod = true;
  18984. }
  18985. $scope.tableParams.page(1);
  18986. $scope.tableParams.reload();
  18987. };
  18988. var ids = [];
  18989. $scope.checks = {
  18990. checked: false
  18991. };
  18992. // 全选框
  18993. $scope.checkAll = function () {
  18994. ids = [];// 每次选择时先清空,防止重复
  18995. angular.forEach($scope.tableParams.data, function (product) {
  18996. if (product.matchresults.length == 1) {
  18997. product.checked = $scope.checks.checked;
  18998. }
  18999. });
  19000. };
  19001. // 单选
  19002. $scope.checkOne = function (product) {
  19003. ids = [];// 每次选择时先清空,防止重复
  19004. product.checked = !product.checked;
  19005. var result = true;
  19006. angular.forEach($scope.tableParams.data, function (item) {
  19007. if (item.$selected != true) {
  19008. result = false;
  19009. return;
  19010. }
  19011. });
  19012. $scope.checks.checked = result;
  19013. var checked = true;
  19014. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19015. if (!message.checked) {
  19016. checked = false;
  19017. }
  19018. });
  19019. $scope.checks.checked = checked;
  19020. };
  19021. $scope.product = {
  19022. checked: false
  19023. };
  19024. var checkResults = function (result) {
  19025. angular.forEach($scope.tableParams.data, function (product) {
  19026. if (product.id == result.prid) {
  19027. product.checked = false;
  19028. angular.forEach(product.matchresults, function (item) {
  19029. if (result.id == item.id) {
  19030. if (item.checked) {
  19031. product.checked = true;
  19032. return;
  19033. }
  19034. } else {
  19035. item.checked = false;
  19036. }
  19037. });
  19038. }
  19039. });
  19040. // checkProductCheck();
  19041. };
  19042. var checkProductCheck = function () {
  19043. var checked = true;
  19044. angular.forEach($scope.tableParams.data, function (product) {
  19045. if (!product.checked) {
  19046. checked = false;
  19047. }
  19048. });
  19049. $scope.product.checked = checked;
  19050. }
  19051. // 单选明细
  19052. $scope.checkItem = function (result) {
  19053. ids = [];
  19054. result.checked = !result.checked;
  19055. checkResults(result);
  19056. }
  19057. // 一键更新
  19058. $scope.updateAll = function () {
  19059. $scope.loading = true;
  19060. angular.forEach($scope.tableParams.data, function (product) {
  19061. if (product.checked) {
  19062. if (product.matchresults.length == 1) {
  19063. ids.push(product.matchresults[0].id);
  19064. }
  19065. if (product.matchresults.length > 1) {
  19066. angular.forEach(product.matchresults, function (item) {
  19067. if (item.checked) {
  19068. ids.push(item.id);
  19069. }
  19070. });
  19071. }
  19072. }
  19073. });
  19074. Products.updateall({status: $scope.checks.checked, type: 'all'}, ids, function (data) {
  19075. if (data.success) {
  19076. toaster.pop('success', '提示', data.success);
  19077. $timeout(function () {
  19078. $scope.tableParams.page(1);
  19079. $scope.tableParams.reload();
  19080. $scope.loading = false;
  19081. }, 500);
  19082. }
  19083. ids = []; // 清空ids,防止重复点击出现多余的数据
  19084. }, function (response) {
  19085. $scope.loading = false;
  19086. toaster.pop('error', '提示', response.data);
  19087. });
  19088. }
  19089. }]);
  19090. // 当前企业匹配的标准物料信息(销售)
  19091. 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) {
  19092. BaseService.scrollBackToTop();
  19093. $scope.active = 'all';
  19094. $scope.agreedText = '全部';
  19095. $scope.dateZoneText = '一个月内';
  19096. $scope.condition = {dateZone: 1};
  19097. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19098. $scope.changeAgreed = function (agreed) {
  19099. $scope.condition.agreed = agreed;
  19100. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19101. $scope.condition.$agreedOpen = false;
  19102. };
  19103. $scope.changeDateZone = function (zone) {
  19104. $scope.condition.dateZone = zone;
  19105. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19106. $scope.condition.$dateZoneOpen = false;
  19107. getDateCondition(zone, $scope.condition);
  19108. $scope.tableParams.reload();
  19109. };
  19110. $scope.setActive = function (state) {
  19111. if ($scope.active != state) {
  19112. $scope.active = state;
  19113. if ($scope.tableParams.page() == 1)
  19114. $scope.tableParams.reload();
  19115. else
  19116. $scope.tableParams.page(1);
  19117. }
  19118. };
  19119. $scope.searchMethod = false;
  19120. var getService = function () {
  19121. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19122. };
  19123. $scope.tableParams = new ngTableParams({
  19124. page: 1,
  19125. count: 20,
  19126. sorting: {
  19127. matchsize: 'asc',
  19128. id: 'desc'
  19129. }
  19130. }, {
  19131. total: 0,
  19132. counts: [5, 10, 25, 50],
  19133. getData: function ($defer, params) {
  19134. $scope.loading = true;
  19135. var pageParams = params.url();
  19136. pageParams.keyword = $scope.keyword;
  19137. pageParams.searchFilter = $scope.searchFilter;
  19138. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19139. if (page) {
  19140. $scope.loading = false;
  19141. params.total(page.totalElement);
  19142. $defer.resolve(page.content);
  19143. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19144. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19145. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19146. ids = [];
  19147. if (product.matchresults.length == 1) {
  19148. product.checked = $scope.checks.checked;
  19149. }
  19150. });
  19151. }
  19152. }, function (response) {
  19153. $scope.loading = false;
  19154. toaster.pop('error', '数据加载失败', response.data);
  19155. });
  19156. }
  19157. });
  19158. // 搜索框回车
  19159. $scope.onSearch = function (keyword) {
  19160. $scope.searchMethod = false;
  19161. if(keyword != null && keyword != '') {
  19162. $scope.searchMethod = true;
  19163. }
  19164. $scope.tableParams.page(1);
  19165. $scope.tableParams.reload();
  19166. };
  19167. var ids = [];
  19168. $scope.checks = {
  19169. checked: false
  19170. };
  19171. // 全选框
  19172. $scope.checkAll = function () {
  19173. ids = [];// 每次选择时先清空,防止重复
  19174. angular.forEach($scope.tableParams.data, function (product) {
  19175. if (product.matchresults.length == 1) {
  19176. product.checked = $scope.checks.checked;
  19177. }
  19178. });
  19179. };
  19180. // 单选
  19181. $scope.checkOne = function (product) {
  19182. ids = [];// 每次选择时先清空,防止重复
  19183. product.checked = !product.checked;
  19184. var result = true;
  19185. angular.forEach($scope.tableParams.data, function (item) {
  19186. if (item.$selected != true) {
  19187. result = false;
  19188. return;
  19189. }
  19190. });
  19191. $scope.checks.checked = result;
  19192. var checked = true;
  19193. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19194. if (!message.checked) {
  19195. checked = false;
  19196. }
  19197. });
  19198. $scope.checks.checked = checked;
  19199. };
  19200. $scope.product = {
  19201. checked: false
  19202. };
  19203. var checkResults = function (result) {
  19204. angular.forEach($scope.tableParams.data, function (product) {
  19205. if (product.id == result.prid) {
  19206. product.checked = false;
  19207. angular.forEach(product.matchresults, function (item) {
  19208. if (result.id == item.id) {
  19209. if (item.checked) {
  19210. product.checked = true;
  19211. return;
  19212. }
  19213. } else {
  19214. item.checked = false;
  19215. }
  19216. });
  19217. }
  19218. });
  19219. // checkProductCheck();
  19220. };
  19221. var checkProductCheck = function () {
  19222. var checked = true;
  19223. angular.forEach($scope.tableParams.data, function (product) {
  19224. if (!product.checked) {
  19225. checked = false;
  19226. }
  19227. });
  19228. $scope.product.checked = checked;
  19229. }
  19230. // 单选明细
  19231. $scope.checkItem = function (result) {
  19232. ids = [];
  19233. result.checked = !result.checked;
  19234. checkResults(result);
  19235. }
  19236. // 一键更新
  19237. $scope.updateAll = function () {
  19238. $scope.loading = true;
  19239. angular.forEach($scope.tableParams.data, function (product) {
  19240. if (product.checked) {
  19241. if (product.matchresults.length == 1) {
  19242. ids.push(product.matchresults[0].id);
  19243. }
  19244. if (product.matchresults.length > 1) {
  19245. angular.forEach(product.matchresults, function (item) {
  19246. if (item.checked) {
  19247. ids.push(item.id);
  19248. }
  19249. });
  19250. }
  19251. }
  19252. });
  19253. Products.updateall({status: $scope.checks.checked, type: 'sale'}, ids, function (data) {
  19254. if (data.success) {
  19255. toaster.pop('success', '提示', data.success);
  19256. $timeout(function () {
  19257. $scope.tableParams.page(1);
  19258. $scope.tableParams.reload();
  19259. $scope.loading = false;
  19260. }, 500);
  19261. }
  19262. ids = []; // 清空ids,防止重复点击出现多余的数据
  19263. }, function (response) {
  19264. $scope.loading = true;
  19265. toaster.pop('error', '提示', response.data);
  19266. });
  19267. }
  19268. }]);
  19269. // 当前企业匹配的标准物料信息(采购)
  19270. 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) {
  19271. BaseService.scrollBackToTop();
  19272. $scope.active = 'all';
  19273. $scope.agreedText = '全部';
  19274. $scope.dateZoneText = '一个月内';
  19275. $scope.condition = {dateZone: 1};
  19276. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19277. $scope.changeAgreed = function (agreed) {
  19278. $scope.condition.agreed = agreed;
  19279. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19280. $scope.condition.$agreedOpen = false;
  19281. };
  19282. $scope.changeDateZone = function (zone) {
  19283. $scope.condition.dateZone = zone;
  19284. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19285. $scope.condition.$dateZoneOpen = false;
  19286. getDateCondition(zone, $scope.condition);
  19287. $scope.tableParams.reload();
  19288. };
  19289. $scope.setActive = function (state) {
  19290. if ($scope.active != state) {
  19291. $scope.active = state;
  19292. if ($scope.tableParams.page() == 1)
  19293. $scope.tableParams.reload();
  19294. else
  19295. $scope.tableParams.page(1);
  19296. }
  19297. };
  19298. $scope.searchMethod = false;
  19299. var getService = function () {
  19300. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19301. };
  19302. $scope.tableParams = new ngTableParams({
  19303. page: 1,
  19304. count: 20,
  19305. sorting: {
  19306. matchsize: 'asc',
  19307. id: 'desc'
  19308. }
  19309. }, {
  19310. total: 0,
  19311. counts: [5, 10, 25, 50],
  19312. getData: function ($defer, params) {
  19313. $scope.loading = true;
  19314. var pageParams = params.url();
  19315. pageParams.keyword = $scope.keyword;
  19316. pageParams.searchFilter = $scope.searchFilter;
  19317. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19318. if (page) {
  19319. $scope.loading = false;
  19320. params.total(page.totalElement);
  19321. $defer.resolve(page.content);
  19322. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19323. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19324. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19325. ids = [];
  19326. if (product.matchresults.length == 1) {
  19327. product.checked = $scope.checks.checked;
  19328. }
  19329. });
  19330. $scope.total = page.totalElement;
  19331. }
  19332. }, function (response) {
  19333. $scope.loading = false;
  19334. toaster.pop('error', '数据加载失败', response.data);
  19335. });
  19336. }
  19337. });
  19338. // 搜索框回车
  19339. $scope.onSearch = function (keyword) {
  19340. $scope.searchMethod = false;
  19341. if(keyword != null && keyword != '') {
  19342. $scope.searchMethod = true;
  19343. }
  19344. $scope.tableParams.page(1);
  19345. $scope.tableParams.reload();
  19346. };
  19347. var ids = [];
  19348. $scope.checks = {
  19349. checked: false
  19350. };
  19351. // 全选框
  19352. $scope.checkAll = function () {
  19353. ids = [];// 每次选择时先清空,防止重复
  19354. angular.forEach($scope.tableParams.data, function (product) {
  19355. if (product.matchresults.length == 1) {
  19356. product.checked = $scope.checks.checked;
  19357. }
  19358. });
  19359. };
  19360. // 单选
  19361. $scope.checkOne = function (product) {
  19362. ids = [];// 每次选择时先清空,防止重复
  19363. product.checked = !product.checked;
  19364. var result = true;
  19365. angular.forEach($scope.tableParams.data, function (item) {
  19366. if (item.$selected != true) {
  19367. result = false;
  19368. return;
  19369. }
  19370. });
  19371. $scope.checks.checked = result;
  19372. var checked = true;
  19373. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19374. if (!message.checked) {
  19375. checked = false;
  19376. }
  19377. });
  19378. $scope.checks.checked = checked;
  19379. };
  19380. $scope.product = {
  19381. checked: false
  19382. };
  19383. var checkResults = function (result) {
  19384. angular.forEach($scope.tableParams.data, function (product) {
  19385. if (product.id == result.prid) {
  19386. product.checked = false;
  19387. angular.forEach(product.matchresults, function (item) {
  19388. if (result.id == item.id) {
  19389. if (item.checked) {
  19390. product.checked = true;
  19391. return;
  19392. }
  19393. } else {
  19394. item.checked = false;
  19395. }
  19396. });
  19397. }
  19398. });
  19399. // checkProductCheck();
  19400. };
  19401. var checkProductCheck = function () {
  19402. var checked = true;
  19403. angular.forEach($scope.tableParams.data, function (product) {
  19404. if (!product.checked) {
  19405. checked = false;
  19406. }
  19407. });
  19408. $scope.product.checked = checked;
  19409. }
  19410. // 单选明细
  19411. $scope.checkItem = function (result) {
  19412. ids = [];
  19413. result.checked = !result.checked;
  19414. checkResults(result);
  19415. }
  19416. // 一键更新
  19417. $scope.updateAll = function () {
  19418. $scope.loading = true;
  19419. angular.forEach($scope.tableParams.data, function (product) {
  19420. if (product.checked) {
  19421. if (product.matchresults.length == 1) {
  19422. ids.push(product.matchresults[0].id);
  19423. }
  19424. if (product.matchresults.length > 1) {
  19425. angular.forEach(product.matchresults, function (item) {
  19426. if (item.checked) {
  19427. ids.push(item.id);
  19428. }
  19429. });
  19430. }
  19431. }
  19432. });
  19433. Products.updateall({status: $scope.checks.checked, type: 'purc'}, ids, function (data) {
  19434. if (data.success) {
  19435. toaster.pop('success', '提示', data.success);
  19436. $timeout(function () {
  19437. $scope.tableParams.page(1);
  19438. $scope.tableParams.reload();
  19439. $scope.loading = false;
  19440. }, 500);
  19441. }
  19442. ids = []; // 清空ids,防止重复点击出现多余的数据
  19443. }, function (response) {
  19444. $scope.loading = false;
  19445. toaster.pop('error', '提示', response.data);
  19446. });
  19447. }
  19448. }]);
  19449. /**
  19450. * 采购物料资料
  19451. */
  19452. 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) {
  19453. BaseService.scrollBackToTop();
  19454. // 用来记录已经选择的id
  19455. $rootScope.ids = [];
  19456. var loadAccount = function () {
  19457. AccountEnterprise.get({}, function (data) {
  19458. $scope.enterprise = data;
  19459. $scope.purcStatus = $scope.enterprise.prodpurc;
  19460. });
  19461. }
  19462. loadAccount();
  19463. $scope.active = 'all';
  19464. $scope.agreedText = '全部';
  19465. $scope.dateZoneText = '一个月内';
  19466. $scope.condition = {dateZone: 1};
  19467. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19468. $scope.changeAgreed = function (agreed) {
  19469. $scope.condition.agreed = agreed;
  19470. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19471. $scope.condition.$agreedOpen = false;
  19472. };
  19473. $scope.changeDateZone = function (zone) {
  19474. $scope.condition.dateZone = zone;
  19475. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19476. $scope.condition.$dateZoneOpen = false;
  19477. getDateCondition(zone, $scope.condition);
  19478. $scope.tableParams.reload();
  19479. };
  19480. $scope.setActive = function (state) {
  19481. if ($scope.active != state) {
  19482. $scope.active = state;
  19483. if ($scope.tableParams.page() == 1)
  19484. $scope.tableParams.reload();
  19485. else
  19486. $scope.tableParams.page(1);
  19487. }
  19488. };
  19489. $scope.searchMethod = false;
  19490. var getService = function () {
  19491. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  19492. };
  19493. $scope.tableParams = new ngTableParams({
  19494. page: 1,
  19495. count: 20,
  19496. sorting: {
  19497. id: 'desc'
  19498. }
  19499. }, {
  19500. total: 0,
  19501. counts: [5, 10, 25, 50],
  19502. getData: function ($defer, params) {
  19503. $scope.loading = true;
  19504. var pageParams = params.url();
  19505. pageParams.keyword = $scope.keyword;
  19506. pageParams.searchFilter = $scope.searchFilter;
  19507. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19508. $scope.loading = false;
  19509. if (page) {
  19510. params.total(page.totalElement);
  19511. $defer.resolve(page.content);
  19512. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19513. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19514. }
  19515. }, function (response) {
  19516. $scope.loading = false;
  19517. toaster.pop('error', '数据加载失败', response.data);
  19518. });
  19519. }
  19520. });
  19521. // //设置单据已读
  19522. // var setOrdersRead = function () {
  19523. // var ids = [];
  19524. // PurcProduct.setRead({}, ids, function (message) {
  19525. // // $scope.getUnreadIds();
  19526. // });
  19527. // };
  19528. // setOrdersRead();
  19529. // 搜索框回车
  19530. $scope.onSearch = function (keyword) {
  19531. $scope.searchMethod = false;
  19532. if(keyword != null && keyword != '') {
  19533. $scope.searchMethod = true;
  19534. }
  19535. $scope.tableParams.page(1);
  19536. $scope.tableParams.reload();
  19537. };
  19538. //删除
  19539. $scope.deleteById = function (id) {
  19540. GetProductInfo.deletePurcById({}, id, function (data) {
  19541. if (data.error) {
  19542. toaster.pop("error", "提示", data.error);
  19543. } else {
  19544. toaster.pop("success", "提示", "删除成功");
  19545. $timeout(function () {
  19546. $scope.tableParams.reload();
  19547. }, 500);
  19548. }
  19549. }), function (response) {
  19550. toaster.pop("error", "删除失败", response.data);
  19551. };
  19552. }
  19553. // 一键开启关闭
  19554. $scope.toggle = function (status) {
  19555. $scope.loading = true;
  19556. Products.toggle({status: status}, {}, function (data) {
  19557. $scope.loading = false;
  19558. toaster.pop('success', '提示', '操作成功');
  19559. loadAccount();
  19560. $scope.tableParams.reload();
  19561. if ($scope.purcStatus == 0) {
  19562. $scope.purcStatus = 1;
  19563. } else {
  19564. $scope.purcStatus = 0;
  19565. }
  19566. }, function (response) {
  19567. $scope.loading = false;
  19568. toaster.pop('error', '提示', response.data);
  19569. })
  19570. }
  19571. var products = [];
  19572. $scope.checks = {
  19573. checked: false
  19574. };
  19575. // 全选框
  19576. $scope.checkAll = function () {
  19577. products = [];// 每次选择时先清空,防止重复
  19578. angular.forEach($scope.tableParams.data, function (product) {
  19579. if (product.cmpUuId == null) {
  19580. product.checked = $scope.checks.checked;
  19581. }
  19582. });
  19583. };
  19584. // 单选
  19585. $scope.checkOne = function (product) {
  19586. products = [];// 每次选择时先清空,防止重复
  19587. var result = true;
  19588. angular.forEach($scope.tableParams.data, function (item) {
  19589. if (item.$selected != true) {
  19590. result = false;
  19591. return;
  19592. }
  19593. });
  19594. $scope.checks.checked = result;
  19595. var checked = true;
  19596. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19597. if (!message.checked) {
  19598. checked = false;
  19599. }
  19600. });
  19601. $scope.checks.checked = checked;
  19602. };
  19603. $scope.updateByBatch = function (updatetype) {
  19604. var modalInstance = $modal.open({
  19605. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  19606. controller: 'UpdateByBatchCtrl',
  19607. size: 'md',
  19608. resolve: {
  19609. updatetype: function () {
  19610. return updatetype;
  19611. },
  19612. active: function () {
  19613. return $scope.active;
  19614. },
  19615. type: function () {
  19616. return 'purchase';
  19617. }
  19618. }
  19619. });
  19620. modalInstance.result.then(function (data) {
  19621. toaster.pop('success', '提示', data.success);
  19622. $scope.tableParams.reload();
  19623. }, function () {
  19624. });
  19625. }
  19626. // 一键匹配
  19627. $scope.matchall = function () {
  19628. $scope.type = "purc";
  19629. $scope.loading = true;
  19630. PurcProduct.matchbytype({type: $scope.type}, {}, function (data) {
  19631. if (data.error) {
  19632. $scope.loading = false;
  19633. toaster.pop('error', '提示', data.error);
  19634. } else {
  19635. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  19636. window.location.href = "#/purc/productmatches";
  19637. }
  19638. }, function (response) {
  19639. $scope.loading = false;
  19640. toaster.pop('error', '提示', response.data);
  19641. });
  19642. }
  19643. // 导出
  19644. $scope.exportXls = function () {
  19645. PurcProduct.exportXls({}, {}, function (data) {
  19646. if (data.success){
  19647. window.location.href = 'purcProduct/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  19648. }
  19649. }, function (response) {
  19650. toaster.pop('error', '数据加载失败', response.data);
  19651. });
  19652. }
  19653. }]);
  19654. /**
  19655. * 采购物料批量上传
  19656. */
  19657. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  19658. BaseService.scrollBackToTop();
  19659. $scope.$watch('myFiles', function () {
  19660. if ($scope.myFiles) {
  19661. var file = $scope.myFiles[0];
  19662. $scope.fileName = file.name;
  19663. }
  19664. })
  19665. // 通过excel批量上传物料
  19666. $scope.upload = function () {
  19667. $scope.loading = true;
  19668. if ($scope.myFiles) {
  19669. var file = $scope.myFiles[0];
  19670. if (file.name) {
  19671. $scope.loading = true;
  19672. $upload.upload({
  19673. url: 'purcProduct/edit/release/excel',
  19674. file: file,
  19675. method: 'POST'
  19676. }).success(function (data) {
  19677. $scope.loading = false;
  19678. if (data.error) {
  19679. toaster.pop('error', '提示', data.error);
  19680. }
  19681. $scope.result = data;
  19682. // $scope.products = $scope.result.products;
  19683. $scope.success = $scope.result.success;
  19684. $scope.total = $scope.result.total;
  19685. $scope.alters = $scope.result.alters;
  19686. $scope.infos = $scope.result.infos;
  19687. $scope.myFiles[0] = "";
  19688. $scope.fileName = "";
  19689. }).error(function (response) {
  19690. $scope.loading = false;
  19691. toaster.pop('error', response.data || response);
  19692. });
  19693. } else {
  19694. $scope.loading = false;
  19695. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  19696. }
  19697. } else {
  19698. $scope.loading = false;
  19699. }
  19700. };
  19701. // 查看范例
  19702. $scope.showImg = function () {
  19703. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  19704. box.show();
  19705. box.find('img').attr('src', src);
  19706. box.find('a').click(function () {
  19707. box.hide();
  19708. });
  19709. box.dblclick(function () {
  19710. box.hide();
  19711. });
  19712. };
  19713. // 下载模板
  19714. $scope.download = function () {
  19715. window.location.href = 'product/baseInfo/upload/template';
  19716. };
  19717. }]);
  19718. /**
  19719. * 新增物料(采购)
  19720. */
  19721. 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) {
  19722. BaseService.scrollBackToTop();
  19723. // 录入人
  19724. AuthenticationService.getAuthentication().success(function (data) {
  19725. $scope.loading = false;
  19726. $scope.user = data;
  19727. });
  19728. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  19729. $scope.prodInfo = {};
  19730. // 选择类目
  19731. $scope.selectKind = function () {
  19732. $modal.open({
  19733. animation: true,
  19734. size: 'lg',
  19735. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  19736. controller: 'KindChooseCtrl',
  19737. }).result.then(function (data) {
  19738. $scope.kindId = data;
  19739. var modalInstance = $modal.open({
  19740. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  19741. controller: 'FindComponentCtrl',
  19742. size: 'lg',
  19743. resolve: {
  19744. KindId: function () {
  19745. return $scope.kindId;
  19746. }
  19747. }
  19748. });
  19749. modalInstance.result.then(function (data) {
  19750. $scope.prodInfo.cmpUuId = data.uuid;
  19751. $scope.prodInfo.pcmpcode = data.code;
  19752. $scope.prodInfo.pbranden = data.brand.nameEn;
  19753. $scope.prodInfo.pbrand = data.brand.nameCn;
  19754. }, function () {
  19755. });
  19756. }, function () {
  19757. });
  19758. };
  19759. // 联想词 start
  19760. // 获取类目
  19761. $scope.getSimilarKinds = function (value) {
  19762. if (value) {
  19763. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  19764. return data.map(function (item) {
  19765. return item;
  19766. });
  19767. });
  19768. }
  19769. };
  19770. $scope.onAssociateKindClick = function (kind, prodInfo) {
  19771. $scope.prodInfo.title = kind.kindName;
  19772. }
  19773. $scope.getSimilarBrands = function (value) {
  19774. if (value) {
  19775. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  19776. return data.map(function (item) {
  19777. return item;
  19778. });
  19779. });
  19780. }
  19781. }
  19782. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  19783. $scope.prodInfo.brand = brand.brandName;
  19784. }
  19785. $scope.getSimilarComponents = function (value) {
  19786. if (value) {
  19787. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  19788. return data.map(function (item) {
  19789. return item;
  19790. });
  19791. });
  19792. }
  19793. }
  19794. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  19795. $scope.prodInfo.cmpCode = cmp.code;
  19796. }
  19797. // 联想词 end
  19798. // 删除
  19799. $scope.clearfile = function () {
  19800. $scope.myFiles = null;
  19801. $scope.previewShow = false;
  19802. }
  19803. //提交
  19804. $scope.submit = function (prodInfo) {
  19805. $scope.loading = true;
  19806. $scope.prodInfo.isPurchase = 1;
  19807. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  19808. $upload.upload({
  19809. url: 'purcProduct/edit/addNewProduct',
  19810. file: file,
  19811. method: 'POST',
  19812. data: {
  19813. prodInfo: prodInfo
  19814. },
  19815. }).success(function (data) {
  19816. $scope.loading = false;
  19817. if (data.success) {
  19818. toaster.pop('success', '提示', data.success);
  19819. $timeout(function () {
  19820. //提交后跳转到详情页面,防止重复提交
  19821. window.location.href = "#/purc/prodList/" + data.id;
  19822. // window.location.href="#/purc/product";
  19823. }, 500);
  19824. }
  19825. if (data.error) {
  19826. toaster.pop('error', '提示', data.error);
  19827. $timeout(function () {
  19828. //提交后跳转到详情页面,防止重复提交
  19829. window.location.href = "#/purc/prodList/" + data.id;
  19830. // window.location.href="#/purc/product";
  19831. }, 500);
  19832. }
  19833. }).error(function (data, status, headers, config) {
  19834. $scope.loading = false;
  19835. $scope.loadingShow = false;
  19836. if (status == 403) {
  19837. toaster.pop('error', '操作失败', data);
  19838. } else {
  19839. toaster.pop('error', '操作失败', data.error);
  19840. }
  19841. });
  19842. };
  19843. $scope.previewShow = false;
  19844. $scope.pdfShow = false;
  19845. $scope.noneFileShow = true;
  19846. $scope.$watch('myFiles', function () {
  19847. if ($scope.myFiles) {
  19848. $scope.noneFileShow = false;
  19849. var file = $scope.myFiles[0];
  19850. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  19851. $scope.pdfShow = true;
  19852. $scope.previewShow = false;
  19853. $scope.imgPreviewName = file.name;
  19854. } else {
  19855. if (typeof(Worker) !== "undefined") {//支持HTML5
  19856. $scope.imgPreview = getObjectURL(file);
  19857. $scope.imgPreviewName = file.name;
  19858. } else {//不支持HTML5
  19859. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  19860. $scope.imgPreviewName = file.name;
  19861. }
  19862. $scope.previewShow = true;
  19863. $scope.pdfShow = false;
  19864. }
  19865. } else {
  19866. $scope.noneFileShow = true;
  19867. $scope.previewShow = false;
  19868. $scope.pdfShow = false;
  19869. }
  19870. });
  19871. //建立一个可存取到该file的url
  19872. var imgurl = null;
  19873. var getObjectURL = function (file) {
  19874. var url = null;
  19875. if (window.createObjectURL != undefined) { // basic
  19876. url = window.createObjectURL(file);
  19877. } else if (window.URL != undefined) { // mozilla(firefox)
  19878. url = window.URL.createObjectURL(file);
  19879. } else if (window.webkitURL != undefined) { // webkit or chrome
  19880. url = window.webkitURL.createObjectURL(file);
  19881. }
  19882. imgurl = url;
  19883. return url;
  19884. };
  19885. // 取消
  19886. $scope.cancel = function () {
  19887. $scope.prodInfo = angular.copy($scope.prodInfo);
  19888. };
  19889. // 查看大图
  19890. $scope.showImg = function () {
  19891. var src = imgurl, box = $('#image-box');
  19892. box.show();
  19893. box.find('img').attr('src', src);
  19894. box.find('a').click(function () {
  19895. box.hide();
  19896. });
  19897. box.dblclick(function () {
  19898. box.hide();
  19899. });
  19900. };
  19901. }]);
  19902. /**
  19903. * 物料详情(采购)
  19904. */
  19905. 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) {
  19906. BaseService.scrollBackToTop();
  19907. // 录入人
  19908. AuthenticationService.getAuthentication().success(function (data) {
  19909. $scope.loading = false;
  19910. $scope.user = data;
  19911. });
  19912. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  19913. $scope.editstatus = false;
  19914. var loadData = function () {
  19915. GetProductInfo.getPurcProduct({id: $stateParams.id}, function (data) {
  19916. if (data.attach) {
  19917. GetProductInfo.getAttach({id: data.attach.id}, function (data) {
  19918. $scope.imgPreview = data.url;
  19919. $scope.previewShow = true;
  19920. })
  19921. }
  19922. $scope.prodInfo = data;
  19923. if ($scope.prodInfo.isbusiness == 0) {
  19924. $scope.editstatus = true;
  19925. }
  19926. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  19927. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  19928. $scope.matchresults = data;
  19929. }, function (response) {
  19930. toaster.pop('error', '提示', response.data);
  19931. });
  19932. }
  19933. $scope.loading = false;
  19934. }, function (response) {
  19935. toaster.pop('error', '数据加载失败', response.data);
  19936. });
  19937. };
  19938. loadData();
  19939. // 联想词 start
  19940. // 获取类目
  19941. $scope.getSimilarKinds = function (value) {
  19942. if (value) {
  19943. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  19944. return data.map(function (item) {
  19945. return item;
  19946. });
  19947. });
  19948. }
  19949. };
  19950. // 设置类目
  19951. $scope.onAssociateKindClick = function (kind, prodInfo) {
  19952. $scope.prodInfo.kind = kind.kindName;
  19953. }
  19954. // 设置名称
  19955. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  19956. $scope.prodInfo.title = kind.kindName;
  19957. }
  19958. $scope.getSimilarBrands = function (value) {
  19959. if (value) {
  19960. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  19961. return data.map(function (item) {
  19962. return item;
  19963. });
  19964. });
  19965. }
  19966. }
  19967. // 设置导入品牌
  19968. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  19969. $scope.prodInfo.brand = brand.brandName;
  19970. }
  19971. // 设置标准品牌
  19972. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  19973. $scope.prodInfo.pbranden = brand.brandName;
  19974. }
  19975. $scope.getSimilarComponents = function (value) {
  19976. if (value) {
  19977. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  19978. return data.map(function (item) {
  19979. return item;
  19980. });
  19981. });
  19982. }
  19983. }
  19984. // 设置标准型号
  19985. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  19986. $scope.prodInfo.pcmpcode = cmp.code;
  19987. }
  19988. // 设置导入的型号
  19989. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  19990. $scope.prodInfo.cmpCode = cmp.code;
  19991. }
  19992. // 联想词 end
  19993. // 选择类目
  19994. $scope.selectKind = function (cmpcode) {
  19995. if (cmpcode == null) {
  19996. $modal.open({
  19997. animation: true,
  19998. size: 'lg',
  19999. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20000. controller: 'KindChooseCtrl',
  20001. }).result.then(function (data) {
  20002. $scope.kindId = data;
  20003. var modalInstance = $modal.open({
  20004. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20005. controller: 'FindComponentCtrl',
  20006. size: 'lg',
  20007. resolve: {
  20008. KindId: function () {
  20009. return $scope.kindId;
  20010. }
  20011. }
  20012. });
  20013. modalInstance.result.then(function (data) {
  20014. $scope.prodInfo.cmpUuId = data.uuid;
  20015. $scope.prodInfo.pcmpcode = data.code;
  20016. $scope.prodInfo.pbranden = data.brand.nameEn;
  20017. $scope.prodInfo.pbrand = data.brand.nameCn;
  20018. }, function () {
  20019. });
  20020. }, function () {
  20021. });
  20022. }
  20023. };
  20024. $scope.isShow = true;
  20025. // 更新
  20026. $scope.update = function () {
  20027. $scope.prodInfo.$editing = true;
  20028. $scope.isShow = true;
  20029. };
  20030. // 取消
  20031. $scope.cancel = function () {
  20032. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  20033. $scope.prodInfo = data;
  20034. $scope.prodInfo.$editing = false;
  20035. $scope.isShow = false;
  20036. $scope.loading = false;
  20037. });
  20038. };
  20039. // 删除
  20040. $scope.clearfile = function () {
  20041. $scope.prodInfo.attach = null;
  20042. $scope.myFiles = null;
  20043. $scope.previewShow = false;
  20044. }
  20045. //删除
  20046. $scope.deleteById = function (id) {
  20047. GetProductInfo.deletePurcById({}, id, function (data) {
  20048. if (data.error) {
  20049. toaster.pop("error", "提示", data.error);
  20050. } else {
  20051. toaster.pop("success", "提示", "删除成功");
  20052. window.location.href = "#/purc/product";
  20053. }
  20054. }, function (response) {
  20055. toaster.pop("error", "删除失败", response.data);
  20056. });
  20057. }
  20058. $scope.submit = function (prodInfo) {
  20059. $scope.prodInfo.isPurchase = 1;
  20060. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20061. $upload.upload({
  20062. url: 'purcProduct/edit/updateProdInfo',
  20063. file: file,
  20064. method: 'POST',
  20065. data: {
  20066. prodInfo: $scope.prodInfo
  20067. },
  20068. }).success(function (data) {
  20069. if (data.success) {
  20070. toaster.pop('success', '提示', data.success);
  20071. loadData();
  20072. // window.location.href="#/sale/prodList";
  20073. }
  20074. if (data.error) {
  20075. toaster.pop('error', '提示', data.error);
  20076. }
  20077. }).error(function (data, status) {
  20078. $scope.loadingShow = false;
  20079. if (status == 403) {
  20080. toaster.pop('error', '操作失败', data);
  20081. } else {
  20082. toaster.pop('error', '操作失败', data.error);
  20083. }
  20084. });
  20085. }
  20086. $scope.previewShow = false;
  20087. $scope.pdfShow = false;
  20088. $scope.noneFileShow = true;
  20089. $scope.$watch('myFiles', function () {
  20090. if ($scope.myFiles) {
  20091. $scope.noneFileShow = false;
  20092. var file = $scope.myFiles[0];
  20093. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20094. $scope.pdfShow = true;
  20095. $scope.previewShow = false;
  20096. $scope.imgPreviewName = file.name;
  20097. } else {
  20098. if (typeof(Worker) !== "undefined") {//支持HTML5
  20099. $scope.imgPreview = getObjectURL(file);
  20100. $scope.imgPreviewName = file.name;
  20101. } else {//不支持HTML5
  20102. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20103. $scope.imgPreviewName = file.name;
  20104. }
  20105. $scope.previewShow = true;
  20106. $scope.pdfShow = false;
  20107. }
  20108. } else {
  20109. $scope.noneFileShow = true;
  20110. $scope.previewShow = false;
  20111. $scope.pdfShow = false;
  20112. }
  20113. });
  20114. //建立一个可存取到该file的url
  20115. var imgurl = null;
  20116. var getObjectURL = function (file) {
  20117. var url = null;
  20118. if (window.createObjectURL != undefined) { // basic
  20119. url = window.createObjectURL(file);
  20120. } else if (window.URL != undefined) { // mozilla(firefox)
  20121. url = window.URL.createObjectURL(file);
  20122. } else if (window.webkitURL != undefined) { // webkit or chrome
  20123. url = window.webkitURL.createObjectURL(file);
  20124. }
  20125. imgurl = url;
  20126. return url;
  20127. };
  20128. // 查看范例
  20129. $scope.showImg = function () {
  20130. if ($scope.prodInfo.attach) {
  20131. GetProductInfo.getAttach({id: $scope.prodInfo.attach.id}, function (data) {
  20132. var src = data.url, box = $('#image-box');
  20133. box.show();
  20134. box.find('img').attr('src', src);
  20135. box.find('a').click(function () {
  20136. box.hide();
  20137. });
  20138. box.dblclick(function () {
  20139. box.hide();
  20140. });
  20141. })
  20142. } else if (imgurl != null) {
  20143. var src = imgurl, box = $('#image-box');
  20144. box.show();
  20145. box.find('img').attr('src', src);
  20146. box.find('a').click(function () {
  20147. box.hide();
  20148. });
  20149. box.dblclick(function () {
  20150. box.hide();
  20151. });
  20152. }
  20153. };
  20154. }]);
  20155. // 供应商绩效考核
  20156. app.controller('VendorPerformanceAssessCtrl', ['$scope', 'VendorPerformanceAssessService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorPerformanceAssessService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  20157. BaseService.scrollBackToTop();
  20158. $scope.vendorPerformanceAssessParams = new ngTableParams({
  20159. page: 1,
  20160. count: 20
  20161. }, {
  20162. total: 0,
  20163. counts: [5, 10, 25, 50],
  20164. getData: function ($defer, params) {
  20165. $scope.loading = true;
  20166. var pageParams = params.url();
  20167. pageParams.keyword = $scope.keyword;
  20168. VendorPerformanceAssessService.get(BaseService.parseParams(pageParams), function (page) {
  20169. $scope.loading = false;
  20170. if (page) {
  20171. params.total(page.totalElement);
  20172. $defer.resolve(page.content);
  20173. $scope.keywordXls = pageParams.keyword;
  20174. }
  20175. $scope.totalCount = page.totalElement;
  20176. }, function (response) {
  20177. $scope.loading = false;
  20178. toaster.pop('error', '数据加载失败', response.data);
  20179. });
  20180. }
  20181. });
  20182. //设置消息已读
  20183. var setOrdersRead = function () {
  20184. var sourceId = [];
  20185. VendorPerformanceAssessService.setRead({}, sourceId, function (message) {
  20186. // $scope.getUnreadIds();
  20187. });
  20188. };
  20189. setOrdersRead();
  20190. // 搜索框回车
  20191. $scope.onSearch = function (keyword) {
  20192. $scope.vendorPerformanceAssessParams.page(1);
  20193. $scope.vendorPerformanceAssessParams.reload();
  20194. $scope.tip = keyword;
  20195. };
  20196. // 查看详情
  20197. $scope.viewDetail = function (id) {
  20198. window.location.hash = "#/sale/vendorPerformanceAssess/" + id;
  20199. }
  20200. }]);
  20201. // 客户详情
  20202. app.controller('VendorPerformanceAssessDetailCtrl', ['$scope', 'toaster', '$stateParams', 'VendorPerformanceAssessService', '$modal', 'ngTableParams', 'BaseService', '$rootScope', 'AuthenticationService', function ($scope, toaster, $stateParams, VendorPerformanceAssessService, $modal, ngTableParams, BaseService, $rootScope, AuthenticationService) {
  20203. BaseService.scrollBackToTop();
  20204. var loadData = function () {
  20205. VendorPerformanceAssessService.getDetail({id: $stateParams.id}, {}, function (data) {
  20206. $scope.vendorPerformanceAssess = data;
  20207. }, function (response) {
  20208. $scope.loading = false;
  20209. toaster.pop('error', '数据加载失败', response.data);
  20210. });
  20211. };
  20212. loadData();
  20213. }]);
  20214. /**
  20215. * 个人产品库
  20216. */
  20217. app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', '$rootScope', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal, $rootScope) {
  20218. BaseService.scrollBackToTop();
  20219. $rootScope.ids = [];// 每次加载先清空数据
  20220. $scope.searchMethod = false;
  20221. var getService = function () {
  20222. return $scope.searchMethod ? prodUser.getInfo : prodUser.info;
  20223. };
  20224. $scope.tableParams = new ngTableParams({ // ng-Table参数
  20225. page: 1,
  20226. count: 20,
  20227. sorting: {
  20228. 'date': 'desc',
  20229. 'id': 'desc'
  20230. }
  20231. }, {
  20232. total: 0,
  20233. counts: [],
  20234. getData: function ($defer, params) { // 获取数据的方法
  20235. $scope.loading = true;
  20236. var pageParams = params.url();
  20237. pageParams.keyword = $scope.keyword;
  20238. $scope.tip = $scope.keyword;
  20239. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  20240. $scope.loading = false;
  20241. if (page) {
  20242. params.total(page.totalElement);
  20243. $defer.resolve(page.content);
  20244. $scope.checkall = true;
  20245. if(page.content.length <= 2) {
  20246. $scope.checkall = false;
  20247. } else {
  20248. angular.forEach(page.content, function (prod) {
  20249. if ($rootScope.ids.indexOf(prod.id) > -1) {
  20250. prod.$selected = true;
  20251. } else {
  20252. $scope.checkall = false;
  20253. }
  20254. });
  20255. }
  20256. $scope.checkboxes = {
  20257. checked: $scope.checkall
  20258. };
  20259. }
  20260. }, function (response) {
  20261. $scope.loading = false;
  20262. toaster.pop('error', '数据加载失败', response.data);
  20263. });
  20264. }
  20265. });
  20266. // 搜索框回车
  20267. $scope.onSearch = function (keyword) {
  20268. // 每次搜索重置获取数据方法
  20269. $scope.searchMethod = false;
  20270. if(keyword != null && keyword != '') {
  20271. $scope.searchMethod = true;
  20272. $scope.tip = keyword;
  20273. }
  20274. $scope.tableParams.page(1);
  20275. $scope.tableParams.reload();
  20276. };
  20277. // 新增产品信息
  20278. $scope.addProduct = function() {
  20279. $modal.open({
  20280. animation: true,
  20281. size: 'lg',
  20282. templateUrl: 'static/tpl/index/approvalFlow/modal/userprod_new_modal.html',
  20283. controller: 'UserProductNewCtrl',
  20284. }).result.then(function (data) {
  20285. $scope.tableParams.page(1);
  20286. $scope.tableParams.reload();
  20287. }, function () {
  20288. });
  20289. }
  20290. // 导入商品信息
  20291. $scope.uploadByBatch = function () {
  20292. var modalInstance = $modal.open({
  20293. templateUrl: 'static/tpl/index/approvalFlow/modal/uplodaByBatch.html',
  20294. controller: 'UserProdUploadCtrl',
  20295. backdrop: 'static',
  20296. keyboard: false,
  20297. size: 'lg',
  20298. resolve: {}
  20299. });
  20300. modalInstance.result.then(function (data) {
  20301. $scope.tableParams.page(1);
  20302. $scope.tableParams.reload();
  20303. }, function () {
  20304. });
  20305. }
  20306. // 删除
  20307. $scope.deleteById = function(id) {
  20308. prodUser.deleteById({}, id, function(data) {
  20309. toaster.pop('success', '提示', '删除成功');
  20310. $scope.tableParams.page(1);
  20311. $scope.tableParams.reload();
  20312. }, function(res) {
  20313. toaster.pop('error', '提示', '删除失败');
  20314. });
  20315. }
  20316. $scope.checkboxes = {
  20317. checked: false
  20318. };
  20319. angular.forEach($scope.tableParams.data, function (item) {
  20320. $scope.checkboxes.checked = false;
  20321. if($rootScope.ids.in_array(item.id)) {
  20322. $rootScope.ids.remove(item.id);
  20323. $scope.checkboxes.checked = true;
  20324. }
  20325. });
  20326. // 点击勾选全部的复选框
  20327. $scope.checkAll = function () {
  20328. angular.forEach($scope.tableParams.data, function (item) {
  20329. item.$selected = $scope.checkboxes.checked;
  20330. if(item.$selected) {
  20331. if(!$rootScope.ids.in_array(item.id)) {
  20332. $rootScope.ids.push(item.id);
  20333. }
  20334. } else {
  20335. if($rootScope.ids.in_array(item.id)) {
  20336. $rootScope.ids.remove(item.id);
  20337. }
  20338. }
  20339. });
  20340. };
  20341. // 判断数组中是否存在某个对象
  20342. Array.prototype.S = String.fromCharCode(2);
  20343. Array.prototype.in_array = function(e) {
  20344. var r = new RegExp(this.S + e + this.S);
  20345. return (r.test(this.S + this.join(this.S) + this.S));
  20346. }
  20347. // 从数组中移除某个对象
  20348. Array.prototype.remove = function(val) {
  20349. var index = this.indexOf(val);
  20350. if (index > -1) {
  20351. this.splice(index, 1);
  20352. }
  20353. };
  20354. // 点击其中一个明细的复选框
  20355. $scope.checkOne = function (product) {
  20356. var result = true;
  20357. angular.forEach($scope.tableParams.data, function (item) {
  20358. if (item.$selected != true) {
  20359. result = false;
  20360. return;
  20361. }
  20362. });
  20363. if(product.$selected) {
  20364. if(!$rootScope.ids.in_array(product.id)) {
  20365. $rootScope.ids.push(product.id);
  20366. }
  20367. } else {
  20368. if($rootScope.ids.in_array(product.id)) {
  20369. $rootScope.ids.remove(product.id);
  20370. }
  20371. }
  20372. $scope.checkboxes = {
  20373. checked: result
  20374. };
  20375. };
  20376. // 批量删除
  20377. $scope.deleteByBatch = function() {
  20378. var ids = angular.toJson($rootScope.ids);
  20379. if($rootScope.ids.length > 0) {
  20380. prodUser.deleteByBatch({ids: ids}, {}, function(data) {
  20381. toaster.pop('success', '提示', '成功移除' + $rootScope.ids.length + '个产品');
  20382. $rootScope.ids = [];
  20383. $scope.tableParams.page(1);
  20384. $scope.tableParams.reload();
  20385. }, function(res) {
  20386. toaster.pop('error', '提示', '移除失败');
  20387. });
  20388. } else {
  20389. toaster.pop('error', '提示', '请先选择产品');
  20390. }
  20391. }
  20392. }]);
  20393. /**
  20394. * 用户产品新增产品
  20395. */
  20396. app.controller('UserProductNewCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', function($scope, toaster, prodUser, $modalInstance) {
  20397. // 确定
  20398. $scope.submit = function(prodInfo) {
  20399. prodUser.addProduct({}, prodInfo, function(data) {
  20400. if(data.success) {
  20401. toaster.pop('success', '提示', data.success);
  20402. } else if(data.info) {
  20403. toaster.pop('info', '提示', data.info);
  20404. }
  20405. $modalInstance.close('success');
  20406. }, function(res) {
  20407. toaster.pop('error', '提示', '添加失败');
  20408. });
  20409. }
  20410. // 取消
  20411. $scope.cancel = function() {
  20412. $modalInstance.dismiss();
  20413. }
  20414. }]);
  20415. /**
  20416. * 用户产品批量导入产品
  20417. */
  20418. app.controller('UserProdUploadCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', '$upload', function($scope, toaster, prodUser, $modalInstance, $upload) {
  20419. // 通过excel批量上传物料
  20420. $scope.upload = function () {
  20421. $scope.loading = true;
  20422. if ($scope.myFiles) {
  20423. var file = $scope.myFiles[0];
  20424. if (file.name) {
  20425. $upload.upload({
  20426. url: 'productuser/edit/release/excel',
  20427. file: file,
  20428. method: 'POST'
  20429. }).success(function (data) {
  20430. $scope.loading = false;
  20431. if (data.error) {
  20432. toaster.pop('error', '提示', data.error);
  20433. }
  20434. $scope.result = data;
  20435. $scope.success = $scope.result.success;
  20436. $scope.total = $scope.result.total;
  20437. $scope.myFiles[0] = "";
  20438. $scope.fileName = "";
  20439. }).error(function (response) {
  20440. $scope.loading = false;
  20441. toaster.pop('error', response.data || response);
  20442. });
  20443. } else {
  20444. $scope.loading = false;
  20445. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20446. }
  20447. } else {
  20448. $scope.loading = false;
  20449. }
  20450. };
  20451. // 取消
  20452. $scope.cancel = function() {
  20453. $modalInstance.dismiss();
  20454. }
  20455. // 下载模板
  20456. $scope.download = function () {
  20457. window.location.href = 'productuser/upload/template';
  20458. };
  20459. // 确定
  20460. $scope.enSure = function() {
  20461. $modalInstance.close('success');
  20462. }
  20463. }]);
  20464. /**
  20465. * 针对卖家,已转询价的公共询价单列表
  20466. */
  20467. app.controller('SalePubInquiryCtrl', ['$scope', '$filter', 'PubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', 'customer', 'AuthenticationService','$stateParams',
  20468. function ($scope, $filter, PubInquirySearchInfo, ngTableParams, toaster, BaseService, PubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, $modal, AccountEnterprise, $http, customer, AuthenticationService, $stateParams) {
  20469. BaseService.scrollBackToTop();
  20470. // 获取当前用户是否为普通用户
  20471. CurrentRole.isUser({}, {}, function (data) {
  20472. $scope.isUser = data.isUser;
  20473. });
  20474. /**
  20475. * active 状态说明:
  20476. * all: 客户公共询价单全部
  20477. * done: 已报价
  20478. * agreed: 已采纳
  20479. * refused: 未采纳
  20480. * invalid: 已失效
  20481. * todo**: 待报价
  20482. * todoAll: 所有公共询价
  20483. * todoRemind: 个人商机
  20484. * todoComRemind: 企业商机
  20485. */
  20486. if ($rootScope.active) {
  20487. $scope.active = $rootScope.active;
  20488. $rootScope.active = null;
  20489. } else {
  20490. $scope.active = 'todoComRemind';
  20491. }
  20492. $scope.agreedText = '全部';
  20493. $scope.dateZoneText = '最近一个月';
  20494. $scope.condition = {dateZone: 1};
  20495. /* 时间筛选初始化*/
  20496. var fromDate = new Date();
  20497. var toDate = new Date();
  20498. fromDate.setMonth(fromDate.getMonth() - 1);
  20499. fromDate.setHours(0, 0, 0, 0);
  20500. toDate.setHours(23, 59, 59, 999);
  20501. $scope.condition.dateFrom = fromDate;
  20502. $scope.condition.dateTo = toDate;
  20503. $scope.changeAgreed = function (agreed) {
  20504. $scope.condition.agreed = agreed;
  20505. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  20506. $scope.condition.$agreedOpen = false;
  20507. };
  20508. $scope.changeDateZone = function (zone) {
  20509. $scope.condition.dateZone = zone;
  20510. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  20511. $scope.condition.$dateZoneOpen = false;
  20512. getDateCondition(zone, $scope.condition);
  20513. $scope.tableParams.page(1);
  20514. $scope.tableParams.reload();
  20515. };
  20516. $scope.setActive = function (state) {
  20517. if ($scope.active != state) {
  20518. $scope.active = state;
  20519. if ($scope.tableParams.page() == 1)
  20520. $scope.tableParams.reload();
  20521. else
  20522. $scope.tableParams.page(1);
  20523. }
  20524. };
  20525. $scope.url = null;
  20526. $scope.tableParams = new ngTableParams({
  20527. page: 1,
  20528. count: 20,
  20529. sorting: {
  20530. 'inquiry.date': 'desc',
  20531. 'inquiry.enterprise.enName': 'asc',
  20532. 'inquiry.code': 'asc'
  20533. }
  20534. }, {
  20535. total: 0,
  20536. counts: [5, 10, 25, 50],
  20537. getData: function ($defer, params) {
  20538. $scope.loading = true;
  20539. var pageParams = params.url();
  20540. pageParams.searchFilter = { // 筛选条件
  20541. keyword: $scope.keyword,
  20542. fromDate: getDateTime($scope.condition.dateFrom),
  20543. endDate: getDateTime($scope.condition.dateTo)
  20544. };
  20545. if ($scope.active == 'overdue') {
  20546. $scope.active = 'end';
  20547. }
  20548. AccountEnterprise.get({}, function(data) {
  20549. $scope.currentEn = data;
  20550. publicInquiry.getUrl({}, function(data) {
  20551. var url = data.url;
  20552. $scope.url = url;
  20553. if ($scope.active == 'todoComRemind') {// 企业商机
  20554. AuthenticationService.getAuthentication().success(function (data) {
  20555. $scope.loading = false;
  20556. $scope.thisUser = data;
  20557. $http({
  20558. method: 'get',
  20559. dataType: 'json',
  20560. url: url + '/inquiry/sale/enremind',
  20561. params: {
  20562. pageNumber: pageParams.page,
  20563. pageSize: pageParams.count,
  20564. useruu: $scope.thisUser.userUU,
  20565. enuu: $scope.currentEn.uu,
  20566. keyword: $scope.keyword,
  20567. fromDate: getDateTime($scope.condition.dateFrom),
  20568. endDate: getDateTime($scope.condition.dateTo),
  20569. enableOffer: 1
  20570. }
  20571. }).success(function (response) {
  20572. $scope.loading = false;
  20573. if (response) {
  20574. params.total(response.totalElements);
  20575. $defer.resolve(response.content);
  20576. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  20577. }
  20578. }).error(function (err) {
  20579. $scope.loading = false;
  20580. toaster.pop('error', '数据加载失败', err);
  20581. });
  20582. });
  20583. } else if ($scope.active == 'todoRemind') {// 推荐报价信息
  20584. AuthenticationService.getAuthentication().success(function (data) {
  20585. $scope.loading = false;
  20586. $scope.thisUser = data;
  20587. $http({
  20588. method: 'get',
  20589. dataType: 'json',
  20590. url: url + '/inquiry/sale/remind',
  20591. params: {
  20592. pageNumber: pageParams.page,
  20593. pageSize: pageParams.count,
  20594. useruu: $scope.thisUser.userUU,
  20595. enuu: $scope.currentEn.uu,
  20596. enableOffer: 1,
  20597. keyword: $scope.keyword,
  20598. fromDate: getDateTime($scope.condition.dateFrom),
  20599. endDate: getDateTime($scope.condition.dateTo)
  20600. }
  20601. }).success(function (response) {
  20602. $scope.loading = false;
  20603. if (response) {
  20604. params.total(response.totalElements);
  20605. $defer.resolve(response.content);
  20606. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  20607. }
  20608. }).error(function (err) {
  20609. $scope.loading = false;
  20610. toaster.pop('error', '数据加载失败', err);
  20611. });
  20612. });
  20613. } else if ($scope.active == 'todoAll') {// 全部
  20614. $http({
  20615. method: 'get',
  20616. dataType: 'json',
  20617. url: url + '/inquiry/public',
  20618. params: {pageNumber: pageParams.page, pageSize: pageParams.count, enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  20619. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo), distribute: $scope.distribute, remind: $scope.remind}
  20620. }).success(function (response) {
  20621. $scope.loading = false;
  20622. if (response) {
  20623. params.total(response.totalElements);
  20624. $defer.resolve(response.content);
  20625. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  20626. }
  20627. }).error(function (err) {
  20628. $scope.loading = false;
  20629. toaster.pop('error', '数据加载失败', err);
  20630. });
  20631. } else {
  20632. var filter = {vendUU: $scope.currentEn.uu, keyword: $scope.keyword,
  20633. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  20634. $http({
  20635. method: 'get',
  20636. dataType: 'json',
  20637. url: url + '/inquiry/public/quotation/list',
  20638. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  20639. }).success(function (response) {
  20640. $scope.loading = false;
  20641. if (response) {
  20642. params.total(response.totalElements);
  20643. $defer.resolve(response.content);
  20644. }
  20645. }).error(function (err) {
  20646. $scope.loading = false;
  20647. toaster.pop('error', '数据加载失败', err);
  20648. });
  20649. }
  20650. });
  20651. });
  20652. }
  20653. });
  20654. $scope.getMinDate = function (item) {
  20655. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  20656. };
  20657. // 搜索框回车
  20658. $scope.onSearch = function (keyword) {
  20659. // 每次搜索重置获取数据方法
  20660. $scope.searchMethod = false;
  20661. if(keyword != null && keyword != '') {
  20662. $scope.searchMethod = true;
  20663. }
  20664. $scope.tableParams.page(1);
  20665. $scope.tableParams.reload();
  20666. };
  20667. // 取消
  20668. $scope.cancel = function () {
  20669. $scope.tableParams.reload();
  20670. }
  20671. // 导出
  20672. $scope.exportXls = function () {
  20673. PurcInquiry.exportXls({}, {}, function (data) {
  20674. if (data.success) {
  20675. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  20676. }
  20677. }, function (response) {
  20678. toaster.pop('error', '数据加载失败', response.data);
  20679. })
  20680. }
  20681. $scope.isOverDue = function (date) {
  20682. if (date) {
  20683. var ndate = new Date();
  20684. ndate.setHours(23, 59, 59 ,999);
  20685. ndate.setDate(ndate.getDate());
  20686. var timestamp = Date.parse(ndate);
  20687. if (date > timestamp) {
  20688. return true;
  20689. } else {
  20690. return false;
  20691. }
  20692. } else {
  20693. return true;
  20694. }
  20695. }
  20696. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  20697. customer.distribute({}, function(data) {
  20698. $scope.customer = data;
  20699. });
  20700. $scope.toDetail = function (item) {
  20701. if (item.quoted == 0) {
  20702. window.location.hash = '#/baseInfo/inquiryList/' + item.id;
  20703. } else {
  20704. window.open("#/sale/pubinquiry/" + item.quteId);
  20705. }
  20706. };
  20707. // 转客户询价
  20708. $scope.qute = function (remind) {
  20709. $http({
  20710. method: 'get',
  20711. dataType: 'json',
  20712. url: $scope.url + '/inquiry/sale/quote',
  20713. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  20714. }).success(function (response) {
  20715. $scope.loading = false;
  20716. if (response.inquiry != null) {
  20717. toaster.pop('error', '该单据已报价');
  20718. } else {
  20719. $http({
  20720. method: 'get',
  20721. dataType: 'json',
  20722. url: $scope.url + '/inquiry/public/findItemByItemId',
  20723. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  20724. }).success(function (response) {
  20725. var inquiryItem = response;
  20726. var modalInstance = $modal.open({
  20727. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  20728. controller: 'QuoteCtrl',
  20729. size: 'lg',
  20730. resolve: {
  20731. inquiryItem: function () {
  20732. return inquiryItem
  20733. }
  20734. }
  20735. });
  20736. modalInstance.result.then(function (data) {
  20737. $scope.tableParams.reload();
  20738. }, function () {
  20739. });
  20740. }).error(function (error) {
  20741. toaster.pop('error', '数据加载失败', error);
  20742. });
  20743. }
  20744. }).error(function (err) {
  20745. toaster.pop('error', '数据加载失败', err);
  20746. });
  20747. }
  20748. // 跳转详情
  20749. $scope.remindDetail = function(remind) {
  20750. if (remind.newId == null) {
  20751. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  20752. } else {
  20753. window.open("#/sale/pubinquiry/" + remind.newId);
  20754. }
  20755. }
  20756. // 搜索框回车
  20757. $scope.onSearch = function () {
  20758. $scope.tableParams.page(1);
  20759. $scope.tableParams.reload();
  20760. };
  20761. // 转客户询价
  20762. $scope.transtoInquiry = function (inquiryItem) {
  20763. if ($scope.currentEn.uu == inquiryItem.inquiry.enUU) {
  20764. toaster.pop('warning', '不能对自己企业报价');
  20765. } else {
  20766. var modalInstance = $modal.open({
  20767. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  20768. controller: 'QuoteCtrl',
  20769. size: 'lg',
  20770. resolve: {
  20771. inquiryItem: function () {
  20772. return inquiryItem
  20773. }
  20774. }
  20775. });
  20776. modalInstance.result.then(function (data) {
  20777. $scope.tableParams.reload();
  20778. }, function () {
  20779. });
  20780. }
  20781. }
  20782. // 跳转到我的报价列表
  20783. $scope.linkToInquiry = function () {
  20784. window.open("#/sale/pubinquiry");
  20785. }
  20786. }]);
  20787. /**
  20788. * 针对卖家,已转询价单的客户公共询价单明细
  20789. */
  20790. app.controller('SalePubInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'publicInquiry', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole, publicInquiry) {
  20791. // 获取当前用户是否为普通用户
  20792. var loadData = function () {
  20793. publicInquiry.inquiryDetail({id: $stateParams.id}, function (data) {
  20794. $scope.inquiryItem = data;
  20795. var inquiry = data.inquiry;
  20796. angular.forEach(inquiry.attachs, function (attach) {
  20797. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  20798. });
  20799. $scope.inquiry = inquiry;
  20800. $scope.attach = null;
  20801. if ($scope.inquiryItem.attaches.length > 0) {
  20802. $scope.attach = $scope.inquiryItem.attaches[0];
  20803. }
  20804. }, function (response) {
  20805. $scope.loading = false;
  20806. toaster.pop('error', '', response.data);
  20807. });
  20808. };
  20809. loadData();
  20810. $scope.getMinDate = function (item) {
  20811. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  20812. };
  20813. $scope.replyPrices = [];
  20814. $scope.replylapQtys = [];
  20815. $scope.replyPrices.push(true);
  20816. $scope.replylapQtys.push(true);
  20817. $scope.addStep = function (inquiryItem) {
  20818. if (inquiryItem.replies.length >= 10) {
  20819. toaster.pop('warning', '提示', '最多支持10个分段!');
  20820. } else
  20821. inquiryItem.replies.push({});
  20822. };
  20823. $scope.removeStep = function (inquiryItem, stepIndex) {
  20824. inquiryItem.replies.splice(stepIndex, 1);
  20825. };
  20826. $scope.openDatePicker = function ($event, item, openParam) {
  20827. $event.preventDefault();
  20828. $event.stopPropagation();
  20829. item[openParam] = !item[openParam];
  20830. };
  20831. $scope.getHistory = function (item) {
  20832. if (!item.history) {
  20833. publicInquiry.getHistory({itemId: item.id}, function (data) {
  20834. item.history = data;
  20835. });
  20836. }
  20837. };
  20838. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  20839. $scope.verify = function (value, type) {
  20840. var regex = /^\d+(.\d{1,6})?$/;//
  20841. switch (type) {
  20842. case 'minOrderQty':
  20843. $scope.minOrderQtyVerify = regex.test(value);
  20844. break;
  20845. case 'minPackQty':
  20846. $scope.minPackQtyVerify = regex.test(value);
  20847. break;
  20848. case 'leadtime':
  20849. $scope.leadtimeVerify = regex.test(value);
  20850. break;
  20851. default:
  20852. $scope.replyPrices[type] = regex.test(value);
  20853. break;
  20854. }
  20855. }
  20856. $scope.verifylapQty = function (value, index, inquiryItem) {
  20857. value = parseInt(value);
  20858. var regex = /^\d+(.\d{1,6})?$/;
  20859. var valid = true;
  20860. angular.forEach(inquiryItem.replies, function(reply, $index) {
  20861. if ($index < index && reply.lapQty >= value) {
  20862. valid = false;
  20863. }
  20864. });
  20865. $scope.replylapQtys[index] = regex.test(value) && valid;
  20866. };
  20867. $scope.isValid = function (item, withSteps) {
  20868. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  20869. if (!withSteps || !bool)
  20870. return bool;
  20871. angular.forEach(item.replies, function (r, i) {
  20872. $scope.verifylapQty(r.lapQty, i, item);
  20873. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  20874. });
  20875. return bool;
  20876. };
  20877. $scope.deleteAttach = function (attaches, index) {
  20878. attaches.splice(index, 1);
  20879. };
  20880. $scope.onReplyClick = function (item, withSteps) {
  20881. if (item.vendFromDate instanceof Date) {
  20882. item.vendFromDate = item.vendFromDate.getTime();
  20883. }
  20884. if (item.vendToDate instanceof Date) {
  20885. item.vendToDate = item.vendToDate.getTime();
  20886. }
  20887. if (item.vendFromDate > item.vendToDate) {
  20888. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  20889. return;
  20890. }
  20891. var replies = [];
  20892. var valid = true;
  20893. var validLapQty = 0;
  20894. angular.forEach(item.replies, function (r, i) {
  20895. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  20896. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  20897. valid = false;
  20898. validLapQty = r.lapQty;
  20899. }
  20900. if ((i > 0 ? r.lapQty : 1) || r.price)
  20901. replies.push(r);
  20902. });
  20903. item.replies = replies;
  20904. $scope.loading = true;
  20905. if (!valid) { // 不合法时给出提示
  20906. if (validLapQty) {
  20907. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  20908. } else {
  20909. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  20910. }
  20911. $scope.loading = false;
  20912. } else {
  20913. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  20914. if (withSteps) {
  20915. if(null != file) {
  20916. $upload.upload({
  20917. url: 'sale/pubInquiry/addAttach',
  20918. file: file,
  20919. method: 'POST',
  20920. data: {
  20921. item: item,
  20922. method: 'reply'
  20923. }
  20924. }).success(function (data) {
  20925. if (data.item) {
  20926. item = data.item;
  20927. }
  20928. toaster.pop('success', '提示', '报价成功');
  20929. loadData();
  20930. }).error(function () {
  20931. toaster.pop('error', '提示', '报价失败');
  20932. });
  20933. } else {
  20934. publicInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  20935. $scope.loading = false;
  20936. toaster.pop('success', '提示', '报价成功');
  20937. loadData();
  20938. }, function (response) {
  20939. $scope.loading = false;
  20940. toaster.pop('error', '询价失效', response.data);
  20941. });
  20942. }
  20943. } else {
  20944. if(null != file) {
  20945. $upload.upload({
  20946. url: 'sale/pubInquiry/addAttach',
  20947. file: file,
  20948. method: 'POST',
  20949. data: {
  20950. item: item,
  20951. method: 'save'
  20952. }
  20953. }).success(function (data) {
  20954. if (data.item) {
  20955. item = data.item;
  20956. }
  20957. toaster.pop('success', '提示', '保存成功');
  20958. loadData();
  20959. }).error(function () {
  20960. toaster.pop('error', '提示', '保存失败');
  20961. });
  20962. } else {
  20963. publicInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  20964. $scope.loading = false;
  20965. toaster.pop('info', '提示', '保存成功');
  20966. loadData();
  20967. }, function (response) {
  20968. $scope.loading = false;
  20969. toaster.pop('error', '保存失败', response.data);
  20970. });
  20971. }
  20972. }
  20973. }
  20974. };
  20975. // 取消
  20976. $scope.cancel = function () {
  20977. $scope.tableParams.reload();
  20978. }
  20979. }]);
  20980. /**
  20981. * 针对买家,已转询价的公共询价单列表
  20982. */
  20983. app.controller('PurcPubInquiryCtrl', ['$scope', '$filter', 'PurcPubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PurcPubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', 'AccountEnterprise', '$http', function ($scope, $filter, PurcPubInquirySearchInfo, ngTableParams, toaster, BaseService, PurcPubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, AccountEnterprise, $http) {
  20984. BaseService.scrollBackToTop();
  20985. // 获取当前用户是否为普通用户
  20986. CurrentRole.isUser({}, {}, function (data) {
  20987. $scope.isUser = data.isUser;
  20988. });
  20989. if ($rootScope.active) {
  20990. $scope.active = $rootScope.active;
  20991. $rootScope.active = null;
  20992. } else {
  20993. $scope.active = 'all';
  20994. }
  20995. $scope.agreedText = '全部';
  20996. $scope.dateZoneText = '最近一个月';
  20997. $scope.condition = {dateZone: 1};
  20998. /* 时间筛选初始化*/
  20999. var fromDate = new Date();
  21000. var toDate = new Date();
  21001. fromDate.setMonth(fromDate.getMonth() - 1);
  21002. fromDate.setHours(0, 0, 0, 0);
  21003. toDate.setHours(23, 59, 59, 999);
  21004. $scope.condition.dateFrom = fromDate;
  21005. $scope.condition.dateTo = toDate;
  21006. $scope.changeAgreed = function (agreed) {
  21007. $scope.condition.agreed = agreed;
  21008. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  21009. $scope.condition.$agreedOpen = false;
  21010. };
  21011. $scope.changeDateZone = function (zone) {
  21012. $scope.condition.dateZone = zone;
  21013. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21014. $scope.condition.$dateZoneOpen = false;
  21015. getDateCondition(zone, $scope.condition);
  21016. $scope.tableParams.page(1);
  21017. $scope.tableParams.reload();
  21018. };
  21019. $scope.setActive = function (state) {
  21020. if ($scope.active != state) {
  21021. $scope.active = state;
  21022. if ($scope.tableParams.page() == 1)
  21023. $scope.tableParams.reload();
  21024. else
  21025. $scope.tableParams.page(1);
  21026. }
  21027. };
  21028. $scope.searchMethod = false;
  21029. var getService = function () {
  21030. return $scope.searchMethod ? PurcPubInquirySearchInfo : PurcPubInquiryNoSearchInfo;
  21031. };
  21032. $scope.tableParams = new ngTableParams({
  21033. page: 1,
  21034. count: 20,
  21035. sorting: {
  21036. 'inquiry.date': 'desc',
  21037. 'inquiry.enterprise.enName': 'asc',
  21038. 'inquiry.code': 'asc'
  21039. }
  21040. }, {
  21041. total: 0,
  21042. counts: [5, 10, 25, 50],
  21043. getData: function ($defer, params) {
  21044. $scope.loading = true;
  21045. var pageParams = params.url();
  21046. var realActive = {};
  21047. pageParams.searchFilter = { // 筛选条件
  21048. keyword: $scope.keyword,
  21049. fromDate: getDateTime($scope.condition.dateFrom),
  21050. endDate: getDateTime($scope.condition.dateTo)
  21051. };
  21052. if ($scope.active == 'overdue') {
  21053. $scope.active = 'end';
  21054. }
  21055. AccountEnterprise.get({}, function(data) {
  21056. $scope.currentEn = data;
  21057. publicInquiry.getUrl({}, function(data) {
  21058. var url = data.url;
  21059. var filter = {enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21060. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21061. $http({
  21062. method: 'get',
  21063. dataType: 'json',
  21064. url: url + '/inquiry/public/quotation/list',
  21065. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21066. }).success(function (response) {
  21067. $scope.loading = false;
  21068. if (response) {
  21069. params.total(response.totalElements);
  21070. $defer.resolve(response.content);
  21071. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  21072. }
  21073. }).error(function (err) {
  21074. $scope.loading = false;
  21075. toaster.pop('error', '数据加载失败', err);
  21076. });
  21077. });
  21078. });
  21079. }
  21080. });
  21081. $scope.isUnread = function (id) {
  21082. for (var i in $scope.unreadCode) {
  21083. if (id == $scope.unreadCode[i]) {
  21084. return true;
  21085. }
  21086. }
  21087. };
  21088. $scope.getMinDate = function (item) {
  21089. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21090. };
  21091. $scope.replyPrices = [];
  21092. $scope.replylapQtys = [];
  21093. $scope.replyPrices.push(true);
  21094. $scope.replylapQtys.push(true);
  21095. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21096. $event.preventDefault();
  21097. $event.stopPropagation();
  21098. item[openParam] = !item[openParam];
  21099. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21100. $scope.tableParams.reload();
  21101. }
  21102. };
  21103. $scope.getHistory = function (item) {
  21104. if (!item.history) {
  21105. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21106. item.history = data;
  21107. });
  21108. }
  21109. };
  21110. // 搜索框回车
  21111. $scope.onSearch = function (keyword) {
  21112. // 每次搜索重置获取数据方法
  21113. $scope.searchMethod = false;
  21114. if(keyword != null && keyword != '') {
  21115. $scope.searchMethod = true;
  21116. }
  21117. $scope.tableParams.page(1);
  21118. $scope.tableParams.reload();
  21119. };
  21120. // 采纳
  21121. $scope.accept = function (id) {
  21122. publicInquiry.accept({id: id}, {}, function (data) {
  21123. if (data.success) {
  21124. toaster.pop('success', '提示', data.success);
  21125. $scope.tableParams.page(1);
  21126. $scope.tableParams.reload();
  21127. }
  21128. if (data.error) {
  21129. toaster.pop('error', '提示', data.error);
  21130. $scope.tableParams.page(1);
  21131. $scope.tableParams.reload();
  21132. }
  21133. }, function (response) {
  21134. toaster.pop('error', '提示', '采纳失败');
  21135. $scope.tableParams.page(1);
  21136. $scope.tableParams.reload();
  21137. })
  21138. };
  21139. // 拒绝
  21140. $scope.refuse = function (id) {
  21141. publicInquiry.refuse({id: id}, {}, function (data) {
  21142. if (data.success) {
  21143. toaster.pop('success', '提示', data.success);
  21144. $scope.tableParams.page(1);
  21145. $scope.tableParams.reload();
  21146. }
  21147. if (data.error) {
  21148. toaster.pop('error', '提示', data.error);
  21149. $scope.tableParams.page(1);
  21150. $scope.tableParams.reload();
  21151. }
  21152. }, function (response) {
  21153. toaster.pop('error', '提示', '操作失败');
  21154. $scope.tableParams.page(1);
  21155. $scope.tableParams.reload();
  21156. })
  21157. }
  21158. // 导出
  21159. $scope.exportXls = function () {
  21160. PurcInquiry.exportXls({}, {}, function (data) {
  21161. if (data.success) {
  21162. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21163. }
  21164. }, function (response) {
  21165. toaster.pop('error', '数据加载失败', response.data);
  21166. })
  21167. }
  21168. }]);
  21169. /**
  21170. * 针对买家,已转询价单的客户公共询价单明细
  21171. */
  21172. app.controller('PurcPubInquiryDetailCtrl', ['$scope', '$stateParams', 'publicInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'AccountEnterprise', '$http', function ($scope, $stateParams, publicInquiry, $filter, toaster, $upload, token, CurrentRole, AccountEnterprise, $http) {
  21173. // 获取当前用户是否为普通用户
  21174. CurrentRole.isUser({}, {}, function (data) {
  21175. $scope.isUser = data.isUser;
  21176. });
  21177. AccountEnterprise.get({}, function(data) {
  21178. $scope.currentEn = data;
  21179. publicInquiry.getUrl({}, function(data) {
  21180. var url = data.url;
  21181. $http({
  21182. method: 'get',
  21183. dataType: 'json',
  21184. url: url + '/inquiry/buyer/detail',
  21185. params: {id: $stateParams.id, enuu: $scope.currentEn.uu}
  21186. }).success(function (response) {
  21187. $scope.newinquiryItems = response;
  21188. var inquiry = response;
  21189. angular.forEach(inquiry.attachs, function (attach) {
  21190. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21191. });
  21192. $scope.inquiry = inquiry;
  21193. });
  21194. });
  21195. });
  21196. $scope.getMinDate = function (item) {
  21197. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21198. };
  21199. $scope.replyPrices = [];
  21200. $scope.replylapQtys = [];
  21201. $scope.replyPrices.push(true);
  21202. $scope.replylapQtys.push(true);
  21203. $scope.getHistory = function (item) {
  21204. if (!item.history) {
  21205. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21206. item.history = data;
  21207. });
  21208. }
  21209. };
  21210. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21211. $scope.verify = function (value, type) {
  21212. var regex = /^\d+(.\d{1,6})?$/;//
  21213. switch (type) {
  21214. case 'minOrderQty':
  21215. $scope.minOrderQtyVerify = regex.test(value);
  21216. break;
  21217. case 'minPackQty':
  21218. $scope.minPackQtyVerify = regex.test(value);
  21219. break;
  21220. case 'leadtime':
  21221. $scope.leadtimeVerify = regex.test(value);
  21222. break;
  21223. default:
  21224. $scope.replyPrices[type] = regex.test(value);
  21225. break;
  21226. }
  21227. }
  21228. // 采纳
  21229. $scope.accept = function (id) {
  21230. publicInquiry.accept({id: id}, {}, function (data) {
  21231. if (data.success) {
  21232. toaster.pop('success', '提示', data.success);
  21233. loadData();
  21234. }
  21235. if (data.error) {
  21236. toaster.pop('error', '提示', data.error);
  21237. }
  21238. }, function (response) {
  21239. toaster.pop('error', '提示', response.data);
  21240. })
  21241. };
  21242. // 拒绝
  21243. $scope.refuse = function (id) {
  21244. publicInquiry.refuse({id: id}, {}, function (data) {
  21245. if (data.success) {
  21246. toaster.pop('success', '提示', data.success);
  21247. loadData();
  21248. }
  21249. if (data.error) {
  21250. toaster.pop('error', '提示', data.error);
  21251. }
  21252. }, function (response) {
  21253. toaster.pop('error', '提示', response.data);
  21254. })
  21255. }
  21256. }]);
  21257. /**
  21258. * 公共询价模态框(供应商报价)
  21259. */
  21260. app.controller('QuoteInquiryCtrl', ['$scope', '$stateParams', 'toaster', 'inquiryItem', '$modalInstance', '$upload', function ($scope, $stateParams, toaster, inquiryItem, $modalInstance, $upload) {
  21261. $scope.inquiryItem = inquiryItem;
  21262. $scope.replyPrices = [];
  21263. $scope.replylapQtys = [];
  21264. $scope.replyPrices.push(true);
  21265. $scope.replylapQtys.push(true);
  21266. // 增加一列分段报价
  21267. $scope.addStep = function (inquiryItem) {
  21268. $scope.replyPrices.push(true);
  21269. if (inquiryItem.replies.length >= 5) {
  21270. toaster.pop('warning', '提示', '最多支持5个分段!');
  21271. } else {
  21272. inquiryItem.replies.push({});
  21273. if (inquiryItem.replies.length != 1) {
  21274. $scope.replyPrices.push(true);
  21275. $scope.replylapQtys.push(true);
  21276. }
  21277. }
  21278. };
  21279. // 删除一列分段报价
  21280. $scope.removeStep = function (inquiryItem, stepIndex) {
  21281. inquiryItem.replies.splice(stepIndex, 1);
  21282. $scope.replyPrices.splice(stepIndex, 1);
  21283. $scope.replylapQtys.splice(stepIndex, 1);
  21284. };
  21285. // 取消,关闭弹出框
  21286. $scope.cancel = function() {
  21287. $modalInstance.dismiss();
  21288. }
  21289. // 保存报价信息
  21290. $scope.save = function(inquiryItem, method) {
  21291. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  21292. $upload.upload({
  21293. url: 'pubInquiry/turnToQuotation',
  21294. file: file,
  21295. method: 'POST',
  21296. data: {
  21297. item: inquiryItem,
  21298. method: method
  21299. }
  21300. }).success(function (data) {
  21301. if (data.item) {
  21302. item = data.item;
  21303. }
  21304. $scope.loading = false;
  21305. toaster.pop('info', '提示', '报价成功');
  21306. $scope.tableParams.reload();
  21307. }).error(function (data) {
  21308. $scope.loading = false;
  21309. toaster.pop('error', '报价失败');
  21310. });
  21311. }
  21312. }]);
  21313. /**
  21314. * 首页侧边栏询价列表
  21315. */
  21316. app.controller('InquiryMessageListCtrl', ['$scope', 'publicInquiry', 'AccountEnterprise', '$http', function($scope, publicInquiry, AccountEnterprise, $http) {
  21317. AccountEnterprise.get({}, function(data) {
  21318. $scope.currentEn = data;
  21319. publicInquiry.getUrl({}, function (data) {
  21320. var url = data.url;
  21321. $http({
  21322. method: 'get',
  21323. url: url + '/inquiry/public/messageList',
  21324. params: {enuu: $scope.currentEn.uu, size: 7},
  21325. dataType: 'json'
  21326. }).success(function(data) {
  21327. $scope.message = data;
  21328. }).error(function(error) {
  21329. });
  21330. });
  21331. });
  21332. }]);
  21333. /**
  21334. * 针对卖家,询价推荐列表
  21335. */
  21336. app.controller('SaleInquiryRemindCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', 'AuthenticationService', function ($scope, $filter, ngTableParams, toaster, BaseService, publicInquiry, $modal, AccountEnterprise, $http, AuthenticationService) {
  21337. BaseService.scrollBackToTop();
  21338. $scope.agreedText = '全部';
  21339. $scope.dateZoneText = '最近一个月';
  21340. $scope.condition = {dateZone: 1};
  21341. /* 时间筛选初始化*/
  21342. var fromDate = new Date();
  21343. var toDate = new Date();
  21344. fromDate.setMonth(fromDate.getMonth() - 1);
  21345. fromDate.setHours(0, 0, 0, 0);
  21346. toDate.setHours(23, 59, 59, 999);
  21347. $scope.condition.dateFrom = fromDate;
  21348. $scope.condition.dateTo = toDate;
  21349. $scope.changeDateZone = function (zone) {
  21350. $scope.condition.dateZone = zone;
  21351. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21352. $scope.condition.$dateZoneOpen = false;
  21353. getDateCondition(zone, $scope.condition);
  21354. $scope.tableParams.page(1);
  21355. $scope.tableParams.reload();
  21356. };
  21357. $scope.tableParams = new ngTableParams({
  21358. page: 1,
  21359. count: 20,
  21360. sorting: {
  21361. 'date': 'desc'
  21362. }
  21363. }, {
  21364. total: 0,
  21365. counts: [5, 10, 25, 50],
  21366. getData: function ($defer, params) {
  21367. $scope.loading = true;
  21368. var pageParams = params.url();
  21369. var realActive = {};
  21370. pageParams.searchFilter = { // 筛选条件
  21371. keyword: $scope.keyword,
  21372. fromDate: getDateTime($scope.condition.dateFrom),
  21373. endDate: getDateTime($scope.condition.dateTo)
  21374. };
  21375. if ($scope.active == 'overdue') {
  21376. $scope.active = 'end';
  21377. }
  21378. AccountEnterprise.get({}, function(data) {
  21379. $scope.currentEn = data;
  21380. publicInquiry.getUrl({}, function(data) {
  21381. $scope.url = data.url;
  21382. AuthenticationService.getAuthentication().success(function (data) {
  21383. $scope.loading = false;
  21384. $scope.thisUser = data;
  21385. $http({
  21386. method: 'get',
  21387. dataType: 'json',
  21388. url: $scope.url + '/inquiry/sale/remind',
  21389. params: {pageNumber: pageParams.page, pageSize: pageParams.count, useruu: $scope.thisUser.userUU, enuu: $scope.currentEn.uu,
  21390. keyword: $scope.keyword, fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)}
  21391. }).success(function (response) {
  21392. $scope.loading = false;
  21393. if (response) {
  21394. params.total(response.totalElements);
  21395. $defer.resolve(response.content);
  21396. }
  21397. }).error(function (err) {
  21398. $scope.loading = false;
  21399. toaster.pop('error', '数据加载失败', err);
  21400. });
  21401. });
  21402. });
  21403. });
  21404. }
  21405. });
  21406. $scope.getMinDate = function (item) {
  21407. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21408. };
  21409. $scope.openDatePicker = function ($event, item, openParam) {
  21410. $event.preventDefault();
  21411. $event.stopPropagation();
  21412. item[openParam] = !item[openParam];
  21413. };
  21414. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21415. $event.preventDefault();
  21416. $event.stopPropagation();
  21417. item[openParam] = !item[openParam];
  21418. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21419. $scope.tableParams.reload();
  21420. }
  21421. };
  21422. // 搜索框回车
  21423. $scope.onSearch = function (keyword) {
  21424. // 每次搜索重置获取数据方法
  21425. $scope.searchMethod = false;
  21426. if(keyword != null && keyword != '') {
  21427. $scope.searchMethod = true;
  21428. }
  21429. $scope.tableParams.page(1);
  21430. $scope.tableParams.reload();
  21431. };
  21432. // 取消
  21433. $scope.cancel = function () {
  21434. $scope.tableParams.reload();
  21435. }
  21436. // 转客户询价
  21437. $scope.qute = function (remind) {
  21438. $http({
  21439. method: 'get',
  21440. dataType: 'json',
  21441. url: $scope.url + '/inquiry/sale/quote',
  21442. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  21443. }).success(function (response) {
  21444. $scope.loading = false;
  21445. if (response.inquiry != null) {
  21446. toaster.pop('error', '该单据已报价');
  21447. } else {
  21448. $http({
  21449. method: 'get',
  21450. dataType: 'json',
  21451. url: $scope.url + '/inquiry/public/findItemByItemId',
  21452. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  21453. }).success(function (response) {
  21454. var inquiryItem = response;
  21455. var modalInstance = $modal.open({
  21456. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  21457. controller: 'QuoteCtrl',
  21458. size: 'lg',
  21459. resolve: {
  21460. inquiryItem: function () {
  21461. return inquiryItem
  21462. }
  21463. }
  21464. });
  21465. modalInstance.result.then(function (data) {
  21466. $scope.tableParams.reload();
  21467. }, function () {
  21468. });
  21469. }).error(function (error) {
  21470. toaster.pop('error', '数据加载失败', error);
  21471. });
  21472. }
  21473. }).error(function (err) {
  21474. toaster.pop('error', '数据加载失败', err);
  21475. });
  21476. }
  21477. // 跳转详情
  21478. $scope.toDetail = function(remind) {
  21479. if (remind.newId == null) {
  21480. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  21481. } else {
  21482. window.open("#/sale/pubinquiry/" + remind.newId);
  21483. }
  21484. }
  21485. }]);
  21486. /**
  21487. * 采购变更单列表
  21488. *
  21489. * @author hejq
  21490. * @date 2018-06-25 17:13
  21491. */
  21492. app.controller('PurcChangeListCtrl', ['$scope', '$filter', 'change', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, change, ngTableParams, toaster, BaseService, CurrentRole) {
  21493. BaseService.scrollBackToTop();
  21494. $scope.active = 'todo';
  21495. $scope.agreedText = '全部';
  21496. $scope.dateZoneText = '一个月内';
  21497. $scope.condition = {dateZone: 1};
  21498. /* 时间筛选初始化*/
  21499. var fromDate = new Date();
  21500. var toDate = new Date();
  21501. fromDate.setMonth(fromDate.getMonth() - 1);
  21502. fromDate.setHours(0, 0, 0, 0);
  21503. toDate.setHours(23, 59, 59, 999);
  21504. $scope.condition.dateFrom = fromDate;
  21505. $scope.condition.dateTo = toDate;
  21506. $scope.changeAgreed = function (agreed) {
  21507. $scope.condition.agreed = agreed;
  21508. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  21509. $scope.condition.$agreedOpen = false;
  21510. };
  21511. $scope.changeDateZone = function (zone) {
  21512. $scope.condition.dateZone = zone;
  21513. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  21514. $scope.condition.$dateZoneOpen = false;
  21515. getDateCondition(zone, $scope.condition);
  21516. $scope.tableParams.page(1);
  21517. $scope.tableParams.reload();
  21518. };
  21519. $scope.setActive = function (state) {
  21520. if ($scope.active != state) {
  21521. $scope.active = state;
  21522. if ($scope.tableParams.page() == 1)
  21523. $scope.tableParams.reload();
  21524. else
  21525. $scope.tableParams.page(1);
  21526. }
  21527. };
  21528. var getService = function () {
  21529. return change;
  21530. };
  21531. $scope.tableParams = new ngTableParams({
  21532. page: 1,
  21533. count: 20,
  21534. sorting: {
  21535. date: 'desc'
  21536. }
  21537. }, {
  21538. total: 0,
  21539. counts: [5, 10, 25, 50],
  21540. getData: function ($defer, params) {
  21541. $scope.loading = true;
  21542. var pageParams = params.url();
  21543. pageParams.searchFilter = {
  21544. keyword: $scope.keyword,
  21545. fromDate: getDateTime($scope.condition.dateFrom),
  21546. endDate: getDateTime($scope.condition.dateTo)
  21547. };
  21548. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  21549. $scope.loading = false;
  21550. if (page) {
  21551. params.total(page.totalElement);
  21552. $defer.resolve(page.content);
  21553. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  21554. }
  21555. }, function (response) {
  21556. $scope.loading = false;
  21557. toaster.pop('error', '数据加载失败', response.data);
  21558. });
  21559. }
  21560. });
  21561. $scope.openDatePicker = function ($event, item, openParam) {
  21562. $event.preventDefault();
  21563. $event.stopPropagation();
  21564. item[openParam] = !item[openParam];
  21565. };
  21566. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21567. $event.preventDefault();
  21568. $event.stopPropagation();
  21569. item[openParam] = !item[openParam];
  21570. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21571. $scope.tableParams.reload();
  21572. }
  21573. };
  21574. // 搜索框回车
  21575. $scope.onSearch = function (keyword) {
  21576. $scope.tableParams.page(1);
  21577. $scope.tableParams.reload();
  21578. };
  21579. // 导出
  21580. $scope.exportXls = function () {
  21581. change.exportXls({}, {}, function (data) {
  21582. if (data.success){
  21583. window.location.href = 'purc/change/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21584. }
  21585. }, function (response) {
  21586. toaster.pop('error', '数据加载失败', response.data);
  21587. });
  21588. }
  21589. }]);
  21590. /**
  21591. * 新增采购变更单
  21592. *
  21593. * @author hejq
  21594. * @date 2018-06-25 16:38
  21595. */
  21596. app.controller('PurcChangeNewCtrl', ['$scope', 'toaster', 'BaseService', 'AuthenticationService', '$modal', '$filter', 'change',
  21597. function ($scope, toaster, BaseService, AuthenticationService, $modal, $filter, change) {
  21598. // 获取登录人员信息
  21599. AuthenticationService.getAuthentication().success(function (data) {
  21600. $scope.user = data;
  21601. initChange();
  21602. });
  21603. // 初始化变更单信息
  21604. var initChange = function () {
  21605. $scope.change = {
  21606. date: new Date(),
  21607. recorder: $scope.user.userName,
  21608. orderCode: null,
  21609. code: 'B2BPC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  21610. orderId: null,
  21611. orderChangeItems: []
  21612. }
  21613. }
  21614. $scope.getEnableOrders = function() {
  21615. initChange();
  21616. var modalInstance = $modal.open({
  21617. animation: true,
  21618. size: 'lg',
  21619. templateUrl: 'static/tpl/index/purc/modal/enableOrderList.html',
  21620. controller: 'EnableChangeListCtrl',
  21621. resolve: {
  21622. }
  21623. });
  21624. modalInstance.result.then(function (data) {
  21625. $scope.change.orderCode = data.code;
  21626. $scope.change.orderId = data.id;
  21627. $scope.orderItems = data.orderItems;
  21628. $scope.change.oldCurrency = data.currency;
  21629. $scope.change.oldPayments = data.payments;
  21630. $scope.change.oldRate = data.rate;
  21631. $scope.change.vendUU = data.vendUU;
  21632. $scope.change.apVendorName = data.receiveName;
  21633. $scope.change.vendUserUU = data.vendUserUU;
  21634. $scope.change.newCurrency = data.currency != null ? data.currency :null;
  21635. $scope.change.newPayments = data.payments != null ? data.payments :null;
  21636. angular.forEach($scope.orderItems, function (item, index) {
  21637. $scope.change.orderChangeItems.push({
  21638. oldProductId: item.productId,
  21639. orderItemId: item.id,
  21640. orderItemNumber: item.number,
  21641. oldQty: item.qty,
  21642. oldPrice: item.price,
  21643. oldTaxrate: item.taxrate,
  21644. oldDelivery: item.delivery,
  21645. newQty: item.qty != null ? item.qty :null,
  21646. newPrice: item.price != null ? item.price :null,
  21647. newTaxrate: item.taxrate != null ? item.taxrate :null,
  21648. newDelivery: item.delivery != null ? item.delivery :null,
  21649. oldProduct: item.product,
  21650. number: index + 1
  21651. });
  21652. });
  21653. });
  21654. }
  21655. // 删除明细
  21656. $scope.del = function (index) {
  21657. $scope.change.orderChangeItems.splice(index, 1);
  21658. }
  21659. $scope.getMinDate = function () {
  21660. return $filter('date')(new Date, 'yyyy-MM-dd');
  21661. };
  21662. $scope.openDatePicker = function ($event, openParam, index) {
  21663. $event.preventDefault();
  21664. $event.stopPropagation();
  21665. $scope.change.orderChangeItems[index].$dateOpen = !openParam;
  21666. };
  21667. $scope.save = function() {
  21668. if ($scope.change.unNeedReply == null) {
  21669. toaster.pop('error', '请选择是否需要供应商确认');
  21670. } else if ($scope.change.orderChangeItems.length == 0) {
  21671. toaster.pop('error', '请至少选择一条采购明细')
  21672. } else {
  21673. change.save({}, $scope.change, function (data) {
  21674. window.location.hash = "/purc/change/" + data.id;
  21675. toaster.pop('success', '采购变更单保存成功');
  21676. }, function(res) {
  21677. toaster.pop('error','请输入正确的信息')
  21678. });
  21679. }
  21680. }
  21681. }]);
  21682. /**
  21683. * 获取可以作为采购变更单的采购单
  21684. *
  21685. * @author hejq
  21686. * @date 2018-06-25 18:41
  21687. */
  21688. app.controller('EnableChangeListCtrl', ['$scope', 'change', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance',
  21689. function ($scope, change, BaseService, ngTableParams, toaster, $modalInstance) {
  21690. $scope.dateZoneText = '一个月内';
  21691. $scope.condition = {dateZone: 1};
  21692. /* 时间筛选初始化*/
  21693. var fromDate = new Date();
  21694. var toDate = new Date();
  21695. fromDate.setMonth(fromDate.getMonth() - 1);
  21696. fromDate.setHours(0, 0, 0, 0);
  21697. toDate.setHours(23, 59, 59, 999);
  21698. $scope.condition.dateFrom = fromDate;
  21699. $scope.condition.dateTo = toDate;
  21700. $scope.changeDateZone = function (zone) {
  21701. $scope.condition.dateZone = zone;
  21702. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  21703. $scope.condition.$dateZoneOpen = false;
  21704. getDateCondition(zone, $scope.condition);
  21705. $scope.tableParams.page(1);
  21706. $scope.tableParams.reload();
  21707. };
  21708. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21709. $event.preventDefault();
  21710. $event.stopPropagation();
  21711. item[openParam] = !item[openParam];
  21712. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21713. $scope.tableParams.reload();
  21714. }
  21715. };
  21716. $scope.tableParams = new ngTableParams({
  21717. page: 1,
  21718. count: 5,
  21719. sorting: {
  21720. 'id': 'desc'
  21721. }
  21722. }, {
  21723. total: 0,
  21724. counts: [],
  21725. getData: function ($defer, params) {
  21726. $scope.loading = true;
  21727. var pageParams = params.url();
  21728. pageParams.searchFilter = { // 筛选条件
  21729. keyword: $scope.keyword,
  21730. fromDate: getDateTime($scope.condition.dateFrom),
  21731. endDate: getDateTime($scope.condition.dateTo)
  21732. };
  21733. change.getEnableOrderList.call(null, BaseService.parseParams(pageParams), function (page) {
  21734. $scope.loading = false;
  21735. if (page) {
  21736. params.total(page.totalElement);
  21737. $defer.resolve(page.content);
  21738. }
  21739. }, function (response) {
  21740. $scope.loading = false;
  21741. toaster.pop('error', '数据加载失败', response.data);
  21742. });
  21743. }
  21744. });
  21745. $scope.checkedOrder = null;
  21746. var checkItems = [];
  21747. // 单选
  21748. $scope.checkOne = function (order) {
  21749. var changeflag = false;
  21750. order.checked = !order.checked;
  21751. if ((order.checked) && ($scope.checkedOrder != null) && ($scope.checkedOrder != order)) {
  21752. $scope.checkedOrder.checked = false;
  21753. angular.forEach($scope.checkedOrder.orderItems, function (item) {
  21754. item.checked = false;
  21755. });
  21756. $scope.checkedOrder = null;
  21757. checkItems = [];
  21758. }
  21759. if (order.checked) {
  21760. $scope.checkedOrder = order;
  21761. angular.forEach(order.orderItems, function (item) {
  21762. if (item.change) {
  21763. item.checked = false;
  21764. changeflag = true;
  21765. } else {
  21766. item.checked = true;
  21767. checkItems.push(item);
  21768. }
  21769. });
  21770. } else {
  21771. $scope.checkedOrder = null;
  21772. angular.forEach(order.orderItems, function (item) {
  21773. item.checked = false;
  21774. });
  21775. checkItems = [];
  21776. }
  21777. if (checkItems.length == 0 && changeflag) {
  21778. order.checked =false;
  21779. toaster.pop('warning', '提示', "该采购单所有明细正在变更中,在供应商确认之前不可再次变更");
  21780. }
  21781. };
  21782. // 明细
  21783. $scope.checkItem = function (item, order) {
  21784. // 先判断选中信息
  21785. if (item.change) {
  21786. toaster.pop('warning', '提示', "该明细正在变更中,在供应商确认之前不可再次变更");
  21787. item.checked = null;
  21788. return;
  21789. }
  21790. order.checked = true;
  21791. if ($scope.checkedOrder != null && order.id != $scope.checkedOrder.id) {
  21792. $scope.checkedOrder.checked = false;
  21793. $scope.checkedOrder = order;
  21794. order.checked = true;
  21795. angular.forEach(checkItems, function (checkItem) {
  21796. checkItem.checked = false;
  21797. });
  21798. checkItems = [];
  21799. }
  21800. item.checked = !item.checked;
  21801. if (item.checked) {
  21802. checkItems.push(item);
  21803. if ($scope.checkedOrder == null) {
  21804. $scope.checkedOrder = order;
  21805. }
  21806. order.checked = true;
  21807. } else {
  21808. angular.forEach(checkItems, function (checkItem, index) {
  21809. if (checkItem.id == item.id) {
  21810. checkItems.splice(index, 1);
  21811. }
  21812. });
  21813. }
  21814. if (checkItems.length == 0) {
  21815. $scope.checkedOrder = null;
  21816. order.checked = false;
  21817. }
  21818. };
  21819. // 搜索框回车
  21820. $scope.onSearch = function (keyword) {
  21821. $scope.tableParams.page(1);
  21822. $scope.tableParams.reload();
  21823. };
  21824. $scope.getCartTotal = function (items) {
  21825. var sum = 0;
  21826. angular.forEach(items, function (item) {
  21827. sum += item.qty * item.price;
  21828. });
  21829. return sum;
  21830. };
  21831. // 选择
  21832. $scope.choose = function () {
  21833. if ($scope.checkedOrder == null || checkItems.length == 0) {
  21834. toaster.pop('error', '请先选择采购单信息');
  21835. } else {
  21836. $scope.checkedOrder.orderItems = checkItems;
  21837. $modalInstance.close($scope.checkedOrder);
  21838. }
  21839. }
  21840. // 关闭
  21841. $scope.close = function () {
  21842. $modalInstance.dismiss();
  21843. };
  21844. }]);
  21845. /**
  21846. * 采购变更单详情
  21847. */
  21848. app.controller('PurcChangeDetailCtrl', ['$scope', '$stateParams', 'change', 'toaster', 'CurrentRole',
  21849. function ($scope, $stateParams, change, toaster, CurrentRole) {
  21850. // 获取当前用户是否为普通用户
  21851. CurrentRole.isUser({}, {}, function (data) {
  21852. $scope.isUser = data.isUser;
  21853. });
  21854. var loadData = function () {
  21855. change.getItem({id: $stateParams.id}, function (data) {
  21856. $scope.change = data;
  21857. }, function (response) {
  21858. toaster.pop('error', '', response.data);
  21859. });
  21860. };
  21861. loadData();
  21862. $scope.openDatePicker = function ($event, item, openParam) {
  21863. $event.preventDefault();
  21864. $event.stopPropagation();
  21865. item[openParam] = !item[openParam];
  21866. };
  21867. }]);
  21868. /**
  21869. * B2C搜索
  21870. */
  21871. app.controller('SearchCtrl', ['$scope', '$http', '$rootScope', 'SessionService', 'AccountEnterprise', function($scope, $http, $rootScope, SessionService, AccountEnterprise) {
  21872. $scope.hotwords = new Array();
  21873. var hasBrand = false;
  21874. var hasComponent = false;
  21875. // 热词搜索品牌
  21876. var hotBrand = function () {
  21877. $http.get($scope.toB2cLink + '/api/product/brand/mostSearchBrands'
  21878. ).success(function(data){
  21879. hasBrand = true;
  21880. angular.forEach(data, function (value) {
  21881. $scope.hotwords.push({name: value.nameEn, url: $scope.toB2cLink + '/search?w='+ value.nameEn +'&type=brand'})
  21882. })
  21883. if (hasBrand) {
  21884. hotComponent();
  21885. }
  21886. }).error(function(response) {
  21887. console.log(response)
  21888. });
  21889. };
  21890. // 热词搜索器件
  21891. var hotComponent = function () {
  21892. $http.get($scope.toB2cLink + '/api/product/component/mostSearchComponent'
  21893. ).success(function(data){
  21894. hasComponent = true;
  21895. if (hasBrand && hasComponent) {
  21896. angular.forEach(data, function (value) {
  21897. $scope.hotwords.push({name: value.code, url: $scope.toB2cLink + '/search?w='+ value.code +'&type=component'})
  21898. })
  21899. }
  21900. }).error(function(response) {
  21901. console.log(response)
  21902. });
  21903. };
  21904. AccountEnterprise.getB2cUrl({}, function(data) {
  21905. $scope.toB2cLink = data.url
  21906. hotBrand();
  21907. });
  21908. // 默认搜索类型
  21909. $scope.searchType = 'component';
  21910. $scope.placeholderSearch = '请输入型号';
  21911. // 选搜索类型
  21912. $scope.setTypeClick = function (type) {
  21913. $scope.keyword = '';
  21914. $scope.searchType = type;
  21915. if (type === 'kind') {
  21916. $scope.placeholderSearch = '请输入物料名称';
  21917. } else if (type === 'store') {
  21918. $scope.placeholderSearch = '请输入卖家名称';
  21919. } else if (type === 'brand') {
  21920. $scope.placeholderSearch = '请输入品牌';
  21921. } else {
  21922. $scope.placeholderSearch = '请输入型号';
  21923. }
  21924. };
  21925. // 搜索
  21926. $scope.search = function() {
  21927. if($scope.keyword) {
  21928. SessionService.set('brand', true);
  21929. SessionService.unset('component');
  21930. window.location.href = $scope.toB2cLink + '/search?w=' + encodeURI($scope.keyword) + '&type=' + $scope.searchType;
  21931. }
  21932. };
  21933. // 搜索框获得焦点,显示联想框
  21934. $scope.onFocus = function() {
  21935. $scope.associate = true;
  21936. $scope.selectIndex = -1;
  21937. if(!$scope.keyword) $scope.keyword = '';
  21938. };
  21939. // 搜索框失去焦点,关闭联想框
  21940. $scope.onBlur = function() {
  21941. $scope.associate = false;
  21942. };
  21943. // 搜索框通过按键选取想要的联想词
  21944. $scope.onKeyup = function() {
  21945. if($scope.associates && $scope.associates.length) {
  21946. if(event.keyCode == 40) { //监听到按下键
  21947. $scope.selectIndex ++;
  21948. if($scope.selectIndex >= $scope.associates.length) $scope.selectIndex = 0;
  21949. $scope.keyword = $scope.associates[$scope.selectIndex];
  21950. } else if(event.keyCode == 38) { //监听到按上键
  21951. $scope.selectIndex --;
  21952. if($scope.selectIndex < 0) $scope.selectIndex = $scope.associates.length - 1;
  21953. $scope.keyword = $scope.keyword = $scope.associates[$scope.selectIndex];
  21954. } else if(event.keyCode == 13) { //确定键
  21955. $scope.search();
  21956. }
  21957. }
  21958. };
  21959. // 输入框内容变化,获取新的联想词
  21960. $scope.onChange = function() {
  21961. if ($scope.keyword) {
  21962. var params = {
  21963. keyword: $scope.keyword,
  21964. type: $scope.searchType
  21965. };
  21966. $http.get($scope.toB2cLink + '/search/similarKeywords', {
  21967. params : params
  21968. }).success(function(data){
  21969. $scope.associates = data.result;// 联想词数组
  21970. }).error(function(response) {
  21971. console.log(response)
  21972. });
  21973. } else {
  21974. $scope.associates = [];// 联想词数组
  21975. }
  21976. };
  21977. // 点击联想词
  21978. $scope.onAssociateClick = function(component) {
  21979. $scope.keyword = component;
  21980. $scope.search();
  21981. };
  21982. // 鼠标进入联想词框,不能关闭联想词框
  21983. $scope.onAssociateEnter = function() {
  21984. $scope.associateEnter = true;
  21985. };
  21986. // 鼠标离开联想词框,可以关闭联想词框
  21987. $scope.onAssociateLeave = function() {
  21988. $scope.associateEnter = false;
  21989. };
  21990. // 跳转到B2C
  21991. $scope.b2cLink = function (url) {
  21992. if (url == '/help/home') {
  21993. window.open($scope.toB2cLink + url)
  21994. } else {
  21995. window.location.href = $scope.toB2cLink + url;
  21996. }
  21997. };
  21998. // 头部固定
  21999. window.addEventListener('scroll', function () {
  22000. var obj = document.getElementById('fixed-header');
  22001. var scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
  22002. $scope.$apply(function () {
  22003. $scope.isFixed = scrolled >= obj.offsetTop;
  22004. });
  22005. }, false);
  22006. }]);
  22007. /**
  22008. * 树结构
  22009. */
  22010. app.controller('treeController', ['$scope', '$location', function($scope, $location){
  22011. $scope.roleList = [
  22012. { "roleName" : "卖家中心(销售)", "roleId" : "role1", 'path': 'sale', level: 0, collapsed: true, "children" : [
  22013. { "roleName" : "商机管理", "roleId" : "role1-1", collapsed: true, "children" : [
  22014. { "roleName" : "客户采购询价", "roleId" : "role1-1-1", 'link' : '#/sale/inquiry', "children" : [] },
  22015. { "roleName" : "客户公共询价", "roleId" : "role1-1-2", 'link' : '#/sale/pubinquiry', "children" : [] },
  22016. { "roleName" : "客户模具询价", "roleId" : "role1-1-3", 'link' : '#/sale/mould', "children" : [] },
  22017. { "roleName" : "主动报价", "roleId" : "role1-1-4", 'link' : '#/sale/quotation/list', "children" : [] },
  22018. { "roleName" : "客户招标", "roleId" : "role1-1-5", 'link' : '#/sale/tender', "children" : [] }
  22019. ] },
  22020. { "roleName" : "订单管理", "roleId" : "role1-2", collapsed: true, "children" : [
  22021. { "roleName" : "客户采购订单", "roleId" : "role1-2-1", 'link' : '#/sale/order', "children" : [] },
  22022. { "roleName" : "客户采购变更单", "roleId" : "role1-2-2", 'link' : '#/sale/change', "children" : [] },
  22023. { "roleName" : "客户委外单", "roleId" : "role1-2-3", 'link' : '#/sale/maketodo/makeorder', "children" : [] },
  22024. { "roleName" : "委外变更单", "roleId" : "role1-2-4", 'link' : '#/sale/makechange', "children" : [] },
  22025. { "roleName" : "客户发货提醒", "roleId" : "role1-2-5", 'link' : '#/sale/notice', "children" : [] },
  22026. { "roleName" : "发货单", "roleId" : "role1-2-6", 'link' : '#/sale/send', "children" : [] }
  22027. ]},
  22028. { "roleName" : "客户出入库", "roleId" : "role1-3", collapsed: true, "children" : [
  22029. { "roleName" : "MRB单", "roleId" : "role1211", 'link' : '#/sale/MRB', "children" : [] },
  22030. { "roleName" : "不良品出库单", "roleId" : "role1-3-1", 'link' : '#/sale/badOut', "children" : [] },
  22031. { "roleName" : "不良品入库单", "roleId" : "role1-3-2", 'link' : '#/sale/badIn', "children" : [] },
  22032. { "roleName" : "客户采购验收单", "roleId" : "role1-3-3", 'link' : '#/sale/accept', "children" : [] },
  22033. { "roleName" : "客户采购验退单", "roleId" : "role1-3-4", 'link' : '#/sale/returns', "children" : [] },
  22034. { "roleName" : "客户委外验收单", "roleId" : "role1-3-5", 'link' : '#/sale/makeaccept', "children" : [] },
  22035. { "roleName" : "客户委外验退单", "roleId" : "role1-3-6", 'link' : '#/sale/makereturns', "children" : [] }
  22036. ] },
  22037. { "roleName" : "样品管理", "roleId" : "role1-4", collapsed: true, "children" : [
  22038. { "roleName" : "客户打样申请", "roleId" : "role1-4-1", 'link' : '#/sale/sample', "children" : [] },
  22039. { "roleName" : "客户认定单", "roleId" : "role1-4-2", 'link' : '#/sale/approval', "children" : [] }
  22040. ] },
  22041. { "roleName" : "基础资料", "roleId" : "role1-5", collapsed: true, "children" : [
  22042. { "roleName" : "客户资料", "roleId" : "role1-5-1", 'link' : '#/sale/customer', "children" : [] },
  22043. { "roleName" : "绩效考核", "roleId" : "role1-5-2", 'link' : '#/sale/vendorPerformanceAssess', "children" : [] },
  22044. { "roleName" : "产品导入", "roleId" : "role1-5-3", 'link' : '#/sale/prodList', "children" : [] }
  22045. ] }
  22046. ]},
  22047. { "roleName" : "买家中心(采购)", "roleId" : "role2", 'path': 'purc', level: 0, collapsed: true, "children" : [
  22048. { "roleName" : "供应商资料", "roleId" : "role2-1-1", 'link' : '#/purc/vendor', "children" : [] },
  22049. { "roleName" : "供应商服务", "roleId" : "role2-1-2", 'link' : '#/purc/vendor/serve', "children" : [] },
  22050. { "roleName" : "采购物料", "roleId" : "role2-1-3", 'link' : '#/purc/product', "children" : [] },
  22051. { "roleName" : "采购招标", "roleId" : "role2-1-4", 'link' : '#/purc/tender', "children" : [] },
  22052. { "roleName" : "采购询价", "roleId" : "role2-1-5", 'link' : '#/purc/purchaseinquiry', "children" : [] },
  22053. { "roleName" : "公共询价", "roleId" : "role2-1-6", 'link' : '#/purc/publicInquiry', "children" : [] },
  22054. { "roleName" : "采购订单", "roleId" : "role2-1-7", 'link' : '#/purc/order', "children" : [] },
  22055. { "roleName" : "采购变更单", "roleId" : "role2-1-8", 'link' : '#/purc/change', "children" : [] },
  22056. { "roleName" : "代采订单", "roleId" : "role2-1-9", 'link' : '#/purc/deputy', "children" : [] },
  22057. { "roleName" : "委外订单", "roleId" : "role2-1-10", 'link' : '#/purc/makeoutorder', "children" : [] }
  22058. ]},
  22059. { "roleName" : "财务", "roleId" : "role3", 'path': 'fa', level: 0, collapsed: true, "children" : [
  22060. { "roleName" : "应收", "roleId" : "role3-1", collapsed: true, "children" : [
  22061. { "roleName" : "发票", "roleId" : "role3-1-1", 'link' : '#/fa/apBill', "children" : [] },
  22062. { "roleName" : "应收对账单", "roleId" : "role3-1-2", 'link' : '#/fa/apCheck', "children" : [] }
  22063. ] },
  22064. { "roleName" : "应付", "roleId" : "role3-2", collapsed: true, "children" : [
  22065. { "roleName" : "应付对账单", "roleId" : "role3-2-1", 'link' : '#/fa/arCheck', "children" : [] }
  22066. ]}
  22067. ]},
  22068. { "roleName" : "企业圈", "roleId" : "role4", 'path': 'baseInfo', level: 0, collapsed: true, "children" : [
  22069. { "roleName" : "我的合作伙伴", "roleId" : "role4-1-1", 'link' : '#/baseInfo/myRequest', "children" : [] },
  22070. { "roleName" : "新的合作伙伴", "roleId" : "role4-1-2", 'link' : '#/baseInfo/newPartner', "children" : [] }
  22071. ]},
  22072. { "roleName" : "基础设置", "roleId" : "role5", 'path': 'approvalFlow', collapsed: true, level: 0, "children" : [
  22073. { "roleName" : "企业信息", "roleId" : "role5-1-1", 'link' : '#/approvalFlow/enterprise', "children" : [] },
  22074. { "roleName" : "物料信息", "roleId" : "role5-1-2", 'link' : '#/approvalFlow/product', "children" : [] },
  22075. { "roleName" : "我的产品库", "roleId" : "role5-1-3", 'link' : '#/approvalFlow/userProduct', "children" : [] },
  22076. { "roleName" : "人员信息", "roleId" : "role5-1-4", 'link' : '#/approvalFlow/user', "children" : [] },
  22077. { "roleName" : "角色权限", "roleId" : "role5-1-5", 'link' : '#/approvalFlow/role', "children" : [] },
  22078. { "roleName" : "审批流", "roleId" : "role5-1-6", 'link' : '#/approvalFlow/flow', "children" : [] },
  22079. { "roleName" : "操作日志", "roleId" : "role5-1-7", 'link' : '#/approvalFlow/log', "children" : [] }
  22080. ]}
  22081. ];
  22082. $scope.currentObj = {};
  22083. var hasChildrenObj = function (target) {
  22084. var flag = false;
  22085. if ($scope.currentObj.roleId && target && target.children) {
  22086. angular.forEach(target.children, function (item) {
  22087. if (item.roleId == $scope.currentObj.roleId) {
  22088. flag = true;
  22089. }
  22090. if (item.children.length && hasChildrenObj(item)) {
  22091. flag = true;
  22092. }
  22093. });
  22094. }
  22095. return flag;
  22096. }
  22097. var roopCall = function (arr, callBack) {
  22098. angular.forEach(arr, function (item) {
  22099. if (item.children && item.children.length) {
  22100. roopCall(item.children, callBack);
  22101. }
  22102. callBack(item);
  22103. })
  22104. }
  22105. var initObj = function (arr, flag) {
  22106. angular.forEach(arr, function (item) {
  22107. if (flag) {
  22108. item.collapsed = false;
  22109. }
  22110. if (item.children && item.children.length) {
  22111. initObj(item.children, item.path && item.path == $location.$$path.split('/')[1]);
  22112. } else {
  22113. if (item.link && item.link.split('#')[1] == $location.$$path) {
  22114. item.selected = 'selected';
  22115. $scope.currentObj = item;
  22116. }
  22117. }
  22118. })
  22119. }
  22120. initObj($scope.roleList);
  22121. var initClose = function () {
  22122. roopCall($scope.roleList, function (item) {
  22123. item.collapsed = !hasChildrenObj(item);
  22124. })
  22125. }
  22126. initClose();
  22127. var closeRow = function (arr) {
  22128. angular.forEach(arr, function (item) {
  22129. item.selected = undefined;
  22130. if (item.children) {
  22131. closeRow(item.children);
  22132. }
  22133. })
  22134. }
  22135. $scope.$watch( 'myTree.currentNode', function( newObj, oldObj ) {
  22136. if( $scope.myTree && angular.isObject($scope.myTree.currentNode) ) {
  22137. $scope.currentObj = newObj;
  22138. if (newObj.link) {
  22139. window.location.href = newObj.link
  22140. }
  22141. roopCall($scope.roleList, function (item) {
  22142. if (item.roleId == newObj.roleId) {
  22143. $scope.currentObj = item;
  22144. // item.collapsed = !item.collapsed;
  22145. } else {
  22146. item.collapsed = !hasChildrenObj(item) && (item.roleId != newObj.roleId);
  22147. }
  22148. })
  22149. // 父级菜单不选择
  22150. if ($scope.currentObj.link) {
  22151. closeRow($scope.roleList);
  22152. $scope.currentObj.selected = 'selected';
  22153. } else {
  22154. $scope.currentObj.selected = null;
  22155. }
  22156. }
  22157. }, false);
  22158. }])
  22159. return app;
  22160. });