app.js 965 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836
  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'], 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']);
  4. app.init = function () {
  5. angular.bootstrap(document, ['myApp']);
  6. };
  7. app.config(['$httpProvider', function ($httpProvider) {
  8. // http拦截
  9. $httpProvider.interceptors.push('httpInterceptor');
  10. }]);
  11. app.factory('httpInterceptor', ['$window', '$q', '$injector', 'BaseService', function ($window, $q, $injector, BaseService) {
  12. var httpInterceptor = {
  13. 'responseError': function (response) {
  14. if (response.status == 401) {// UNAUTHORIZED
  15. // window.location.href = response.data.loginUrl || 'index';
  16. // window.location.href = window.location.origin + window.location.pathname + '/login';
  17. window.location.reload();
  18. return $q.reject(response);
  19. }
  20. return $q.reject(response);
  21. }
  22. }
  23. return httpInterceptor;
  24. }]);
  25. app.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
  26. $stateProvider.state('index', {
  27. url: "/index",
  28. views: {
  29. "left-view": {
  30. templateUrl: "static/tpl/index/home/left.html",
  31. controller: 'LeftCtrl'
  32. },
  33. "right-view": {
  34. templateUrl: "static/tpl/index/home/right.html",
  35. controller: 'RightCtrl'
  36. }
  37. }
  38. }).state('home', {
  39. url: "/",
  40. views: {
  41. "left-view": {
  42. templateUrl: "static/tpl/index/home/left.html",
  43. controller: 'LeftCtrl'
  44. },
  45. "right-view": {
  46. templateUrl: "static/tpl/index/home/right.html",
  47. controller: 'RightCtrl'
  48. }
  49. }
  50. }).state('sale', {
  51. url: "/sale",
  52. views: {
  53. "left-view": {
  54. templateUrl: "static/tpl/index/sale/left.html",
  55. controller: 'LeftCtrl'
  56. },
  57. "right-view": {
  58. templateUrl: "static/tpl/index/sale/right.html"
  59. }
  60. },
  61. controller: function ($scope) {
  62. $scope.truck = [];
  63. $scope.dataChanged = false;
  64. }
  65. }).state('sale.index', {
  66. url: "",
  67. templateUrl: "static/tpl/index/sale/index.html"
  68. }).state('sale.home', {
  69. url: "/",
  70. templateUrl: "static/tpl/index/sale/index.html"
  71. }).state('purc', {
  72. url: "/purc",
  73. views: {
  74. "left-view": {
  75. templateUrl: "static/tpl/index/purc/left.html",
  76. controller: 'LeftCtrl'
  77. },
  78. "right-view": {
  79. templateUrl: "static/tpl/index/purc/right.html"
  80. }
  81. },
  82. controller: function ($scope) {
  83. $scope.truck = [];
  84. $scope.dataChanged = false;
  85. }
  86. }).state('purc.index', {
  87. url: "",
  88. templateUrl: "static/tpl/index/purc/index.html"
  89. }).state('purc.home', {
  90. url: "/",
  91. templateUrl: "static/tpl/index/purc/index.html"
  92. }).state('purc.introduce', {
  93. url: "/introduce",
  94. templateUrl: "static/tpl/index/purc/introduce.html"
  95. }).state('purc.order', {
  96. url: "/order",
  97. templateUrl: "static/tpl/index/purc/order.html",
  98. controller: 'PurcOrderCtrl'
  99. }).state('purc.order_detail', {
  100. url: "/order/:id",
  101. templateUrl: "static/tpl/index/purc/order_detail.html",
  102. controller: 'PurcOrderDetailCtrl'
  103. }).state('purc.newOrder', {
  104. url: "/addOrder",
  105. templateUrl: "static/tpl/index/purc/addOrder.html",
  106. controller: 'PurcNewOrderCtrl'
  107. }).state('purc.cart', {
  108. url: "/cart",
  109. templateUrl: "static/tpl/index/purc/cart.html",
  110. controller: 'CartController'
  111. }).state('purc.cartDetail', {
  112. url: "/cart/:id",
  113. templateUrl: "static/tpl/index/purc/cart_detail.html",
  114. controller: 'CartDetailController'
  115. }).state('purc.deputy', {
  116. url: "/deputy",
  117. templateUrl: "static/tpl/index/purc/deputyOrder.html",
  118. controller: 'DeputyOrderCtrl'
  119. }).state('purc.deputylog', {
  120. url: "/deputylog",
  121. templateUrl: "static/tpl/index/purc/deputyorders_log.html",
  122. controller: 'DeputyOrderLogCtrl'
  123. }).state('purc.newdeputy', {
  124. url: "/deputy/add",
  125. templateUrl: "static/tpl/index/purc/deputyOrder_new.html",
  126. controller: 'NewDeputyOrderCtrl'
  127. }).state('purc.deputydetail', {
  128. url: "/deputy/:id",
  129. templateUrl: "static/tpl/index/purc/deputyOrder_detail.html",
  130. controller: 'DeputyOrderDetailCtrl'
  131. /* 招标列表 */
  132. }).state('purc.tenderlist', {
  133. url: "/tender",
  134. templateUrl: "static/tpl/index/purc/tenderlist.html",
  135. controller: 'PurcTenderCtrl'
  136. /* 招标答疑列表 */
  137. }).state('purc.tenderanswerlist', {
  138. url: "/tender/answer",
  139. templateUrl: "static/tpl/index/purc/tender_answer_list.html",
  140. controller: 'PurcTenderAnswerListCtrl'
  141. /* 招标答疑详情 */
  142. }).state('purc.tenderanswerdetail', {
  143. url: "/tender/answer/:id",
  144. templateUrl: "static/tpl/index/purc/tender_answer_detail.html",
  145. controller: 'PurcTenderAnswerDetailCtrl'
  146. }).state('purc.waiting.tenderlist', {
  147. url: "/tender",
  148. templateUrl: "static/tpl/index/purc/tenderlist.html",
  149. controller: 'PurcTenderCtrl'
  150. }).state('purc.todo.tenderlist', {
  151. url: "/tender/todo",
  152. templateUrl: "static/tpl/index/purc/tenderlist.html",
  153. controller: 'PurcTenderCtrl'
  154. /* 招标 */
  155. }).state('purc.tender', {
  156. url: "/addTender",
  157. templateUrl: "static/tpl/index/purc/tender.html",
  158. controller: 'PurcNewTenderCtrl'
  159. }).state('purc.savedtender', {
  160. url: "/tender/:id",
  161. templateUrl: "static/tpl/index/purc/tender.html",
  162. controller: 'PurcNewTenderCtrl'
  163. /* 评标 */
  164. }).state('purc.evaluation', {
  165. url: "/evaluation/:id",
  166. templateUrl: "static/tpl/index/purc/tender_evaluation.html",
  167. controller: 'PurcEvaluationCtrl'
  168. /* 采购供应商资料 */
  169. }).state('purc.vendor', {
  170. url: "/vendor",
  171. templateUrl: "static/tpl/index/purc/vendor.html",
  172. controller: 'PurcVendorCtrl'
  173. /* 采购供应商资料 详情*/
  174. }).state('purc.vendorserve', {
  175. url: "/vendor/serve",
  176. templateUrl: "static/tpl/index/cs/right.html",
  177. controller: 'CustServeCtrl'
  178. }).state('purc.vendordetail', {
  179. url: "/vendor/:id",
  180. templateUrl: "static/tpl/index/purc/vendor_detail.html",
  181. controller: 'PurcVendorDetailCtrl'
  182. /* 客户指定招标列表 */
  183. }).state('purc.makeoutorder', {
  184. url: "/makeoutorder",
  185. templateUrl: "static/tpl/index/make/outorder.html",
  186. controller: 'MakeOutOrderCtrl'
  187. }).state('purc.outorder_detail', {
  188. url: "/makeoutorder/:id",
  189. templateUrl: "static/tpl/index/make/outorder_detail.html",
  190. controller: 'MakeOutOrderDetailCtrl'
  191. /*平台新增询价单*/
  192. }).state('purc.inquiry_new', {
  193. url: "/purcinquiry",
  194. templateUrl: "static/tpl/index/purc/inquiry_new.html",
  195. controller: 'PurcInquiryCtrl'
  196. /*新增公共询价*/
  197. }).state('purc.pubinquiry_new', {
  198. url: "/pubinquiry/new",
  199. templateUrl: "static/tpl/index/purc/pubInquiry_new.html",
  200. controller: 'PurcInquiryCtrl'
  201. }).state('purc.purcinquiry_new', {
  202. url: "/purcinquiry/:bussinessCode",
  203. templateUrl: "static/tpl/index/purc/purcinquiry_new.html",
  204. controller: 'PurcInquiryNewCtrl'
  205. }).state('purc.inquiry', {
  206. url: "/purchaseinquiry",
  207. templateUrl: "static/tpl/index/purc/inquiry.html",
  208. controller: 'PurchaseInquiryCtrl'
  209. }).state('purc.inquiry_detail', {
  210. url: "/purcinquirydetail",
  211. templateUrl: "static/tpl/index/purc/inquiry_detail.html",
  212. controller: 'PurcInquiryDetailCtrl'
  213. }).state('purc.inquiryInfo_detail', {
  214. url: "/purcinquirydetail/:id",
  215. templateUrl: "static/tpl/index/purc/inquiryInfo_detail.html",
  216. controller: 'PurcInquiryInfoDetailCtrl'
  217. }).state('purc.inquiry_unapply', {
  218. url: "/inquiry_unapply",
  219. templateUrl: "static/tpl/index/purc/inquiry_unapply.html",
  220. controller: 'UnapplyInquiryCtrl'
  221. }).state('purc.pubInquiry', {
  222. /**
  223. * 针对客户,查询已转报价的公共询价单列表
  224. */
  225. url: "/publicInquiry",
  226. templateUrl: "static/tpl/index/purc/pubInquiry.html",
  227. controller: 'PurcPubInquiryCtrl'
  228. }).state('purc.pubInquiry_detail', {
  229. /**
  230. * 针对客户,查询已转报价单的公共询价详情
  231. */
  232. url: "/publicInquiry/:id",
  233. templateUrl: "static/tpl/index/purc/pubInquiry_detail.html",
  234. controller: 'PurcPubInquiryDetailCtrl'
  235. }).state('purc.product', {
  236. url: "/product",
  237. templateUrl: "static/tpl/index/purc/prodList.html",
  238. controller: 'PurcProductCtrl'
  239. }).state('purc.newProduct', {
  240. url: "/newProduct",
  241. templateUrl: "static/tpl/index/purc/newProdInfo.html",
  242. controller: 'PurcNewProdInfoCtrl'
  243. }).state('purc.productDetail', {
  244. url: "/prodList/:id",
  245. templateUrl: "static/tpl/index/purc/productDetail.html",
  246. controller: 'PurcProdDetailCtrl'
  247. }).state('purc.productmatches', {
  248. url: "/productmatches",
  249. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  250. controller: 'ProductmatchesForPurcCtrl'
  251. }).state('purc.uploadProduct', {
  252. url: "/uploadProduct",
  253. templateUrl: "static/tpl/index/purc/uploadByBatch.html",
  254. controller: 'UploadProductCtrl'
  255. }).state('sale.tenderlist', {
  256. url: "/tender",
  257. templateUrl: "static/tpl/index/sale/tenderlist.html",
  258. controller: 'SaleTenderCtrl'
  259. /* 招标提问列表 */
  260. }).state('sale.tenderquestionlist', {
  261. url: "/tender/question",
  262. templateUrl: "static/tpl/index/sale/tender_question_list.html",
  263. controller: 'SaleTenderQuestionListCtrl'
  264. /* 招标提问详情 */
  265. }).state('sale.tenderquestiondetail', {
  266. url: "/tender/question/:id",
  267. templateUrl: "static/tpl/index/sale/tender_question_detail.html",
  268. controller: 'SaleTenderQuestionDetailCtrl'
  269. }).state('sale.todo.tenderlist', {
  270. url: "/tender",
  271. templateUrl: "static/tpl/index/sale/tenderlist.html",
  272. controller: 'SaleTenderCtrl'
  273. /* 平台公开招标列表 */
  274. }).state('baseInfo.openTenderList', {
  275. url: "/openTenderList",
  276. templateUrl: "static/tpl/index/sale/open_tender_list.html",
  277. controller: 'SaleOpenTenderCtrl'
  278. /* 查看公开招标详情 */
  279. }).state('baseInfo.open_tender_detail', {
  280. url: "/openTenderDetail/:id",
  281. templateUrl: "static/tpl/index/sale/open_tender_detail.html",
  282. controller: 'OpenSaleTenderDetailCtrl'
  283. /* 投标 */
  284. }).state('sale.tender', {
  285. url: "/tender/:id",
  286. templateUrl: "static/tpl/index/sale/tender.html",
  287. controller: 'SaleTenderDetailCtrl'
  288. /* 采购方查看供应商投标 */
  289. }).state('sale.vendortender', {
  290. url: "/tender/:vendUU/:id",
  291. templateUrl: "static/tpl/index/sale/vendor_tender.html",
  292. controller: 'SaleVendorTenderDetailCtrl'
  293. }).state('sale.todo', {
  294. url: "/todo",
  295. templateUrl: "static/tpl/index/sale/todo.html"
  296. }).state('sale.todo.inquiry', {
  297. url: "/inquiry",
  298. templateUrl: "static/tpl/index/sale/inquiry.html",
  299. controller: 'SaleInquiryCtrl'
  300. }).state('sale.todo.order', {
  301. url: "/order",
  302. templateUrl: "static/tpl/index/sale/order.html",
  303. controller: 'SaleOrderCtrl'
  304. }).state('sale.todo.change', {
  305. url: "/change",
  306. templateUrl: "static/tpl/index/sale/change.html",
  307. controller: 'SaleChangeCtrl'
  308. }).state('sale.todo.notice', {
  309. url: "/notice",
  310. templateUrl: "static/tpl/index/sale/notice.html",
  311. controller: 'SaleNoticeCtrl'
  312. }).state('sale.customer', {
  313. url: "/customer",
  314. templateUrl: "static/tpl/index/sale/customer.html",
  315. controller: 'CustomerCtrl'
  316. }).state('sale.customer_detail', {
  317. url: "/customer/:id",
  318. templateUrl: "static/tpl/index/sale/customer_detail.html",
  319. controller: 'CustomerDetailCtrl'
  320. }).state('sale.customerProduct', {
  321. url: "/customerProduct",
  322. templateUrl: "static/tpl/index/sale/customer.html",
  323. controller: 'CustomerCtrl'
  324. }).state('sale.inquiry', {
  325. url: "/inquiry",
  326. templateUrl: "static/tpl/index/sale/inquiry.html",
  327. controller: 'SaleInquiryCtrl'
  328. }).state('sale.pubinquiry', {
  329. /**
  330. * 针对卖家,展示已转询价报价的公共询价单列表
  331. */
  332. url: "/pubinquiry",
  333. templateUrl: "static/tpl/index/sale/pubinquiry.html",
  334. controller: 'SalePubInquiryCtrl'
  335. }).state('sale.pubinquiry_detail', {
  336. /**
  337. * 针对卖家,已转询价报价单的公共询价单详情
  338. */
  339. url: "/pubinquiry/:id",
  340. templateUrl: "static/tpl/index/sale/pubinquiry_detail.html",
  341. controller: 'SalePubInquiryDetailCtrl'
  342. }).state('sale.inquiryRemind', {
  343. /**
  344. * 针对卖家,查询推荐的询价列表
  345. */
  346. url: "/inquiryRemind",
  347. templateUrl: "static/tpl/index/sale/inquiryRemind.html",
  348. controller: 'SaleInquiryRemindCtrl'
  349. }).state('sale.inquirymould', {
  350. url: "/mould",
  351. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  352. controller: 'SaleInquiryMouldCtrl'
  353. }).state('sale.todo.inquirymould', {
  354. url: "/mould",
  355. templateUrl: "static/tpl/index/sale/inquiry_mould.html",
  356. controller: 'SaleInquiryMouldCtrl'
  357. }).state('sale.inquiry_mould_detail', {
  358. url: "/mould/:id",
  359. templateUrl: "static/tpl/index/sale/inquiry_mould_detail.html",
  360. controller: 'SaleInquiryMouldDetailCtrl'
  361. }).state('sale.inquiry_detail', {
  362. url: "/inquiry/:id",
  363. templateUrl: "static/tpl/index/sale/inquiry_detail.html",
  364. controller: 'SaleInquiryDetailCtrl'
  365. }).state('sale.quotation', {
  366. url: "/quotation",
  367. templateUrl: "static/tpl/index/sale/quotation.html"
  368. }).state('sale.quotation.new', {
  369. url: "/new",
  370. templateUrl: "static/tpl/index/sale/quotation_new.html",
  371. controller: 'SaleQuotationNewCtrl',
  372. params: {
  373. 'inquiryItem': null
  374. }
  375. }).state('sale.quotation.list', {
  376. url: "/list",
  377. templateUrl: "static/tpl/index/sale/quotation_list.html",
  378. controller: 'SaleQuotationListCtrl'
  379. }).state('sale.quotation.item', {
  380. url: "/:id",
  381. templateUrl: "static/tpl/index/sale/quotation_new.html",
  382. controller: 'SaleQuotationNewCtrl'
  383. }).state('sale.order', {
  384. url: "/order",
  385. templateUrl: "static/tpl/index/sale/order.html",
  386. controller: 'SaleOrderCtrl'
  387. }).state('sale.order_detail', {
  388. url: "/order/:id",
  389. templateUrl: "static/tpl/index/sale/order_detail.html",
  390. controller: 'SaleOrderDetailCtrl'
  391. }).state('sale.change', {
  392. url: "/change",
  393. templateUrl: "static/tpl/index/sale/change.html",
  394. controller: 'SaleChangeCtrl'
  395. }).state('sale.change_detail', {
  396. url: "/change/:id",
  397. templateUrl: "static/tpl/index/sale/change_detail.html",
  398. controller: 'SaleChangeDetailCtrl'
  399. }).state('sale.notice', {
  400. url: "/notice",
  401. templateUrl: "static/tpl/index/sale/notice.html",
  402. controller: 'SaleNoticeCtrl'
  403. }).state('sale.send', {
  404. url: "/send",
  405. templateUrl: "static/tpl/index/sale/send.html",
  406. controller: 'SaleSendCtrl'
  407. }).state('sale.send_detail', {
  408. url: "/send/:id",
  409. templateUrl: "static/tpl/index/sale/send_detail.html",
  410. controller: 'SaleSendDetailCtrl'
  411. }).state('sale.forecast', {
  412. url: "/forecast",
  413. templateUrl: "static/tpl/index/sale/forecast.html",
  414. controller: 'SaleForecastCtrl'
  415. }).state('sale.accept', {
  416. url: "/accept",
  417. templateUrl: "static/tpl/index/sale/accept.html",
  418. controller: 'SaleAcceptCtrl'
  419. }).state('sale.accept_detail', {
  420. url: "/accept/:id",
  421. templateUrl: "static/tpl/index/sale/accept_detail.html",
  422. controller: 'SaleAcceptDetailCtrl'
  423. }).state('sale.returns', {
  424. url: "/returns",
  425. templateUrl: "static/tpl/index/sale/returns.html",
  426. controller: 'SaleReturnsCtrl'
  427. }).state('sale.return_detail', {
  428. url: "/return/:id",
  429. templateUrl: "static/tpl/index/sale/return_detail.html",
  430. controller: 'SaleReturnsDetailCtrl'
  431. }).state('sale.sample', {
  432. url: "/sample",
  433. templateUrl: "static/tpl/index/sale/sample.html",
  434. controller: 'SaleSampleCtrl'
  435. }).state('sale.sample_detail', {
  436. url: "/sample/:id",
  437. templateUrl: "static/tpl/index/sale/sample_detail.html",
  438. controller: 'SaleSampleDetailCtrl'
  439. }).state('sale.approval', {
  440. url: "/approval",
  441. templateUrl: "static/tpl/index/sale/approval.html",
  442. controller: 'SaleApprovalCtrl'
  443. }).state('sale.prodList', {
  444. url: "/prodList",
  445. templateUrl: "static/tpl/index/baseInfo/prodList.html",
  446. controller: 'ProductListCtrl'
  447. }).state('sale.newProdInfo', {
  448. url: "/newProdInfo",
  449. templateUrl: "static/tpl/index/baseInfo/newProdInfo.html",
  450. controller: 'NewProdInfoCtrl'
  451. }).state('sale.uploadByBatch', {
  452. url: "/uploadByBatch",
  453. templateUrl: "static/tpl/index/baseInfo/uploadByBatch.html",
  454. controller: 'UploadByBatchCtrl'
  455. }).state('sale.productDetail', {
  456. url: "/prodList/:id",
  457. templateUrl: "static/tpl/index/baseInfo/productDetail.html",
  458. controller: 'ProductDetailCtrl'
  459. }).state('sale.productmatches', {
  460. url: "/productmatches",
  461. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  462. controller: 'ProductmatchesForSaleCtrl'
  463. }).state('sale.maketodo', {
  464. url: "/maketodo",
  465. templateUrl: "static/tpl/index/make/todo.html"
  466. }).state('sale.maketodo.order', {
  467. url: "/makeorder",
  468. templateUrl: "static/tpl/index/make/order.html",
  469. controller: 'MakeOrderCtrl'
  470. }).state('sale.makeorder', {
  471. url: "/makeorder",
  472. templateUrl: "static/tpl/index/make/order.html",
  473. controller: 'MakeOrderCtrl'
  474. }).state('sale.makeorder_detail', {
  475. url: "/makeorder/:id",
  476. templateUrl: "static/tpl/index/make/order_detail.html",
  477. controller: 'MakeOrderDetailCtrl'
  478. }).state('sale.badOut', {
  479. url: "/badOut",
  480. templateUrl: "static/tpl/index/qc/badOut.html",
  481. controller: 'SaleBadOutCtrl'
  482. }).state('sale.MRB', {
  483. url: "/MRB",
  484. templateUrl: "static/tpl/index/qc/MRB.html",
  485. controller: 'SaleMRBCtrl'
  486. }).state('sale.badIn', {
  487. url: "/badIn",
  488. templateUrl: "static/tpl/index/qc/badIn.html",
  489. controller: 'SaleBadInCtrl'
  490. }).state('sale.makeaccept', {
  491. url: "/makeaccept",
  492. templateUrl: "static/tpl/index/make/accept.html",
  493. controller: 'MakeAcceptCtrl'
  494. }).state('sale.makereturns', {
  495. url: "/makereturns",
  496. templateUrl: "static/tpl/index/make/returns.html",
  497. controller: 'MakeReturnCtrl'
  498. }).state('sale.makechange', {
  499. url: "/makechange",
  500. templateUrl: "static/tpl/index/make/change.html",
  501. controller: 'MakeChangeCtrl'
  502. }).state('sale.makechange_detail', {
  503. url: "/makechange/:id",
  504. templateUrl: "static/tpl/index/make/change_detail.html",
  505. controller: 'MakeChangeDetailCtrl'
  506. }).state('account', {
  507. url: "/account",
  508. views: {
  509. "left-view": {
  510. templateUrl: "static/tpl/index/account/left.html",
  511. controller: 'LeftCtrl'
  512. },
  513. "right-view": {
  514. templateUrl: "static/tpl/index/account/right.html"
  515. }
  516. }
  517. }).state('account.index', {
  518. url: "",
  519. templateUrl: "static/tpl/index/account/index.html",
  520. controller: 'RightCtrl'
  521. }).state('account.home', {
  522. url: "/",
  523. templateUrl: "static/tpl/index/account/index.html",
  524. controller: 'RightCtrl'
  525. }).state('baseInfo', {//基础资料
  526. url: "/baseInfo",
  527. views: {
  528. "left-view": {},
  529. "right-view": {
  530. templateUrl: "static/tpl/index/baseInfo/right.html"
  531. }
  532. }
  533. }).state('baseInfo.index', {
  534. url: "/enterpriseList",
  535. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  536. controller: 'EnterpriseListCtrl'
  537. }).state('baseInfo.home', {
  538. url: "/enterpriseList",
  539. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  540. controller: 'EnterpriseListCtrl'
  541. }).state('baseInfo.enterpriseList', {
  542. url: "/enterpriseList",
  543. templateUrl: "static/tpl/index/baseInfo/enterpriseList.html",
  544. controller: 'EnterpriseListCtrl'
  545. }).state('baseInfo.myClient', {
  546. url: "/myClient",
  547. templateUrl: "static/tpl/index/baseInfo/myClient.html",
  548. controller: 'MyClientCtrl'
  549. }).state('baseInfo.mySupplier', {
  550. url: "/mySupplier",
  551. templateUrl: "static/tpl/index/baseInfo/mySupplier.html",
  552. controller: 'MySupplierCtrl'
  553. }).state('baseInfo.myRequest', {
  554. url: "/myRequest",
  555. templateUrl: "static/tpl/index/baseInfo/myRequest.html",
  556. controller: 'AddPartnerRequestCtrl'
  557. }).state('baseInfo.newPartner', {
  558. url: "/newPartner",
  559. templateUrl: "static/tpl/index/baseInfo/newPartner.html",
  560. controller: 'NewPartnerCtrl'
  561. }).state('baseInfo.myMessage', {
  562. url: "/myMessage",
  563. templateUrl: "static/tpl/index/baseInfo/myMessage.html",
  564. controller: 'AddPartnerMessageCtrl'
  565. }).state('baseInfo.myPartners', {
  566. url: '/myPartners',
  567. templateUrl: "static/tpl/index/baseInfo/myPartners.html",
  568. controller: 'MyPartnersCtrl'
  569. }).state('baseInfo.businessGroups', {
  570. url: '/businessGroups',
  571. controller: 'BusinessGroupsCtrl'
  572. }).state('baseInfo.inquiryList', {
  573. url: '/inquiryList',
  574. templateUrl: "static/tpl/index/baseInfo/inquiry_list.html",
  575. controller: 'PublicInquiryListCtrl'
  576. }).state('baseInfo.inquiryListDetail', {
  577. url: '/inquiryList/:id',
  578. templateUrl: "static/tpl/index/baseInfo/inquiryItem_detail.html",
  579. controller: 'PublicInquiryListDetailCtrl'
  580. }).state('baseInfo.vendorInfo', {
  581. url: '/enume/vendorInfo',
  582. templateUrl: "static/tpl/index/baseInfo/vendorsInfo.html",
  583. controller: 'VendorsInfoCtrl'
  584. }).state('baseInfo.servicerInfo', {
  585. url: '/enume/servicerInfo',
  586. templateUrl: "static/tpl/index/baseInfo/servicerInfo.html",
  587. controller: 'ServicerInfoCtrl'
  588. }).state('baseInfo.customerInfo', {
  589. url: '/enume/customerInfo',
  590. templateUrl: "static/tpl/index/baseInfo/customersInfo.html",
  591. controller: 'CustomersInfoCtrl'
  592. }).state('baseInfo.enume', {
  593. url: '/enume',
  594. templateUrl: "static/tpl/index/baseInfo/vendorAndCustomer.html"
  595. }).state('baseInfo.partner', {
  596. url: '/partner',
  597. templateUrl: "static/tpl/index/baseInfo/addPartners.html",
  598. controller: 'AddPartnersCtrl'
  599. }).state('baseInfo.partner_searchresult', {
  600. url: '/search',
  601. templateUrl: "static/tpl/index/baseInfo/searchresult.html",
  602. controller: 'EnterpriseSearchCtrl'
  603. }).state('baseInfo.invitation', {
  604. url: '/invitation',
  605. templateUrl: "static/tpl/index/baseInfo/invitation.html",
  606. controller: 'InvitationCtrl'
  607. }).state('qc', {
  608. url: "/qc",
  609. views: {
  610. "left-view": {
  611. templateUrl: "static/tpl/index/qc/left.html"
  612. },
  613. "right-view": {
  614. templateUrl: "static/tpl/index/qc/right.html"
  615. }
  616. }
  617. }).state('qc.index', {
  618. url: "",
  619. templateUrl: "static/tpl/index/qc/index.html"
  620. }).state('qc.home', {
  621. url: "/",
  622. templateUrl: "static/tpl/index/qc/index.html"
  623. }).state('fa', {
  624. url: "/fa",
  625. views: {
  626. "left-view": {
  627. templateUrl: "static/tpl/index/fa/left.html"
  628. },
  629. "right-view": {
  630. templateUrl: "static/tpl/index/fa/right.html"
  631. }
  632. }
  633. }).state('fa.index', {
  634. url: "",
  635. templateUrl: "static/tpl/index/fa/index.html"
  636. }).state('fa.home', {
  637. url: "/",
  638. templateUrl: "static/tpl/index/fa/index.html"
  639. }).state('fa.apBill', {
  640. url: "/apBill",
  641. templateUrl: "static/tpl/index/fa/apBill.html",
  642. controller: 'SaleApBillCtrl'
  643. }).state('fa.apBill_detail', {
  644. url: "/apBill/:id",
  645. templateUrl: "static/tpl/index/fa/apBill_detail.html",
  646. controller: 'SaleApBillDetailCtrl'
  647. }).state('fa.arCheck', {
  648. url: "/arCheck",
  649. templateUrl: "static/tpl/index/fa/arCheck.html",
  650. controller: 'SaleArCheckCtrl'
  651. }).state('fa.arCheck_detail', {
  652. url: "/arCheck/:id",
  653. templateUrl: "static/tpl/index/fa/arCheck_detail.html",
  654. controller: 'SaleArCheckDetailCtrl'
  655. }).state('fa.apCheck', {
  656. url: "/apCheck",
  657. params: {
  658. 'id': null
  659. },
  660. templateUrl: "static/tpl/index/fa/apCheck.html",
  661. controller: 'PurchaseApCheckCtrl'
  662. }).state('fa.apCheck_detail', {
  663. url: "/apCheck/:id",
  664. templateUrl: "static/tpl/index/fa/apCheck_detail.html",
  665. controller: 'PurchaseApCheckDetailCtrl'
  666. }).state('fa.apCheckList', {
  667. url: "/apCheckList",
  668. templateUrl: "static/tpl/index/fa/apCheckList.html",
  669. controller: 'PurchaseApCheckListCtrl'
  670. }).state('fa.apBillOut', {
  671. url: "/apBillOut",
  672. params:{
  673. 'id':null
  674. },
  675. templateUrl: "static/tpl/index/fa/apBillOut.html",
  676. controller: 'PurchaseApBillOutCtrl'
  677. }).state('fa.apBillOut_detail', {
  678. url: "/apBillOut/:id",
  679. templateUrl: "static/tpl/index/fa/apBillOut_detail.html",
  680. controller: 'PurchaseApBillOutDetailCtrl'
  681. }).state('fa.apBillOutList', {
  682. url: "/apBillOutList",
  683. templateUrl: "static/tpl/index/fa/apBillOutList.html",
  684. controller: 'PurchaseApBillOutListCtrl'
  685. }).state('fa.adjustList', {
  686. url: "/adjustList",
  687. templateUrl: "static/tpl/index/fa/adjustList.html",
  688. controller: 'PurchaseAdjustListCtrl'
  689. }).state('make', {
  690. url: "/make",
  691. views: {
  692. "left-view": {
  693. templateUrl: "static/tpl/index/make/left.html"
  694. },
  695. "right-view": {
  696. templateUrl: "static/tpl/index/make/right.html"
  697. }
  698. }
  699. }).state('make.index', {
  700. url: "",
  701. templateUrl: "static/tpl/index/make/index.html"
  702. }).state('make.home', {
  703. url: "/",
  704. templateUrl: "static/tpl/index/make/index.html"
  705. }).state('cs', {// 客户服务
  706. url: "/cs",
  707. views: {
  708. "left-view": {
  709. templateUrl: "static/tpl/index/cs/left.html"
  710. },
  711. "right-view": {
  712. templateUrl: "static/tpl/index/cs/right.html"
  713. }
  714. }
  715. }).state('cs.index', {
  716. url: "",
  717. templateUrl: "static/tpl/index/cs/index.html"
  718. }).state('cs.home', {
  719. url: "/",
  720. templateUrl: "static/tpl/index/cs/index.html"
  721. }).state('search', { //顶部搜索
  722. url: "/search?keyword=",
  723. views: {
  724. "left-view": {
  725. templateUrl: "static/tpl/index/search/left.html"
  726. },
  727. "right-view": {
  728. templateUrl: "static/tpl/index/search/search_result.html",
  729. controller: 'TopSearchCtrl'
  730. }
  731. }
  732. }).state('approvalflow', { //审批流
  733. url: "/approvalFlow",
  734. views: {
  735. "left-view": {
  736. templateUrl: "static/tpl/index/approvalFlow/left.html"
  737. },
  738. "right-view": {
  739. templateUrl: "static/tpl/index/approvalFlow/right.html",
  740. }
  741. }
  742. }).state('approvalflow.flow', {
  743. url: "/flow",
  744. templateUrl: "static/tpl/index/approvalFlow/home.html",
  745. controller: 'approvalFlowCtrl'
  746. }).state('approvalflow.enterprise', {
  747. url: "/enterprise",
  748. templateUrl: "static/tpl/index/approvalFlow/enterprise.html",
  749. controller: 'EnterpriseCtrl'
  750. }).state('approvalflow.user', {
  751. url: "/user",
  752. templateUrl: "static/tpl/index/approvalFlow/user.html",
  753. controller: 'UserCtrl'
  754. }).state('approvalflow.log', {
  755. url: "/log",
  756. templateUrl: "static/tpl/index/approvalFlow/log.html",
  757. controller: 'LogCtrl'
  758. }).state('approvalflow.resource', {
  759. url: "/resource",
  760. templateUrl: "static/tpl/index/approvalFlow/resource.html",
  761. controller: 'ResourceCtrl'
  762. }).state('approvalflow.role', {
  763. url: "/role",
  764. templateUrl: "static/tpl/index/approvalFlow/role.html",
  765. controller: 'RoleCtrl'
  766. }).state('approvalflow.product', {
  767. url: "/product",
  768. templateUrl: "static/tpl/index/approvalFlow/prodList.html",
  769. controller: 'ProductAllCtrl'
  770. }).state('approvalflow.userProduct', {
  771. url: "/userProduct",
  772. templateUrl: "static/tpl/index/approvalFlow/userProduct.html",
  773. controller: 'UserProductCtrl'
  774. }).state('approvalflow.productmatches', {
  775. url: "/productmatches",
  776. templateUrl: "static/tpl/index/approvalFlow/productmatches.html",
  777. controller: 'ProductmatchesCtrl'
  778. }).state('sale.vendorPerformanceAssess', {
  779. url: "/vendorPerformanceAssess",
  780. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess.html",
  781. controller: 'VendorPerformanceAssessCtrl'
  782. }).state('sale.vendorPerformanceAssess_detail', {
  783. url: "/vendorPerformanceAssess/:id",
  784. templateUrl: "static/tpl/index/sale/vendorPerformanceAssess_detail.html",
  785. controller: 'VendorPerformanceAssessDetailCtrl'
  786. });
  787. $urlRouterProvider.otherwise('/index');
  788. }]);
  789. /**
  790. * 表示符号
  791. */
  792. app.factory('Symbol', function () {
  793. return {
  794. currency: function (cur) {
  795. if (cur == 'RMB') return '¥';
  796. else if (cur == 'USD') return '$';
  797. else if (cur == 'EUR') return '€';
  798. else if (cur == null || cur == '') return '¥';
  799. else return cur;
  800. }
  801. };
  802. }).factory('Lodop', function () {
  803. return {
  804. getLodop: function (oOBJECT, oEMBED) {
  805. var CreatedOKLodop7766 = null;
  806. /**************************
  807. 本函数根据浏览器类型决定采用哪个页面元素作为Lodop对象:
  808. IE系列、IE内核系列的浏览器采用oOBJECT,
  809. 其它浏览器(Firefox系列、Chrome系列、Opera系列、Safari系列等)采用oEMBED,
  810. 如果页面没有相关对象元素,则新建一个或使用上次那个,避免重复生成。
  811. 64位浏览器指向64位的安装程序install_lodop64.exe。
  812. **************************/
  813. var strHtmInstall = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  814. var strHtmUpdate = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop32.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  815. var strHtm64_Install = "<br><font color='#FF00FF'>打印控件未安装!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行安装</a>,安装后请刷新页面或重新进入。</font>";
  816. var strHtm64_Update = "<br><font color='#FF00FF'>打印控件需要升级!点击这里<a href='static/lib/lodopActivex/install_lodop64.exe' target='_self'>执行升级</a>,升级后请重新进入。</font>";
  817. var strHtmFireFox = "<br><br><font color='#FF00FF'>(注意:如曾安装过Lodop旧版附件npActiveXPLugin,请在【工具】->【附加组件】->【扩展】中先卸它)</font>";
  818. var strHtmChrome = "<br><br><font color='#FF00FF'>(如果此前正常,仅因浏览器升级或重安装而出问题,需重新执行以上安装)</font>";
  819. var LODOP;
  820. try {
  821. //=====判断浏览器类型:===============
  822. var isIE = (navigator.userAgent.indexOf('MSIE') >= 0) || (navigator.userAgent.indexOf('Trident') >= 0);
  823. var is64IE = isIE && (navigator.userAgent.indexOf('x64') >= 0);
  824. //=====如果页面有Lodop就直接使用,没有则新建:==========
  825. if (oOBJECT != undefined || oEMBED != undefined) {
  826. if (isIE)
  827. LODOP = oOBJECT;
  828. else
  829. LODOP = oEMBED;
  830. } else {
  831. if (CreatedOKLodop7766 == null) {
  832. LODOP = document.createElement("object");
  833. LODOP.setAttribute("width", 0);
  834. LODOP.setAttribute("height", 0);
  835. LODOP.setAttribute("style", "position:absolute;left:0px;top:-100px;width:0px;height:0px;");
  836. if (isIE) LODOP.setAttribute("classid", "clsid:2105C259-1E0C-4534-8141-A753534CB4CA");
  837. else LODOP.setAttribute("type", "application/x-print-lodop");
  838. document.documentElement.appendChild(LODOP);
  839. CreatedOKLodop7766 = LODOP;
  840. } else
  841. LODOP = CreatedOKLodop7766;
  842. }
  843. ;
  844. //=====判断Lodop插件是否安装过,没有安装或版本过低就提示下载安装:==========
  845. if ((LODOP == null) || (typeof(LODOP.VERSION) == "undefined")) {
  846. if (navigator.userAgent.indexOf('Chrome') >= 0)
  847. document.documentElement.innerHTML = strHtmChrome + document.documentElement.innerHTML;
  848. if (navigator.userAgent.indexOf('Firefox') >= 0)
  849. document.documentElement.innerHTML = strHtmFireFox + document.documentElement.innerHTML;
  850. if (is64IE) document.write(strHtm64_Install); else if (isIE) document.write(strHtmInstall); else
  851. document.documentElement.innerHTML = strHtmInstall + document.documentElement.innerHTML;
  852. return LODOP;
  853. } else if (LODOP.VERSION < "6.1.9.8") {
  854. if (is64IE) document.write(strHtm64_Update); else if (isIE) document.write(strHtmUpdate); else
  855. document.documentElement.innerHTML = strHtmUpdate + document.documentElement.innerHTML;
  856. return LODOP;
  857. }
  858. ;
  859. //=====如下空白位置适合调用统一功能(如注册码、语言选择等):====
  860. LODOP.SET_LICENSES("深圳市优软科技有限公司", "BBF53BD5AB0D522B3207D05CDE381F65", "", "");
  861. //============================================================
  862. return LODOP;
  863. } catch (err) {
  864. if (is64IE)
  865. document.documentElement.innerHTML = "Error:" + strHtm64_Install + document.documentElement.innerHTML; else
  866. document.documentElement.innerHTML = "Error:" + strHtmInstall + document.documentElement.innerHTML;
  867. return LODOP;
  868. }
  869. ;
  870. }
  871. }
  872. });
  873. app.controller('MyCtrl', ['$scope', '$rootScope', '$modal', 'toaster', function ($scope, $rootScope, $modal, toaster) {
  874. $rootScope.$on('$locationChangeSuccess', function (evt, newUrl) {
  875. var routeState = newUrl.substr(newUrl.indexOf('#/') + 2);
  876. if (routeState.indexOf('/') > -1)
  877. routeState = routeState.substring(0, routeState.indexOf('/'));
  878. if (routeState.indexOf('.') > -1)
  879. routeState = routeState.substring(0, routeState.indexOf('.'));
  880. $scope.routeState = routeState || 'home';
  881. });
  882. $scope.search = function (keyword) {
  883. if (keyword != null && keyword != '') {
  884. $rootScope.searchKeyword = keyword;
  885. window.location.hash = '#/search?keyword=' + keyword;
  886. } else {
  887. $rootScope.searchKeyword = null;
  888. window.location.hash = '#/search';
  889. }
  890. };
  891. $scope.showMessage = function () {
  892. var modalInstance = $modal.open({
  893. templateUrl: 'static/tpl/index/home/pagingRelease.html',
  894. controller: 'PagingReleaseCtrl'
  895. });
  896. };
  897. // 连接到询价
  898. $scope.linktoInquiry = function (active) {
  899. $rootScope.active = active;
  900. window.location.href = "#/sale/inquiry";
  901. }
  902. // 连接到招标
  903. $scope.linktoSaleTender = function (active) {
  904. $rootScope.active = active;
  905. window.location.href = "#/sale/tender";
  906. }
  907. // 链接到打样申请
  908. $scope.linktoSample = function (active) {
  909. $rootScope.active = active;
  910. window.location.href = "#/sale/sample";
  911. }
  912. // 链接到采购招标
  913. $scope.linktoPurcTender = function (active) {
  914. $rootScope.tenderActive = active;
  915. window.location.href = "#/purc/tender";
  916. }
  917. $scope.linktoPurcInquiry = function (active) {
  918. $rootScope.active = active;
  919. window.location.href = "#/purc/purchaseinquiry";
  920. }
  921. }]);
  922. /**
  923. * 新消息提醒(调用公共服务接口) -2018-01-22 19:36:50
  924. * @author dongbw
  925. */
  926. app.controller('PagingReleaseCtrl', ['$scope', 'PagingRelease', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'PagingReleaseInfo',
  927. function ($scope, PagingRelease, BaseService, ngTableParams, toaster, $modalInstance, PagingReleaseInfo) {
  928. $scope.active = "todo";
  929. $scope.setActive = function (state) {
  930. if ($scope.active != state) {
  931. $scope.active = state;
  932. if ($scope.tableParams.page() == 1)
  933. $scope.tableParams.reload();
  934. else
  935. $scope.tableParams.page(1);
  936. }
  937. };
  938. /**
  939. * 页面状态按钮过滤
  940. */
  941. var getMessageState = function (active) {
  942. var fn = 'get';
  943. switch (active) {
  944. case 'done':
  945. fn = 'getDone';
  946. break;
  947. case 'todo':
  948. fn = 'getTodo';
  949. break;
  950. }
  951. return fn;
  952. };
  953. $scope.tableParams = new ngTableParams({
  954. page: 1,
  955. count: 5,
  956. sorting: {
  957. 'createTime': 'desc'
  958. }
  959. }, {
  960. total: 0,
  961. counts: [],
  962. getData: function ($defer, params) {
  963. $scope.loading = true;
  964. var pageParams = params.url();
  965. var realActive = {};
  966. pageParams.searchFilter = { // 筛选条件
  967. keyword: $scope.keyword
  968. // fromDate: getDateTime($scope.condition.dateFrom),
  969. // endDate: getDateTime($scope.condition.dateTo)
  970. };
  971. PagingRelease[getMessageState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  972. $scope.loading = false;
  973. if (page) {
  974. params.total(page.totalElements);
  975. $defer.resolve(page.content);
  976. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  977. }
  978. }, function (response) {
  979. $scope.loading = false;
  980. toaster.pop('error', '数据加载失败', response.data);
  981. });
  982. }
  983. });
  984. $scope.close = function () {
  985. $modalInstance.close();
  986. window.location.reload();
  987. };
  988. $scope.checks = {
  989. checked: false
  990. };// 全选框
  991. $scope.checkAll = function () {
  992. angular.forEach($scope.tableParams.data, function (message) {
  993. message.checked = $scope.checks.checked;
  994. });
  995. };
  996. // 单选
  997. $scope.checkOne = function (vendor) {
  998. vendor.checked = true;
  999. var checked = true;
  1000. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  1001. if (!message.checked) {
  1002. checked = false;
  1003. }
  1004. });
  1005. $scope.checks.checked = checked;
  1006. };
  1007. // 单反选
  1008. $scope.unCheckOne = function (vendor) {
  1009. vendor.checked = false;
  1010. $scope.checks.checked = false;
  1011. };
  1012. /**
  1013. * 当前页标为已读
  1014. */
  1015. $scope.setRead = function () {
  1016. $scope.loading = true;
  1017. var messageIds = [];
  1018. angular.forEach($scope.tableParams.data, function(message) {
  1019. messageIds.push(message.id);
  1020. });
  1021. PagingRelease.setPageRead({}, messageIds, function (data) {
  1022. $scope.loading = false;
  1023. if (data.success) {
  1024. toaster.pop("success", "设置已读成功");
  1025. }
  1026. if (data.error) {
  1027. toaster.pop("error", "设置已读失败");
  1028. }
  1029. $scope.tableParams.page(1);
  1030. $scope.tableParams.reload();
  1031. });
  1032. };
  1033. // 点击内容连接之后,信息标为已读
  1034. $scope.setOneRead = function (id) {
  1035. $scope.loading = true;
  1036. $modalInstance.close();
  1037. PagingRelease.setMessageRead({id: id}, {}, function (data) {
  1038. $scope.loading = false;
  1039. }, function (response) {
  1040. $scope.loading = false;
  1041. toaster.pop('error', '提示', response.data);
  1042. });
  1043. };
  1044. // 搜索框回车
  1045. $scope.onSearch = function () {
  1046. $scope.tableParams.page(1);
  1047. $scope.tableParams.reload();
  1048. };
  1049. }]);
  1050. // 高亮显示关键词
  1051. app.filter('getkey', ['$sce', '$rootScope', function ($sce, $rootScope) {
  1052. var search = $rootScope.searchKeyword;
  1053. return function (content, search) {
  1054. content = encodeURI(content);
  1055. search = encodeURI(search);
  1056. var reg = new RegExp(search, 'gim');
  1057. var result = content.replace(reg, '<font color="red">$&</font>');
  1058. result = decodeURIComponent(result);
  1059. return $sce.trustAsHtml(result);
  1060. };
  1061. $rootScope.searchKeyword = null;// 清除缓存的关键字
  1062. }]);
  1063. /**
  1064. * 顶部搜索
  1065. */
  1066. 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) {
  1067. BaseService.scrollBackToTop();
  1068. $scope.active = 'all';
  1069. $scope.tip = $rootScope.searchKeyword;
  1070. // 企业搜索
  1071. var getService = function () {
  1072. return getAccountUserSpace;
  1073. };
  1074. $scope.tableParams = new ngTableParams({
  1075. page: 1,
  1076. count: 20,
  1077. sorting: {}
  1078. }, {
  1079. total: 0,
  1080. counts: [5, 10, 25, 50],
  1081. getData: function ($defer, params) {
  1082. $scope.loading = true;
  1083. var pageParams = params.url();
  1084. pageParams.keyword = $rootScope.searchKeyword;
  1085. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1086. $scope.loading = false;
  1087. if (page) {
  1088. $scope.total = page.totalElement;
  1089. params.total(page.totalElement);
  1090. $defer.resolve(page.content);
  1091. }
  1092. }, function (response) {
  1093. $scope.loading = false;
  1094. toaster.pop('error', '数据加载失败', response.data);
  1095. });
  1096. }
  1097. });
  1098. // 添加合作关系
  1099. $scope.addPartner = function (name, businessCode) {
  1100. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  1101. if (data.success) {
  1102. toaster.pop("success", '添加成功', data.success);
  1103. $scope.tableParams.reload();
  1104. }
  1105. if (data.error) {
  1106. toaster.pop("error", '添加失败', data.error);
  1107. }
  1108. }, function (response) {
  1109. toaster.pop('error', '失败', response.data);
  1110. });
  1111. }
  1112. // 物料搜索
  1113. var getProdService = function () {
  1114. return SearchProd;
  1115. };
  1116. $scope.prodTableParams = new ngTableParams({
  1117. page: 1,
  1118. count: 20,
  1119. sorting: {}
  1120. }, {
  1121. total: 0,
  1122. counts: [5, 10, 25, 50],
  1123. getData: function ($defer, params) {
  1124. $scope.loading = true;
  1125. var pageParams = params.url();
  1126. pageParams.keyword = $rootScope.searchKeyword;
  1127. getProdService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  1128. $scope.loading = false;
  1129. if (page) {
  1130. $scope.prodtotal = page.totalElement;
  1131. params.total(page.totalElement);
  1132. $defer.resolve(page.content);
  1133. }
  1134. }, function (response) {
  1135. $scope.loading = false;
  1136. toaster.pop('error', '数据加载失败', response.data);
  1137. });
  1138. }
  1139. });
  1140. /**
  1141. * 向企业购买
  1142. */
  1143. $scope.PurcByEn = function (businessCode) {
  1144. $rootScope.businessCode = businessCode;
  1145. window.location.hash = "#/purc/addOrder";
  1146. }
  1147. /**
  1148. * 选中单个物料购买
  1149. * @param businessCode
  1150. * @param id
  1151. */
  1152. $scope.PurcByEnAndProd = function (businessCode, id) {
  1153. $rootScope.businessCode = businessCode;
  1154. $rootScope.prodId = id;
  1155. window.location.hash = "#/purc/addOrder";
  1156. }
  1157. /**
  1158. * 询价
  1159. */
  1160. $scope.PurcInquiry = function (businessCode, id) {
  1161. $rootScope.prodId = id;
  1162. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  1163. }
  1164. /**
  1165. * 邀请注册商务平台
  1166. */
  1167. $scope.invite = function (name) {
  1168. var modalInstance = $modal.open({
  1169. animation: true,
  1170. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1171. controller: 'InviteCtrl',
  1172. resolve: {
  1173. enname: function () {
  1174. return name
  1175. }
  1176. }
  1177. });
  1178. modalInstance.result.then(function (data) {
  1179. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1180. if (data.success) {
  1181. toaster.pop('success', '提示', data.success);
  1182. }
  1183. if (data.error) {
  1184. toaster.pop('error', '提示', data.error);
  1185. }
  1186. }, function (response) {
  1187. toaster.pop('error', '提示', response.data);
  1188. });
  1189. });
  1190. }
  1191. /**
  1192. * 立即查看
  1193. */
  1194. $scope.view = function (name) {
  1195. $rootScope.vendName = name;
  1196. window.location.hash = "#/baseInfo/newPartner";
  1197. }
  1198. }]);
  1199. app.controller('InviteCtrl', ['$scope', 'toaster', '$modalInstance', 'enname', 'InvitationRecord', '$modal', function ($scope, toaster, $modalInstance, enname, InvitationRecord, $modal) {
  1200. $scope.enter = {
  1201. vendname: enname
  1202. };
  1203. $scope.save = function (enter) {
  1204. // 先检验是否已注册
  1205. InvitationRecord.enterpriseList({name: enter.vendname}, {}, function(data) {
  1206. $scope.existEn = data;
  1207. if ($scope.existEn.length == 0) {
  1208. $modalInstance.close(enter);
  1209. var modalInstance = $modal.open({
  1210. animation: true,
  1211. templateUrl: 'static/tpl/index/baseInfo/modal/QQshare_modal.html',
  1212. controller: 'QQShareCtrl',
  1213. });
  1214. } else {
  1215. $scope.enterprise = $scope.existEn[0];
  1216. }
  1217. });
  1218. }
  1219. $scope.viewDetail = function() {
  1220. $scope.exist = 1;
  1221. }
  1222. $scope.cancel = function () {
  1223. $modalInstance.dismiss();
  1224. }
  1225. $scope.closeDetail = function() {
  1226. $scope.exist = 0;
  1227. }
  1228. /**
  1229. * 添加合作伙伴
  1230. * @param enterprise
  1231. */
  1232. $scope.addPartner = function(en) {
  1233. InvitationRecord.addPart({inviteEnUU: $scope.enterprise.uu, inviteUserName: en.vendusername, inviteUserTel: en.vendusertel}, {}, function(data) {
  1234. if (data.success) {
  1235. toaster.pop('success', data.success);
  1236. $modalInstance.dismiss();
  1237. } else if (data.error) {
  1238. toaster.pop('error', data.error);
  1239. }
  1240. }, function(response) {
  1241. toaster.pop('error', response.data);
  1242. });
  1243. }
  1244. }]);
  1245. /**
  1246. * QQ分享
  1247. */
  1248. app.controller('QQShareCtrl', ['$scope', 'InvitationRecord', '$modalInstance', function($scope, InvitationRecord, $modalInstance) {
  1249. InvitationRecord.getInviteUrl({}, function(data) {
  1250. $scope.inviteUrl = data.url;
  1251. var p = {
  1252. url: $scope.inviteUrl, /*获取URL,可加上来自分享到QQ标识,方便统计*/
  1253. // desc: 'hejq', /*分享理由(风格应模拟用户对话),支持多分享语随机展现(使用|分隔)*/
  1254. // title: '', /*分享标题(可选)*/
  1255. // summary: '', /*分享摘要(可选)*/
  1256. // pics: '', /*分享图片(可选)*/
  1257. // flash: '', /*视频地址(可选)*/
  1258. // site: '', /*分享来源(可选) 如:QQ分享*/
  1259. // style: '201',
  1260. // width: 32,
  1261. // height: 32
  1262. };
  1263. var s = [];
  1264. for(var i in p){
  1265. s.push(i + '=' + encodeURIComponent(p[i]||''));
  1266. }
  1267. s.join('&');
  1268. $scope.QQshare = function() {
  1269. window.open("http://connect.qq.com/widget/shareqq/index.html?" + s)
  1270. }
  1271. });
  1272. $scope.close = function() {
  1273. $modalInstance.dismiss();
  1274. }
  1275. }]);
  1276. /**
  1277. * 再次邀请
  1278. */
  1279. app.controller('ReInviteCtrl', ['$scope', 'toaster', '$modalInstance', 'id', 'InvitationRecord', function ($scope, toaster, $modalInstance, id, InvitationRecord) {
  1280. var loadData = function (id) {
  1281. InvitationRecord.getRecordById({id: id}, {}, function (data) {
  1282. if (data.user !== null) {
  1283. data.user = {};
  1284. }
  1285. $scope.enter = data;
  1286. });
  1287. };
  1288. loadData(id);
  1289. $scope.save = function (enter) {
  1290. if (!enter.vendusertel && !enter.venduseremail) {
  1291. toaster.pop('info', '提示', '手机号或邮箱至少填写一个才能通知到客户');
  1292. } else {
  1293. $modalInstance.close(enter);
  1294. }
  1295. };
  1296. $scope.cancel = function () {
  1297. $modalInstance.dismiss();
  1298. }
  1299. }]);
  1300. /**
  1301. * 邀请记录
  1302. */
  1303. app.controller('InvitationCtrl', ['$scope', 'toaster', 'InvitationRecord', 'BaseService', 'ngTableParams', '$modal', function ($scope, toaster, InvitationRecord, BaseService, ngTableParams, $modal) {
  1304. BaseService.scrollBackToTop();
  1305. $scope.status = "invitation";
  1306. $scope.active = "invitation";
  1307. var getService = function () {
  1308. if ($scope.active === "invitation") {
  1309. return InvitationRecord.records;
  1310. } else if ($scope.active === "invitationTeam") {
  1311. return InvitationRecord.getActiveRecordsByEn; // 只获取已激活的
  1312. }
  1313. };
  1314. $scope.setActive = function (state) {
  1315. if ($scope.active !== state) {
  1316. $scope.active = state;
  1317. if ($scope.tableParams.page() === 1)
  1318. $scope.tableParams.reload();
  1319. else
  1320. $scope.tableParams.page(1);
  1321. }
  1322. };
  1323. $scope.tableParams = new ngTableParams({ // ng-Table参数
  1324. page: 1,
  1325. count: 20,
  1326. sorting: {}
  1327. }, {
  1328. total: 0,
  1329. counts: [],
  1330. getData: function ($defer, params) { // 获取数据的方法
  1331. $scope.loading = true;
  1332. var pageParams = params.url();
  1333. pageParams.keyword = $scope.keyword;
  1334. $scope.tip = $scope.keyword;
  1335. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  1336. $scope.loading = false;
  1337. if (page) {
  1338. params.total(page.totalElement);
  1339. $defer.resolve(page.content);
  1340. }
  1341. }, function (response) {
  1342. $scope.loading = false;
  1343. toaster.pop('error', '数据加载失败', response.data);
  1344. });
  1345. }
  1346. });
  1347. $scope.onSearch = function (keyword) {
  1348. $scope.tableParams.page(1);
  1349. $scope.tableParams.reload();
  1350. $scope.tip = keyword;
  1351. }
  1352. $scope.search = function (name) {
  1353. $modal.open({
  1354. templateUrl: 'static/tpl/index/baseInfo/modal/fuzzysearch_enterprise_modal.html',
  1355. controller: 'FuzzySearchCtrl',
  1356. resolve: {
  1357. name: function () {
  1358. return name
  1359. }
  1360. }
  1361. }).result.then(function (data) {
  1362. });
  1363. };
  1364. // 再次邀请
  1365. $scope.reInvite = function (id) {
  1366. var modalInstance = $modal.open({
  1367. animation: true,
  1368. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  1369. controller: 'ReInviteCtrl',
  1370. resolve: {
  1371. id: function () {
  1372. return id
  1373. }
  1374. }
  1375. });
  1376. modalInstance.result.then(function (data) {
  1377. InvitationRecord.invite({formStore: data}, {}, function (data) {
  1378. if (data.success) {
  1379. toaster.pop('success', '提示', data.success);
  1380. $scope.tableParams.reload();
  1381. }
  1382. if (data.error) {
  1383. toaster.pop('error', '提示', data.error);
  1384. }
  1385. }, function (response) {
  1386. toaster.pop('error', '提示', response.data);
  1387. });
  1388. });
  1389. }
  1390. }]);
  1391. /**
  1392. * 模糊查询相似的企业名称
  1393. */
  1394. app.controller('FuzzySearchCtrl', ['$scope', 'name', 'InvitationRecord', 'toaster', 'BaseService', function ($scope, name, InvitationRecord, toaster, BaseService) {
  1395. $scope.name = name;
  1396. if ($scope.name != null) {
  1397. InvitationRecord.enterpriseList({name: $scope.name}, {}, function (data) {
  1398. $scope.enterprises = data;
  1399. }, function (response) {
  1400. toaster.pop('error', '提示', response.data);
  1401. });
  1402. }
  1403. }]);
  1404. app.controller('AuthCtrl', ['$scope', '$window', 'AuthenticationService', 'toaster', 'BaseService', '$modal', function ($scope, $window, AuthenticationService, toaster, BaseService, $modal) {
  1405. $scope.isAuthed = AuthenticationService.isAuthed(); //AuthenticationService模块在common/下
  1406. AuthenticationService.getAuthentication().success(function (data) {
  1407. if (data.enterprises) {
  1408. data.enterprise = data.enterprises[data.enterprises.length - 1];
  1409. if (data.enterprises.length > 1) {
  1410. var enSelect = [];
  1411. angular.forEach(data.enterprises, function (e) {
  1412. if (e.current)
  1413. data.enterprise = e;
  1414. else
  1415. enSelect.push(e);
  1416. });
  1417. data.enSelect = enSelect;
  1418. }
  1419. }
  1420. $scope.userInfo = data;
  1421. if (data == null || !data.userUU) {
  1422. $scope.isAuthed = false;
  1423. AuthenticationService.redirectSignin();
  1424. } else {
  1425. }
  1426. });
  1427. $scope.logout = function () {
  1428. $modal.open({
  1429. templateUrl: 'static/tpl/index/account/logout.html',
  1430. controller: 'LogOutCtrl'
  1431. }).result.then(function (s) {
  1432. if (s) {
  1433. AuthenticationService.logout();
  1434. }
  1435. });
  1436. };
  1437. $scope.switchto = function (enUU) {// 切换企业
  1438. AuthenticationService.reSignin(enUU).success(function () {
  1439. $window.location.reload();
  1440. });
  1441. };
  1442. $scope.addFavorite = function () {
  1443. var url = encodeURI(window.location.href);
  1444. try {
  1445. //ie浏览器收藏方式
  1446. window.external.addFavorite(url, "优软商务平台");
  1447. } catch (e) {
  1448. try {
  1449. //火狐浏览器收藏方式
  1450. window.sidebar.addPanel("优软商务平台", url);
  1451. } catch (e) {
  1452. toaster.pop('warning', '提示', "您的浏览器不支持自动添加收藏夹,请使用Ctrl+D进行添加," +
  1453. "或手动在浏览器里进行设置。");
  1454. }
  1455. }
  1456. };
  1457. }]);
  1458. app.controller('LogOutCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1459. $scope.close = function (confirm) {
  1460. $modalInstance.close(confirm);
  1461. };
  1462. }]);
  1463. app.controller('ImageInsertCtrl', ['$scope', '$modalInstance', function ($scope, $modalInstance) {
  1464. $scope.image = {src: null};
  1465. // 图片上传成功之后
  1466. $scope.onUploadSuccess = function (data) {
  1467. var path = data.path;
  1468. path = path.substring(0, path.lastIndexOf('.')) + "_150x90" + path.substr(path.lastIndexOf('.'));
  1469. $scope.$apply(function () {
  1470. $scope.image.src = data.path;
  1471. $scope.image.thumb = path;
  1472. });
  1473. };
  1474. $scope.close = function () {
  1475. $modalInstance.dismiss();
  1476. };
  1477. $scope.confirm = function () {
  1478. $modalInstance.close($scope.image);
  1479. $scope.imageUrl = null;
  1480. };
  1481. }]);
  1482. app.controller('TodoCtrl', ['$scope', 'SnapshotService', 'BaseService', '$rootScope', function ($scope, SnapshotService, BaseService, $rootScope) {
  1483. BaseService.scrollBackToTop();
  1484. SnapshotService.getTodo(function (data) {
  1485. $scope.todo = data;
  1486. });
  1487. var getUnread = function () {
  1488. SnapshotService.getUnread('all', function (data) {
  1489. $scope.unread = data;
  1490. });
  1491. };
  1492. getUnread();
  1493. //去除红点
  1494. $scope.setOrdersRead = function (type) {
  1495. switch (type){
  1496. case 'product':
  1497. $scope.unread.product = 0;
  1498. break;
  1499. case 'vendorPerformanceAssess':
  1500. $scope.unread.vendorPerformanceAssess = 0;
  1501. break;
  1502. case 'customer':
  1503. $scope.unread.customer = 0;
  1504. break;
  1505. case 'purcProduct':
  1506. $scope.unread.purcProduct = 0;
  1507. break;
  1508. case 'vendor':
  1509. $scope.unread.purcVendor = 0;
  1510. break;
  1511. }
  1512. };
  1513. $scope.setTenderActive = function (active) {
  1514. $rootScope.tenderActive = active;
  1515. window.location.hash = '#/purc/tender';
  1516. }
  1517. }]);
  1518. // header
  1519. app.controller('HeaderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1520. SnapshotService.getMessage(function (data) {
  1521. $scope.message = data;
  1522. });
  1523. }]);
  1524. app.controller('TruckCtrl', ['$scope', '$rootScope', '$modal', 'SaleTruck', function ($scope, $rootScope, $modal, SaleTruck) {
  1525. SaleTruck.query({}, function (data) {
  1526. $rootScope.truck = data;
  1527. $scope.truckCount = data ? data.length : 0;
  1528. });
  1529. $scope.$watch(function () {
  1530. return $rootScope.truck;
  1531. }, function (data) {
  1532. $scope.truckCount = data ? data.length : 0;
  1533. }, true);
  1534. $scope.clearAll = function () {
  1535. SaleTruck.remove({}, function () {
  1536. $rootScope.truck = [];
  1537. });
  1538. };
  1539. $scope.openTrack = function () {
  1540. $modal.open({
  1541. templateUrl: 'static/tpl/index/sale/track.html',
  1542. controller: 'TruckModalCtrl',
  1543. size: 'lg'
  1544. }).result.then(function (s) {
  1545. if (s) {
  1546. $scope.clearAll();
  1547. $rootScope.dataChanged = true;
  1548. }
  1549. });
  1550. };
  1551. }]);
  1552. app.controller('TruckModalCtrl', ['$scope', '$rootScope', '$modalInstance', 'SaleTruck', 'PurcNotice', 'toaster', '$state', '$filter', '$timeout', 'token', function ($scope, $rootScope, $modalInstance, SaleTruck, PurcNotice, toaster, $state, $filter, $timeout, token) {
  1553. $scope.loading = false;
  1554. $scope.saleSend = {sendItems: []};
  1555. SaleTruck.detail({}, function (data) {
  1556. // 按物料编号排序
  1557. $scope.notices = $filter('orderBy')(data, 'orderItem.product.code');
  1558. });
  1559. $scope.remove = function (index, notice) {
  1560. SaleTruck.remove({noticeId: notice.id}, function (data) {
  1561. $rootScope.truck = data;
  1562. $scope.notices.splice(index, 1);
  1563. });
  1564. };
  1565. $scope.$watch(function () {
  1566. return $scope.notices;
  1567. }, function (data) {
  1568. var q = 0, t = 0;
  1569. if (data) {
  1570. angular.forEach(data, function (d) {
  1571. q += d.thisSendQty;
  1572. t += d.thisSendQty * d.orderItem.price;
  1573. });
  1574. }
  1575. $scope.totalQty = q;
  1576. $scope.total = t;
  1577. }, true);
  1578. $scope.cancel = function () {
  1579. $modalInstance.close();
  1580. };
  1581. $scope.lockstatus = false;
  1582. // 锁定时间按钮5秒
  1583. $scope.lockClick = function () {
  1584. $scope.lockstatus = true;
  1585. $timeout(function () {
  1586. $scope.lockstatus = false;
  1587. }, 5000);
  1588. }
  1589. var getToken = function() {
  1590. token.info({userType: 'salenotice'}, {}, function(data) {
  1591. $scope.token = data.token;
  1592. }, function(response) {
  1593. toaster.pop('error', '提示', response.data);
  1594. });
  1595. }
  1596. getToken();
  1597. $scope.send = function () {// 发货
  1598. $scope.loading = true;
  1599. if (!$scope.saleSend.code || $scope.saleSend.code == '') {//送货单号为空
  1600. toaster.pop('error', '错误', '请输入送货单号');
  1601. $scope.loading = false;
  1602. return;
  1603. }
  1604. var currency = $scope.notices[0].orderItem.order.currency,
  1605. custUU = $scope.notices[0].enUU,
  1606. payments = $scope.notices[0].orderItem.order.payments, valid = true, items = [];
  1607. var num = 1;
  1608. for (var i in $scope.notices) {
  1609. var item = $scope.notices[i];
  1610. if (item.id) {
  1611. if (item.orderItem.order.currency != currency || item.enUU != custUU || item.orderItem.order.payments != payments) {
  1612. valid = false;
  1613. break;
  1614. }
  1615. items[i] = {noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++};
  1616. }
  1617. }
  1618. if (!valid) {
  1619. $scope.loading = false;
  1620. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  1621. } else {
  1622. var send = angular.extend(angular.copy($scope.saleSend), {
  1623. currency: currency,
  1624. custUU: custUU,
  1625. payments: payments,
  1626. sendItems: items
  1627. });
  1628. if($scope.token != null) {
  1629. PurcNotice.sendByBatch({token: $scope.token}, send, function (data) {
  1630. $scope.loading = false;
  1631. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + send.code);
  1632. $modalInstance.close(true);
  1633. $state.go('sale.send_detail', {id: data.id});
  1634. }, function (response) {
  1635. $scope.loading = false;
  1636. toaster.pop('error', '错误', response.data);
  1637. });
  1638. }
  1639. }
  1640. $scope.setCheckedNoticeRead = function () {
  1641. var ids = [];
  1642. for (var i in $scope.notices) {
  1643. var item = $scope.notices[i];
  1644. if (item.id) {
  1645. ids.push(item.id);
  1646. }
  1647. }
  1648. PurcNotice.setRead({}, ids, function (message) {
  1649. });
  1650. }
  1651. };
  1652. }]);
  1653. app.controller('PersonalSaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1654. SaleStat.cust({}, function (data) {
  1655. var p = [], q = [];
  1656. angular.forEach(data.month, function (d) {
  1657. p.push({
  1658. x: (d.enterprise.enShortname || d.enterprise.enName),
  1659. y: [(d.total || 0)],
  1660. tooltip: (d.total || 0)
  1661. });
  1662. });
  1663. angular.forEach(data.year, function (d) {
  1664. q.push({
  1665. x: (d.enterprise.enShortname || d.enterprise.enName),
  1666. y: [(d.total || 0)],
  1667. tooltip: (d.total || 0)
  1668. });
  1669. });
  1670. $scope.custCharts = {
  1671. month: {
  1672. chartType: 'pie',
  1673. datas: {
  1674. data: p
  1675. },
  1676. config: {
  1677. labels: false,
  1678. title: "客户月采购量排行榜",
  1679. legend: {
  1680. display: true,
  1681. position: 'right'
  1682. },
  1683. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1684. click: function (d) {
  1685. },
  1686. mouseover: function (d) {
  1687. },
  1688. mouseout: function (d) {
  1689. },
  1690. innerRadius: 0,
  1691. lineLegend: 'lineEnd'
  1692. }
  1693. },
  1694. year: {
  1695. chartType: 'pie',
  1696. datas: {
  1697. data: q
  1698. },
  1699. config: {
  1700. labels: false,
  1701. title: "客户年采购量排行榜",
  1702. legend: {
  1703. display: true,
  1704. position: 'right'
  1705. },
  1706. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1707. click: function (d) {
  1708. },
  1709. mouseover: function (d) {
  1710. },
  1711. mouseout: function (d) {
  1712. },
  1713. innerRadius: 0,
  1714. lineLegend: 'lineEnd'
  1715. }
  1716. }
  1717. };
  1718. });
  1719. SaleStat.seller({}, function (data) {
  1720. var p = [], q = [];
  1721. angular.forEach(data.month, function (d) {
  1722. p.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1723. });
  1724. angular.forEach(data.year, function (d) {
  1725. q.push({x: d.seller.userName, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1726. });
  1727. $scope.sellerCharts = {
  1728. month: {
  1729. chartType: 'pie',
  1730. datas: {
  1731. data: p
  1732. },
  1733. config: {
  1734. labels: false,
  1735. title: "业务员月销量排行榜",
  1736. legend: {
  1737. display: true,
  1738. position: 'right'
  1739. },
  1740. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1741. click: function (d) {
  1742. },
  1743. mouseover: function (d) {
  1744. },
  1745. mouseout: function (d) {
  1746. },
  1747. innerRadius: 0,
  1748. lineLegend: 'lineEnd'
  1749. }
  1750. },
  1751. year: {
  1752. chartType: 'pie',
  1753. datas: {
  1754. data: q
  1755. },
  1756. config: {
  1757. labels: false,
  1758. title: "业务员年销量排行榜",
  1759. legend: {
  1760. display: true,
  1761. position: 'right'
  1762. },
  1763. colors: ['#4D9934', '#33D6EA', '#98E1CC', '#8060E4', '#9999CC'],
  1764. click: function (d) {
  1765. },
  1766. mouseover: function (d) {
  1767. },
  1768. mouseout: function (d) {
  1769. },
  1770. innerRadius: 0,
  1771. lineLegend: 'lineEnd'
  1772. }
  1773. }
  1774. };
  1775. });
  1776. }]);
  1777. app.controller('SaleStatCtrl', ['$scope', 'SaleStat', function ($scope, SaleStat) {
  1778. SaleStat.get({}, function (data) {
  1779. var p = [], q = [], r = [];
  1780. angular.forEach(data.day, function (d) {
  1781. p.push({x: d.day, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1782. });
  1783. angular.forEach(data.month, function (d) {
  1784. q.push({x: d.month, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1785. });
  1786. angular.forEach(data.year, function (d) {
  1787. r.push({x: d.year, y: [(d.total || 0)], tooltip: (d.total || 0)});
  1788. });
  1789. $scope.charts = {
  1790. day: {
  1791. chartType: "line",
  1792. datas: {
  1793. series: ['销售额'],
  1794. data: p
  1795. },
  1796. config: {
  1797. "labels": false,
  1798. "title": "销售额统计(近15日线)",
  1799. "legend": {
  1800. "display": true,
  1801. "position": "right"
  1802. },
  1803. colors: ['#4D9934'],
  1804. "innerRadius": 0,
  1805. "lineLegend": "lineEnd"
  1806. }
  1807. },
  1808. month: {
  1809. chartType: "line",
  1810. datas: {
  1811. series: ['销售额'],
  1812. data: q
  1813. },
  1814. config: {
  1815. "labels": false,
  1816. "title": "销售额统计(近12月线)",
  1817. "legend": {
  1818. "display": true,
  1819. "position": "right"
  1820. },
  1821. colors: ['#4D9934'],
  1822. "innerRadius": 0,
  1823. "lineLegend": "lineEnd"
  1824. }
  1825. },
  1826. year: {
  1827. chartType: "line",
  1828. datas: {
  1829. series: ['销售额'],
  1830. data: r
  1831. },
  1832. config: {
  1833. "labels": false,
  1834. "title": "销售额统计(近10年线)",
  1835. "legend": {
  1836. "display": true,
  1837. "position": "right"
  1838. },
  1839. colors: ['#4D9934'],
  1840. "innerRadius": 0,
  1841. "lineLegend": "lineEnd"
  1842. }
  1843. }
  1844. };
  1845. });
  1846. }]);
  1847. app.controller('NoticeCtrl', ['$scope', 'SnapshotService', 'AuthenticationService', function ($scope, SnapshotService, AuthenticationService) {
  1848. AuthenticationService.getAuthentication().success(function (data) {
  1849. $scope.loading = false;
  1850. $scope.useruu = data.userUU;
  1851. SnapshotService.getNotice(7, $scope.useruu, function (data) { //5表示首页显示的公告条数
  1852. $scope.notices = data;
  1853. });
  1854. /**
  1855. * 设置单据阅读状态
  1856. * @param id
  1857. */
  1858. $scope.setReadStatus = function(id) {
  1859. SnapshotService.setNoticeStatusAfterRead(id, $scope.useruu);
  1860. }
  1861. /**
  1862. * 判断是否当天时间
  1863. * @param date
  1864. * @param time
  1865. * @returns {boolean}
  1866. */
  1867. $scope.isCurrentTime = function(date, time) {
  1868. var date1 = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
  1869. var date2 = new Date(time).getFullYear() + '-' + new Date(time).getMonth() + 1 + '-' + new Date(time).getDate();
  1870. return date1 == date2;
  1871. }
  1872. });
  1873. $scope.dateTime = new Date();
  1874. $scope.time = new Date().getTime();
  1875. }]);
  1876. app.controller('TenderCtrl', ['$scope', 'SnapshotService', function ($scope, SnapshotService) {
  1877. SnapshotService.getOpenTender(5, function (data) {
  1878. $scope.openTenders = data;
  1879. var newDate = new Date();
  1880. newDate = newDate.getTime() - 3 * 24 * 60 * 60 * 1000;
  1881. angular.forEach($scope.openTenders, function (tender) {
  1882. if (tender.date - newDate > 0) {
  1883. tender.isNew = true;
  1884. } else {
  1885. tender.isNew = false;
  1886. }
  1887. });
  1888. });
  1889. $scope.dateTime = new Date();
  1890. }]);
  1891. app.controller('VendCountCtrl', ['$scope', 'VendorService', function ($scope, VendorService) {
  1892. VendorService.getCount(function (date) {
  1893. $scope.count = date;
  1894. });
  1895. }]);
  1896. // 客户
  1897. app.controller('CustomerCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  1898. BaseService.scrollBackToTop();
  1899. $scope.userInfoResult = true;
  1900. AuthenticationService.getAuthentication().success(function (data) {
  1901. $scope.loading = false;
  1902. $scope.thisUser = data;
  1903. });
  1904. // 获取当前用户分配客户的操作权限
  1905. CurrentRole.roles({}, function (data) {
  1906. // 存在权限或者user表sys字段为1时
  1907. $scope.enabled = data.count > 0 || $scope.thisUser.sys;
  1908. }, function (response) {
  1909. });
  1910. var getCustInfos = function (custuu) {
  1911. if (custuu) {
  1912. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  1913. $scope.custInfos = data;
  1914. var getPage = function (page, size) {
  1915. if ($scope.custInfos) {
  1916. var result = {};
  1917. result.totalCount = $scope.custInfos.length;
  1918. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  1919. if ($scope.custInfos.length % size == 0) {
  1920. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  1921. } else {
  1922. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  1923. }
  1924. result.first = page == 1;
  1925. result.last = page == result.totalPage;
  1926. result.page = page;
  1927. result.next = page - 0 + 1;
  1928. result.pre = page - 1;
  1929. return result;
  1930. }
  1931. }
  1932. $scope.userdata = getPage(1, 4);
  1933. $scope.first = function () {
  1934. $scope.userdata = getPage($scope.userdata.pre, 4);
  1935. }
  1936. $scope.last = function () {
  1937. $scope.userdata = getPage($scope.userdata.next, 4);
  1938. }
  1939. }, function (response) {
  1940. $scope.loading = false;
  1941. toaster.pop('error', '数据加载失败', response.data);
  1942. });
  1943. }
  1944. }
  1945. // 分配用户
  1946. $scope.addUserInfo = function (customer) {
  1947. if (!$scope.enabled) {
  1948. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  1949. return;
  1950. }
  1951. // 获取当前用户在当前企业是否被转移权限
  1952. AccountUser.getEnTransfer ({custUU: customer.myEnterprise.uu}, function(data) {
  1953. customer.enTransfer = data.result;
  1954. //是管理员,或者被转移了权限时
  1955. if ($scope.enabled || customer.enTransfer) {
  1956. var modalInstance = $modal.open({
  1957. animation: true,
  1958. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  1959. controller: 'AddUserInfoCtrl',
  1960. resolve: {
  1961. customer: function () {
  1962. return customer;
  1963. }
  1964. }
  1965. });
  1966. modalInstance.result.then(function (changed, checked) {
  1967. if (changed) {
  1968. if (checked)
  1969. $scope.newUser.roles = checked;
  1970. else
  1971. loadUsers();
  1972. }
  1973. });
  1974. } else {
  1975. toaster.pop('error', '您没有为当前客户分配用户的权限!');
  1976. }
  1977. });
  1978. };
  1979. // 转移权限
  1980. $scope.transferUserInfo = function (customer) {
  1981. customer.enDistribute = null;
  1982. if (!$scope.enabled) {
  1983. toaster.pop('error', '您没有转移当前客户权限的权限!');
  1984. return;
  1985. }
  1986. // 获取当前用户在当前企业是否被转移权限
  1987. AccountUser.getDistribute ({custUU: customer.myEnterprise.uu}, function(data) {
  1988. customer.enDistribute = data.result;
  1989. //是管理员,或者被分配时
  1990. if ($scope.enabled || customer.enDistribute) {
  1991. var modalInstance = $modal.open({
  1992. animation: true,
  1993. templateUrl: 'static/tpl/index/account/transfer_userInfo.html',
  1994. controller: 'TransferUserInfoCtrl',
  1995. resolve: {
  1996. customer: function () {
  1997. return customer;
  1998. }
  1999. }
  2000. });
  2001. modalInstance.result.then(function (changed, checked) {
  2002. if (changed) {
  2003. if (checked)
  2004. $scope.newUser.roles = checked;
  2005. else
  2006. loadUsers();
  2007. }
  2008. });
  2009. } else {
  2010. toaster.pop('error', '您没有转移当前客户权限的权限!');
  2011. }
  2012. });
  2013. };
  2014. $scope.showUserInfo = function (customer, boo) {
  2015. $scope.custInfo = customer;
  2016. if (boo) {
  2017. getCustInfos(customer.myEnterprise.uu);
  2018. $scope.userInfoResult = true;
  2019. }
  2020. };
  2021. var getService = function () {
  2022. return VendorService;
  2023. };
  2024. $scope.customerParams = new ngTableParams({
  2025. page: 1,
  2026. count: 20
  2027. }, {
  2028. total: 0,
  2029. counts: [5, 10, 25, 50],
  2030. getData: function ($defer, params) {
  2031. $scope.loading = true;
  2032. var pageParams = params.url();
  2033. pageParams.keyword = $scope.keyword;
  2034. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  2035. $scope.loading = false;
  2036. if (page) {
  2037. params.total(page.totalElement);
  2038. $defer.resolve(page.content);
  2039. $scope.keywordXls = pageParams.keyword;
  2040. }
  2041. $scope.totalCount = page.totalElement;
  2042. }, function (response) {
  2043. $scope.loading = false;
  2044. toaster.pop('error', '数据加载失败', response.data);
  2045. });
  2046. }
  2047. });
  2048. //设置消息已读
  2049. var setOrdersRead = function () {
  2050. var sourceId = [];
  2051. Vendor.setRead({}, sourceId, function (message) {
  2052. // $scope.getUnreadIds();
  2053. });
  2054. };
  2055. setOrdersRead();
  2056. // 搜索框回车
  2057. $scope.onSearch = function (keyword) {
  2058. $scope.customerParams.page(1);
  2059. $scope.customerParams.reload();
  2060. $scope.tip = keyword;
  2061. };
  2062. // 查看详情
  2063. $scope.viewDetail = function (id) {
  2064. window.location.hash = "#/sale/customer/" + id;
  2065. }
  2066. // 导出客户资料列表
  2067. $scope.exportXls = function () {
  2068. VendorService.exportXls.get({}, {}, function (data) {
  2069. if (data.success){
  2070. window.location.href = 'vendor/customer/xls?keyword='+ ($scope.keywordXls || '');
  2071. }
  2072. }, function (response) {
  2073. toaster.pop('error', '数据加载失败', response.data);
  2074. });
  2075. }
  2076. }]);
  2077. // 客户详情
  2078. 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) {
  2079. BaseService.scrollBackToTop();
  2080. $scope.userInfoResult = true;
  2081. AuthenticationService.getAuthentication().success(function (data) {
  2082. $scope.loading = false;
  2083. $scope.thisUser = data;
  2084. });
  2085. $scope.vendorContacts = [];
  2086. var loadData = function () {
  2087. Vendor.getCustomerDetail({id: $stateParams.id}, {}, function (data) {
  2088. $scope.customer = data.myEnterprise;
  2089. $scope.customerInfo = data;
  2090. Vendor.custContacts({enuu: $scope.customer.uu}, {}, function (data) {
  2091. $scope.Contacts = data;
  2092. });
  2093. // 查看已分配人员
  2094. VendorService.userInfo.query({uu: $scope.customer.uu}, null, function (data) {
  2095. $scope.custInfos = data;
  2096. var getPage = function (page, size) {
  2097. if ($scope.custInfos) {
  2098. var result = {};
  2099. result.totalCount = $scope.custInfos.length;
  2100. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  2101. if ($scope.custInfos.length % size == 0) {
  2102. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  2103. } else {
  2104. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  2105. }
  2106. result.first = page == 1;
  2107. result.last = page == result.totalPage;
  2108. result.page = page;
  2109. result.next = page - 0 + 1;
  2110. result.pre = page - 1;
  2111. return result;
  2112. }
  2113. }
  2114. $scope.userdata = getPage(1, 4);
  2115. $scope.first = function () {
  2116. $scope.userdata = getPage($scope.userdata.pre, 4);
  2117. }
  2118. $scope.last = function () {
  2119. $scope.userdata = getPage($scope.userdata.next, 4);
  2120. }
  2121. }, function (response) {
  2122. $scope.loading = false;
  2123. toaster.pop('error', '数据加载失败', response.data);
  2124. });
  2125. }, function (response) {
  2126. $scope.loading = false;
  2127. toaster.pop('error', '数据加载失败', response.data);
  2128. });
  2129. };
  2130. loadData();
  2131. // 新增客户联系人
  2132. $scope.addContact = function (uu) {
  2133. var modalInstance = $modal.open({
  2134. animation: true,
  2135. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2136. controller: 'AddContacCtrl',
  2137. resolve: {}
  2138. });
  2139. modalInstance.result.then(function (data) {
  2140. $scope.contact = data;
  2141. $scope.contact.myenuu = uu;
  2142. Vendor.saveCustContact({}, $scope.contact, function (data) {
  2143. toaster.pop('success', '提示', '联系人保存成功');
  2144. $scope.Contacts.push(data);
  2145. }, function (response) {
  2146. toaster.pop('error', '失败', response.data);
  2147. });
  2148. });
  2149. }
  2150. // 编辑客户联系人
  2151. $scope.edit = function (contact) {
  2152. var modalInstance = $modal.open({
  2153. animation: true,
  2154. templateUrl: 'static/tpl/index/sale/contact_person_modal.html',
  2155. controller: 'EditContacCtrl',
  2156. resolve: {
  2157. contact: function () {
  2158. return contact;
  2159. }
  2160. }
  2161. });
  2162. modalInstance.result.then(function (data) {
  2163. Vendor.saveContact({}, data, function (data) {
  2164. loadData();
  2165. toaster.pop('success', '提示', '联系人修改成功');
  2166. }, function (response) {
  2167. toaster.pop('error', '失败', response.data);
  2168. });
  2169. });
  2170. }
  2171. // 删除客户联系人
  2172. $scope.deleteById = function (id, index) {
  2173. $scope.Contacts.splice(index, 1);
  2174. Vendor.deleteContact({id: id}, {}, function (data) {
  2175. toaster.pop('success', '提示', '客户联系人删除成功');
  2176. loadData();
  2177. }, function (response) {
  2178. toaster.pop('error', '提示', response.data);
  2179. });
  2180. }
  2181. // 供应商物料信息
  2182. $scope.viewProdList = function (uu) {
  2183. $scope.uu = uu;
  2184. $scope.tableParams.page(1);
  2185. $scope.tableParams.reload();
  2186. };
  2187. // 搜索框回车
  2188. $scope.onSearch = function (keyword) {
  2189. $scope.keyword = keyword;
  2190. $scope.tableParams.page(1);
  2191. $scope.tableParams.reload();
  2192. };
  2193. // 供应商物料信息
  2194. $scope.tableParams = new ngTableParams({
  2195. page: 1,
  2196. count: 20
  2197. }, {
  2198. total: 0,
  2199. counts: [5, 10, 25, 50],
  2200. getData: function ($defer, params) {
  2201. $scope.loading = true;
  2202. var pageParams = params.url();
  2203. pageParams.custUU = $scope.uu;
  2204. pageParams.keyword = $scope.keyword;
  2205. $scope.tip = $scope.keyword;
  2206. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  2207. $scope.loading = false;
  2208. if (page) {
  2209. params.total(page.totalElement);
  2210. $scope.total = page.totalElement;
  2211. $defer.resolve(page.content);
  2212. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  2213. }
  2214. }, function (response) {
  2215. $scope.loading = false;
  2216. toaster.pop('error', '数据加载失败', response.data);
  2217. });
  2218. }
  2219. });
  2220. $scope.addUserInfo = function () {
  2221. //TODO
  2222. if ($scope.thisUser.sys) {
  2223. var modalInstance = $modal.open({
  2224. animation: true,
  2225. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  2226. controller: 'AddUserInfoCtrl',
  2227. resolve: {
  2228. customer: function () {
  2229. return $scope.customerInfo;
  2230. }
  2231. }
  2232. });
  2233. modalInstance.result.then(function (changed, checked) {
  2234. loadData();
  2235. if (changed) {
  2236. if (checked) {
  2237. $scope.newUser.roles = checked;
  2238. } else {
  2239. loadUsers();
  2240. }
  2241. }
  2242. });
  2243. } else {
  2244. toaster.pop('error', '您不是管理员,无权限分配用户!');
  2245. }
  2246. }
  2247. $scope.Quotation = function (uu, id) {
  2248. $rootScope.custuu = uu;
  2249. $rootScope.prodId = id;
  2250. window.location.hash = "#/sale/quotation/new";
  2251. }
  2252. }]);
  2253. app.controller('AddUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', function ($scope, $modalInstance, customer, AccountUser, toaster) {
  2254. $scope.checkboxes = {
  2255. checked: false
  2256. };
  2257. $scope.loading = true;
  2258. $scope.distribute = [];
  2259. AccountUser.findUsers({uu: customer.myEnterprise.uu}, null, function (data) {
  2260. $scope.userinfos = data;
  2261. var distribute = [];
  2262. angular.forEach($scope.userinfos, function (user, index) {
  2263. if (user.distribute) {
  2264. distribute.push({num: index});
  2265. }
  2266. });
  2267. $scope.distribute = distribute;
  2268. $scope.havedone = angular.copy($scope.distribute);
  2269. $scope.loading = false;
  2270. })
  2271. var checkStatus = function (userinfos) {
  2272. var distribute = [];
  2273. angular.forEach(userinfos, function (user, index) {
  2274. if (user.distribute) {
  2275. distribute.push({num: index});
  2276. }
  2277. });
  2278. $scope.distribute = distribute;
  2279. $scope.isChanged = !angular.equals($scope.havedone, $scope.distribute);
  2280. }
  2281. $scope.isChanged = false;
  2282. $scope.isChangedAll = false;
  2283. $scope.changes = [];
  2284. // 点击勾选全部的复选框
  2285. $scope.checkAll = function () {
  2286. angular.forEach($scope.userinfos, function (item, index) {
  2287. item.distribute = $scope.checkboxes.checked;
  2288. });
  2289. checkStatus($scope.userinfos);
  2290. };
  2291. // 点击其中一个明细的复选框
  2292. $scope.checkOne = function () {
  2293. var result = true;
  2294. angular.forEach($scope.userinfos, function (item) {
  2295. if (item.distribute != true) {
  2296. result = false;
  2297. return;
  2298. }
  2299. });
  2300. $scope.checkboxes.checked = result;
  2301. checkStatus($scope.userinfos);
  2302. };
  2303. $scope.close = function (save) {
  2304. var chooseResult = [];
  2305. if (save) {
  2306. if (customer.myEnterprise.uu) {
  2307. angular.forEach($scope.userinfos, function (item, i) {
  2308. chooseResult.push(item);
  2309. });
  2310. if (chooseResult.length > 0) {
  2311. $scope.loading = true;
  2312. AccountUser.addUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2313. $scope.loading = false;
  2314. toaster.pop('success', '提示', '保存成功');
  2315. $modalInstance.close(false);
  2316. }, function (response) {
  2317. $scope.loading = false;
  2318. toaster.pop('error', '保存失败', response.data);
  2319. $modalInstance.close(false);
  2320. })
  2321. } else {
  2322. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2323. }
  2324. } else {
  2325. $modalInstance.close(true, $scope.checkboxes.checked);
  2326. }
  2327. } else {
  2328. $modalInstance.close(false);
  2329. }
  2330. };
  2331. }]);
  2332. // 转移权限
  2333. app.controller('TransferUserInfoCtrl', ['$scope', '$modalInstance', 'customer', 'AccountUser', 'toaster', 'AuthenticationService', function ($scope, $modalInstance, customer, AccountUser, toaster, AuthenticationService) {
  2334. AuthenticationService.getAuthentication().success(function (data) {
  2335. $scope.loading = false;
  2336. $scope.thisUser = data;
  2337. });
  2338. $scope.checkboxes = {
  2339. checked: false
  2340. };
  2341. $scope.loading = true;
  2342. $scope.transfer = [];
  2343. AccountUser.findUsers({uu: customer.myEnterprise.uu}, {}, function (data) {
  2344. $scope.userinfos = data;
  2345. var transfer = [];
  2346. angular.forEach($scope.userinfos, function (user, index) {
  2347. // 当前用户是被管理员转移权限时,转移的是被管理员转移的权限。
  2348. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2349. $scope.thisUser.transfer = true;
  2350. }
  2351. });
  2352. angular.forEach($scope.userinfos, function (user, index) {
  2353. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2354. if (user.transfer) {
  2355. transfer.push({num: index});
  2356. user.checked = true;
  2357. }
  2358. } else {
  2359. if (user.distribute) {
  2360. transfer.push({num: index});
  2361. user.checked = true;
  2362. }
  2363. }
  2364. });
  2365. $scope.transfer = transfer;
  2366. $scope.havedone = angular.copy($scope.transfer);
  2367. $scope.loading = false;
  2368. });
  2369. var checkStatus = function (userinfos) {
  2370. var transfer = [];
  2371. angular.forEach(userinfos, function (user, index) {
  2372. if ($scope.thisUser.sys || $scope.thisUser.transfer) {
  2373. if (user.transfer) {
  2374. transfer.push({num: index});
  2375. }
  2376. } else {
  2377. if (user.distribute) {
  2378. transfer.push({num: index});
  2379. }
  2380. }
  2381. });
  2382. $scope.transfer = transfer;
  2383. $scope.isChanged = !angular.equals($scope.havedone, $scope.transfer);
  2384. };
  2385. $scope.isChanged = false;
  2386. $scope.isChangedAll = false;
  2387. $scope.changes = [];
  2388. // 点击其中一个明细的复选框
  2389. $scope.checkOne = function (user) {
  2390. $scope.changes = [];
  2391. if ($scope.thisUser.sys) { // 管理员操作
  2392. user.$checked = !user.$checked;
  2393. angular.forEach($scope.userinfos, function (userInfo) {
  2394. if ($scope.thisUser.userUU === user.userUU && user.transfer) {
  2395. $scope.thisUser.transfer = true;
  2396. }
  2397. if (user.userUU !== userInfo.userUU) {
  2398. userInfo.transfer = false;
  2399. }
  2400. });
  2401. } else if ($scope.thisUser.transfer) { // 被管理员转移权限的非管理员操作
  2402. user.$checked = !user.$checked;
  2403. angular.forEach($scope.userinfos, function (userInfo) {
  2404. if (user.userUU !== userInfo.userUU) {
  2405. userInfo.transfer = false;
  2406. } else {
  2407. userInfo.transfer = true;
  2408. }
  2409. });
  2410. } else { // 被分配客户的用户
  2411. user.$checked = !user.$checked;
  2412. angular.forEach($scope.userinfos, function (userInfo) {
  2413. if (user.userUU !== userInfo.userUU) {
  2414. userInfo.distribute = false;
  2415. } else {
  2416. userInfo.distribute = true;
  2417. }
  2418. });
  2419. }
  2420. checkStatus($scope.userinfos);
  2421. };
  2422. $scope.close = function (save) {
  2423. var chooseResult = [];
  2424. if (save) {
  2425. if (customer.myEnterprise.uu) {
  2426. // 当前用户是管理员时
  2427. if ($scope.thisUser.sys) {
  2428. angular.forEach($scope.userinfos, function (item, i) {
  2429. chooseResult.push(item);
  2430. });
  2431. if (chooseResult.length > 0) {
  2432. $scope.loading = true;
  2433. AccountUser.transferUserToVendor({uu: customer.myEnterprise.uu}, chooseResult, function (data) {
  2434. $scope.loading = false;
  2435. toaster.pop('success', '提示', '保存成功');
  2436. $modalInstance.close(false);
  2437. }, function (response) {
  2438. $scope.loading = false;
  2439. toaster.pop('error', '保存失败', response.data);
  2440. $modalInstance.close(false);
  2441. })
  2442. } else {
  2443. toaster.pop('error', '保存失败', "您未勾选任何记录");
  2444. }
  2445. } else {
  2446. // 非管理员转移自己的权限时
  2447. angular.forEach($scope.userinfos, function (item, i) {
  2448. if (item.transfer && item.userUU !== $scope.thisUser.userUU) {
  2449. $scope.target = item;
  2450. }
  2451. });
  2452. if (!$scope.target) {
  2453. toaster.pop('error', '保存失败', "您未选择权限转移对象");
  2454. } else {
  2455. $scope.loading = true;
  2456. AccountUser.transferMyDistribute({custUU: customer.myEnterprise.uu, userUU: $scope.target.userUU}, {} ,function (data) {
  2457. $scope.loading = false;
  2458. toaster.pop('success', '提示', '保存成功');
  2459. $modalInstance.close(false);
  2460. }, function (response) {
  2461. $scope.loading = false;
  2462. toaster.pop('error', '保存失败', response.data);
  2463. $modalInstance.close(false);
  2464. });
  2465. }
  2466. }
  2467. } else {
  2468. $modalInstance.close(true, $scope.checkboxes.checked);
  2469. }
  2470. } else {
  2471. $modalInstance.close(false);
  2472. }
  2473. };
  2474. }]);
  2475. /**
  2476. * 页面状态按钮过滤
  2477. */
  2478. var getState = function (active) {
  2479. var fn = 'get';
  2480. switch (active) {
  2481. case 'done':
  2482. fn = 'getDone';
  2483. break;
  2484. case 'todo':
  2485. fn = 'getTodo';
  2486. break;
  2487. case 'end':
  2488. fn = 'getEnd';
  2489. break;
  2490. case 'waiting':
  2491. fn = 'getWaiting';
  2492. break;
  2493. case 'received':
  2494. fn = 'getReceived';
  2495. break;
  2496. case 'invalid':
  2497. fn = 'getInvalid';
  2498. break;
  2499. // 已采纳
  2500. case 'agreed':
  2501. fn = 'getAgreed';
  2502. break;
  2503. // 未采纳
  2504. case 'refused':
  2505. fn = 'getRefused';
  2506. break;
  2507. // 个人
  2508. case 'personal':
  2509. fn = 'getPersonal';
  2510. break;
  2511. // 集体
  2512. case 'teams':
  2513. fn = 'getTeams';
  2514. break;
  2515. // 非标准
  2516. case 'nonstandard':
  2517. fn = 'getNonstandard';
  2518. break;
  2519. // 标准
  2520. case 'standard':
  2521. fn = 'getStandard';
  2522. break;
  2523. // 变更单无需确认
  2524. case 'unread':
  2525. fn = 'getUnread';
  2526. break;
  2527. }
  2528. return fn;
  2529. };
  2530. /**
  2531. * 改变单据日期范围
  2532. */
  2533. var getDateCondition = function (zone, condition) {
  2534. var fromDate = new Date();
  2535. var toDate = new Date();
  2536. //去除时分秒限制,dateFrom设置成0时0分0秒,dateTo设置成23时59分59秒
  2537. fromDate.setHours(0, 0, 0, 0);
  2538. toDate.setHours(23, 59, 59, 999);
  2539. if (zone == -1) { // 自定义时间,什么都不做
  2540. } else if (zone == 1) {
  2541. fromDate.setMonth(fromDate.getMonth() - 1);
  2542. condition.dateFrom = fromDate;
  2543. condition.dateTo = toDate;
  2544. } else if (zone == 3) {
  2545. fromDate.setMonth(fromDate.getMonth() - 3);
  2546. condition.dateFrom = fromDate;
  2547. condition.dateTo = toDate;
  2548. } else if (zone == 6) {
  2549. fromDate.setMonth(fromDate.getMonth() - 6);
  2550. condition.dateFrom = fromDate;
  2551. condition.dateTo = toDate;
  2552. } else {
  2553. condition.dateFrom = null;
  2554. condition.dateTo = null;
  2555. }
  2556. };
  2557. /**
  2558. * 改变单据交货日期范围
  2559. */
  2560. var getDelveryCondition = function (zone, condition) {
  2561. var date = new Date();
  2562. if (zone == -1) {
  2563. condition.deliveryFrom = null;
  2564. condition.deliveryTo = null;
  2565. } else if (zone == 1) {
  2566. date.setMonth(date.getMonth() + 1);
  2567. condition.deliveryTo = date;
  2568. condition.deliveryFrom = new Date();
  2569. } else if (zone == 2) {
  2570. date.setMonth(date.getMonth() + 2);
  2571. condition.deliveryTo = date;
  2572. condition.deliveryFrom = new Date();
  2573. }
  2574. };
  2575. /**
  2576. * 将日期转化为整数日期
  2577. */
  2578. var getDateTime = function (date) {
  2579. if (angular.isDate(date)) {
  2580. return date.getTime();
  2581. } else {
  2582. return null;
  2583. }
  2584. };
  2585. /**
  2586. * 删除数组里某个特定的值
  2587. */
  2588. var removeByValue = function (arr, val) {
  2589. for(var i=0; i<arr.length; i++) {
  2590. if(arr[i] == val) {
  2591. arr.splice(i, 1);
  2592. break;
  2593. }
  2594. }
  2595. };
  2596. app.controller('PurcOrderCtrl', ['$scope', '$filter', 'PurcOrders', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', '$rootScope', 'PurchaseOrder', 'PurcOrdersInfo', 'PurcOrderItem', 'CurrentRole',
  2597. function ($scope, $filter, PurcOrders, PurcOrder, ngTableParams, toaster, ReportService, BaseService, $rootScope, PurchaseOrder, PurcOrdersInfo, PurcOrderItem, CurrentRole) {
  2598. BaseService.scrollBackToTop();
  2599. // 获取当前用户是否为普通用户
  2600. CurrentRole.isUser({}, {}, function (data) {
  2601. $scope.isUser = data.isUser;
  2602. });
  2603. if ($rootScope.active) {
  2604. $scope.active = $rootScope.active;
  2605. $rootScope.active = null;
  2606. } else {
  2607. $scope.active = 'all';
  2608. }
  2609. $scope.dateZoneText = '不限';
  2610. $scope.deliveryZoneText = '不限';
  2611. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2612. /* 时间筛选初始化*/
  2613. var fromDate = new Date();
  2614. var toDate = new Date();
  2615. fromDate.setMonth(fromDate.getMonth() - 1);
  2616. fromDate.setHours(0, 0, 0, 0);
  2617. toDate.setHours(23, 59, 59, 999);
  2618. $scope.condition.dateFrom = fromDate;
  2619. $scope.condition.dateTo = toDate;
  2620. $scope.changeDateZone = function (zone) {
  2621. $scope.condition.dateZone = zone;
  2622. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2623. $scope.condition.$dateZoneOpen = false;
  2624. getDateCondition(zone, $scope.condition);
  2625. $scope.tableParams.page(1);
  2626. $scope.tableParams.reload();
  2627. };
  2628. $scope.changeDeliveryZone = function (zone) {
  2629. $scope.condition.deliveryZoneText = zone;
  2630. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2631. $scope.condition.$delievryZoneOpen = false;
  2632. getDelveryCondition(zone, $scope.condition);
  2633. $scope.tableParams.reload();
  2634. };
  2635. $scope.searchMethod = false;
  2636. var getService = function () {
  2637. return $scope.searchMethod ? PurcOrders : PurcOrdersInfo;
  2638. };
  2639. // 切换单据类型
  2640. $scope.setActive = function (state) {
  2641. if ($scope.active != state) {
  2642. $scope.active = state;
  2643. if ($scope.tableParams.page() == 1)
  2644. $scope.tableParams.reload();
  2645. else
  2646. $scope.tableParams.page(1);
  2647. }
  2648. };
  2649. var getPurcStatus = function (active) {
  2650. var fn = 'getPurcAll';
  2651. switch (active) {
  2652. case 'done':
  2653. fn = 'getPurcDone';
  2654. break;
  2655. case 'todo':
  2656. fn = 'getPurcTodo';
  2657. break;
  2658. case 'end':
  2659. fn = 'getPurcEnd';
  2660. break;
  2661. case 'waiting':
  2662. fn = 'getPurcWaiting';
  2663. break;
  2664. }
  2665. return fn;
  2666. };
  2667. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2668. page: 1,
  2669. count: 20,
  2670. sorting: {
  2671. display: 'desc',
  2672. date: 'desc'
  2673. }
  2674. }, {
  2675. total: 0,
  2676. counts: [5, 10, 15, 25, 50],
  2677. getData: function ($defer, params) {// 获取数据的方法
  2678. $scope.loading = true;
  2679. var pageParams = params.url();
  2680. pageParams.searchFilter = { // 筛选条件
  2681. keyword: $scope.keyword,
  2682. fromDate: getDateTime($scope.condition.dateFrom),
  2683. endDate: getDateTime($scope.condition.dateTo)
  2684. };
  2685. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2686. $scope.loading = false;
  2687. if (page) {
  2688. $defer.resolve(page.content);
  2689. $scope.total = page.totalElement;
  2690. params.total(page.totalElement);
  2691. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2692. }
  2693. }, function (response) {
  2694. $scope.loading = false;
  2695. toaster.pop('error', '数据加载失败', response.data);
  2696. });
  2697. }
  2698. });
  2699. //获得各分类未阅读数量
  2700. var getUnreadCount = function () {
  2701. PurcOrders.getUnreadCount(null, function (data) {
  2702. $scope.unread = data;
  2703. });
  2704. };
  2705. getUnreadCount();
  2706. //设置单据已读
  2707. $scope.setOrdersRead = function (id) {
  2708. // 如果单据本身已读,则不发送请求修改数据
  2709. if (!$scope.isUnread(id)){
  2710. return;
  2711. }
  2712. var sourceId = [];
  2713. sourceId.push(id);
  2714. PurcOrders.setRead({}, sourceId, function (message) {
  2715. // $scope.getUnreadIds();
  2716. getUnreadCount();
  2717. });
  2718. };
  2719. //获取未读单据id
  2720. var getUnreadIds = function () {
  2721. PurcOrders.getUnreadIds({}, "", function (message) {
  2722. $scope.unreadCode = message.content;
  2723. });
  2724. };
  2725. getUnreadIds();
  2726. //判断单据是否未读
  2727. $scope.isUnread = function (id) {
  2728. for (var i in $scope.unreadCode) {
  2729. if (id == $scope.unreadCode[i]) {
  2730. return true;
  2731. }
  2732. }
  2733. };
  2734. $scope.getReply = function (item) {
  2735. if (!item.replies) {
  2736. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2737. item.replies = replies;
  2738. });
  2739. }
  2740. };
  2741. $scope.getOrderTotal = function (items) {
  2742. var sum = 0;
  2743. angular.forEach(items, function (item) {
  2744. sum += item.qty * item.price;
  2745. });
  2746. return sum;
  2747. };
  2748. // 需方 打印 采购单
  2749. $scope.custPrint = function (order) {
  2750. var newPage = window.open("about:blank");
  2751. PurcOrder.printPermission({}, function () {
  2752. PurcOrder.custPrintCount({id: order.id}, {});//增加打印此次
  2753. ReportService.print(order.enUU, 'PURCLIST_CUST', "where purc$orders.pu_id=" + order.id, newPage);
  2754. }, function (response) {
  2755. newPage.close();
  2756. toaster.pop('error', '打印失败', response.data);
  2757. });
  2758. };
  2759. $scope.openDatePicker = function ($event, item, openParam) {
  2760. $event.preventDefault();
  2761. $event.stopPropagation();
  2762. item[openParam] = !item[openParam];
  2763. };
  2764. $scope.openFilterDatePicker = function ($event, item, openParam) {
  2765. $event.preventDefault();
  2766. $event.stopPropagation();
  2767. item[openParam] = !item[openParam];
  2768. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  2769. $scope.tableParams.reload();
  2770. }
  2771. };
  2772. $scope.parseDate = function (dateStr) {
  2773. if (dateStr)
  2774. return Date.parse(dateStr, 'yyyy-MM-dd');
  2775. return new Date();
  2776. };
  2777. $scope.checkboxes = {
  2778. checked: false
  2779. };
  2780. // 点击勾选全部的复选框
  2781. $scope.checkAll = function () {
  2782. angular.forEach($scope.tableParams.data, function (item) {
  2783. item.$selected = $scope.checkboxes.checked;
  2784. });
  2785. };
  2786. // 点击其中一个明细的复选框
  2787. $scope.checkOne = function (order) {
  2788. var result = true;
  2789. angular.forEach($scope.tableParams.data, function (item) {
  2790. if (item.$selected != true) {
  2791. result = false;
  2792. return;
  2793. }
  2794. });
  2795. $scope.checkboxes.checked = result;
  2796. };
  2797. // 搜索框回车
  2798. $scope.onSearch = function (keyword) {
  2799. // 每次搜索重置获取数据方法
  2800. $scope.searchMethod = false;
  2801. if(keyword != null && keyword != '') {
  2802. $scope.searchMethod = true;
  2803. }
  2804. $scope.tableParams.page(1);
  2805. $scope.tableParams.reload();
  2806. $scope.tip = keyword;
  2807. };
  2808. // 选择查找日期
  2809. $scope.onDateCondition = function () {
  2810. $scope.tableParams.page(1);
  2811. $scope.tableParams.reload();
  2812. };
  2813. // 复制订单
  2814. $scope.copyorder = function (id) {
  2815. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  2816. if (data.id) {
  2817. toaster.pop('success', '提示', '单据复制成功');
  2818. window.location.hash = "#purc/cart/" + data.id;
  2819. }
  2820. }, function (response) {
  2821. toaster.pop('error', '提示', response.data);
  2822. });
  2823. }
  2824. // 导出
  2825. $scope.exportXls = function () {
  2826. PurcOrders.exportXls({}, {}, function (data) {
  2827. if (data.success){
  2828. window.location.href = 'sale/orders/purc/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  2829. }
  2830. }, function (response) {
  2831. toaster.pop('error', '数据加载失败', response.data);
  2832. });
  2833. }
  2834. }]);
  2835. app.controller('PurcOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'PurcOrdersInfo', 'CurrentRole', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, PurcOrdersInfo, CurrentRole) {
  2836. // 获取当前用户是否为普通用户
  2837. CurrentRole.isUser({}, {}, function (data) {
  2838. $scope.isUser = data.isUser;
  2839. });
  2840. var loadData = function () {
  2841. $scope.loading = true;
  2842. PurcOrdersInfo.getAll({id: $stateParams.id},{}, function (data) {
  2843. $scope.order = data;
  2844. var sum = 0;
  2845. angular.forEach($scope.order.orderItems, function (item) {
  2846. sum += item.qty * item.price;
  2847. });
  2848. $scope.order.total = sum;
  2849. // if($scope.order.display == 1) {//未查看的设为已查看
  2850. // $scope.setDisplay('setRead', $scope.order.id);
  2851. // }
  2852. //$scope.loading = false;
  2853. }, function (response) {
  2854. toaster.pop('error', '提示', response.data);
  2855. });
  2856. };
  2857. loadData();
  2858. $scope.getReply = function (item) {
  2859. if (!item.replies) {
  2860. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  2861. item.replies = replies;
  2862. });
  2863. }
  2864. };
  2865. $scope.openDatePicker = function ($event, item, openParam) {
  2866. $event.preventDefault();
  2867. $event.stopPropagation();
  2868. item[openParam] = !item[openParam];
  2869. };
  2870. $scope.onReplyClick = function (item, inverse) {
  2871. if (item.reply) {
  2872. if (!item.reply.qty || item.reply.qty < 0 || item.reply.qty > item.qty) {
  2873. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  2874. return;
  2875. }
  2876. var reply = angular.copy(item.reply);
  2877. if (reply.delivery) {
  2878. if (typeof reply.delivery == 'object')
  2879. reply.delivery = reply.delivery.getTime();
  2880. } else {
  2881. reply.delivery = item.delivery;
  2882. }
  2883. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  2884. $scope.loading = true;
  2885. PurcOrderItem.reply({orderItemId: item.id}, reply, function () {
  2886. $scope.loading = false;
  2887. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  2888. loadData();
  2889. }, function (response) {
  2890. $scope.loading = false;
  2891. toaster.pop('error', '回复失败', response.data);
  2892. });
  2893. }
  2894. };
  2895. //设置为已查看
  2896. $scope.setDisplay = function (state, orderId) {
  2897. if (orderId) {//设置单个
  2898. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  2899. // $scope.tableParams.reload();
  2900. }, function () {
  2901. toaster.pop('error', '错误', "设置失败");
  2902. });
  2903. } else {//设置已勾选的
  2904. var str = null;
  2905. angular.forEach($scope.tableParams.data, function (order) {
  2906. if (order.$selected == true) {
  2907. if (str != null && str != '') str += ',';
  2908. str += order.id;
  2909. }
  2910. });
  2911. if (str != null && str != '') {
  2912. PurcOrder[state].call({}, {ids: '' + str}, function () {
  2913. $scope.tableParams.reload();
  2914. }, function () {
  2915. toaster.pop('error', '错误', "设置失败");
  2916. });
  2917. }
  2918. }
  2919. };
  2920. }]);
  2921. app.controller('SaleOrderCtrl', ['$scope', '$filter', 'PurcOrderItem', 'PurcOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'PurcOrderItemHis', 'PagingRelease', 'SnapshotService', 'PurcOrderItemInfo', 'token', 'CurrentRole', '$timeout', '$modal', function ($scope, $filter, PurcOrderItem, PurcOrder, ngTableParams, toaster, ReportService, BaseService, PurcOrderItemHis, PagingRelease, SnapshotService, PurcOrderItemInfo, token, CurrentRole, $timeout, $modal) {
  2922. BaseService.scrollBackToTop();
  2923. // 判断是否为普通用户
  2924. CurrentRole.isUser({}, {}, function (data) {
  2925. $scope.isUser = data.isUser;
  2926. });
  2927. $scope.active = 'todo';
  2928. $scope.dateZoneText = '不限';
  2929. $scope.deliveryZoneText = '不限';
  2930. $scope.condition = {dateZone: 1, deliveryZone: -1};
  2931. /* 时间筛选初始化*/
  2932. var fromDate = new Date();
  2933. var toDate = new Date();
  2934. fromDate.setMonth(fromDate.getMonth() - 1);
  2935. fromDate.setHours(0, 0, 0, 0);
  2936. toDate.setHours(23, 59, 59, 999);
  2937. $scope.condition.dateFrom = fromDate;
  2938. $scope.condition.dateTo = toDate;
  2939. $scope.changeDateZone = function (zone) {
  2940. $scope.condition.dateZone = zone;
  2941. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  2942. $scope.condition.$dateZoneOpen = false;
  2943. getDateCondition(zone, $scope.condition);
  2944. $scope.tableParams.page(1);
  2945. $scope.tableParams.reload();
  2946. };
  2947. $scope.changeDeliveryZone = function (zone) {
  2948. $scope.condition.deliveryZoneText = zone;
  2949. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  2950. $scope.condition.$delievryZoneOpen = false;
  2951. getDelveryCondition(zone, $scope.condition);
  2952. $scope.tableParams.reload();
  2953. };
  2954. $scope.nowdate = new Date();
  2955. // 切换单据类型
  2956. $scope.setActive = function (state) {
  2957. if ($scope.active != state) {
  2958. $scope.active = state;
  2959. if ($scope.tableParams.page() == 1)
  2960. $scope.tableParams.reload();
  2961. else
  2962. $scope.tableParams.page(1);
  2963. }
  2964. };
  2965. $scope.searchMethod = false;
  2966. // 切换数据来源(正常数据 or 历史数据)
  2967. var getService = function () {
  2968. return $scope.searchMethod ? PurcOrderItem : PurcOrderItemInfo;
  2969. };
  2970. $scope.tableParams = new ngTableParams({ // ng-Table参数
  2971. page: 1,
  2972. count: 20,
  2973. sorting: {
  2974. date: 'desc',
  2975. id: 'desc'
  2976. }
  2977. }, {
  2978. total: 0,
  2979. counts: [5, 10, 15, 25, 50],
  2980. getData: function ($defer, params) { // 获取数据的方法
  2981. $scope.loading = true;
  2982. var pageParams = params.url();
  2983. pageParams.searchFilter = { // 筛选条件
  2984. keyword: $scope.keyword,
  2985. fromDate: getDateTime($scope.condition.dateFrom),
  2986. endDate: getDateTime($scope.condition.dateTo)
  2987. };
  2988. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  2989. $scope.loading = false;
  2990. if (page) {
  2991. $defer.resolve(page.content);
  2992. params.total(page.totalElement);
  2993. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  2994. }
  2995. }, function (response) {
  2996. $scope.loading = false;
  2997. toaster.pop('error', '数据加载失败', response.data);
  2998. });
  2999. }
  3000. });
  3001. //获得各分类未阅读数量
  3002. var getUnreadCount = function () {
  3003. PurcOrderItem.getUnreadCount(null, function (data) {
  3004. $scope.unread = data;
  3005. });
  3006. };
  3007. getUnreadCount();
  3008. //设置单据已读
  3009. $scope.setOrdersRead = function (id) {
  3010. // 如果单据本身已读,则不发送请求修改数据
  3011. if (!$scope.isUnread(id)){
  3012. return;
  3013. }
  3014. var sourceId = [];
  3015. sourceId.push(id);
  3016. PurcOrderItem.setRead({}, sourceId, function (message) {
  3017. getUnreadCount();
  3018. });
  3019. };
  3020. //批量设置单据已读
  3021. $scope.setOrdersReadByBatch = function () {
  3022. var sourceId = [];
  3023. angular.forEach($scope.tableParams.data, function (order) {
  3024. if (order.$selected == true) {
  3025. sourceId.push(order.id);
  3026. }
  3027. });
  3028. PurcOrderItem.setRead({}, sourceId, function (message) {
  3029. getUnreadCount();
  3030. });
  3031. };
  3032. $scope.setOrdersReadByState = function () {
  3033. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3034. return;
  3035. }
  3036. PurcOrderItem.setReadByState({}, function () {
  3037. getUnreadIds();
  3038. getUnreadCount();
  3039. });
  3040. };
  3041. var getUnreadIds = function () {
  3042. PurcOrderItem.getUnreadIds({}, "", function (message) {
  3043. $scope.unreadCode = message.content;
  3044. });
  3045. };
  3046. getUnreadIds();
  3047. $scope.isUnread = function (id) {
  3048. for (var i in $scope.unreadCode) {
  3049. if (id == $scope.unreadCode[i]) {
  3050. return true;
  3051. }
  3052. }
  3053. };
  3054. $scope.getOrderTotal = function (items) {
  3055. var sum = 0;
  3056. angular.forEach(items, function (item) {
  3057. sum += item.qty * item.price;
  3058. });
  3059. return sum;
  3060. };
  3061. $scope.openDatePicker = function ($event, item, openParam) {
  3062. $event.preventDefault();
  3063. $event.stopPropagation();
  3064. item[openParam] = !item[openParam];
  3065. };
  3066. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3067. $event.preventDefault();
  3068. $event.stopPropagation();
  3069. item[openParam] = !item[openParam];
  3070. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3071. $scope.tableParams.reload();
  3072. }
  3073. };
  3074. $scope.parseDate = function (dateStr) {
  3075. if (dateStr)
  3076. return Date.parse(dateStr, 'yyyy-MM-dd');
  3077. return new Date();
  3078. };
  3079. // 获取token信息
  3080. $scope.getToken = function() {
  3081. token.info({userType: 'sale'}, {}, function(data) {
  3082. $scope.token = data.token;
  3083. }, function(response) {
  3084. toaster.pop('error', '提示', response.data);
  3085. });
  3086. }
  3087. $scope.onReplyClick = function (item, inverse) {
  3088. if (item.reply) {
  3089. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3090. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3091. return;
  3092. }
  3093. var reply = angular.copy(item.reply);
  3094. if (reply.delivery) {
  3095. if (typeof reply.delivery == 'object')
  3096. reply.delivery = reply.delivery.getTime();
  3097. } else {
  3098. reply.delivery = item.delivery;
  3099. }
  3100. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3101. $scope.loading = true;
  3102. if($scope.token != null) {
  3103. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3104. $scope.loading = false;
  3105. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3106. $scope.tableParams.reload();
  3107. }, function (response) {
  3108. $scope.loading = false;
  3109. toaster.pop('error', '回复失败', response.data);
  3110. });
  3111. }
  3112. }
  3113. };
  3114. //打印 采购单
  3115. $scope.print = function (order) {
  3116. var newPage = window.open("about:blank");
  3117. PurcOrder.printPermission({}, function () {
  3118. PurcOrder.printCount({id: order.id}, {});//增加打印此次 // 在此方法内添加记录日志
  3119. if (order.display == 1) $scope.setDisplay('setRead', order.id);//设置为已查看状态
  3120. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id , newPage);
  3121. $scope.tableParams.reload();
  3122. },function (response) {
  3123. newPage.close();
  3124. toaster.pop('error', '打印失败', response.data);
  3125. });
  3126. };
  3127. $scope.getReply = function (item) {
  3128. if (!item.replies) {
  3129. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3130. item.replies = replies;
  3131. });
  3132. }
  3133. };
  3134. $scope.checkboxes = {
  3135. checked: false
  3136. };
  3137. // 点击勾选全部的复选框
  3138. $scope.checkAll = function () {
  3139. angular.forEach($scope.tableParams.data, function (item) {
  3140. item.$selected = $scope.checkboxes.checked;
  3141. });
  3142. };
  3143. // 点击其中一个明细的复选框
  3144. $scope.checkOne = function (order) {
  3145. var result = true;
  3146. angular.forEach($scope.tableParams.data, function (item) {
  3147. if (item.$selected != true) {
  3148. result = false;
  3149. return;
  3150. }
  3151. });
  3152. $scope.checkboxes.checked = result;
  3153. };
  3154. //批量回复采购订单
  3155. $scope.replyByBatch = function () {
  3156. $scope.loading = true;
  3157. var str = '';
  3158. angular.forEach($scope.tableParams.data, function (order) {
  3159. if (order.$selected == true) {
  3160. angular.forEach(order.orderItems, function (item) {
  3161. str += item.id;
  3162. str += ',';
  3163. });
  3164. }
  3165. });
  3166. if (!(str == '')) {
  3167. $scope.loading = false;
  3168. str = str.substr(0, str.length - 1);
  3169. var modalInstance = $modal.open({
  3170. animation: true,
  3171. templateUrl: 'static/tpl/index/sale/modal/reply_bybatch.html',
  3172. controller: 'ReplyByBatchCtrl',
  3173. resolve: {}
  3174. });
  3175. modalInstance.result.then(function(data) {
  3176. $scope.loading = true;
  3177. var reply = data;
  3178. var date = null;
  3179. if (reply.date && reply.method == 1) {
  3180. date = reply.date.getTime();
  3181. }
  3182. PurcOrderItem.replyByBatch({date: date}, str, function () {
  3183. $scope.loading = false;
  3184. $scope.tableParams.reload();
  3185. toaster.pop('success', '提示', '批量回复成功');
  3186. }, function (response) {
  3187. $scope.loading = false;
  3188. toaster.pop('error', '提示', '批量回复失败');
  3189. });
  3190. });
  3191. } else {//没有勾选其中的明细
  3192. toaster.pop('error', '提示', '请先选择需要回复的单据');
  3193. $scope.loading = false;
  3194. }
  3195. };
  3196. // 搜索框回车
  3197. $scope.onSearch = function (keyword) {
  3198. // 每次搜索重置获取数据方法
  3199. $scope.searchMethod = false;
  3200. if(keyword != null && keyword != '') {
  3201. $scope.searchMethod = true;
  3202. }
  3203. $scope.tableParams.page(1);
  3204. $scope.tableParams.reload();
  3205. };
  3206. // 选择查找日期
  3207. $scope.onDateCondition = function () {
  3208. $scope.tableParams.page(1);
  3209. $scope.tableParams.reload();
  3210. };
  3211. //设置为已查看
  3212. $scope.setDisplay = function (state, orderId) {
  3213. if (orderId) {//设置单个
  3214. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3215. $scope.tableParams.reload();
  3216. }, function () {
  3217. toaster.pop('error', '错误', "设置失败");
  3218. });
  3219. } else {//设置已勾选的
  3220. var str = null;
  3221. angular.forEach($scope.tableParams.data, function (order) {
  3222. if (order.$selected == true) {
  3223. if (str != null && str != '') str += ',';
  3224. str += order.id;
  3225. }
  3226. });
  3227. if (str != null && str != '') {
  3228. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3229. $scope.tableParams.reload();
  3230. }, function () {
  3231. toaster.pop('error', '错误', "设置失败");
  3232. });
  3233. }
  3234. }
  3235. };
  3236. // 导出
  3237. $scope.exportXls = function () {
  3238. PurcOrderItem.exportXls({}, {}, function (data) {
  3239. if (data.success){
  3240. window.location.href = 'sale/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3241. }
  3242. }, function (response) {
  3243. toaster.pop('error', '数据加载失败', response.data);
  3244. });
  3245. }
  3246. }]);
  3247. /**
  3248. * 批量回复模态框
  3249. */
  3250. app.controller('ReplyByBatchCtrl', ['$scope', '$modalInstance', '$filter', 'toaster', function($scope, $modalInstance, $filter, toaster) {
  3251. $scope.activeTab = 'custom';
  3252. $scope.reply = {
  3253. method: 1
  3254. };
  3255. $scope.getMinDate = function () {
  3256. return $filter('date')(new Date, 'yyyy-MM-dd');
  3257. };
  3258. $scope.openDatePicker = function ($event, openParam) {
  3259. $event.preventDefault();
  3260. $event.stopPropagation();
  3261. $scope.$dateOpen = !openParam;
  3262. };
  3263. // 取消
  3264. $scope.cancel = function () {
  3265. $modalInstance.dismiss();
  3266. }
  3267. // 提交
  3268. $scope.submit = function () {
  3269. if ($scope.reply.method == 0) {
  3270. $modalInstance.close($scope.reply);
  3271. } else if ($scope.reply.method == 1) {
  3272. if (angular.isUndefined($scope.reply.date)) {
  3273. toaster.pop('error', '提示', '请先选择日期')
  3274. } else {
  3275. $modalInstance.close($scope.reply);
  3276. }
  3277. }
  3278. }
  3279. }]);
  3280. app.controller('SaleOrderDetailCtrl', ['$scope', '$stateParams', 'PurcOrder', 'PurcOrderItem', 'toaster', 'ReportService', 'CurrentRole', 'token', 'file', function ($scope, $stateParams, PurcOrder, PurcOrderItem, toaster, ReportService, CurrentRole, token, file) {
  3281. // 获取当前用户是否为普通用户
  3282. CurrentRole.isUser({}, {}, function (data) {
  3283. $scope.isUser = data.isUser;
  3284. });
  3285. var loadData = function () {
  3286. PurcOrder.get({id: $stateParams.id}, function (data) {
  3287. $scope.order = data;
  3288. var sum = 0;
  3289. angular.forEach($scope.order.orderItems, function (item) {
  3290. sum += item.qty * item.price;
  3291. });
  3292. $scope.order.total = sum;
  3293. if ($scope.order.display == 1) {//未查看的设为已查看
  3294. $scope.setDisplay('setRead', $scope.order.id);
  3295. }
  3296. $scope.loading = false;
  3297. }, function (response) {
  3298. toaster.pop('error', '', response.data);
  3299. });
  3300. };
  3301. loadData();
  3302. $scope.getReply = function (item) {
  3303. if (!item.replies) {
  3304. PurcOrderItem.getReply({orderItemId: item.id}, function (replies) {
  3305. item.replies = replies;
  3306. });
  3307. }
  3308. };
  3309. $scope.openDatePicker = function ($event, item, openParam) {
  3310. $event.preventDefault();
  3311. $event.stopPropagation();
  3312. item[openParam] = !item[openParam];
  3313. };
  3314. // 获取token信息
  3315. var getToken = function() {
  3316. token.info({userType: 'sale'}, {}, function(data) {
  3317. $scope.token = data.token;
  3318. }, function(response) {
  3319. toaster.pop('error', '提示', response.data);
  3320. });
  3321. };
  3322. getToken();
  3323. $scope.onReplyClick = function (item, inverse) {
  3324. if (item.reply) {
  3325. if (!item.reply.qty || item.reply.qty < 0 /*|| item.reply.qty > item.qty*/) {
  3326. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  3327. return;
  3328. }
  3329. var reply = angular.copy(item.reply);
  3330. if (reply.delivery) {
  3331. if (typeof reply.delivery == 'object')
  3332. reply.delivery = reply.delivery.getTime();
  3333. } else {
  3334. reply.delivery = item.delivery;
  3335. }
  3336. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  3337. $scope.loading = true;
  3338. if($scope.token != null) {
  3339. PurcOrderItem.reply({orderItemId: item.id, token: $scope.token}, reply, function () {
  3340. $scope.loading = false;
  3341. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  3342. $scope.tableParams.reload();
  3343. }, function (response) {
  3344. $scope.loading = false;
  3345. toaster.pop('error', '回复失败', response.data);
  3346. });
  3347. }
  3348. }
  3349. };
  3350. // 采购单
  3351. $scope.print = function (order) {
  3352. var newPage = window.open("about:blank");
  3353. PurcOrder.printPermission({}, function () {
  3354. PurcOrder.printCount({id: order.id}, {});//增加打印此次
  3355. ReportService.print(order.enUU, 'PURCLIST', "where purc$orders.pu_id=" + order.id, newPage);
  3356. },function (response) {
  3357. newPage.close();
  3358. toaster.pop('error', '打印失败', response.data);
  3359. });
  3360. };
  3361. //设置为已查看
  3362. $scope.setDisplay = function (state, orderId) {
  3363. if (orderId) {//设置单个
  3364. PurcOrder[state].call({}, {ids: '' + orderId}, function () {
  3365. $scope.tableParams.reload();
  3366. }, function () {
  3367. toaster.pop('error', '错误', "设置失败");
  3368. });
  3369. } else {//设置已勾选的
  3370. var str = null;
  3371. angular.forEach($scope.tableParams.data, function (order) {
  3372. if (order.$selected == true) {
  3373. if (str != null && str != '') str += ',';
  3374. str += order.id;
  3375. }
  3376. });
  3377. if (str != null && str != '') {
  3378. PurcOrder[state].call({}, {ids: '' + str}, function () {
  3379. $scope.tableParams.reload();
  3380. }, function () {
  3381. toaster.pop('error', '错误', "设置失败");
  3382. });
  3383. }
  3384. }
  3385. };
  3386. $scope.fileDownload = function (id) {
  3387. window.open("file/batch/" + id);
  3388. }
  3389. }]);
  3390. app.controller('SaleChangeCtrl', ['$scope', '$filter', 'PurcChange', 'PurcChanges', 'ngTableParams', 'toaster', 'BaseService', 'PurcChangeHis', 'CurrentRole', function ($scope, $filter, PurcChange, PurcChanges, ngTableParams, toaster, BaseService, PurcChangeHis, CurrentRole) {
  3391. BaseService.scrollBackToTop();
  3392. // 获取当前用户是否为普通用户
  3393. CurrentRole.isUser({}, {}, function (data) {
  3394. $scope.isUser = data.isUser;
  3395. });
  3396. $scope.active = 'todo';
  3397. $scope.agreedText = '全部';
  3398. $scope.dateZoneText = '一个月内';
  3399. $scope.condition = {dateZone: 1};
  3400. /* 时间筛选初始化*/
  3401. var fromDate = new Date();
  3402. var toDate = new Date();
  3403. fromDate.setMonth(fromDate.getMonth() - 1);
  3404. fromDate.setHours(0, 0, 0, 0);
  3405. toDate.setHours(23, 59, 59, 999);
  3406. $scope.condition.dateFrom = fromDate;
  3407. $scope.condition.dateTo = toDate;
  3408. $scope.changeAgreed = function (agreed) {
  3409. $scope.condition.agreed = agreed;
  3410. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  3411. $scope.condition.$agreedOpen = false;
  3412. };
  3413. $scope.changeDateZone = function (zone) {
  3414. $scope.condition.dateZone = zone;
  3415. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  3416. $scope.condition.$dateZoneOpen = false;
  3417. getDateCondition(zone, $scope.condition);
  3418. $scope.tableParams.page(1);
  3419. $scope.tableParams.reload();
  3420. };
  3421. $scope.setActive = function (state) {
  3422. if ($scope.active != state) {
  3423. $scope.active = state;
  3424. if ($scope.tableParams.page() == 1)
  3425. $scope.tableParams.reload();
  3426. else
  3427. $scope.tableParams.page(1);
  3428. }
  3429. };
  3430. $scope.searchMethod = false;
  3431. var getService = function () {
  3432. return $scope.searchMethod ? PurcChange : PurcChanges;
  3433. };
  3434. $scope.tableParams = new ngTableParams({
  3435. page: 1,
  3436. count: 20,
  3437. sorting: {
  3438. date: 'desc'
  3439. }
  3440. }, {
  3441. total: 0,
  3442. counts: [5, 10, 25, 50],
  3443. getData: function ($defer, params) {
  3444. $scope.loading = true;
  3445. var pageParams = params.url();
  3446. pageParams.searchFilter = {
  3447. keyword: $scope.keyword,
  3448. fromDate: getDateTime($scope.condition.dateFrom),
  3449. endDate: getDateTime($scope.condition.dateTo)
  3450. };
  3451. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3452. $scope.loading = false;
  3453. if (page) {
  3454. params.total(page.totalElement);
  3455. $defer.resolve(page.content);
  3456. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3457. }
  3458. }, function (response) {
  3459. $scope.loading = false;
  3460. toaster.pop('error', '数据加载失败', response.data);
  3461. });
  3462. }
  3463. });
  3464. //获得各分类未阅读数量
  3465. var getUnreadCount = function () {
  3466. PurcChange.getUnreadCount(null, function(data){
  3467. $scope.unread = data;
  3468. });
  3469. };
  3470. getUnreadCount();
  3471. //设置单据已读
  3472. $scope.setOrdersRead = function (id) {
  3473. // 如果单据本身已读,则不发送请求修改数据
  3474. if (!$scope.isUnread(id)){
  3475. return;
  3476. }
  3477. var sourceId = [];
  3478. sourceId.push(id);
  3479. PurcChange.setRead({}, sourceId, function (message) {
  3480. // $scope.getUnreadIds();
  3481. getUnreadCount();
  3482. });
  3483. };
  3484. $scope.setOrdersReadByState = function () {
  3485. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3486. return;
  3487. }
  3488. PurcChange.setReadByState({}, function () {
  3489. getUnreadIds();
  3490. getUnreadCount();
  3491. });
  3492. };
  3493. //获取未读单据id
  3494. var getUnreadIds = function (){
  3495. PurcChange.getUnreadIds({}, "", function (message) {
  3496. $scope.unreadCode = message.content;
  3497. });
  3498. };
  3499. getUnreadIds();
  3500. //判断单据是否未读
  3501. $scope.isUnread = function (id){
  3502. for (var i in $scope.unreadCode) {
  3503. if (id == $scope.unreadCode[i]) {
  3504. return true;
  3505. }
  3506. }
  3507. };
  3508. $scope.openDatePicker = function ($event, item, openParam) {
  3509. $event.preventDefault();
  3510. $event.stopPropagation();
  3511. item[openParam] = !item[openParam];
  3512. };
  3513. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3514. $event.preventDefault();
  3515. $event.stopPropagation();
  3516. item[openParam] = !item[openParam];
  3517. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3518. $scope.tableParams.reload();
  3519. }
  3520. };
  3521. $scope.onReplyClick = function (change) {
  3522. if (change.$agreed) {
  3523. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3524. $scope.loading = true;
  3525. PurcChange.reply({changeId: change.id}, reply, function () {
  3526. $scope.loading = false;
  3527. toaster.pop('info', '提示', '回复成功');
  3528. $scope.tableParams.reload();
  3529. }, function (response) {
  3530. $scope.loading = false;
  3531. toaster.pop('error', '回复失败', response.data);
  3532. });
  3533. }
  3534. };
  3535. // 搜索框回车
  3536. $scope.onSearch = function (keyword) {
  3537. // 每次搜索重置获取数据方法
  3538. $scope.searchMethod = false;
  3539. if(keyword != null && keyword != '') {
  3540. $scope.searchMethod = true;
  3541. }
  3542. $scope.tableParams.page(1);
  3543. $scope.tableParams.reload();
  3544. };
  3545. // 导出
  3546. $scope.exportXls = function () {
  3547. PurcChange.exportXls({}, {}, function (data) {
  3548. if (data.success){
  3549. window.location.href = 'sale/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3550. }
  3551. }, function (response) {
  3552. toaster.pop('error', '数据加载失败', response.data);
  3553. });
  3554. }
  3555. }]);
  3556. app.controller('SaleChangeDetailCtrl', ['$scope', '$stateParams', 'PurcChange', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcChange, toaster, CurrentRole) {
  3557. // 获取当前用户是否为普通用户
  3558. CurrentRole.isUser({}, {}, function (data) {
  3559. $scope.isUser = data.isUser;
  3560. });
  3561. var loadData = function () {
  3562. PurcChange.getItem({id: $stateParams.id}, function (data) {
  3563. $scope.change = data;
  3564. }, function (response) {
  3565. toaster.pop('error', '', response.data);
  3566. });
  3567. };
  3568. loadData();
  3569. $scope.openDatePicker = function ($event, item, openParam) {
  3570. $event.preventDefault();
  3571. $event.stopPropagation();
  3572. item[openParam] = !item[openParam];
  3573. };
  3574. $scope.onReplyClick = function (change) {
  3575. if (change.$agreed) {
  3576. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  3577. PurcChange.reply({changeId: change.id}, reply, function () {
  3578. toaster.pop('info', '提示', '回复成功');
  3579. loadData();
  3580. }, function (response) {
  3581. toaster.pop('error', '回复失败', response.data);
  3582. });
  3583. }
  3584. };
  3585. }]);
  3586. //客户采购询价
  3587. 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) {
  3588. BaseService.scrollBackToTop();
  3589. // 获取当前用户是否为普通用户
  3590. CurrentRole.isUser({}, {}, function (data) {
  3591. $scope.isUser = data.isUser;
  3592. });
  3593. if ($rootScope.active) {
  3594. $scope.active = $rootScope.active;
  3595. $rootScope.active = null;
  3596. } else {
  3597. $scope.active = 'todo';
  3598. }
  3599. $scope.agreedText = '全部';
  3600. $scope.dateZoneText = '最近一个月';
  3601. $scope.condition = {dateZone: 1};
  3602. /* 时间筛选初始化*/
  3603. var fromDate = new Date();
  3604. var toDate = new Date();
  3605. fromDate.setMonth(fromDate.getMonth() - 1);
  3606. fromDate.setHours(0, 0, 0, 0);
  3607. toDate.setHours(23, 59, 59, 999);
  3608. $scope.condition.dateFrom = fromDate;
  3609. $scope.condition.dateTo = toDate;
  3610. $scope.changeAgreed = function (agreed) {
  3611. $scope.condition.agreed = agreed;
  3612. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  3613. $scope.condition.$agreedOpen = false;
  3614. };
  3615. $scope.changeDateZone = function (zone) {
  3616. $scope.condition.dateZone = zone;
  3617. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  3618. $scope.condition.$dateZoneOpen = false;
  3619. getDateCondition(zone, $scope.condition);
  3620. $scope.tableParams.page(1);
  3621. $scope.tableParams.reload();
  3622. };
  3623. $scope.setActive = function (state) {
  3624. if ($scope.active != state) {
  3625. $scope.active = state;
  3626. if ($scope.tableParams.page() == 1)
  3627. $scope.tableParams.reload();
  3628. else
  3629. $scope.tableParams.page(1);
  3630. }
  3631. };
  3632. // 设置阅读状态
  3633. $scope.setReadStatus = function(msg) {
  3634. if(!msg.read) {
  3635. PurcInquiry.setStatus({id: msg.inid}, {}, function(data) {
  3636. });
  3637. }
  3638. }
  3639. $scope.searchMethod = false;
  3640. var getService = function () {
  3641. return $scope.searchMethod ? PurcInquiry : PurcInquiryInfo;
  3642. };
  3643. $scope.tableParams = new ngTableParams({
  3644. page: 1,
  3645. count: 20,
  3646. sorting: {
  3647. 'inquiry.date': 'desc',
  3648. 'inquiry.enterprise.enName': 'asc',
  3649. 'inquiry.code': 'asc'
  3650. }
  3651. }, {
  3652. total: 0,
  3653. counts: [5, 10, 25, 50],
  3654. getData: function ($defer, params) {
  3655. $scope.loading = true;
  3656. var pageParams = params.url();
  3657. var realActive = {};
  3658. pageParams.searchFilter = { // 筛选条件
  3659. keyword: $scope.keyword,
  3660. fromDate: getDateTime($scope.condition.dateFrom),
  3661. endDate: getDateTime($scope.condition.dateTo)
  3662. };
  3663. if ($scope.active == 'overdue') {
  3664. $scope.active = 'end';
  3665. }
  3666. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  3667. $scope.loading = false;
  3668. if (page) {
  3669. params.total(page.totalElement);
  3670. $defer.resolve(page.content);
  3671. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  3672. }
  3673. }, function (response) {
  3674. $scope.loading = false;
  3675. toaster.pop('error', '数据加载失败', response.data);
  3676. });
  3677. }
  3678. });
  3679. //获得各分类未阅读数量
  3680. var getUnreadCount = function () {
  3681. PurcInquiry.getUnreadCount(null, function (data) {
  3682. $scope.unread = data;
  3683. });
  3684. };
  3685. getUnreadCount();
  3686. //设置单据已读
  3687. $scope.setOrdersRead = function (id) {
  3688. // 如果单据本身已读,则不发送请求修改数据
  3689. if (!$scope.isUnread(id)){
  3690. return;
  3691. }
  3692. var sourceId = [];
  3693. sourceId.push(id);
  3694. PurcInquiry.setRead({}, sourceId, function (message) {
  3695. getUnreadCount();
  3696. removeByValue($scope.unreadCode, id);
  3697. });
  3698. };
  3699. $scope.setOrdersReadByState = function () {
  3700. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  3701. return;
  3702. }
  3703. PurcInquiry.setReadByState({}, function () {
  3704. getUnreadIds();
  3705. getUnreadCount();
  3706. });
  3707. };
  3708. var getUnreadIds = function () {
  3709. PurcInquiry.getUnreadIds({}, "", function (message) {
  3710. $scope.unreadCode = message.content;
  3711. });
  3712. };
  3713. getUnreadIds();
  3714. $scope.isUnread = function (id) {
  3715. for (var i in $scope.unreadCode) {
  3716. if (id == $scope.unreadCode[i]) {
  3717. return true;
  3718. }
  3719. }
  3720. };
  3721. $scope.getMinDate = function (item) {
  3722. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3723. };
  3724. $scope.replyPrices = [];
  3725. $scope.replylapQtys = [];
  3726. $scope.replyPrices.push(true);
  3727. $scope.replylapQtys.push(true);
  3728. $scope.addStep = function (inquiryItem) {
  3729. $scope.replyPrices.push(true);
  3730. if (inquiryItem.replies.length >= 10) {
  3731. toaster.pop('warning', '提示', '最多支持10个分段!');
  3732. } else {
  3733. inquiryItem.replies.push({});
  3734. if (inquiryItem.replies.length != 1) {
  3735. $scope.replyPrices.push(true);
  3736. $scope.replylapQtys.push(true);
  3737. }
  3738. }
  3739. };
  3740. $scope.removeStep = function (inquiryItem, stepIndex) {
  3741. inquiryItem.replies.splice(stepIndex, 1);
  3742. $scope.replyPrices.splice(stepIndex, 1);
  3743. $scope.replylapQtys.splice(stepIndex, 1);
  3744. };
  3745. $scope.openDatePicker = function ($event, item, openParam) {
  3746. $event.preventDefault();
  3747. $event.stopPropagation();
  3748. item[openParam] = !item[openParam];
  3749. };
  3750. $scope.openFilterDatePicker = function ($event, item, openParam) {
  3751. $event.preventDefault();
  3752. $event.stopPropagation();
  3753. item[openParam] = !item[openParam];
  3754. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  3755. $scope.tableParams.reload();
  3756. }
  3757. };
  3758. $scope.getHistory = function (item) {
  3759. if (!item.history) {
  3760. PurcInquiry.getHistory({itemId: item.id},function (data) {
  3761. $scope.historyShow = true;
  3762. item.history = data;
  3763. }, function (response) {
  3764. $scope.historyShow = false;
  3765. //toaster.pop('error', '数据加载失败', response.data);
  3766. });
  3767. }
  3768. };
  3769. // 获取token信息
  3770. $scope.getToken = function() {
  3771. token.info({userType: 'saleinquiry'}, {}, function(data) {
  3772. $scope.token = data.token;
  3773. }, function(response) {
  3774. toaster.pop('error', '提示', response.data);
  3775. });
  3776. };
  3777. $scope.deleteAttach = function (attaches, index) {
  3778. attaches.splice(index, 1);
  3779. };
  3780. $scope.onReplyClick = function (item, withSteps) {
  3781. if (item.vendFromDate instanceof Date) {
  3782. item.vendFromDate = item.vendFromDate.getTime();
  3783. }
  3784. if (item.vendToDate instanceof Date) {
  3785. item.vendToDate = item.vendToDate.getTime();
  3786. }
  3787. if (item.vendFromDate > item.vendToDate) {
  3788. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  3789. return;
  3790. }
  3791. var replies = [];
  3792. // 判断分段数是否合法
  3793. var valid = true;
  3794. var validLapQty = 0;
  3795. angular.forEach(item.replies, function (r, i) {
  3796. if ((i > 0 ? r.lapQty : 1) || r.price) {
  3797. replies.push(r);
  3798. }
  3799. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  3800. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  3801. valid = false;
  3802. validLapQty = r.lapQty;
  3803. }
  3804. });
  3805. item.replies = replies;
  3806. $scope.loading = true;
  3807. if (!valid) {
  3808. if (validLapQty) {
  3809. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  3810. } else {
  3811. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  3812. }
  3813. $scope.loading = false;
  3814. } else {
  3815. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  3816. if (withSteps) { // 保存并报价
  3817. if(null != file) {
  3818. $upload.upload({
  3819. url: 'sale/inquiry/addAttach',
  3820. file: file,
  3821. method: 'POST',
  3822. data: {
  3823. item: item,
  3824. method: 'reply'
  3825. }
  3826. }).success(function (data) {
  3827. if (data.item) {
  3828. item = data.item;
  3829. }
  3830. $scope.loading = false;
  3831. toaster.pop('info', '提示', '报价成功');
  3832. $scope.tableParams.reload();
  3833. }).error(function (data) {
  3834. $scope.loading = false;
  3835. toaster.pop('error', '附件上传失败');
  3836. });
  3837. } else {
  3838. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function (data) {
  3839. $scope.loading = false;
  3840. toaster.pop('info', '提示', '报价成功');
  3841. $scope.tableParams.reload();
  3842. }, function (response) {
  3843. $scope.loading = false;
  3844. toaster.pop('error', '询价失效', response.data);
  3845. });
  3846. }
  3847. } else { // 保存
  3848. if(null != file) {
  3849. $upload.upload({
  3850. url: 'sale/inquiry/addAttach',
  3851. file: file,
  3852. method: 'POST',
  3853. data: {
  3854. item: item,
  3855. method: 'save'
  3856. }
  3857. }).success(function (data) {
  3858. if (data.item) {
  3859. item = data.item;
  3860. }
  3861. $scope.loading = false;
  3862. toaster.pop('info', '提示', '保存成功');
  3863. $scope.tableParams.reload();
  3864. }).error(function (data) {
  3865. $scope.loading = false;
  3866. toaster.pop('error', '附件上传失败');
  3867. });
  3868. } else {
  3869. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function (data) {
  3870. $scope.loading = false;
  3871. toaster.pop('info', '提示', '保存成功');
  3872. $scope.tableParams.reload();
  3873. }, function (response) {
  3874. $scope.loading = false;
  3875. toaster.pop('error', '保存失败', response.data);
  3876. });
  3877. }
  3878. }
  3879. }
  3880. };
  3881. $scope.isValid = function (item, withSteps) {
  3882. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  3883. if (!withSteps || !bool)
  3884. return bool;
  3885. angular.forEach(item.replies, function (r, i) {
  3886. $scope.verifylapQty(r.lapQty, i, item);
  3887. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  3888. });
  3889. return bool;
  3890. };
  3891. $scope.verifylapQty = function (value, index, inquiryItem) {
  3892. value = parseInt(value);
  3893. var regex = /^\d+(.\d{1,5})?$/;
  3894. var valid = true;
  3895. angular.forEach(inquiryItem.replies, function(reply, $index) {
  3896. if ($index < index && reply.lapQty >= value) {
  3897. valid = false;
  3898. }
  3899. });
  3900. $scope.replylapQtys[index] = regex.test(value) && valid;
  3901. };
  3902. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  3903. $scope.verify = function (value, type) {
  3904. var regex = /^\d+(.\d{1,5})?$/;//
  3905. switch (type) {
  3906. case 'minOrderQty':
  3907. $scope.minOrderQtyVerify = regex.test(value);
  3908. break;
  3909. case 'minPackQty':
  3910. $scope.minPackQtyVerify = regex.test(value);
  3911. break;
  3912. case 'leadtime':
  3913. $scope.leadtimeVerify = regex.test(value);
  3914. break;
  3915. default:
  3916. $scope.replyPrices[type] = regex.test(value);
  3917. break;
  3918. }
  3919. }
  3920. // 搜索框回车
  3921. $scope.onSearch = function (keyword) {
  3922. // 每次搜索重置获取数据方法
  3923. $scope.searchMethod = false;
  3924. if(keyword != null && keyword != '') {
  3925. $scope.searchMethod = true;
  3926. }
  3927. $scope.tableParams.page(1);
  3928. $scope.tableParams.reload();
  3929. };
  3930. // 取消
  3931. $scope.cancel = function () {
  3932. $scope.tableParams.reload();
  3933. }
  3934. // 导出
  3935. $scope.exportXls = function () {
  3936. PurcInquiry.exportXls({}, {}, function (data) {
  3937. if (data.success) {
  3938. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  3939. }
  3940. }, function (response) {
  3941. toaster.pop('error', '数据加载失败', response.data);
  3942. })
  3943. }
  3944. }]);
  3945. // 询价单明细
  3946. app.controller('SaleInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole) {
  3947. // 获取当前用户是否为普通用户
  3948. CurrentRole.isUser({}, {}, function (data) {
  3949. $scope.isUser = data.isUser;
  3950. });
  3951. var loadData = function () {
  3952. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  3953. $scope.newinquiryItems = data;
  3954. var inquiry = data[0].inquiry;
  3955. //inquiry.inquiryItems = data;
  3956. angular.forEach(inquiry.attachs, function (attach) {
  3957. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  3958. });
  3959. $scope.inquiry = inquiry;
  3960. }, function (response) {
  3961. $scope.loading = false;
  3962. toaster.pop('error', '', response.data);
  3963. });
  3964. };
  3965. loadData();
  3966. $scope.getMinDate = function (item) {
  3967. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  3968. };
  3969. $scope.replyPrices = [];
  3970. $scope.replylapQtys = [];
  3971. $scope.replyPrices.push(true);
  3972. $scope.replylapQtys.push(true);
  3973. $scope.addStep = function (inquiryItem) {
  3974. if (inquiryItem.replies.length >= 10) {
  3975. toaster.pop('warning', '提示', '最多支持10个分段!');
  3976. } else
  3977. inquiryItem.replies.push({});
  3978. };
  3979. $scope.removeStep = function (inquiryItem, stepIndex) {
  3980. inquiryItem.replies.splice(stepIndex, 1);
  3981. };
  3982. $scope.openDatePicker = function ($event, item, openParam) {
  3983. $event.preventDefault();
  3984. $event.stopPropagation();
  3985. item[openParam] = !item[openParam];
  3986. };
  3987. $scope.getHistory = function (item) {
  3988. if (!item.history) {
  3989. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  3990. item.history = data;
  3991. });
  3992. }
  3993. };
  3994. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  3995. $scope.verify = function (value, type) {
  3996. var regex = /^\d+(.\d{1,5})?$/;//
  3997. switch (type) {
  3998. case 'minOrderQty':
  3999. $scope.minOrderQtyVerify = regex.test(value);
  4000. break;
  4001. case 'minPackQty':
  4002. $scope.minPackQtyVerify = regex.test(value);
  4003. break;
  4004. case 'leadtime':
  4005. $scope.leadtimeVerify = regex.test(value);
  4006. break;
  4007. default:
  4008. $scope.replyPrices[type] = regex.test(value);
  4009. break;
  4010. }
  4011. }
  4012. $scope.verifylapQty = function (value, index, inquiryItem) {
  4013. value = parseInt(value);
  4014. var regex = /^\d+(.\d{1,5})?$/;
  4015. var valid = true;
  4016. angular.forEach(inquiryItem.replies, function(reply, $index) {
  4017. if ($index < index && reply.lapQty >= value) {
  4018. valid = false;
  4019. }
  4020. });
  4021. $scope.replylapQtys[index] = regex.test(value) && valid;
  4022. };
  4023. $scope.isValid = function (item, withSteps) {
  4024. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  4025. if (!withSteps || !bool)
  4026. return bool;
  4027. angular.forEach(item.replies, function (r, i) {
  4028. $scope.verifylapQty(r.lapQty, i, item);
  4029. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  4030. });
  4031. return bool;
  4032. };
  4033. // 获取token信息
  4034. $scope.getToken = function() {
  4035. token.info({userType: 'saleinquiry'}, {}, function(data) {
  4036. $scope.token = data.token;
  4037. }, function(response) {
  4038. toaster.pop('error', '提示', response.data);
  4039. });
  4040. };
  4041. $scope.deleteAttach = function (attaches, index) {
  4042. attaches.splice(index, 1);
  4043. };
  4044. $scope.onReplyClick = function (item, withSteps) {
  4045. if (item.vendFromDate instanceof Date) {
  4046. item.vendFromDate = item.vendFromDate.getTime();
  4047. }
  4048. if (item.vendToDate instanceof Date) {
  4049. item.vendToDate = item.vendToDate.getTime();
  4050. }
  4051. if (item.vendFromDate > item.vendToDate) {
  4052. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  4053. return;
  4054. }
  4055. var replies = [];
  4056. var valid = true;
  4057. var validLapQty = 0;
  4058. angular.forEach(item.replies, function (r, i) {
  4059. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  4060. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  4061. valid = false;
  4062. validLapQty = r.lapQty;
  4063. }
  4064. if ((i > 0 ? r.lapQty : 1) || r.price)
  4065. replies.push(r);
  4066. });
  4067. item.replies = replies;
  4068. $scope.loading = true;
  4069. if (!valid) { // 不合法时给出提示
  4070. if (validLapQty) {
  4071. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  4072. } else {
  4073. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  4074. }
  4075. $scope.loading = false;
  4076. } else {
  4077. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  4078. if (withSteps) {
  4079. if(null != file) {
  4080. $upload.upload({
  4081. url: 'sale/inquiry/addAttach',
  4082. file: file,
  4083. method: 'POST',
  4084. data: {
  4085. item: item,
  4086. method: 'reply'
  4087. }
  4088. }).success(function (data) {
  4089. if (data.item) {
  4090. item = data.item;
  4091. }
  4092. window.location.reload();
  4093. });
  4094. } else {
  4095. PurcInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  4096. $scope.loading = false;
  4097. toaster.pop('info', '提示', '报价成功');
  4098. // loadData();
  4099. window.location.reload();
  4100. }, function (response) {
  4101. $scope.loading = false;
  4102. toaster.pop('error', '询价失效', response.data);
  4103. });
  4104. }
  4105. } else {
  4106. if(null != file) {
  4107. $upload.upload({
  4108. url: 'sale/inquiry/addAttach',
  4109. file: file,
  4110. method: 'POST',
  4111. data: {
  4112. item: item,
  4113. method: 'save'
  4114. }
  4115. }).success(function (data) {
  4116. if (data.item) {
  4117. item = data.item;
  4118. }
  4119. window.location.reload();
  4120. });
  4121. } else {
  4122. PurcInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  4123. $scope.loading = false;
  4124. toaster.pop('info', '提示', '保存成功');
  4125. // loadData();
  4126. window.location.reload();
  4127. }, function (response) {
  4128. $scope.loading = false;
  4129. toaster.pop('error', '保存失败', response.data);
  4130. });
  4131. }
  4132. }
  4133. }
  4134. };
  4135. // 取消
  4136. $scope.cancel = function () {
  4137. $scope.tableParams.reload();
  4138. }
  4139. }]);
  4140. // 平台新增的询价单
  4141. app.controller('PurcInquiryCtrl', ['$scope', 'PurchaseInquiry', 'toaster', 'BaseService', '$upload', '$filter', '$modal', '$rootScope', 'ngTableParams', 'PurcProduct', 'PurcProductNewest', '$timeout', '$http', 'ShipAddress', 'Search', 'ComponentActiveAPI', function ($scope, PurchaseInquiry, toaster, BaseService, $upload, $filter, $modal, $rootScope, ngTableParams, PurcProduct, PurcProductNewest, $timeout, $http, ShipAddress, Search, ComponentActiveAPI) {
  4142. $scope.status = 'InquiryNew';
  4143. $scope.active = 'all';
  4144. $rootScope.tenderVendor = null;// 清除掉已选择的
  4145. $scope.searchMethod = false;
  4146. var getService = function () {
  4147. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  4148. };
  4149. $scope.inquiry = {
  4150. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  4151. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  4152. priceType: '采购',
  4153. isOpen: 1,
  4154. invoice: 0,
  4155. ifTax: 1,
  4156. currency: 'RMB',
  4157. inquirytype: '询价'
  4158. };
  4159. $scope.changeCurrency = function (inquiry) {
  4160. if (inquiry.currency !== 'RMB') {
  4161. $scope.notRMB = true;
  4162. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  4163. inquiry.invoice = 0;
  4164. } else {
  4165. $scope.notRMB = false;
  4166. }
  4167. };
  4168. // 获取收货地址列表
  4169. var loadShipAddress = function () {
  4170. ShipAddress.shipAddList({}, function (data) {
  4171. $scope.ships = data;
  4172. if (angular.isDefined($scope.ships)) {
  4173. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  4174. }
  4175. });
  4176. };
  4177. loadShipAddress();
  4178. // 获取地址信息
  4179. $http.get('resources/citydata/city.json', {
  4180. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  4181. }).then(function (response) {
  4182. $scope.provinces = response.data;
  4183. });
  4184. // 新增收货地址保存
  4185. $scope.saveShipAddress = function (ship) {
  4186. ship.address = ship.province + ship.city + ship.district;
  4187. ShipAddress.saveAddress({}, ship, function (data) {
  4188. if (data.success) {
  4189. // 获取收货地址列表
  4190. loadShipAddress();
  4191. toaster.pop('success', '提示', data.success);
  4192. }
  4193. if (data.error) {
  4194. toaster.pop('error', '提示', data.error);
  4195. }
  4196. });
  4197. };
  4198. $scope.currentDay = function () {
  4199. return $filter('date')(new Date(), 'yyyy-MM-dd');
  4200. };
  4201. $scope.vendors = [];
  4202. // 查找供应商
  4203. $scope.dbfindVendor = function () {
  4204. var modalInstance = $modal.open({
  4205. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  4206. controller: 'DbfindVendorCtrl',
  4207. size: 'lg',
  4208. resolve: {}
  4209. });
  4210. modalInstance.result.then(function (data) {
  4211. var ifPush = true;
  4212. modalInstance.result.then(function (data) {
  4213. angular.forEach(data, function (vendor) {
  4214. if (!$scope.vendors) {// 不存在就先创建
  4215. $scope.vendors = [{}];
  4216. $scope.vendors.splice(0, 1, vendor.vendorEnterprise);
  4217. } else {
  4218. for (var i = 0; i < $scope.vendors.length; i++) {
  4219. ifPush = true;
  4220. if ($scope.vendors[i].enName == vendor.vendorEnterprise.enName) {
  4221. ifPush = false;
  4222. break; // 判定到已存在供应商,就终止循环。
  4223. }
  4224. }
  4225. if (ifPush) {
  4226. $scope.vendors.push({
  4227. enName: vendor.vendorEnterprise.enName,
  4228. enuu: vendor.vendorEnterprise.uu
  4229. });
  4230. }
  4231. }
  4232. });
  4233. $rootScope.tenderVendor = $scope.vendors;
  4234. }, function () {
  4235. });
  4236. }, function () {
  4237. });
  4238. };
  4239. // 删除一个供应商
  4240. $scope.removeVendor = function (index) {
  4241. $scope.vendors.splice(index, 1);
  4242. };
  4243. $scope.removeChecked = function () {
  4244. if ($scope.vendors.length > 0) {
  4245. $scope.vendors = [];
  4246. $rootScope.tenderVendor = '';
  4247. }
  4248. }
  4249. // 物料信息
  4250. $scope.tableParams = new ngTableParams({
  4251. page: 1,
  4252. count: 20,
  4253. sorting: {
  4254. id: 'desc'
  4255. }
  4256. }, {
  4257. total: 0,
  4258. counts: [5, 10, 25, 50],
  4259. getData: function ($defer, params) {
  4260. $scope.loading = true;
  4261. var pageParams = params.url();
  4262. pageParams.keyword = $scope.keyword;
  4263. $scope.tip = $scope.keyword;
  4264. pageParams.searchFilter = $scope.searchFilter;
  4265. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4266. $scope.loading = false;
  4267. if (page) {
  4268. params.total(page.totalElement);
  4269. $scope.total = page.totalElement;
  4270. $defer.resolve(page.content);
  4271. }
  4272. }, function (response) {
  4273. $scope.loading = false;
  4274. toaster.pop('error', '数据加载失败', response.data);
  4275. });
  4276. }
  4277. });
  4278. // 搜索框回车
  4279. $scope.onSearch = function (keyword) {
  4280. // 每次搜索重置获取数据方法
  4281. $scope.searchMethod = false;
  4282. if(keyword != null && keyword != '') {
  4283. $scope.searchMethod = true;
  4284. }
  4285. $scope.tableParams.page(1);
  4286. $scope.tableParams.reload();
  4287. };
  4288. $scope.inquiry.inquiryItems = [];
  4289. var prod = {
  4290. cmpCode: null,
  4291. prodTitle: null,
  4292. inbrand: null,
  4293. toDate: null,
  4294. unit: 'PCS',
  4295. needquantity: null
  4296. };
  4297. $scope.inquiry.inquiryItems.push(prod);
  4298. // 联想词start
  4299. // 获取品牌联想词
  4300. $scope.getSimilarBrands = function (value) {
  4301. if (value) {
  4302. // 获取品牌联想词
  4303. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  4304. return data.map(function (item) {
  4305. return item;
  4306. });
  4307. });
  4308. }
  4309. };
  4310. // 获取产品型号联想词
  4311. $scope.getSimilarCodes = function (value) {
  4312. if (value) {
  4313. // 获取产品型号联想词
  4314. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  4315. return data.map(function (item) {
  4316. return item;
  4317. })
  4318. });
  4319. }
  4320. };
  4321. $scope.selectKind = function (prod) {
  4322. var submit = [];
  4323. $modal.open({
  4324. animation: true,
  4325. size: 'lg',
  4326. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  4327. controller: 'ProdKindChooseCtrl',
  4328. resolve: {
  4329. actives: function () {
  4330. return $scope.actives;
  4331. }
  4332. }
  4333. }).result.then(function (data) {
  4334. $scope.actives = data.actives;
  4335. var size = data.actives.length;
  4336. submit.gradeOneKiName = '';
  4337. submit.gradeTwoKiName = '';
  4338. submit.gradeThreeKiName = '';
  4339. if (size > 0) {
  4340. submit.gradeOneKiName = $scope.actives[0].nameCn;
  4341. prod.prodTitle = submit.gradeOneKiName;
  4342. if (size > 1) {
  4343. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  4344. prod.prodTitle = submit.gradeTwoKiName;
  4345. if (size > 2) {
  4346. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  4347. prod.prodTitle = submit.gradeThreeKiName;
  4348. }
  4349. }
  4350. }
  4351. }, function () {
  4352. });
  4353. };
  4354. // 点击联想词获取品牌信息
  4355. $scope.onAssociateBrandClick = function (brand, prod) {
  4356. if (brand instanceof String) {
  4357. prod.inbrand = brand;
  4358. } else if (brand instanceof Object) {
  4359. prod.inbrand = brand.brandCn;
  4360. }
  4361. };
  4362. // 打开品牌选择的模态框
  4363. $scope.selectBrand = function (prod) { //打开模态
  4364. var modalInstance = $modal.open({
  4365. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  4366. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  4367. });
  4368. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  4369. });
  4370. modalInstance.result.then(function (brand) {
  4371. prod.inbrand = brand.nameCn;
  4372. }, function (reason) {
  4373. });
  4374. };
  4375. // 点击联想词获取器件信息 带入产品分类和品牌
  4376. $scope.onAssociateCmpClick = function (cmp, prod) {
  4377. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  4378. $scope.component = data;
  4379. prod.cmpCode = data.code;
  4380. prod.prodTitle = data.kind.nameCn;
  4381. prod.inbrand = data.brand.nameCn;
  4382. }, function (res) {
  4383. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  4384. })
  4385. };
  4386. //联想词end
  4387. // 导入商品信息
  4388. $scope.uplodaByBatch = function () {
  4389. var modalInstance = $modal.open({
  4390. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  4391. controller: 'PurcInquiryUploadCtrl',
  4392. size: 'lg',
  4393. resolve: {}
  4394. });
  4395. modalInstance.result.then(function (data) {
  4396. angular.forEach(data, function (prod) {
  4397. $scope.inquiry.inquiryItems.push(prod);
  4398. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4399. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4400. $scope.inquiry.inquiryItems.splice(i, 1);
  4401. }
  4402. }
  4403. })
  4404. }, function () {
  4405. });
  4406. }
  4407. //增加商品
  4408. $scope.add = function () {
  4409. $scope.inquiry.inquiryItems.push(
  4410. {
  4411. cmpCode: null,
  4412. prodTitle: null,
  4413. unit: 'PCS',
  4414. ibrand: null,
  4415. toDate: null,
  4416. needquantity: null
  4417. });
  4418. };
  4419. //删除商品
  4420. $scope.del = function (index) {
  4421. $scope.inquiry.inquiryItems.splice(index, 1);
  4422. };
  4423. $scope.check = function (product) {
  4424. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4425. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  4426. $scope.inquiry.inquiryItems.splice(i, 1);
  4427. }
  4428. }
  4429. $scope.inquiry.inquiryItems.push({
  4430. cmpCode: product.cmpCode, prodTitle: product.title, spec: product.spec, unit: product.unit,
  4431. currency: null, toDate: null, needquantity: null, productId: product.id, inbrand: product.brand
  4432. });
  4433. }
  4434. $scope.getMinDate = function (item) {
  4435. return $filter('date')(new Date, 'yyyy-MM-dd');
  4436. };
  4437. $scope.openDatePicker = function ($event, openParam, index) {
  4438. $event.preventDefault();
  4439. $event.stopPropagation();
  4440. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  4441. };
  4442. $scope.openEndDatePicker = function ($event, item, openParam) {
  4443. $event.preventDefault();
  4444. $event.stopPropagation();
  4445. item[openParam] = !item[openParam];
  4446. };
  4447. $scope.ifrepeat = false;
  4448. // 保存
  4449. $scope.save = function () {
  4450. $scope.loading = true;
  4451. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4452. $scope.item = $scope.inquiry.inquiryItems[i];
  4453. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4454. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4455. if (i != j) {
  4456. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4457. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4458. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4459. $scope.ifrepeat = true;
  4460. }
  4461. }
  4462. }
  4463. }
  4464. if (!$scope.ifrepeat) {
  4465. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4466. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4467. if ($scope.vendors.length > 0) {
  4468. $upload.upload({
  4469. url: 'purc/inquiry/save/withVendor',
  4470. file: file,
  4471. method: 'POST',
  4472. data: {
  4473. inquiry: $scope.inquiry,
  4474. contacts: $scope.vendors
  4475. },
  4476. }).success(function (data) {
  4477. $scope.loading = false;
  4478. if (data.success) {
  4479. toaster.pop('success', '提示', data.success);
  4480. $timeout(function () {
  4481. $rootScope.active = 'todo';
  4482. window.location.hash = "#/purc/inquiry_unapply";
  4483. }, 500);
  4484. }
  4485. if (data.error) {
  4486. toaster.pop('error', '提示', data.error);
  4487. }
  4488. }).error(function (data, status, headers, config) {
  4489. $scope.loadingShow = false;
  4490. if (status == 403) { // 抛异常专用
  4491. toaster.pop('error', '操作失败', data);
  4492. } else {
  4493. toaster.pop('error', '操作失败', data.error);
  4494. }
  4495. });
  4496. } else {
  4497. toaster.pop('info', '提示', '请先选择供应商');
  4498. }
  4499. } else {
  4500. $upload.upload({
  4501. url: 'purc/inquiry/save/withoutVendor',
  4502. file: file,
  4503. method: 'POST',
  4504. data: {
  4505. inquiry: $scope.inquiry,
  4506. },
  4507. }).success(function (data) {
  4508. $scope.loading = false;
  4509. if (data.success) {
  4510. toaster.pop('success', '提示', data.success);
  4511. $timeout(function () {
  4512. $rootScope.active = 'done';
  4513. window.location.hash = "#/baseInfo/inquiryList";
  4514. }, 500);
  4515. }
  4516. if (data.error) {
  4517. toaster.pop('error', '提示', data.error);
  4518. }
  4519. }).error(function (data, status, headers, config) {
  4520. $scope.loadingShow = false;
  4521. if (status == 403) { // 抛异常专用
  4522. toaster.pop('error', '操作失败', data);
  4523. } else {
  4524. toaster.pop('error', '操作失败', data.error);
  4525. }
  4526. });
  4527. }
  4528. } else {
  4529. $scope.loading = false;
  4530. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4531. }
  4532. }
  4533. // 保存并提交
  4534. $scope.submit = function () {
  4535. $scope.loading = true;
  4536. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  4537. $scope.item = $scope.inquiry.inquiryItems[i];
  4538. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  4539. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  4540. if (i != j) {
  4541. if ($scope.item.prodCode == $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  4542. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  4543. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  4544. $scope.ifrepeat = true;
  4545. }
  4546. }
  4547. }
  4548. }
  4549. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  4550. if (!$scope.ifrepeat) {
  4551. if ($scope.inquiry.isOpen == 0) { // 指定询价
  4552. if ($scope.vendors.length > 0) {
  4553. $upload.upload({
  4554. url: 'purc/inquiry/submit/withVendor',
  4555. file: file,
  4556. method: 'POST',
  4557. data: {
  4558. inquiry: $scope.inquiry,
  4559. contacts: $scope.vendors
  4560. },
  4561. }).success(function (data) {
  4562. $scope.loading = false;
  4563. if (data.success) {
  4564. toaster.pop('success', '提示', data.success);
  4565. $timeout(function () {
  4566. window.location.hash = "#/purc/purchaseinquiry";
  4567. }, 500);
  4568. }
  4569. if (data.error) {
  4570. toaster.pop('error', '提示', data.error);
  4571. }
  4572. }).error(function (data, status, headers, config) {
  4573. $scope.loadingShow = false;
  4574. if (status == 403) { // 抛异常专用
  4575. toaster.pop('error', '操作失败', data);
  4576. } else {
  4577. toaster.pop('error', '操作失败', data.error);
  4578. }
  4579. });
  4580. } else {
  4581. toaster.pop('info', '提示', '请先选择供应商');
  4582. }
  4583. } else {
  4584. $upload.upload({
  4585. url: 'purc/inquiry/submit/withoutVendor',
  4586. file: file,
  4587. method: 'POST',
  4588. data: {
  4589. inquiry: $scope.inquiry,
  4590. },
  4591. }).success(function (data) {
  4592. $scope.loading = false;
  4593. if (data.success) {
  4594. toaster.pop('success', '提示', data.success);
  4595. $timeout(function () {
  4596. window.location.hash = "#/baseInfo/inquiryList";
  4597. }, 500);
  4598. }
  4599. if (data.error) {
  4600. toaster.pop('error', '提示', data.error);
  4601. }
  4602. }).error(function (data, status, headers, config) {
  4603. $scope.loadingShow = false;
  4604. if (status == 403) { // 抛异常专用
  4605. toaster.pop('error', '操作失败', data);
  4606. } else {
  4607. toaster.pop('error', '操作失败', data.error);
  4608. }
  4609. });
  4610. }
  4611. } else {
  4612. $scope.loading = false;
  4613. toaster.pop('error', '提示', '存在相同条件的物料信息');
  4614. }
  4615. }
  4616. $scope.previewShow = false;
  4617. $scope.pdfShow = false;
  4618. $scope.noneFileShow = true;
  4619. $scope.$watch('myFiles', function () {
  4620. if ($scope.myFiles) {
  4621. $scope.noneFileShow = false;
  4622. var file = $scope.myFiles[0];
  4623. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  4624. $scope.pdfShow = true;
  4625. $scope.previewShow = false;
  4626. $scope.imgPreviewName = file.name;
  4627. } else {
  4628. if (typeof(Worker) !== "undefined") {//支持HTML5
  4629. $scope.imgPreview = getObjectURL(file);
  4630. $scope.imgPreviewName = file.name;
  4631. } else {//不支持HTML5
  4632. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  4633. $scope.imgPreviewName = file.name;
  4634. }
  4635. $scope.previewShow = true;
  4636. $scope.pdfShow = false;
  4637. }
  4638. } else {
  4639. $scope.noneFileShow = true;
  4640. $scope.previewShow = false;
  4641. $scope.pdfShow = false;
  4642. }
  4643. });
  4644. //建立一个可存取到该file的url
  4645. var getObjectURL = function (file) {
  4646. var url = null;
  4647. if (window.createObjectURL != undefined) { // basic
  4648. url = window.createObjectURL(file);
  4649. } else if (window.URL != undefined) { // mozilla(firefox)
  4650. url = window.URL.createObjectURL(file);
  4651. } else if (window.webkitURL != undefined) { // webkit or chrome
  4652. url = window.webkitURL.createObjectURL(file);
  4653. }
  4654. return url;
  4655. };
  4656. }]);
  4657. /**
  4658. * 代采订单批量导入
  4659. */
  4660. app.controller('PurcInquiryUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  4661. // 通过excel批量上传物料
  4662. $scope.result = null;
  4663. $scope.upload = function () {
  4664. var file = $scope.myFiles[0];
  4665. $upload.upload({
  4666. url: 'purc/inquiry/release/excel',
  4667. file: file,
  4668. method: 'POST'
  4669. }).success(function (data) {
  4670. $scope.result = data;
  4671. $scope.success = $scope.result.success;
  4672. $scope.total = $scope.result.total;
  4673. $scope.alters = $scope.result.alters;
  4674. }).error(function (response) {
  4675. toaster.pop('error', response.data || response);
  4676. });
  4677. };
  4678. // 查看范例
  4679. $scope.showImg = function () {
  4680. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  4681. box.show();
  4682. box.find('img').attr('src', src);
  4683. box.find('a').click(function () {
  4684. box.hide();
  4685. });
  4686. box.dblclick(function () {
  4687. box.hide();
  4688. });
  4689. };
  4690. // 下载模板
  4691. $scope.download = function () {
  4692. window.location.href = 'purc/inquiry/upload/template';
  4693. };
  4694. $scope.enSure = function () {
  4695. $modalInstance.close($scope.result.items);
  4696. }
  4697. $scope.cancel = function () {
  4698. $modalInstance.dismiss();
  4699. }
  4700. }]);
  4701. // 平台询价单(已提交)
  4702. app.controller('PurchaseInquiryCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'PurchaseInquiry', '$rootScope', 'CurrentRole', function ($scope, $filter, ngTableParams, toaster, BaseService, PurchaseInquiry, $rootScope, CurrentRole) {
  4703. $scope.status = 'InquirySubmit';
  4704. BaseService.scrollBackToTop();
  4705. // 获取当前用户是否为普通用户
  4706. CurrentRole.isUser({}, {}, function (data) {
  4707. $scope.isUser = data.isUser;
  4708. });
  4709. if ($rootScope.active) {
  4710. $scope.active = $rootScope.active;
  4711. $rootScope.active = null;
  4712. } else {
  4713. $scope.active = 'todo';
  4714. }
  4715. $scope.agreedText = '全部';
  4716. $scope.dateZoneText = '一个月内';
  4717. $scope.condition = {dateZone: 1};
  4718. /* 时间筛选初始化*/
  4719. var fromDate = new Date();
  4720. var toDate = new Date();
  4721. fromDate.setMonth(fromDate.getMonth() - 1);
  4722. fromDate.setHours(0, 0, 0, 0);
  4723. toDate.setHours(23, 59, 59, 999);
  4724. $scope.condition.dateFrom = fromDate;
  4725. $scope.condition.dateTo = toDate;
  4726. $scope.changeAgreed = function (agreed) {
  4727. $scope.condition.agreed = agreed;
  4728. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  4729. $scope.condition.$agreedOpen = false;
  4730. };
  4731. $scope.changeDateZone = function (zone) {
  4732. $scope.condition.dateZone = zone;
  4733. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  4734. $scope.condition.$dateZoneOpen = false;
  4735. getDateCondition(zone, $scope.condition);
  4736. $scope.tableParams.page(1);
  4737. $scope.tableParams.reload();
  4738. };
  4739. $scope.setActive = function (state) {
  4740. if ($scope.active != state) {
  4741. $scope.active = state;
  4742. if ($scope.tableParams.page() == 1) {
  4743. $scope.tableParams.reload();
  4744. } else {
  4745. $scope.tableParams.page(1);
  4746. }
  4747. }
  4748. }
  4749. var getService = function () {
  4750. return PurchaseInquiry;
  4751. };
  4752. $scope.tableParams = new ngTableParams({
  4753. page: 1,
  4754. count: 20,
  4755. sorting: {
  4756. 'inquiry.date': 'desc',
  4757. 'inquiry.enterprise.enName': 'asc',
  4758. 'inquiry.code': 'asc'
  4759. }
  4760. }, {
  4761. total: 0,
  4762. counts: [5, 10, 25, 50],
  4763. getData: function ($defer, params) {
  4764. $scope.loading = true;
  4765. var pageParams = params.url();
  4766. var realActive = {};
  4767. pageParams.searchFilter = {
  4768. keyword: $scope.keyword,
  4769. fromDate: getDateTime($scope.condition.dateFrom),
  4770. endDate: getDateTime($scope.condition.dateTo)
  4771. };
  4772. if ($scope.active == 'overdue') {
  4773. $scope.active = 'end';
  4774. }
  4775. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  4776. $scope.loading = false;
  4777. if (page) {
  4778. params.total(page.totalElement);
  4779. $defer.resolve(page.content);
  4780. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  4781. }
  4782. }, function (response) {
  4783. $scope.loading = false;
  4784. toaster.pop('error', '数据加载失败', response.data);
  4785. });
  4786. }
  4787. });
  4788. //获得各分类未阅读数量
  4789. var getUnreadCount = function () {
  4790. PurchaseInquiry.getUnreadCount(null, function(data){
  4791. $scope.unread = data;
  4792. });
  4793. };
  4794. getUnreadCount();
  4795. //设置单据已读
  4796. $scope.setOrdersRead = function (id) {
  4797. // 如果单据本身已读,则不发送请求修改数据
  4798. if (!$scope.isUnread(id)){
  4799. return;
  4800. }
  4801. var sourceId = [];
  4802. sourceId.push(id);
  4803. PurchaseInquiry.setRead({}, sourceId, function (message) {
  4804. getUnreadIds();
  4805. getUnreadCount();
  4806. });
  4807. };
  4808. //获得未读单据id
  4809. var getUnreadIds = function (){
  4810. PurchaseInquiry.getUnreadIds({}, "", function (message) {
  4811. $scope.unreadCode = message.content;
  4812. });
  4813. };
  4814. getUnreadIds();
  4815. //判断单据是否未读
  4816. $scope.isUnread = function (id){
  4817. for (var i in $scope.unreadCode) {
  4818. if (id == $scope.unreadCode[i]) {
  4819. return true;
  4820. }
  4821. }
  4822. };
  4823. $scope.openDatePicker = function ($event, item, openParam) {
  4824. $event.preventDefault();
  4825. $event.stopPropagation();
  4826. item[openParam] = !item[openParam];
  4827. };
  4828. $scope.openFilterDatePicker = function ($event, item, openParam) {
  4829. $event.preventDefault();
  4830. $event.stopPropagation();
  4831. item[openParam] = !item[openParam];
  4832. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  4833. $scope.tableParams.reload();
  4834. }
  4835. };
  4836. // 搜索框回车
  4837. $scope.onSearch = function () {
  4838. $scope.tableParams.page(1);
  4839. $scope.tableParams.reload();
  4840. };
  4841. // 采纳
  4842. $scope.accept = function (id) {
  4843. PurchaseInquiry.accept({id: id}, {}, function (data) {
  4844. if (data.success) {
  4845. toaster.pop('success', '提示', data.success);
  4846. $scope.tableParams.reload();
  4847. }
  4848. if (data.error) {
  4849. toaster.pop('error', '提示', data.error);
  4850. }
  4851. }, function (response) {
  4852. toaster.pop('error', '提示', response.data);
  4853. })
  4854. };
  4855. // 拒绝
  4856. $scope.refuse = function (id) {
  4857. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  4858. if (data.success) {
  4859. toaster.pop('success', '提示', data.success);
  4860. $scope.tableParams.reload();
  4861. }
  4862. if (data.error) {
  4863. toaster.pop('error', '提示', data.error);
  4864. }
  4865. }, function (response) {
  4866. toaster.pop('error', '提示', response.data);
  4867. })
  4868. }
  4869. // 导出
  4870. $scope.exportXls = function () {
  4871. PurchaseInquiry.exportXls({}, {}, function (data) {
  4872. if (data.success){
  4873. window.location.href = 'purc/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  4874. }
  4875. }, function (response) {
  4876. toaster.pop('error', '数据加载失败', response.data);
  4877. });
  4878. }
  4879. }]);
  4880. // 平台询价单(未提交)
  4881. app.controller('UnapplyInquiryCtrl', ['$scope', 'PurchaseInquiry', 'ngTableParams', 'BaseService', 'toaster', '$rootScope', function ($scope, PurchaseInquiry, ngTableParams, BaseService, toaster, $rootScope) {
  4882. BaseService.scrollBackToTop();
  4883. if ($rootScope.active = 'done') {
  4884. $scope.active = 'done';
  4885. $rootScope.active = '';
  4886. }
  4887. if ($rootScope.active = 'todo') {
  4888. $scope.active = 'todo';
  4889. $rootScope.active = '';
  4890. }
  4891. var getService = function () {
  4892. if ($scope.active == 'todo') {
  4893. return PurchaseInquiry.getUnapply;
  4894. }
  4895. if ($scope.active == 'done') {
  4896. return PurchaseInquiry.getSubmit;
  4897. }
  4898. }
  4899. $scope.setActive = function (state) {
  4900. if ($scope.active != state) {
  4901. $scope.active = state;
  4902. if ($scope.tableParams.page() == 1) {
  4903. $scope.tableParams.reload();
  4904. } else {
  4905. $scope.tableParams.page(1);
  4906. }
  4907. }
  4908. }
  4909. $scope.tableParams = new ngTableParams({
  4910. page: 1,
  4911. count: 20,
  4912. sorting: {
  4913. 'date': 'desc',
  4914. 'enterprise.enName': 'asc',
  4915. 'code': 'asc'
  4916. }
  4917. }, {
  4918. total: 0,
  4919. counts: [5, 10, 25, 50],
  4920. getData: function ($defer, params) {
  4921. $scope.loading = true;
  4922. var pageParams = params.url();
  4923. var realActive = {};
  4924. if ($scope.active == 'overdue') {
  4925. $scope.active = 'end';
  4926. }
  4927. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  4928. $scope.loading = false;
  4929. if (page) {
  4930. params.total(page.totalElements);
  4931. $defer.resolve(page.content);
  4932. }
  4933. }, function (response) {
  4934. $scope.loading = false;
  4935. toaster.pop('error', '数据加载失败', response.data);
  4936. });
  4937. }
  4938. });
  4939. // 删除明细
  4940. $scope.deleteById = function (id) {
  4941. PurchaseInquiry.deleteById({id: id}, {}, function (data) {
  4942. toaster.pop('success', '提示', '删除成功');
  4943. $scope.tableParams.reload();
  4944. }, function (response) {
  4945. toaster.pop('error', '提示', response.data);
  4946. });
  4947. }
  4948. // 删除主表
  4949. $scope.clearOrder = function (id) {
  4950. PurchaseInquiry.clearOrder({id: id}, {}, function (data) {
  4951. toaster.pop('success', '提示', '删除成功');
  4952. $scope.tableParams.reload();
  4953. }, function (response) {
  4954. toaster.pop('error', '提示', response.data);
  4955. });
  4956. }
  4957. // 提交
  4958. $scope.submit = function (id) {
  4959. PurchaseInquiry.submitUnapply({id: id}, {}, function (data) {
  4960. toaster.pop('success', '提示', '单据提交成功');
  4961. $scope.active = 'done';
  4962. $scope.tableParams.reload();
  4963. }, function (response) {
  4964. toaster.pop('error', '提示', response.data);
  4965. })
  4966. }
  4967. // 发布公共询价
  4968. $scope.publish = function (id) {
  4969. PurchaseInquiry.publishInquiry({id: id}, {}, function (data) {
  4970. toaster.pop('success', '提示', data.success);
  4971. $scope.active = 'done';
  4972. $scope.tableParams.reload();
  4973. }, function (response) {
  4974. toaster.pop('error', '提示', response.data);
  4975. })
  4976. }
  4977. }]);
  4978. // 公共询价列表
  4979. 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) {
  4980. BaseService.scrollBackToTop();
  4981. /**
  4982. * 改变单据日期范围
  4983. */
  4984. var getTenderDateCondition = function (zone, condition) {
  4985. var date = new Date();
  4986. if (zone == -1) {
  4987. condition.dateFrom = null;
  4988. condition.dateTo = null;
  4989. } else if (zone == 7) { // 一星期内
  4990. date.setHours(0, 0, 0 ,0);
  4991. date.setDate(date.getDate() - 7);
  4992. condition.dateFrom = date;
  4993. var ndate = new Date();
  4994. ndate.setHours(23, 59, 59 ,999);
  4995. ndate.setDate(ndate.getDate() - 1);
  4996. condition.dateTo = ndate;
  4997. } else if (zone == 1) { // 一个月内
  4998. date.setMonth(date.getMonth() - 1);
  4999. condition.dateFrom = date;
  5000. condition.dateTo = new Date();
  5001. } else if (zone == 3) { // 三个月内
  5002. date.setMonth(date.getMonth() - 3);
  5003. condition.dateFrom = date;
  5004. condition.dateTo = new Date();
  5005. } else if (zone == 6) { // 半年内
  5006. date.setMonth(date.getMonth() - 6);
  5007. condition.dateFrom = date;
  5008. condition.dateTo = new Date();
  5009. } else { // 一年内
  5010. date.setYear(date.getYear() - 1);
  5011. condition.dateFrom = date;
  5012. condition.dateTo = new Date();
  5013. }
  5014. };
  5015. $scope.active = 'all';
  5016. $scope.dateZoneText = '不限';
  5017. $scope.deliveryZoneText = '不限';
  5018. $scope.condition = {dateZone: -1};
  5019. $scope.changeDateZone = function (zone) {
  5020. $scope.condition.dateZone = zone;
  5021. $scope.condition.$dateZoneOpen = false;
  5022. getTenderDateCondition(zone, $scope.condition);
  5023. $scope.tableParams.page(1);
  5024. $scope.tableParams.reload();
  5025. };
  5026. $scope.openDatePicker = function ($event, item, openParam) {
  5027. $event.preventDefault();
  5028. $event.stopPropagation();
  5029. item[openParam] = !item[openParam];
  5030. };
  5031. $scope.parseDate = function (dateStr) {
  5032. if (dateStr)
  5033. return Date.parse(dateStr, 'yyyy-MM-dd');
  5034. return new Date();
  5035. };
  5036. $scope.isOverDue = function (date) {
  5037. if (date) {
  5038. var ndate = new Date();
  5039. ndate.setHours(23, 59, 59 ,999);
  5040. ndate.setDate(ndate.getDate());
  5041. var timestamp = Date.parse(ndate);
  5042. if (date > timestamp) {
  5043. return true;
  5044. } else {
  5045. return false;
  5046. }
  5047. } else {
  5048. return true;
  5049. }
  5050. }
  5051. // 选择查找日期
  5052. $scope.onDateCondition = function () {
  5053. $scope.tableParams.page(1);
  5054. $scope.tableParams.reload();
  5055. };
  5056. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  5057. var getState = function (active) {
  5058. var fn = 'getOpenAll';
  5059. switch (active) {
  5060. case 'all':
  5061. fn = 'getOpenAll';
  5062. break;
  5063. case 'todo':
  5064. fn = 'getOpenTodo';
  5065. break;
  5066. case 'end':
  5067. fn = 'getOpenEnd';
  5068. break;
  5069. }
  5070. return fn;
  5071. };
  5072. customer.distribute({}, function(data) {
  5073. $scope.customer = data;
  5074. });
  5075. $scope.setActive = function (state) {
  5076. if ($scope.active != state) {
  5077. $scope.active = state;
  5078. if ($scope.active == 'all') {
  5079. $scope.distribute = null;
  5080. $scope.remind = false;
  5081. } else if ($scope.active == 'customer') {
  5082. $scope.distribute = $scope.customer;
  5083. if ($scope.distribute.length == 0) {
  5084. $scope.distribute = [0];
  5085. }
  5086. $scope.remind = false;
  5087. } else if ($scope.active == 'remind') {
  5088. $scope.remind = true;
  5089. }
  5090. if ($scope.tableParams.page() == 1) {
  5091. $scope.tableParams.reload();
  5092. } else {
  5093. $scope.tableParams.page(1);
  5094. }
  5095. }
  5096. };
  5097. var getService = function () {
  5098. return publicInquiryList.getInquirylist;
  5099. }
  5100. $scope.tableParams = new ngTableParams({
  5101. page: 1,
  5102. count: 20,
  5103. sorting: {
  5104. // 'tender.endDate': 'desc',
  5105. // 'tender.enterprise.enName': 'asc',
  5106. // 'tender.code': 'asc'
  5107. }
  5108. }, {
  5109. total: 0,
  5110. counts: [10, 25, 50, 100],
  5111. getData: function ($defer, params) {
  5112. $scope.loading = true;
  5113. var pageParams = params.url();
  5114. // var realActive = {};
  5115. pageParams.searchFilter = { // 筛选条件
  5116. keyword: $scope.keyword,
  5117. fromDate: getDateTime($scope.condition.dateFrom),
  5118. endDate: getDateTime($scope.condition.dateTo)
  5119. };
  5120. AccountEnterprise.get({}, function(data) {
  5121. $scope.currentEn = data;
  5122. publicInquiry.getUrl({}, function(data) {
  5123. $scope.url = data.url;
  5124. if (!$scope.remind) {// 非推荐信息
  5125. $http({
  5126. method: 'get',
  5127. dataType: 'json',
  5128. url: $scope.url + '/inquiry/public',
  5129. params: {pageNumber: pageParams.page, pageSize: pageParams.count, enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  5130. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo), distribute: $scope.distribute, remind: $scope.remind}
  5131. }).success(function (response) {
  5132. $scope.loading = false;
  5133. if (response) {
  5134. params.total(response.totalElements);
  5135. $defer.resolve(response.content);
  5136. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5137. }
  5138. }).error(function (err) {
  5139. $scope.loading = false;
  5140. toaster.pop('error', '数据加载失败', err);
  5141. });
  5142. } else {// 推荐报价信息
  5143. AuthenticationService.getAuthentication().success(function (data) {
  5144. $scope.loading = false;
  5145. $scope.thisUser = data;
  5146. $http({
  5147. method: 'get',
  5148. dataType: 'json',
  5149. url: $scope.url + '/inquiry/sale/remind',
  5150. params: {pageNumber: pageParams.page, pageSize: pageParams.count, useruu: $scope.thisUser.userUU, enuu: $scope.currentEn.uu,
  5151. keyword: $scope.keyword, fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)}
  5152. }).success(function (response) {
  5153. $scope.loading = false;
  5154. if (response) {
  5155. params.total(response.totalElements);
  5156. $defer.resolve(response.content);
  5157. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5158. }
  5159. }).error(function (err) {
  5160. $scope.loading = false;
  5161. toaster.pop('error', '数据加载失败', err);
  5162. });
  5163. });
  5164. }
  5165. // 顶部滚动消息
  5166. $http({
  5167. method: 'get',
  5168. url: $scope.url + '/inquiry/public/messageList',
  5169. params: {enuu: $scope.currentEn.uu, size: 10},
  5170. dataType: 'json'
  5171. }).success(function(data) {
  5172. $scope.message = data;
  5173. }).error(function(error) {
  5174. });
  5175. });
  5176. });
  5177. }
  5178. });
  5179. $scope.toDetail = function (item) {
  5180. if (item.quoted == 0) {
  5181. window.location.hash = '#/baseInfo/inquiryList/' + item.id;
  5182. } else {
  5183. window.open("#/sale/pubinquiry/" + item.quteId);
  5184. }
  5185. };
  5186. // 转客户询价
  5187. $scope.qute = function (remind) {
  5188. $http({
  5189. method: 'get',
  5190. dataType: 'json',
  5191. url: $scope.url + '/inquiry/sale/quote',
  5192. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  5193. }).success(function (response) {
  5194. $scope.loading = false;
  5195. if (response.inquiry != null) {
  5196. toaster.pop('error', '该单据已报价');
  5197. } else {
  5198. $http({
  5199. method: 'get',
  5200. dataType: 'json',
  5201. url: $scope.url + '/inquiry/public/findItemByItemId',
  5202. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  5203. }).success(function (response) {
  5204. var inquiryItem = response;
  5205. var modalInstance = $modal.open({
  5206. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5207. controller: 'QuoteCtrl',
  5208. size: 'lg',
  5209. resolve: {
  5210. inquiryItem: function () {
  5211. return inquiryItem
  5212. }
  5213. }
  5214. });
  5215. modalInstance.result.then(function (data) {
  5216. $scope.tableParams.reload();
  5217. }, function () {
  5218. });
  5219. }).error(function (error) {
  5220. toaster.pop('error', '数据加载失败', error);
  5221. });
  5222. }
  5223. }).error(function (err) {
  5224. toaster.pop('error', '数据加载失败', err);
  5225. });
  5226. }
  5227. // 跳转详情
  5228. $scope.remindDetail = function(remind) {
  5229. if (remind.newId == null) {
  5230. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  5231. } else {
  5232. window.open("#/sale/pubinquiry/" + remind.newId);
  5233. }
  5234. }
  5235. // 搜索框回车
  5236. $scope.onSearch = function () {
  5237. $scope.tableParams.page(1);
  5238. $scope.tableParams.reload();
  5239. };
  5240. // 转客户询价
  5241. $scope.transtoInquiry = function (inquiryItem) {
  5242. if ($scope.currentEn.uu == inquiryItem.inquiry.enUU) {
  5243. toaster.pop('warning', '不能对自己企业报价');
  5244. } else {
  5245. var modalInstance = $modal.open({
  5246. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5247. controller: 'QuoteCtrl',
  5248. size: 'lg',
  5249. resolve: {
  5250. inquiryItem: function () {
  5251. return inquiryItem
  5252. }
  5253. }
  5254. });
  5255. modalInstance.result.then(function (data) {
  5256. $scope.tableParams.reload();
  5257. }, function () {
  5258. });
  5259. }
  5260. }
  5261. // 跳转到我的报价列表
  5262. $scope.linkToInquiry = function () {
  5263. window.open("#/sale/pubinquiry");
  5264. }
  5265. }]);
  5266. /**
  5267. * 报价操作
  5268. */
  5269. app.controller('QuoteCtrl', ['$scope', 'inquiryItem', 'toaster', 'publicInquiry', '$modalInstance', '$upload', function($scope, inquiryItem, toaster, publicInquiry, $modalInstance, $upload) {
  5270. $scope.inquiryItem = inquiryItem;
  5271. if ($scope.inquiryItem.replies == null || $scope.inquiryItem.replies.length == 0) {
  5272. $scope.inquiryItem.replies = [];
  5273. var reply = {
  5274. lapQty: 0,
  5275. price: null
  5276. };
  5277. $scope.inquiryItem.replies.push(reply);
  5278. }
  5279. $scope.replyPrices = [];
  5280. $scope.replylapQtys = [];
  5281. $scope.replyPrices.push(true);
  5282. $scope.replylapQtys.push(true);
  5283. // 获取默认币别
  5284. publicInquiry.getCurrency({}, function(data) {
  5285. $scope.currencies = data;
  5286. });
  5287. // 增加一列分段报价
  5288. $scope.addStep = function (inquiryItem) {
  5289. var check = true;
  5290. angular.forEach(inquiryItem.replies, function(reply) {
  5291. if (reply.lapQty == null) {
  5292. toaster.pop('error', '提示', '存在未填写分段数量的分段,请先填写分段数量');
  5293. check = false;
  5294. }
  5295. if (check && reply.price == null) {
  5296. toaster.pop('error', '提示', '存在未填写价格的分段,请先填写价格');
  5297. check = false;
  5298. }
  5299. });
  5300. if (check) {
  5301. $scope.replyPrices.push(true);
  5302. if (inquiryItem.replies.length >= 5) {
  5303. toaster.pop('warning', '提示', '最多支持5个分段!');
  5304. } else {
  5305. inquiryItem.replies.push({});
  5306. if (inquiryItem.replies.length != 1) {
  5307. $scope.replyPrices.push(true);
  5308. $scope.replylapQtys.push(true);
  5309. }
  5310. }
  5311. }
  5312. };
  5313. // 删除一列分段报价
  5314. $scope.removeStep = function (inquiryItem, stepIndex) {
  5315. inquiryItem.replies.splice(stepIndex, 1);
  5316. $scope.replyPrices.splice(stepIndex, 1);
  5317. $scope.replylapQtys.splice(stepIndex, 1);
  5318. };
  5319. // 取消,关闭弹出框
  5320. $scope.cancel = function() {
  5321. $modalInstance.dismiss();
  5322. }
  5323. // 保存报价信息
  5324. $scope.save = function(inquiryItem, method) {
  5325. var replies = [];
  5326. // 判断分段数是否合法
  5327. var valid = true;
  5328. var validLapQty = 0;
  5329. angular.forEach(inquiryItem.replies, function (r, i) {
  5330. if ((i > 0 ? r.lapQty : 1) || r.price) {
  5331. replies.push(r);
  5332. }
  5333. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  5334. if (i > 0 && parseInt(r.lapQty) <= parseInt(inquiryItem.replies[i - 1].lapQty) || r.lapQty == null) {
  5335. valid = false;
  5336. validLapQty = r.lapQty;
  5337. }
  5338. });
  5339. inquiryItem.replies = replies;
  5340. $scope.loading = true;
  5341. if (!valid) {
  5342. if (validLapQty) {
  5343. toaster.pop('error', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  5344. } else {
  5345. toaster.pop('error', '提示', '分段数量不合法,不能报价!');
  5346. }
  5347. } else {
  5348. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  5349. $upload.upload({
  5350. url: 'pubInquiry/turnToQuotation',
  5351. file: file,
  5352. method: 'POST',
  5353. data: {
  5354. item: inquiryItem,
  5355. method: method
  5356. }
  5357. }).success(function (data) {
  5358. if (data.item) {
  5359. item = data.item;
  5360. }
  5361. $scope.loading = false;
  5362. toaster.pop('info', '提示', '报价成功');
  5363. $modalInstance.close();
  5364. }).error(function (data) {
  5365. $scope.loading = false;
  5366. toaster.pop('error', '附件上传失败');
  5367. });
  5368. }
  5369. }
  5370. $scope.previewShow = false;
  5371. $scope.pdfShow = false;
  5372. $scope.noneFileShow = true;
  5373. $scope.$watch('myFiles', function () {
  5374. if ($scope.myFiles) {
  5375. $scope.noneFileShow = false;
  5376. var file = $scope.myFiles[0];
  5377. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  5378. $scope.pdfShow = true;
  5379. $scope.previewShow = false;
  5380. $scope.imgPreviewName = file.name;
  5381. } else {
  5382. if (typeof(Worker) !== "undefined") {//支持HTML5
  5383. $scope.imgPreview = getObjectURL(file);
  5384. $scope.imgPreviewName = file.name;
  5385. } else {//不支持HTML5
  5386. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  5387. $scope.imgPreviewName = file.name;
  5388. }
  5389. $scope.previewShow = true;
  5390. $scope.pdfShow = false;
  5391. }
  5392. } else {
  5393. $scope.noneFileShow = true;
  5394. $scope.previewShow = false;
  5395. $scope.pdfShow = false;
  5396. }
  5397. });
  5398. //建立一个可存取到该file的url
  5399. var imgurl = null;
  5400. var getObjectURL = function (file) {
  5401. var url = null;
  5402. if (window.createObjectURL != undefined) { // basic
  5403. url = window.createObjectURL(file);
  5404. } else if (window.URL != undefined) { // mozilla(firefox)
  5405. url = window.URL.createObjectURL(file);
  5406. } else if (window.webkitURL != undefined) { // webkit or chrome
  5407. url = window.webkitURL.createObjectURL(file);
  5408. }
  5409. imgurl = url;
  5410. return url;
  5411. };
  5412. }]);
  5413. /**
  5414. * 公共询价详情
  5415. */
  5416. 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) {
  5417. BaseService.scrollBackToTop();
  5418. $scope.currentHasBid = false;
  5419. var loadData = function () {
  5420. // 当前企业
  5421. AccountEnterprise.get({}, function (data) {
  5422. $scope.enterprise = data
  5423. publicInquiry.getUrl({}, function(data) {
  5424. var url = data.url;
  5425. $http({
  5426. method: 'get',
  5427. dataType: 'json',
  5428. url: url + '/inquiry/sale/publicInquiry/detail',
  5429. params: {id: $stateParams.id, enuu: $scope.enterprise.uu}
  5430. }).success(function (response) {
  5431. if (response) {
  5432. $scope.inquiryItem = response.inquiryItem;
  5433. }
  5434. }).error(function (err) {
  5435. toaster.pop('error', '数据加载失败', err);
  5436. });
  5437. });
  5438. });
  5439. };
  5440. loadData();
  5441. // 当前时间
  5442. $scope.nowdate = new Date().getTime() - 24 * 3600 * 1000;
  5443. // 当前企业
  5444. AccountEnterprise.get({}, function (data) {
  5445. $scope.enterprise = data;
  5446. });
  5447. $scope.isOverDue = function (date) {
  5448. if (date) {
  5449. var ndate = new Date();
  5450. ndate.setHours(23, 59, 59 ,999);
  5451. ndate.setDate(ndate.getDate());
  5452. var timestamp = Date.parse(ndate);
  5453. if (date > timestamp) {
  5454. return true;
  5455. } else {
  5456. return false;
  5457. }
  5458. } else {
  5459. return true;
  5460. }
  5461. }
  5462. // 转客户询价
  5463. $scope.transtoInquiry = function (inquiryItem) {
  5464. publicInquiry.quotationInfo({id: inquiryItem.id}, function(data) {
  5465. if (data.inquiryItem) { //存在已报价的就不进行报价操作
  5466. toaster.pop('error', '该询价单已已经报价');
  5467. } else {
  5468. var modalInstance = $modal.open({
  5469. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  5470. controller: 'QuoteCtrl',
  5471. size: 'lg',
  5472. resolve: {
  5473. inquiryItem: function () {
  5474. return inquiryItem
  5475. }
  5476. }
  5477. });
  5478. modalInstance.result.then(function (data) {
  5479. $scope.tableParams.reload();
  5480. }, function () {
  5481. });
  5482. }
  5483. });
  5484. }
  5485. }]);
  5486. // 询价单明细
  5487. app.controller('PurcInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurcInquiry, $filter, toaster, CurrentRole) {
  5488. // 获取当前用户是否为普通用户
  5489. CurrentRole.isUser({}, {}, function (data) {
  5490. $scope.isUser = !data.isUser;
  5491. });
  5492. var loadData = function () {
  5493. PurcInquiry.getAll({id: $stateParams.id}, function (data) {
  5494. $scope.newinquiryItems = data;
  5495. var inquiry = data[0].inquiry;
  5496. //inquiry.inquiryItems = data;
  5497. angular.forEach(inquiry.attachs, function (attach) {
  5498. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5499. });
  5500. $scope.inquiry = inquiry;
  5501. });
  5502. };
  5503. loadData();
  5504. $scope.getMinDate = function (item) {
  5505. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5506. };
  5507. $scope.addStep = function (inquiryItem) {
  5508. if (inquiryItem.replies.length >= 10) {
  5509. toaster.pop('warning', '提示', '最多支持10个分段!');
  5510. } else
  5511. inquiryItem.replies.push({});
  5512. };
  5513. $scope.removeStep = function (inquiryItem, stepIndex) {
  5514. inquiryItem.replies.splice(stepIndex, 1);
  5515. };
  5516. $scope.openDatePicker = function ($event, item, openParam) {
  5517. $event.preventDefault();
  5518. $event.stopPropagation();
  5519. item[openParam] = !item[openParam];
  5520. };
  5521. $scope.getHistory = function (item) {
  5522. if (!item.history) {
  5523. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5524. item.history = data;
  5525. });
  5526. }
  5527. };
  5528. $scope.isValid = function (item, withSteps) {
  5529. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5530. if (!withSteps || !bool)
  5531. return bool;
  5532. angular.forEach(item.replies, function (r, i) {
  5533. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5534. });
  5535. return bool;
  5536. };
  5537. $scope.onReplyClick = function (item, withSteps) {
  5538. if (item.vendFromDate instanceof Date) {
  5539. item.vendFromDate = item.vendFromDate.getTime();
  5540. }
  5541. if (item.vendToDate instanceof Date) {
  5542. item.vendToDate = item.vendToDate.getTime();
  5543. }
  5544. if (item.vendFromDate > item.vendToDate) {
  5545. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5546. return;
  5547. }
  5548. var replies = [];
  5549. angular.forEach(item.replies, function (r, i) {
  5550. if ((i > 0 ? r.lapQty : 1) || r.price)
  5551. replies.push(r);
  5552. });
  5553. item.replies = replies;
  5554. if (withSteps) {
  5555. PurcInquiry.reply({itemId: item.id}, item, function () {
  5556. toaster.pop('info', '提示', '报价成功');
  5557. loadData();
  5558. }, function (response) {
  5559. toaster.pop('error', '报价失败', response.data);
  5560. });
  5561. }
  5562. };
  5563. }]);
  5564. // 询价单明细(发出)
  5565. app.controller('PurcInquiryInfoDetailCtrl', ['$scope', '$stateParams', 'PurchaseInquiry', '$filter', 'toaster', 'CurrentRole', function ($scope, $stateParams, PurchaseInquiry, $filter, toaster, CurrentRole) {
  5566. // 获取当前用户是否为普通用户
  5567. CurrentRole.isUser({}, {}, function (data) {
  5568. $scope.isUser = data.isUser;
  5569. });
  5570. var loadData = function () {
  5571. PurchaseInquiry.detail({id: $stateParams.id}, {},function (data) {
  5572. $scope.inquiry = data;
  5573. },function (response) {
  5574. toaster.pop('error', '提示', response.data);
  5575. });
  5576. };
  5577. loadData();
  5578. $scope.getMinDate = function (item) {
  5579. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5580. };
  5581. $scope.nowDate = new Date().getTime();
  5582. $scope.addStep = function (inquiryItem) {
  5583. if (inquiryItem.replies.length >= 10) {
  5584. toaster.pop('warning', '提示', '最多支持10个分段!');
  5585. } else
  5586. inquiryItem.replies.push({});
  5587. };
  5588. $scope.removeStep = function (inquiryItem, stepIndex) {
  5589. inquiryItem.replies.splice(stepIndex, 1);
  5590. };
  5591. $scope.openDatePicker = function ($event, item, openParam) {
  5592. $event.preventDefault();
  5593. $event.stopPropagation();
  5594. item[openParam] = !item[openParam];
  5595. };
  5596. $scope.getHistory = function (item) {
  5597. if (!item.history) {
  5598. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  5599. item.history = data;
  5600. });
  5601. }
  5602. };
  5603. $scope.isValid = function (item, withSteps) {
  5604. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  5605. if (!withSteps || !bool)
  5606. return bool;
  5607. angular.forEach(item.replies, function (r, i) {
  5608. bool = (i > 0 ? r.lapQty : 1) && r.price;
  5609. });
  5610. return bool;
  5611. };
  5612. $scope.onReplyClick = function (item, withSteps) {
  5613. if (item.vendFromDate instanceof Date) {
  5614. item.vendFromDate = item.vendFromDate.getTime();
  5615. }
  5616. if (item.vendToDate instanceof Date) {
  5617. item.vendToDate = item.vendToDate.getTime();
  5618. }
  5619. if (item.vendFromDate > item.vendToDate) {
  5620. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  5621. return;
  5622. }
  5623. var replies = [];
  5624. angular.forEach(item.replies, function (r, i) {
  5625. if ((i > 0 ? r.lapQty : 1) || r.price)
  5626. replies.push(r);
  5627. });
  5628. item.replies = replies;
  5629. if (withSteps) {
  5630. PurcInquiry.reply({itemId: item.id}, item, function () {
  5631. toaster.pop('info', '提示', '报价成功');
  5632. loadData();
  5633. }, function (response) {
  5634. toaster.pop('error', '报价失败', response.data);
  5635. });
  5636. }
  5637. };
  5638. // 采纳
  5639. $scope.accept = function (id) {
  5640. PurchaseInquiry.accept({id: id}, {}, function (data) {
  5641. if (data.success) {
  5642. toaster.pop('success', '提示', data.success);
  5643. loadData();
  5644. }
  5645. if (data.error) {
  5646. toaster.pop('error', '提示', data.error);
  5647. }
  5648. }, function (response) {
  5649. toaster.pop('error', '提示', response.data);
  5650. })
  5651. };
  5652. // 拒绝
  5653. $scope.refuse = function (id) {
  5654. PurchaseInquiry.refuse({id: id}, {}, function (data) {
  5655. if (data.success) {
  5656. toaster.pop('success', '提示', data.success);
  5657. loadData();
  5658. }
  5659. if (data.error) {
  5660. toaster.pop('error', '提示', data.error);
  5661. }
  5662. }, function (response) {
  5663. toaster.pop('error', '提示', response.data);
  5664. })
  5665. }
  5666. }]);
  5667. // 模具询价管理
  5668. app.controller('SaleInquiryMouldCtrl', ['$scope', '$filter', 'PurcInquiryMould', 'ngTableParams', 'toaster', 'BaseService', '$upload', 'PurcInquiryMouldSql', 'CurrentRole', function ($scope, $filter, PurcInquiryMould, ngTableParams, toaster, BaseService, $upload, PurcInquiryMouldSql, CurrentRole) {
  5669. BaseService.scrollBackToTop();
  5670. // 获取当前用户是否为普通用户
  5671. CurrentRole.isUser({}, {}, function (data) {
  5672. $scope.isUser = data.isUser;
  5673. });
  5674. $scope.active = 'todo';
  5675. $scope.agreedText = '全部';
  5676. $scope.dateZoneText = '不限';
  5677. $scope.condition = {dateZone: 1};
  5678. /* 时间筛选初始化*/
  5679. var fromDate = new Date();
  5680. var toDate = new Date();
  5681. fromDate.setMonth(fromDate.getMonth() - 1);
  5682. fromDate.setHours(0, 0, 0, 0);
  5683. toDate.setHours(23, 59, 59, 999);
  5684. $scope.condition.dateFrom = fromDate;
  5685. $scope.condition.dateTo = toDate;
  5686. var inquiryMould_copy = {};
  5687. $scope.changeAgreed = function (agreed) {
  5688. $scope.condition.agreed = agreed;
  5689. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  5690. $scope.condition.$agreedOpen = false;
  5691. };
  5692. $scope.changeDateZone = function (zone) {
  5693. $scope.condition.dateZone = zone;
  5694. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  5695. $scope.condition.$dateZoneOpen = false;
  5696. getDateCondition(zone, $scope.condition);
  5697. $scope.tableParams.page(1);
  5698. $scope.tableParams.reload();
  5699. };
  5700. $scope.setActive = function (state) {
  5701. if ($scope.active != state) {
  5702. $scope.active = state;
  5703. if ($scope.tableParams.page() == 1) {
  5704. $scope.tableParams.reload();
  5705. } else {
  5706. $scope.tableParams.page(1);
  5707. }
  5708. }
  5709. };
  5710. var getService = function () {
  5711. if ($scope.keyword) {
  5712. return PurcInquiryMould;
  5713. } else {
  5714. return PurcInquiryMouldSql;
  5715. }
  5716. };
  5717. $scope.tableParams = new ngTableParams({
  5718. page: 1,
  5719. count: 5
  5720. }, {
  5721. total: 0,
  5722. counts: [5, 10, 25, 50],
  5723. getData: function ($defer, params) {
  5724. $scope.loading = true;
  5725. var pageParams = params.url();
  5726. var realActive = {};
  5727. pageParams.searchFilter = {
  5728. keyword: $scope.keyword,
  5729. fromDate: getDateTime($scope.condition.dateFrom),
  5730. endDate: getDateTime($scope.condition.dateTo)
  5731. };
  5732. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  5733. $scope.loading = false;
  5734. // 用来验证价格修改
  5735. var mould = page.content;
  5736. inquiryMould_copy = angular.copy(mould);
  5737. if (page) {
  5738. params.total(page.totalElement);
  5739. $defer.resolve(page.content);
  5740. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词 $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  5741. }
  5742. }, function (response) {
  5743. $scope.loading = false;
  5744. toaster.pop('error', '数据加载失败', response.data);
  5745. });
  5746. }
  5747. });
  5748. //获得各分类未阅读数量
  5749. var getUnreadCount = function () {
  5750. PurcInquiryMould.getUnreadCount(null, function(data){
  5751. $scope.unread = data;
  5752. });
  5753. };
  5754. getUnreadCount();
  5755. //设置单据已读
  5756. $scope.setOrdersRead = function (id) {
  5757. // 如果单据本身已读,则不发送请求修改数据
  5758. if (!$scope.isUnread(id)){
  5759. return;
  5760. }
  5761. var sourceId = [];
  5762. sourceId.push(id);
  5763. PurcInquiryMould.setRead({}, sourceId, function (message) {
  5764. // $scope.getUnreadIds();
  5765. getUnreadCount();
  5766. });
  5767. };
  5768. $scope.setOrdersReadByState = function () {
  5769. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  5770. return;
  5771. }
  5772. PurcInquiryMould.setReadByState({}, function () {
  5773. getUnreadIds();
  5774. getUnreadCount();
  5775. });
  5776. };
  5777. //获取未读单据id
  5778. var getUnreadIds = function (){
  5779. PurcInquiryMould.getUnreadIds({}, "", function (message) {
  5780. $scope.unreadCode = message.content;
  5781. });
  5782. };
  5783. getUnreadIds();
  5784. //判断单据是否未读
  5785. $scope.isUnread = function (id){
  5786. for (var i in $scope.unreadCode) {
  5787. if (id == $scope.unreadCode[i]) {
  5788. return true;
  5789. }
  5790. }
  5791. };
  5792. $scope.getMinDate = function (item) {
  5793. return $filter('date')(item.inquiryMould.date, 'yyyy-MM-dd');
  5794. };
  5795. $scope.replyPrices = [];
  5796. $scope.replyPrices.push(true);
  5797. // 取消
  5798. $scope.reload = function () {
  5799. $scope.tableParams.reload();
  5800. $scope.canSave = false;
  5801. }
  5802. // 能否保存设置
  5803. $scope.canSave = false;
  5804. // items价格验证
  5805. $scope.verifyItems = function (price, reply) {
  5806. var regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;// ^[0-9]+(\.[0-9]{1,6})?$
  5807. if (regex.test(price) && price != 0) {
  5808. if (price != reply) {
  5809. $scope.canSave = true;
  5810. } else {
  5811. $scope.canSave = false;
  5812. }
  5813. } else {
  5814. $scope.canSave = false;
  5815. }
  5816. }
  5817. // prod下prods价格验证
  5818. $scope.verifyProds = function (price, reply) {
  5819. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  5820. if (regex.test(price) && price != 0) {
  5821. if (price != reply) {
  5822. $scope.canSave = true;
  5823. } else {
  5824. $scope.canSave = false;
  5825. }
  5826. } else {
  5827. $scope.canSave = false;
  5828. }
  5829. }
  5830. //有价格为0或者不符合正则式,则不能报价
  5831. $scope.notZero = function (mould) {
  5832. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5833. angular.forEach(mould.inquiryMouldItems, function (item) {
  5834. if (item.price == 0 || !regex.test(item.price)) {
  5835. $scope.canSave = false;
  5836. }
  5837. angular.forEach(item.inquiryMouldDetails, function (detail) {
  5838. if (detail.price == 0 || !regex.test(detail.price)) {
  5839. $scope.canSave = false;
  5840. }
  5841. })
  5842. });
  5843. }
  5844. $scope.blurPrice = function (price) {
  5845. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  5846. if (!regex.test(price)) {
  5847. toaster.pop('warning', '格式错误', '请输入有效价格');
  5848. }
  5849. }
  5850. // 获取历史报价
  5851. $scope.getHistory = function (mould) {
  5852. if (!mould.history) {
  5853. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  5854. $scope.historyShow = true;
  5855. mould.history = data;
  5856. },function (response) {
  5857. $scope.historyShow = false;
  5858. });
  5859. }
  5860. };
  5861. var uploadAttach = function (mould, file) {
  5862. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  5863. $scope.mould = mould;
  5864. $upload.upload({
  5865. url: 'sale/mould/' + mould.id + '/send',
  5866. method: 'POST',
  5867. file: file,
  5868. data: {
  5869. json: $scope.mould
  5870. }
  5871. }).success(function (res) {
  5872. $scope.mould.sellAttachs.push(res);
  5873. }).error(function (res) {
  5874. });
  5875. }
  5876. $scope.pushFile = function(mould, file) {
  5877. // var file = $scope.myFiles;
  5878. if (file.length > 0) {
  5879. for (var i = 0; i < file.length; i++) {
  5880. console.log(file[i].name);
  5881. var flag = true;
  5882. if (mould.sellAttachs.length > 0) {
  5883. for (var j = 0; j < mould.sellAttachs.length; j++) {
  5884. if (mould.sellAttachs[j].name == file[i].name
  5885. && mould.sellAttachs[j].size == file[i].size) {
  5886. flag = false;
  5887. break;
  5888. }
  5889. }
  5890. }
  5891. if (flag) {
  5892. uploadAttach(mould, file[i]);
  5893. $scope.canSave = true;
  5894. }
  5895. }
  5896. }
  5897. document.getElementById("inquiryMould.sellAttachs").value = "";
  5898. };
  5899. $scope.removeFile = function(mould, file) {
  5900. $scope.inquiryMould = mould;
  5901. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  5902. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  5903. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  5904. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  5905. $scope.inquiryMould.sellAttachs.splice(i, 1);
  5906. }
  5907. }
  5908. }
  5909. };
  5910. // 保存并确认报价
  5911. $scope.onReplyClick = function (mould, withSteps) {
  5912. $scope.loading = true;
  5913. if (withSteps) {
  5914. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  5915. $scope.loading = false;
  5916. toaster.pop('info', '提示', '报价成功');
  5917. $scope.tableParams.reload();
  5918. $scope.canSave = false;
  5919. }, function (response) {
  5920. $scope.loading = false;
  5921. toaster.pop('error', '报价失败', response.data);
  5922. });
  5923. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  5924. }, function (response) {
  5925. });
  5926. } else {
  5927. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  5928. $scope.loading = false;
  5929. toaster.pop('info', '提示', '保存成功');
  5930. $scope.tableParams.reload();
  5931. }, function (response) {
  5932. $scope.loading = false;
  5933. toaster.pop('error', '保存失败', response.data);
  5934. });
  5935. }
  5936. };
  5937. // 搜索框回车
  5938. $scope.onSearch = function () {
  5939. $scope.tableParams.page(1);
  5940. $scope.tableParams.reload();
  5941. };
  5942. $scope.openDatePicker = function ($event, item, openParam) {
  5943. $event.preventDefault();
  5944. $event.stopPropagation();
  5945. item[openParam] = !item[openParam];
  5946. };
  5947. $scope.openFilterDatePicker = function ($event, item, openParam) {
  5948. $event.preventDefault();
  5949. $event.stopPropagation();
  5950. item[openParam] = !item[openParam];
  5951. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  5952. $scope.tableParams.reload();
  5953. }
  5954. };
  5955. $scope.parseDate = function (dateStr) {
  5956. if (dateStr)
  5957. return Date.parse(dateStr, 'yyyy-MM-dd');
  5958. return new Date();
  5959. };
  5960. // 导出客户资料列表
  5961. $scope.exportXls = function () {
  5962. PurcInquiryMould.exportXls({}, {}, function (data) {
  5963. if (data.success){
  5964. window.location.href = 'sale/mould/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  5965. }
  5966. }, function (response) {
  5967. toaster.pop('error', '数据加载失败', response.data);
  5968. });
  5969. }
  5970. }]);
  5971. // 模具询价单明细
  5972. app.controller('SaleInquiryMouldDetailCtrl', ['$scope', '$stateParams', 'PurcInquiryMould', '$filter', 'toaster', '$upload', 'CurrentRole', function ($scope, $stateParams, PurcInquiryMould, $filter, toaster, $upload, CurrentRole) {
  5973. // 获取当前用户是否为普通用户
  5974. CurrentRole.isUser({}, {}, function (data) {
  5975. $scope.isUser = data.isUser;
  5976. });
  5977. var inquiryMould_copy = {};
  5978. var loadData = function () {
  5979. PurcInquiryMould.getAll({id: $stateParams.id}, function (data) {
  5980. // 用来验证价格修改
  5981. inquiryMould_copy = angular.copy(data);
  5982. $scope.inquiryMould_copy = inquiryMould_copy;
  5983. $scope.newinquirymould = data;
  5984. var mould = data;
  5985. angular.forEach(mould.attachs, function (attach) {
  5986. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  5987. });
  5988. $scope.inquiryMould = mould;
  5989. }, function (response) {
  5990. toaster.pop('error', '数据加载失败', response.data);
  5991. });
  5992. };
  5993. loadData();
  5994. $scope.getMinDate = function (item) {
  5995. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  5996. };
  5997. // 取消
  5998. $scope.reload = function () {
  5999. loadData();
  6000. $scope.canSave = false;
  6001. }
  6002. //有价格为0,则不能报价
  6003. $scope.notZero = function (mould) {
  6004. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  6005. angular.forEach(mould.inquiryMouldItems, function (item) {
  6006. if (item.price == 0 || !regex.test(item.price)) {
  6007. $scope.canSave = false;
  6008. }
  6009. angular.forEach(item.inquiryMouldDetails, function (detail) {
  6010. if (detail.price == 0 || !regex.test(detail.price)) {
  6011. $scope.canSave = false;
  6012. }
  6013. })
  6014. });
  6015. }
  6016. $scope.blurPrice = function (price) {
  6017. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  6018. if (!regex.test(price)) {
  6019. toaster.pop('warning', '格式错误', '请输入有效价格');
  6020. }
  6021. }
  6022. // 获取历史报价
  6023. $scope.getHistory = function (mould) {
  6024. if (!mould.history) {
  6025. PurcInquiryMould.getHistory({id: mould.id},{}, function (data) {
  6026. $scope.historyShow = true;
  6027. mould.history = data;
  6028. },function (response) {
  6029. $scope.historyShow = false;
  6030. //toaster.pop('error', '提示', response.data);
  6031. });
  6032. }
  6033. };
  6034. $scope.canSave = false;
  6035. // items价格验证
  6036. $scope.verifyItems = function (price, index) {
  6037. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  6038. if (regex.test(price) && price != 0) {
  6039. var itemprice = $scope.inquiryMould.inquiryMouldItems[index].price;
  6040. if (itemprice != inquiryMould_copy.inquiryMouldItems[index].price) {
  6041. $scope.canSave = true;
  6042. } else {
  6043. $scope.canSave = false;
  6044. }
  6045. } else {
  6046. $scope.canSave = false;
  6047. }
  6048. }
  6049. // prod下prods价格验证
  6050. $scope.verifyProds = function (price, index, parentIndex) {
  6051. var regex = /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/;//
  6052. if (regex.test(price) && price != 0) {
  6053. var prodPrice = $scope.inquiryMould.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price;
  6054. if (prodPrice != inquiryMould_copy.inquiryMouldItems[parentIndex].inquiryMouldDetails[index].price) {
  6055. $scope.canSave = true;
  6056. } else {
  6057. $scope.canSave = false;
  6058. }
  6059. } else {
  6060. $scope.canSave = false;
  6061. }
  6062. }
  6063. // 上传附件
  6064. var uploadAttach = function(file) {
  6065. // var file = mould.attachFile.$viewValue, file = file && file.length > 0 ? file[0] : null;
  6066. $scope.mould = $scope.inquiryMould;
  6067. $upload.upload({
  6068. url: 'sale/mould/' + $scope.mould.id + '/send',
  6069. method: 'POST',
  6070. file: file,
  6071. data: {
  6072. json: $scope.mould
  6073. }
  6074. }).success(function(attach){
  6075. if (attach){
  6076. $scope.inquiryMould.sellAttachs.push(attach);
  6077. }
  6078. }).error(function(res){
  6079. console.log("failure");
  6080. console.log(res);
  6081. });
  6082. }
  6083. $scope.pushFile = function(file) {
  6084. // var file = $scope.myFiles;
  6085. if (file.length > 0) {
  6086. for (var i = 0; i < file.length; i++) {
  6087. console.log(file[i].name);
  6088. var flag = true;
  6089. if ($scope.inquiryMould.sellAttachs.length > 0) {
  6090. for (var j = 0; j < $scope.inquiryMould.sellAttachs.length; j++) {
  6091. if ($scope.inquiryMould.sellAttachs[j].name == file[i].name
  6092. && $scope.inquiryMould.sellAttachs[j].size == file[i].size) {
  6093. flag = false;
  6094. break;
  6095. }
  6096. }
  6097. }
  6098. if (flag) {
  6099. uploadAttach(file[i]);
  6100. }
  6101. }
  6102. }
  6103. };
  6104. $scope.removeFile = function(file) {
  6105. if ($scope.inquiryMould.sellAttachs != null && $scope.inquiryMould.sellAttachs.length > 0) {
  6106. for (var i = 0; i < $scope.inquiryMould.sellAttachs.length; i++) {
  6107. if ($scope.inquiryMould.sellAttachs[i].name == file.name
  6108. && $scope.inquiryMould.sellAttachs[i].size == file.size) {
  6109. $scope.inquiryMould.sellAttachs.splice(i, 1);
  6110. document.getElementById("file").value = "";
  6111. }
  6112. }
  6113. }
  6114. };
  6115. $scope.onReplyClick = function (mould, withSteps) {
  6116. $scope.loading = true;
  6117. if (withSteps) {
  6118. PurcInquiryMould.reply({id: mould.id}, mould, function () {
  6119. $scope.loading = false;
  6120. toaster.pop('info', '提示', '报价成功');
  6121. loadData();
  6122. $scope.canSave = false;
  6123. }, function (response) {
  6124. $scope.loading = false;
  6125. toaster.pop('error', '报价失败', response.data);
  6126. });
  6127. PurcInquiryMould.saveHistory({id: mould.id}, mould, function () {
  6128. }, function (response) {
  6129. });
  6130. } else {
  6131. PurcInquiryMould.saveItem({id: mould.id}, mould, function () {
  6132. $scope.loading = false;
  6133. toaster.pop('info', '提示', '保存成功');
  6134. loadData();
  6135. }, function (response) {
  6136. $scope.loading = false;
  6137. toaster.pop('error', '保存失败', response.data);
  6138. });
  6139. }
  6140. };
  6141. }]);
  6142. // 主动报价 - 列表
  6143. app.controller('SaleQuotationListCtrl', ['$scope', '$filter', 'Quotation', 'PurcInquiry', 'ngTableParams', 'toaster', 'BaseService', '$rootScope', 'QuotationInfo', 'CurrentRole', function ($scope, $filter, Quotation, PurcInquiry, ngTableParams, toaster, BaseService, $rootScope, QuotationInfo, CurrentRole) {
  6144. BaseService.scrollBackToTop();
  6145. // 获取当前用户是否为普通用户
  6146. CurrentRole.isUser({}, {}, function (data) {
  6147. $scope.isUser = data.isUser;
  6148. });
  6149. $rootScope.enteryStatus = false;
  6150. $scope.active = 'todo';
  6151. $scope.agreedText = '全部';
  6152. $scope.dateZoneText = '一个月内';
  6153. $scope.condition = {dateZone: 1};
  6154. /* 时间筛选初始化*/
  6155. var fromDate = new Date();
  6156. var toDate = new Date();
  6157. fromDate.setMonth(fromDate.getMonth() - 1);
  6158. fromDate.setHours(0, 0, 0, 0);
  6159. toDate.setHours(23, 59, 59, 999);
  6160. $scope.condition.dateFrom = fromDate;
  6161. $scope.condition.dateTo = toDate;
  6162. $scope.changeDateZone = function (zone) {
  6163. $scope.condition.dateZone = zone;
  6164. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6165. $scope.condition.$dateZoneOpen = false;
  6166. getDateCondition(zone, $scope.condition);
  6167. $scope.tableParams.page(1);
  6168. $scope.tableParams.reload();
  6169. };
  6170. $scope.setActive = function (state) {
  6171. if ($scope.active != state) {
  6172. $scope.active = state;
  6173. if ($scope.tableParams.page() == 1)
  6174. $scope.tableParams.reload();
  6175. else
  6176. $scope.tableParams.page(1);
  6177. }
  6178. };
  6179. $scope.searchMethod = false;
  6180. var getService = function () {
  6181. return $scope.searchMethod ? Quotation : QuotationInfo;
  6182. };
  6183. $scope.tableParams = new ngTableParams({
  6184. page: 1,
  6185. count: 20,
  6186. sorting: {
  6187. 'date': 'desc'
  6188. }
  6189. }, {
  6190. total: 0,
  6191. counts: [5, 10, 25, 50],
  6192. getData: function ($defer, params) {
  6193. $scope.loading = true;
  6194. var pageParams = params.url();
  6195. pageParams.searchFilter = {
  6196. keyword: $scope.keyword,
  6197. fromDate: getDateTime($scope.condition.dateFrom),
  6198. endDate: getDateTime($scope.condition.dateTo)
  6199. };
  6200. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6201. $scope.loading = false;
  6202. if (page) {
  6203. params.total(page.totalElement);
  6204. $defer.resolve(page.content);
  6205. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  6206. }
  6207. }, function (response) {
  6208. $scope.loading = false;
  6209. toaster.pop('error', '数据加载失败', response.data);
  6210. });
  6211. }
  6212. });
  6213. $scope.openDatePicker = function ($event, item, openParam) {
  6214. $event.preventDefault();
  6215. $event.stopPropagation();
  6216. item[openParam] = !item[openParam];
  6217. };
  6218. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6219. $event.preventDefault();
  6220. $event.stopPropagation();
  6221. item[openParam] = !item[openParam];
  6222. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6223. $scope.tableParams.reload();
  6224. }
  6225. };
  6226. $scope.getHistory = function (item) {
  6227. if (!item.history) {
  6228. PurcInquiry.getHistory({itemId: item.id}, function (data) {
  6229. item.history = data;
  6230. });
  6231. }
  6232. };
  6233. $scope.isValid = function (item, withSteps) {
  6234. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  6235. if (!withSteps || !bool)
  6236. return bool;
  6237. angular.forEach(item.replies, function (r, i) {
  6238. bool = (i > 0 ? r.lapQty : 1) && r.price;
  6239. });
  6240. return bool;
  6241. };
  6242. // 搜索框回车
  6243. $scope.onSearch = function (keyword) {
  6244. // 每次搜索重置获取数据方法
  6245. $scope.searchMethod = false;
  6246. if(keyword != null && keyword != '') {
  6247. $scope.searchMethod = true;
  6248. }
  6249. $scope.tableParams.page(1);
  6250. $scope.tableParams.reload();
  6251. };
  6252. // 导出
  6253. $scope.exportXls = function () {
  6254. Quotation.exportXls({}, {}, function (data) {
  6255. if (data.success){
  6256. window.location.href = 'sale/quotation/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  6257. }
  6258. }, function (response) {
  6259. toaster.pop('error', '数据加载失败', response.data);
  6260. });
  6261. }
  6262. }]);
  6263. // Controller 主动报价 - 新增
  6264. 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) {
  6265. BaseService.scrollBackToTop();
  6266. // 获取当前用户是否为普通用户
  6267. CurrentRole.isUser({}, {}, function (data) {
  6268. $scope.isUser = data.isUser;
  6269. });
  6270. var staticItem = null;
  6271. if (!angular.isUndefined($stateParams.id)) {// 查看模式
  6272. $scope.loading = true;
  6273. $rootScope.enteryStatus = true;
  6274. Quotation.getItem({id: $stateParams.id}, function (data) {
  6275. // data.$editing = false;
  6276. $scope.item = data;
  6277. $scope.item.$editing = true; // 取消要点击修改才可以编辑的交互
  6278. staticItem = angular.copy(data);
  6279. $scope.loading = false;
  6280. }, function (response) {
  6281. $scope.loading = false;
  6282. toaster.pop('error', '数据加载失败', response.data);
  6283. });
  6284. } else {// 新增模式
  6285. $rootScope.enteryStatus = false;
  6286. $scope.item = {
  6287. quotation: {
  6288. currency: 'RMB',
  6289. taxrate: 17,
  6290. },
  6291. product: {},
  6292. prices: [{lapQty: 0}],
  6293. minOrderQty: 1,
  6294. minPackQty: 1,
  6295. $endDateOpen: false,
  6296. $editing: true
  6297. };
  6298. }
  6299. $scope.getMinDate = function (item) {
  6300. return $filter('date')(new Date, 'yyyy-MM-dd');
  6301. };
  6302. //是否不能被点击
  6303. $scope.isDisabled = function () {
  6304. return $scope.item.quotation.status == 101 && $scope.item.agreed == null;
  6305. }
  6306. $scope.openDatePicker = function ($event, openParam) {
  6307. $event.preventDefault();
  6308. $event.stopPropagation();
  6309. $scope.item.$endDateOpen = !openParam;
  6310. };
  6311. // 增加一个分段
  6312. $scope.addPrice = function () {
  6313. if ($scope.item.prices.length >= 10) {
  6314. toaster.pop('warning', '提示', '最多支持10个分段!');
  6315. } else
  6316. $scope.item.prices.push({});
  6317. };
  6318. // 删除一个分段
  6319. $scope.removePrice = function (index) {
  6320. $scope.item.prices.splice(index, 1);
  6321. };
  6322. // 查找客户
  6323. $scope.dbfindCust = function () {
  6324. if ($scope.item.$editing) {
  6325. var modalInstance = $modal.open({
  6326. templateUrl: 'static/tpl/index/sale/quotation_new_cust.html',
  6327. controller: 'DbfindCustCtrl',
  6328. size: 'lg',
  6329. resolve: {}
  6330. });
  6331. modalInstance.result.then(function (data) {
  6332. $scope.item.quotation.cust = data.myEnterprise;
  6333. $scope.item.quotation.custUser = data.myUser;
  6334. $scope.item.product = null;
  6335. }, function () {
  6336. });
  6337. }
  6338. };
  6339. // 赋值客户信息
  6340. if ($rootScope.custuu) {
  6341. VendorInfo.customerInfo({custuu: $rootScope.custuu}, {}, function (data) {
  6342. $scope.item.quotation.cust = data.myEnterprise;
  6343. $scope.item.quotation.custUser = data.myUser;
  6344. })
  6345. }
  6346. // 赋值物料信息
  6347. if ($rootScope.prodId) {
  6348. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  6349. $scope.item.product.code = data.code;
  6350. $scope.item.product.title = data.title;
  6351. $scope.item.product.spec = data.spec;
  6352. $scope.item.product.unit = data.unit;
  6353. $scope.item.product.id = data.id;
  6354. }, function (response) {
  6355. });
  6356. }
  6357. // 查找客户物料
  6358. $scope.dbfindCustProd = function () {
  6359. if ($scope.item.$editing) {
  6360. if ($scope.item.quotation.cust) {
  6361. var modalInstance = $modal.open({
  6362. templateUrl: 'static/tpl/index/sale/quotation_new_custProd.html',
  6363. controller: 'DbfindCustProdCtrl',
  6364. size: 'lg',
  6365. resolve: {
  6366. custUU: function () {
  6367. return $scope.item.quotation.cust.uu
  6368. }
  6369. }
  6370. });
  6371. modalInstance.result.then(function (data) {
  6372. $scope.item.product = data;
  6373. }, function () {
  6374. });
  6375. } else {
  6376. toaster.pop('error', '错误', '请先选择客户');
  6377. }
  6378. }
  6379. };
  6380. // 根据传入的询价相关的信息封装成报价需要的信息
  6381. if ($stateParams.inquiryItem != null) {
  6382. var item = $stateParams.inquiryItem;
  6383. $scope.item.quotation.cust = item.inquiry.enterprise;
  6384. $scope.item.quotation.custUser = item.inquiry.recorderUser;
  6385. $scope.item.quotation.custUserUU = item.inquiry.recorderUU;
  6386. if (item.product == null || item.product.id == null) {
  6387. toaster.pop('info', '暂未匹配到物料信息,请手动选择');
  6388. } else {
  6389. $scope.item.product = item.product;
  6390. if (item.replies.length > 0) {
  6391. $scope.item.prices = item.replies;
  6392. angular.forEach($scope.item.prices, function(price) {
  6393. price.id = null;
  6394. });
  6395. }
  6396. $scope.item.quotation.taxrate = item.taxrate;
  6397. $scope.item.minPackQty = item.minPackQty;
  6398. $scope.item.minOrderQty = item.minOrderQty;
  6399. $scope.item.leadtime = item.leadtime;
  6400. $scope.item.quotation.currency = item.currency;
  6401. }
  6402. }
  6403. // 保存
  6404. $scope.save = function () {
  6405. var valid = true;
  6406. angular.forEach($scope.item.prices, function(price, $index) {
  6407. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6408. valid = false;
  6409. }
  6410. });
  6411. if (!valid) {
  6412. toaster.pop('info', '提示', '分段数量请保持递增!');
  6413. } else {
  6414. $scope.loading = true;
  6415. if (!$scope.item.quotation.code) //新增,设单号
  6416. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6417. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6418. if ($scope.item.quotation.custUserUU == null) {
  6419. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6420. }
  6421. $scope.item.productId = $scope.item.product.id;
  6422. Quotation.save({}, $scope.item, function (data) {
  6423. $scope.loading = false;
  6424. $scope.item = data;
  6425. toaster.pop('success', '成功', '保存成功');
  6426. if ($stateParams.id)
  6427. window.location.reload();
  6428. else
  6429. window.location.hash = '#/sale/quotation/list';
  6430. }, function (response) {
  6431. $scope.loading = false;
  6432. toaster.pop('error', '保存失败', response.data);
  6433. });
  6434. }
  6435. };
  6436. // 更新
  6437. $scope.update = function () {
  6438. $scope.item.$editing = true;
  6439. };
  6440. // 取消
  6441. $scope.cancel = function () {
  6442. $scope.item.$editing = false;
  6443. $scope.item = angular.copy(staticItem);
  6444. };
  6445. // 提交
  6446. $scope.submit = function () {
  6447. var valid = true;
  6448. angular.forEach($scope.item.prices, function(price, $index) {
  6449. if ($index > 0 && price.lapQty <= $scope.item.prices[$index - 1].lapQty) {
  6450. valid = false;
  6451. }
  6452. });
  6453. if (!valid) {
  6454. toaster.pop('info', '提示', '分段数量请保持递增!');
  6455. } else {
  6456. $scope.loading = true;
  6457. if (!$scope.item.quotation.code) //新增,设单号
  6458. $scope.item.quotation.code = 'BJ' + $filter('date')(new Date(), 'yyMMddHHmmss_sss');
  6459. $scope.item.quotation.custUU = $scope.item.quotation.cust.uu;
  6460. if ($scope.item.quotation.custUserUU == null) {
  6461. $scope.item.quotation.custUserUU = $scope.item.quotation.custUser.userUU;
  6462. }
  6463. $scope.item.productId = $scope.item.product.id;
  6464. // $scope.item.quotation.status = 101;//已提交
  6465. if ($scope.item.quotation.date instanceof Date) {
  6466. $scope.item.quotation.date = $scope.item.quotation.date.getTime();
  6467. }
  6468. if ($scope.item.quotation.endDate instanceof Date) {
  6469. $scope.item.quotation.endDate = $scope.item.quotation.endDate.getTime();
  6470. }
  6471. Quotation.submit({}, $scope.item, function (data) {
  6472. $scope.loading = false;
  6473. $scope.item = data;
  6474. toaster.pop('success', '成功', '提交成功');
  6475. // window.location.hash = '#/sale/quotation/' + data.id;
  6476. window.location.hash = '#/sale/quotation/list';
  6477. }, function (response) {
  6478. $scope.loading = false;
  6479. toaster.pop('error', '保存失败', response.data);
  6480. });
  6481. }
  6482. };
  6483. $scope.deleteById = function (id) {
  6484. Quotation.deleteById({id: id}, {}, function (data) {
  6485. window.location.href = "#/sale/quotation/list";
  6486. }, function (response) {
  6487. toaster.pop('error', '提示', response.data);
  6488. })
  6489. }
  6490. }]);
  6491. // 查找客户
  6492. app.controller('DbfindCustCtrl', ['$scope', 'Customer', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', function ($scope, Customer, BaseService, ngTableParams, toaster, $modalInstance) {
  6493. BaseService.scrollBackToTop();
  6494. $scope.tableParams = new ngTableParams({
  6495. page: 1,
  6496. count: 20
  6497. }, {
  6498. total: 0,
  6499. counts: [5, 10, 25, 50],
  6500. getData: function ($defer, params) {
  6501. $scope.loading = true;
  6502. var pageParams = params.url();
  6503. pageParams.keyword = $scope.keyword;
  6504. Customer.get(BaseService.parseParams(pageParams), function (page) {
  6505. $scope.loading = false;
  6506. if (page) {
  6507. params.total(page.totalElement);
  6508. $defer.resolve(page.content);
  6509. }
  6510. $scope.totalCount = page.totalElement;
  6511. }, function (response) {
  6512. $scope.loading = false;
  6513. toaster.pop('error', '数据加载失败', response.data);
  6514. });
  6515. }
  6516. });
  6517. $scope.onSearch = function () {
  6518. $scope.tableParams.page(1);
  6519. $scope.tableParams.reload();
  6520. };
  6521. $scope.cancel = function () {
  6522. $modalInstance.dismiss();
  6523. };
  6524. $scope.check = function (cust) {
  6525. $modalInstance.close(cust);
  6526. };
  6527. }]);
  6528. // 查找客户物料
  6529. app.controller('DbfindCustProdCtrl', ['$scope', 'Product', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'custUU', function ($scope, Product, BaseService, ngTableParams, toaster, $modalInstance, custUU) {
  6530. BaseService.scrollBackToTop();
  6531. $scope.tableParams = new ngTableParams({
  6532. page: 1,
  6533. count: 20
  6534. }, {
  6535. total: 0,
  6536. counts: [5, 10, 25, 50],
  6537. getData: function ($defer, params) {
  6538. $scope.loading = true;
  6539. var pageParams = params.url();
  6540. pageParams.keyword = $scope.keyword;
  6541. pageParams.custUU = custUU;
  6542. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  6543. $scope.loading = false;
  6544. if (page) {
  6545. params.total(page.totalElement);
  6546. $defer.resolve(page.content);
  6547. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6548. }
  6549. }, function (response) {
  6550. $scope.loading = false;
  6551. toaster.pop('error', '数据加载失败', response.data);
  6552. });
  6553. }
  6554. });
  6555. // 取消
  6556. $scope.cancel = function () {
  6557. $modalInstance.dismiss();
  6558. };
  6559. // 选择
  6560. $scope.check = function (cust) {
  6561. $modalInstance.close(cust);
  6562. };
  6563. // 搜索框回车
  6564. $scope.onSearch = function () {
  6565. $scope.tableParams.page(1);
  6566. $scope.tableParams.reload();
  6567. };
  6568. }]);
  6569. // 查找供应商
  6570. app.controller('DbfindVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', '$rootScope', function ($scope, Vendor, BaseService, ngTableParams, toaster, $modalInstance, $rootScope) {
  6571. BaseService.scrollBackToTop();
  6572. // 搜索框回车
  6573. $scope.onSearch = function (keyword) {
  6574. $scope.keyword = keyword;
  6575. $scope.tableParams.page(1);
  6576. $scope.tableParams.reload();
  6577. };
  6578. $scope.tableParams = new ngTableParams({
  6579. page: 1,
  6580. count: 20
  6581. }, {
  6582. total: 0,
  6583. counts: [10, 25, 50, 100],
  6584. getData: function ($defer, params) {
  6585. $scope.loading = true;
  6586. var pageParams = params.url();
  6587. pageParams.keyword = $scope.keyword;
  6588. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  6589. $scope.loading = false;
  6590. if (page) {
  6591. params.total(page.totalElement);
  6592. $defer.resolve(page.content);
  6593. // 添加供应商时,将已存在的选中
  6594. if ($rootScope.tenderVendor) {
  6595. angular.forEach(page.content, function (vendor) {
  6596. for (var i = 0; i < $rootScope.tenderVendor.length; i++) {
  6597. vendor.checked = false;
  6598. if (vendor.vendorEnterprise.enName == $rootScope.tenderVendor[i].enName) {
  6599. vendor.checked = true;
  6600. break;
  6601. }
  6602. }
  6603. });
  6604. }
  6605. }
  6606. $scope.totalCount = page.totalElement;
  6607. }, function (response) {
  6608. $scope.loading = false;
  6609. toaster.pop('error', '数据加载失败', response.data);
  6610. });
  6611. }
  6612. });
  6613. $scope.cancel = function () {
  6614. $modalInstance.dismiss();
  6615. };
  6616. $scope.checks = {
  6617. checked: false
  6618. };// 全选框
  6619. $scope.checkAll = function () {
  6620. angular.forEach($scope.tableParams.data, function (vendor) {
  6621. vendor.checked = $scope.checks.checked;
  6622. });
  6623. };
  6624. // 单选
  6625. $scope.checkOne = function (vendor) {
  6626. vendor.checked = true;
  6627. var checked = true;
  6628. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  6629. if (!message.checked) {
  6630. checked = false;
  6631. }
  6632. });
  6633. $scope.checks.checked = checked;
  6634. };
  6635. // 单反选
  6636. $scope.unCheckOne = function (vendor) {
  6637. vendor.checked = false;
  6638. $scope.checks.checked = false;
  6639. };
  6640. $scope.close = function () {
  6641. var vendors = [];
  6642. angular.forEach($scope.tableParams.data, function (vendor) {
  6643. if (vendor.checked) {
  6644. vendors.push(vendor);
  6645. $modalInstance.close(vendors);
  6646. }
  6647. });
  6648. };
  6649. }]);
  6650. // 发货提醒
  6651. app.controller('SaleNoticeCtrl', ['$scope', '$rootScope', '$filter', 'PurcNotice', 'ngTableParams', 'toaster', 'BaseService', 'PurcNoticeHis', '$modal', 'SaleTruck', 'Symbol', '$state', '$timeout', 'PurcNoticeInfo', 'token', 'CurrentRole', function ($scope, $rootScope, $filter, PurcNotice, ngTableParams, toaster, BaseService, PurcNoticeHis, $modal, SaleTruck, Symbol, $state, $timeout, PurcNoticeInfo, token, CurrentRole) {
  6652. BaseService.scrollBackToTop();
  6653. // 获取当前用户是否为普通用户
  6654. CurrentRole.isUser({}, {}, function (data) {
  6655. $scope.isUser = data.isUser;
  6656. });
  6657. // 用来记录已经选择的id
  6658. $rootScope.ids = [];
  6659. $scope.active = 'todo';
  6660. $scope.currency = Symbol.currency;
  6661. $scope.dateZoneText = '不限';
  6662. $scope.condition = {dateZone: 1};
  6663. $scope.searchStatus = false;
  6664. /* 时间筛选初始化*/
  6665. var fromDate = new Date();
  6666. var toDate = new Date();
  6667. fromDate.setMonth(fromDate.getMonth() - 1);
  6668. fromDate.setHours(0, 0, 0, 0);
  6669. toDate.setHours(23, 59, 59, 999);
  6670. $scope.condition.dateFrom = fromDate;
  6671. $scope.condition.dateTo = toDate;
  6672. $scope.changeDateZone = function (zone) {
  6673. $scope.condition.dateZone = zone;
  6674. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  6675. $scope.condition.$dateZoneOpen = false;
  6676. getDateCondition(zone, $scope.condition);
  6677. $scope.tableParams.page(1);
  6678. $scope.tableParams.reload();
  6679. };
  6680. $scope.setActive = function (state) {
  6681. if ($scope.active != state) {
  6682. $scope.active = state;
  6683. if ($scope.tableParams.page() == 1)
  6684. $scope.tableParams.reload();
  6685. else
  6686. $scope.tableParams.page(1);
  6687. }
  6688. };
  6689. var getService = function () {
  6690. if ($scope.searchStatus) {
  6691. return PurcNotice;
  6692. }
  6693. return PurcNoticeInfo;
  6694. };
  6695. $scope.tableParams = new ngTableParams({
  6696. page: 1,
  6697. count: 20,
  6698. sorting: {
  6699. 'id': 'desc'
  6700. }
  6701. }, {
  6702. total: 0,
  6703. counts: [5, 10, 25, 50],
  6704. getData: function ($defer, params) {
  6705. $scope.loading = true;
  6706. var pageParams = params.url();
  6707. pageParams.keyword = $scope.keyword;
  6708. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  6709. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  6710. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  6711. $scope.loading = false;
  6712. if (page) {
  6713. params.total(page.totalElement);
  6714. $defer.resolve(page.content);
  6715. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  6716. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  6717. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  6718. $scope.checkall = true;
  6719. angular.forEach(page.content, function (notice) {
  6720. if ($rootScope.ids.indexOf(notice.id) > -1) {
  6721. notice.$selected = true;
  6722. } else {
  6723. $scope.checkall = false;
  6724. }
  6725. });
  6726. $scope.checkboxes = {
  6727. checked: $scope.checkall
  6728. };
  6729. }
  6730. }, function (response) {
  6731. $scope.loading = false;
  6732. toaster.pop('error', '数据加载失败', response.data);
  6733. });
  6734. }
  6735. });
  6736. //获得各分类未阅读数量
  6737. var getUnreadCount = function () {
  6738. PurcNotice.getUnreadCount(null, function (data) {
  6739. $scope.unread = data;
  6740. });
  6741. };
  6742. getUnreadCount();
  6743. //设置单据已读
  6744. $scope.setOrdersRead = function (id) {
  6745. // 如果单据本身已读,则不发送请求修改数据
  6746. if (!$scope.isUnread(id)){
  6747. return;
  6748. }
  6749. var sourceId = [];
  6750. sourceId.push(id);
  6751. PurcNotice.setRead({}, sourceId, function (message) {
  6752. // $scope.getUnreadIds();
  6753. getUnreadCount();
  6754. });
  6755. };
  6756. $scope.setOrdersReadByState = function () {
  6757. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  6758. return;
  6759. }
  6760. PurcNotice.setReadByState({}, function () {
  6761. getUnreadIds();
  6762. getUnreadCount();
  6763. });
  6764. };
  6765. var getUnreadIds = function () {
  6766. PurcNotice.getUnreadIds({}, "", function (message) {
  6767. $scope.unreadCode = message.content;
  6768. });
  6769. };
  6770. getUnreadIds();
  6771. $scope.isUnread = function (id) {
  6772. for (var i in $scope.unreadCode) {
  6773. if (id == $scope.unreadCode[i]) {
  6774. return true;
  6775. }
  6776. }
  6777. };
  6778. $scope.openDatePicker = function ($event, item, openParam) {
  6779. $event.preventDefault();
  6780. $event.stopPropagation();
  6781. item[openParam] = !item[openParam];
  6782. };
  6783. $scope.openFilterDatePicker = function ($event, item, openParam) {
  6784. $event.preventDefault();
  6785. $event.stopPropagation();
  6786. item[openParam] = !item[openParam];
  6787. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  6788. $scope.tableParams.reload();
  6789. }
  6790. };
  6791. //生成随机单号
  6792. $scope.autoCode = function (notice) {
  6793. notice.send.code = $filter('date')(new Date(), 'yyMMddHHmmss-sss');
  6794. };
  6795. // 获取token信息 并打开询价模态框
  6796. $scope.getToken = function() {
  6797. token.info({userType: 'salenotice'}, {}, function(data) {
  6798. $scope.token = data.token;
  6799. }, function(response) {
  6800. toaster.pop('error', '提示', response.data);
  6801. });
  6802. }
  6803. //可送货日期
  6804. $scope.sendDate = function (notice) {
  6805. var stock = notice.orderItem.product.ltinstock || 0;
  6806. var de = new Date(notice.delivery);
  6807. if (stock == -1) {
  6808. de.setMonth(de.getMonth() - 1);
  6809. de.setDate(25);
  6810. } else if (stock >= 0) {
  6811. de.setDate(de.getDate() - stock - 1);
  6812. }
  6813. return de;
  6814. };
  6815. $scope.lockstatus = false;
  6816. // 锁定时间按钮5秒
  6817. $scope.lockClick = function (notice) {
  6818. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6819. } else if (!notice.send.code) {
  6820. } else {
  6821. $scope.lockstatus = true;
  6822. $timeout(function () {
  6823. $scope.lockstatus = false;
  6824. }, 5000);
  6825. }
  6826. };
  6827. var isSumbit = false;
  6828. $scope.onReplyClick = function (notice) {
  6829. if (!notice.send || !notice.send.qty || notice.send.qty > notice.qty - (notice.endQty || 0)) {
  6830. toaster.pop('warning', '警告', '数量填写错误!');
  6831. } else if (!notice.send.code) {
  6832. toaster.pop('warning', '警告', '请填写发货单号!');
  6833. } else {
  6834. if (!isSumbit) {
  6835. var send = {
  6836. code: notice.send.code,
  6837. remark: notice.send.remark,
  6838. sendItems: [{qty: notice.send.qty}]
  6839. };
  6840. $scope.loading = true;
  6841. PurcNotice.save({id: notice.id, token: $scope.token}, send, function (data) {
  6842. $scope.loading = false;
  6843. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + notice.send.code);
  6844. $state.go('sale.send_detail', {id: data.id});
  6845. }, function (response) {
  6846. $scope.loading = false;
  6847. toaster.pop('error', '发货失败', response.data);
  6848. });
  6849. isSumbit = true;
  6850. return true;
  6851. } else {
  6852. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  6853. return false;
  6854. }
  6855. }
  6856. }
  6857. $scope.checkboxes = {
  6858. checked: false
  6859. };
  6860. angular.forEach($scope.tableParams.data, function (item) {
  6861. $scope.checkboxes.checked = false;
  6862. if($rootScope.ids.in_array(item.id)) {
  6863. $rootScope.ids.remove(item.id);
  6864. $scope.checkboxes.checked = true;
  6865. }
  6866. });
  6867. // 点击勾选全部的复选框
  6868. $scope.checkAll = function () {
  6869. angular.forEach($scope.tableParams.data, function (item) {
  6870. if (!item.waiting) {
  6871. item.$selected = $scope.checkboxes.checked;
  6872. if(item.$selected) {
  6873. if(!$rootScope.ids.in_array(item.id)) {
  6874. $rootScope.ids.push(item.id);
  6875. }
  6876. } else {
  6877. if($rootScope.ids.in_array(item.id)) {
  6878. $rootScope.ids.remove(item.id);
  6879. }
  6880. }
  6881. }
  6882. });
  6883. };
  6884. // 判断数组中是否存在某个对象
  6885. Array.prototype.S = String.fromCharCode(2);
  6886. Array.prototype.in_array = function(e) {
  6887. var r = new RegExp(this.S + e + this.S);
  6888. return (r.test(this.S + this.join(this.S) + this.S));
  6889. }
  6890. // 从数组中移除某个对象
  6891. Array.prototype.remove = function(val) {
  6892. var index = this.indexOf(val);
  6893. if (index > -1) {
  6894. this.splice(index, 1);
  6895. }
  6896. };
  6897. // 点击其中一个明细的复选框
  6898. $scope.checkOne = function (order) {
  6899. var result = true;
  6900. angular.forEach($scope.tableParams.data, function (item) {
  6901. if (item.$selected != true) {
  6902. result = false;
  6903. return;
  6904. }
  6905. });
  6906. if(order.$selected) {
  6907. if(!$rootScope.ids.in_array(order.id)) {
  6908. $rootScope.ids.push(order.id);
  6909. }
  6910. } else {
  6911. if($rootScope.ids.in_array(order.id)) {
  6912. $rootScope.ids.remove(order.id);
  6913. }
  6914. }
  6915. $scope.checkboxes = {
  6916. checked: result
  6917. };
  6918. };
  6919. // 打开批量发货模态框
  6920. var sendByBatch = function() {
  6921. var modalInstance = $modal.open({
  6922. animation: true,
  6923. templateUrl: 'static/tpl/index/sale/sendByBatch.html',
  6924. controller: 'SaleNoticeSendByBatchCtrl',
  6925. size: 'lg',
  6926. resolve: {
  6927. selectedNotices: function () {
  6928. return $scope.tableParams.data;
  6929. },
  6930. token: function() {
  6931. return $scope.token;
  6932. },
  6933. ids: function() {
  6934. return $rootScope.ids;
  6935. }
  6936. }
  6937. });
  6938. modalInstance.result.then(function () {
  6939. $scope.tableParams.reload();
  6940. }, function () {
  6941. });
  6942. }
  6943. $scope.sendByBatch = function () {
  6944. if($scope.token == null) {
  6945. token.info({userType: 'salenotice'}, {}, function(data) {
  6946. $scope.token = data.token;
  6947. sendByBatch();
  6948. }, function(response) {
  6949. toaster.pop('error', '提示', response.data);
  6950. });
  6951. } else {
  6952. sendByBatch();
  6953. }
  6954. };
  6955. $scope.getSends = function (notice) {
  6956. if (!notice.sends && notice.endQty > 0) {
  6957. notice.getSendsing = true;
  6958. notice.getSendsError = false;
  6959. PurcNotice.getSends({id: notice.id}, function (data) {
  6960. notice.getSendsing = false;
  6961. notice.getSendsError = false;
  6962. notice.sends = data;
  6963. }, function (response) {
  6964. notice.getSendsing = false;
  6965. notice.getSendsError = true;
  6966. notice.getErrorMessage = response.data;
  6967. });
  6968. }
  6969. };
  6970. // 搜索框回车
  6971. $scope.onSearch = function () {
  6972. $scope.searchStatus = true;
  6973. $scope.tableParams.page(1);
  6974. $scope.tableParams.reload();
  6975. };
  6976. // 选择查找日期
  6977. $scope.onDateCondition = function () {
  6978. $scope.tableParams.page(1);
  6979. $scope.tableParams.reload();
  6980. };
  6981. //货车功能
  6982. var truck = $rootScope.truck;
  6983. if (!truck) {
  6984. SaleTruck.query({}, function (data) {
  6985. $rootScope.truck = data;
  6986. });
  6987. }
  6988. $scope.isInTruck = function (noticeId) {
  6989. return truck.indexOf(noticeId) > -1;
  6990. };
  6991. $scope.addtoTruck = function (notice) {
  6992. SaleTruck.save({noticeId: notice.id}, {}, function (data) {
  6993. $rootScope.truck = data;
  6994. });
  6995. };
  6996. $scope.delFromTruck = function (notice) {
  6997. SaleTruck.remove({noticeId: notice.id}, {}, function (data) {
  6998. $rootScope.truck = data;
  6999. });
  7000. };
  7001. $scope.$watch(function () {
  7002. return $rootScope.truck;
  7003. }, function (data) {
  7004. truck = $rootScope.truck;
  7005. }, true);
  7006. $scope.$watch(function () {
  7007. return $rootScope.dataChanged;
  7008. }, function (data) {
  7009. data && ($scope.tableParams.reload());
  7010. }, true);
  7011. // 导出
  7012. $scope.exportXls = function () {
  7013. PurcNotice.exportXls({}, {}, function (data) {
  7014. if (data.success){
  7015. window.location.href = 'sale/notice/xls?_state='+$scope.active+
  7016. '&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7017. }
  7018. }, function (response) {
  7019. toaster.pop('error', '数据加载失败', response.data);
  7020. });
  7021. }
  7022. }]);
  7023. 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) {
  7024. // $scope.notices = angular.copy(selectedNotices);
  7025. PurcNotice.findByIds({ids : angular.toJson(ids)}, function(data) {
  7026. $scope.notices = angular.copy(data);
  7027. }, function(res) {
  7028. toaster.pop('error', '提示', '发货提醒查询失败');
  7029. });
  7030. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7031. $scope.saleSend = {
  7032. code: '',
  7033. payments: '',
  7034. currency: '',
  7035. custUU: null,
  7036. custUserUU: null,
  7037. remark: '批量发货',
  7038. sendItems: []
  7039. };
  7040. // 计算总数、总额
  7041. $scope.$watch(function () {
  7042. return $scope.notices;
  7043. }, function (data) {
  7044. var q = 0, t = 0;
  7045. if (data) {
  7046. angular.forEach(data, function (d) {
  7047. q += (d.thisSendQty || 0);
  7048. t += (d.thisSendQty || 0) * (d.orderItem.price || 0);
  7049. });
  7050. }
  7051. $scope.totalQty = q;
  7052. $scope.total = t;
  7053. }, true);
  7054. /**
  7055. * 删除一个已选中的送货提醒
  7056. */
  7057. $scope.removeOne = function (index) {
  7058. $scope.notices.splice(index, 1);
  7059. };
  7060. $scope.lockstatus = false;
  7061. // 锁定时间按钮5秒
  7062. $scope.lockClick = function () {
  7063. $scope.lockstatus = true;
  7064. $timeout(function () {
  7065. $scope.lockstatus = false;
  7066. }, 5000);
  7067. }
  7068. $scope.lockstatus = false;
  7069. // 锁定时间按钮5秒
  7070. $scope.lockClick = function (notice) {
  7071. if ($scope.saleSend.code == '') {//送货单号为空
  7072. return;
  7073. } else {
  7074. $scope.lockstatus = true;
  7075. $timeout(function () {
  7076. $scope.lockstatus = false;
  7077. }, 5000);
  7078. }
  7079. };
  7080. var isSumbit = false;
  7081. //确认送货
  7082. $scope.sendByBatch = function () {
  7083. $scope.saleSend.sendItems = [];
  7084. if ($scope.saleSend.code == '') {//送货单号为空
  7085. toaster.pop('error', '错误', '请输入送货单号');
  7086. return;
  7087. }
  7088. var a = 0;
  7089. var num = 1;
  7090. var valid = true;
  7091. angular.forEach($scope.notices, function (item, key) {
  7092. if (a == 0) {//第一次
  7093. $scope.saleSend.currency = item.orderItem.order.currency;
  7094. $scope.saleSend.custUU = item.enUU;
  7095. $scope.saleSend.payments = item.orderItem.order.payments;
  7096. a = 1;
  7097. } else {//其他
  7098. if ($scope.saleSend.currency != item.orderItem.order.currency) valid = false;
  7099. if ($scope.saleSend.custUU != item.enUU) valid = false;
  7100. if ($scope.saleSend.payments != item.orderItem.order.payments) valid = false;
  7101. }
  7102. $scope.saleSend.sendItems.push({
  7103. noticeId: item.id, qty: item.thisSendQty, price: item.orderItem.price, number: num++
  7104. });
  7105. });
  7106. if (!valid) {
  7107. toaster.pop('error', '错误', '只有客户一致、币别一致、付款方式一致才能一起发货。');
  7108. } else {
  7109. if (!isSumbit) {
  7110. PurcNotice.sendByBatch({token: token}, $scope.saleSend, function (data) {
  7111. if(data.id) {
  7112. toaster.pop('success', '提示', '发货成功,跳转至发货单:' + $scope.saleSend.code);
  7113. $modalInstance.close('success');
  7114. $state.go('sale.send_detail', {id: data.id});
  7115. } else {
  7116. toaster.pop('error', '提示', '发货失败,请刷新页面重试');
  7117. }
  7118. }, function (response) {
  7119. toaster.pop('error', '错误', response.data);
  7120. });
  7121. isSumbit = true;
  7122. return true;
  7123. } else {
  7124. toaster.pop('error', '提示', '为防止重复发货,请刷新页面后重新填写');
  7125. return false;
  7126. }
  7127. }
  7128. };
  7129. $scope.cancel = function () {
  7130. $modalInstance.dismiss();
  7131. };
  7132. }]);
  7133. /**
  7134. * 发货单
  7135. */
  7136. app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'ReportService', function ($scope, $filter, SaleSend, ngTableParams, toaster, BaseService, Symbol, ReportService) {
  7137. BaseService.scrollBackToTop();
  7138. $scope.active = 'all';
  7139. $scope.currency = Symbol.currency;
  7140. $scope.dateZoneText = '不限';
  7141. $scope.condition = {dateZone: 1};
  7142. /* 时间筛选初始化*/
  7143. var fromDate = new Date();
  7144. var toDate = new Date();
  7145. fromDate.setMonth(fromDate.getMonth() - 1);
  7146. fromDate.setHours(0, 0, 0, 0);
  7147. toDate.setHours(23, 59, 59, 999);
  7148. $scope.condition.dateFrom = fromDate;
  7149. $scope.condition.dateTo = toDate;
  7150. $scope.changeDateZone = function (zone) {
  7151. $scope.condition.dateZone = zone;
  7152. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
  7153. $scope.condition.$dateZoneOpen = false;
  7154. getDateCondition(zone, $scope.condition);
  7155. $scope.tableParams.page(1);
  7156. $scope.tableParams.reload();
  7157. };
  7158. $scope.setActive = function (state) {
  7159. if ($scope.active != state) {
  7160. $scope.active = state;
  7161. if ($scope.tableParams.page() == 1)
  7162. $scope.tableParams.reload();
  7163. else
  7164. $scope.tableParams.page(1);
  7165. }
  7166. };
  7167. var getService = function () {
  7168. return SaleSend;
  7169. };
  7170. $scope.tableParams = new ngTableParams({
  7171. page: 1,
  7172. count: 20,
  7173. sorting: {
  7174. date: 'desc'
  7175. }
  7176. }, {
  7177. total: 0,
  7178. counts: [5, 10, 25, 50],
  7179. getData: function ($defer, params) {
  7180. $scope.loading = true;
  7181. var pageParams = params.url();
  7182. pageParams.keyword = $scope.keyword;
  7183. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  7184. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  7185. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7186. $scope.loading = false;
  7187. if (page) {
  7188. params.total(page.totalElement);
  7189. $defer.resolve(page.content);
  7190. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  7191. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  7192. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  7193. }
  7194. }, function (response) {
  7195. $scope.loading = false;
  7196. toaster.pop('error', '数据加载失败', response.data);
  7197. });
  7198. }
  7199. });
  7200. //打印 发货单
  7201. $scope.print = function (send) {
  7202. var newPage = window.open("about:blank");
  7203. SaleSend.printPermission({}, function () {
  7204. SaleSend.printCount({id: send.id}, {}); //增加打印此次
  7205. ReportService.print(send.custUU, 'SALESEND', "where sale$send.ss_id=" + send.id, newPage);
  7206. $scope.tableParams.reload();
  7207. }, function (response) {
  7208. newPage.close();
  7209. toaster.pop('error', '打印失败', response.data);
  7210. });
  7211. };
  7212. $scope.openDatePicker = function ($event, item, openParam) {
  7213. $event.preventDefault();
  7214. $event.stopPropagation();
  7215. item[openParam] = !item[openParam];
  7216. };
  7217. $scope.openFilterDatePicker = function ($event, item, openParam) {
  7218. $event.preventDefault();
  7219. $event.stopPropagation();
  7220. item[openParam] = !item[openParam];
  7221. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  7222. $scope.tableParams.reload();
  7223. }
  7224. };
  7225. // 搜索框回车
  7226. $scope.onSearch = function () {
  7227. $scope.tableParams.page(1);
  7228. $scope.tableParams.reload();
  7229. };
  7230. // 选择查找日期
  7231. $scope.onDateCondition = function () {
  7232. $scope.tableParams.page(1);
  7233. $scope.tableParams.reload();
  7234. };
  7235. $scope.exportXls = function () {
  7236. SaleSend.exportXls({}, {}, function (data) {
  7237. if (data.success){
  7238. window.location.href = 'sale/notice/sends/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || '')+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  7239. }
  7240. }, function (response) {
  7241. toaster.pop('error', '数据加载失败', response.data);
  7242. });
  7243. }
  7244. }]);
  7245. /**
  7246. * 发货单(包括发货条码维护)
  7247. */
  7248. app.controller('SaleSendDetailCtrl', ['$scope', '$stateParams', 'SaleSend', 'toaster', 'ReportService', 'ngTableParams', 'Lodop', '$modal', 'CurrentRole', function ($scope, $stateParams, SaleSend, toaster, ReportService, ngTableParams, Lodop, $modal, CurrentRole) {
  7249. // 获取当前用户是否为普通用户
  7250. CurrentRole.isUser({}, {}, function (data) {
  7251. $scope.isUser = data.isUser;
  7252. });
  7253. var loading = true;
  7254. $scope.checkBarCode = [];
  7255. $scope.checkBoxCode = [];
  7256. var vm = $scope.vm = {};
  7257. $scope.getCheckedItems = {};
  7258. vm.editBar = false;
  7259. vm.showBarCode = [];
  7260. $scope.barCode = function () {
  7261. vm.editBar = !vm.editBar;
  7262. }
  7263. $scope.checkboxes = {
  7264. checked: false
  7265. };
  7266. $scope.checkbars = {
  7267. checked: false
  7268. };
  7269. // 点击勾选barCode全部的复选框
  7270. $scope.checkBarAll = function () {
  7271. angular.forEach($scope.checkBarCode, function (item, key) {
  7272. $scope.checkBarCode[key] = $scope.checkbars.checked;
  7273. });
  7274. };
  7275. //点击barCode单选
  7276. $scope.checkBarOne = function () {
  7277. var result = true;
  7278. angular.forEach($scope.checkBarCode, function (item, key) {
  7279. if (item != true) {
  7280. result = false;
  7281. return;
  7282. }
  7283. });
  7284. $scope.checkbars.checked = result;
  7285. }
  7286. // 点击boxCode全部的复选框
  7287. $scope.checkBoxAll = function () {
  7288. angular.forEach($scope.checkBoxCode, function (item, key) {
  7289. $scope.checkBoxCode[key] = $scope.checkboxes.checked;
  7290. });
  7291. };
  7292. //点击boxCode单选
  7293. $scope.checkBoxOne = function () {
  7294. var result = true;
  7295. angular.forEach($scope.checkBoxCode, function (item) {
  7296. if (item != true) {
  7297. result = false;
  7298. return;
  7299. }
  7300. });
  7301. $scope.checkboxes.checked = result;
  7302. }
  7303. /**
  7304. * 生成条码和箱号
  7305. */
  7306. $scope.generateBarCode = function (item) {
  7307. //获取勾选了生成条码的明细行,只勾选生成箱号的明细行不会生成条码和箱号
  7308. $scope.getCheckedItems = [];
  7309. var warningdata = '';
  7310. angular.forEach($scope.checkBarCode, function (item, key) {
  7311. $scope.getCheckedItem = {};
  7312. if (item == true) {
  7313. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7314. $scope.getCheckedItem.isOutboxChecked = $scope.checkBoxCode[key];
  7315. $scope.getCheckedItems.push($scope.getCheckedItem);
  7316. //判断是否生成过条码
  7317. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7318. warningdata += $scope.order.sendItems[key].number + ","
  7319. }
  7320. }
  7321. });
  7322. if ($scope.getCheckedItems.length == 0) {
  7323. toaster.pop('warning', '提示', '请勾选需要生成条码的明细行!');
  7324. return;
  7325. }
  7326. if (warningdata != '') {
  7327. if (!confirm('明细行序号:' + warningdata + "已经生成了条码,继续生成将清空原有条码?")) {
  7328. return;
  7329. }
  7330. }
  7331. SaleSend.generateBarcodes({id: $scope.order.id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7332. toaster.pop('success', '提示', '生成成功!');
  7333. loadData();
  7334. }, function (response) {
  7335. $scope.loading = false;
  7336. toaster.pop('error', '生成失败', response.data);
  7337. });
  7338. }
  7339. /**
  7340. * 打印条码和箱号
  7341. */
  7342. $scope.printCode = function (type) {
  7343. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7344. //勾选需要打印的行
  7345. $scope.getCheckedItems = [];
  7346. var warningdata = ''
  7347. angular.forEach($scope.checkBarCode, function (item, key) {
  7348. $scope.getCheckedItem = {};
  7349. if (item == true) {
  7350. $scope.getCheckedItem.id = $scope.order.sendItems[key].id;
  7351. $scope.getCheckedItems.push($scope.getCheckedItem);
  7352. //判断是否生成过条码
  7353. if ($scope.order.sendItems[key].barSendNotify.length > 0) {
  7354. warningdata += $scope.order.sendItems[key].number + ","
  7355. }
  7356. }
  7357. });
  7358. if ($scope.getCheckedItems.length == 0) {
  7359. toaster.pop('warning', '提示', '请勾选需要打印的明细行!');
  7360. return;
  7361. }
  7362. if (warningdata == '') {
  7363. toaster.pop('warning', '提示', '明细行序号:' + warningdata + '未生成条码无法打印');
  7364. return;
  7365. }
  7366. //选择打印模板
  7367. var modalInstance = $modal.open({
  7368. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7369. controller: 'BarPrintModalCtrl',
  7370. resolve: {
  7371. typeItem: function () {
  7372. return {'type': type, 'id': $scope.order.id};
  7373. }
  7374. }
  7375. });
  7376. modalInstance.result.then(function (s) {
  7377. if (s) {
  7378. //获取打印数据
  7379. SaleSend.getPrintBarcodes({lpsId: s.tp_id}, angular.fromJson($scope.getCheckedItems), function (data) {
  7380. if (s.type == 'print') {//判断选择是打印还是打印预览
  7381. lodopPrint(data.message, LODOP, type);
  7382. } else if (s.type == 'printPreview') {
  7383. lodopPrintPreview(data.message, LODOP, type);
  7384. }
  7385. }, function (response) {
  7386. toaster.pop('error', '获取打印数据失败', response.data);
  7387. });
  7388. }
  7389. });
  7390. };
  7391. //打印单个条码
  7392. $scope.printSingleCode = function (id) {
  7393. var LODOP = Lodop.getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));
  7394. //选择打印模板
  7395. var modalInstance = $modal.open({
  7396. templateUrl: 'static/tpl/index/sale/bar_print_template.html',
  7397. controller: 'BarPrintModalCtrl',
  7398. resolve: {
  7399. typeItem: function () {
  7400. return {'type': 'Bar', 'id': $scope.order.id};
  7401. }
  7402. }
  7403. });
  7404. modalInstance.result.then(function (s) {
  7405. if (s) {
  7406. //获取打印数据
  7407. SaleSend.getSPrintBarcode({lpsId: s.tp_id, bsnId: id}, function (data) {
  7408. if (s.type == 'print') {//判断选择是打印还是打印预览
  7409. lodopSPrint(data.message, LODOP);
  7410. } else if (s.type == 'printPreview') {
  7411. lodopSPrintPreview(data.message, LODOP);
  7412. }
  7413. }, function (response) {
  7414. toaster.pop('error', '获取打印数据失败', response.data);
  7415. });
  7416. }
  7417. });
  7418. }
  7419. var lodopSPrint = function (printStore, LODOP) {//单个条码打印
  7420. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7421. if (selectOrNot != -1) {
  7422. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7423. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7424. var strs = pagesize.split("*"); //字符分割
  7425. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7426. angular.forEach(printStore, function (data, index) {
  7427. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7428. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7429. if (data['LP_VALUETYPE'] == 'barcode') {
  7430. 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']);
  7431. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7432. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7433. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7434. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7435. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7436. } else if (data['LP_VALUETYPE'] == 'text') {
  7437. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7438. }
  7439. });
  7440. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7441. LODOP.PRINT();
  7442. }
  7443. };
  7444. var lodopSPrintPreview = function (printStore, LODOP) {//单个条码打印预览
  7445. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7446. var pagesize = printStore[0]['LA_PAGESIZE'];//获取标签的大小
  7447. var strs = pagesize.split("*"); //字符分割
  7448. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7449. angular.forEach(printStore, function (data, index) {
  7450. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7451. if (data['LP_VALUETYPE'] == 'barcode') {
  7452. 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']);
  7453. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7454. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7455. } else if (data['LP_VALUETYPE'] == 'text') {
  7456. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7457. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7458. }
  7459. });
  7460. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7461. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7462. LODOP.PREVIEW();//打印预览
  7463. };
  7464. var lodopPrint = function (printStore, LODOP, type) {//勾选发货单明细进行打印
  7465. var selectOrNot = LODOP.SELECT_PRINTER();//选择打印机,未-1就是取消,如果是其他数字就是设置打印机序号
  7466. if (selectOrNot != -1) {
  7467. LODOP.PRINT_INIT("标签打印");//设定纸张大小
  7468. var pagesize = printStore[0]['pagesize'];//获取标签的大小
  7469. var strs = new Array(); //定义一数组
  7470. strs = pagesize.split("*"); //字符分割
  7471. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7472. var ids = new Array();
  7473. angular.forEach(printStore, function (value, key) {
  7474. //LODOP.NewPage();
  7475. angular.forEach(value['data'], function (record, key) {
  7476. angular.forEach(record['store'], function (data, index) {
  7477. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7478. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7479. if (data['LP_VALUETYPE'] == 'barcode') {
  7480. 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']);
  7481. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7482. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7483. //“ShowBarText” :(一维)条码的码值是否显示 0/1
  7484. //“AlignJustify”:设置“text文本”是否两端对齐或“barcode条码文字”靠齐方式
  7485. //设置“barcode条码文字”时,0-两端对齐(默认) 1-左靠齐 2-居中 3-右靠齐
  7486. } else if (data['LP_VALUETYPE'] == 'text') {
  7487. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7488. }
  7489. });
  7490. });
  7491. var o = new Object();
  7492. o['id'] = record['si_id']
  7493. ids.push(o);
  7494. LODOP.SET_PRINT_STYLEA(0, "NotOnlyHighPrecision", true);//设置打印的精度
  7495. LODOP.PRINT();
  7496. });
  7497. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7498. if (type == 'Bar') {
  7499. //更新打印状态
  7500. SaleSend.updatePrintStatus({}, ids, function (data) {
  7501. }, function (res) {
  7502. });
  7503. }
  7504. }
  7505. };
  7506. var lodopPrintPreview = function (printData, LODOP, type) {//打印预览
  7507. var ids = new Array();
  7508. angular.forEach(printData, function (record, index) {
  7509. angular.forEach(record['data'], function (value, index) {
  7510. LODOP.NewPage();
  7511. angular.forEach(value['store'], function (data, index) {
  7512. LODOP.SET_PRINT_STYLE("FontSize", data['LP_SIZE']);
  7513. if (data['LP_VALUETYPE'] == 'barcode') {
  7514. 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']);
  7515. LODOP.SET_PRINT_STYLEA(0, "ShowBarText", data['LP_IFSHOWNOTE']);
  7516. LODOP.SET_PRINT_STYLEA(0, "AlignJustify", data['LP_NOTEALIGNJUSTIFY']);
  7517. } else if (data['LP_VALUETYPE'] == 'text') {
  7518. LODOP.SET_PRINT_STYLE("FontName", data['LP_FONT']);
  7519. LODOP.ADD_PRINT_TEXT(data['LP_TOPRATE'] + "mm", data['LP_LEFTRATE'] + "mm", data['LP_WIDTH'] + "mm", data['LP_HEIGHT'] + "mm", data['value']);
  7520. }
  7521. });
  7522. });
  7523. var o = new Object();
  7524. o['id'] = record['si_id']
  7525. ids.push(o);
  7526. });
  7527. var pagesize = printData[0]['pagesize'];//获取标签的大小
  7528. var strs = new Array(); //定义一数组
  7529. strs = pagesize.split("*"); //字符分割
  7530. LODOP.SET_PREVIEW_WINDOW(0, 0, 0, 0, 0, "");
  7531. LODOP.SET_SHOW_MODE("HIDE_SBUTTIN_PREVIEW", 1);
  7532. LODOP.SET_PRINT_PAGESIZE(1, strs[0] * 10, strs[1] * 10, "");
  7533. var times = LODOP.PREVIEW();//打印预览
  7534. if (times > 0) {//点击了打印预览内的打印按钮
  7535. //如果打印的是条码则更新打印状态,如果是箱号则不不要打印
  7536. if (type == 'Bar') {
  7537. //更新打印状态
  7538. SaleSend.updatePrintStatus({}, ids, function (data) {
  7539. loadData();
  7540. }, function (res) {
  7541. });
  7542. }
  7543. }
  7544. };
  7545. /**
  7546. * 查看条码按钮
  7547. */
  7548. $scope.showBarCode = function (number) {
  7549. $scope.keys = number;
  7550. for (var i = 0; i < vm.showBarCode.length; i++) {
  7551. if (i != number) {
  7552. vm.showBarCode[i] = false;
  7553. }
  7554. }
  7555. vm.showBarCode[number] = !vm.showBarCode[number];
  7556. $scope.barcodes = [];
  7557. $scope.barcodes = $scope.order.sendItems[number].barSendNotify;
  7558. var getPage = function (page, size) {
  7559. if ($scope.barcodes) {
  7560. var result = {};
  7561. result.totalCount = $scope.barcodes.length;
  7562. result.content = $scope.barcodes.slice((page - 1) * size, page * size);
  7563. if ($scope.barcodes.length % size == 0) {
  7564. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size;
  7565. } else {
  7566. result.totalPage = ($scope.barcodes.length - $scope.barcodes.length % size) / size + 1;
  7567. }
  7568. result.first = page == 1;
  7569. result.last = page == result.totalPage;
  7570. result.page = page;
  7571. result.next = page - 0 + 1;
  7572. result.pre = page - 1;
  7573. return result;
  7574. }
  7575. }
  7576. $scope.barData = getPage(1, 5);
  7577. $scope.first = function () {
  7578. $scope.barData = getPage($scope.barData.pre, 5);
  7579. }
  7580. $scope.last = function () {
  7581. $scope.barData = getPage($scope.barData.next, 5);
  7582. }
  7583. };
  7584. /**
  7585. * 更新外箱号
  7586. */
  7587. $scope.updateOutBox = function (item, number) {
  7588. if ($scope.oldoutBoxQty[number] == item.outBoxQty) {
  7589. } else {
  7590. if (item.outBoxQty > 0) {
  7591. if (!(item.outBoxQty % item.packageQty)) {
  7592. SaleSend.update({id: item.id}, item, function () {
  7593. toaster.pop('success', '提示', '保存成功!');
  7594. loadData();
  7595. }, function (response) {
  7596. $scope.loading = false;
  7597. toaster.pop('error', '回复失败', response.data);
  7598. })
  7599. } else {
  7600. toaster.pop('warning', '提示', '请输入最小包数的整数倍!(' + item.packageQty + '的整数倍)');
  7601. }
  7602. } else {
  7603. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  7604. }
  7605. }
  7606. loadData();
  7607. };
  7608. /**
  7609. * 更新最小包数
  7610. */
  7611. $scope.updatePackage = function (item, number) {
  7612. if (item.packageQty == $scope.oldpackageQty[number]) {
  7613. } else {
  7614. if (item.orderItem.product.minPack != 0) {
  7615. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7616. if (!(item.packageQty % item.orderItem.product.minPack)) {
  7617. SaleSend.update({id: item.id}, item, function () {
  7618. toaster.pop('success', '提示', '保存成功!');
  7619. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7620. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7621. }
  7622. loadData();
  7623. }, function (response) {
  7624. $scope.loading = false;
  7625. toaster.pop('error', '回复失败', response.data);
  7626. })
  7627. } else {
  7628. toaster.pop('warning', '提示', '请输入最小物料包装的整数倍!(' + item.orderItem.product.minPack + '的整数倍)');
  7629. }
  7630. } else {
  7631. toaster.pop('warning', '提示', '请填写有效的数量!');
  7632. }
  7633. } else {
  7634. if (item.packageQty > 0 && item.packageQty <= item.qty) {
  7635. SaleSend.update({id: item.id}, item, function () {
  7636. toaster.pop('success', '提示', '保存成功!');
  7637. if (item.outBoxQty && item.outBoxQty % item.packageQty) {
  7638. toaster.pop('warning', '提示', '外箱容量必须是最小包数的整数倍,请及时修改(' + item.packageQty + '的整数倍)');
  7639. }
  7640. loadData();
  7641. }, function (response) {
  7642. $scope.loading = false;
  7643. toaster.pop('error', '回复失败', response.data);
  7644. })
  7645. } else {
  7646. toaster.pop('warning', '提示', '请填写有效的数量!');
  7647. }
  7648. }
  7649. }
  7650. loadData();
  7651. };
  7652. var loadData = function () {
  7653. SaleSend.getItem({id: $stateParams.id}, function (data) {
  7654. $scope.order = data;
  7655. var orderCount = $scope.order.sendItems.length;
  7656. $scope.oldpackageQty = [];
  7657. $scope.oldoutBoxQty = [];
  7658. var sum = 0;
  7659. vm.oldpackageQty = [];
  7660. angular.forEach(data.sendItems, function (value, key) {
  7661. //给showBarCode数组赋初值
  7662. if (vm.showBarCode.length < orderCount) {
  7663. vm.showBarCode.push(false);
  7664. }
  7665. if ($scope.checkBarCode.length < orderCount) {
  7666. $scope.checkBarCode.push(false);
  7667. }
  7668. if ($scope.checkBoxCode.length < orderCount) {
  7669. $scope.checkBoxCode.push(false);
  7670. }
  7671. //给个初值
  7672. if (!value.packageQty) {
  7673. value.packageQty = value.orderItem.product.minPack;
  7674. }
  7675. $scope.oldpackageQty.push(value.packageQty);
  7676. if (value.outBoxQty) {
  7677. $scope.oldoutBoxQty.push(value.outBoxQty);
  7678. }
  7679. sum += value.price * value.qty;
  7680. });
  7681. data.total = sum;
  7682. $scope.loading = false;
  7683. }, function (response) {
  7684. loading = false;
  7685. toaster.pop('error', '获取数据失败', response.data);
  7686. });
  7687. };
  7688. loadData();
  7689. }]);
  7690. app.controller('BarPrintModalCtrl', ['$scope', 'typeItem', 'SaleSend', 'toaster', '$modalInstance', function ($scope, typeItem, SaleSend, toaster, $modalInstance) {
  7691. $scope.typeItem = typeItem;
  7692. $scope.template = [];
  7693. $scope.choose = {};
  7694. //获取打印模板
  7695. SaleSend.getPrintTemplate({id: $scope.typeItem.id, type: $scope.typeItem.type}, function (data) {
  7696. if (data.message) {
  7697. $scope.template = data.message;
  7698. $scope.choose.tp_id = $scope.template[0].id;
  7699. }
  7700. }, function (res) {
  7701. toaster.pop('error', '获取模板错误', res.data);
  7702. });
  7703. $scope.print = function () {
  7704. $scope.choose.type = 'print';
  7705. $modalInstance.close($scope.choose);
  7706. };
  7707. $scope.printPreview = function () {
  7708. $scope.choose.type = 'printPreview';
  7709. $modalInstance.close($scope.choose);
  7710. }
  7711. $scope.cancel = function () {
  7712. $modalInstance.close();
  7713. }
  7714. }]);
  7715. app.controller('SaleSampleDetailCtrl', ['$scope', '$stateParams', 'PurcSample', 'toaster', '$modal', 'BaseService', 'CurrentRole', function ($scope, $stateParams, PurcSample, toaster, $modal, BaseService, CurrentRole) {
  7716. BaseService.scrollBackToTop();
  7717. // 获取当前用户是否为普通用户
  7718. CurrentRole.isUser({}, {}, function (data) {
  7719. $scope.isUser = data.isUser;
  7720. });
  7721. var loading = true;
  7722. var loadData = function () {
  7723. PurcSample.getItem({id: $stateParams.id}, function (data) {
  7724. $scope.sample = data;
  7725. if (!$scope.sample.sends) {
  7726. $scope.sample.getSendInfo = '加载中...';
  7727. PurcSample.getSend({id: $stateParams.id}, function (sendData) {
  7728. if (sendData) {
  7729. $scope.sample.getSendInfo = null;
  7730. $scope.sample.sends = sendData;
  7731. } else {
  7732. $scope.sample.getSendInfo = '无送样信息';
  7733. $scope.sample.sends = '无送样信息';
  7734. }
  7735. }, function (response) {
  7736. $scope.sample.getSendInfo = '加载失败!';
  7737. toaster.pop('error', '', response.data);
  7738. });
  7739. }
  7740. $scope.loading = false;
  7741. }, function (response) {
  7742. loading = false;
  7743. toaster.pop('error', '获取数据失败', response.data);
  7744. });
  7745. };
  7746. loadData();
  7747. $scope.openSend = function (index, sample) {
  7748. var modalInstance = $modal.open({
  7749. animation: true,
  7750. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7751. controller: 'SampleSendCtrl',
  7752. resolve: {
  7753. sampleItem: function () {
  7754. return sample;
  7755. }
  7756. }
  7757. });
  7758. modalInstance.result.then(function () {
  7759. toaster.pop('info', '提示', '送样成功');
  7760. $scope.tableParams.reload();
  7761. }, function () {
  7762. });
  7763. };
  7764. }]);
  7765. /**
  7766. * 客户打样申请
  7767. */
  7768. 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) {
  7769. BaseService.scrollBackToTop();
  7770. // 获取当前用户是否为普通用户
  7771. CurrentRole.isUser({}, {}, function (data) {
  7772. $scope.isUser = data.isUser;
  7773. });
  7774. if ($rootScope.active) {
  7775. $scope.active = $rootScope.active;
  7776. $rootScope.active = null;
  7777. } else {
  7778. $scope.active = 'todo';
  7779. }
  7780. $scope.agreedText = '全部';
  7781. $scope.dateZoneText = '一个月内';
  7782. $scope.condition = {dateZone: 1};
  7783. /*初始化筛选时间*/
  7784. var fromDate = new Date();
  7785. var toDate = new Date();
  7786. fromDate.setMonth(fromDate.getMonth() - 1);
  7787. fromDate.setHours(0, 0, 0, 0);
  7788. toDate.setHours(23, 59, 59, 999);
  7789. $scope.condition.dateFrom = fromDate;
  7790. $scope.condition.dateTo = toDate;
  7791. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  7792. $scope.changeAgreed = function (agreed) {
  7793. $scope.condition.agreed = agreed;
  7794. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  7795. $scope.condition.$agreedOpen = false;
  7796. };
  7797. $scope.changeDateZone = function (zone) {
  7798. $scope.condition.dateZone = zone;
  7799. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  7800. $scope.condition.$dateZoneOpen = false;
  7801. getDateCondition(zone, $scope.condition);
  7802. $scope.tableParams.page(1);
  7803. $scope.tableParams.reload();
  7804. };
  7805. $scope.setActive = function (state) {
  7806. if ($scope.active != state) {
  7807. $scope.active = state;
  7808. if ($scope.tableParams.page() == 1)
  7809. $scope.tableParams.reload();
  7810. else
  7811. $scope.tableParams.page(1);
  7812. }
  7813. };
  7814. $scope.searchMethod = false;
  7815. var getService = function () {
  7816. return $scope.searchMethod ? PurcSample : PurcSampleInfo;
  7817. };
  7818. $scope.tableParams = new ngTableParams({
  7819. page: 1,
  7820. count: 20,
  7821. sorting: {
  7822. proofingDate: 'desc'
  7823. }
  7824. }, {
  7825. total: 0,
  7826. counts: [5, 10, 25, 50],
  7827. getData: function ($defer, params) {
  7828. $scope.loading = true;
  7829. var pageParams = params.url();
  7830. pageParams.searchFilter = {
  7831. keyword: $scope.keyword,
  7832. fromDate: getDateTime($scope.condition.dateFrom),
  7833. endDate: getDateTime($scope.condition.dateTo)
  7834. };
  7835. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  7836. $scope.loading = false;
  7837. if (page) {
  7838. params.total(page.totalElement);
  7839. $defer.resolve(page.content);
  7840. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  7841. }
  7842. getUnreadCount();
  7843. }, function (response) {
  7844. $scope.loading = false;
  7845. toaster.pop('error', '数据加载失败', response.data);
  7846. });
  7847. }
  7848. });
  7849. //获得各分类未阅读数量
  7850. var getUnreadCount = function () {
  7851. PurcSample.getUnreadCount(null, function(data){
  7852. $scope.unread = data;
  7853. });
  7854. };
  7855. getUnreadCount();
  7856. //设置单个单据已读
  7857. $scope.setOrdersRead = function (id) {
  7858. if (!$scope.isUnread(id)) {
  7859. return;
  7860. }
  7861. var sourceId = [];
  7862. sourceId.push(id);
  7863. PurcSample.setRead({}, sourceId, function (message) {
  7864. getUnreadIds();
  7865. getUnreadCount();
  7866. });
  7867. };
  7868. //获取未读单据id
  7869. var getUnreadIds = function (){
  7870. PurcSample.getUnreadIds({}, "", function (message) {
  7871. $scope.unreadCode = message.content;
  7872. });
  7873. };
  7874. getUnreadIds();
  7875. //判断单据是否未读
  7876. $scope.isUnread = function (id){
  7877. for (var i in $scope.unreadCode) {
  7878. if (id == $scope.unreadCode[i]) {
  7879. return true;
  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.openSend = function (index, sample) {
  7897. var modalInstance = $modal.open({
  7898. animation: true,
  7899. templateUrl: 'static/tpl/index/sale/sample_send.html',
  7900. controller: 'SampleSendCtrl',
  7901. resolve: {
  7902. sampleItem: function () {
  7903. return sample;
  7904. }
  7905. }
  7906. });
  7907. modalInstance.result.then(function () {
  7908. toaster.pop('info', '提示', '送样成功');
  7909. $scope.tableParams.reload();
  7910. }, function () {
  7911. });
  7912. };
  7913. //打印 样品采购单
  7914. $scope.print = function (sample) {
  7915. var newPage = window.open("about:blank");
  7916. PurcSample.printPermission({}, function () {
  7917. PurcSample.printCount({id: sample.id}, {});//增加打印此次
  7918. ReportService.print(sample.proofing.enUU, 'PURCPROOFING', "where purc$proofingitems.ppi_id =" + sample.id, newPage);
  7919. }, function (response) {
  7920. newPage.close();
  7921. toaster.pop('error', '打印失败', response.data);
  7922. });
  7923. };
  7924. $scope.getSend = function (proofing) {
  7925. if (!proofing.sends) {
  7926. proofing.getSendInfo = '加载中...';
  7927. PurcSample.getSend({id: proofing.id}, function (data) {
  7928. if (data) {
  7929. proofing.getSendInfo = null;
  7930. proofing.sends = data;
  7931. } else {
  7932. proofing.getSendInfo = '无送样信息';
  7933. proofing.sends = '无送样信息';
  7934. }
  7935. }, function (response) {
  7936. proofing.getSendInfo = '加载失败!';
  7937. });
  7938. }
  7939. };
  7940. // 搜索框回车
  7941. $scope.onSearch = function (keyword) {
  7942. // 每次搜索重置获取数据方法
  7943. $scope.searchMethod = false;
  7944. if(keyword != null && keyword != '') {
  7945. $scope.searchMethod = true;
  7946. }
  7947. $scope.tableParams.page(1);
  7948. $scope.tableParams.reload();
  7949. };
  7950. // 导出
  7951. $scope.exportXls = function () {
  7952. PurcSample.exportXls({}, {}, function (data) {
  7953. if (data.success){
  7954. window.location.href = 'sale/sample/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  7955. }
  7956. }, function (response) {
  7957. toaster.pop('error', '数据加载失败', response.data);
  7958. });
  7959. }
  7960. }]);
  7961. app.controller('SampleSendCtrl', ['$scope', '$modalInstance', 'sampleItem', 'PurcSample', '$upload', 'toaster', function ($scope, $modalInstance, sampleItem, PurcSample, $upload, toaster) {
  7962. if (!sampleItem.sends) {
  7963. PurcSample.getSend({id: sampleItem.id}, function (data) {
  7964. if (data) {
  7965. sampleItem.sends = data; // 获取送样信息
  7966. angular.forEach(data, function (send) {
  7967. sampleItem.sendQty = send.sendQty + (sampleItem.sendQty || 0);
  7968. });
  7969. }
  7970. }, function (response) {
  7971. });
  7972. }
  7973. $scope.sampleItem = sampleItem;
  7974. $scope.sampleItem.sampleSend = $scope.sampleItem.sampleSend || {};
  7975. //确认送样
  7976. $scope.ok = function (form) {
  7977. $scope.loading = true;
  7978. // 多次送样时,由于ng-model是sendQty,所以需要加上送样历史中的数量
  7979. $scope.sampleItem.sampleSend.sendQty = $scope.sampleItem.sampleSend.sendQty + ($scope.sampleItem.sendQty || 0);
  7980. $scope.sampleItem.sendQty = $scope.sampleItem.sampleSend.sendQty; // 判断是否需要多次送样
  7981. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  7982. $upload.upload({
  7983. url: 'sale/sample/' + $scope.sampleItem.id + '/send',
  7984. method: 'POST',
  7985. file: file,
  7986. data: {
  7987. json: $scope.sampleItem.sampleSend
  7988. }
  7989. }).success(function (data) {
  7990. $scope.loading = false;
  7991. $modalInstance.close('success');
  7992. }).error(function (data) {
  7993. $scope.loading = false;
  7994. toaster.pop('error', '错误', data);
  7995. });
  7996. };
  7997. $scope.cancel = function () {
  7998. $modalInstance.dismiss(sampleItem);
  7999. };
  8000. //设置单个单据已读
  8001. $scope.setOrdersRead = function (id) {
  8002. var sourceId = [];
  8003. sourceId.push(id);
  8004. PurcSample.setRead({}, sourceId, function (message) {
  8005. // $scope.getUnreadIds();
  8006. });
  8007. };
  8008. }]);
  8009. /**
  8010. * 客户认定单
  8011. */
  8012. app.controller('SaleApprovalCtrl', ['$scope', '$filter', 'PurcApproval', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcApproval, ngTableParams, toaster, BaseService, Symbol) {
  8013. BaseService.scrollBackToTop();
  8014. $scope.active = 'all';
  8015. $scope.agreedText = '全部';
  8016. $scope.dateZoneText = '一个月内';
  8017. $scope.condition = {dateZone: 1};
  8018. /* 时间筛选初始化*/
  8019. var fromDate = new Date();
  8020. var toDate = new Date();
  8021. fromDate.setMonth(fromDate.getMonth() - 1);
  8022. fromDate.setHours(0, 0, 0, 0);
  8023. toDate.setHours(23, 59, 59, 999);
  8024. $scope.condition.dateFrom = fromDate;
  8025. $scope.condition.dateTo = toDate;
  8026. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8027. $scope.changeDateZone = function (zone) {
  8028. $scope.condition.dateZone = zone;
  8029. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8030. $scope.condition.$dateZoneOpen = false;
  8031. getDateCondition(zone, $scope.condition);
  8032. $scope.tableParams.page(1);
  8033. $scope.tableParams.reload();
  8034. };
  8035. $scope.setActive = function (state) {
  8036. if ($scope.active != state) {
  8037. $scope.active = state;
  8038. if ($scope.tableParams.page() == 1)
  8039. $scope.tableParams.reload();
  8040. else
  8041. $scope.tableParams.page(1);
  8042. }
  8043. };
  8044. var getService = function () {
  8045. return PurcApproval;
  8046. };
  8047. $scope.tableParams = new ngTableParams({
  8048. page: 1,
  8049. count: 20,
  8050. sorting: {
  8051. inDate: 'desc'
  8052. }
  8053. }, {
  8054. total: 0,
  8055. counts: [5, 10, 25, 50],
  8056. getData: function ($defer, params) {
  8057. $scope.loading = true;
  8058. var pageParams = params.url();
  8059. pageParams.keyword = $scope.keyword;
  8060. pageParams.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  8061. pageParams.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  8062. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8063. $scope.loading = false;
  8064. if (page) {
  8065. params.total(page.totalElement);
  8066. $defer.resolve(page.content);
  8067. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8068. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  8069. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  8070. }
  8071. }, function (response) {
  8072. $scope.loading = false;
  8073. toaster.pop('error', '数据加载失败', response.data);
  8074. });
  8075. }
  8076. });
  8077. $scope.openDatePicker = function ($event, item, openParam) {
  8078. $event.preventDefault();
  8079. $event.stopPropagation();
  8080. item[openParam] = !item[openParam];
  8081. };
  8082. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8083. $event.preventDefault();
  8084. $event.stopPropagation();
  8085. item[openParam] = !item[openParam];
  8086. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8087. $scope.tableParams.reload();
  8088. }
  8089. };
  8090. $scope.parseDate = function (dateStr) {
  8091. if (dateStr)
  8092. return Date.parse(dateStr, 'yyyy-MM-dd');
  8093. return new Date();
  8094. };
  8095. // 搜索框回车
  8096. $scope.onSearch = function () {
  8097. $scope.tableParams.page(1);
  8098. $scope.tableParams.reload();
  8099. };
  8100. // 选择查找日期
  8101. $scope.onDateCondition = function () {
  8102. $scope.tableParams.page(1);
  8103. $scope.tableParams.reload();
  8104. };
  8105. // 导出
  8106. $scope.exportXls = function () {
  8107. PurcApproval.exportXls({}, {}, function (data) {
  8108. if (data.success){
  8109. window.location.href = 'sale/sample/approval/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  8110. }
  8111. }, function (response) {
  8112. toaster.pop('error', '数据加载失败', response.data);
  8113. });
  8114. }
  8115. }]);
  8116. /**
  8117. * 客户采购预测
  8118. */
  8119. app.controller('SaleForecastCtrl', ['$scope', '$filter', 'PurcForecast', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcForecast, ngTableParams, toaster, BaseService, Symbol) {
  8120. BaseService.scrollBackToTop();
  8121. $scope.active = 'all';
  8122. $scope.agreedText = '全部';
  8123. $scope.dateZoneText = '一个月内';
  8124. $scope.condition = {dateZone: 1};
  8125. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8126. $scope.changeAgreed = function (agreed) {
  8127. $scope.condition.agreed = agreed;
  8128. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8129. $scope.condition.$agreedOpen = false;
  8130. };
  8131. $scope.changeDateZone = function (zone) {
  8132. $scope.condition.dateZone = zone;
  8133. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  8134. $scope.condition.$dateZoneOpen = false;
  8135. };
  8136. $scope.setActive = function (state) {
  8137. if ($scope.active != state) {
  8138. $scope.active = state;
  8139. if ($scope.tableParams.page() == 1)
  8140. $scope.tableParams.reload();
  8141. else
  8142. $scope.tableParams.page(1);
  8143. }
  8144. };
  8145. var getService = function () {
  8146. return PurcForecast;
  8147. };
  8148. $scope.tableParams = new ngTableParams({
  8149. page: 1,
  8150. count: 20,
  8151. sorting: {
  8152. orderDate: 'desc'
  8153. }
  8154. }, {
  8155. total: 0,
  8156. counts: [5, 10, 25, 50],
  8157. getData: function ($defer, params) {
  8158. $scope.loading = true;
  8159. var pageParams = params.url();
  8160. pageParams.keyword = $scope.keyword;
  8161. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8162. $scope.loading = false;
  8163. if (page) {
  8164. params.total(page.totalElement);
  8165. $defer.resolve(page.content);
  8166. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  8167. }
  8168. }, function (response) {
  8169. $scope.loading = false;
  8170. toaster.pop('error', '数据加载失败', response.data);
  8171. });
  8172. }
  8173. });
  8174. $scope.openDatePicker = function ($event, item, openParam) {
  8175. $event.preventDefault();
  8176. $event.stopPropagation();
  8177. item[openParam] = !item[openParam];
  8178. };
  8179. // 搜索框回车
  8180. $scope.onSearch = function () {
  8181. $scope.tableParams.page(1);
  8182. $scope.tableParams.reload();
  8183. };
  8184. }]);
  8185. /**
  8186. * 客户采购验收
  8187. */
  8188. app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8189. BaseService.scrollBackToTop();
  8190. // 获取当前用户是否为普通用户
  8191. CurrentRole.isUser({}, {}, function (data) {
  8192. $scope.isUser = data.isUser;
  8193. });
  8194. $scope.active = 'all';
  8195. $scope.dateZoneText = '不限';
  8196. $scope.deliveryZoneText = '不限';
  8197. $scope.condition = {dateZone: 1, deliveryZone: -1};
  8198. /* 时间筛选初始化*/
  8199. var fromDate = new Date();
  8200. var toDate = new Date();
  8201. fromDate.setMonth(fromDate.getMonth() - 1);
  8202. fromDate.setHours(0, 0, 0, 0);
  8203. toDate.setHours(23, 59, 59, 999);
  8204. $scope.condition.dateFrom = fromDate;
  8205. $scope.condition.dateTo = toDate;
  8206. $scope.changeDateZone = function (zone) {
  8207. $scope.condition.dateZone = zone;
  8208. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8209. $scope.condition.$dateZoneOpen = false;
  8210. getDateCondition(zone, $scope.condition);
  8211. $scope.tableParams.page(1);
  8212. $scope.tableParams.reload();
  8213. };
  8214. $scope.changeDeliveryZone = function (zone) {
  8215. $scope.condition.deliveryZoneText = zone;
  8216. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  8217. $scope.condition.$delievryZoneOpen = false;
  8218. getDelveryCondition(zone, $scope.condition);
  8219. $scope.tableParams.reload();
  8220. };
  8221. $scope.setActive = function (state) {
  8222. if ($scope.active != state) {
  8223. $scope.active = state;
  8224. if ($scope.tableParams.page() == 1)
  8225. $scope.tableParams.reload();
  8226. else
  8227. $scope.tableParams.page(1);
  8228. }
  8229. };
  8230. var getService = function () {
  8231. return PurcAccept;
  8232. };
  8233. $scope.tableParams = new ngTableParams({
  8234. page: 1,
  8235. count: 20,
  8236. sorting: {
  8237. date: 'desc'
  8238. }
  8239. }, {
  8240. total: 0,
  8241. counts: [5, 10, 25, 50],
  8242. getData: function ($defer, params) {
  8243. $scope.loading = true;
  8244. var pageParams = params.url();
  8245. pageParams.searchFilter = { // 筛选条件
  8246. keyword: $scope.keyword,
  8247. fromDate: getDateTime($scope.condition.dateFrom),
  8248. endDate: getDateTime($scope.condition.dateTo)
  8249. };
  8250. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8251. $scope.loading = false;
  8252. if (page) {
  8253. params.total(page.totalElement);
  8254. $defer.resolve(page.content);
  8255. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8256. }
  8257. }, function (response) {
  8258. $scope.loading = false;
  8259. toaster.pop('error', '数据加载失败', response.data);
  8260. });
  8261. }
  8262. });
  8263. $scope.openDatePicker = function ($event, item, openParam) {
  8264. $event.preventDefault();
  8265. $event.stopPropagation();
  8266. item[openParam] = !item[openParam];
  8267. };
  8268. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8269. $event.preventDefault();
  8270. $event.stopPropagation();
  8271. item[openParam] = !item[openParam];
  8272. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8273. $scope.tableParams.reload();
  8274. }
  8275. };
  8276. $scope.parseDate = function (dateStr) {
  8277. if (dateStr)
  8278. return Date.parse(dateStr, 'yyyy-MM-dd');
  8279. return new Date();
  8280. };
  8281. // 选择查找日期
  8282. $scope.onDateCondition = function () {
  8283. $scope.tableParams.page(1);
  8284. $scope.tableParams.reload();
  8285. };
  8286. // 搜索框回车
  8287. $scope.onSearch = function () {
  8288. $scope.tableParams.page(1);
  8289. $scope.tableParams.reload();
  8290. };
  8291. // 导出
  8292. $scope.exportXls = function () {
  8293. PurcAccept.exportXls({}, {}, function (data) {
  8294. if (data.success){
  8295. window.location.href = 'sale/accept/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8296. }
  8297. }, function (response) {
  8298. toaster.pop('error', '数据加载失败', response.data);
  8299. });
  8300. }
  8301. }]);
  8302. /**
  8303. * 客户采购验收详情
  8304. */
  8305. app.controller('SaleAcceptDetailCtrl', ['$scope', 'PurcAccept', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcAccept, toaster, BaseService, $stateParams, CurrentRole) {
  8306. BaseService.scrollBackToTop();
  8307. // 获取当前用户是否为普通用户
  8308. CurrentRole.isUser({}, {}, function (data) {
  8309. $scope.isUser = data.isUser;
  8310. });
  8311. if ($stateParams.id) {
  8312. PurcAccept.getDetail({id: $stateParams.id}, {}, function (data) {
  8313. $scope.accept = data;
  8314. if ($scope.accept.acceptItems != null) {
  8315. var sum = 0;
  8316. angular.forEach($scope.accept.acceptItems, function (item) {
  8317. if (item.orderPrice == null) {
  8318. item.orderPrice = 0;
  8319. }
  8320. sum += item.orderPrice * item.qty;
  8321. });
  8322. $scope.totalPrice = sum;
  8323. }
  8324. }, function (response) {
  8325. toaster.pop('error', '提示', response.data);
  8326. });
  8327. }
  8328. }]);
  8329. /**
  8330. * 客户采购验退
  8331. */
  8332. app.controller('SaleReturnsCtrl', ['$scope', '$filter', 'PurcReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8333. BaseService.scrollBackToTop();
  8334. // 获取当前用户是否为普通用户
  8335. CurrentRole.isUser({}, {}, function (data) {
  8336. $scope.isUser = data.isUser;
  8337. });
  8338. $scope.active = 'all';
  8339. $scope.agreedText = '全部';
  8340. $scope.dateZoneText = '一个月内';
  8341. $scope.condition = {dateZone: 1};
  8342. /* 时间筛选初始化*/
  8343. var fromDate = new Date();
  8344. var toDate = new Date();
  8345. fromDate.setMonth(fromDate.getMonth() - 1);
  8346. fromDate.setHours(0, 0, 0, 0);
  8347. toDate.setHours(23, 59, 59, 999);
  8348. $scope.condition.dateFrom = fromDate;
  8349. $scope.condition.dateTo = toDate;
  8350. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8351. $scope.changeAgreed = function (agreed) {
  8352. $scope.condition.agreed = agreed;
  8353. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8354. $scope.condition.$agreedOpen = false;
  8355. };
  8356. $scope.changeDateZone = function (zone) {
  8357. $scope.condition.dateZone = zone;
  8358. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8359. $scope.condition.$dateZoneOpen = false;
  8360. getDateCondition(zone, $scope.condition);
  8361. $scope.tableParams.page(1);
  8362. $scope.tableParams.reload();
  8363. };
  8364. $scope.setActive = function (state) {
  8365. if ($scope.active != state) {
  8366. $scope.active = state;
  8367. if ($scope.tableParams.page() == 1)
  8368. $scope.tableParams.reload();
  8369. else
  8370. $scope.tableParams.page(1);
  8371. }
  8372. };
  8373. var getService = function () {
  8374. return PurcReturn;
  8375. };
  8376. $scope.tableParams = new ngTableParams({
  8377. page: 1,
  8378. count: 20,
  8379. sorting: {
  8380. date: 'desc'
  8381. }
  8382. }, {
  8383. total: 0,
  8384. counts: [5, 10, 25, 50],
  8385. getData: function ($defer, params) {
  8386. $scope.loading = true;
  8387. var pageParams = params.url();
  8388. pageParams.searchFilter = {
  8389. keyword: $scope.keyword,
  8390. fromDate: getDateTime($scope.condition.dateFrom),
  8391. endDate: getDateTime($scope.condition.dateTo)
  8392. };
  8393. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8394. $scope.loading = false;
  8395. if (page) {
  8396. params.total(page.totalElement);
  8397. $defer.resolve(page.content);
  8398. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8399. angular.forEach(page.content, function (data) {
  8400. if (!data.returnItems[0].orderItem) {
  8401. PurcReturn.getEnterpriseName({id: data.id, enuu: data.enUU}, function (enterprise) {
  8402. data.enName = enterprise.enName;
  8403. });
  8404. }
  8405. });
  8406. }
  8407. }, function (response) {
  8408. $scope.loading = false;
  8409. toaster.pop('error', '数据加载失败', response.data);
  8410. });
  8411. }
  8412. });
  8413. $scope.openDatePicker = function ($event, item, openParam) {
  8414. $event.preventDefault();
  8415. $event.stopPropagation();
  8416. item[openParam] = !item[openParam];
  8417. };
  8418. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8419. $event.preventDefault();
  8420. $event.stopPropagation();
  8421. item[openParam] = !item[openParam];
  8422. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8423. $scope.tableParams.reload();
  8424. }
  8425. };
  8426. // 搜索框回车
  8427. $scope.onSearch = function () {
  8428. $scope.tableParams.page(1);
  8429. $scope.tableParams.reload();
  8430. };
  8431. // 导出
  8432. $scope.exportXls = function () {
  8433. PurcReturn.exportXls({}, {}, function (data) {
  8434. if (data.success){
  8435. window.location.href = 'sale/return/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8436. }
  8437. }, function (response) {
  8438. toaster.pop('error', '数据加载失败', response.data);
  8439. });
  8440. }
  8441. }]);
  8442. /**
  8443. * 客户采购验退详情
  8444. */
  8445. app.controller('SaleReturnsDetailCtrl', ['$scope', 'PurcReturn', 'toaster', 'BaseService', '$stateParams', 'CurrentRole', function ($scope, PurcReturn, toaster, BaseService, $stateParams, CurrentRole) {
  8446. BaseService.scrollBackToTop();'' +
  8447. // 获取当前用户是否为普通用户
  8448. CurrentRole.isUser({}, {}, function (data) {
  8449. $scope.isUser = data.isUser;
  8450. });
  8451. if ($stateParams.id != null) {
  8452. PurcReturn.getDetail({id: $stateParams.id}, {}, function (data) {
  8453. $scope.returns = data;
  8454. if ($scope.returns.returnItems != null) {
  8455. var sum = 0;
  8456. angular.forEach($scope.returns.returnItems, function (item) {
  8457. if (null != item.orderPrice) {
  8458. sum += item.orderPrice * item.qty;
  8459. }
  8460. });
  8461. $scope.totalPrice = sum;
  8462. }
  8463. }, function (response) {
  8464. toaster.pop('error', '提示', response.data);
  8465. });
  8466. }
  8467. }]);
  8468. /**
  8469. * 客户不良品入库
  8470. */
  8471. app.controller('SaleBadInCtrl', ['$scope', '$filter', 'PurcBadIn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadIn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8472. BaseService.scrollBackToTop();
  8473. // 获取当前用户是否为普通用户
  8474. CurrentRole.isUser({}, {}, function (data) {
  8475. $scope.isUser = data.isUser;
  8476. });
  8477. $scope.active = 'all';
  8478. $scope.agreedText = '全部';
  8479. $scope.dateZoneText = '一个月内';
  8480. $scope.condition = {dateZone: 1};
  8481. /* 时间筛选初始化*/
  8482. var fromDate = new Date();
  8483. var toDate = new Date();
  8484. fromDate.setMonth(fromDate.getMonth() - 1);
  8485. fromDate.setHours(0, 0, 0, 0);
  8486. toDate.setHours(23, 59, 59, 999);
  8487. $scope.condition.dateFrom = fromDate;
  8488. $scope.condition.dateTo = toDate;
  8489. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8490. $scope.changeAgreed = function (agreed) {
  8491. $scope.condition.agreed = agreed;
  8492. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8493. $scope.condition.$agreedOpen = false;
  8494. };
  8495. $scope.changeDateZone = function (zone) {
  8496. $scope.condition.dateZone = zone;
  8497. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8498. $scope.condition.$dateZoneOpen = false;
  8499. getDateCondition(zone, $scope.condition);
  8500. $scope.tableParams.page(1);
  8501. $scope.tableParams.reload();
  8502. };
  8503. $scope.setActive = function (state) {
  8504. if ($scope.active != state) {
  8505. $scope.active = state;
  8506. if ($scope.tableParams.page() == 1)
  8507. $scope.tableParams.reload();
  8508. else
  8509. $scope.tableParams.page(1);
  8510. }
  8511. };
  8512. var getService = function () {
  8513. return PurcBadIn;
  8514. };
  8515. $scope.tableParams = new ngTableParams({
  8516. page: 1,
  8517. count: 20,
  8518. sorting: {
  8519. date: 'desc'
  8520. }
  8521. }, {
  8522. total: 0,
  8523. counts: [5, 10, 25, 50],
  8524. getData: function ($defer, params) {
  8525. $scope.loading = true;
  8526. var pageParams = params.url();
  8527. pageParams.searchFilter = {
  8528. keyword: $scope.keyword,
  8529. fromDate: getDateTime($scope.condition.dateFrom),
  8530. endDate: getDateTime($scope.condition.dateTo)
  8531. };
  8532. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8533. $scope.loading = false;
  8534. if (page) {
  8535. params.total(page.totalElement);
  8536. $defer.resolve(page.content);
  8537. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8538. }
  8539. }, function (response) {
  8540. $scope.loading = false;
  8541. toaster.pop('error', '数据加载失败', response.data);
  8542. });
  8543. }
  8544. });
  8545. $scope.openDatePicker = function ($event, item, openParam) {
  8546. $event.preventDefault();
  8547. $event.stopPropagation();
  8548. item[openParam] = !item[openParam];
  8549. };
  8550. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8551. $event.preventDefault();
  8552. $event.stopPropagation();
  8553. item[openParam] = !item[openParam];
  8554. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8555. $scope.tableParams.reload();
  8556. }
  8557. };
  8558. // 搜索框回车
  8559. $scope.onSearch = function (keyword) {
  8560. $scope.keyword = keyword;
  8561. $scope.tableParams.page(1);
  8562. $scope.tableParams.reload();
  8563. };
  8564. // 导出
  8565. $scope.exportXls = function () {
  8566. PurcBadIn.exportXls({}, {}, function (data) {
  8567. if (data.success){
  8568. window.location.href = 'sale/badIn/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8569. }
  8570. }, function (response) {
  8571. toaster.pop('error', '数据加载失败', response.data);
  8572. });
  8573. }
  8574. }]);
  8575. /**
  8576. * 客户不良品出库
  8577. */
  8578. app.controller('SaleBadOutCtrl', ['$scope', '$filter', 'PurcBadOut', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, PurcBadOut, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  8579. BaseService.scrollBackToTop();
  8580. // 获取当前用户是否为普通用户
  8581. CurrentRole.isUser({}, {}, function (data) {
  8582. $scope.isUser = data.isUser;
  8583. });
  8584. $scope.active = 'all';
  8585. $scope.agreedText = '全部';
  8586. $scope.dateZoneText = '一个月内';
  8587. $scope.condition = {dateZone: 1};
  8588. /* 时间筛选初始化*/
  8589. var fromDate = new Date();
  8590. var toDate = new Date();
  8591. fromDate.setMonth(fromDate.getMonth() - 1);
  8592. fromDate.setHours(0, 0, 0, 0);
  8593. toDate.setHours(23, 59, 59, 999);
  8594. $scope.condition.dateFrom = fromDate;
  8595. $scope.condition.dateTo = toDate;
  8596. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8597. $scope.changeAgreed = function (agreed) {
  8598. $scope.condition.agreed = agreed;
  8599. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8600. $scope.condition.$agreedOpen = false;
  8601. };
  8602. $scope.changeDateZone = function (zone) {
  8603. $scope.condition.dateZone = zone;
  8604. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8605. $scope.condition.$dateZoneOpen = false;
  8606. getDateCondition(zone, $scope.condition);
  8607. $scope.tableParams.page(1);
  8608. $scope.tableParams.reload();
  8609. };
  8610. $scope.setActive = function (state) {
  8611. if ($scope.active != state) {
  8612. $scope.active = state;
  8613. if ($scope.tableParams.page() == 1)
  8614. $scope.tableParams.reload();
  8615. else
  8616. $scope.tableParams.page(1);
  8617. }
  8618. };
  8619. var getService = function () {
  8620. return PurcBadOut;
  8621. };
  8622. $scope.tableParams = new ngTableParams({
  8623. page: 1,
  8624. count: 20,
  8625. sorting: {
  8626. date: 'desc'
  8627. }
  8628. }, {
  8629. total: 0,
  8630. counts: [5, 10, 25, 50],
  8631. getData: function ($defer, params) {
  8632. $scope.loading = true;
  8633. var pageParams = params.url();
  8634. pageParams.searchFilter = {
  8635. keyword: $scope.keyword,
  8636. fromDate: getDateTime($scope.condition.dateFrom),
  8637. endDate: getDateTime($scope.condition.dateTo)
  8638. };
  8639. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8640. $scope.loading = false;
  8641. if (page) {
  8642. params.total(page.totalElement);
  8643. $defer.resolve(page.content);
  8644. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8645. }
  8646. }, function (response) {
  8647. $scope.loading = false;
  8648. toaster.pop('error', '数据加载失败', response.data);
  8649. });
  8650. }
  8651. });
  8652. $scope.openDatePicker = function ($event, item, openParam) {
  8653. $event.preventDefault();
  8654. $event.stopPropagation();
  8655. item[openParam] = !item[openParam];
  8656. };
  8657. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8658. $event.preventDefault();
  8659. $event.stopPropagation();
  8660. item[openParam] = !item[openParam];
  8661. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8662. $scope.tableParams.reload();
  8663. }
  8664. };
  8665. // 搜索框回车
  8666. $scope.onSearch = function () {
  8667. $scope.tableParams.page(1);
  8668. $scope.tableParams.reload();
  8669. };
  8670. // 导出
  8671. $scope.exportXls = function () {
  8672. PurcBadOut.exportXls({}, {}, function (data) {
  8673. if (data.success){
  8674. window.location.href = 'sale/badOut/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8675. }
  8676. }, function (response) {
  8677. toaster.pop('error', '数据加载失败', response.data);
  8678. });
  8679. }
  8680. }]);
  8681. /**
  8682. * 客户MRB
  8683. */
  8684. app.controller('SaleMRBCtrl', ['$scope', '$filter', 'PurcMRB', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, PurcMRB, ngTableParams, toaster, BaseService, Symbol) {
  8685. BaseService.scrollBackToTop();
  8686. $scope.active = 'all';
  8687. $scope.agreedText = '全部';
  8688. $scope.dateZoneText = '一个月内';
  8689. $scope.condition = {dateZone: 1};
  8690. /* 时间筛选初始化*/
  8691. var fromDate = new Date();
  8692. var toDate = new Date();
  8693. fromDate.setMonth(fromDate.getMonth() - 1);
  8694. fromDate.setHours(0, 0, 0, 0);
  8695. toDate.setHours(23, 59, 59, 999);
  8696. $scope.condition.dateFrom = fromDate;
  8697. $scope.condition.dateTo = toDate;
  8698. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8699. $scope.changeAgreed = function (agreed) {
  8700. $scope.condition.agreed = agreed;
  8701. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  8702. $scope.condition.$agreedOpen = false;
  8703. };
  8704. $scope.changeDateZone = function (zone) {
  8705. $scope.condition.dateZone = zone;
  8706. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8707. $scope.condition.$dateZoneOpen = false;
  8708. getDateCondition(zone, $scope.condition);
  8709. $scope.tableParams.page(1);
  8710. $scope.tableParams.reload();
  8711. };
  8712. $scope.setActive = function (state) {
  8713. if ($scope.active != state) {
  8714. $scope.active = state;
  8715. if ($scope.tableParams.page() == 1)
  8716. $scope.tableParams.reload();
  8717. else
  8718. $scope.tableParams.page(1);
  8719. }
  8720. };
  8721. var getService = function () {
  8722. return PurcMRB;
  8723. };
  8724. $scope.tableParams = new ngTableParams({
  8725. page: 1,
  8726. count: 20,
  8727. sorting: {
  8728. date: 'desc'
  8729. }
  8730. }, {
  8731. total: 0,
  8732. counts: [5, 10, 25, 50],
  8733. getData: function ($defer, params) {
  8734. $scope.loading = true;
  8735. var pageParams = params.url();
  8736. pageParams.searchFilter = {
  8737. keyword: $scope.keyword,
  8738. fromDate: getDateTime($scope.condition.dateFrom),
  8739. endDate: getDateTime($scope.condition.dateTo)
  8740. };
  8741. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  8742. $scope.loading = false;
  8743. if (page) {
  8744. params.total(page.totalElement);
  8745. $defer.resolve(page.content);
  8746. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  8747. }
  8748. }, function (response) {
  8749. $scope.loading = false;
  8750. toaster.pop('error', '数据加载失败', response.data);
  8751. });
  8752. }
  8753. });
  8754. $scope.openDatePicker = function ($event, item, openParam) {
  8755. $event.preventDefault();
  8756. $event.stopPropagation();
  8757. item[openParam] = !item[openParam];
  8758. };
  8759. $scope.openFilterDatePicker = function ($event, item, openParam) {
  8760. $event.preventDefault();
  8761. $event.stopPropagation();
  8762. item[openParam] = !item[openParam];
  8763. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  8764. $scope.tableParams.reload();
  8765. }
  8766. };
  8767. // 搜索框回车
  8768. $scope.onSearch = function () {
  8769. $scope.tableParams.page(1);
  8770. $scope.tableParams.reload();
  8771. };
  8772. // 导出
  8773. $scope.exportXls = function () {
  8774. PurcMRB.exportXls({}, {}, function (data) {
  8775. if (data.success){
  8776. window.location.href = 'sale/MRB/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  8777. }
  8778. }, function (response) {
  8779. toaster.pop('error', '数据加载失败', response.data);
  8780. });
  8781. }
  8782. }]);
  8783. //客户航天开票
  8784. app.controller('PurchaseApBillOutCtrl',['$scope', 'FaApBillOut', 'BaseService', 'ngTableParams', 'toaster','ReportService', 'Symbol', function ($scope, FaApBillOut, BaseService, ngTableParams, toaster, ReportService , Symbol) {
  8785. BaseService.scrollBackToTop();
  8786. $scope.dateZoneText = '不限';
  8787. $scope.condition = {dateZone: 1};
  8788. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  8789. $scope.active = 'all';
  8790. /* 时间筛选初始化*/
  8791. var fromDate = new Date();
  8792. var toDate = new Date();
  8793. fromDate.setMonth(fromDate.getMonth() - 1);
  8794. fromDate.setHours(0,0,0,0);
  8795. toDate.setHours(23,59,59,999);
  8796. $scope.condition.dateFrom = fromDate;
  8797. $scope.condition.dateTo = toDate;
  8798. //打印 开票单
  8799. $scope.print = function (billOut) {
  8800. FaApBillOut.printCount({id: billOut.id},function (data) {
  8801. if(!data.error) {
  8802. toaster.pop('success', '提示', '打印成功');
  8803. //$scope.tableParams.reload();
  8804. }else{
  8805. toaster.pop('error', '提示', '打印失败');
  8806. }
  8807. });
  8808. //ReportService.print(billOut.custUu, 'PURCBILLOUT', 'where purc$apbillout.pabo_id =' + billOut.id);
  8809. };
  8810. //状态
  8811. $scope.setActive = function (state) {
  8812. if($scope.active != state) {
  8813. $scope.active = state;
  8814. if($scope.tableParams.page() == 1)
  8815. $scope.tableParams.reload();
  8816. else
  8817. $scope.tableParams.page(1);
  8818. }
  8819. };
  8820. $scope.changeDateZone = function (zone) {
  8821. $scope.condition.dateZone = zone;
  8822. $scope.dateZoneText = zone == 1? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  8823. $scope.condition.$dateZoneOpen = false;
  8824. getDateCondition(zone, $scope.condition);
  8825. $scope.tableParams.page(1);
  8826. $scope.tableParams.reload();
  8827. };
  8828. //获取全部已确定应收对账单
  8829. $scope.tableParams = new ngTableParams({
  8830. page: 1,
  8831. count: 20,
  8832. sorting: {
  8833. recordDate: 'desc'
  8834. }
  8835. }, {
  8836. total: 0,
  8837. counts: [5, 10, 25, 50],
  8838. getData: function ($defer, params) {
  8839. $scope.loading = true;
  8840. var pageParams = params.url();
  8841. pageParams.searchFilter = { // 筛选条件
  8842. keyword: $scope.keyword,
  8843. fromDate: getDateTime($scope.condition.dateFrom),
  8844. endDate: getDateTime($scope.condition.dateTo)
  8845. };
  8846. FaApBillOut[getState($scope.active )](BaseService.parseParams(pageParams), function (page) {
  8847. $scope.loading = false;
  8848. if(page) {
  8849. params.total(page.totalElement);
  8850. $scope.data = $defer.resolve(page.content);
  8851. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  8852. }
  8853. }, function (response) {
  8854. $scope.loading = false;
  8855. toaster.pop('error', '数据加载失败', response.data);
  8856. });
  8857. }
  8858. });
  8859. $scope.openDatePicker = function ($event, item, openParam) {
  8860. $event.preventDefault();
  8861. $event.stopPropagation();
  8862. item[openParam] = !item[openParam];
  8863. if($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]){
  8864. $scope.tableParams.reload();
  8865. }
  8866. };
  8867. // 计算开票数量
  8868. $scope.getTotalProd = function (billOut) {
  8869. var total = 0;
  8870. if(billOut.items) {
  8871. angular.forEach(billOut.items, function (value) {
  8872. total += value.NowQty;
  8873. });
  8874. }
  8875. return total;
  8876. };
  8877. // 搜索框回车
  8878. $scope.onSearch = function () {
  8879. $scope.tableParams.page(1);
  8880. $scope.tableParams.reload();
  8881. };
  8882. // 选择查找日期
  8883. $scope.onDateCondition = function () {
  8884. $scope.tableParams.page(1);
  8885. $scope.tableParams.reload();
  8886. };
  8887. }]);
  8888. //开票单详情
  8889. app.controller('PurchaseApBillOutDetailCtrl',['$scope', 'toaster', 'FaApBillOut', 'FaApCheck', '$stateParams', 'BaseService', function ($scope, toaster, FaApBillOut, FaApCheck, $stateParams, BaseService) {
  8890. BaseService.scrollBackToTop();
  8891. $scope.haveSelected = true;
  8892. $scope.data = {};
  8893. //控制提交和删除按钮的显示
  8894. $scope.ifShow = true;
  8895. var loadData = function () {
  8896. FaApBillOut.get({id:$stateParams.id},function (data) {
  8897. $scope.data = data;
  8898. if($scope.data.status){
  8899. }else{
  8900. $scope.ifShow = true;
  8901. }
  8902. })
  8903. };
  8904. if($stateParams.id){
  8905. loadData();
  8906. }
  8907. $scope.haveSource = false;
  8908. //TODO 提交开票单
  8909. $scope.invoiceIssued = function (apBillOut) {
  8910. $scope.loading = true;
  8911. FaApBillOut.invoiceIssued({id:apBillOut.id},function (data) {
  8912. $scope.loading = false;
  8913. if(data.apBillOut) {
  8914. $scope.haveSelected = false;
  8915. window.location.href = '#/fa/apBillOut';
  8916. toaster.pop('success', '提示', '提交成功');
  8917. } else {
  8918. $scope.loading = false;
  8919. toaster.pop('error', '提示', data.error);
  8920. }
  8921. })
  8922. }
  8923. //删除开票单(后台同时更新对账单明细表已开票数)
  8924. $scope.deleteApBillOut = function () {
  8925. FaApBillOut.deleteApBillOut({id:$stateParams.id},function (data) {
  8926. window.location.href = '#/fa/apBillOut';
  8927. toaster.pop('success','提示','删除成功');
  8928. },function () {
  8929. toaster.pop('error','提示','删除失败');
  8930. });
  8931. $scope.haveSelected = false;
  8932. }
  8933. //TODO 作废开票单
  8934. $scope.InvoiceCancel = function () {
  8935. $scope.loading = true;
  8936. FaApBillOut.InvoiceCancel({id:$stateParams.id},function (data) {
  8937. $scope.loading = false;
  8938. if(!data.error) {
  8939. toaster.pop('success', '提示', '作废成功');
  8940. window.location.href = '#/fa/apBillOut';
  8941. $scope.tableParams.reload();
  8942. }else{
  8943. toaster.pop('error', '提示', data.error);
  8944. }
  8945. },function (response) {
  8946. $scope.loading = false;
  8947. toaster.pop('error', '提示', response.data);
  8948. });
  8949. }
  8950. }]);
  8951. //航天开票单据列表
  8952. app.controller('PurchaseApBillOutListCtrl',['$scope', 'FaApCheck', 'FaApBillOut', 'toaster', '$state','$filter', '$modal', function ($scope, FaApCheck, FaApBillOut, toaster, $state, $filter, $modal) {
  8953. $scope.data = [];// 列表数据
  8954. $scope.condition = {
  8955. $fromOpened: false
  8956. }
  8957. $scope.openDatePicker = function ($event, item, openParam) {
  8958. $event.preventDefault();
  8959. $event.stopPropagation();
  8960. item[openParam] = !item[openParam];
  8961. }
  8962. //查找客户
  8963. $scope.searchCust = function (suuorname) {
  8964. var modalInstance = $modal.open({
  8965. animation: true,
  8966. templateUrl: 'static/tpl/index/fa/custInfo.html',
  8967. controller: 'SearchCustInfoCtrl',
  8968. resolve: {
  8969. suuorname: function () {
  8970. return suuorname;
  8971. }
  8972. }
  8973. });
  8974. modalInstance.result.then(function (suuorname) {
  8975. $scope.suuorname = suuorname;
  8976. });
  8977. }
  8978. // 点击筛选根据条件选择数据
  8979. $scope.suuorname = '';
  8980. // 默认本月
  8981. $scope.sdateTo = new Date();
  8982. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  8983. $scope.vuuorname = '';
  8984. $scope.factory = '';
  8985. $scope.prodTitle = '';
  8986. $scope.prodSpec = '';
  8987. $scope.condition.uuorname = '';
  8988. $scope.condition.dateFrom = '';
  8989. $scope.condition.dateTo = '';
  8990. $scope.condition.venduuorname = '';
  8991. $scope.condition.factory = '';
  8992. $scope.condition.prodTitle = '';
  8993. $scope.condition.prodSpec = '';
  8994. $scope.searchOrder = function (check) {
  8995. $scope.data = [];
  8996. $scope.checkboxes.checked = false;
  8997. $scope.totalMoney = 0;
  8998. $scope.condition.uuorname = $scope.suuorname;
  8999. $scope.condition.factory = $scope.factory;
  9000. $scope.condition.prodTitle = $scope.prodTitle;
  9001. $scope.condition.prodSpec = $scope.prodSpec;
  9002. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9003. $scope.thisdatato = ($scope.sdateTo || 0);
  9004. if($scope.thisdatato != 0) {
  9005. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9006. } else {
  9007. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9008. }
  9009. $scope.condition.venduuorname = $scope.vuuorname;
  9010. if($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9011. $scope.fromDate =$scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9012. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9013. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  9014. + "|"+ ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  9015. + "|"+ ($scope.condition.factory == null ? "" : $scope.condition.factory)
  9016. + "|"+ ($scope.condition.prodTitle == null ? "" : $scope.condition.prodTitle)
  9017. + "|"+ ($scope.condition.prodSpec == null ? "" : $scope.condition.prodSpec));//保存当前取值的关键词
  9018. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9019. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9020. if(!$scope.suuorname) {
  9021. toaster.pop('warning','提示', '请先选择客户');
  9022. document.getElementById('suuorname').focus();//光标默认在客户
  9023. } else {
  9024. $scope.loading = true;
  9025. FaApBillOut.getDoneApCheckByKeywords({fromDate: $scope.fromDate, endDate: $scope.endDate, keyword:$scope.keywordXls}, function(data) {
  9026. if(data.length > 0) {
  9027. angular.forEach(data, function (checkItem) {
  9028. checkItem.$selected = true;
  9029. if(checkItem.billed) {
  9030. checkItem.thisBilledQty = checkItem.checkQty - checkItem.billed;
  9031. //$filter('number')(checkItem.thisBilledQty, 2);
  9032. } else {
  9033. checkItem.billed = 0;
  9034. checkItem.thisBilledQty = checkItem.checkQty;
  9035. }
  9036. //最大最小开票数
  9037. checkItem.maxThisBilledQty = checkItem.thisBilledQty;
  9038. checkItem.minThisBilledQty = 0;
  9039. });
  9040. $scope.data = data;
  9041. $scope.checkboxes.checked = true;
  9042. $scope.getTotalMoney();
  9043. } else {
  9044. toaster.pop('info', '提示', '当前没有需要对账记录');
  9045. }
  9046. $scope.loading = false;
  9047. }, function (response) {
  9048. $scope.loading = false;
  9049. toaster.pop('error', '提示', response.data);
  9050. });
  9051. }
  9052. }
  9053. }
  9054. /**
  9055. * 点击勾选框,选中要转应收对账单的订单
  9056. * */
  9057. $scope.totalMoney = 0;
  9058. $scope.checkboxes = {
  9059. checked: false
  9060. };
  9061. // 点击勾选全部的复选框
  9062. $scope.checkAll = function () {
  9063. $scope.totalMoney = 0;
  9064. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodTitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodSpec || $scope.condition.factory);
  9065. var uuorname = $scope.suuorname;
  9066. var venduuorname = $scope.venduuorname;
  9067. var dateFrom = $scope.condition.dateFrom;
  9068. var dateTo = $scope.condition.dateTo;
  9069. var prodTitle = $scope.condition.prodTitle;
  9070. var prodSpec = $scope.condition.prodSpec;
  9071. var factory = $scope.condition.factory;
  9072. angular.forEach($scope.filteredData, function (item) {
  9073. if((item.apCheck.apDate >= dateFrom || dateFrom == '') && (item.apCheck.apDate < dateTo || dateTo == '')){
  9074. item.$selected = $scope.checkboxes.checked;
  9075. }
  9076. });
  9077. $scope.getTotalMoney();
  9078. };
  9079. //获取已选单据总金额
  9080. var total = true;
  9081. $scope.getTotalMoney = function () {
  9082. $scope.totalMoney = 0;
  9083. angular.forEach($scope.data, function (check) {
  9084. if(check.$selected){
  9085. $scope.totalMoney += (check.CheckQty || 0)*(check.orderPrice || 0);
  9086. }else{
  9087. $scope.totalMoney += 0;
  9088. }
  9089. });
  9090. }
  9091. // 点击其中一个明细的复选框
  9092. $scope.checkOne = function (check) {
  9093. var result = true;
  9094. angular.forEach($scope.data, function (item) {
  9095. if(item.$selected != true){
  9096. result = false;
  9097. return;
  9098. }
  9099. });
  9100. $scope.checkboxes.checked = result;
  9101. };
  9102. $scope.haveSelected = false;
  9103. //生成开票单
  9104. $scope.createApBillOut = function () {
  9105. //保存应收对账单主记录字段
  9106. $scope.apBillOut = {
  9107. custUu: '',
  9108. custName: '',
  9109. beginDate: '',
  9110. endDate: '',
  9111. enUu: '',
  9112. recordDate: '',
  9113. checkStatus: '未开票',
  9114. currency: '',
  9115. rate: '',
  9116. //billed:'',
  9117. //apBillOutItemId:'',
  9118. items: [],
  9119. sourceInfos: []
  9120. };
  9121. //保存来源单据相关信息
  9122. //var sourceInfos = [];
  9123. //所允许的本次对账最大最小数量
  9124. //$scope.data.maxThisCheckQty = 0;
  9125. //$scope.data.minThisCheckQty = 0;
  9126. $scope.sameCust = true;
  9127. $scope.validQty = true;
  9128. $scope.loading = true;
  9129. angular.forEach($scope.data, function (checkItem) {
  9130. //保存开票单明细行数据
  9131. $scope.item = {
  9132. inoutno: '',
  9133. inoutnodetno: '',
  9134. orderCode: '',
  9135. orderClass: '',
  9136. orderDetno: '',
  9137. price: '',
  9138. NowQty: '',
  9139. //amount: '',
  9140. sourceId:'',
  9141. sourceTable:'',
  9142. //oldYCheckQty:'',
  9143. status: 0,
  9144. //receiveCode:'',
  9145. //receiveName:'',
  9146. prodCode:'',
  9147. //prodSpec:'',
  9148. taxrate: '',
  9149. //sendcode: '',
  9150. //whname: '',
  9151. };
  9152. //开票单明细行来源表信息(新的已开票数)
  9153. $scope.sourceInfo = {
  9154. sourceId: '',
  9155. sourceTable: '',
  9156. newBilledQty: 0
  9157. };
  9158. //本次开票新的开票数
  9159. //$scope.thisBilledQty = 0;
  9160. if(checkItem.$selected == true) {
  9161. $scope.apBillOut.custName = checkItem.apCheck.custName;
  9162. $scope.apBillOut.enUu = checkItem.apCheck.enUu;
  9163. $scope.item.inoutno = checkItem.inoutno;
  9164. $scope.item.inoutnodetno = checkItem.inoutnodetno;
  9165. $scope.item.orderCode = checkItem.orderCode;
  9166. $scope.item.orderClass = checkItem.orderClass;
  9167. $scope.item.orderDetno = checkItem.orderDetno;
  9168. $scope.item.NowQty = checkItem.thisBilledQty;
  9169. if (typeof(checkItem.billed) == "undefined") {
  9170. checkItem.billed = 0;
  9171. $scope.sourceInfo.newBilledQty =checkItem.thisBilledQty;
  9172. } else {
  9173. //TODO 变成了字符串相加?
  9174. $scope.sourceInfo.newBilledQty = checkItem.thisBilledQty + checkItem.billed;
  9175. }
  9176. //$scope.apBillOut.apBillOutItemId = check.id;
  9177. $scope.apBillOut.recordDate = checkItem.recordDate;
  9178. $scope.apBillOut.rate = checkItem.apCheck.rate;
  9179. //必须是同一家客户才能生成对账单,否则提示错误
  9180. if($scope.apBillOut.custUu == ''){
  9181. $scope.apBillOut.custUu = checkItem.apCheck.custUu;
  9182. }else if($scope.apBillOut.custUu !== checkItem.apCheck.custUu){
  9183. $scope.sameCust = false;
  9184. $scope.loading = false;
  9185. toaster.pop('error', '请选择同一家客户');
  9186. }
  9187. //必须是相同币别才能生成对账单,否则提示错误
  9188. if ($scope.apBillOut.currency == '') {
  9189. $scope.apBillOut.currency = checkItem.apCheck.currency;
  9190. } else if ($scope.apBillOut.currency !== checkItem.apCheck.currency) {
  9191. $scope.sameCust = false;
  9192. $scope.loading = false;
  9193. toaster.pop('error', '请选择同一种币别');
  9194. }
  9195. //本次对账数量必须小于总对账数量
  9196. if (checkItem.checkQty > 0) {
  9197. if (checkItem.minThisBilledQty >checkItem.thisBilledQty || checkItem.maxThisBilledQty <checkItem.thisBilledQty) {
  9198. $scope.validQty = false;
  9199. $scope.loading = false;
  9200. toaster.pop('error','本次开票数量,填写有误!');
  9201. }
  9202. } else if (check.qty < 0) {
  9203. $scope.data.maxCheckQty = 0;
  9204. $scope.data.minCheckQty = check.qty;
  9205. if(((-check.qty)-(-check.yCheckQty) < (-check.CheckQty)) || check.CheckQty > 0 || check.CheckQty == 0){
  9206. $scope.validQty = false;
  9207. $scope.loading = false;
  9208. toaster.pop('error','本次开票数量,填写有误!');
  9209. }
  9210. }
  9211. //TODO
  9212. //获取最小时间作为对账区间的起始时间
  9213. if($scope.apBillOut.beginDate == ''){
  9214. $scope.apBillOut.beginDate = checkItem.apCheck.apDate;
  9215. }else{
  9216. $scope.apBillOut.beginDate = $scope.apBillOut.beginDate>checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.beginDate;
  9217. }
  9218. //获取最大时间作为对账区间的截止时间
  9219. if($scope.apBillOut.endDate == ''){
  9220. $scope.apBillOut.endDate = checkItem.apCheck.apDate;
  9221. }else{
  9222. $scope.apBillOut.endDate = $scope.apBillOut.endDate<checkItem.apCheck.apDate? checkItem.apCheck.apDate : checkItem.apCheck.endDate;
  9223. }
  9224. //应收开票单明细行数据
  9225. $scope.item.price = checkItem.price;
  9226. $scope.item.sourceId = checkItem.id;
  9227. $scope.item.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  9228. $scope.item.NowQty = checkItem.thisBilledQty;
  9229. $scope.item.prodCode = checkItem.prodCode;
  9230. $scope.item.taxrate = checkItem.taxrate;
  9231. //来源表相关信息
  9232. $scope.sourceInfo.sourceId = checkItem.id;
  9233. $scope.sourceInfo.sourceTable = 'PURC$APCHECKITEM';//瑕疵
  9234. $scope.sourceInfo.newBilledQty = ((checkItem.billed || 0) + checkItem.thisBilledQty);
  9235. //sourceInfos.push($scope.sourceInfo);
  9236. $scope.apBillOut.items.push($scope.item);
  9237. $scope.apBillOut.sourceInfos.push($scope.sourceInfo);
  9238. $scope.haveSelected = true;
  9239. }
  9240. });
  9241. //保存生成的开票单,后台同时更新对账单明细表中已开票数
  9242. $scope.saveApBillOut = function () {
  9243. FaApBillOut.saveApBillOut({}, $scope.apBillOut, function (data) {
  9244. $scope.loading = false;
  9245. toaster.pop('success', '成功', '生成开票单成功');
  9246. $state.go('fa.apBillOut_detail', {id: data.id}, {reload:true});
  9247. }, function (response) {
  9248. toaster.pop('error', '生成开票单失败', response.data);
  9249. });
  9250. };
  9251. //如果是同一家客户,生成对账单的同时,关闭模态框
  9252. if($scope.sameCust && $scope.validQty) {
  9253. $scope.saveApBillOut();
  9254. }
  9255. }
  9256. }]);
  9257. /**
  9258. * 客户应付发票
  9259. */
  9260. app.controller('SaleApBillCtrl', ['$scope', '$filter', 'FaApBill', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, FaApBill, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  9261. BaseService.scrollBackToTop();
  9262. // 获取当前用户是否为普通用户
  9263. CurrentRole.isUser({}, {}, function (data) {
  9264. $scope.isUser = data.isUser;
  9265. });
  9266. $scope.active = 'all';
  9267. $scope.dateZoneText = '不限';
  9268. $scope.condition = {dateZone: 1};
  9269. /* 时间筛选初始化*/
  9270. var fromDate = new Date();
  9271. var toDate = new Date();
  9272. fromDate.setMonth(fromDate.getMonth() - 1);
  9273. fromDate.setHours(0, 0, 0, 0);
  9274. toDate.setHours(23, 59, 59, 999);
  9275. $scope.condition.dateFrom = fromDate;
  9276. $scope.condition.dateTo = toDate;
  9277. $scope.changeDateZone = function (zone) {
  9278. $scope.condition.dateZone = zone;
  9279. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9280. $scope.condition.$dateZoneOpen = false;
  9281. getDateCondition(zone, $scope.condition);
  9282. $scope.tableParams.page(1);
  9283. $scope.tableParams.reload();
  9284. };
  9285. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9286. $scope.setActive = function (state) {
  9287. if ($scope.active != state) {
  9288. $scope.active = state;
  9289. if ($scope.tableParams.page() == 1)
  9290. $scope.tableParams.reload();
  9291. else
  9292. $scope.tableParams.page(1);
  9293. }
  9294. };
  9295. var getService = function () {
  9296. return FaApBill;
  9297. };
  9298. $scope.tableParams = new ngTableParams({
  9299. page: 1,
  9300. count: 20,
  9301. sorting: {
  9302. date: 'desc'
  9303. }
  9304. }, {
  9305. total: 0,
  9306. counts: [5, 10, 25, 50],
  9307. getData: function ($defer, params) {
  9308. $scope.loading = true;
  9309. var pageParams = params.url();
  9310. pageParams.searchFilter = { // 筛选条件
  9311. keyword: $scope.keyword,
  9312. fromDate: getDateTime($scope.condition.dateFrom),
  9313. endDate: getDateTime($scope.condition.dateTo)
  9314. };
  9315. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  9316. $scope.loading = false;
  9317. if (page) {
  9318. params.total(page.totalElement);
  9319. $defer.resolve(page.content);
  9320. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  9321. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9322. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9323. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);
  9324. }
  9325. }, function (response) {
  9326. $scope.loading = false;
  9327. toaster.pop('error', '数据加载失败', response.data);
  9328. });
  9329. }
  9330. });
  9331. $scope.openDatePicker = function ($event, item, openParam) {
  9332. $event.preventDefault();
  9333. $event.stopPropagation();
  9334. item[openParam] = !item[openParam];
  9335. };
  9336. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9337. $event.preventDefault();
  9338. $event.stopPropagation();
  9339. item[openParam] = !item[openParam];
  9340. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9341. $scope.tableParams.reload();
  9342. }
  9343. };
  9344. $scope.parseDate = function (dateStr) {
  9345. if (dateStr)
  9346. return Date.parse(dateStr, 'yyyy-MM-dd');
  9347. return new Date();
  9348. };
  9349. // 搜索框回车
  9350. $scope.onSearch = function () {
  9351. $scope.tableParams.page(1);
  9352. $scope.tableParams.reload();
  9353. };
  9354. // 选择查找日期
  9355. $scope.onDateCondition = function () {
  9356. $scope.tableParams.page(1);
  9357. $scope.tableParams.reload();
  9358. };
  9359. // 导出
  9360. $scope.exportXls = function () {
  9361. FaApBill.exportXls({}, {}, function (data) {
  9362. if (data.success){
  9363. window.location.href = 'sale/apBill/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  9364. }
  9365. }, function (response) {
  9366. toaster.pop('error', '数据加载失败', response.data);
  9367. });
  9368. }
  9369. }]);
  9370. /**
  9371. * 客户应付发票详情
  9372. */
  9373. app.controller('SaleApBillDetailCtrl', ['$scope', '$filter', 'FaApBill', 'toaster', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, $filter, FaApBill, toaster, $stateParams, BaseService, CurrentRole) {
  9374. BaseService.scrollBackToTop();
  9375. // 获取当前用户是否为普通用户
  9376. CurrentRole.isUser({}, {}, function (data) {
  9377. $scope.isUser = data.isUser;
  9378. });
  9379. var loadData = function () {
  9380. FaApBill.getAll({id: $stateParams.id}, function (data) {
  9381. $scope.bill = data;
  9382. $scope.loading = false;
  9383. }, function (response) {
  9384. toaster.pop('error', '', response.data);
  9385. });
  9386. };
  9387. loadData(); // 初始获取单据数据
  9388. }]);
  9389. /**
  9390. * 应付对账单
  9391. */
  9392. app.controller('SaleArCheckCtrl', ['$scope', '$filter', 'FaArCheck', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function ($scope, $filter, FaArCheck, ngTableParams, toaster, BaseService, Symbol) {
  9393. BaseService.scrollBackToTop();
  9394. $scope.active = 'all';
  9395. $scope.dateZoneText = '不限';
  9396. $scope.condition = {dateZone: 1};
  9397. /* 时间筛选初始化*/
  9398. var fromDate = new Date();
  9399. var toDate = new Date();
  9400. fromDate.setMonth(fromDate.getMonth() - 1);
  9401. fromDate.setHours(0, 0, 0, 0);
  9402. toDate.setHours(23, 59, 59, 999);
  9403. $scope.condition.dateFrom = fromDate;
  9404. $scope.condition.dateTo = toDate;
  9405. $scope.changeDateZone = function (zone) {
  9406. $scope.condition.dateZone = zone;
  9407. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9408. $scope.condition.$dateZoneOpen = false;
  9409. getDateCondition(zone, $scope.condition);
  9410. $scope.tableParams.page(1);
  9411. $scope.tableParams.reload();
  9412. };
  9413. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9414. $scope.setActive = function (state) {
  9415. if ($scope.active != state) {
  9416. $scope.active = state;
  9417. if ($scope.tableParams.page() == 1)
  9418. $scope.tableParams.reload();
  9419. else
  9420. $scope.tableParams.page(1);
  9421. }
  9422. };
  9423. var getService = function () {
  9424. return FaArCheck;
  9425. };
  9426. $scope.tableParams = new ngTableParams({
  9427. page: 1,
  9428. count: 20,
  9429. sorting: {
  9430. date: 'desc'
  9431. }
  9432. }, {
  9433. total: 0,
  9434. counts: [5, 10, 25, 50],
  9435. getData: function ($defer, params) {
  9436. $scope.loading = true;
  9437. var pageParams = params.url();
  9438. pageParams.searchFilter = {};
  9439. pageParams.searchFilter.keyword = $scope.keyword;
  9440. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9441. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9442. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  9443. $scope.loading = false;
  9444. if (page) {
  9445. params.total(page.totalElement);
  9446. $defer.resolve(page.content);
  9447. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  9448. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9449. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9450. }
  9451. }, function (response) {
  9452. $scope.loading = false;
  9453. toaster.pop('error', '数据加载失败', response.data);
  9454. });
  9455. }
  9456. });
  9457. $scope.openDatePicker = function ($event, item, openParam) {
  9458. $event.preventDefault();
  9459. $event.stopPropagation();
  9460. item[openParam] = !item[openParam];
  9461. };
  9462. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9463. $event.preventDefault();
  9464. $event.stopPropagation();
  9465. item[openParam] = !item[openParam];
  9466. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9467. $scope.tableParams.reload();
  9468. }
  9469. };
  9470. // 计算单据的商品总数
  9471. $scope.getTotalProd = function (check) {
  9472. var total = 0;
  9473. if (check.items) {
  9474. angular.forEach(check.items, function (value) {
  9475. total += value.qty;
  9476. });
  9477. }
  9478. return total;
  9479. };
  9480. // 搜索框回车
  9481. $scope.onSearch = function () {
  9482. $scope.tableParams.page(1);
  9483. $scope.tableParams.reload();
  9484. };
  9485. // 选择查找日期
  9486. $scope.onDateCondition = function () {
  9487. $scope.tableParams.page(1);
  9488. $scope.tableParams.reload();
  9489. };
  9490. }]);
  9491. // 应付对账单详情页
  9492. app.controller('SaleArCheckDetailCtrl', ['$scope', '$stateParams', 'FaArCheck', 'toaster', '$state', 'BaseService', function ($scope, $stateParams, FaArCheck, toaster, $state, BaseService) {
  9493. BaseService.scrollBackToTop();
  9494. var loadData = function () {
  9495. FaArCheck.get({id: $stateParams.id}, function (data) {
  9496. $scope.order = data;
  9497. $scope.loading = false;
  9498. });
  9499. };
  9500. loadData(); // 初始获取单据数据
  9501. $scope.onReplyClick = function (item, isAgreed) {
  9502. if (isAgreed) {// 同意确认
  9503. FaArCheck.agree({itemId: item.id}, {}, function (data) {
  9504. toaster.pop('success', '确认成功', '确认供应商对账数量成功');
  9505. }, function (response) {
  9506. toaster.pop('danger', '确认失败', response.data);
  9507. });
  9508. } else {// 不同意回复
  9509. FaArCheck.disagree({itemId: item.id}, {
  9510. qty: item.$replyQty,
  9511. remark: item.$replyRemark
  9512. }, function (data) {
  9513. toaster.pop('success', '确认成功', '您提交的数量将发送给供应商确认');
  9514. }, function (response) {
  9515. toaster.pop('danger', '确认失败', response.data);
  9516. });
  9517. }
  9518. };
  9519. // 获取明细的回复记录
  9520. $scope.getReplies = function (item) {
  9521. if (!item.replies) {
  9522. FaArCheck.getReplies({itemId: item.id}, function (data) {
  9523. item.replies = data;
  9524. }, function (response) {
  9525. toaster.pop('danger', '获取对账记录失败', response.data);
  9526. });
  9527. }
  9528. };
  9529. }]);
  9530. //应收对账单列表
  9531. app.controller('PurchaseApCheckCtrl', ['$scope', 'FaApCheck', 'BaseService', 'ngTableParams', 'toaster', 'ReportService', 'Symbol', 'CurrentRole', function ($scope, FaApCheck, BaseService, ngTableParams, toaster, ReportService, Symbol, CurrentRole) {
  9532. BaseService.scrollBackToTop();
  9533. // 获取当前用户是否为普通用户
  9534. CurrentRole.isUser({}, {}, function (data) {
  9535. $scope.isUser = data.isUser;
  9536. });
  9537. $scope.dateZoneText = '不限';
  9538. $scope.condition = {dateZone: 1};
  9539. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  9540. $scope.active = 'todo';
  9541. /* 时间筛选初始化*/
  9542. var fromDate = new Date();
  9543. var toDate = new Date();
  9544. fromDate.setMonth(fromDate.getMonth() - 1);
  9545. fromDate.setHours(0, 0, 0, 0);
  9546. toDate.setHours(23, 59, 59, 999);
  9547. $scope.condition.dateFrom = fromDate;
  9548. $scope.condition.dateTo = toDate;
  9549. //打印 对账单
  9550. $scope.print = function (check) {
  9551. var newPage = window.open("about:blank");
  9552. FaApCheck.printPermission({}, function () {
  9553. FaApCheck.printCount({id: check.id}, {});//增加打印此次
  9554. ReportService.print(check.custUu, 'PURCCHECK', 'where purc$apcheck.pa_id =' + check.id, newPage);
  9555. }, function (response) {
  9556. newPage.close();
  9557. toaster.pop('error', '打印失败', response.data);
  9558. });
  9559. };
  9560. //状态
  9561. $scope.setActive = function (state) {
  9562. if ($scope.active != state) {
  9563. $scope.active = state;
  9564. if ($scope.tableParams.page() == 1)
  9565. $scope.tableParams.reload();
  9566. else
  9567. $scope.tableParams.page(1);
  9568. }
  9569. };
  9570. $scope.changeDateZone = function (zone) {
  9571. $scope.condition.dateZone = zone;
  9572. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  9573. $scope.condition.$dateZoneOpen = false;
  9574. getDateCondition(zone, $scope.condition);
  9575. $scope.tableParams.page(1);
  9576. $scope.tableParams.reload();
  9577. };
  9578. //获取应收对账单全部
  9579. $scope.tableParams = new ngTableParams({
  9580. page: 1,
  9581. count: 20,
  9582. sorting: {
  9583. recordDate: 'desc'
  9584. }
  9585. }, {
  9586. total: 0,
  9587. counts: [5, 10, 25, 50],
  9588. getData: function ($defer, params) {
  9589. $scope.loading = true;
  9590. var pageParams = params.url();
  9591. pageParams.searchFilter = { // 筛选条件
  9592. keyword: $scope.keyword,
  9593. fromDate: getDateTime($scope.condition.dateFrom),
  9594. endDate: getDateTime($scope.condition.dateTo)
  9595. };
  9596. FaApCheck[getState($scope.active)](BaseService.parseParams(pageParams), function (page) {
  9597. $scope.loading = false;
  9598. if (page) {
  9599. params.total(page.totalElement);
  9600. $scope.data = $defer.resolve(page.content);
  9601. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的条件
  9602. }
  9603. }, function (response) {
  9604. $scope.loading = false;
  9605. toaster.pop('error', '数据加载失败', response.data);
  9606. });
  9607. }
  9608. });
  9609. //获得各分类未阅读数量
  9610. var getUnreadCount = function () {
  9611. FaApCheck.getUnreadCount(null, function(data){
  9612. $scope.unread = data;
  9613. });
  9614. };
  9615. getUnreadCount();
  9616. //设置单据已读
  9617. $scope.setOrdersRead = function (id) {
  9618. // 如果单据本身已读,则不发送请求修改数据
  9619. if (!$scope.isUnread(id)){
  9620. return;
  9621. }
  9622. var sourceId = [];
  9623. sourceId.push(id);
  9624. FaApCheck.setRead({}, sourceId, function (message) {
  9625. getUnreadCount();
  9626. });
  9627. };
  9628. //获取未读单据id
  9629. var getUnreadIds = function (){
  9630. FaApCheck.getUnreadIds({}, "", function (message) {
  9631. $scope.unreadCode = message.content;
  9632. });
  9633. };
  9634. getUnreadIds();
  9635. //判断单据是否未读
  9636. $scope.isUnread = function (id){
  9637. for (var i in $scope.unreadCode) {
  9638. if (id == $scope.unreadCode[i]) {
  9639. return true;
  9640. }
  9641. }
  9642. };
  9643. $scope.openDatePicker = function ($event, item, openParam) {
  9644. $event.preventDefault();
  9645. $event.stopPropagation();
  9646. item[openParam] = !item[openParam];
  9647. };
  9648. $scope.openFilterDatePicker = function ($event, item, openParam) {
  9649. $event.preventDefault();
  9650. $event.stopPropagation();
  9651. item[openParam] = !item[openParam];
  9652. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  9653. $scope.tableParams.reload();
  9654. }
  9655. };
  9656. // 计算单据的商品总数
  9657. $scope.getTotalProd = function (check) {
  9658. var total = 0;
  9659. if (check.items) {
  9660. angular.forEach(check.items, function (value) {
  9661. total += value.checkQty;
  9662. });
  9663. }
  9664. return total;
  9665. };
  9666. // 搜索框回车
  9667. $scope.onSearch = function () {
  9668. $scope.tableParams.page(1);
  9669. $scope.tableParams.reload();
  9670. };
  9671. // 选择查找日期
  9672. $scope.onDateCondition = function () {
  9673. $scope.tableParams.page(1);
  9674. $scope.tableParams.reload();
  9675. };
  9676. // 导出
  9677. $scope.exportXls = function () {
  9678. FaApCheck.exportXls({}, {}, function (data) {
  9679. if (data.success){
  9680. window.location.href = 'sale/apCheck/xls/list?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  9681. }
  9682. }, function (response) {
  9683. toaster.pop('error', '数据加载失败', response.data);
  9684. });
  9685. }
  9686. }]);
  9687. //应收对账单详情
  9688. app.controller('PurchaseApCheckDetailCtrl', ['$scope', 'toaster', 'FaApCheck', '$stateParams', 'BaseService', 'CurrentRole', function ($scope, toaster, FaApCheck, $stateParams, BaseService, CurrentRole) {
  9689. BaseService.scrollBackToTop();
  9690. // 获取当前用户是否为普通用户
  9691. CurrentRole.isUser({}, {}, function (data) {
  9692. $scope.isUser = data.isUser;
  9693. });
  9694. $scope.haveSelected = true;
  9695. $scope.data = {};
  9696. //控制提交和删除按钮的显示
  9697. $scope.ifShow = true;
  9698. var loadData = function () {
  9699. FaApCheck.getItem({id: $stateParams.id}, function (data) {
  9700. $scope.data = data;
  9701. if ($scope.data.status) {
  9702. } else {
  9703. $scope.ifShow = true;
  9704. }
  9705. }, function (response) {
  9706. toaster.pop('error', '', response.data);
  9707. })
  9708. };
  9709. if ($stateParams.id) {
  9710. loadData();
  9711. }
  9712. $scope.haveSource = false;
  9713. //提交应收对账单
  9714. $scope.submitApCheck = function () {
  9715. FaApCheck.updateStatus({id: $stateParams.id}, {}, function (data) {
  9716. if (data.result) {
  9717. toaster.pop('success', '提示', '提交成功');
  9718. $scope.haveSelected = false;
  9719. window.location.href = '#/fa/apCheck';
  9720. } else {
  9721. $scope.haveSource = true;
  9722. loadData();
  9723. toaster.pop('error', '提示', '单据被反过账,请立即作废本单据');
  9724. $scope.haveSelected = true;
  9725. }
  9726. }, function (response) {
  9727. $scope.loading = false;
  9728. toaster.pop('error', '更新已转数失败', response.data);
  9729. });
  9730. }
  9731. //删除应收对账单的同时更新来源表已转数
  9732. var updateYCheckQty = function () {
  9733. var sourceInfos = [];
  9734. angular.forEach($scope.data.items, function (item) {
  9735. $scope.sourceInfo = {
  9736. sourceId: '',
  9737. sourceTable: '',
  9738. newYCheckQty: ''
  9739. };
  9740. $scope.sourceInfo.sourceId = item.sourceId;
  9741. $scope.sourceInfo.sourceTable = item.sourceTable;
  9742. $scope.sourceInfo.newYCheckQty = item.oldYCheckQty;
  9743. sourceInfos.push($scope.sourceInfo);
  9744. });
  9745. FaApCheck.update({}, sourceInfos, function () {
  9746. }, function (response) {
  9747. $scope.loading = false;
  9748. toaster.pop('error', '更新已转数失败', response.data);
  9749. });
  9750. }
  9751. //删除应收对账单
  9752. $scope.deleteApCheck = function () {
  9753. FaApCheck.deleteApCheck({id: $stateParams.id}, {}, function (data) {
  9754. updateYCheckQty();
  9755. toaster.pop('success', '提示', '删除成功');
  9756. }, function (response) {
  9757. toaster.pop('error', '删除失败', response.data);
  9758. });
  9759. $scope.haveSelected = false;
  9760. }
  9761. //作废应收对账单
  9762. $scope.cancelApCheck = function (check) {
  9763. FaApCheck.cancel({id: check.id}, {}, function (data) {
  9764. $scope.checkResult = false;
  9765. if (data.result) {
  9766. $scope.checkResult = true;
  9767. toaster.pop('success', '提示', '作废成功');
  9768. $scope.tableParams.reload();
  9769. } else {
  9770. toaster.pop('error', '提示', '作废失败');
  9771. }
  9772. }, function (response) {
  9773. $scope.loading = false;
  9774. toaster.pop('error', '作废失败', response.data);
  9775. });
  9776. }
  9777. }]);
  9778. //未对账单据列表
  9779. app.controller('PurchaseApCheckListCtrl', ['$scope', 'FaApCheck', 'toaster', '$state', '$filter', '$modal', 'Vendor', 'DecimalNumber', function ($scope, FaApCheck, toaster, $state, $filter, $modal, Vendor, DecimalNumber) {
  9780. $scope.data = [];// 列表数据
  9781. $scope.condition = {
  9782. $fromOpened: false
  9783. }
  9784. $scope.openDatePicker = function ($event, item, openParam) {
  9785. $event.preventDefault();
  9786. $event.stopPropagation();
  9787. item[openParam] = !item[openParam];
  9788. }
  9789. // 客户联想词
  9790. $scope.getSimilarCustomers = function (value) {
  9791. if (value) {
  9792. return Vendor.getSimilarCustomers({keyword: value}).$promise.then(function (data) {
  9793. return data.map(function (item) {
  9794. return item;
  9795. });
  9796. });
  9797. }
  9798. };
  9799. $scope.onAssociateCustomerClick = function (vendor) {
  9800. if (vendor.apcheck == 0) {
  9801. toaster.pop('info', '提示', '该客户暂未启用平台对账功能');
  9802. $scope.suuorname = '';
  9803. } else {
  9804. $scope.suuorname = vendor.custName;
  9805. }
  9806. }
  9807. //查找客户
  9808. $scope.searchCust = function (suuorname) {
  9809. var modalInstance = $modal.open({
  9810. animation: true,
  9811. templateUrl: 'static/tpl/index/fa/apcheck_customer.html',
  9812. controller: 'SearchCustInfoCtrl',
  9813. size: 'lg',
  9814. resolve: {
  9815. suuorname: function () {
  9816. return suuorname;
  9817. }
  9818. }
  9819. });
  9820. modalInstance.result.then(function (customer) {
  9821. $scope.suuorname = customer.myEnterprise.enName;
  9822. });
  9823. }
  9824. // 点击筛选根据条件选择数据
  9825. $scope.suuorname = '';
  9826. // 默认本月
  9827. $scope.sdateTo = new Date();
  9828. $scope.sdateFrom = new Date($scope.sdateTo.getFullYear(), $scope.sdateTo.getMonth(), 1);
  9829. $scope.vuuorname = '';
  9830. $scope.factory = '';
  9831. $scope.prodtitle = '';
  9832. $scope.prodspec = '';
  9833. $scope.condition.uuorname = '';
  9834. $scope.condition.dateFrom = '';
  9835. $scope.condition.dateTo = '';
  9836. $scope.condition.venduuorname = '';
  9837. $scope.condition.factory = '';
  9838. $scope.condition.prodtitle = '';
  9839. $scope.condition.prodspec = '';
  9840. $scope.searchOrder = function (check) {
  9841. $scope.data = [];
  9842. $scope.checkboxes.checked = false;
  9843. $scope.totalMoney = 0;
  9844. $scope.condition.uuorname = $scope.suuorname;
  9845. $scope.condition.factory = $scope.factory
  9846. $scope.condition.prodtitle = $scope.prodtitle;
  9847. $scope.condition.prodspec = $scope.prodspec;
  9848. $scope.condition.dateFrom = ($scope.sdateFrom || 0);
  9849. $scope.thisdatato = ($scope.sdateTo || 0);
  9850. if ($scope.thisdatato != 0) {
  9851. $scope.condition.dateTo = (new Date($scope.thisdatato.valueOf()) || 0);
  9852. } else {
  9853. $scope.condition.dateTo = ($scope.sdateTo || 0);
  9854. }
  9855. $scope.condition.venduuorname = $scope.vuuorname;
  9856. if ($scope.condition.dateFrom != null || $scope.condition.dateTo != null || $scope.keywordXls != null) {
  9857. $scope.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  9858. $scope.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  9859. $scope.keywordXls = angular.copy(($scope.condition.uuorname == null ? "" : $scope.condition.uuorname)
  9860. + "|" + ($scope.condition.venduuorname == null ? "" : $scope.condition.venduuorname)
  9861. + "|" + ($scope.condition.factory == null ? "" : $scope.condition.factory)
  9862. + "|" + ($scope.condition.prodtitle == null ? "" : $scope.condition.prodtitle)
  9863. + "|" + ($scope.condition.prodspec == null ? "" : $scope.condition.prodspec));//保存当前取值的关键词
  9864. $scope.exportKeywordXls = encodeURIComponent($scope.keywordXls);
  9865. $scope.fromDateXls = angular.copy($scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null);//保存当前取值的起始日期
  9866. $scope.endDateXls = angular.copy($scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null);//保存当前取值的截止日期
  9867. if (!$scope.suuorname) {
  9868. toaster.pop('warning', '提示', '请先选择客户');
  9869. document.getElementById('suuorname').focus();//光标默认在客户
  9870. } else {
  9871. $scope.loading = true;
  9872. FaApCheck.getAllByKeywords({
  9873. fromDate: $scope.fromDate,
  9874. endDate: $scope.endDate,
  9875. keyword: $scope.keywordXls
  9876. }, function (data) {
  9877. if (data.length > 0) {
  9878. angular.forEach(data, function (item) {
  9879. item.$selected = true;
  9880. });
  9881. $scope.data = data;
  9882. $scope.checkboxes.checked = true;
  9883. $scope.getTotalMoney();
  9884. } else {
  9885. toaster.pop('info', '提示', '当前没有需要对账记录');
  9886. }
  9887. $scope.loading = false;
  9888. }, function (response) {
  9889. $scope.loading = false;
  9890. toaster.pop('error', '提示', response.data);
  9891. });
  9892. }
  9893. }
  9894. }
  9895. /**
  9896. * 点击勾选框,选中要转应收对账单的订单
  9897. * */
  9898. $scope.totalMoney = 0;
  9899. $scope.checkboxes = {
  9900. checked: false
  9901. };
  9902. // 点击勾选全部的复选框
  9903. $scope.checkAll = function () {
  9904. $scope.totalMoney = 0;
  9905. $scope.filteredData = $filter('filter')($scope.data, $scope.condition.prodtitle || $scope.condition.uuorname || $scope.condition.venduuorname || $scope.condition.prodspec || $scope.condition.factory);
  9906. var uuorname = $scope.suuorname;
  9907. var venduuorname = $scope.venduuorname;
  9908. var dateFrom = $scope.condition.dateFrom;
  9909. var dateTo = $scope.condition.dateTo;
  9910. var prodTitle = $scope.condition.prodtitle;
  9911. var prodSpec = $scope.condition.prodspec;
  9912. var factory = $scope.condition.factory;
  9913. angular.forEach($scope.filteredData, function (item) {
  9914. if ((item.pidate >= dateFrom || dateFrom == '') && (item.pidate < dateTo || dateTo == '')) {
  9915. item.$selected = $scope.checkboxes.checked;
  9916. }
  9917. });
  9918. $scope.getTotalMoney();
  9919. };
  9920. //获取已选单据总金额
  9921. var total = true;
  9922. $scope.getTotalMoney = function () {
  9923. $scope.totalMoney = 0;
  9924. angular.forEach($scope.data, function (check) {
  9925. if (check.$selected) {
  9926. var price = DecimalNumber.accMul((check.thischeckqty || 0), (check.orderprice || 0));
  9927. $scope.totalMoney += Math.round(price * 100) / 100;
  9928. } else {
  9929. $scope.totalMoney += 0;
  9930. }
  9931. });
  9932. }
  9933. // 点击其中一个明细的复选框
  9934. $scope.checkOne = function (check) {
  9935. var result = true;
  9936. angular.forEach($scope.data, function (item) {
  9937. if (item.$selected != true) {
  9938. result = false;
  9939. return;
  9940. }
  9941. });
  9942. $scope.checkboxes.checked = result;
  9943. };
  9944. $scope.haveSelected = false;
  9945. //生成应收对账单
  9946. $scope.createApCheck = function () {
  9947. //保存应收对账单主记录字段
  9948. $scope.apCheck = {
  9949. custUu: '',
  9950. custName: '',
  9951. enUu: '',
  9952. apDate: '',
  9953. beginDate: '',
  9954. endDate: '',
  9955. checkStatus: '未对账',
  9956. checkAmount: 0,
  9957. currency: '',
  9958. rate: '',
  9959. items: [],
  9960. taxrate: ''
  9961. };
  9962. //保存来源单据相关信息
  9963. var sourceInfos = [];
  9964. //所允许的本次对账最大最小数量
  9965. $scope.data.maxThisCheckQty = 0;
  9966. $scope.data.minThisCheckQty = 0;
  9967. $scope.sameCust = true;
  9968. $scope.validQty = true;
  9969. $scope.loading = true;
  9970. angular.forEach($scope.data, function (check) {
  9971. //保存应收对账单明细行数据
  9972. $scope.item = {
  9973. inoutno: '',
  9974. inoutnodetno: '',
  9975. orderCode: '',
  9976. orderClass: '',
  9977. orderDetno: '',
  9978. price: '',
  9979. checkQty: '',
  9980. amount: '',
  9981. sourceId: '',
  9982. sourceTable: '',
  9983. oldYCheckQty: '',
  9984. status: 0,
  9985. receiveCode: '',
  9986. receiveName: '',
  9987. prodCode: '',
  9988. prodTitle: '',
  9989. prodSpec: '',
  9990. taxrate: '',
  9991. sendcode: '',
  9992. whname: '',
  9993. };
  9994. //应收对账单明细行来源表信息
  9995. $scope.sourceInfo = {
  9996. sourceId: '',
  9997. sourceTable: '',
  9998. newYCheckQty: ''
  9999. };
  10000. //此次对账后新的已转数
  10001. $scope.newYCheckQty = 0;
  10002. if (check.$selected == true) {
  10003. $scope.apCheck.custName = check.custname;
  10004. $scope.apCheck.enUu = check.enuu;
  10005. $scope.apCheck.checkAmount += (check.thischeckqty || 0) * (check.orderprice || 0);
  10006. $scope.apCheck.apDate = check.pidate;
  10007. $scope.apCheck.rate = check.rate;
  10008. //必须是同一家客户才能生成对账单,否则提示错误
  10009. if ($scope.apCheck.custUu == '') {
  10010. $scope.apCheck.custUu = check.custuu;
  10011. } else if ($scope.apCheck.custUu !== check.custuu) {
  10012. $scope.sameCust = false;
  10013. $scope.loading = false;
  10014. toaster.pop('error', '请选择同一家客户');
  10015. }
  10016. //必须是相同币别才能生成对账单,否则提示错误
  10017. if ($scope.apCheck.currency == '') {
  10018. $scope.apCheck.currency = check.currency;
  10019. } else if ($scope.apCheck.currency !== check.currency) {
  10020. $scope.sameCust = false;
  10021. $scope.loading = false;
  10022. toaster.pop('error', '请选择同一种币别');
  10023. }
  10024. //必须是相同税率才能生成对账单,否则提示错误
  10025. if (!angular.isNumber($scope.apCheck.taxrate)) {
  10026. $scope.apCheck.taxrate = check.taxrate;
  10027. } else if ($scope.apCheck.taxrate != check.taxrate) {
  10028. $scope.sameCust = false;
  10029. $scope.loading = false;
  10030. toaster.pop('error', '请选择相同的税率');
  10031. }
  10032. //本次对账数量必须小于总对账数量
  10033. if (check.qty > 0) {
  10034. $scope.data.maxThisCheckQty = check.qty;
  10035. $scope.data.minThisCheckQty = 0;
  10036. if (check.qty - (check.ycheckqty || 0) < check.thischeckqty || check.thischeckqty < 0 || check.thischeckqty == 0) {
  10037. $scope.validQty = false;
  10038. $scope.loading = false;
  10039. toaster.pop('error', '本次对账数量,填写有误!');
  10040. }
  10041. } else if (check.qty < 0) {
  10042. $scope.data.maxThisCheckQty = 0;
  10043. $scope.data.minThisCheckQty = check.qty;
  10044. if (((-check.qty) - (-check.ycheckqty) < (-check.thischeckqty)) || check.thischeckqty > 0 || check.thischeckqty == 0) {
  10045. $scope.validQty = false;
  10046. $scope.loading = false;
  10047. toaster.pop('error', '本次对账数量,填写有误!');
  10048. }
  10049. }
  10050. //获取最小时间作为对账区间的起始时间
  10051. if ($scope.apCheck.beginDate == '') {
  10052. $scope.apCheck.beginDate = check.pidate;
  10053. } else {
  10054. $scope.apCheck.beginDate = $scope.apCheck.beginDate > check.pidate ? check.pidate : $scope.apCheck.beginDate;
  10055. }
  10056. //获取最大时间作为对账区间的截止时间
  10057. if ($scope.apCheck.endDate == '') {
  10058. $scope.apCheck.endDate = check.pidate;
  10059. } else {
  10060. $scope.apCheck.endDate = $scope.apCheck.endDate < check.pidate ? check.pidate : $scope.apCheck.endDate;
  10061. }
  10062. //应收对账单明细行数据
  10063. $scope.item.orderCode = check.ordercode;
  10064. $scope.item.orderClass = check.piclass;
  10065. $scope.item.orderDetno = check.orderdetno;
  10066. $scope.item.price = check.orderprice;
  10067. $scope.item.checkQty = check.thischeckqty;
  10068. $scope.item.amount = (check.thischeckqty || 0) * (check.orderprice || 0);
  10069. $scope.item.sourceId = check.sourceid;
  10070. $scope.item.sourceTable = check.sourcetable;
  10071. $scope.item.oldYCheckQty = check.ycheckqty;
  10072. $scope.item.prodCode = check.prodcode;
  10073. $scope.item.prodTitle = check.prodtitle;
  10074. $scope.item.prodSpec = check.prodspec;
  10075. $scope.item.inoutno = check.inoutno;
  10076. $scope.item.inoutnodetno = check.detno;
  10077. $scope.item.taxrate = check.taxrate;
  10078. $scope.item.receiveCode = check.receivecode;
  10079. $scope.item.receiveName = check.receivename;
  10080. $scope.item.sendcode = check.sendcode;
  10081. $scope.item.whname = check.whname;
  10082. //来源表相关信息
  10083. $scope.sourceInfo.sourceid = check.sourceid;
  10084. $scope.sourceInfo.sourcetable = check.sourcetable;
  10085. $scope.sourceInfo.newYCheckQty = ((check.ycheckqty || 0) + check.thischeckqty);
  10086. sourceInfos.push($scope.sourceInfo);
  10087. $scope.apCheck.items.push($scope.item);
  10088. $scope.haveSelected = true;
  10089. }
  10090. });
  10091. //保存生成的应收对账单
  10092. $scope.saveApCheck = function () {
  10093. FaApCheck.saveApCheck({}, $scope.apCheck, function (data) {
  10094. $scope.loading = false;
  10095. toaster.pop('success', '成功', '生成应收对账成功');
  10096. $state.go('fa.apCheck_detail', {id: data.id}, {reload: true});
  10097. }, function (response) {
  10098. $scope.loading = false;
  10099. toaster.pop('error', '生成对账单失败', response.data);
  10100. })
  10101. };
  10102. //如果是同一家客户,生成对账单的同时,关闭模态框
  10103. if ($scope.sameCust && $scope.validQty) {
  10104. $scope.saveApCheck();
  10105. }
  10106. }
  10107. }]);
  10108. // 企业信息设置
  10109. app.controller('EnterpriseCtrl', ['$scope', 'AccountEnterprise', 'toaster', '$state', '$modal', 'BaseService', 'ShipAddress', '$http', 'DeputyOrder', function ($scope, AccountEnterprise, toaster, $state, $modal, BaseService, ShipAddress, $http, DeputyOrder) {
  10110. BaseService.scrollBackToTop();
  10111. $scope.loading = true;
  10112. AccountEnterprise.get({}, function (data) {
  10113. $scope.loading = false;
  10114. $scope.enterprise = data;
  10115. if (data.tags) {
  10116. $scope.tags = data.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  10117. } else {
  10118. $scope.tags = [];
  10119. }
  10120. // 获取付款企业信息
  10121. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  10122. $scope.pays = data;
  10123. }, function (response) {
  10124. toaster.pop('error', '提示', response.data);
  10125. });
  10126. // 获取企业开票信息
  10127. AccountEnterprise.getApBillOutInfo({enuu: $scope.enterprise.uu}, {}, function(data) {
  10128. $scope.apBillOutInfo = data;
  10129. }, function(response) {
  10130. toaster.pop('error', '提示', response.data);
  10131. });
  10132. });
  10133. // 更新企业信息
  10134. $scope.updateDetailInfo = function () {
  10135. $scope.loading = true;
  10136. $scope.enterprise = $scope.copyEnterprise;
  10137. $scope.enterprise.tags = $scope.tags.join(','); // 将标签数组转换成逗号分隔的字符串,便于储存
  10138. AccountEnterprise.save($scope.enterprise, function () {
  10139. $scope.loading = false;
  10140. $scope.connectionEditing = false;
  10141. toaster.pop('success', '提示', '修改企业信息成功');
  10142. $state.reload();
  10143. }, function (response) {
  10144. $scope.loading = false;
  10145. toaster.pop('error', '修改信息失败', response.data);
  10146. });
  10147. };
  10148. // 更新企业开票信息
  10149. $scope.updateApBillOutInfo = function(uu){
  10150. $scope.loading = true;
  10151. $scope.apBillOutInfo.uu = uu;
  10152. AccountEnterprise.saveApBillOutInfo($scope.apBillOutInfo, function(){
  10153. $scope.loading = false;
  10154. $scope.apBillOutInfoEditing = false;
  10155. toaster.pop('success', '提示', '修改企业开票信息成功');
  10156. $state.reload();
  10157. }, function(response){
  10158. $scope.loading = false;
  10159. toaster.pop('error', '修改信息失败', response.data);
  10160. });
  10161. };
  10162. // 申请Saas
  10163. $scope.applySaas = function () {
  10164. if ($scope.enterprise.enUrl && $scope.enterprise.enAddress && $scope.enterprise.enIndustry) {
  10165. var modalInstance = $modal.open({
  10166. animation: true,
  10167. templateUrl: 'static/tpl/index/account/applySaas.html',
  10168. controller: 'ApplySaasCtrl',
  10169. resolve: {
  10170. enterprise: function () {
  10171. return angular.copy($scope.enterprise);
  10172. }
  10173. }
  10174. });
  10175. modalInstance.result.then(function () {
  10176. $state.reload();
  10177. }, function () {
  10178. });
  10179. } else {
  10180. toaster.pop('info', '请完善信息', '申请优企云服请先完善企业详细信息');
  10181. }
  10182. };
  10183. // 获取收货地址列表
  10184. ShipAddress.shipAddList({}, function (data) {
  10185. $scope.ships = data;
  10186. });
  10187. // 判断是否是代采企业
  10188. DeputyOrder.isDeputyEnterprise({}, function (data) {
  10189. $scope.deputyEnter = data;
  10190. });
  10191. // 获取地址信息
  10192. $http.get('resources/citydata/city.json', {
  10193. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10194. }).then(function (response) {
  10195. $scope.provinces = response.data;
  10196. });
  10197. // 新增收货地址保存
  10198. $scope.saveShipAddress = function (ship) {
  10199. ship.address = ship.province + ship.city + ship.district;
  10200. ShipAddress.saveAddress({}, ship, function (data) {
  10201. if (data.success) {
  10202. ShipAddress.shipAddList({}, function (data) {
  10203. $scope.ships = data;
  10204. });
  10205. toaster.pop('success', '提示', data.success);
  10206. $scope.ship = {receiver: null, usertel: null, phone: null, email: null, province: null, city: null, district: null, addressdet: null, addalias: null, address: null};
  10207. }
  10208. if (data.error) {
  10209. toaster.pop('error', '提示', data.error);
  10210. }
  10211. });
  10212. }
  10213. // 删除收货地址
  10214. $scope.removeShip = function (id, index) {
  10215. ShipAddress.removeShipAddress({id: id}, {}, function (data) {
  10216. $scope.ships.splice(index, 1);
  10217. toaster.pop('success', '提示', '收货地址删除成功');
  10218. }, function (response) {
  10219. toaster.pop('error', '提示', response.data);
  10220. });
  10221. };
  10222. // 编辑收货地址
  10223. $scope.editShip = function (ship) {
  10224. var modalInstance = $modal.open({
  10225. animation: true,
  10226. templateUrl: 'static/tpl/index/approvalFlow/shipaddress_modal.html',
  10227. controller: 'ShipAddressCtrl',
  10228. resolve: {
  10229. ship: function () {
  10230. return ship;
  10231. }
  10232. }
  10233. });
  10234. modalInstance.result.then(function () {
  10235. ShipAddress.shipAddList({}, function (data) {
  10236. $scope.ships = data;
  10237. });
  10238. }, function () {
  10239. });
  10240. };
  10241. // 新增付款企业
  10242. $scope.addPayCompany = function () {
  10243. var modalInstance = $modal.open({
  10244. animation: true,
  10245. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  10246. controller: 'PayCompanyCtrl',
  10247. resolve: {
  10248. pay: function () {
  10249. return null;
  10250. }
  10251. }
  10252. });
  10253. modalInstance.result.then(function () {
  10254. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  10255. $scope.pays = data;
  10256. // 获取付款企业信息
  10257. DeputyOrder.paycompanies({enuu: $scope.enterprise.uu}, {}, function (data) {
  10258. $scope.pays = data;
  10259. }, function (response) {
  10260. toaster.pop('error', '提示', response.data);
  10261. });
  10262. }, function (response) {
  10263. toaster.pop('error', '提示', response.data);
  10264. });
  10265. }, function () {
  10266. });
  10267. }
  10268. // 删除付款企业
  10269. $scope.removePay = function (id, index) {
  10270. DeputyOrder.removePayCompany({id: id}, {}, function (data) {
  10271. $scope.pays.splice(index, 1);
  10272. toaster.pop('success', '提示', '付款企业信息删除成功');
  10273. }, function (response) {
  10274. toaster.pop('error', '提示', response.data);
  10275. });
  10276. };
  10277. // 编辑付款企业
  10278. $scope.editPay = function (pay, uu) {
  10279. var modalInstance = $modal.open({
  10280. animation: true,
  10281. templateUrl: 'static/tpl/index/approvalFlow/paycompany_modal.html',
  10282. controller: 'PayCompanyCtrl',
  10283. resolve: {
  10284. pay: function () {
  10285. return pay;
  10286. }
  10287. }
  10288. });
  10289. modalInstance.result.then(function () {
  10290. DeputyOrder.paycompanies({enuu: uu}, {}, function (data) {
  10291. $scope.pays = data;
  10292. }, function (response) {
  10293. toaster.pop('error', '提示', response.data);
  10294. });
  10295. }, function () {
  10296. });
  10297. };
  10298. // 设置logo
  10299. $scope.showImageDialog = function (modal) {
  10300. require(['jquery-uploadify'], function () {
  10301. $modal.open({
  10302. templateUrl: 'static/tpl/index/home/insert.html',
  10303. controller: 'ImageInsertCtrl',
  10304. backdrop: 'static'
  10305. }).result.then(function (image) {
  10306. $scope.imageUrl = image.thumb;
  10307. User.postImageUrl(null, angular.toJson($scope.imageUrl), function (data) {
  10308. $scope.user = data;
  10309. }, function (response) {
  10310. toaster.pop('error', '设置图像失败,' + response.data);
  10311. });
  10312. });
  10313. });
  10314. }
  10315. // 添加经营范围标签
  10316. $scope.addTag = function () {
  10317. if ($scope.tags.indexOf($scope.tag) == -1){
  10318. if (null != $scope.tag && '' != $scope.tag) {
  10319. $scope.tags.push($scope.tag);
  10320. }
  10321. }
  10322. $scope.tag = '';
  10323. }
  10324. // 移除经营范围标签
  10325. $scope.removeTag = function (tag) {
  10326. removeByValue($scope.tags, tag);
  10327. }
  10328. // 获取行业信息
  10329. $http.get('static/data/profession.json').success(function (data) {
  10330. $scope.list = data;
  10331. });
  10332. // 选择行业
  10333. $scope.profession = new Array();
  10334. $scope.showProfession = false;
  10335. $scope.selectProfession = function () {
  10336. $scope.professionArray = [];
  10337. $scope.active = [];
  10338. $scope.showProfession = !$scope.showProfession;
  10339. $scope.profession[0] = $scope.list;
  10340. }
  10341. $scope.isInList = false;
  10342. $scope.isInInput = false;
  10343. $scope.hideList = function () {
  10344. if (!$scope.isInList && !$scope.isInInput && $scope.showProfession) {
  10345. $scope.showProfession = false;
  10346. }
  10347. }
  10348. // 行业子菜单点击
  10349. $scope.onItemClick = function (key, index, value) {
  10350. $scope.active[index] = key;
  10351. if (angular.isString(value)){ // 值为字符串说明点击的是最后一级
  10352. $scope.copyEnterprise.profession = value;
  10353. $scope.showProfession = false;
  10354. return;
  10355. }
  10356. $scope.professionArray = [];
  10357. $scope.profession.splice(index+1);
  10358. if (angular.isArray(value)){ // 值为数组说明下一级是最后一级
  10359. $scope.professionArray = value;
  10360. } else if (angular.isObject(value)) {
  10361. $scope.profession[index+1] = value;
  10362. }
  10363. }
  10364. // 判断值是否为字符串
  10365. $scope.isString = function (value) {
  10366. return angular.isString(value);
  10367. }
  10368. // 拷贝企业数据,在编辑企业数据是使用拷贝数据
  10369. $scope.copyData = function () {
  10370. $scope.copyEnterprise = angular.copy($scope.enterprise);
  10371. if ($scope.enterprise.tags) {
  10372. $scope.tags = $scope.enterprise.tags.split(','); // 将逗号分隔的标签字符串转换成数组,便于操作
  10373. } else {
  10374. $scope.tags = [];
  10375. }
  10376. }
  10377. }]);
  10378. // 编辑收货地址
  10379. app.controller('ShipAddressCtrl', ['$scope', 'ShipAddress', 'ship', '$modalInstance', 'toaster', '$http', function ($scope, ShipAddress, ship, $modalInstance, toaster, $http) {
  10380. $scope.ship = ship;
  10381. // 获取地址信息
  10382. $http.get('resources/citydata/city.json', {
  10383. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10384. }).then(function (response) {
  10385. $scope.provinces = response.data;
  10386. });
  10387. // 新增收货地址保存
  10388. $scope.saveShipAddress = function (ship) {
  10389. ship.address = ship.province + ship.city + ship.district;
  10390. ShipAddress.saveAddress({}, ship, function (data) {
  10391. if (data.success) {
  10392. toaster.pop('success', '提示', data.success);
  10393. $modalInstance.close();
  10394. }
  10395. if (data.error) {
  10396. toaster.pop('error', '提示', data.error);
  10397. }
  10398. });
  10399. }
  10400. $scope.cancel = function () {
  10401. $modalInstance.dismiss();
  10402. }
  10403. }]);
  10404. // 编辑付款企业信息
  10405. app.controller('PayCompanyCtrl', ['$scope', 'DeputyOrder', 'pay', '$modalInstance', 'toaster', '$http', function ($scope, DeputyOrder, pay, $modalInstance, toaster, $http) {
  10406. $scope.pay = pay;
  10407. // 获取地址信息
  10408. $http.get('resources/citydata/city.json', {
  10409. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  10410. }).then(function (response) {
  10411. $scope.provinces = response.data;
  10412. });
  10413. // 新增收货地址保存
  10414. $scope.savePayCompany = function (pay) {
  10415. pay.address = pay.province + pay.city + pay.district + pay.addressdet;
  10416. DeputyOrder.savePaycompany({}, pay, function (data) {
  10417. toaster.pop('success', '提示', '保存成功');
  10418. $modalInstance.dismiss();
  10419. }, function (response) {
  10420. toaster.pop('error', '提示', response.data);
  10421. });
  10422. }
  10423. $scope.cancel = function () {
  10424. $modalInstance.dismiss();
  10425. }
  10426. }]);
  10427. // 申请Saas Controller
  10428. app.controller('ApplySaasCtrl', ['$scope', '$modalInstance', 'enterprise', 'AccountEnterprise', 'toaster', '$http', function ($scope, $modalInstance, enterprise, AccountEnterprise, toaster, $http) {
  10429. $scope.enterprise = enterprise;
  10430. $scope.checking = false;
  10431. $scope.$watch('enterprise.enSaasUrl', function () {
  10432. if ($scope.enterprise.enSaasUrl) {
  10433. $http.get('signup/saasUrlEnable', {
  10434. params: {
  10435. enSaasUrl: $scope.enterprise.enSaasUrl
  10436. }
  10437. }).success(function (data) {
  10438. if (data && data == 'true') {
  10439. $scope.applySaasForm.enSaasUrl.$setValidity('available', true);
  10440. } else {
  10441. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10442. $scope.enSaasUrlErrorInfo = '优企云服域名已被使用';
  10443. }
  10444. }).error(function () {
  10445. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10446. $scope.enSaasUrlErrorInfo = '验证出错';
  10447. });
  10448. } else {
  10449. $scope.applySaasForm.enSaasUrl.$setValidity('available', false);
  10450. }
  10451. });
  10452. var setSaasUrl = function (url) {
  10453. var index = url.indexOf('www.');
  10454. if (index != -1) {//包含www.
  10455. var substr = url.substring(index + 4, url.length);
  10456. $scope.enterprise.enSaasUrl = substr.substring(0, substr.indexOf('.'));
  10457. } else {
  10458. $scope.enterprise.enSaasUrl = getHost(url);
  10459. }
  10460. };
  10461. // 解析获取网址的一级域名
  10462. var getHost = function (host) {
  10463. var newhost;
  10464. var domain;
  10465. var ArrDomain = new Array('.com.cn', '.net.cn', '.org.cn', '.gov.cn', '.com', '.cn', '.tel', '.mobi', '.net', '.org', '.asia', '.me', '.cc', '.name', '.info');//枚举所有后缀
  10466. for (var k in ArrDomain) {
  10467. var re = eval('/\\' + ArrDomain[k] + '$/g');
  10468. newhost = host.replace(re, '');
  10469. if (newhost != host) {
  10470. domain = ArrDomain[k];
  10471. break;
  10472. }
  10473. }
  10474. var hostar = newhost.split('.');
  10475. var s = hostar[hostar.length - 1];
  10476. return s;
  10477. };
  10478. // 设置优企云服域名为官网网址一级域名
  10479. if ($scope.enterprise.enUrl) setSaasUrl($scope.enterprise.enUrl);
  10480. $scope.apply = function () {
  10481. $scope.loading = true;
  10482. AccountEnterprise.applySaas({
  10483. enUU: $scope.enterprise.uu,
  10484. enSaasUrl: $scope.enterprise.enSaasUrl,
  10485. enAdminPassword: $scope.enterprise.enAdminPassword
  10486. }, {}, function () {
  10487. $scope.loading = false;
  10488. toaster.pop('success', '申请成功', '已提交系统开通优企云服,开通后将会发送邮件至管理员邮箱');
  10489. $modalInstance.close();
  10490. }, function (response) {
  10491. $scope.loading = false;
  10492. toaster.pop('error', '申请失败', response.data);
  10493. });
  10494. };
  10495. $scope.cancel = function () {
  10496. $modalInstance.dismiss();
  10497. };
  10498. }]);
  10499. 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) {
  10500. BaseService.scrollBackToTop();
  10501. $scope.editing = false;
  10502. $scope.loading = true;
  10503. $scope.enterprise = null;
  10504. $scope.searchMthod = false;
  10505. $scope.keyword = null;
  10506. AccountUser.findDistribute({}, function (data) {
  10507. $scope.distributes = data;
  10508. }, function (response) {
  10509. toaster.pop('error', '系统错误', response.data);
  10510. });
  10511. AuthenticationService.getAuthentication().success(function (data) {
  10512. $scope.loading = false;
  10513. $scope.user = data;
  10514. });
  10515. var users = [];
  10516. var getMangagerInfo = function() {
  10517. CurrentRole.isManager({}, function(data) {
  10518. $scope.isManager = data.isManager || $scope.user.sys;
  10519. });
  10520. CurrentRole.roles({}, function(data) {
  10521. $scope.roles = data.count || $scope.user.sys;
  10522. });
  10523. };
  10524. getMangagerInfo();
  10525. $scope.tableParams = new ngTableParams({
  10526. page: 1,
  10527. count: 20,
  10528. sorting: {
  10529. userName: 'asc'
  10530. }
  10531. }, {
  10532. total: 0,
  10533. counts: [15, 25, 50, 100],
  10534. getData: function ($defer, params) {
  10535. $scope.loading = true;
  10536. var pageParams = params.url();
  10537. pageParams.keyword = $scope.keyword;
  10538. $scope.tip = $scope.keyword;
  10539. AccountUser.getAll.call(null, BaseService.parseParams(pageParams), function (page) {
  10540. $scope.loading = false;
  10541. if (page) {
  10542. params.total(page.totalElement);
  10543. $defer.resolve(page.content);
  10544. users = page.content;
  10545. if(users.length > 0) {
  10546. if(users.length > 0) {
  10547. angular.forEach(users, function (user) { // 从验证中获取到的用户信息,不包含身份证号。在这里赋值
  10548. if (user.userTel === $scope.user.userTel && user.userUU === $scope.user.userUU) {
  10549. $scope.user.userIdcode = user.userIdcode;
  10550. }
  10551. });
  10552. }
  10553. }
  10554. }
  10555. }, function (response) {
  10556. $scope.loading = false;
  10557. toaster.pop('error', '数据加载失败', response.data);
  10558. });
  10559. }
  10560. });
  10561. $scope.onSearch = function(keyword) {
  10562. $scope.keyword = keyword;
  10563. $scope.tableParams.reload();
  10564. $scope.tableParams.page(1);
  10565. }
  10566. $scope.saveUser = function () {
  10567. $scope.loading = true;
  10568. AccountUser.update({}, $scope.user, function (data) {
  10569. $scope.loading = false;
  10570. toaster.pop('success', '提示', '修改用户信息成功');
  10571. AuthenticationService.getAuthentication().success(function (data) {
  10572. $scope.user = data;
  10573. });
  10574. loadUsers();
  10575. $scope.editing = false;
  10576. }, function (reponse) {
  10577. $scope.loading = false;
  10578. toaster.pop('error', '失败', reponse.data);
  10579. });
  10580. };
  10581. $scope.updatePassword = function () {
  10582. var newPage = window.open("about:black");
  10583. AccountUser.getUpdatePasswordUrl({}, function (data) {
  10584. newPage.location.href = data.url;
  10585. });
  10586. };
  10587. $scope.updateDetail = function () {
  10588. var newPage = window.open("about:black");
  10589. AccountUser.getCloudCenterUrl({}, function (data) {
  10590. newPage.location.href = data.url;
  10591. });
  10592. }
  10593. $scope.newUser = {};
  10594. //弹出添加用户模态框
  10595. $scope.addExistUser = function () {
  10596. var modalInstance = $modal.open({
  10597. animation: true,
  10598. templateUrl: 'static/tpl/index/account/addExistUser.html',
  10599. controller: 'AddExistUserCtrl'
  10600. });
  10601. modalInstance.result.then(function () {
  10602. $scope.userTelSuccess = false;
  10603. $scope.userTelError = false;
  10604. $scope.tableParams.reload();
  10605. }, function () {
  10606. });
  10607. };
  10608. /**
  10609. * 添加未注册用户
  10610. */
  10611. $scope.submit = false;
  10612. $scope.addUser = function () {
  10613. $scope.submit = true;
  10614. $scope.adding = true;
  10615. $scope.loading = true;
  10616. AccountUser.save({}, $scope.newUser, function (data) {
  10617. $scope.loading = false;
  10618. $scope.submit = false;
  10619. toaster.pop('success', '提示', '增加用户成功:' + $scope.newUser.userName);
  10620. $scope.newUser = {userSex: 'M'};
  10621. $scope.tableParams.reload();
  10622. $scope.adding = false;
  10623. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10624. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10625. $scope.userTelSuccess = false;
  10626. $scope.userTelError = false;
  10627. $scope.userEmailSuccess = false;
  10628. $scope.userEmailError = false;
  10629. }, function (response) {
  10630. $scope.submit = false;
  10631. $scope.loading = false;
  10632. toaster.pop('error', '错误', response.data);
  10633. });
  10634. };
  10635. /**
  10636. * 验证手机号是否可用
  10637. */
  10638. $scope.telValid = function (tel) {
  10639. if (tel) {
  10640. $http.get('account/user/telEnable', {
  10641. params: {
  10642. tel: tel
  10643. }
  10644. }).success(function (data) {
  10645. data = eval(data);
  10646. if (data == true) {
  10647. $scope.newUserForm.newUserTel.$setValidity('available', true);
  10648. $scope.userTelSuccess = true;
  10649. $scope.userTelError = false;
  10650. } else {
  10651. $scope.newUserForm.newUserTel.$setValidity('available', false);
  10652. $scope.userTelError = true;
  10653. $scope.userTelSuccess = false;
  10654. if (tel.length == 11)
  10655. toaster.pop('error', '错误', '手机号 ' + tel + ' 已被注册');
  10656. }
  10657. }).error(function () {
  10658. $scope.userTelSuccess = false;
  10659. $scope.userTelError = true;
  10660. });
  10661. } else {
  10662. $scope.userTelSuccess = false;
  10663. $scope.userTelError = false;
  10664. }
  10665. };
  10666. /**
  10667. * 验证邮箱是否可用
  10668. */
  10669. $scope.emailValid = function (email) {
  10670. if (email) {
  10671. $http.get('account/user/emailEnable', {
  10672. params: {
  10673. email: email
  10674. }
  10675. }).success(function (data) {
  10676. data = eval(data);
  10677. if (data == true) {
  10678. $scope.newUserForm.newUserEmail.$setValidity('available', true);
  10679. $scope.userEmailSuccess = true;
  10680. $scope.userEmailError = false;
  10681. } else {
  10682. $scope.newUserForm.newUserEmail.$setValidity('available', false);
  10683. $scope.userEmailError = true;
  10684. $scope.userEmailSuccess = false;
  10685. }
  10686. }).error(function () {
  10687. $scope.userEmailError = true;
  10688. $scope.userEmailSuccess = false;
  10689. });
  10690. } else {
  10691. $scope.userEmailError = false;
  10692. $scope.userEmailSuccess = false;
  10693. }
  10694. };
  10695. /**
  10696. * 删除用户
  10697. */
  10698. $scope.removeUser = function (user) {
  10699. new ngAlert({
  10700. title: '提示',
  10701. content: '确定删除用户(' + user.userName + ')吗?'
  10702. }, function () {
  10703. AccountUser.remove({uu: user.userUU}, function () {
  10704. toaster.pop('success', '提示', '用户删除成功。');
  10705. loadUsers();
  10706. }, function (response) {
  10707. toaster.pop('error', '删除失败', response.data);
  10708. });
  10709. });
  10710. };
  10711. // 编辑用户的角色
  10712. $scope.editUserRole = function (user) {
  10713. var modalInstance = $modal.open({
  10714. animation: true,
  10715. templateUrl: 'static/tpl/index/approvalFlow/user_role.html',
  10716. controller: 'UserRoleCtrl',
  10717. resolve: {
  10718. user: function () {
  10719. return user;
  10720. }
  10721. }
  10722. });
  10723. modalInstance.result.then(function (changed, checked) {
  10724. if (changed) {
  10725. if (checked)
  10726. $scope.newUser.roles = checked;
  10727. else
  10728. loadUsers();
  10729. }
  10730. });
  10731. };
  10732. // 为用户分配角色(删除企业)
  10733. $scope.removeVendor = function (user) {
  10734. var resultRole = true;
  10735. angular.forEach(user.roles, function (role) {
  10736. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10737. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10738. resultRole = false;
  10739. return;
  10740. }
  10741. });
  10742. if (resultRole) {
  10743. var modalInstance = $modal.open({
  10744. animation: true,
  10745. templateUrl: 'static/tpl/index/account/remove_vendor.html',
  10746. controller: 'RemoveVendorCtrl',
  10747. resolve: {
  10748. user: function () {
  10749. return user;
  10750. }
  10751. }
  10752. });
  10753. }
  10754. };
  10755. // 为用户分配角色(添加企业)
  10756. $scope.addVendor = function (user, isIssy) {
  10757. if (!$scope.roles) {
  10758. toaster.pop('error', '提示', '你不是管理员或销售经理,无权限分配!请立即联系管理员');
  10759. return;
  10760. }
  10761. var resultRole = true;
  10762. angular.forEach(user.roles, function (role) {
  10763. if (role.issys == 1 || role.name == 'ROLE_SALEMANAGER') {
  10764. toaster.pop('error', '提示', '管理员和销售经理无需分配客户');
  10765. resultRole = false;
  10766. return;
  10767. }
  10768. })
  10769. if (resultRole) {
  10770. var modalInstance = $modal.open({
  10771. animation: true,
  10772. templateUrl: 'static/tpl/index/account/add_vendor.html',
  10773. controller: 'AddVendorCtrl',
  10774. resolve: {
  10775. user: function () {
  10776. return user;
  10777. }
  10778. }
  10779. });
  10780. modalInstance.result.then(function (changed, checked) {
  10781. if (changed) {
  10782. if (checked)
  10783. $scope.newUser.roles = checked;
  10784. else
  10785. loadUsers();
  10786. }
  10787. });
  10788. }
  10789. };
  10790. }]);
  10791. // 登录手机号码验证
  10792. app.controller('CheckTelCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'AuthenticationService', 'SendCheckMsg', 'SessionService', '$timeout', function ($scope, $modalInstance, user, AccountUser, AuthenticationService, SendCheckMsg, SessionService, $timeout) {
  10793. $scope.user = user;
  10794. $scope.cancel = function () {
  10795. $modalInstance.close();
  10796. }
  10797. }]);
  10798. app.controller('RemoveVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10799. $scope.checkboxes = {
  10800. checked: false
  10801. };
  10802. $scope.loading = true;
  10803. AccountUser.findChooseVendor({uu: user.userUU}, function (data) {
  10804. $scope.enters = data;
  10805. $scope.loading = false;
  10806. angular.forEach($scope.enters, function (item) {
  10807. item:{
  10808. $selected:true;
  10809. }
  10810. });
  10811. })
  10812. // 点击勾选全部的复选框
  10813. $scope.checkAll = function () {
  10814. angular.forEach($scope.enters, function (item) {
  10815. item.$selected = $scope.checkboxes.checked;
  10816. });
  10817. };
  10818. // 点击其中一个明细的复选框
  10819. $scope.checkOne = function (vendor) {
  10820. var result = true;
  10821. angular.forEach($scope.enters, function (item) {
  10822. if (item.$selected != true) {
  10823. result = false;
  10824. return;
  10825. }
  10826. });
  10827. $scope.checkboxes.checked = result;
  10828. };
  10829. $scope.close = function (save) {
  10830. var chooseResult = [];
  10831. if (save) {
  10832. if (user.userUU) {
  10833. angular.forEach($scope.enters, function (item, i) {
  10834. if (item.$selected) {
  10835. chooseResult.push(item.id);
  10836. }
  10837. });
  10838. if (chooseResult.length > 0) {
  10839. $scope.loading = true;
  10840. AccountUser.removeChooseVendor({uu: user.userUU}, chooseResult, function (data) {
  10841. $scope.loading = false;
  10842. toaster.pop('success', '提示', '删除成功');
  10843. $modalInstance.close(false);
  10844. }, function (response) {
  10845. $scope.loading = false;
  10846. toaster.pop('error', '删除失败', response.data);
  10847. $modalInstance.close(false);
  10848. })
  10849. } else {
  10850. toaster.pop('error', '删除失败', "您未勾选任何记录");
  10851. }
  10852. } else {
  10853. $modalInstance.close(true, $scope.checkboxes.checked);
  10854. }
  10855. } else {
  10856. $modalInstance.close(false);
  10857. }
  10858. };
  10859. }]);
  10860. app.controller('AddVendorCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10861. $scope.checkboxes = {
  10862. checked: false
  10863. };
  10864. $scope.loading = true;
  10865. AccountUser.findVendor({uu: user.userUU}, function (data) {
  10866. $scope.enters = data;
  10867. $scope.loading = false;
  10868. })
  10869. // 点击勾选全部的复选框
  10870. $scope.checkAll = function () {
  10871. angular.forEach($scope.enters, function (item) {
  10872. item.distribute = $scope.checkboxes.checked;
  10873. });
  10874. };
  10875. // 点击其中一个明细的复选框
  10876. $scope.checkOne = function (vendor) {
  10877. var result = true;
  10878. angular.forEach($scope.enters, function (item) {
  10879. if (item.distribute != true) {
  10880. result = false;
  10881. return;
  10882. }
  10883. });
  10884. $scope.checkboxes.checked = result;
  10885. };
  10886. $scope.close = function (save) {
  10887. var chooseResult = [];
  10888. if (save) {
  10889. if (user.userUU) {
  10890. angular.forEach($scope.enters, function (item, i) {
  10891. chooseResult.push(item);
  10892. });
  10893. if (chooseResult.length > 0) {
  10894. $scope.loading = true;
  10895. AccountUser.addVendor({uu: user.userUU}, chooseResult, function (data) {
  10896. $scope.loading = false;
  10897. toaster.pop('success', '提示', '保存成功');
  10898. $modalInstance.close(false);
  10899. }, function (response) {
  10900. $scope.loading = false;
  10901. toaster.pop('error', '保存失败', response.data);
  10902. $modalInstance.close(false);
  10903. })
  10904. } else {
  10905. toaster.pop('error', '保存失败', "您未勾选任何记录");
  10906. }
  10907. } else {
  10908. $modalInstance.close(true, $scope.checkboxes.checked);
  10909. }
  10910. } else {
  10911. $modalInstance.close(false);
  10912. }
  10913. };
  10914. }]);
  10915. app.controller('UserRoleCtrl', ['$scope', '$modalInstance', 'user', 'AccountRole', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountRole, AccountUser, toaster) {
  10916. $scope.checked = [];
  10917. $scope.master = [];
  10918. AccountRole.query({}, function (data) {
  10919. if (user && data) {
  10920. var rs = [], checked = [];
  10921. angular.forEach(user.roles, function (r) {
  10922. rs.push(r.id);
  10923. });
  10924. angular.forEach(data, function (d) {
  10925. if (rs.indexOf(d.id) > -1) {
  10926. d.$checked = true;
  10927. checked.push(d);
  10928. }
  10929. });
  10930. }
  10931. $scope.roles = data;
  10932. $scope.checked = checked;
  10933. $scope.master = angular.copy($scope.checked);
  10934. });
  10935. $scope.select = function (role) {
  10936. role.$checked = !role.$checked;
  10937. if (role.$checked) {
  10938. if (role.desc === '管理员' || role.desc === '普通用户') {
  10939. $scope.checked = [];
  10940. angular.forEach($scope.roles, function (r) {
  10941. r.$checked = false;
  10942. });
  10943. role.$checked = true;
  10944. $scope.checked.push(role);
  10945. } else {
  10946. angular.forEach( $scope.checked, function (r, i) {
  10947. if (r.desc === '管理员' || r.desc === '普通用户') {
  10948. $scope.checked.splice(i, 1);
  10949. }
  10950. });
  10951. angular.forEach($scope.roles, function (r) {
  10952. if (r.desc === '管理员' || r.desc === '普通用户') {
  10953. r.$checked = false;
  10954. }
  10955. });
  10956. $scope.checked.push(role);
  10957. }
  10958. } else {
  10959. angular.forEach($scope.checked, function (c, i) {
  10960. if (c.id == role.id)
  10961. $scope.checked.splice(i, 1);
  10962. });
  10963. }
  10964. };
  10965. $scope.isChanged = function () {
  10966. return !angular.equals($scope.master, $scope.checked);
  10967. };
  10968. $scope.close = function (save) {
  10969. if (save) {
  10970. if (user.userUU) {
  10971. user.roles = $scope.checked;
  10972. AccountUser.updateRole({}, user, function () {
  10973. toaster.pop('success', '提示', '保存成功');
  10974. $modalInstance.close(true);
  10975. }, function (response) {
  10976. toaster.pop('error', '保存失败', response.data);
  10977. });
  10978. } else {
  10979. $modalInstance.close(true, $scope.checked);
  10980. }
  10981. } else {
  10982. $modalInstance.close(false);
  10983. }
  10984. };
  10985. }]);
  10986. // 修改密码Controller
  10987. app.controller('PasswordCtrl', ['$scope', '$modalInstance', 'user', 'AccountUser', 'toaster', function ($scope, $modalInstance, user, AccountUser, toaster) {
  10988. $scope.user = user;
  10989. $scope.checking = false;
  10990. //输入原密码后验证原密码是否正确
  10991. $scope.checkPassword = function (password) {
  10992. $scope.checking = true;
  10993. $scope.checkSuccess = false;
  10994. $scope.checkFailed = false;
  10995. AccountUser.checkPassword({password: password}, function (data) {
  10996. $scope.checkSuccess = true;
  10997. $scope.checking = false;
  10998. $scope.checkFailed = false;
  10999. }, function (response) {
  11000. $scope.checkFailed = true;
  11001. $scope.checking = false;
  11002. $scope.checkSuccess = false;
  11003. });
  11004. };
  11005. //修改密码
  11006. $scope.ok = function () {
  11007. if ($scope.user.newPassword == $scope.user.newPassword1) {//验证重复密码相等
  11008. AccountUser.updatePassword({
  11009. password: $scope.user.password,
  11010. newPassword: $scope.user.newPassword
  11011. }, {}, function (data) {
  11012. var tip = '修改成功,请牢记您的新密码:' + $scope.user.newPassword;
  11013. toaster.pop('success', '成功', tip);
  11014. $scope.user.password = null;
  11015. $scope.user.newPassword = null;
  11016. $scope.user.newPassword1 = null;
  11017. $scope.checking = false;
  11018. $scope.checkSuccess = false;
  11019. $scope.checkFailed = false;
  11020. $modalInstance.close();
  11021. }, function (response) {
  11022. toaster.pop('error', '错误', response.data);
  11023. });
  11024. } else {
  11025. toaster.pop('error', '错误', '重复密码不一致');
  11026. }
  11027. };
  11028. $scope.cancel = function () {
  11029. $modalInstance.dismiss();
  11030. };
  11031. }]);
  11032. /*
  11033. * 绑定用户到企业
  11034. */
  11035. app.controller('AddExistUserCtrl', ['$scope', '$modalInstance', 'FuzzySearch', 'AuthenticationService', '$timeout', 'toaster', function ($scope, $modalInstance, FuzzySearch, AuthenticationService, $timeout, toaster) {
  11036. $scope.searching = false;
  11037. //根据输入的内容查找用户
  11038. $scope.searchUser = function (keyWord) {
  11039. $scope.searching = true;
  11040. $scope.searchSuccess = false;
  11041. $scope.searchFailed = false;
  11042. $scope.illegalError = false;
  11043. $scope.reBindError = false;
  11044. $scope.okDisabled = false;
  11045. FuzzySearch.searchUser({keyWord: keyWord}, function (data) {
  11046. $scope.searchSuccess = true;
  11047. $scope.searchFailed = false;
  11048. $scope.user = data; //查询到的用户
  11049. }, function (response) {
  11050. $scope.searchSuccess = false;
  11051. $scope.searchFailed = true;
  11052. });
  11053. };
  11054. //确认绑定
  11055. $scope.ok = function (keyWord) {
  11056. AuthenticationService.getAuthentication().success(function (data) {
  11057. $scope.currentUser = data; //当前登录的用户(管理员)
  11058. //不可自己绑定自己
  11059. if ($scope.currentUser.userUU == $scope.user.userUU) {
  11060. $scope.illegalError = true;
  11061. $scope.okDisabled = true;
  11062. return false;
  11063. }
  11064. //用户未绑定到任何企业时
  11065. if (!$scope.user.enterprises) {
  11066. //正常绑定
  11067. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  11068. $scope.okDisabled = true;
  11069. toaster.pop("success", "提示", "用户绑定成功");
  11070. $modalInstance.close(true);
  11071. }, function (response) {
  11072. });
  11073. return true;
  11074. }
  11075. //用户已绑定到某些企业时
  11076. for (var i = 0; i < $scope.currentUser.enterprises.length; i++) {
  11077. if ($scope.currentUser.enterprises[i].current) {
  11078. for (var j = 0; j < $scope.user.enterprises.length; j++) {
  11079. //该用户已绑定到当前企业,不可重复绑定
  11080. if ($scope.currentUser.enterprises[i].uu == $scope.user.enterprises[j].uu) {
  11081. $scope.reBindError = true;
  11082. $scope.okDisabled = true;
  11083. return false;
  11084. }
  11085. }
  11086. //该用户未绑定到当前企业,可以进行绑定
  11087. FuzzySearch.bindUserToMyEnterprise({userUU: $scope.user.userUU}, function (data) {
  11088. $scope.okDisabled = true;
  11089. toaster.pop("success", "提示", "用户绑定成功");
  11090. $modalInstance.close(true);
  11091. }, function (response) {
  11092. console.log("绑定失败!");
  11093. });
  11094. }
  11095. }
  11096. });
  11097. };
  11098. $scope.cancel = function () {
  11099. $modalInstance.dismiss();
  11100. };
  11101. }]);
  11102. app.controller('LogCtrl', ['$scope', 'BaseService', 'ngTableParams', 'ErpLog', 'UsageLog', function ($scope, BaseService, ngTableParams, ErpLog, UsageLog) {
  11103. $scope.erpParams = new ngTableParams({
  11104. page: 1,
  11105. count: 20,
  11106. sorting: {
  11107. time: 'desc'
  11108. }
  11109. }, {
  11110. total: 0,
  11111. counts: [5, 10, 25, 50],
  11112. getData: function ($defer, params) {
  11113. $scope.loading = true;
  11114. ErpLog.get(BaseService.parseParams(params.url()), function (page) {
  11115. $scope.loading = false;
  11116. if (page) {
  11117. params.total(page.totalElements);
  11118. $defer.resolve(page.content);
  11119. }
  11120. }, function (response) {
  11121. $scope.loading = false;
  11122. toaster.pop('error', '数据加载失败', response.data);
  11123. });
  11124. }
  11125. });
  11126. $scope.usageParams = new ngTableParams({
  11127. page: 1,
  11128. count: 20,
  11129. sorting: {
  11130. time: 'desc'
  11131. }
  11132. }, {
  11133. total: 0,
  11134. counts: [5, 10, 25, 50],
  11135. getData: function ($defer, params) {
  11136. $scope.loading = true;
  11137. UsageLog.get(BaseService.parseParams(params.url()), function (page) {
  11138. $scope.loading = false;
  11139. if (page) {
  11140. params.total(page.totalElements);
  11141. $defer.resolve(page.content);
  11142. }
  11143. }, function (response) {
  11144. $scope.loading = false;
  11145. toaster.pop('error', '数据加载失败', response.data);
  11146. });
  11147. }
  11148. });
  11149. }]);
  11150. app.controller('ResourceCtrl', ['$scope', 'AccountResource', function ($scope, AccountResource) {
  11151. AccountResource.query({}, function (data) {
  11152. if (data && data.length > 0) {
  11153. data[0].$open = true;
  11154. }
  11155. $scope.resources = data;
  11156. });
  11157. }]);
  11158. app.controller('RoleCtrl', ['$scope', '$modal', 'AccountRole', function ($scope, $modal, AccountRole) {
  11159. $scope.roles = {};
  11160. var getData = function () {
  11161. AccountRole.query({}, function (data) {
  11162. var defaults = [], custom = [];
  11163. angular.forEach(data, function (d) {
  11164. if (d.isdefault == 1)
  11165. defaults.push(d);
  11166. else
  11167. custom.push(d);
  11168. });
  11169. $scope.roles = {defaults: defaults, custom: custom};
  11170. });
  11171. };
  11172. getData();
  11173. $scope.editRole = function (role) {
  11174. var modalInstance = $modal.open({
  11175. animation: true,
  11176. templateUrl: 'static/tpl/index/approvalFlow/role_detail.html',
  11177. controller: 'RoleEditCtrl',
  11178. resolve: {
  11179. role: function () {
  11180. return role;
  11181. }
  11182. }
  11183. });
  11184. modalInstance.result.then(function (added) {
  11185. added && (getData());
  11186. });
  11187. };
  11188. }]);
  11189. 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) {
  11190. BaseService.scrollBackToTop();
  11191. // 获取当前用户是否为管理员
  11192. AuthenticationService.getAuthentication().success(function (data) {
  11193. $scope.loading = false;
  11194. $scope.user = data;
  11195. });
  11196. CurrentRole.isManager({}, {}, function (data) {
  11197. $scope.isManager = data.isManager || $scope.user.sys;
  11198. });
  11199. $scope.role = role;
  11200. $scope.master = angular.copy($scope.role);
  11201. var isNew = role == null;
  11202. $scope.cancel = function () {
  11203. $modalInstance.close(false);
  11204. };
  11205. AccountResource.query({}, function (data) {
  11206. if (data && data.length > 0) {
  11207. if (role && role.resourceItems) {
  11208. var rs = [];// 已分配的资源的id
  11209. angular.forEach(role.resourceItems, function (item) {
  11210. rs.push(item.id);
  11211. });
  11212. angular.forEach(data, function (resource) {
  11213. var c = 0;
  11214. angular.forEach(resource.items, function (item) {
  11215. if (rs.indexOf(item.id) > -1) {
  11216. item.$checked = true;
  11217. c += 1;
  11218. }
  11219. });
  11220. resource.$checked = c == resource.items.length;
  11221. });
  11222. }
  11223. $scope.resourceItems = data[0].items;
  11224. data[0].$active = true;
  11225. }
  11226. $scope.resources = data;
  11227. $timeout(function () {
  11228. angular.forEach($scope.resources, function (resource) {
  11229. var c = 0;
  11230. angular.forEach(resource.items, function (item) {
  11231. item.$checked && (c += 1);
  11232. });
  11233. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  11234. });
  11235. }, 100);
  11236. });
  11237. $scope.onItemClick = function (resource) {
  11238. $scope.resourceItems = resource.items;
  11239. angular.forEach($scope.resources, function (r) {
  11240. r.$active = false;
  11241. });
  11242. resource.$active = true;
  11243. };
  11244. var getChecked = function () {
  11245. var items = [];
  11246. angular.forEach($scope.resources, function (resource) {
  11247. angular.forEach(resource.items, function (item) {
  11248. item.$checked && (items.push(item));
  11249. });
  11250. });
  11251. $scope.role.resourceItems = items;
  11252. };
  11253. $scope.onResourceChange = function (resource) {
  11254. angular.forEach(resource.items, function (item) {
  11255. item.$checked = resource.$checked;
  11256. });
  11257. getChecked();
  11258. };
  11259. $scope.onItemChange = function () {
  11260. angular.forEach($scope.resources, function (resource) {
  11261. if (resource.$active) {
  11262. var c = 0;
  11263. angular.forEach(resource.items, function (item) {
  11264. item.$checked && (c += 1);
  11265. });
  11266. resource.$checked = (c == resource.items.length);
  11267. angular.element(document.getElementById('check_' + resource.id)).prop('indeterminate', (c > 0 && !resource.$checked));
  11268. }
  11269. });
  11270. getChecked();
  11271. };
  11272. $scope.isChanged = function (formData) {
  11273. if (!$scope.master)
  11274. return true;
  11275. return !angular.equals(formData, $scope.master);
  11276. };
  11277. $scope.save = function () {
  11278. $scope.master = angular.copy($scope.role);
  11279. AccountRole.save($scope.master, function () {
  11280. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 资料' + (isNew ? '添加' : '修改') + '成功');
  11281. $modalInstance.close(true);
  11282. }, function (response) {
  11283. toaster.pop('error', '错误', response.data);
  11284. });
  11285. };
  11286. $scope.del = function () {
  11287. new ngAlert({
  11288. title: '提示',
  11289. content: '确定删除角色(' + $scope.role.desc + ')吗?'
  11290. }, function () {
  11291. AccountRole.remove({id: role.id}, {}, function () {
  11292. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 删除成功');
  11293. $modalInstance.close(true);
  11294. }, function (response) {
  11295. toaster.pop('error', '错误', response.data);
  11296. });
  11297. })
  11298. };
  11299. $scope.updateDefault = function () {
  11300. new ngAlert({
  11301. title: '提示',
  11302. content: '确定把(' + $scope.role.desc + ')信息更新到标准库吗?'
  11303. }, function () {
  11304. AccountRole.updateDefault({desc: $scope.role.desc}, $scope.role.resourceItems, function () {
  11305. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 更新成功');
  11306. $modalInstance.close(true);
  11307. }, function (response) {
  11308. toaster.pop('error', '错误', response.data);
  11309. });
  11310. })
  11311. }
  11312. $scope.recover = function () {
  11313. new ngAlert({
  11314. title: '提示',
  11315. content: '确定将“' + $scope.role.desc + '”恢复默认权限吗?'
  11316. }, function () {
  11317. AccountRole.recover({roleId: role.id}, {}, function () {
  11318. toaster.pop('success', '提示', '角色:' + $scope.role.desc + ' 恢复默认权限成功');
  11319. $modalInstance.close(true);
  11320. }, function (response) {
  11321. toaster.pop('error', '错误', response.data);
  11322. });
  11323. })
  11324. };
  11325. }]);
  11326. /**
  11327. * 委外订单
  11328. */
  11329. app.controller('MakeOrderCtrl', ['$scope', '$filter', 'MakeOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole',
  11330. function ($scope, $filter, MakeOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  11331. BaseService.scrollBackToTop();
  11332. // 获取当前用户是否为普通用户
  11333. CurrentRole.isUser({}, {}, function (data) {
  11334. $scope.isUser = data.isUser;
  11335. });
  11336. $scope.active = 'todo';
  11337. $scope.dateZoneText = '不限';
  11338. $scope.condition = {dateZone: 1};
  11339. /* 时间筛选初始化*/
  11340. var fromDate = new Date();
  11341. var toDate = new Date();
  11342. fromDate.setMonth(fromDate.getMonth() - 1);
  11343. fromDate.setHours(0, 0, 0, 0);
  11344. toDate.setHours(23, 59, 59, 999);
  11345. $scope.condition.dateFrom = fromDate;
  11346. $scope.condition.dateTo = toDate;
  11347. $scope.changeDateZone = function (zone) {
  11348. $scope.condition.dateZone = zone;
  11349. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11350. $scope.condition.$dateZoneOpen = false;
  11351. getDateCondition(zone, $scope.condition);
  11352. $scope.tableParams.page(1);
  11353. $scope.tableParams.reload();
  11354. };
  11355. $scope.setActive = function (state) {
  11356. if ($scope.active != state) {
  11357. $scope.active = state;
  11358. if ($scope.tableParams.page() == 1)
  11359. $scope.tableParams.reload();
  11360. else
  11361. $scope.tableParams.page(1);
  11362. }
  11363. };
  11364. var getService = function () {
  11365. return MakeOrder;
  11366. };
  11367. $scope.tableParams = new ngTableParams({
  11368. page: 1,
  11369. count: 20,
  11370. sorting: {
  11371. date: 'desc'
  11372. }
  11373. }, {
  11374. total: 0,
  11375. counts: [5, 10, 25, 50],
  11376. getData: function ($defer, params) {
  11377. $scope.loading = true;
  11378. var pageParams = params.url();
  11379. pageParams.searchFilter = {
  11380. keyword: $scope.keyword,
  11381. fromDate: getDateTime($scope.condition.dateFrom),
  11382. endDate: getDateTime($scope.condition.dateTo)
  11383. };
  11384. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11385. $scope.loading = false;
  11386. if (page) {
  11387. params.total(page.totalElement);
  11388. $defer.resolve(page.content);
  11389. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11390. }
  11391. }, function (response) {
  11392. $scope.loading = false;
  11393. toaster.pop('error', '数据加载失败', response.data);
  11394. });
  11395. }
  11396. });
  11397. //获得各分类未阅读数量
  11398. var getUnreadCount = function () {
  11399. MakeOrder.getUnreadCount(null, function (data) {
  11400. $scope.unread = data;
  11401. });
  11402. };
  11403. getUnreadCount();
  11404. //设置单据已读
  11405. $scope.setOrdersRead = function (id) {
  11406. // 如果单据本身已读,则不发送请求修改数据
  11407. if (!$scope.isUnread(id)){
  11408. return;
  11409. }
  11410. var sourceId = [];
  11411. sourceId.push(id);
  11412. MakeOrder.setRead({}, sourceId, function (message) {
  11413. // $scope.getUnreadIds();
  11414. getUnreadCount();
  11415. });
  11416. };
  11417. $scope.setOrdersReadByState = function () {
  11418. if (!$scope.unread.replied || $scope.unread.replied == 0) {
  11419. return;
  11420. }
  11421. MakeOrder.setReadByState({}, function () {
  11422. getUnreadIds();
  11423. getUnreadCount();
  11424. });
  11425. };
  11426. var getUnreadIds = function () {
  11427. MakeOrder.getUnreadIds({}, "", function (message) {
  11428. $scope.unreadCode = message.content;
  11429. });
  11430. };
  11431. getUnreadIds();
  11432. $scope.isUnread = function (id) {
  11433. for (var i in $scope.unreadCode) {
  11434. if (id == $scope.unreadCode[i]) {
  11435. return true;
  11436. }
  11437. }
  11438. };
  11439. $scope.getOrderTotal = function (items) {
  11440. var sum = 0;
  11441. angular.forEach(items, function (item) {
  11442. sum += item.qty * item.price;
  11443. });
  11444. return sum;
  11445. };
  11446. $scope.openDatePicker = function ($event, item, openParam) {
  11447. $event.preventDefault();
  11448. $event.stopPropagation();
  11449. item[openParam] = !item[openParam];
  11450. };
  11451. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11452. $event.preventDefault();
  11453. $event.stopPropagation();
  11454. item[openParam] = !item[openParam];
  11455. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11456. $scope.tableParams.reload();
  11457. }
  11458. };
  11459. $scope.parseDate = function (dateStr) {
  11460. if (dateStr)
  11461. return Date.parse(dateStr, 'yyyy-MM-dd');
  11462. return new Date();
  11463. };
  11464. // 打开回复
  11465. $scope.openReply = function (order) {
  11466. if (!order.reply) {
  11467. order.reply = {
  11468. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11469. delivery: order.delivery
  11470. }
  11471. }
  11472. order.$editing = true;
  11473. };
  11474. // 关闭回复
  11475. $scope.closeReply = function (order) {
  11476. order.$editing = false;
  11477. }
  11478. // 搜索框回车
  11479. $scope.onSearch = function () {
  11480. $scope.tableParams.page(1);
  11481. $scope.tableParams.reload();
  11482. };
  11483. // 选择查找日期
  11484. $scope.onDateCondition = function () {
  11485. $scope.tableParams.page(1);
  11486. $scope.tableParams.reload();
  11487. };
  11488. // 点击回复
  11489. $scope.onReplyClick = function (order, inverse) {
  11490. if (order.reply) {
  11491. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11492. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11493. return;
  11494. }
  11495. var reply = angular.copy(order.reply);
  11496. if (reply.delivery) {
  11497. if (typeof reply.delivery == 'object')
  11498. reply.delivery = reply.delivery.getTime();
  11499. } else {
  11500. reply.delivery = order.delivery;
  11501. }
  11502. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11503. $scope.loading = true;
  11504. MakeOrder.reply({orderId: order.id}, reply, function () {
  11505. $scope.loading = false;
  11506. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11507. $scope.tableParams.reload();
  11508. }, function (response) {
  11509. $scope.loading = false;
  11510. toaster.pop('error', '回复失败', response.data);
  11511. });
  11512. }
  11513. };
  11514. //委外加工单
  11515. $scope.print = function (order) {
  11516. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11517. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id=' + order.id);
  11518. };
  11519. // 获取回复记录
  11520. $scope.getReply = function (order) {
  11521. if (!order.replies) {
  11522. MakeOrder.getReply({orderId: order.id}, function (replies) {
  11523. order.replies = replies;
  11524. });
  11525. }
  11526. };
  11527. // 导出
  11528. $scope.exportXls = function () {
  11529. MakeOrder.exportXls({}, {}, function (data) {
  11530. if (data.success){
  11531. window.location.href = 'make/orders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11532. }
  11533. }, function (response) {
  11534. toaster.pop('error', '数据加载失败', response.data);
  11535. });
  11536. }
  11537. }]);
  11538. /**
  11539. * 委外加工单详细
  11540. */
  11541. app.controller('MakeOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOrder, toaster, ReportService, BaseService, CurrentRole) {
  11542. BaseService.scrollBackToTop();
  11543. // 获取当前用户是否为普通用户
  11544. CurrentRole.isUser({}, {}, function (data) {
  11545. $scope.isUser = data.isUser;
  11546. });
  11547. var loadData = function () {
  11548. MakeOrder.getItem({id: $stateParams.id}, function (data) {
  11549. $scope.order = data;
  11550. var sum = $scope.order.qty * $scope.order.price;
  11551. $scope.order.total = sum;
  11552. $scope.loading = false;
  11553. }, function (response) {
  11554. toaster.pop('error', '', response.data);
  11555. });
  11556. };
  11557. loadData();
  11558. // 获取回复记录
  11559. $scope.getReply = function (item) {
  11560. if (!item.replies) {
  11561. MakeOrder.getReply({orderId: item.id}, function (replies) {
  11562. item.replies = replies;
  11563. });
  11564. }
  11565. };
  11566. $scope.openDatePicker = function ($event, item, openParam) {
  11567. $event.preventDefault();
  11568. $event.stopPropagation();
  11569. item[openParam] = !item[openParam];
  11570. };
  11571. // 点击回复
  11572. $scope.onReplyClick = function (order, inverse) {
  11573. if (order.reply) {
  11574. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  11575. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  11576. return;
  11577. }
  11578. var reply = angular.copy(order.reply);
  11579. if (reply.delivery) {
  11580. if (typeof reply.delivery == 'object')
  11581. reply.delivery = reply.delivery.getTime();
  11582. } else {
  11583. reply.delivery = order.delivery;
  11584. }
  11585. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  11586. $scope.loading = true;
  11587. MakeOrder.reply({orderId: order.id}, reply, function () {
  11588. $scope.loading = false;
  11589. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  11590. loadData();
  11591. }, function (response) {
  11592. $scope.loading = false;
  11593. toaster.pop('error', '回复失败', response.data);
  11594. });
  11595. }
  11596. };
  11597. // 打开回复
  11598. $scope.openReply = function (order) {
  11599. if (!order.reply) {
  11600. order.reply = {
  11601. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  11602. delivery: order.delivery
  11603. }
  11604. }
  11605. order.$editing = true;
  11606. };
  11607. // 关闭回复
  11608. $scope.closeReply = function (order) {
  11609. order.$editing = false;
  11610. }
  11611. // 委外订单
  11612. $scope.print = function (order) {
  11613. MakeOrder.printCount({id: order.id}, {});//增加打印此次
  11614. ReportService.print(order.enUU, 'MAKE', 'where make$orders.ma_id =' + order.id);
  11615. };
  11616. }]);
  11617. /**
  11618. * 客户委外验收
  11619. */
  11620. app.controller('MakeAcceptCtrl', ['$scope', '$filter', 'MakeAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeAccept, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11621. BaseService.scrollBackToTop();
  11622. // 获取当前用户是否为普通用户
  11623. CurrentRole.isUser({}, {}, function (data) {
  11624. $scope.isUser = data.isUser;
  11625. });
  11626. $scope.active = 'all';
  11627. $scope.agreedText = '全部';
  11628. $scope.dateZoneText = '一个月内';
  11629. $scope.condition = {dateZone: 1};
  11630. /* 时间筛选初始化*/
  11631. var fromDate = new Date();
  11632. var toDate = new Date();
  11633. fromDate.setMonth(fromDate.getMonth() - 1);
  11634. fromDate.setHours(0, 0, 0, 0);
  11635. toDate.setHours(23, 59, 59, 999);
  11636. $scope.condition.dateFrom = fromDate;
  11637. $scope.condition.dateTo = toDate;
  11638. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11639. $scope.changeAgreed = function (agreed) {
  11640. $scope.condition.agreed = agreed;
  11641. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11642. $scope.condition.$agreedOpen = false;
  11643. };
  11644. $scope.changeDateZone = function (zone) {
  11645. $scope.condition.dateZone = zone;
  11646. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  11647. $scope.condition.$dateZoneOpen = false;
  11648. getDateCondition(zone, $scope.condition);
  11649. $scope.tableParams.page(1);
  11650. $scope.tableParams.reload();
  11651. };
  11652. $scope.setActive = function (state) {
  11653. if ($scope.active != state) {
  11654. $scope.active = state;
  11655. if ($scope.tableParams.page() == 1)
  11656. $scope.tableParams.reload();
  11657. else
  11658. $scope.tableParams.page(1);
  11659. }
  11660. };
  11661. var getService = function () {
  11662. return MakeAccept;
  11663. };
  11664. $scope.tableParams = new ngTableParams({
  11665. page: 1,
  11666. count: 20,
  11667. sorting: {
  11668. date: 'desc'
  11669. }
  11670. }, {
  11671. total: 0,
  11672. counts: [5, 10, 25, 50],
  11673. getData: function ($defer, params) {
  11674. $scope.loading = true;
  11675. var pageParams = params.url();
  11676. pageParams.searchFilter = {};
  11677. pageParams.searchFilter.keyword = $scope.keyword;
  11678. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11679. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11680. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11681. $scope.loading = false;
  11682. if (page) {
  11683. params.total(page.totalElement);
  11684. $defer.resolve(page.content);
  11685. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11686. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11687. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11688. }
  11689. }, function (response) {
  11690. $scope.loading = false;
  11691. toaster.pop('error', '数据加载失败', response.data);
  11692. });
  11693. }
  11694. });
  11695. $scope.openDatePicker = function ($event, item, openParam) {
  11696. $event.preventDefault();
  11697. $event.stopPropagation();
  11698. item[openParam] = !item[openParam];
  11699. };
  11700. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11701. $event.preventDefault();
  11702. $event.stopPropagation();
  11703. item[openParam] = !item[openParam];
  11704. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11705. $scope.tableParams.reload();
  11706. }
  11707. };
  11708. // 搜索框回车
  11709. $scope.onSearch = function () {
  11710. $scope.tableParams.page(1);
  11711. $scope.tableParams.reload();
  11712. };
  11713. // 选择查找日期
  11714. $scope.onDateCondition = function () {
  11715. $scope.tableParams.page(1);
  11716. $scope.tableParams.reload();
  11717. };
  11718. // 导出
  11719. $scope.exportXls = function () {
  11720. MakeAccept.exportXls({}, {}, function (data) {
  11721. if (data.success){
  11722. window.location.href = 'make/accept/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11723. }
  11724. }, function (response) {
  11725. toaster.pop('error', '数据加载失败', response.data);
  11726. });
  11727. }
  11728. }]);
  11729. /**
  11730. * 客户委外验退
  11731. */
  11732. app.controller('MakeReturnCtrl', ['$scope', '$filter', 'MakeReturn', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', 'CurrentRole', function ($scope, $filter, MakeReturn, ngTableParams, toaster, BaseService, Symbol, CurrentRole) {
  11733. BaseService.scrollBackToTop();
  11734. // 获取当前用户是否为普通用户
  11735. CurrentRole.isUser({}, {}, function (data) {
  11736. $scope.isUser = data.isUser;
  11737. });
  11738. $scope.active = 'all';
  11739. $scope.agreedText = '全部';
  11740. $scope.dateZoneText = '一个月内';
  11741. $scope.condition = {dateZone: 1};
  11742. /* 时间筛选初始化*/
  11743. var fromDate = new Date();
  11744. var toDate = new Date();
  11745. fromDate.setMonth(fromDate.getMonth() - 1);
  11746. fromDate.setHours(0, 0, 0, 0);
  11747. toDate.setHours(23, 59, 59, 999);
  11748. $scope.condition.dateFrom = fromDate;
  11749. $scope.condition.dateTo = toDate;
  11750. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  11751. $scope.changeAgreed = function (agreed) {
  11752. $scope.condition.agreed = agreed;
  11753. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11754. $scope.condition.$agreedOpen = false;
  11755. };
  11756. $scope.changeDateZone = function (zone) {
  11757. $scope.condition.dateZone = zone;
  11758. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11759. $scope.condition.$dateZoneOpen = false;
  11760. getDateCondition(zone, $scope.condition);
  11761. $scope.tableParams.page(1);
  11762. $scope.tableParams.reload();
  11763. };
  11764. $scope.setActive = function (state) {
  11765. if ($scope.active != state) {
  11766. $scope.active = state;
  11767. if ($scope.tableParams.page() == 1)
  11768. $scope.tableParams.reload();
  11769. else
  11770. $scope.tableParams.page(1);
  11771. }
  11772. };
  11773. var getService = function () {
  11774. return MakeReturn;
  11775. };
  11776. $scope.tableParams = new ngTableParams({
  11777. page: 1,
  11778. count: 20,
  11779. sorting: {
  11780. date: 'desc'
  11781. }
  11782. }, {
  11783. total: 0,
  11784. counts: [5, 10, 25, 50],
  11785. getData: function ($defer, params) {
  11786. $scope.loading = true;
  11787. var pageParams = params.url();
  11788. pageParams.searchFilter = {};
  11789. pageParams.searchFilter.keyword = $scope.keyword;
  11790. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  11791. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  11792. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11793. $scope.loading = false;
  11794. if (page) {
  11795. params.total(page.totalElement);
  11796. $defer.resolve(page.content);
  11797. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  11798. $scope.fromDateXls = angular.copy(pageParams.searchFilter.fromDate);//保存当前取值的关键词
  11799. $scope.endDateXls = angular.copy(pageParams.searchFilter.endDate);//保存当前取值的关键词
  11800. }
  11801. }, function (response) {
  11802. $scope.loading = false;
  11803. toaster.pop('error', '数据加载失败', response.data);
  11804. });
  11805. }
  11806. });
  11807. $scope.openDatePicker = function ($event, item, openParam) {
  11808. $event.preventDefault();
  11809. $event.stopPropagation();
  11810. item[openParam] = !item[openParam];
  11811. };
  11812. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11813. $event.preventDefault();
  11814. $event.stopPropagation();
  11815. item[openParam] = !item[openParam];
  11816. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11817. $scope.tableParams.reload();
  11818. }
  11819. };
  11820. // 搜索框回车
  11821. $scope.onSearch = function () {
  11822. $scope.tableParams.page(1);
  11823. $scope.tableParams.reload();
  11824. };
  11825. // 选择查找日期
  11826. $scope.onDateCondition = function () {
  11827. $scope.tableParams.page(1);
  11828. $scope.tableParams.reload();
  11829. };
  11830. // 导出
  11831. $scope.exportXls = function () {
  11832. MakeReturn.exportXls({}, {}, function (data) {
  11833. if (data.success){
  11834. window.location.href = 'make/return/xls?_state='+$scope.active+'&keyword='+($scope.keywordXls || "")+'&fromDate='+$scope.fromDateXls+'&endDate='+$scope.endDateXls;
  11835. }
  11836. }, function (response) {
  11837. toaster.pop('error', '数据加载失败', response.data);
  11838. });
  11839. }
  11840. }]);
  11841. /**
  11842. * 委外加工变更
  11843. */
  11844. app.controller('MakeChangeCtrl', ['$scope', '$filter', 'MakeChange', 'ngTableParams', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeChange, ngTableParams, toaster, BaseService, CurrentRole) {
  11845. BaseService.scrollBackToTop();
  11846. // 获取当前用户是否为普通用户
  11847. CurrentRole.isUser({}, {}, function (data) {
  11848. $scope.isUser = data.isUser;
  11849. });
  11850. $scope.active = 'all';
  11851. $scope.agreedText = '全部';
  11852. $scope.dateZoneText = '一个月内';
  11853. $scope.condition = {dateZone: 1};
  11854. /* 时间筛选初始化*/
  11855. var fromDate = new Date();
  11856. var toDate = new Date();
  11857. fromDate.setMonth(fromDate.getMonth() - 1);
  11858. fromDate.setHours(0, 0, 0, 0);
  11859. toDate.setHours(23, 59, 59, 999);
  11860. $scope.condition.dateFrom = fromDate;
  11861. $scope.condition.dateTo = toDate;
  11862. $scope.changeAgreed = function (agreed) {
  11863. $scope.condition.agreed = agreed;
  11864. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  11865. $scope.condition.$agreedOpen = false;
  11866. };
  11867. $scope.changeDateZone = function (zone) {
  11868. $scope.condition.dateZone = zone;
  11869. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  11870. $scope.condition.$dateZoneOpen = false;
  11871. getDateCondition(zone, $scope.condition);
  11872. $scope.tableParams.page(1);
  11873. $scope.tableParams.reload();
  11874. };
  11875. $scope.setActive = function (state) {
  11876. if ($scope.active != state) {
  11877. $scope.active = state;
  11878. if ($scope.tableParams.page() == 1)
  11879. $scope.tableParams.reload();
  11880. else
  11881. $scope.tableParams.page(1);
  11882. }
  11883. };
  11884. var getService = function () {
  11885. return MakeChange;
  11886. };
  11887. $scope.tableParams = new ngTableParams({
  11888. page: 1,
  11889. count: 20,
  11890. sorting: {
  11891. orderChangeDate: 'desc'
  11892. }
  11893. }, {
  11894. total: 0,
  11895. counts: [5, 10, 25, 50],
  11896. getData: function ($defer, params) {
  11897. $scope.loading = true;
  11898. var pageParams = params.url();
  11899. pageParams.searchFilter = {
  11900. keyword: $scope.keyword,
  11901. fromDate: getDateTime($scope.condition.dateFrom),
  11902. endDate: getDateTime($scope.condition.dateTo)
  11903. };
  11904. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  11905. $scope.loading = false;
  11906. if (page) {
  11907. params.total(page.totalElement);
  11908. $defer.resolve(page.content);
  11909. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  11910. }
  11911. }, function (response) {
  11912. $scope.loading = false;
  11913. toaster.pop('error', '数据加载失败', response.data);
  11914. });
  11915. }
  11916. });
  11917. $scope.openDatePicker = function ($event, item, openParam) {
  11918. $event.preventDefault();
  11919. $event.stopPropagation();
  11920. item[openParam] = !item[openParam];
  11921. };
  11922. $scope.openFilterDatePicker = function ($event, item, openParam) {
  11923. $event.preventDefault();
  11924. $event.stopPropagation();
  11925. item[openParam] = !item[openParam];
  11926. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  11927. $scope.tableParams.reload();
  11928. }
  11929. };
  11930. // 打开回复
  11931. $scope.openReply = function (change) {
  11932. change.$editing = true;
  11933. };
  11934. // 关闭回复
  11935. $scope.closeReply = function (change) {
  11936. change.$editing = false;
  11937. }
  11938. // 确定回复
  11939. $scope.onReplyClick = function (change) {
  11940. if (change.$agreed) {
  11941. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11942. $scope.loading = true;
  11943. MakeChange.reply({itemId: change.id}, reply, function () {
  11944. $scope.loading = false;
  11945. toaster.pop('info', '提示', '回复成功');
  11946. $scope.tableParams.reload();
  11947. }, function (response) {
  11948. $scope.loading = false;
  11949. toaster.pop('error', '回复失败', response.data);
  11950. });
  11951. }
  11952. };
  11953. // 搜索框回车
  11954. $scope.onSearch = function () {
  11955. $scope.tableParams.page(1);
  11956. $scope.tableParams.reload();
  11957. };
  11958. // 选择查找日期
  11959. $scope.onDateCondition = function () {
  11960. $scope.tableParams.page(1);
  11961. $scope.tableParams.reload();
  11962. };
  11963. // 导出
  11964. $scope.exportXls = function () {
  11965. MakeChange.exportXls({}, {}, function (data) {
  11966. if (data.success){
  11967. window.location.href = 'make/changes/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  11968. }
  11969. }, function (response) {
  11970. toaster.pop('error', '数据加载失败', response.data);
  11971. });
  11972. }
  11973. }]);
  11974. app.controller('MakeChangeDetailCtrl', ['$scope', '$stateParams', 'MakeChange', 'toaster', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeChange, toaster, BaseService, CurrentRole) {
  11975. BaseService.scrollBackToTop();
  11976. CurrentRole.isUser({}, {}, function (data) {
  11977. $scope.isUser = data.isUser;
  11978. });
  11979. var loadData = function () {
  11980. MakeChange.getItem({id: $stateParams.id}, function (data) {
  11981. $scope.change = data;
  11982. }, function (response) {
  11983. toaster.pop('error', '数据加载失败', response.data);
  11984. });
  11985. };
  11986. loadData();
  11987. $scope.openDatePicker = function ($event, item, openParam) {
  11988. $event.preventDefault();
  11989. $event.stopPropagation();
  11990. item[openParam] = !item[openParam];
  11991. };
  11992. $scope.onReplyClick = function (change) {
  11993. if (change.$agreed) {
  11994. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  11995. MakeChange.reply({itemId: change.id}, reply, function () {
  11996. toaster.pop('info', '提示', '回复成功');
  11997. loadData();
  11998. }, function (response) {
  11999. toaster.pop('error', '回复失败', response.data);
  12000. });
  12001. }
  12002. };
  12003. }]);
  12004. /**
  12005. * 委外加工
  12006. */
  12007. app.controller('MakeOutOrderCtrl', ['$scope', '$filter', 'MakeOutOrder', 'ngTableParams', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $filter, MakeOutOrder, ngTableParams, toaster, ReportService, BaseService, CurrentRole) {
  12008. BaseService.scrollBackToTop();
  12009. // 获取当前用户是否为普通用户
  12010. CurrentRole.isUser({}, {}, function (data) {
  12011. $scope.isUser = data.isUser;
  12012. });
  12013. $scope.active = 'all';
  12014. $scope.agreedText = '全部';
  12015. $scope.dateZoneText = '一个月内';
  12016. $scope.condition = {dateZone: 1};
  12017. /* 时间筛选初始化*/
  12018. var fromDate = new Date();
  12019. var toDate = new Date();
  12020. fromDate.setMonth(fromDate.getMonth() - 1);
  12021. fromDate.setHours(0, 0, 0, 0);
  12022. toDate.setHours(23, 59, 59, 999);
  12023. $scope.condition.dateFrom = fromDate;
  12024. $scope.condition.dateTo = toDate;
  12025. $scope.changeAgreed = function (agreed) {
  12026. $scope.condition.agreed = agreed;
  12027. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12028. $scope.condition.$agreedOpen = false;
  12029. };
  12030. $scope.changeDateZone = function (zone) {
  12031. $scope.condition.dateZone = zone;
  12032. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  12033. $scope.condition.$dateZoneOpen = false;
  12034. getDateCondition(zone, $scope.condition);
  12035. $scope.tableParams.page(1);
  12036. $scope.tableParams.reload();
  12037. };
  12038. $scope.setActive = function (state) {
  12039. if ($scope.active != state) {
  12040. $scope.active = state;
  12041. if ($scope.tableParams.page() == 1)
  12042. $scope.tableParams.reload();
  12043. else
  12044. $scope.tableParams.page(1);
  12045. }
  12046. };
  12047. var getService = function () {
  12048. return MakeOutOrder;
  12049. };
  12050. $scope.tableParams = new ngTableParams({
  12051. page: 1,
  12052. count: 20,
  12053. sorting: {
  12054. date: 'desc'
  12055. }
  12056. }, {
  12057. total: 0,
  12058. counts: [5, 10, 25, 50],
  12059. getData: function ($defer, params) {
  12060. $scope.loading = true;
  12061. var pageParams = params.url();
  12062. pageParams.searchFilter = {};
  12063. pageParams.searchFilter.keyword = $scope.keyword;
  12064. pageParams.searchFilter.fromDate = $scope.condition.dateFrom ? $scope.condition.dateFrom.getTime() : null;
  12065. pageParams.searchFilter.endDate = $scope.condition.dateTo ? $scope.condition.dateTo.getTime() : null;
  12066. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12067. $scope.loading = false;
  12068. if (page) {
  12069. params.total(page.totalElement);
  12070. $defer.resolve(page.content);
  12071. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
  12072. }
  12073. }, function (response) {
  12074. $scope.loading = false;
  12075. toaster.pop('error', '数据加载失败', response.data);
  12076. });
  12077. }
  12078. });
  12079. $scope.openDatePicker = function ($event, item, openParam) {
  12080. $event.preventDefault();
  12081. $event.stopPropagation();
  12082. item[openParam] = !item[openParam];
  12083. };
  12084. $scope.openFilterDatePicker = function ($event, item, openParam) {
  12085. $event.preventDefault();
  12086. $event.stopPropagation();
  12087. item[openParam] = !item[openParam];
  12088. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  12089. $scope.tableParams.reload();
  12090. }
  12091. };
  12092. // 获取回复记录
  12093. $scope.getReply = function (item) {
  12094. if (!item.replies) {
  12095. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  12096. item.replies = replies;
  12097. });
  12098. }
  12099. };
  12100. // 打开回复
  12101. $scope.openReply = function (change) {
  12102. change.$editing = true;
  12103. };
  12104. // 关闭回复
  12105. $scope.closeReply = function (change) {
  12106. change.$editing = false;
  12107. }
  12108. // 确定回复
  12109. $scope.onReplyClick = function (change) {
  12110. if (change.$agreed) {
  12111. var reply = {id: change.id, agreed: Number(change.$agreed), replyRemark: change.replyRemark};
  12112. $scope.loading = true;
  12113. MakeOutOrder.reply({itemId: change.id}, reply, function () {
  12114. $scope.loading = false;
  12115. toaster.pop('info', '提示', '回复成功');
  12116. $scope.tableParams.reload();
  12117. }, function (response) {
  12118. $scope.loading = false;
  12119. toaster.pop('error', '回复失败', response.data);
  12120. });
  12121. }
  12122. };
  12123. // 搜索框回车
  12124. $scope.onSearch = function () {
  12125. $scope.tableParams.page(1);
  12126. $scope.tableParams.reload();
  12127. };
  12128. // 选择查找日期
  12129. $scope.onDateCondition = function () {
  12130. $scope.tableParams.page(1);
  12131. $scope.tableParams.reload();
  12132. };
  12133. // 导出
  12134. $scope.exportXls = function () {
  12135. MakeOutOrder.exportXls({}, {}, function (data) {
  12136. if (data.success){
  12137. window.location.href = 'make/outorders/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  12138. }
  12139. }, function (response) {
  12140. toaster.pop('error', '数据加载失败', response.data);
  12141. });
  12142. }
  12143. }]);
  12144. /**
  12145. * 委外加工详细
  12146. */
  12147. app.controller('MakeOutOrderDetailCtrl', ['$scope', '$stateParams', 'MakeOutOrder', 'toaster', 'ReportService', 'BaseService', 'CurrentRole', function ($scope, $stateParams, MakeOutOrder, toaster, ReportService, BaseService, CurrentRole) {
  12148. BaseService.scrollBackToTop();
  12149. // 获取当前用户是否为普通用户
  12150. CurrentRole.isUser({}, {}, function (data) {
  12151. $scope.isUser = data.isUser;
  12152. });
  12153. var loadData = function () {
  12154. MakeOutOrder.getItem({id: $stateParams.id},{}, function (data) {
  12155. $scope.order = data;
  12156. var sum = $scope.order.qty * $scope.order.price;
  12157. $scope.order.total = sum;
  12158. $scope.loading = false;
  12159. }, function (response) {
  12160. toaster.pop('error', '提示', response.data);
  12161. });
  12162. };
  12163. loadData();
  12164. // 获取回复记录
  12165. $scope.getReply = function (item) {
  12166. if (!item.replies) {
  12167. MakeOutOrder.getReply({orderId: item.id}, function (replies) {
  12168. item.replies = replies;
  12169. });
  12170. }
  12171. };
  12172. $scope.openDatePicker = function ($event, item, openParam) {
  12173. $event.preventDefault();
  12174. $event.stopPropagation();
  12175. item[openParam] = !item[openParam];
  12176. };
  12177. // 点击回复
  12178. $scope.onReplyClick = function (order, inverse) {
  12179. if (order.reply) {
  12180. if (!order.reply.qty || order.reply.qty < 0 || order.reply.qty > order.qty) {
  12181. toaster.pop('warning', '提示', '请填写有效的回复数量!');
  12182. return;
  12183. }
  12184. var reply = angular.copy(order.reply);
  12185. if (reply.delivery) {
  12186. if (typeof reply.delivery == 'object')
  12187. reply.delivery = reply.delivery.getTime();
  12188. } else {
  12189. reply.delivery = order.delivery;
  12190. }
  12191. if (inverse && inverse == -1) reply.qty = -1 * reply.qty;// 取相反
  12192. $scope.loading = true;
  12193. MakeOutOrder.reply({orderId: order.id}, reply, function () {
  12194. $scope.loading = false;
  12195. toaster.pop('info', '提示', (inverse == -1 ? '撤销成功' : '回复成功'));
  12196. loadData();
  12197. }, function (response) {
  12198. $scope.loading = false;
  12199. toaster.pop('error', '回复失败', response.data);
  12200. });
  12201. }
  12202. };
  12203. // 打开回复
  12204. $scope.openReply = function (order) {
  12205. if (!order.reply) {
  12206. order.reply = {
  12207. qty: order.qty - (order.replyQty ? order.replyQty : 0),
  12208. delivery: order.delivery
  12209. }
  12210. }
  12211. order.$editing = true;
  12212. };
  12213. // 关闭回复
  12214. $scope.closeReply = function (order) {
  12215. order.$editing = false;
  12216. }
  12217. // 自己委外加工订单
  12218. $scope.print = function (order) {
  12219. MakeOutOrder.printCount({id: order.id}, {});//增加打印此次
  12220. ReportService.print(order.enUU, 'MAKE', 'where make$outorders.ma_id =' + order.id);
  12221. };
  12222. }]);
  12223. /**
  12224. * 计算时间差
  12225. */
  12226. app.filter('timespan', function () {
  12227. return function (time) {
  12228. if (time == null)
  12229. return '9999年';
  12230. var now = new Date().getTime(), span = time - now,
  12231. d = Math.ceil(span / 86400000), h = Math.ceil(span / 3600000),
  12232. m = Math.ceil(span / 60000);
  12233. if (span < 0)
  12234. return '1天';
  12235. if (d > 0)
  12236. return d + 1 + '天';
  12237. if (h > 0)
  12238. return h + '小时';
  12239. if (m > 0)
  12240. return m + '分钟';
  12241. return '0天';
  12242. };
  12243. });
  12244. /**
  12245. * 公共询价计算时间差
  12246. */
  12247. app.filter('datespan', function () {
  12248. return function (time) {
  12249. if (time == null) {
  12250. return '剩余9999年';
  12251. }
  12252. var now = new Date().getTime(), span = time - now,
  12253. d = Math.floor(span / 86400000), h = Math.floor(span / 3600000),
  12254. m = Math.floor(span / 60000);
  12255. if (d > 0) {
  12256. var day = d + 1;
  12257. return '剩余' + day + '天';
  12258. }
  12259. if (h > 0) {
  12260. return '<span class="text-inverse">剩余' + h + '小时</span>';
  12261. }
  12262. if (m > 0) {
  12263. return '<span class="text-inverse">剩余' + m + '分钟</span>';
  12264. }
  12265. return '已结束';
  12266. };
  12267. });
  12268. app.filter('firstchar', function () {
  12269. return function (str) {
  12270. if (str == null)
  12271. return null;
  12272. return str.substring(0, 1);
  12273. };
  12274. });
  12275. app.filter('summary', function () {
  12276. return function (data, field) {
  12277. var sum = 0;
  12278. if (data) {
  12279. angular.forEach(data, function (d) {
  12280. sum += d[field];
  12281. });
  12282. }
  12283. return sum;
  12284. };
  12285. });
  12286. /**
  12287. * 搜索框,回车触发
  12288. */
  12289. app.directive('ngSearch', ['$parse', function ($parse) {
  12290. return {
  12291. require: '?ngModel',
  12292. restrict: 'A',
  12293. link: function (scope, element, attrs, ngModel) {
  12294. var searchFn = $parse(attrs.ngSearch);
  12295. element.bind('keypress', function (event) {
  12296. if (event.keyCode == '13') {
  12297. event.preventDefault();
  12298. event.stopPropagation();
  12299. searchFn(scope, {$data: ngModel.$modelValue, $event: event});
  12300. }
  12301. });
  12302. }
  12303. };
  12304. }]);
  12305. /**
  12306. * 状态码 -> 描述
  12307. */
  12308. app.filter('status', function () {
  12309. return function (data) {
  12310. var statusConfig = {
  12311. '101': '已提交',
  12312. '102': '已审核',
  12313. '103': '未通过',
  12314. '200': '未回复',
  12315. '201': '已回复',
  12316. '313': '已激活',
  12317. '316': '已过账',
  12318. '311': '申请中',
  12319. '312': '未激活'
  12320. };
  12321. return statusConfig[data];
  12322. }
  12323. });
  12324. //弹出问题反馈模态框
  12325. app.controller('LeftCtrl', ['$scope', '$modal', 'AuthenticationService', function ($scope, $modal, AuthenticationService) {
  12326. //获取当前用户
  12327. AuthenticationService.getAuthentication().success(function (data) {
  12328. $scope.user = data;
  12329. });
  12330. $scope.showModal = function () {
  12331. var modalInstance = $modal.open({
  12332. animation: true,
  12333. templateUrl: 'static/tpl/serve/feedback.html',
  12334. controller: 'FeedbackCtrl',
  12335. resolve: {
  12336. user: function () {
  12337. return $scope.user;
  12338. } //传递当前用户到模态框Controller
  12339. }
  12340. });
  12341. modalInstance.result.then(function () {
  12342. }, function () {
  12343. });
  12344. }
  12345. }]);
  12346. /*
  12347. * 提交我的反馈
  12348. */
  12349. app.controller('FeedbackCtrl', ['$scope', '$modalInstance', 'FeedBackService', 'toaster', 'AuthenticationService', 'user', function ($scope, $modalInstance, FeedBackService, toaster, AuthenticationService, user) {
  12350. $scope.isPublic = 1; //默认公开
  12351. $scope.classId = 1; //默认类别
  12352. $scope.user = user;
  12353. $scope.ok = function () {
  12354. if (!$scope.user) { //用户未登录
  12355. $scope.uu = null;
  12356. } else { //用户已登录
  12357. $scope.uu = $scope.user.userUU;
  12358. }
  12359. //FeedBackService定义于common/service.js里,供不同页面的问题反馈功能使用
  12360. FeedBackService.feedBackQuestion({
  12361. classId: $scope.classId,
  12362. isPublic: $scope.isPublic,
  12363. title: $scope.title,
  12364. userUU: $scope.uu
  12365. }, {},
  12366. function (data) {
  12367. toaster.pop('success', '成功', '您的问题反馈成功!');
  12368. $scope.cancel();
  12369. }, function (response) {
  12370. toaster.pop('error', '错误', response.data);
  12371. });
  12372. }
  12373. $scope.cancel = function () {
  12374. $modalInstance.dismiss();
  12375. };
  12376. }]);
  12377. //“我的问题反馈”跳转控制
  12378. app.controller('RightCtrl', ['$scope', 'AuthenticationService', 'toaster', '$rootScope', function ($scope, AuthenticationService, toaster, $rootScope) {
  12379. $scope.myFeedback = function () {
  12380. AuthenticationService.getAuthentication().success(function (data) {
  12381. $scope.user = data;
  12382. if (!$scope.user) {
  12383. toaster.pop('warning', '提示', '您还未登录,请登录后再查看!');
  12384. return false;
  12385. } else {
  12386. window.location.href = "./serve#/question/myFeedback";
  12387. }
  12388. });
  12389. };
  12390. $scope.getSaleOrderCount = function (unread) {
  12391. if (unread != undefined) {
  12392. return unread.order + unread.change + unread.makeOrder;
  12393. }
  12394. };
  12395. $scope.getSaleInquiryCount = function (unread) {
  12396. if (unread != undefined) {
  12397. return unread.inquiry + unread.mould;
  12398. }
  12399. };
  12400. $scope.setActive = function (active) {
  12401. $rootScope.active = active;
  12402. }
  12403. }]);
  12404. //客户服务
  12405. app.controller('CustServeCtrl', ['$scope', 'Vendor', function ($scope, Vendor) {
  12406. Vendor.getServe(function (datas) {
  12407. $scope.vendors = datas;
  12408. // 自动跳转
  12409. if (datas && datas.length == 1)
  12410. $scope.redirect(datas[0]);
  12411. });
  12412. $scope.redirect = function (vendor) {
  12413. window.open('purc/vendor/serve/' + vendor.vendorEnterprise.uu);
  12414. };
  12415. }]);
  12416. /**
  12417. * 物料资料
  12418. */
  12419. 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) {
  12420. BaseService.scrollBackToTop();
  12421. var loadAccount = function () {
  12422. AccountEnterprise.get({}, function (data) {
  12423. $scope.loading = false;
  12424. $scope.enterprise = data;
  12425. $scope.saleStatus = $scope.enterprise.prodsale;
  12426. });
  12427. }
  12428. loadAccount();
  12429. $scope.active = 'all';
  12430. $scope.agreedText = '全部';
  12431. $scope.dateZoneText = '一个月内';
  12432. $scope.condition = {dateZone: 1};
  12433. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  12434. $scope.changeAgreed = function (agreed) {
  12435. $scope.condition.agreed = agreed;
  12436. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  12437. $scope.condition.$agreedOpen = false;
  12438. };
  12439. $scope.changeDateZone = function (zone) {
  12440. $scope.condition.dateZone = zone;
  12441. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  12442. $scope.condition.$dateZoneOpen = false;
  12443. getDateCondition(zone, $scope.condition);
  12444. $scope.tableParams.reload();
  12445. };
  12446. $scope.setActive = function (state) {
  12447. if ($scope.active != state) {
  12448. $scope.active = state;
  12449. if ($scope.tableParams.page() == 1)
  12450. $scope.tableParams.reload();
  12451. else
  12452. $scope.tableParams.page(1);
  12453. }
  12454. };
  12455. $scope.searchMethod = false;
  12456. var getService = function () {
  12457. return $scope.searchMethod ? GetProductInfo : GetProductInfoNewest;
  12458. };
  12459. $scope.tableParams = new ngTableParams({
  12460. page: 1,
  12461. count: 20,
  12462. sorting: {
  12463. id: 'desc',
  12464. }
  12465. }, {
  12466. total: 0,
  12467. counts: [5, 10, 25, 50],
  12468. getData: function ($defer, params) {
  12469. $scope.loading = true;
  12470. var pageParams = params.url();
  12471. pageParams.keyword = $scope.keyword;
  12472. pageParams.searchFilter = $scope.searchFilter;
  12473. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  12474. $scope.loading = false;
  12475. if (page) {
  12476. params.total(page.totalElement);
  12477. $defer.resolve(page.content);
  12478. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  12479. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  12480. }
  12481. }, function (response) {
  12482. $scope.loading = false;
  12483. toaster.pop('error', '数据加载失败', response.data);
  12484. });
  12485. }
  12486. });
  12487. // //设置单据已读
  12488. // var setOrdersRead = function () {
  12489. // var ids = [];
  12490. // GetProductInfo.setRead({}, ids, function (message) {
  12491. // });
  12492. // };
  12493. // setOrdersRead();
  12494. // 搜索框回车
  12495. $scope.onSearch = function (keyword) {
  12496. // 每次搜索重置获取数据方法
  12497. $scope.searchMethod = false;
  12498. if(keyword != null && keyword != '') {
  12499. $scope.searchMethod = true;
  12500. }
  12501. $scope.tableParams.page(1);
  12502. $scope.tableParams.reload();
  12503. };
  12504. //删除
  12505. $scope.deleteById = function (id) {
  12506. $scope.loading = true;
  12507. GetProductInfo.deleteById({}, id, function (data) {
  12508. if (data.error) {
  12509. toaster.pop("error", "提示", data.error);
  12510. } else {
  12511. toaster.pop("success", "提示", "删除成功");
  12512. $timeout(function () {
  12513. $scope.tableParams.reload();
  12514. }, 500);
  12515. }
  12516. $scope.loading = false;
  12517. }, function (response) {
  12518. $scope.loading = false;
  12519. toaster.pop("error", "删除失败", response.data);
  12520. });
  12521. };
  12522. $rootScope.isProductEdit = false;
  12523. // 编辑
  12524. $scope.isProductEdit = function () {
  12525. $rootScope.isProductEdit = true;
  12526. };
  12527. // 一键开启关闭
  12528. $scope.toggle = function (status) {
  12529. if ($scope.saleStatus == 0) {
  12530. $scope.saleStatus = 1;
  12531. } else {
  12532. $scope.saleStatus = 0;
  12533. }
  12534. $scope.loading = true;
  12535. GetProductInfo.toggle({status: status}, {}, function (data) {
  12536. $scope.loading = false;
  12537. toaster.pop('success', '提示', '操作成功');
  12538. loadAccount();
  12539. $scope.tableParams.reload();
  12540. }, function (response) {
  12541. $scope.loading = false;
  12542. toaster.pop('error', '提示', response.data);
  12543. })
  12544. }
  12545. var products = [];
  12546. $scope.checks = {
  12547. checked: false
  12548. };
  12549. // 全选框
  12550. $scope.checkAll = function () {
  12551. products = [];// 每次选择时先清空,防止重复
  12552. angular.forEach($scope.tableParams.data, function (product) {
  12553. if (product.cmpUuId == null) {
  12554. product.checked = $scope.checks.checked;
  12555. }
  12556. });
  12557. };
  12558. // 单选
  12559. $scope.checkOne = function (product) {
  12560. products = [];// 每次选择时先清空,防止重复
  12561. var result = true;
  12562. angular.forEach($scope.tableParams.data, function (item) {
  12563. if (item.$selected != true) {
  12564. result = false;
  12565. return;
  12566. }
  12567. });
  12568. $scope.checks.checked = result;
  12569. var checked = true;
  12570. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  12571. if (!message.checked) {
  12572. checked = false;
  12573. }
  12574. });
  12575. $scope.checks.checked = checked;
  12576. };
  12577. $scope.updateByBatch = function (updatetype) {
  12578. var modalInstance = $modal.open({
  12579. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  12580. controller: 'UpdateByBatchCtrl',
  12581. size: 'md',
  12582. resolve: {
  12583. updatetype: function () {
  12584. return updatetype;
  12585. },
  12586. active: function () {
  12587. return $scope.active;
  12588. },
  12589. type: function () {
  12590. return 'sale';
  12591. }
  12592. }
  12593. });
  12594. modalInstance.result.then(function (data) {
  12595. toaster.pop('success', '提示', data.success);
  12596. $scope.tableParams.reload();
  12597. }, function () {
  12598. });
  12599. }
  12600. // 一键匹配
  12601. $scope.matchall = function () {
  12602. $scope.loading = true;
  12603. $scope.type = "sale";
  12604. GetProductInfo.matchbytype({type: $scope.type}, {}, function (data) {
  12605. if (data.error) {
  12606. $scope.loading = false;
  12607. toaster.pop('error', '提示', data.error);
  12608. } else {
  12609. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  12610. window.location.href = "#/sale/productmatches";
  12611. }
  12612. }, function (response) {
  12613. $scope.loading = false;
  12614. toaster.pop('error', '提示', response.data);
  12615. });
  12616. }
  12617. $scope.exportXls = function () {
  12618. GetProductInfo.exportXls({},{}, function (data) {
  12619. if (data.success) {
  12620. window.location.href = 'product/baseInfo/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  12621. }
  12622. }, function (response) {
  12623. toaster.pop('error', '数据加载失败', response.data);
  12624. })
  12625. }
  12626. }]);
  12627. /**
  12628. * 批量修改
  12629. */
  12630. app.controller('UpdateByBatchCtrl', ['$scope', '$modalInstance', 'toaster', 'BaseService', 'updatetype', 'Products', 'active', 'type', function ($scope, $modalInstance, toaster, BaseService, updatetype, Products, active, type) {
  12631. $scope.updatetype = updatetype;
  12632. $scope.changed = false;
  12633. $scope.parameter = {
  12634. updatetype: updatetype,
  12635. standard: active,
  12636. type: type,
  12637. oldvalue: null,
  12638. newvalue: null
  12639. };
  12640. $scope.cancel = function () {
  12641. $modalInstance.dismiss();
  12642. }
  12643. if (updatetype === '品牌')
  12644. var loadData = function () {
  12645. Products.getBrands({parameter: $scope.parameter}, {}, function (data) {
  12646. $scope.products = data;
  12647. }, function (response) {
  12648. toaster.pop('error', '提示', response.data);
  12649. })
  12650. }
  12651. if (updatetype === '名称(类目)')
  12652. var loadData = function () {
  12653. Products.getTitles({parameter: $scope.parameter}, {}, function (data) {
  12654. $scope.products = data;
  12655. }, function (response) {
  12656. toaster.pop('error', '提示', response.data);
  12657. })
  12658. }
  12659. loadData();
  12660. $scope.okay = function (newvalue) {
  12661. if (newvalue == '' || newvalue == null) {
  12662. toaster.pop('error', '提示', '修改的值不能为空');
  12663. } else {
  12664. $scope.loading = true;
  12665. Products.alterByBatch({parameter: $scope.parameter}, {}, function (data) {
  12666. $scope.loading = false;
  12667. $modalInstance.close(data);
  12668. }, function (response) {
  12669. $scope.loading = false;
  12670. toaster.pop('error', '提示', response.data);
  12671. });
  12672. }
  12673. }
  12674. }]);
  12675. /**
  12676. * 物料批量上传
  12677. */
  12678. app.controller('UploadByBatchCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  12679. BaseService.scrollBackToTop();
  12680. $scope.$watch('myFiles', function () {
  12681. if ($scope.myFiles) {
  12682. var file = $scope.myFiles[0];
  12683. $scope.fileName = file.name;
  12684. }
  12685. })
  12686. // 通过excel批量上传物料
  12687. $scope.upload = function () {
  12688. $scope.loading = true;
  12689. if ($scope.myFiles) {
  12690. var file = $scope.myFiles[0];
  12691. if (file.name) {
  12692. $upload.upload({
  12693. url: 'product/baseInfo/edit/release/excel',
  12694. file: file,
  12695. method: 'POST'
  12696. }).success(function (data) {
  12697. $scope.loading = false;
  12698. if (data.error) {
  12699. toaster.pop('error', '提示', data.error);
  12700. }
  12701. $scope.result = data;
  12702. // $scope.products = $scope.result.products;
  12703. $scope.success = $scope.result.success;
  12704. $scope.total = $scope.result.total;
  12705. $scope.alters = $scope.result.alters;
  12706. $scope.infos = $scope.result.infos;
  12707. $scope.myFiles[0] = "";
  12708. $scope.fileName = "";
  12709. }).error(function (response) {
  12710. $scope.loading = false;
  12711. toaster.pop('error', response.data || response);
  12712. });
  12713. } else {
  12714. $scope.loading = false;
  12715. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  12716. }
  12717. } else {
  12718. $scope.loading = false;
  12719. }
  12720. };
  12721. // 查看范例
  12722. $scope.showImg = function () {
  12723. var src = "static/img/eg/uploadByBatch_prod_example.png", box = $('#image-box');
  12724. box.show();
  12725. box.find('img').attr('src', src);
  12726. box.find('a').click(function () {
  12727. box.hide();
  12728. });
  12729. box.dblclick(function () {
  12730. box.hide();
  12731. });
  12732. };
  12733. // 下载模板
  12734. $scope.download = function () {
  12735. window.location.href = 'product/baseInfo/upload/template';
  12736. };
  12737. }]);
  12738. /**
  12739. * 物料详情
  12740. */
  12741. 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) {
  12742. BaseService.scrollBackToTop();
  12743. // 录入人
  12744. AuthenticationService.getAuthentication().success(function (data) {
  12745. $scope.loading = false;
  12746. $scope.user = data;
  12747. });
  12748. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  12749. $scope.editstatus = false;
  12750. var loadData = function () {
  12751. GetProductInfo.getSaleProduct({id: $stateParams.id}, function (data) {
  12752. if (data.attachment) {
  12753. $scope.imgPreview = data.attachment;
  12754. $scope.previewShow = true;
  12755. }
  12756. $scope.prodInfo = data;
  12757. if ($scope.prodInfo.isbusiness == 0) {
  12758. $scope.editstatus = true;
  12759. }
  12760. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  12761. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  12762. $scope.matchresults = data;
  12763. }, function (response) {
  12764. toaster.pop('error', '提示', response.data);
  12765. });
  12766. }
  12767. $scope.loading = false;
  12768. }, function (response) {
  12769. $scope.loading = false;
  12770. toaster.pop('error', '数据加载失败', response.data);
  12771. });
  12772. };
  12773. loadData();
  12774. // 联想词 start
  12775. // 获取类目
  12776. $scope.getSimilarKinds = function (value) {
  12777. if (value) {
  12778. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  12779. return data.map(function (item) {
  12780. return item;
  12781. });
  12782. });
  12783. }
  12784. };
  12785. // 设置类目
  12786. $scope.onAssociateKindClick = function (kind, prodInfo) {
  12787. $scope.prodInfo.kind = kind.kindName;
  12788. }
  12789. // 设置名称
  12790. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  12791. $scope.prodInfo.title = kind.kindName;
  12792. }
  12793. $scope.getSimilarBrands = function (value) {
  12794. if (value) {
  12795. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  12796. return data.map(function (item) {
  12797. return item;
  12798. });
  12799. });
  12800. }
  12801. }
  12802. // 设置导入品牌
  12803. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  12804. $scope.prodInfo.brand = brand.brandName;
  12805. }
  12806. // 设置标准品牌
  12807. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  12808. $scope.prodInfo.pbranden = brand.brandName;
  12809. }
  12810. $scope.getSimilarComponents = function (value) {
  12811. if (value) {
  12812. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  12813. return data.map(function (item) {
  12814. return item;
  12815. });
  12816. });
  12817. }
  12818. }
  12819. // 设置标准型号
  12820. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  12821. $scope.prodInfo.pcmpcode = cmp.code;
  12822. }
  12823. // 设置导入的型号
  12824. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  12825. $scope.prodInfo.cmpCode = cmp.code;
  12826. }
  12827. // 联想词 end
  12828. //更新为标准器件
  12829. $scope.updateone = function (id) {
  12830. $scope.loading = true;
  12831. Products.updateone({id: id}, {}, function (data) {
  12832. if (data.success) {
  12833. toaster.pop('success', '提示', data.success);
  12834. window.location.reload();
  12835. }
  12836. $scope.loading = false;
  12837. }, function (response) {
  12838. toaster.pop('error', '提示', response.data);
  12839. });
  12840. }
  12841. // 选择类目
  12842. $scope.selectKind = function (cmpcode) {
  12843. if (cmpcode == null) {
  12844. $modal.open({
  12845. animation: true,
  12846. size: 'lg',
  12847. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  12848. controller: 'KindChooseCtrl',
  12849. }).result.then(function (data) {
  12850. $scope.kindId = data;
  12851. var modalInstance = $modal.open({
  12852. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  12853. controller: 'FindComponentCtrl',
  12854. size: 'lg',
  12855. resolve: {
  12856. KindId: function () {
  12857. return $scope.kindId;
  12858. }
  12859. }
  12860. });
  12861. modalInstance.result.then(function (data) {
  12862. $scope.prodInfo.cmpUuId = data.uuid;
  12863. $scope.prodInfo.pcmpcode = data.code;
  12864. $scope.prodInfo.pbranden = data.brand.nameEn;
  12865. $scope.prodInfo.pbrand = data.brand.nameCn;
  12866. }, function () {
  12867. });
  12868. }, function () {
  12869. });
  12870. }
  12871. };
  12872. $scope.isShow = true;
  12873. // 更新
  12874. $scope.update = function () {
  12875. $scope.prodInfo.$editing = true;
  12876. $scope.isShow = true;
  12877. };
  12878. // 取消
  12879. $scope.cancel = function () {
  12880. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  12881. $scope.prodInfo = data;
  12882. $scope.prodInfo.$editing = false;
  12883. $scope.isShow = false;
  12884. $scope.loading = false;
  12885. });
  12886. };
  12887. // 删除
  12888. $scope.clearfile = function () {
  12889. $scope.prodInfo.attachment = null;
  12890. $scope.myFiles = null;
  12891. $scope.previewShow = false;
  12892. }
  12893. //删除
  12894. $scope.deleteById = function (id) {
  12895. $scope.loading = true;
  12896. GetProductInfo.deleteById({}, id, function (data) {
  12897. $scope.loading = false;
  12898. if (data.error) {
  12899. toaster.pop("error", "提示", data.error);
  12900. } else {
  12901. toaster.pop("success", "提示", "删除成功");
  12902. window.location.href = "#/sale/prodList";
  12903. }
  12904. }, function (response) {
  12905. $scope.loading = false;
  12906. toaster.pop("error", "删除失败", response.data);
  12907. });
  12908. };
  12909. $scope.submit = function (prodInfo) {
  12910. $scope.prodInfo.isSale = 1;
  12911. $scope.loading = true;
  12912. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  12913. $upload.upload({
  12914. url: 'product/baseInfo/edit/updateProdInfo',
  12915. file: file,
  12916. method: 'POST',
  12917. data: {
  12918. prodInfo: $scope.prodInfo
  12919. },
  12920. }).success(function (data) {
  12921. $scope.loading = false;
  12922. if (data.success) {
  12923. toaster.pop('success', '提示', data.success);
  12924. $rootScope.isProductEdit = false;
  12925. loadData();
  12926. // window.location.href="#/sale/prodList";
  12927. }
  12928. if (data.error) {
  12929. toaster.pop('error', '提示', data.error);
  12930. }
  12931. }).error(function (data, status) {
  12932. $scope.loading = false;
  12933. $scope.loadingShow = false;
  12934. if (status == 403){
  12935. toaster.pop('error', '操作失败', data);
  12936. } else {
  12937. toaster.pop('error', '操作失败', data.error);
  12938. }
  12939. });
  12940. }
  12941. $scope.previewShow = false;
  12942. $scope.pdfShow = false;
  12943. $scope.noneFileShow = true;
  12944. $scope.$watch('myFiles', function () {
  12945. if ($scope.myFiles) {
  12946. $scope.noneFileShow = false;
  12947. var file = $scope.myFiles[0];
  12948. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  12949. $scope.pdfShow = true;
  12950. $scope.previewShow = false;
  12951. $scope.imgPreviewName = file.name;
  12952. } else {
  12953. if (typeof(Worker) !== "undefined") {//支持HTML5
  12954. $scope.imgPreview = getObjectURL(file);
  12955. $scope.imgPreviewName = file.name;
  12956. } else {//不支持HTML5
  12957. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  12958. $scope.imgPreviewName = file.name;
  12959. }
  12960. $scope.previewShow = true;
  12961. $scope.pdfShow = false;
  12962. }
  12963. } else {
  12964. $scope.noneFileShow = true;
  12965. $scope.previewShow = false;
  12966. $scope.pdfShow = false;
  12967. }
  12968. });
  12969. //建立一个可存取到该file的url
  12970. var imgurl = null;
  12971. var getObjectURL = function (file) {
  12972. var url = null;
  12973. if (window.createObjectURL != undefined) { // basic
  12974. url = window.createObjectURL(file);
  12975. } else if (window.URL != undefined) { // mozilla(firefox)
  12976. url = window.URL.createObjectURL(file);
  12977. } else if (window.webkitURL != undefined) { // webkit or chrome
  12978. url = window.webkitURL.createObjectURL(file);
  12979. }
  12980. imgurl = url;
  12981. return url;
  12982. };
  12983. // 查看范例
  12984. $scope.showImg = function () {
  12985. if ($scope.prodInfo.attachment) {
  12986. $scope.imgPreview = $scope.prodInfo.attachment;
  12987. var src = $scope.prodInfo.attachment, box = $('#image-box');
  12988. box.show();
  12989. box.find('img').attr('src', src);
  12990. box.find('a').click(function () {
  12991. box.hide();
  12992. });
  12993. box.dblclick(function () {
  12994. box.hide();
  12995. });
  12996. $scope.previewShow = true;
  12997. } else if (imgurl != null) {
  12998. var src = imgurl, box = $('#image-box');
  12999. box.show();
  13000. box.find('img').attr('src', src);
  13001. box.find('a').click(function () {
  13002. box.hide();
  13003. });
  13004. box.dblclick(function () {
  13005. box.hide();
  13006. });
  13007. }
  13008. };
  13009. }]);
  13010. /**
  13011. * 新增物料(销售)
  13012. */
  13013. 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) {
  13014. BaseService.scrollBackToTop();
  13015. // 录入人
  13016. AuthenticationService.getAuthentication().success(function (data) {
  13017. $scope.loading = false;
  13018. $scope.user = data;
  13019. });
  13020. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  13021. $scope.prodInfo = {};
  13022. // 选择类目
  13023. $scope.selectKind = function () {
  13024. $modal.open({
  13025. animation: true,
  13026. size: 'lg',
  13027. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  13028. controller: 'KindChooseCtrl',
  13029. }).result.then(function (data) {
  13030. $scope.kindId = data;
  13031. var modalInstance = $modal.open({
  13032. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  13033. controller: 'FindComponentCtrl',
  13034. size: 'lg',
  13035. resolve: {
  13036. KindId: function () {
  13037. return $scope.kindId;
  13038. }
  13039. }
  13040. });
  13041. modalInstance.result.then(function (data) {
  13042. $scope.prodInfo.cmpUuId = data.uuid;
  13043. $scope.prodInfo.pcmpcode = data.code;
  13044. $scope.prodInfo.pbranden = data.brand.nameEn;
  13045. $scope.prodInfo.pbrand = data.brand.nameCn;
  13046. }, function () {
  13047. });
  13048. }, function () {
  13049. });
  13050. };
  13051. // 联想词 start
  13052. // 获取类目
  13053. $scope.getSimilarKinds = function (value) {
  13054. if (value) {
  13055. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  13056. return data.map(function (item) {
  13057. return item;
  13058. });
  13059. });
  13060. }
  13061. };
  13062. $scope.onAssociateKindClick = function (kind, prodInfo) {
  13063. $scope.prodInfo.title = kind.kindName;
  13064. }
  13065. $scope.getSimilarBrands = function (value) {
  13066. if (value) {
  13067. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  13068. return data.map(function (item) {
  13069. return item;
  13070. });
  13071. });
  13072. }
  13073. }
  13074. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  13075. $scope.prodInfo.brand = brand.brandName;
  13076. }
  13077. $scope.getSimilarComponents = function (value) {
  13078. if (value) {
  13079. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  13080. return data.map(function (item) {
  13081. return item;
  13082. });
  13083. });
  13084. }
  13085. }
  13086. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  13087. $scope.prodInfo.cmpCode = cmp.code;
  13088. }
  13089. // 联想词 end
  13090. // 删除
  13091. $scope.clearfile = function () {
  13092. $scope.myFiles = null;
  13093. $scope.previewShow = false;
  13094. }
  13095. //提交
  13096. $scope.submit = function (prodInfo) {
  13097. $scope.loading = true;
  13098. $scope.prodInfo.isSale = 1;
  13099. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  13100. $upload.upload({
  13101. url: 'product/baseInfo/edit/addNewProduct',
  13102. file: file,
  13103. method: 'POST',
  13104. data: {
  13105. prodInfo: prodInfo
  13106. },
  13107. }).success(function (data) {
  13108. $scope.loading = false;
  13109. if (data.success) {
  13110. toaster.pop('success', '提示', '产品添加成功');
  13111. $timeout(function () {
  13112. //提交后跳转到详情页面,防止重复提交
  13113. window.location.href = "#/sale/prodList/" + data.id;
  13114. // window.location.href="#/sale/prodList";
  13115. }, 500);
  13116. }
  13117. if (data.error) {
  13118. toaster.pop('error', '提示', data.error);
  13119. $timeout(function () {
  13120. //提交后跳转到详情页面,防止重复提交
  13121. window.location.href = "#/sale/prodList/" + data.id;
  13122. // window.location.href="#/sale/prodList";
  13123. }, 500);
  13124. }
  13125. }).error(function (data, status) {
  13126. $scope.loading = false;
  13127. $scope.loadingShow = false;
  13128. if (status == 403) {
  13129. toaster.pop('error', '操作失败', data);
  13130. } else {
  13131. toaster.pop('error', '操作失败', data.error);
  13132. }
  13133. });
  13134. };
  13135. $scope.previewShow = false;
  13136. $scope.pdfShow = false;
  13137. $scope.noneFileShow = true;
  13138. $scope.$watch('myFiles', function () {
  13139. if ($scope.myFiles) {
  13140. $scope.noneFileShow = false;
  13141. var file = $scope.myFiles[0];
  13142. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  13143. $scope.pdfShow = true;
  13144. $scope.previewShow = false;
  13145. $scope.imgPreviewName = file.name;
  13146. } else {
  13147. if (typeof(Worker) !== "undefined") {//支持HTML5
  13148. $scope.imgPreview = getObjectURL(file);
  13149. $scope.imgPreviewName = file.name;
  13150. } else {//不支持HTML5
  13151. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  13152. $scope.imgPreviewName = file.name;
  13153. }
  13154. $scope.previewShow = true;
  13155. $scope.pdfShow = false;
  13156. }
  13157. } else {
  13158. $scope.noneFileShow = true;
  13159. $scope.previewShow = false;
  13160. $scope.pdfShow = false;
  13161. }
  13162. });
  13163. //建立一个可存取到该file的url
  13164. var imgUrl = null
  13165. var getObjectURL = function (file) {
  13166. var url = null;
  13167. if (window.createObjectURL != undefined) { // basic
  13168. url = window.createObjectURL(file);
  13169. } else if (window.URL != undefined) { // mozilla(firefox)
  13170. url = window.URL.createObjectURL(file);
  13171. } else if (window.webkitURL != undefined) { // webkit or chrome
  13172. url = window.webkitURL.createObjectURL(file);
  13173. }
  13174. imgUrl = url;
  13175. return url;
  13176. };
  13177. // 查看范例
  13178. $scope.showImg = function () {
  13179. var src = imgUrl, box = $('#image-box');
  13180. box.show();
  13181. box.find('img').attr('src', src);
  13182. box.find('a').click(function () {
  13183. box.hide();
  13184. });
  13185. box.dblclick(function () {
  13186. box.hide();
  13187. });
  13188. };
  13189. // 取消
  13190. $scope.cancel = function () {
  13191. $scope.prodInfo = angular.copy($scope.prodInfo);
  13192. };
  13193. }]);
  13194. /**
  13195. * 类目选择模态框
  13196. */
  13197. app.controller('KindChooseCtrl', ['$scope', 'KindAPI', 'toaster', '$modalInstance', '$modal', function ($scope, KindAPI, toaster, $modalInstance, $modal) {
  13198. $scope.kindId = null;
  13199. $scope.kinds = [[], [], [], []];
  13200. // 获取子类目
  13201. var getChildren = function (pid, deep) {
  13202. KindAPI.getChildren({parentId: pid}, function (data) {
  13203. $scope.kinds[deep] = data;
  13204. }, function (response) {
  13205. toaster.pop('error', '获取子类目失败', response.data);
  13206. });
  13207. };
  13208. // 改变节点选中状态
  13209. var changeStatus = function (item, deep) {
  13210. var kindId = null, level = 0;
  13211. angular.forEach($scope.kinds, function (ks, i) {
  13212. if (i > deep) {
  13213. $scope.kinds[i] = [];
  13214. } else {
  13215. angular.forEach(ks, function (k, j) {
  13216. if (i == deep) {
  13217. if (k.id == item.id) {
  13218. $scope.kinds[i][j].$active = true;
  13219. kindId = k.id;
  13220. } else {
  13221. k.$active = null;
  13222. }
  13223. }
  13224. });
  13225. }
  13226. });
  13227. // 选择的节点
  13228. $scope.kindId = kindId;
  13229. $scope.active = item;
  13230. // 当前可操作的层级
  13231. if (deep < 3) {
  13232. $scope.activeDeep = deep + 1;
  13233. }
  13234. };
  13235. // 节点点击后获取子类目,节点被选中
  13236. $scope.onItemClick = function (item, deep) {
  13237. changeStatus(item, deep);
  13238. if (!item.isLeaf) {
  13239. getChildren(item.id, deep + 1);
  13240. }
  13241. };
  13242. // 重新加载数据
  13243. function reload(deep) {
  13244. var pid;
  13245. if (deep) {
  13246. pid = $scope.actives[deep - 1].id;
  13247. } else {
  13248. pid = 0;
  13249. deep = 0;
  13250. }
  13251. getChildren(pid, deep);
  13252. }
  13253. // 初始加载数据,获取第一层的类目
  13254. if ($scope.actives) {
  13255. angular.forEach($scope.actives, function (v, k) {
  13256. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  13257. $scope.kinds[k] = data;
  13258. angular.forEach($scope.kinds[k], function (kind, i) {
  13259. if (kind.id == v.id) {
  13260. $scope.kinds[k][i].$active = true;
  13261. $scope.actives[k] = $scope.kinds[k][i];
  13262. }
  13263. })
  13264. }, function (response) {
  13265. toaster.pop('error', '获取子类目失败', response.data);
  13266. });
  13267. });
  13268. } else {
  13269. reload();
  13270. }
  13271. // 取消
  13272. $scope.cancel = function () {
  13273. $modalInstance.dismiss();
  13274. };
  13275. // 确认选择
  13276. $scope.check = function () {
  13277. $modalInstance.close($scope.kindId);
  13278. };
  13279. }]);
  13280. /**
  13281. * 器件筛选
  13282. */
  13283. app.controller('FindComponentCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'ComponentActive', 'KindId', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, ComponentActive, KindId) {
  13284. //状态
  13285. $scope.setActive = function (state) {
  13286. if ($scope.active != state) {
  13287. $scope.active = state;
  13288. if ($scope.tableParams.page() == 1)
  13289. $scope.tableParams.reload();
  13290. else
  13291. $scope.tableParams.page(1);
  13292. }
  13293. };
  13294. $scope.tableParams = new ngTableParams({
  13295. page: 1,
  13296. count: 20
  13297. }, {
  13298. total: 0,
  13299. counts: [5, 10, 25, 50],
  13300. getData: function ($defer, params) {
  13301. $scope.loading = true;
  13302. var pageParams = params.url();
  13303. pageParams.keyword = $scope.keyword;
  13304. pageParams.kindId = KindId;
  13305. ComponentActive.getComponentsByKindid(BaseService.parseParams(pageParams), function (page) {
  13306. $scope.loading = false;
  13307. if (page) {
  13308. params.total(page.totalElement);
  13309. $defer.resolve(page.content);
  13310. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  13311. }
  13312. }, function (response) {
  13313. $scope.loading = false;
  13314. toaster.pop('error', '数据加载失败', response.data);
  13315. });
  13316. }
  13317. });
  13318. // 取消
  13319. $scope.cancel = function () {
  13320. $modalInstance.dismiss();
  13321. };
  13322. // 选择
  13323. $scope.check = function (data) {
  13324. $modalInstance.close(data);
  13325. };
  13326. // 搜索框回车
  13327. $scope.onSearch = function () {
  13328. $scope.tableParams.page(1);
  13329. $scope.tableParams.reload();
  13330. };
  13331. }]);
  13332. /**
  13333. * 企业列表
  13334. */
  13335. app.controller('EnterpriseListCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope) {
  13336. BaseService.scrollBackToTop();
  13337. $scope.active = 'all';
  13338. $scope.agreedText = '全部';
  13339. $scope.dateZoneText = '一个月内';
  13340. $scope.condition = {dateZone: 1};
  13341. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  13342. $scope.changeAgreed = function (agreed) {
  13343. $scope.condition.agreed = agreed;
  13344. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  13345. $scope.condition.$agreedOpen = false;
  13346. };
  13347. $scope.changeDateZone = function (zone) {
  13348. $scope.condition.dateZone = zone;
  13349. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  13350. $scope.condition.$dateZoneOpen = false;
  13351. getDateCondition(zone, $scope.condition);
  13352. $scope.tableParams.reload();
  13353. };
  13354. $scope.setActive = function (state) {
  13355. if ($scope.active != state) {
  13356. $scope.active = state;
  13357. if ($scope.tableParams.page() == 1)
  13358. $scope.tableParams.reload();
  13359. else
  13360. $scope.tableParams.page(1);
  13361. }
  13362. };
  13363. var getService = function () {
  13364. return getAccountUserSpace;
  13365. };
  13366. $scope.tableParams = new ngTableParams({
  13367. page: 1,
  13368. count: 20,
  13369. sorting: {}
  13370. }, {
  13371. total: 0,
  13372. counts: [5, 10, 25, 50],
  13373. getData: function ($defer, params) {
  13374. $scope.loading = true;
  13375. var pageParams = params.url();
  13376. pageParams.keyword = $scope.keyword;
  13377. $scope.tip = $scope.keyword;
  13378. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  13379. $scope.loading = false;
  13380. if (page) {
  13381. params.total(page.totalElement);
  13382. $defer.resolve(page.content);
  13383. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  13384. }
  13385. }, function (response) {
  13386. $scope.loading = false;
  13387. toaster.pop('error', '数据加载失败', response.data);
  13388. });
  13389. }
  13390. });
  13391. // 搜索框回车
  13392. $scope.onSearch = function () {
  13393. $scope.tableParams.page(1);
  13394. $scope.tableParams.reload();
  13395. };
  13396. // 添加合作关系
  13397. $scope.addPartner = function (name, businessCode) {
  13398. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  13399. if (data.success) {
  13400. toaster.pop("success", '添加成功', data.success);
  13401. $scope.tableParams.reload();
  13402. }
  13403. if (data.error) {
  13404. toaster.pop("error", '添加失败', data.error);
  13405. }
  13406. }, function (response) {
  13407. toaster.pop('error', '失败', response.data);
  13408. });
  13409. }
  13410. $scope.status = 'enList';
  13411. }]);
  13412. /**
  13413. * 新增采购单
  13414. */
  13415. app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', 'recentPrice',
  13416. function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token, recentPrice) {
  13417. BaseService.scrollBackToTop();
  13418. // 每次进入时先清除掉rootScope下的venduu
  13419. $rootScope.venduu = null;
  13420. // 获取收货地址列表
  13421. ShipAddress.shipAddList({}, function (data) {
  13422. $scope.ships = data;
  13423. $scope.order.shipadd = $scope.ships[0];
  13424. });
  13425. // 获取地址信息
  13426. $http.get('resources/citydata/city.json', {
  13427. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  13428. }).then(function (response) {
  13429. $scope.provinces = response.data;
  13430. });
  13431. var getToken = function() {
  13432. if($scope.token == null) {
  13433. token.info({userType: 'purcorder'}, {}, function(data) {
  13434. $scope.token = data.token;
  13435. }, function(response) {
  13436. toaster.pop('error', '提示', response.data);
  13437. });
  13438. }
  13439. }
  13440. getToken();
  13441. $scope.order = {
  13442. date: new Date(),
  13443. vend: {
  13444. uu: '',
  13445. },
  13446. vendUser: {},
  13447. code: $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  13448. orderItems: {
  13449. product: {},
  13450. },
  13451. rate: 17
  13452. };
  13453. //商品信息
  13454. $scope.order.orderItems = [];
  13455. var item = {
  13456. code: null,
  13457. title: null,
  13458. spec: null,
  13459. unit: null,
  13460. qty: null,
  13461. price: null,
  13462. remark: null,
  13463. delivery: null,
  13464. prid: null,
  13465. taxrate: null
  13466. };
  13467. if ($rootScope.businessCode) {
  13468. VendorInfo.getVendorInfo({businessCode: $rootScope.businessCode}, {}, function (data) {
  13469. $scope.id = data.id;
  13470. $scope.order.vend.enName = data.vendorEnterprise.enName;
  13471. $scope.order.vend.enAddress = data.vendorEnterprise.enAddress;
  13472. $scope.order.vend.uu = data.vendorEnterprise.uu;
  13473. $scope.order.paymethods = data.paymethod;
  13474. $rootScope.venduu = data.vendorEnterprise.uu;
  13475. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13476. $scope.contacts = data;
  13477. $scope.order.vendor = $scope.contacts[0];
  13478. });
  13479. }, function (response) {
  13480. });
  13481. }
  13482. ;
  13483. // 查找供应商
  13484. $scope.dbfindVend = function () {
  13485. var modalInstance = $modal.open({
  13486. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  13487. controller: 'DbfindVendorInfoCtrl',
  13488. size: 'lg',
  13489. resolve: {
  13490. orderItems: function () {
  13491. return $scope.order.orderItems;
  13492. }
  13493. }
  13494. });
  13495. modalInstance.result.then(function (data) {
  13496. $rootScope.venduu = data.vendorEnterprise.uu;
  13497. $scope.id = data.id;
  13498. $scope.order.vend = data.vendorEnterprise;
  13499. $scope.order.vend.enName = data.vendorEnterprise.enName;
  13500. $scope.order.vendUser = data.vendorUser;
  13501. $scope.order.payments = data.paymethod;
  13502. $scope.order.orderItems = [];
  13503. var item = {
  13504. code: null,
  13505. title: null,
  13506. spec: null,
  13507. unit: null,
  13508. qty: null,
  13509. price: null,
  13510. remark: null,
  13511. delivery: null,
  13512. taxrate: null
  13513. };
  13514. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13515. $scope.contacts = data;
  13516. $scope.order.vendor = $scope.contacts[0];
  13517. });
  13518. }, function () {
  13519. });
  13520. };
  13521. // 联想词 start
  13522. // 获取供应商
  13523. $scope.getSimilarVendors = function (value) {
  13524. if (value) {
  13525. return Vendor.getSimilarVendors({keyword: value}).$promise.then(function (data) {
  13526. return data.map(function (item) {
  13527. return item;
  13528. });
  13529. });
  13530. }
  13531. };
  13532. $scope.onAssociateCmpClick = function (vendor, order) {
  13533. $scope.order.vend.uu = vendor.venduu;
  13534. $scope.id = vendor.id;
  13535. $scope.order.payments = vendor.paymethod;
  13536. $rootScope.venduu = $scope.order.vend.uu;
  13537. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13538. $scope.contacts = data;
  13539. $scope.order.vendor = $scope.contacts[0];
  13540. });
  13541. }
  13542. // 联想词 end
  13543. // $scope.order.orderItems.push(item);
  13544. if ($rootScope.prodId) {
  13545. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  13546. item.code = data.code;
  13547. item.title = data.title;
  13548. item.spec = data.spec;
  13549. item.unit = data.unit;
  13550. item.id = data.id;
  13551. $scope.order.orderItems.push(item);
  13552. $rootScope.prodId = null;// 清除掉prodId
  13553. }, function (response) {
  13554. });
  13555. }
  13556. //增加商品
  13557. $scope.addProduct = function (index) {
  13558. if ($scope.order.orderItems[index].code == null) {
  13559. toaster.pop('info', '提示', '请先选择商品');
  13560. } else {
  13561. $scope.order.orderItems.push({
  13562. code: null,
  13563. title: null,
  13564. spec: null,
  13565. unit: null,
  13566. qty: null,
  13567. price: null,
  13568. remark: null,
  13569. delivery: null,
  13570. $endDateOpen: false,
  13571. taxrate: $scope.order.rate,
  13572. prodsource: 'seller'
  13573. });
  13574. }
  13575. };
  13576. //删除商品
  13577. $scope.deleteProduct = function (index) {
  13578. $scope.order.orderItems.splice(index, 1);
  13579. };
  13580. // 搜索框回车
  13581. $scope.onSearch = function (keyword) {
  13582. $scope.keyword = keyword;
  13583. $scope.tableParams.page(1);
  13584. $scope.tableParams.reload();
  13585. };
  13586. $scope.tableParams = new ngTableParams({
  13587. page: 1,
  13588. count: 20
  13589. }, {
  13590. total: 0,
  13591. counts: [5, 10, 25, 50],
  13592. getData: function ($defer, params) {
  13593. $scope.loading = true;
  13594. var pageParams = params.url();
  13595. pageParams.keyword = $scope.keyword;
  13596. $scope.tip = $scope.keyword;
  13597. pageParams.vendUU = $scope.order.vend.uu;
  13598. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  13599. $scope.loading = false;
  13600. if (page) {
  13601. params.total(page.totalElement);
  13602. $scope.total = page.totalElement;
  13603. $defer.resolve(page.content);
  13604. }
  13605. }, function (response) {
  13606. $scope.loading = false;
  13607. toaster.pop('error', '数据加载失败', response.data);
  13608. });
  13609. }
  13610. });
  13611. // 选择
  13612. $scope.check = function (data) {
  13613. var price = null;
  13614. if (data.id) {
  13615. recentPrice.agreed({prId: data.id}, {}, function(response) {
  13616. price = response.price;
  13617. $scope.order.orderItems.push({
  13618. code: data.code,
  13619. title: data.title,
  13620. spec: data.spec,
  13621. unit: data.unit,
  13622. qty: null,
  13623. price: price,
  13624. remark: null,
  13625. delivery: null,
  13626. prid: data.id,
  13627. taxrate: $scope.order.rate,
  13628. prodsource: 'seller',
  13629. });
  13630. });
  13631. }
  13632. };
  13633. // 导入商品信息
  13634. $scope.uplodaByBatch = function () {
  13635. var modalInstance = $modal.open({
  13636. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  13637. controller: 'PurcUploadByBatchCtrl',
  13638. size: 'lg',
  13639. resolve: {}
  13640. });
  13641. modalInstance.result.then(function (data) {
  13642. angular.forEach(data, function (prod) {
  13643. $scope.order.orderItems.push({
  13644. code: prod.code,
  13645. title: prod.title,
  13646. unit: 'PCS',
  13647. spec: prod.spec,
  13648. qty: prod.amount,
  13649. price: prod.price,
  13650. remark: prod.remark,
  13651. delivery: prod.date,
  13652. prid: prod.id,
  13653. taxrate: prod.rate,
  13654. prodsource: 'purchaser'
  13655. });
  13656. })
  13657. }, function () {
  13658. });
  13659. };
  13660. // 监听venduu发生变化,重新加载物料信息
  13661. $scope.$watch('order.vend.uu', function (n, o) {
  13662. if (n == o) {
  13663. return;
  13664. } else {
  13665. $scope.tableParams.page(1);
  13666. $scope.tableParams.reload();
  13667. }
  13668. }, true);
  13669. $scope.getMinDate = function (item) {
  13670. return $filter('date')(new Date, 'yyyy-MM-dd');
  13671. };
  13672. $scope.openDatePicker = function ($event, openParam, index) {
  13673. $event.preventDefault();
  13674. $event.stopPropagation();
  13675. $scope.order.orderItems[index].$endDateOpen = !openParam;
  13676. };
  13677. // 添加到购物车
  13678. $scope.addToCart = function (order) {
  13679. $scope.loading = true;
  13680. $scope.order.status = 311;
  13681. $scope.order.vendusertel = order.vendor.tel;
  13682. $scope.order.venduser = order.vendor.venduser;
  13683. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13684. $scope.order.vendUU = $scope.order.vend.uu;
  13685. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13686. if ($scope.order.date instanceof Date) {
  13687. $scope.order.date = $scope.order.date.getTime();
  13688. }
  13689. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13690. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13691. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13692. }
  13693. if ($scope.order.currency != 'RMB') {
  13694. $scope.order.orderItems[i].rate = 0;
  13695. }
  13696. }
  13697. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13698. $scope.loading = false;
  13699. toaster.pop('success', '成功', '保存成功');
  13700. window.location.hash = '#/purc/cart/' + data.id;
  13701. $window.location.reload();
  13702. }, function (response) {
  13703. $scope.loading = false;
  13704. toaster.pop('error', '保存失败', response.data);
  13705. });
  13706. };
  13707. // 立即购买
  13708. $scope.addToOrder = function (order) {
  13709. $scope.loading = true;
  13710. $scope.order.status = 200;
  13711. $scope.order.vendusertel = order.vendor.tel;
  13712. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  13713. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  13714. $scope.order.vendUU = $scope.order.vend.uu;
  13715. $scope.order.vendUserUU = $scope.order.vendUser.userUU;
  13716. if ($scope.order.date instanceof Date) {
  13717. $scope.order.date = $scope.order.date.getTime();
  13718. }
  13719. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  13720. if ($scope.order.orderItems[i].delivery instanceof Date) {
  13721. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  13722. }
  13723. if ($scope.order.currency != 'RMB') {
  13724. $scope.order.orderItems[i].rate = 0;
  13725. }
  13726. }
  13727. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  13728. $scope.loading = false;
  13729. toaster.pop('success', '成功', '保存成功');
  13730. window.location.hash = '#/purc/order/' + data.id;
  13731. }, function (response) {
  13732. $scope.loading = false;
  13733. toaster.pop('error', '保存失败', response.data);
  13734. });
  13735. };
  13736. // 新增收货地址保存
  13737. $scope.saveShipAddress = function (ship) {
  13738. ship.address = ship.province + ship.city + ship.district;
  13739. ShipAddress.saveAddress({}, ship, function (data) {
  13740. if (data.success) {
  13741. ShipAddress.shipAddList({}, function (data) {
  13742. $scope.ships = data;
  13743. $scope.order.shipadd = $scope.ships[0];
  13744. });
  13745. toaster.pop('success', '提示', data.success);
  13746. }
  13747. if (data.error) {
  13748. toaster.pop('error', '提示', data.error);
  13749. }
  13750. });
  13751. }
  13752. // 新增供应商联系人
  13753. $scope.addContact = function (uu) {
  13754. var modalInstance = $modal.open({
  13755. animation: true,
  13756. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  13757. controller: 'AddContacCtrl',
  13758. resolve: {}
  13759. });
  13760. modalInstance.result.then(function (data) {
  13761. $scope.contact = data;
  13762. $scope.contact.venduu = uu;
  13763. Vendor.saveContact({}, $scope.contact, function (data) {
  13764. Vendor.contacts({venduu: $scope.order.vend.uu}, {}, function (data) {
  13765. $scope.contacts = data;
  13766. $scope.order.vendor = $scope.contacts[0];
  13767. });
  13768. toaster.pop('success', '提示', '联系人保存成功');
  13769. }, function (response) {
  13770. toaster.pop('error', '失败', response.data);
  13771. });
  13772. });
  13773. }
  13774. }]);
  13775. /**
  13776. * 采购批量导入
  13777. */
  13778. app.controller('PurcUploadByBatchCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  13779. // 通过excel批量上传物料
  13780. $scope.result = null;
  13781. $scope.loading = false;
  13782. $scope.upload = function () {
  13783. $scope.loading = true;
  13784. var file = $scope.myFiles[0];
  13785. $upload.upload({
  13786. url: 'purchase/release/excel',
  13787. file: file,
  13788. method: 'POST'
  13789. }).success(function (data) {
  13790. $scope.loading = false;
  13791. $scope.result = data;
  13792. $scope.success = $scope.result.success;
  13793. $scope.total = $scope.result.total;
  13794. $scope.alters = $scope.result.alters;
  13795. }).error(function (response) {
  13796. $scope.loading = false;
  13797. toaster.pop('error', response.data || response);
  13798. });
  13799. };
  13800. // 下载模板
  13801. $scope.download = function () {
  13802. window.location.href = 'purchase/upload/template';
  13803. };
  13804. $scope.enSure = function () {
  13805. $modalInstance.close($scope.result.products);
  13806. }
  13807. // 点击确定时增加加载标志
  13808. $scope.addClass = function() {
  13809. $scope.loading = true;
  13810. }
  13811. $scope.cancel = function () {
  13812. $modalInstance.dismiss();
  13813. }
  13814. }]);
  13815. // 查找供应商
  13816. app.controller('DbfindVendorInfoCtrl', ['$scope', 'BaseService', 'ngTableParams', 'toaster', '$modalInstance', 'Vendor', '$rootScope', 'orderItems', function ($scope, BaseService, ngTableParams, toaster, $modalInstance, Vendor, $rootScope, orderItems) {
  13817. $scope.prod = false;
  13818. if (orderItems.length != 0) {
  13819. $scope.prod = true;
  13820. }
  13821. BaseService.scrollBackToTop();
  13822. if ($rootScope.venduu != null) {
  13823. $scope.venduu = $rootScope.venduu;
  13824. }
  13825. // 搜索框回车
  13826. $scope.onSearch = function (keyword) {
  13827. $scope.keyword = keyword;
  13828. $scope.customerParams.page(1);
  13829. $scope.customerParams.reload();
  13830. };
  13831. $scope.customerParams = new ngTableParams({
  13832. page: 1,
  13833. count: 20
  13834. }, {
  13835. total: 0,
  13836. counts: [5, 10, 25, 50],
  13837. getData: function ($defer, params) {
  13838. $scope.loading = true;
  13839. var pageParams = params.url();
  13840. pageParams.keyword = $scope.keyword;
  13841. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13842. $scope.loading = false;
  13843. if (page) {
  13844. params.total(page.totalElement);
  13845. $defer.resolve(page.content);
  13846. }
  13847. $scope.totalCount = page.totalElement;
  13848. }, function (response) {
  13849. $scope.loading = false;
  13850. toaster.pop('error', '数据加载失败', response.data);
  13851. });
  13852. }
  13853. });
  13854. $scope.cancel = function () {
  13855. $modalInstance.dismiss();
  13856. };
  13857. $scope.ensure = false;
  13858. $scope.check = function (vendor) { // 需要进行判断的选择
  13859. $scope.vendorInfo = vendor;
  13860. $scope.ensure = true;
  13861. };
  13862. $scope.checkVendor = function (vendor) { // 直接选择
  13863. $modalInstance.close(vendor);
  13864. }
  13865. }]);
  13866. /**
  13867. * 我的客户
  13868. */
  13869. app.controller('MyClientCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster) {
  13870. $scope.userInfoResult = true;
  13871. AuthenticationService.getAuthentication().success(function (data) {
  13872. $scope.loading = false;
  13873. $scope.thisUser = data;
  13874. });
  13875. var getCustInfos = function (custuu) {
  13876. if (custuu) {
  13877. VendorService.userInfo.query({uu: custuu}, null, function (data) {
  13878. $scope.custInfos = data;
  13879. var getPage = function (page, size) {
  13880. if ($scope.custInfos) {
  13881. var result = {};
  13882. result.totalCount = $scope.custInfos.length;
  13883. result.content = $scope.custInfos.slice((page - 1) * size, page * size);
  13884. if ($scope.custInfos.length % size == 0) {
  13885. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size;
  13886. } else {
  13887. result.totalPage = ($scope.custInfos.length - $scope.custInfos.length % size) / size + 1;
  13888. }
  13889. result.first = page == 1;
  13890. result.last = page == result.totalPage;
  13891. result.page = page;
  13892. result.next = page - 0 + 1;
  13893. result.pre = page - 1;
  13894. return result;
  13895. }
  13896. }
  13897. $scope.userdata = getPage(1, 4);
  13898. $scope.first = function () {
  13899. $scope.userdata = getPage($scope.userdata.pre, 4);
  13900. }
  13901. $scope.last = function () {
  13902. $scope.userdata = getPage($scope.userdata.next, 4);
  13903. }
  13904. }, function (response) {
  13905. $scope.loading = false;
  13906. toaster.pop('error', '数据加载失败', response.data);
  13907. });
  13908. }
  13909. }
  13910. // 分配权限
  13911. $scope.addUserInfo = function (customer) {
  13912. //TODO
  13913. if ($scope.thisUser.sys) {
  13914. var modalInstance = $modal.open({
  13915. animation: true,
  13916. templateUrl: 'static/tpl/index/account/add_userInfo.html',
  13917. controller: 'AddUserInfoCtrl',
  13918. resolve: {
  13919. customer: function () {
  13920. return customer;
  13921. }
  13922. }
  13923. });
  13924. modalInstance.result.then(function (changed, checked) {
  13925. if (changed) {
  13926. if (checked)
  13927. $scope.newUser.roles = checked;
  13928. else
  13929. loadUsers();
  13930. }
  13931. });
  13932. } else {
  13933. toaster.pop('error', '您没有分配用户的权限!');
  13934. }
  13935. };
  13936. $scope.showUserInfo = function (customer, boo) {
  13937. $scope.custInfo = customer;
  13938. if (boo) {
  13939. getCustInfos(customer.myEnterprise.uu);
  13940. $scope.userInfoResult = true;
  13941. }
  13942. }
  13943. $scope.customerParams = new ngTableParams({
  13944. page: 1,
  13945. count: 20
  13946. }, {
  13947. total: 0,
  13948. counts: [5, 10, 25, 50],
  13949. getData: function ($defer, params) {
  13950. $scope.loading = true;
  13951. VendorService.customer.get(BaseService.parseParams(params.url()), function (page) {
  13952. $scope.loading = false;
  13953. if (page) {
  13954. params.total(page.totalElement);
  13955. $defer.resolve(page.content);
  13956. }
  13957. $scope.totalCount = page.totalElement;
  13958. }, function (response) {
  13959. $scope.loading = false;
  13960. toaster.pop('error', '数据加载失败', response.data);
  13961. });
  13962. }
  13963. });
  13964. }]);
  13965. /**
  13966. * 我的供应商
  13967. */
  13968. app.controller('PurcVendorCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  13969. BaseService.scrollBackToTop();
  13970. // 搜索框回车
  13971. $scope.onSearch = function (keyword) {
  13972. $scope.keyword = keyword;
  13973. $scope.customerParams.page(1);
  13974. $scope.customerParams.reload();
  13975. };
  13976. $scope.customerParams = new ngTableParams({
  13977. page: 1,
  13978. count: 20
  13979. }, {
  13980. total: 0,
  13981. counts: [5, 10, 25, 50],
  13982. getData: function ($defer, params) {
  13983. $scope.loading = true;
  13984. var pageParams = params.url();
  13985. pageParams.keyword = $scope.keyword;
  13986. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  13987. $scope.loading = false;
  13988. if (page) {
  13989. params.total(page.totalElement);
  13990. $scope.total = page.totalElement;
  13991. $defer.resolve(page.content);
  13992. }
  13993. $scope.totalCount = page.totalElement;
  13994. }, function (response) {
  13995. $scope.loading = false;
  13996. toaster.pop('error', '数据加载失败', response.data);
  13997. });
  13998. }
  13999. });
  14000. //设置消息已读
  14001. var setOrdersRead = function () {
  14002. var ids=[];
  14003. Vendor.setVendorRead({}, ids, function (message) {
  14004. });
  14005. };
  14006. setOrdersRead();
  14007. // 查看供应商详情
  14008. $scope.VendorDetail = function (id, uu) {
  14009. $rootScope.vendorId = id;
  14010. $rootScope.vendoruu = uu;
  14011. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  14012. }
  14013. // 向企业购买
  14014. $scope.purcByEn = function (businessCode) {
  14015. $rootScope.businessCode = businessCode;
  14016. window.location.hash = "#/purc/addOrder";
  14017. }
  14018. }]);
  14019. /**
  14020. * 供应商详情
  14021. */
  14022. app.controller('PurcVendorDetailCtrl', ['$scope', 'toaster', '$stateParams', 'Vendor', '$modal', 'Product', 'ngTableParams', 'BaseService', '$rootScope', function ($scope, toaster, $stateParams, Vendor, $modal, Product, ngTableParams, BaseService, $rootScope) {
  14023. BaseService.scrollBackToTop();
  14024. $scope.vendorContacts = [];
  14025. var loadData = function () {
  14026. Vendor.getVendorDetail({id: $stateParams.id}, {}, function (data) {
  14027. $scope.vendor = data.vendorEnterprise;
  14028. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  14029. $scope.vendorContacts = data;
  14030. });
  14031. }, function (response) {
  14032. toaster.pop('error', '提示', response.data);
  14033. });
  14034. };
  14035. loadData();
  14036. // 新增供应商联系人
  14037. $scope.addContact = function (uu) {
  14038. var modalInstance = $modal.open({
  14039. animation: true,
  14040. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  14041. controller: 'AddContacCtrl',
  14042. resolve: {}
  14043. });
  14044. modalInstance.result.then(function (data) {
  14045. $scope.contact = data;
  14046. $scope.contact.venduu = uu;
  14047. Vendor.saveContact({}, $scope.contact, function (data) {
  14048. toaster.pop('success', '提示', '联系人保存成功');
  14049. $scope.vendorContacts.push(data);
  14050. }, function (response) {
  14051. toaster.pop('error', '失败', response.data);
  14052. });
  14053. });
  14054. };
  14055. // 编辑供应商联系人
  14056. $scope.edit = function (contact) {
  14057. var modalInstance = $modal.open({
  14058. animation: true,
  14059. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  14060. controller: 'EditContacCtrl',
  14061. resolve: {
  14062. contact: function () {
  14063. return contact;
  14064. }
  14065. }
  14066. });
  14067. modalInstance.result.then(function (data) {
  14068. Vendor.saveContact({}, data, function (data) {
  14069. loadData();
  14070. toaster.pop('success', '提示', '联系人修改成功');
  14071. }, function (response) {
  14072. toaster.pop('error', '失败', response.data);
  14073. });
  14074. });
  14075. }
  14076. // 删除供应商联系人
  14077. $scope.deleteById = function (id, index) {
  14078. $scope.vendorContacts.splice(index, 1);
  14079. Vendor.deleteContact({id: id}, {}, function (data) {
  14080. toaster.pop('success', '提示', '供应商联系人删除成功');
  14081. loadData();
  14082. }, function (response) {
  14083. toaster.pop('error', '提示', response.data);
  14084. });
  14085. }
  14086. // 供应商物料信息
  14087. $scope.viewProdList = function (uu) {
  14088. $scope.uu = uu;
  14089. $scope.tableParams.page(1);
  14090. $scope.tableParams.reload();
  14091. };
  14092. // 搜索框回车
  14093. $scope.onSearch = function (keyword) {
  14094. $scope.keyword = keyword;
  14095. $scope.tableParams.page(1);
  14096. $scope.tableParams.reload();
  14097. };
  14098. // 供应商物料信息
  14099. $scope.tableParams = new ngTableParams({
  14100. page: 1,
  14101. count: 20
  14102. }, {
  14103. total: 0,
  14104. counts: [5, 10, 25, 50],
  14105. getData: function ($defer, params) {
  14106. $scope.loading = true;
  14107. var pageParams = params.url();
  14108. pageParams.custUU = $scope.uu;
  14109. pageParams.keyword = $scope.keyword;
  14110. $scope.tip = $scope.keyword;
  14111. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  14112. $scope.loading = false;
  14113. if (page) {
  14114. params.total(page.totalElement);
  14115. $scope.total = page.totalElement;
  14116. $defer.resolve(page.content);
  14117. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  14118. }
  14119. }, function (response) {
  14120. $scope.loading = false;
  14121. toaster.pop('error', '数据加载失败', response.data);
  14122. });
  14123. }
  14124. });
  14125. /**
  14126. * 选中单个物料购买
  14127. * @param businessCode
  14128. * @param id
  14129. */
  14130. $scope.PurcByEnAndProd = function (businessCode, id) {
  14131. $rootScope.businessCode = businessCode;
  14132. $rootScope.prodId = id;
  14133. window.location.hash = "#/purc/addOrder";
  14134. }
  14135. /**
  14136. * 询价
  14137. */
  14138. $scope.PurcInquiry = function (businessCode, id) {
  14139. $rootScope.prodId = id;
  14140. window.location.hash = "#/purc/purcinquiry/" + businessCode;
  14141. }
  14142. }]);
  14143. /**
  14144. * 编辑供应商联系人
  14145. */
  14146. app.controller('EditContacCtrl', ['$scope', 'toaster', '$modalInstance', 'contact', function ($scope, toaster, $modalInstance, contact) {
  14147. $scope.contact = angular.copy(contact);
  14148. $scope.save = function (contact) {
  14149. $modalInstance.close(contact);
  14150. };
  14151. $scope.cancel = function () {
  14152. $modalInstance.dismiss();
  14153. }
  14154. }]);
  14155. /**
  14156. * 新增供应商联系人
  14157. */
  14158. app.controller('AddContacCtrl', ['$scope', 'toaster', '$modalInstance', function ($scope, toaster, $modalInstance) {
  14159. $scope.save = function (contact) {
  14160. $modalInstance.close(contact);
  14161. };
  14162. $scope.cancel = function () {
  14163. $modalInstance.dismiss();
  14164. }
  14165. }]);
  14166. /**
  14167. * 建立合作关系申请 (我的合作伙伴)
  14168. */
  14169. app.controller('AddPartnerRequestCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  14170. BaseService.scrollBackToTop();
  14171. $scope.status = "partner";
  14172. $scope.active = 'done';
  14173. var getRequestStatus = function (active) {
  14174. var fn = 'getAllRequest';
  14175. switch (active) {
  14176. case 'done':
  14177. fn = 'getRequestDone';
  14178. break;
  14179. case 'todo':
  14180. fn = 'getRequestTodo';
  14181. break;
  14182. case 'end':
  14183. fn = 'getRequestEnd';
  14184. break;
  14185. }
  14186. return fn;
  14187. }
  14188. // 切换单据类型
  14189. $scope.setActive = function (state) {
  14190. if ($scope.active != state) {
  14191. $scope.active = state;
  14192. if ($scope.tableParams.page() == 1)
  14193. $scope.tableParams.reload();
  14194. else
  14195. $scope.tableParams.page(1);
  14196. }
  14197. };
  14198. // 切换数据来源(正常数据 or 历史数据)
  14199. var getService = function () {
  14200. return AddPartnerMyRequest;
  14201. };
  14202. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14203. page: 1,
  14204. count: 20,
  14205. sorting: {}
  14206. }, {
  14207. total: 0,
  14208. counts: [],
  14209. getData: function ($defer, params) { // 获取数据的方法
  14210. $scope.loading = true;
  14211. var pageParams = params.url();
  14212. pageParams.keyword = $scope.keyword;
  14213. if ($rootScope.vendName) {
  14214. pageParams.keyword = $rootScope.vendName;
  14215. $scope.keyword = $rootScope.vendName;
  14216. $rootScope.vendName = null;
  14217. }
  14218. $scope.tip = $scope.keyword;
  14219. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14220. $scope.loading = false;
  14221. if (page) {
  14222. params.total(page.totalElement);
  14223. $defer.resolve(page.content);
  14224. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14225. }
  14226. }, function (response) {
  14227. $scope.loading = false;
  14228. toaster.pop('error', '数据加载失败', response.data);
  14229. });
  14230. }
  14231. });
  14232. // 再次申请
  14233. $scope.addAgain = function (name, businessCode) {
  14234. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14235. if (data.success) {
  14236. toaster.pop("success", '添加成功', data.success);
  14237. $scope.tableParams.reload();
  14238. }
  14239. if (data.error) {
  14240. toaster.pop("error", '添加失败', data.error);
  14241. }
  14242. }, function (response) {
  14243. toaster.pop('error', '失败', response.data);
  14244. });
  14245. }
  14246. // 添加为供应商
  14247. $scope.addSupplier = function (vendUID) {
  14248. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14249. if (data.success) {
  14250. toaster.pop('success', '提示', data.success);
  14251. $scope.tableParams.reload();
  14252. }
  14253. if (data.error) {
  14254. toaster.pop('error', '提示', data.error);
  14255. }
  14256. }, function (response) {
  14257. toaster.pop('error', '失败', response.data);
  14258. })
  14259. };
  14260. // 添加为供应商
  14261. $scope.addServicer = function (vendUID) {
  14262. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14263. if (data.success) {
  14264. toaster.pop('success', '提示', data.success);
  14265. $scope.tableParams.reload();
  14266. }
  14267. if (data.error) {
  14268. toaster.pop('error', '提示', data.error);
  14269. }
  14270. }, function (response) {
  14271. toaster.pop('error', '失败', response.data);
  14272. })
  14273. };
  14274. // 添加客户
  14275. $scope.addCust = function (vendUID) {
  14276. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14277. if (data.success) {
  14278. toaster.pop('success', '提示', data.success);
  14279. $scope.tableParams.reload();
  14280. }
  14281. if (data.error) {
  14282. toaster.pop('error', '提示', data.error);
  14283. }
  14284. }, function (response) {
  14285. toaster.pop('error', '失败', response.data);
  14286. })
  14287. };
  14288. // 搜索框回车
  14289. $scope.onSearch = function () {
  14290. $scope.tableParams.page(1);
  14291. $scope.tableParams.reload();
  14292. };
  14293. // 同意申请
  14294. $scope.agree = function (id) {
  14295. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14296. if (data.success) {
  14297. toaster.pop('success', '提示', '操作成功');
  14298. }
  14299. if (data.error) {
  14300. toaster.pop('error', '提示', '操作失败');
  14301. }
  14302. // $scope.tableParams.reload();
  14303. $window.location.reload();
  14304. }, function (response) {
  14305. toaster.pop('error', '提示', response.data);
  14306. });
  14307. };
  14308. // 拒绝申请
  14309. $scope.refuse = function (id, reason) {
  14310. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14311. if (data.success) {
  14312. toaster.pop('success', '提示', '操作成功');
  14313. }
  14314. if (data.error) {
  14315. toaster.pop('error', '提示', '操作失败');
  14316. }
  14317. // $scope.tableParams.reload();
  14318. $window.location.reload();
  14319. }, function (response) {
  14320. toaster.pop('error', '提示', response.data);
  14321. });
  14322. };
  14323. // 取消供应商关系
  14324. $scope.relieve = function (id) {
  14325. VendorInfo.relieve({id: id}, {}, function (data) {
  14326. if (data.success) {
  14327. toaster.pop('success', '提示', data.success);
  14328. }
  14329. // $scope.tableParams.page(1);
  14330. $scope.tableParams.reload();
  14331. }, function (response) {
  14332. toaster.pop('error', '提示', response.data);
  14333. });
  14334. };
  14335. // 建立供应商关系
  14336. $scope.activeVend = function (id) {
  14337. VendorInfo.activeVend({id: id}, {}, function (data) {
  14338. if (data.success) {
  14339. toaster.pop('success', '提示', data.success);
  14340. }
  14341. // $scope.tableParams.page(1);
  14342. $scope.tableParams.reload();
  14343. }, function (response) {
  14344. toaster.pop('error', '提示', response.data);
  14345. });
  14346. };
  14347. // 取消服务商
  14348. $scope.relieveServicer = function (id) {
  14349. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14350. if (data.success) {
  14351. toaster.pop('success', '提示', data.success);
  14352. }
  14353. $scope.tableParams.reload();
  14354. }, function (response) {
  14355. toaster.pop('error', '提示', response.data);
  14356. });
  14357. };
  14358. // 启用服务商
  14359. $scope.activeServicer = function (id) {
  14360. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14361. if (data.success) {
  14362. toaster.pop('success', '提示', data.success);
  14363. }
  14364. $scope.tableParams.reload();
  14365. }, function (response) {
  14366. toaster.pop('error', '提示', response.data);
  14367. });
  14368. };
  14369. // 取消客户关系
  14370. $scope.disableCust = function (id) {
  14371. VendorInfo.disableCust({id: id}, {}, function (data) {
  14372. if (data.success) {
  14373. toaster.pop('success', '提示', data.success);
  14374. }
  14375. $scope.tableParams.page(1);
  14376. $scope.tableParams.reload();
  14377. }, function (response) {
  14378. toaster.pop('error', '提示', response.data);
  14379. });
  14380. };
  14381. // 激活客户关系
  14382. $scope.activeCust = function (id) {
  14383. VendorInfo.activeCust({id: id}, {}, function (data) {
  14384. if (data.success) {
  14385. toaster.pop('success', '提示', data.success);
  14386. }
  14387. $scope.tableParams.page(1);
  14388. $scope.tableParams.reload();
  14389. }, function (response) {
  14390. toaster.pop('error', '提示', response.data);
  14391. });
  14392. }
  14393. }]);
  14394. /**
  14395. * 建立合作关系申请 (新的合作伙伴)
  14396. */
  14397. app.controller('NewPartnerCtrl', ['$scope', 'AddPartnerMyRequest', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', '$timeout', '$rootScope', 'VendorInfo', '$window', function ($scope, AddPartnerMyRequest, toaster, BaseService, ngTableParams, AddPartner, $timeout, $rootScope, VendorInfo, $window) {
  14398. BaseService.scrollBackToTop();
  14399. $scope.status = "partner";
  14400. $scope.active = 'all'; // 所有申请记录
  14401. var getRequestStatus = function (active) {
  14402. var fn = 'getAllRequest';
  14403. switch (active) {
  14404. case 'done':
  14405. fn = 'getRequestDone';
  14406. break;
  14407. case 'todo':
  14408. fn = 'getRequestTodo';
  14409. break;
  14410. case 'end':
  14411. fn = 'getRequestEnd';
  14412. break;
  14413. }
  14414. return fn;
  14415. }
  14416. // 切换单据类型
  14417. $scope.setActive = function (state) {
  14418. if ($scope.active != state) {
  14419. $scope.active = state;
  14420. if ($scope.tableParams.page() == 1)
  14421. $scope.tableParams.reload();
  14422. else
  14423. $scope.tableParams.page(1);
  14424. }
  14425. };
  14426. // 切换数据来源(正常数据 or 历史数据)
  14427. var getService = function () {
  14428. return AddPartnerMyRequest;
  14429. };
  14430. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14431. page: 1,
  14432. count: 20,
  14433. sorting: {}
  14434. }, {
  14435. total: 0,
  14436. counts: [],
  14437. getData: function ($defer, params) { // 获取数据的方法
  14438. $scope.loading = true;
  14439. var pageParams = params.url();
  14440. pageParams.keyword = $scope.keyword;
  14441. if ($rootScope.vendName) {
  14442. pageParams.keyword = $rootScope.vendName;
  14443. $scope.keyword = $rootScope.vendName;
  14444. $rootScope.vendName = null;
  14445. }
  14446. $scope.tip = $scope.keyword;
  14447. getService()[getRequestStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14448. $scope.loading = false;
  14449. if (page) {
  14450. params.total(page.totalElement);
  14451. $defer.resolve(page.content);
  14452. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14453. }
  14454. }, function (response) {
  14455. $scope.loading = false;
  14456. toaster.pop('error', '数据加载失败', response.data);
  14457. });
  14458. }
  14459. });
  14460. // 再次申请
  14461. $scope.addAgain = function (name, businessCode) {
  14462. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  14463. if (data.success) {
  14464. toaster.pop("success", '添加成功', data.success);
  14465. $scope.tableParams.reload();
  14466. }
  14467. if (data.error) {
  14468. toaster.pop("error", '添加失败', data.error);
  14469. }
  14470. }, function (response) {
  14471. toaster.pop('error', '失败', response.data);
  14472. });
  14473. }
  14474. // 添加为供应商
  14475. $scope.addSupplier = function (vendUID) {
  14476. AddPartner.addSupplier({businessCode: vendUID}, {}, function (data) {
  14477. if (data.success) {
  14478. toaster.pop('success', '提示', data.success);
  14479. $scope.tableParams.reload();
  14480. }
  14481. if (data.error) {
  14482. toaster.pop('error', '提示', data.error);
  14483. }
  14484. }, function (response) {
  14485. toaster.pop('error', '失败', response.data);
  14486. })
  14487. };
  14488. // 添加为供应商
  14489. $scope.addServicer = function (vendUID) {
  14490. AddPartner.addServicer({businessCode: vendUID}, {}, function (data) {
  14491. if (data.success) {
  14492. toaster.pop('success', '提示', data.success);
  14493. $scope.tableParams.reload();
  14494. }
  14495. if (data.error) {
  14496. toaster.pop('error', '提示', data.error);
  14497. }
  14498. }, function (response) {
  14499. toaster.pop('error', '失败', response.data);
  14500. })
  14501. };
  14502. // 添加客户
  14503. $scope.addCust = function (vendUID) {
  14504. AddPartner.addCust({businessCode: vendUID}, {}, function (data) {
  14505. if (data.success) {
  14506. toaster.pop('success', '提示', data.success);
  14507. $scope.tableParams.reload();
  14508. }
  14509. if (data.error) {
  14510. toaster.pop('error', '提示', data.error);
  14511. }
  14512. }, function (response) {
  14513. toaster.pop('error', '失败', response.data);
  14514. })
  14515. };
  14516. // 搜索框回车
  14517. $scope.onSearch = function () {
  14518. $scope.tableParams.page(1);
  14519. $scope.tableParams.reload();
  14520. };
  14521. // 同意申请
  14522. $scope.agree = function (id) {
  14523. AddPartner.agreeRequest({id: id}, {}, function (data) {
  14524. if (data.success) {
  14525. toaster.pop('success', '提示', '操作成功');
  14526. }
  14527. if (data.error) {
  14528. toaster.pop('error', '提示', '操作失败');
  14529. }
  14530. // $scope.tableParams.reload();
  14531. $window.location.reload();
  14532. }, function (response) {
  14533. toaster.pop('error', '提示', response.data);
  14534. });
  14535. };
  14536. AddPartnerMyRequest.requestAmount({}, function (data) {
  14537. $scope.requestTodo = data;
  14538. });
  14539. // 拒绝申请
  14540. $scope.refuse = function (id, reason) {
  14541. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14542. if (data.success) {
  14543. toaster.pop('success', '提示', '操作成功');
  14544. }
  14545. if (data.error) {
  14546. toaster.pop('error', '提示', '操作失败');
  14547. }
  14548. // $scope.tableParams.reload();
  14549. $window.location.reload();
  14550. }, function (response) {
  14551. toaster.pop('error', '提示', response.data);
  14552. });
  14553. };
  14554. // 取消供应商关系
  14555. $scope.relieve = function (id) {
  14556. VendorInfo.relieve({id: id}, {}, function (data) {
  14557. if (data.success) {
  14558. toaster.pop('success', '提示', data.success);
  14559. }
  14560. // $scope.tableParams.page(1);
  14561. $scope.tableParams.reload();
  14562. }, function (response) {
  14563. toaster.pop('error', '提示', response.data);
  14564. });
  14565. }
  14566. // 建立供应商关系
  14567. $scope.activeVend = function (id) {
  14568. VendorInfo.activeVend({id: id}, {}, function (data) {
  14569. if (data.success) {
  14570. toaster.pop('success', '提示', data.success);
  14571. }
  14572. // $scope.tableParams.page(1);
  14573. $scope.tableParams.reload();
  14574. }, function (response) {
  14575. toaster.pop('error', '提示', response.data);
  14576. });
  14577. }
  14578. // 取消服务商
  14579. $scope.relieveServicer = function (id) {
  14580. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  14581. if (data.success) {
  14582. toaster.pop('success', '提示', data.success);
  14583. }
  14584. $scope.tableParams.reload();
  14585. }, function (response) {
  14586. toaster.pop('error', '提示', response.data);
  14587. });
  14588. }
  14589. // 启用服务商
  14590. $scope.activeServicer = function (id) {
  14591. VendorInfo.activeServicer({id: id}, {}, function (data) {
  14592. if (data.success) {
  14593. toaster.pop('success', '提示', data.success);
  14594. }
  14595. $scope.tableParams.reload();
  14596. }, function (response) {
  14597. toaster.pop('error', '提示', response.data);
  14598. });
  14599. }
  14600. // 取消客户关系
  14601. $scope.disableCust = function (id) {
  14602. VendorInfo.disableCust({id: id}, {}, function (data) {
  14603. if (data.success) {
  14604. toaster.pop('success', '提示', data.success);
  14605. }
  14606. // $scope.tableParams.page(1);
  14607. $scope.tableParams.reload();
  14608. }, function (response) {
  14609. toaster.pop('error', '提示', response.data);
  14610. });
  14611. }
  14612. // 激活客户关系
  14613. $scope.activeCust = function (id) {
  14614. VendorInfo.activeCust({id: id}, {}, function (data) {
  14615. if (data.success) {
  14616. toaster.pop('success', '提示', data.success);
  14617. }
  14618. // $scope.tableParams.page(1);
  14619. $scope.tableParams.reload();
  14620. }, function (response) {
  14621. toaster.pop('error', '提示', response.data);
  14622. });
  14623. }
  14624. }]);
  14625. /**
  14626. * 建立合作关系处理申请
  14627. */
  14628. app.controller('AddPartnerMessageCtrl', ['$scope', 'AddPartnerMyMessage', 'toaster', 'BaseService', 'ngTableParams', 'AddPartner', 'AddPartnerMyRequest', '$window', function ($scope, AddPartnerMyMessage, toaster, BaseService, ngTableParams, AddPartner, AddPartnerMyRequest, $window) {
  14629. BaseService.scrollBackToTop();
  14630. $scope.active = 'todo';
  14631. var getMessagetStatus = function (active) {
  14632. var fn = 'getAllMessage';
  14633. switch (active) {
  14634. case 'done':
  14635. fn = 'getMessageDone';
  14636. break;
  14637. case 'todo':
  14638. fn = 'getMessageTodo';
  14639. break;
  14640. case 'end':
  14641. fn = 'getMessageEnd';
  14642. break;
  14643. }
  14644. return fn;
  14645. }
  14646. // 切换单据类型
  14647. $scope.setActive = function (state) {
  14648. if ($scope.active != state) {
  14649. $scope.active = state;
  14650. if ($scope.tableParams.page() == 1)
  14651. $scope.tableParams.reload();
  14652. else
  14653. $scope.tableParams.page(1);
  14654. }
  14655. };
  14656. var getService = function () {
  14657. return AddPartnerMyMessage;
  14658. };
  14659. $scope.tableParams = new ngTableParams({ // ng-Table参数
  14660. page: 1,
  14661. count: 20,
  14662. sorting: {}
  14663. }, {
  14664. total: 0,
  14665. counts: [5, 10, 15, 25, 50],
  14666. getData: function ($defer, params) { // 获取数据的方法
  14667. $scope.loading = true;
  14668. var pageParams = params.url();
  14669. pageParams.searchFilter = { // 筛选条件
  14670. keyword: $scope.keyword,
  14671. };
  14672. getService()[getMessagetStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14673. $scope.loading = false;
  14674. if (page) {
  14675. params.total(page.totalElement);
  14676. $defer.resolve(page.content);
  14677. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  14678. }
  14679. }, function (response) {
  14680. $scope.loading = false;
  14681. toaster.pop('error', '数据加载失败', response.data);
  14682. });
  14683. }
  14684. });
  14685. // 同意申请
  14686. $scope.agree = function (id) {
  14687. AddPartner.agreeReq
  14688. uest({id: id}, {}, function (data) {
  14689. if (data.success) {
  14690. toaster.pop('success', '提示', '操作成功');
  14691. }
  14692. if (data.error) {
  14693. toaster.pop('error', '提示', '操作失败');
  14694. }
  14695. // $scope.tableParams.reload();
  14696. $window.location.reload();
  14697. }, function (response) {
  14698. toaster.pop('error', '提示', response.data);
  14699. });
  14700. };
  14701. // 拒绝申请
  14702. $scope.refuse = function (id, reason) {
  14703. AddPartner.refuseRequest({id: id, reason: reason}, {}, function (data) {
  14704. if (data.success) {
  14705. toaster.pop('success', '提示', '操作成功');
  14706. }
  14707. if (data.error) {
  14708. toaster.pop('error', '提示', '操作失败');
  14709. }
  14710. // $scope.tableParams.reload();
  14711. $window.location.reload();
  14712. }, function (response) {
  14713. toaster.pop('error', '提示', response.data);
  14714. });
  14715. };
  14716. $scope.status = 'get';
  14717. }]);
  14718. /**
  14719. * 我的合作伙伴
  14720. */
  14721. app.controller('MyPartnersCtrl', ['$scope', 'toaster', 'GetProductInfo', 'BaseService', function ($scope, toaster, GetProductInfo, BaseService) {
  14722. BaseService.scrollBackToTop();
  14723. // 默认显示合作伙伴
  14724. $scope.status = 'news';
  14725. // 获取所有的合作伙伴
  14726. GetProductInfo.getAllPartners({}, function (data) {
  14727. $scope.partners = data;
  14728. }, function (res) {
  14729. toaster.pop('error', '获取列表失败', res.data);
  14730. });
  14731. // 添加为客户
  14732. $scope.addCust = function (partner) {
  14733. GetProductInfo.addCust({}, partner, function (data) {
  14734. toaster.pop('success', '提示', '添加客户成功');
  14735. $scope.tableParams.reload();
  14736. }, function (response) {
  14737. toaster.pop('error', '添加客户失败', response.data);
  14738. });
  14739. }
  14740. // 添加为供应商
  14741. $scope.addSupplier = function (partner) {
  14742. GetProductInfo.addSupplier({}, partner, function (data) {
  14743. toaster.pop('success', '提示', '添加供应商成功');
  14744. $scope.tableParams.reload();
  14745. }, function (response) {
  14746. toaster.pop('error', '添加供应商失败', response.data);
  14747. });
  14748. }
  14749. }]);
  14750. /**
  14751. * 财务对账时,企业进行筛选操作
  14752. */
  14753. app.controller('SearchCustInfoCtrl', ['$scope', '$modalInstance', 'suuorname', 'FaApCheck', 'VendorService', 'ngTableParams', 'BaseService', function ($scope, $modalInstance, suuorname, FaApCheck, VendorService, ngTableParams, BaseService) {
  14754. var getData = function () {
  14755. $scope.loading = true;
  14756. FaApCheck.getAllCustomers(function (data) {
  14757. $scope.custs = data;
  14758. $scope.loading = false;
  14759. });
  14760. };
  14761. getData();
  14762. $scope.customerParams = new ngTableParams({
  14763. page: 1,
  14764. count: 20
  14765. }, {
  14766. total: 0,
  14767. counts: [5, 10, 25, 50],
  14768. getData: function ($defer, params) {
  14769. $scope.loading = true;
  14770. var pageParams = params.url();
  14771. pageParams.keyword = $scope.keyword;
  14772. VendorService.customer.get(BaseService.parseParams(pageParams), function (page) {
  14773. $scope.loading = false;
  14774. if (page) {
  14775. params.total(page.totalElement);
  14776. $defer.resolve(page.content);
  14777. }
  14778. $scope.totalCount = page.totalElement;
  14779. }, function (response) {
  14780. $scope.loading = false;
  14781. toaster.pop('error', '数据加载失败', response.data);
  14782. });
  14783. }
  14784. });
  14785. // 搜索框回车
  14786. $scope.onSearch = function (keyword) {
  14787. $scope.customerParams.page(1);
  14788. $scope.customerParams.reload();
  14789. $scope.tip = keyword;
  14790. };
  14791. $scope.select = function (customer) {
  14792. if (customer.apcheck != 0) {
  14793. $modalInstance.close(customer);
  14794. }
  14795. }
  14796. $scope.close = function () {
  14797. $modalInstance.dismiss();
  14798. }
  14799. }]);
  14800. /**
  14801. * 跳转到企业圈
  14802. */
  14803. app.controller('BusinessGroupsCtrl', ['$scope', 'GetProductInfo', 'toaster', function ($scope, GetProductInfo, toaster) {
  14804. GetProductInfo.businessGroups({}, function (data) {
  14805. window.open(data.url);
  14806. }, function (response) {
  14807. toaster.pop('error', '提示', response.data);
  14808. });
  14809. }]);
  14810. /**
  14811. * 购物车
  14812. */
  14813. app.controller('CartController', ['$scope', 'toaster', 'getCartList', 'ngTableParams', '$filter', 'BaseService', 'cartOperation', '$timeout', 'cartList', 'PurchaseOrder', function ($scope, toaster, getCartList, ngTableParams, $filter, BaseService, cartOperation, $timeout, cartList, PurchaseOrder) {
  14814. BaseService.scrollBackToTop();
  14815. $scope.active = 'all';
  14816. $scope.agreedText = '全部';
  14817. $scope.dateZoneText = '一个月内';
  14818. $scope.condition = {dateZone: 1};
  14819. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  14820. $scope.hasClick = false;
  14821. /* 时间筛选初始化*/
  14822. var fromDate = new Date();
  14823. var toDate = new Date();
  14824. fromDate.setMonth(fromDate.getMonth() - 1);
  14825. fromDate.setHours(0, 0, 0, 0);
  14826. toDate.setHours(23, 59, 59, 999);
  14827. $scope.condition.dateFrom = fromDate;
  14828. $scope.condition.dateTo = toDate;
  14829. $scope.changeDateZone = function (zone) {
  14830. $scope.condition.dateZone = zone;
  14831. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  14832. $scope.condition.$dateZoneOpen = false;
  14833. getDateCondition(zone, $scope.condition);
  14834. $scope.tableParams.page(1);
  14835. $scope.tableParams.reload();
  14836. };
  14837. $scope.changeDeliveryZone = function (zone) {
  14838. $scope.condition.deliveryZoneText = zone;
  14839. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  14840. $scope.condition.$delievryZoneOpen = false;
  14841. getDelveryCondition(zone, $scope.condition);
  14842. $scope.tableParams.reload();
  14843. };
  14844. $scope.openDatePicker = function ($event, item, openParam) {
  14845. $event.preventDefault();
  14846. $event.stopPropagation();
  14847. item[openParam] = !item[openParam];
  14848. };
  14849. $scope.openFilterDatePicker = function ($event, item, openParam) {
  14850. $event.preventDefault();
  14851. $event.stopPropagation();
  14852. item[openParam] = !item[openParam];
  14853. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  14854. $scope.tableParams.reload();
  14855. }
  14856. };
  14857. $scope.parseDate = function (dateStr) {
  14858. if (dateStr)
  14859. return Date.parse(dateStr, 'yyyy-MM-dd');
  14860. return new Date();
  14861. };
  14862. $scope.setActive = function (state) {
  14863. if ($scope.active != state) {
  14864. $scope.active = state;
  14865. if ($scope.tableParams.page() == 1)
  14866. $scope.tableParams.reload();
  14867. else
  14868. $scope.tableParams.page(1);
  14869. }
  14870. };
  14871. $scope.searchMethod = false;
  14872. var getService = function () {
  14873. return $scope.searchMethod ? cartList : getCartList;
  14874. };
  14875. var getTodoCartCount = function () {
  14876. cartOperation.getTodoCartCount({}, function (data) {
  14877. $scope.countTodo = data.cartTodo;
  14878. });
  14879. };
  14880. getTodoCartCount();
  14881. $scope.tableParams = new ngTableParams({
  14882. page: 1,
  14883. count: 20,
  14884. sorting: {
  14885. date: 'desc'
  14886. }
  14887. }, {
  14888. total: 0,
  14889. counts: [5, 10, 25, 50],
  14890. getData: function ($defer, params) {
  14891. $scope.loading = true;
  14892. var pageParams = params.url();
  14893. pageParams.searchFilter = { // 筛选条件
  14894. keyword: $scope.keyword,
  14895. fromDate: getDateTime($scope.condition.dateFrom),
  14896. endDate: getDateTime($scope.condition.dateTo)
  14897. };
  14898. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  14899. $scope.loading = false;
  14900. if (page) {
  14901. params.total(page.totalElement);
  14902. $defer.resolve(page.content);
  14903. }
  14904. }, function (response) {
  14905. $scope.loading = false;
  14906. toaster.pop('error', '数据加载失败', response.data);
  14907. });
  14908. }
  14909. });
  14910. $scope.getCartTotal = function (items) {
  14911. var sum = 0;
  14912. angular.forEach(items, function (item) {
  14913. sum += item.qty * item.price;
  14914. });
  14915. return sum;
  14916. };
  14917. // 搜索框回车
  14918. $scope.onSearch = function (keyword) {
  14919. // 每次搜索重置获取数据方法
  14920. $scope.searchMethod = false;
  14921. if(keyword != null && keyword != '') {
  14922. $scope.searchMethod = true;
  14923. }
  14924. $scope.tableParams.page(1);
  14925. $scope.tableParams.reload();
  14926. };
  14927. var changeClickStatus = function () {
  14928. $scope.hasClick = true;
  14929. $timeout(function () {
  14930. $scope.hasClick = false;
  14931. }, 500);
  14932. }
  14933. // 提交
  14934. $scope.addtoOrder = function (id) {
  14935. cartOperation.addToOrder({id: id}, {}, function (data) {
  14936. if (data.success) {
  14937. toaster.pop('success', '提示', data.success);
  14938. getTodoCartCount();
  14939. $timeout(function () {
  14940. window.location.hash = '#/purc/order/' + data.id;
  14941. window.location.reload();
  14942. }, 500);
  14943. }
  14944. if (data.error) {
  14945. toaster.pop('error', '提示', data.error);
  14946. }
  14947. }, function (response) {
  14948. toaster.pop('erroer', '提示', response.data);
  14949. });
  14950. };
  14951. // 删除一条主记录
  14952. $scope.deleteCart = function (id) {
  14953. changeClickStatus();
  14954. $scope.loading = true;
  14955. cartOperation.deleteCart({id: id}, {}, function (data) {
  14956. if (data.success) {
  14957. toaster.pop('success', '提示', data.success);
  14958. getTodoCartCount();
  14959. getTodoCartCount();
  14960. $timeout(function () {
  14961. $scope.tableParams.page(1);
  14962. $scope.tableParams.reload();
  14963. }, 500);
  14964. }
  14965. if (data.error) {
  14966. toaster.pop('error', '提示', data.error);
  14967. }
  14968. $scope.loading = false;
  14969. }, function (response) {
  14970. $scope.loading = false;
  14971. toaster.pop('erroer', '提示', response.data);
  14972. });
  14973. };
  14974. // 删除一条明细
  14975. $scope.deleteDetail = function (id) {
  14976. changeClickStatus();
  14977. $scope.loading = true;
  14978. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  14979. if (data.success) {
  14980. toaster.pop('success', '提示', data.success);
  14981. $timeout(function () {
  14982. $scope.tableParams.reload();
  14983. }, 500);
  14984. }
  14985. if (data.error) {
  14986. toaster.pop('error', '提示', data.error);
  14987. }
  14988. $scope.loading = false;
  14989. }, function (response) {
  14990. toaster.pop('erroer', '提示', response.data);
  14991. $scope.loading = false;
  14992. });
  14993. };
  14994. // 清空购物车
  14995. $scope.clearCart = function () {
  14996. changeClickStatus();
  14997. $scope.loading = true;
  14998. cartOperation.deleteCarts({}, function (data) {
  14999. if (data.success) {
  15000. toaster.pop('success', '提示', data.success);
  15001. getTodoCartCount();
  15002. $timeout(function () {
  15003. $scope.tableParams.reload();
  15004. }, 500);
  15005. }
  15006. if (data.error) {
  15007. toaster.pop('error', '提示', data.error);
  15008. }
  15009. $scope.loading = false;
  15010. }, function (response) {
  15011. toaster.pop('erroer', '提示', response.data);
  15012. $scope.loading = false;
  15013. });
  15014. }
  15015. // 复制订单
  15016. $scope.copyorder = function (id) {
  15017. changeClickStatus();
  15018. $scope.loading = true;
  15019. PurchaseOrder.copyorder({id: id}, {}, function (data) {
  15020. if (data.id) {
  15021. toaster.pop('success', '提示', '单据复制成功');
  15022. getTodoCartCount();
  15023. $scope.loading = false;
  15024. window.location.hash = "#purc/cart/" + data.id;
  15025. }
  15026. }, function (response) {
  15027. toaster.pop('error', '提示', response.data);
  15028. $scope.loading = false;
  15029. });
  15030. }
  15031. }]);
  15032. /**
  15033. * 购物车详情
  15034. */
  15035. app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', 'recentPrice',
  15036. function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token, recentPrice) {
  15037. BaseService.scrollBackToTop();
  15038. $scope.loading = true;
  15039. var loadData = function () {
  15040. cartOperation.getCartDetail({id: $stateParams.id}, function (data) {
  15041. if (data.code) {
  15042. $scope.order = data;
  15043. var sum = 0;
  15044. angular.forEach($scope.order.orderItems, function (item) {
  15045. sum += item.qty * item.price;
  15046. });
  15047. $scope.order.total = sum;
  15048. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  15049. $scope.contacts = data;
  15050. $scope.order.vendor = $scope.order.venduser;
  15051. });
  15052. $scope.loading = false;
  15053. } else {
  15054. window.location.hash = '#/purc/cart';
  15055. }
  15056. });
  15057. };
  15058. loadData();
  15059. var getToken = function() {
  15060. token.info({userType: 'cart'}, {}, function(data) {
  15061. $scope.token = data.token;
  15062. }, function(response) {
  15063. toaster.pop('error', '提示', response.data);
  15064. });
  15065. }
  15066. getToken();
  15067. // 获取地址信息
  15068. $http.get('resources/citydata/city.json', {
  15069. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  15070. }).then(function (response) {
  15071. $scope.provinces = response.data;
  15072. });
  15073. // 获取收货地址列表
  15074. ShipAddress.shipAddList({}, function (data) {
  15075. $scope.ships = data;
  15076. $scope.order.shipadd = $scope.ships[0];
  15077. });
  15078. //增加商品
  15079. $scope.addProduct = function (index) {
  15080. if ($scope.order.orderItems[index].code == null) {
  15081. toaster.pop('info', '提示', '请先选择商品');
  15082. } else {
  15083. $scope.order.orderItems.push({
  15084. code: null,
  15085. title: null,
  15086. spec: null,
  15087. unit: null,
  15088. qty: null,
  15089. price: null,
  15090. remark: null,
  15091. delivery: null,
  15092. $endDateOpen: false,
  15093. taxrate: $scope.order.rate
  15094. });
  15095. }
  15096. };
  15097. //删除商品
  15098. $scope.deleteProduct = function (index, id) {
  15099. $scope.order.orderItems.splice(index, 1);
  15100. if (id != null) {
  15101. cartOperation.deleteCartDetail({id: id}, {}, function (data) {
  15102. if (data.success) {
  15103. loadData();
  15104. }
  15105. if (data.error) {
  15106. toaster.pop('error', '提示', data.error);
  15107. }
  15108. }, function (response) {
  15109. toaster.pop('erroer', '提示', response.data);
  15110. });
  15111. }
  15112. };
  15113. // 搜索框回车
  15114. $scope.onSearch = function (keyword) {
  15115. $scope.keyword = keyword;
  15116. $scope.tableParams.page(1);
  15117. $scope.tableParams.reload();
  15118. };
  15119. $scope.tableParams = new ngTableParams({
  15120. page: 1,
  15121. count: 20
  15122. }, {
  15123. total: 0,
  15124. counts: [5, 10, 25, 50],
  15125. getData: function ($defer, params) {
  15126. $scope.loading = true;
  15127. var pageParams = params.url();
  15128. pageParams.keyword = $scope.keyword;
  15129. $scope.tip = $scope.keyword;
  15130. pageParams.vendUU = $scope.order.receiveCode;
  15131. Product.vendPord.call(null, BaseService.parseParams(pageParams), function (page) {
  15132. $scope.loading = false;
  15133. if (page) {
  15134. params.total(page.totalElement);
  15135. $scope.total = page.totalElement;
  15136. $defer.resolve(page.content);
  15137. }
  15138. }, function (response) {
  15139. $scope.loading = false;
  15140. toaster.pop('error', '数据加载失败', response.data);
  15141. });
  15142. }
  15143. });
  15144. // 选择
  15145. $scope.check = function (data) {
  15146. var price = null;
  15147. if (data.id) {
  15148. recentPrice.agreed({prId: data.id}, {}, function(response) {
  15149. price = response.price;
  15150. $scope.order.orderItems.push({
  15151. code: data.code,
  15152. title: data.title,
  15153. spec: data.spec,
  15154. unit: data.unit,
  15155. qty: null,
  15156. price: price,
  15157. remark: null,
  15158. delivery: null,
  15159. prid: data.id,
  15160. taxrate: $scope.order.rate,
  15161. prodsource: 'seller',
  15162. });
  15163. });
  15164. }
  15165. };
  15166. // 导入商品信息
  15167. $scope.uplodaByBatch = function () {
  15168. var modalInstance = $modal.open({
  15169. templateUrl: 'static/tpl/index/purc/modal/purc_uplodaByBatch.html',
  15170. controller: 'PurcUploadByBatchCtrl',
  15171. size: 'lg',
  15172. resolve: {}
  15173. });
  15174. modalInstance.result.then(function (data) {
  15175. angular.forEach(data, function (prod) {
  15176. $scope.order.orderItems.push({
  15177. code: prod.code,
  15178. title: data.title,
  15179. unit: 'PCS',
  15180. spec: prod.spec,
  15181. qty: prod.amount,
  15182. price: prod.price,
  15183. remark: prod.remark,
  15184. delivery: prod.date,
  15185. prid: prod.id,
  15186. taxrate: prod.rate
  15187. });
  15188. })
  15189. }, function () {
  15190. });
  15191. }
  15192. // 删除一条主记录
  15193. $scope.deleteCart = function (id) {
  15194. cartOperation.deleteCart({id: id}, {}, function (data) {
  15195. if (data.success) {
  15196. toaster.pop('success', '提示', data.success);
  15197. $timeout(function () {
  15198. window.location.reload();
  15199. }, 500);
  15200. }
  15201. if (data.error) {
  15202. toaster.pop('error', '提示', data.error);
  15203. }
  15204. }, function (response) {
  15205. toaster.pop('erroer', '提示', response.data);
  15206. });
  15207. };
  15208. $scope.getMinDate = function (item) {
  15209. return $filter('date')(new Date, 'yyyy-MM-dd');
  15210. };
  15211. $scope.openDatePicker = function ($event, openParam, index) {
  15212. $event.preventDefault();
  15213. $event.stopPropagation();
  15214. $scope.order.orderItems[index].$endDateOpen = !openParam;
  15215. };
  15216. // 添加到购物车
  15217. $scope.addToCart = function (order) {
  15218. $scope.loading = true;
  15219. if (order.vendor.tel != null) {
  15220. $scope.order.vendusertel = order.vendor.tel;
  15221. }
  15222. if (order.vendor.venduser != null && order.vendor.tel != null) {
  15223. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  15224. }
  15225. if (order.shipadd != null) {
  15226. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  15227. }
  15228. if ($scope.order.date instanceof Date) {
  15229. $scope.order.date = $scope.order.date.getTime();
  15230. }
  15231. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  15232. if ($scope.order.orderItems[i].delivery instanceof Date) {
  15233. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  15234. }
  15235. if ($scope.order.currency != 'RMB') {
  15236. $scope.order.orderItems[i].rate = 0;
  15237. }
  15238. }
  15239. $scope.order.status = 311;
  15240. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  15241. $scope.loading = false;
  15242. toaster.pop('success', '成功', '保存成功');
  15243. loadData();
  15244. }, function (response) {
  15245. $scope.loading = false;
  15246. toaster.pop('error', '保存失败', response.data);
  15247. });
  15248. };
  15249. // 立即购买
  15250. $scope.addToOrder = function (order) {
  15251. $scope.loading = true;
  15252. if (order.vendor.tel != null) {
  15253. $scope.order.vendusertel = order.vendor.tel;
  15254. }
  15255. if (order.vendor.venduser != null && order.vendor.tel != null) {
  15256. $scope.order.venduser = order.vendor.venduser + '' + order.vendor.tel;
  15257. }
  15258. if (order.shipadd != null) {
  15259. $scope.order.shipaddress = order.shipadd.address + order.shipadd.addressdet + '' + order.shipadd.receiver + '' + order.shipadd.usertel;
  15260. }
  15261. if ($scope.order.date instanceof Date) {
  15262. $scope.order.date = $scope.order.date.getTime();
  15263. }
  15264. for (var i = 0; i < $scope.order.orderItems.length; i++) {
  15265. if ($scope.order.orderItems[i].delivery instanceof Date) {
  15266. $scope.order.orderItems[i].delivery = $scope.order.orderItems[i].delivery.getTime();
  15267. }
  15268. if ($scope.order.currency != 'RMB') {
  15269. $scope.order.orderItems[i].rate = 0;
  15270. }
  15271. }
  15272. $scope.order.status = 200;
  15273. addtoCart.save({token: $scope.token}, $scope.order, function (data) {
  15274. $scope.loading = false;
  15275. toaster.pop('success', '成功', '保存成功');
  15276. window.location.hash = '#/purc/order/' + data.id;
  15277. }, function (response) {
  15278. $scope.loading = false;
  15279. toaster.pop('error', '保存失败', response.data);
  15280. });
  15281. };
  15282. // 新增收货地址保存
  15283. $scope.saveShipAddress = function (ship) {
  15284. ship.address = ship.province + ship.city + ship.district;
  15285. ShipAddress.saveAddress({}, ship, function (data) {
  15286. if (data.success) {
  15287. ShipAddress.shipAddList({}, function (data) {
  15288. $scope.ships = data;
  15289. $scope.order.shipadd = $scope.ships[0];
  15290. });
  15291. toaster.pop('success', '提示', data.success);
  15292. }
  15293. if (data.error) {
  15294. toaster.pop('error', '提示', data.error);
  15295. }
  15296. });
  15297. }
  15298. // 新增供应商联系人
  15299. $scope.addContact = function (uu) {
  15300. var modalInstance = $modal.open({
  15301. animation: true,
  15302. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  15303. controller: 'AddContacCtrl',
  15304. resolve: {}
  15305. });
  15306. modalInstance.result.then(function (data) {
  15307. $scope.contact = data;
  15308. $scope.contact.venduu = $scope.order.receiveCode;
  15309. Vendor.saveContact({}, $scope.contact, function (data) {
  15310. Vendor.contacts({venduu: $scope.order.receiveCode}, {}, function (data) {
  15311. $scope.contacts = data;
  15312. });
  15313. toaster.pop('success', '提示', '联系人保存成功');
  15314. }, function (response) {
  15315. toaster.pop('error', '失败', response.data);
  15316. });
  15317. });
  15318. }
  15319. }]);
  15320. /**
  15321. * 审批流
  15322. */
  15323. app.controller('approvalFlowCtrl', ['$scope', 'toaster', '$modal', 'appFlow', 'BaseService', function ($scope, toaster, $modal, appFlow, BaseService) {
  15324. BaseService.scrollBackToTop();
  15325. $scope.vacation = false;
  15326. $scope.workovertime = false;
  15327. $scope.workdaily = false;
  15328. $scope.feeplease = false;
  15329. $scope.signapp = false;
  15330. appFlow.viewAppFlow({}, function (data) {// 获取已设置的列表
  15331. $scope.nodes = data;
  15332. angular.forEach($scope.nodes, function (node) {
  15333. if (node.appname = '请假单') {
  15334. $scope.vacation = true;
  15335. }
  15336. if (node.appname = '加班单') {
  15337. $scope.workovertime = true;
  15338. }
  15339. if (node.appname = '工作日报') {
  15340. $scope.workdaily = true;
  15341. }
  15342. if (node.appname = '出差单') {
  15343. $scope.feeplease = true;
  15344. }
  15345. if (node.appname = '申诉单') {
  15346. $scope.signapp = true;
  15347. }
  15348. });
  15349. }, function (response) {
  15350. });
  15351. $scope.NoteSet = function () {
  15352. var modalInstance = $modal.open({
  15353. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15354. controller: 'NoteStep1Ctrl',
  15355. size: 'lg',
  15356. resolve: {
  15357. AppName: function () {
  15358. return '请假单';
  15359. }
  15360. }
  15361. });
  15362. modalInstance.result.then(function (data) {
  15363. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15364. if (data.error) {
  15365. toaster.pop('error', '提示', data.error);
  15366. }
  15367. if (data.success) {
  15368. toaster.pop('success', '提示', data.success);
  15369. }
  15370. }, function (response) {
  15371. });
  15372. }, function () {
  15373. });
  15374. }
  15375. $scope.overTimeSet = function () {
  15376. var modalInstance = $modal.open({
  15377. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15378. controller: 'NoteStep1Ctrl',
  15379. size: 'lg',
  15380. resolve: {
  15381. AppName: function () {
  15382. return '加班单';
  15383. }
  15384. }
  15385. });
  15386. modalInstance.result.then(function (data) {
  15387. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15388. if (data.error) {
  15389. toaster.pop('error', '提示', data.error);
  15390. }
  15391. if (data.success) {
  15392. toaster.pop('success', '提示', data.success);
  15393. }
  15394. }, function (response) {
  15395. });
  15396. }, function () {
  15397. });
  15398. }
  15399. $scope.feePleaseSet = function () {
  15400. var modalInstance = $modal.open({
  15401. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15402. controller: 'NoteStep1Ctrl',
  15403. size: 'lg',
  15404. resolve: {
  15405. AppName: function () {
  15406. return '出差单';
  15407. }
  15408. }
  15409. });
  15410. modalInstance.result.then(function (data) {
  15411. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15412. if (data.error) {
  15413. toaster.pop('error', '提示', data.error);
  15414. }
  15415. if (data.success) {
  15416. toaster.pop('success', '提示', data.success);
  15417. }
  15418. }, function (response) {
  15419. });
  15420. }, function () {
  15421. });
  15422. }
  15423. $scope.workDailySet = function () {
  15424. var modalInstance = $modal.open({
  15425. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15426. controller: 'NoteStep1Ctrl',
  15427. size: 'lg',
  15428. resolve: {
  15429. AppName: function () {
  15430. return '工作日报';
  15431. }
  15432. }
  15433. });
  15434. modalInstance.result.then(function (data) {
  15435. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15436. if (data.error) {
  15437. toaster.pop('error', '提示', data.error);
  15438. }
  15439. if (data.success) {
  15440. toaster.pop('success', '提示', data.success);
  15441. }
  15442. }, function (response) {
  15443. });
  15444. }, function () {
  15445. });
  15446. }
  15447. $scope.signAppSet = function () {
  15448. var modalInstance = $modal.open({
  15449. templateUrl: 'static/tpl/index/approvalFlow/step1.html',
  15450. controller: 'NoteStep1Ctrl',
  15451. size: 'lg',
  15452. resolve: {
  15453. AppName: function () {
  15454. return '申诉单';
  15455. }
  15456. }
  15457. });
  15458. modalInstance.result.then(function (data) {
  15459. appFlow.saveAppFlowSet({json: data}, {}, function (data) {
  15460. if (data.error) {
  15461. toaster.pop('error', '提示', data.error);
  15462. }
  15463. if (data.success) {
  15464. toaster.pop('success', '提示', data.success);
  15465. }
  15466. }, function (response) {
  15467. });
  15468. }, function () {
  15469. });
  15470. }
  15471. }]);
  15472. /**
  15473. * 审核条件设置
  15474. */
  15475. app.controller('NoteStep1Ctrl', ['$scope', 'toaster', '$modalInstance', 'appFlow', 'AppName', '$filter', '$rootScope', function ($scope, toaster, $modalInstance, appFlow, AppName, $filter, $rootScope) {
  15476. $scope.appName = AppName;// 标题名称
  15477. $scope.AppFlow = {
  15478. appName: $scope.appName,
  15479. appNodes: {}
  15480. };
  15481. $scope.AppFlow.appNodes = [];
  15482. appFlow.getNodeByName({name: AppName}, {}, function (data) {// 通过单据名称查询单个审批流
  15483. if (data.appNodes.length != 0) {
  15484. $scope.node = data;
  15485. $scope.AppFlow = data;
  15486. }
  15487. }, function () {
  15488. });
  15489. $scope.copy = function () {//复制
  15490. $rootScope.flowcopy = angular.copy($scope.AppFlow);
  15491. toaster.pop('info', '提示', '复制成功');
  15492. $modalInstance.dismiss();
  15493. }
  15494. $scope.paste = function () {
  15495. $scope.AppFlow = {appName: $scope.appName, appNodes: {}};
  15496. $scope.AppFlow.appNodes = $rootScope.flowcopy.appNodes;
  15497. }
  15498. $scope.clear = function () {// 清空
  15499. $scope.AppFlow = {
  15500. appName: $scope.appName,
  15501. appNodes: {}
  15502. };
  15503. $scope.AppFlow.appNodes = [];
  15504. }
  15505. appFlow.getPositions({}, function (data) {// 获取人员信息
  15506. $scope.users = data;
  15507. }, function (response) {
  15508. });
  15509. appFlow.getPositionInfo({}, function (data) { // 获取职位信息
  15510. $scope.roles = data;
  15511. }, function (response) {
  15512. });
  15513. $scope.SelectUser = function (data) { // 添加人员
  15514. var item = {
  15515. useruu: null,
  15516. username: null,
  15517. level: null
  15518. };
  15519. item.useruu = data.useruu;
  15520. item.username = data.username;
  15521. $scope.AppFlow.appNodes.push(item);
  15522. }
  15523. $scope.SelectRole = function (data) {// 添加职位
  15524. var item = {
  15525. position: null,
  15526. level: null
  15527. };
  15528. item.position = data;
  15529. $scope.AppFlow.appNodes.push(item);
  15530. }
  15531. $scope.deleteNode = function (index) {// 删除节点
  15532. $scope.AppFlow.appNodes.splice(index, 1);
  15533. };
  15534. $scope.saveNode = function () { // 保存
  15535. angular.forEach($scope.AppFlow.appNodes, function (value, key) {
  15536. $scope.AppFlow.appNodes[key].level = key;
  15537. });
  15538. if ($scope.AppFlow.appNodes.length == 0) {
  15539. toaster.pop('info', '提示', '您还未设置审批人');
  15540. } else {
  15541. $modalInstance.close($scope.AppFlow);
  15542. }
  15543. ;
  15544. };
  15545. $scope.cancel = function () {// 取消
  15546. $modalInstance.dismiss();
  15547. }
  15548. }]);
  15549. /***
  15550. * 代采定单
  15551. */
  15552. app.controller('DeputyOrderCtrl', ['$scope', 'toaster', 'getDeOrder', 'ngTableParams', 'BaseService', 'DeputyOrder', 'ReportService', 'getOrderInfo', '$modal', 'CurrentRole', function ($scope, toaster, getDeOrder, ngTableParams, BaseService, DeputyOrder, ReportService, getOrderInfo, $modal, CurrentRole) {
  15553. BaseService.scrollBackToTop();
  15554. // 获取当前用户是否为普通用户
  15555. CurrentRole.isUser({}, {}, function (data) {
  15556. $scope.isUser = data.isUser;
  15557. });
  15558. $scope.active = 'all';
  15559. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  15560. $scope.total = null;
  15561. $scope.setActive = function (state) {
  15562. if ($scope.active != state) {
  15563. $scope.active = state;
  15564. if ($scope.tableParams.page() == 1)
  15565. $scope.tableParams.reload();
  15566. else
  15567. $scope.tableParams.page(1);
  15568. }
  15569. };
  15570. $scope.agreedText = '全部';
  15571. $scope.dateZoneText = '不限';
  15572. $scope.condition = {dateZone: 1};
  15573. /* 时间筛选初始化*/
  15574. var fromDate = new Date();
  15575. var toDate = new Date();
  15576. fromDate.setMonth(fromDate.getMonth() - 1);
  15577. fromDate.setHours(0, 0, 0, 0);
  15578. toDate.setHours(23, 59, 59, 999);
  15579. $scope.condition.dateFrom = fromDate;
  15580. $scope.condition.dateTo = toDate;
  15581. $scope.changeDateZone = function (zone) {
  15582. $scope.condition.dateZone = zone;
  15583. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  15584. $scope.condition.$dateZoneOpen = false;
  15585. getDateCondition(zone, $scope.condition);
  15586. $scope.tableParams.page(1);
  15587. $scope.tableParams.reload();
  15588. };
  15589. $scope.openDatePicker = function ($event, item, openParam) {
  15590. $event.preventDefault();
  15591. $event.stopPropagation();
  15592. item[openParam] = !item[openParam];
  15593. };
  15594. $scope.openFilterDatePicker = function ($event, item, openParam) {
  15595. $event.preventDefault();
  15596. $event.stopPropagation();
  15597. item[openParam] = !item[openParam];
  15598. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  15599. $scope.tableParams.reload();
  15600. }
  15601. };
  15602. $scope.searchMethod = false;
  15603. var getSerivce = function() {
  15604. return $scope.searchMethod ? getDeOrder : getOrderInfo;
  15605. }
  15606. getSerivce();
  15607. // 获取订单总金额
  15608. var getOrdersAmount = function() {
  15609. DeputyOrder.odersAmount({}, function(data) {
  15610. $scope.odersAmount = data.amount;
  15611. });
  15612. }
  15613. getOrdersAmount();
  15614. $scope.tableParams = new ngTableParams({
  15615. page: 1,
  15616. count: 20,
  15617. sorting: {'date': 'desc', 'id': 'desc'}
  15618. }, {
  15619. total: 0,
  15620. counts: [5, 10, 25, 50],
  15621. getData: function ($defer, params) {
  15622. $scope.loading = true;
  15623. var pageParams = params.url();
  15624. pageParams.searchFilter = {
  15625. keyword: $scope.keyword,
  15626. fromDate: getDateTime($scope.condition.dateFrom),
  15627. endDate: getDateTime($scope.condition.dateTo)
  15628. };
  15629. getSerivce()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  15630. $scope.loading = false;
  15631. if (page) {
  15632. params.total(page.totalElement);
  15633. $scope.total = page.totalElement;
  15634. $defer.resolve(page.content);
  15635. $scope.keywordXls = angular.copy(pageParams.searchFilter.keyword);//保存当前取值的关键词
  15636. }
  15637. }, function (response) {
  15638. $scope.loading = false;
  15639. toaster.pop('error', '数据加载失败', response.data);
  15640. });
  15641. }
  15642. });
  15643. //打印
  15644. $scope.print = function (deputyOrder) {
  15645. DeputyOrder.printCount({id: deputyOrder.id}, {});//增加打印此次
  15646. $scope.tableParams.reload();
  15647. ReportService.print(deputyOrder.deputyuu, 'PURCNOTICE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 定向采购通知
  15648. ReportService.print(deputyOrder.deputyuu, 'PURCHASE', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 采购订单
  15649. ReportService.print(deputyOrder.deputyuu, 'PAYCONFIRM', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 付款确认
  15650. ReportService.print(deputyOrder.deputyuu, 'TRADECONTRACT', "where purc$deputyorders.deo_id=" + deputyOrder.id); // 买卖合同
  15651. };
  15652. // 搜索框回车
  15653. $scope.onSearch = function (keyword) {
  15654. // 每次搜索重置获取数据方法
  15655. $scope.searchMethod = false;
  15656. if(keyword != null && keyword != '') {
  15657. $scope.searchMethod = true;
  15658. }
  15659. $scope.tableParams.page(1);
  15660. $scope.tableParams.reload();
  15661. };
  15662. // 复制采购单
  15663. $scope.copyorder = function (id) {
  15664. $scope.loading = true;
  15665. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  15666. $scope.loading = false;
  15667. if (data.id) {
  15668. toaster.pop('success', '提示', '复制生成单据成功');
  15669. window.location.hash = "#/purc/deputy/" + data.id;
  15670. }
  15671. if (data.error) {
  15672. toaster.pop('error', '提示', '保存失败');
  15673. }
  15674. }, function (response) {
  15675. $scope.loading = false;
  15676. toaster.pop('error', '提示', response.data);
  15677. });
  15678. }
  15679. // 删除代采订单
  15680. $scope.clear = function (id) {
  15681. $scope.loading = true;
  15682. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  15683. if (data.success) {
  15684. toaster.pop('success', '提示', data.success);
  15685. $scope.tableParams.reload();
  15686. }
  15687. $scope.loading = false;
  15688. }, function (response) {
  15689. $scope.loading = false;
  15690. toaster.pop('error', '提示', response.data);
  15691. });
  15692. }
  15693. $scope.viewApprove = function(salecode, uu) {
  15694. var modalInstance = $modal.open({
  15695. templateUrl: 'static/tpl/index/purc/modal/approval_detail.html',
  15696. controller: 'ViewApprovalDetailCtrl',
  15697. resolve: {
  15698. uu: function () {
  15699. return uu
  15700. },
  15701. salecode: function () {
  15702. return salecode
  15703. }
  15704. }
  15705. });
  15706. }
  15707. }]);
  15708. // 查询代采定单在信扬中的审批情况
  15709. app.controller('ViewApprovalDetailCtrl', ['$scope', 'toaster', '$modalInstance', 'DeputyOrder', 'BaseService', 'ngTableParams', 'uu', 'salecode', function ($scope, toaster, $modalInstance, DeputyOrder, BaseService, ngTableParams, uu, salecode) {
  15710. DeputyOrder.approve({uu: uu, code: salecode}, {}, function (data) {
  15711. $scope.nodes = data.nodes;
  15712. $scope.process = data.process;
  15713. if(data.error) {
  15714. toaster.pop('error', '提示', data.error);
  15715. }
  15716. }, function (response) {
  15717. toaster.pop('error', '提示', '暂未获取到相关单据的信息');
  15718. });
  15719. $scope.cancel = function () {
  15720. $modalInstance.dismiss();
  15721. };
  15722. $scope.select = function (company) { // 直接选择
  15723. $modalInstance.close(company);
  15724. }
  15725. }]);
  15726. /**
  15727. * 新增代采订单
  15728. */
  15729. app.controller('NewDeputyOrderCtrl', ['$scope', 'toaster', '$modal', 'DeputyOrder', '$filter', 'ngTableParams', 'BaseService', 'DecimalNumber', 'DekeyValue', function ($scope, toaster, $modal, DeputyOrder, $filter, ngTableParams, BaseService, DecimalNumber, DekeyValue) {
  15730. BaseService.scrollBackToTop();
  15731. //默认采购单号不重复
  15732. $scope.orderCodeEnable = true;
  15733. $scope.deOrder = {
  15734. code: 'DC' + $filter('date')(new Date(), 'yyMMddHHmmss_sss'),
  15735. entrydate: new Date(),
  15736. status: '在录入',
  15737. goodspacking: '供应商原厂包装,如外包装完好视为货物完好',
  15738. pickupdate: '我方自向贵公司支付货款之日起3个自然日内提货完毕',
  15739. riskmethod: '甲方承担',
  15740. taxpaymentmethod: '甲方承担',
  15741. totalamount: 0,
  15742. totalpayament: 0,
  15743. orderamount: 0,
  15744. usdpayment: 0
  15745. };
  15746. $scope.deOrder.deputyOrderItems = [];
  15747. var item = {
  15748. prodname: null,
  15749. prodcode: null,
  15750. prodspec: null,
  15751. amount: null,
  15752. unitprice: null,
  15753. purcprice: null,
  15754. remark: null,
  15755. orderprice: null,
  15756. };
  15757. $scope.deOrder.deputyOrderItems.push(item);
  15758. // 代采企业列表
  15759. DeputyOrder.deputyEnterprise({}, function (data) {
  15760. $scope.deputyEnterprises = data;
  15761. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  15762. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  15763. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  15764. });
  15765. var getPayMethod = function(enuu, key) {
  15766. // 获取我方付款支付方式默认值
  15767. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  15768. $scope.methods = data.content;
  15769. });
  15770. }
  15771. // 更新名称时后台更改uu号
  15772. $scope.change = function (deputyname) {
  15773. DeputyOrder.deputyEnterprise({}, function (data) {
  15774. $scope.deputyEn = data;
  15775. angular.forEach($scope.deputyEn, function (en) {
  15776. if (deputyname == en.deputyenname) {
  15777. $scope.deputyuu = en.deputyenuu;
  15778. getPayMethod($scope.deputyuu, 'paymentmethod');
  15779. }
  15780. });
  15781. });
  15782. }
  15783. // 查找付款企业
  15784. $scope.dbfindPayCompany = function (deputyuu) {
  15785. var modalInstance = $modal.open({
  15786. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  15787. controller: 'DbfindDeputyPayCompanyCtrl',
  15788. resolve: {
  15789. deputyuu: function () {
  15790. return deputyuu
  15791. }
  15792. }
  15793. });
  15794. modalInstance.result.then(function (data) {
  15795. $scope.deOrder.paycomname = data.enname;
  15796. $scope.deOrder.paycomaddress = data.address;
  15797. })
  15798. }
  15799. // 查询上次的关键词记录
  15800. $scope.getHisKeyword = function (tervendor) {
  15801. DeputyOrder.hisKeywords({tervendor: tervendor}, {}, function (data) {
  15802. $scope.deOrder.vendtel = data.vendtel;
  15803. $scope.deOrder.venduser = data.venduser;
  15804. $scope.deOrder.otherdata = data.otherdata;
  15805. $scope.deOrder.companyname = data.companyname;
  15806. $scope.deOrder.bankaccount = data.bankaccount;
  15807. $scope.deOrder.bankaddress = data.bankaddress;
  15808. $scope.deOrder.bankcode = data.bankcode;
  15809. $scope.deOrder.bankname = data.bankname;
  15810. $scope.deOrder.legalrepresent = data.legalrepresent;
  15811. $scope.deOrder.tervendaddress = data.tervendaddress;
  15812. $scope.deOrder.enfax = data.enfax;
  15813. $scope.deOrder.deliverymethod = data.deliverymethod;
  15814. }, function (response) {
  15815. toaster.pop('error', '提示', response.data);
  15816. });
  15817. }
  15818. // 查询历史供应商
  15819. DeputyOrder.hisvendors({}, function (data) {
  15820. $scope.hisvendors = data;
  15821. }, function (response) {
  15822. toaster.pop('error', '提示', response.data);
  15823. });
  15824. // 上次填写记录(不关联供应商)
  15825. DeputyOrder.lastKeywords({}, function (data) {
  15826. $scope.lastkeyowrds = data;
  15827. $scope.deOrder.madealdate = $scope.lastkeyowrds.madealdate;
  15828. $scope.deOrder.madealcode = $scope.lastkeyowrds.madealcode;
  15829. }, function (response) {
  15830. toaster.pop('error', '提示', response.data);
  15831. });
  15832. //增加商品
  15833. $scope.add = function (index) {
  15834. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  15835. toaster.pop('info', '提示', '请先填写商品信息');
  15836. } else {
  15837. $scope.deOrder.deputyOrderItems.push(
  15838. {
  15839. prodname: null,
  15840. prodcode: null,
  15841. prodspec: null,
  15842. prodbrand: null,
  15843. amount: null,
  15844. unitprice: null,
  15845. purcprice: null,
  15846. remark: null,
  15847. orderprice: null
  15848. });
  15849. }
  15850. };
  15851. //删除商品
  15852. $scope.del = function (index) {
  15853. $scope.deOrder.deputyOrderItems.splice(index, 1);
  15854. };
  15855. // 导入商品信息
  15856. $scope.uplodaByBatch = function () {
  15857. var modalInstance = $modal.open({
  15858. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  15859. controller: 'DeputyOrderUploadCtrl',
  15860. size: 'lg',
  15861. resolve: {}
  15862. });
  15863. modalInstance.result.then(function (data) {
  15864. angular.forEach(data, function (data) {
  15865. $scope.deOrder.deputyOrderItems.push(data);
  15866. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  15867. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  15868. $scope.deOrder.deputyOrderItems.splice(i, 1);
  15869. }
  15870. }
  15871. })
  15872. $scope.deOrder.totalamount = 0;
  15873. $scope.deOrder.usdpayment = 0;
  15874. $scope.deOrder.orderamount = 0;
  15875. $scope.deOrder.totalpayament = 0;
  15876. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15877. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15878. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15879. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15880. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15881. });
  15882. }, function () {
  15883. });
  15884. }
  15885. // 查找供应商
  15886. $scope.dbfindVendor = function (deputyuu) {
  15887. var modalInstance = $modal.open({
  15888. templateUrl: 'static/tpl/index/purc/modal/purc_order_vendor.html',
  15889. controller: 'DbfindDeputyVendorInfoCtrl',
  15890. size: 'lg',
  15891. resolve: {
  15892. deputyuu: function () {
  15893. return deputyuu
  15894. }
  15895. }
  15896. });
  15897. modalInstance.result.then(function (data) {
  15898. $scope.deOrder.customer = data.vendorEnterprise.enName;
  15899. $scope.deOrder.legalrepresent = data.vendorUser.userName;
  15900. $scope.deOrder.enaddress = data.vendorEnterprise.enAddress;
  15901. $scope.deOrder.usertel = data.vendorUser.userTel;
  15902. })
  15903. }
  15904. // 检验订单编号是否存在
  15905. $scope.checkOrder = function (salecode, deputyuu) {
  15906. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  15907. $scope.orderCodeEnable = true;
  15908. if (data.info) {
  15909. toaster.pop('error', '提示', data.info);
  15910. $scope.orderCodeEnable = false;
  15911. }
  15912. }, function (response) {
  15913. toaster.pop('error', '提示', response.data);
  15914. })
  15915. }
  15916. //计算采购单价
  15917. $scope.checkPrice = function (rate) {
  15918. $scope.deOrder.totalamount = 0;
  15919. $scope.deOrder.usdpayment = 0;
  15920. $scope.deOrder.orderamount = 0;
  15921. $scope.deOrder.totalpayament = 0;
  15922. if (rate == null) {
  15923. toaster.pop('info', '提示', '请先填入税率');
  15924. } else {
  15925. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15926. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  15927. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15928. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15929. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15930. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15931. });
  15932. }
  15933. }
  15934. // 获取订单总价
  15935. $scope.totalPrice = function () {
  15936. $scope.deOrder.totalamount = 0;
  15937. $scope.deOrder.usdpayment = 0;
  15938. $scope.deOrder.orderamount = 0;
  15939. $scope.deOrder.totalpayament = 0;
  15940. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  15941. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  15942. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  15943. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  15944. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  15945. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  15946. }
  15947. });
  15948. }
  15949. $scope.checkresult = false;
  15950. var checkKeyword = function () {
  15951. if ($scope.deOrder.madealdate == null) {
  15952. toaster.pop('info', '提示', '主协议签订日期未选择');
  15953. } else if ($scope.deOrder.madealcode == null) {
  15954. toaster.pop('info', '提示', '主协议签订编号未填写');
  15955. } else if ($scope.deOrder.tervendor == null) {
  15956. toaster.pop('info', '提示', '终端供应商名称未填写');
  15957. } else if ($scope.deOrder.vendtel == null) {
  15958. toaster.pop('info', '提示', '电话号码未填写');
  15959. } else if ($scope.deOrder.venduser == null) {
  15960. toaster.pop('info', '提示', '联系人未填写');
  15961. } else if ($scope.deOrder.shipdate == null) {
  15962. toaster.pop('info', '提示', '供应商发货时间未选择');
  15963. } else if ($scope.deOrder.goodspacking == null) {
  15964. toaster.pop('info', '提示', '货物包装要求未填写');
  15965. } else if ($scope.deOrder.deliverymethod == null) {
  15966. toaster.pop('info', '提示', '供应商交货方式未填写');
  15967. } else if ($scope.deOrder.pickupmethod == null) {
  15968. toaster.pop('info', '提示', '我方提货方式未填写');
  15969. } else if ($scope.deOrder.paymentmethod == null) {
  15970. toaster.pop('info', '提示', '我方付款方式未填写');
  15971. } else if ($scope.deOrder.pickupdate == null) {
  15972. toaster.pop('info', '提示', '我方提货时间未选择');
  15973. } else if ($scope.deOrder.currency == null) {
  15974. toaster.pop('info', '提示', '交易币别未选择');
  15975. } else if ($scope.deOrder.deputyuu == null) {
  15976. toaster.pop('info', '提示', '代采企业未选择');
  15977. } else if ($scope.deOrder.salecode == null) {
  15978. toaster.pop('info', '提示', '订单编号未填写');
  15979. } else if ($scope.deOrder.paydeldate == null) {
  15980. toaster.pop('info', '提示', '我方付款提货时间未选择');
  15981. } else if ($scope.deOrder.riskmethod == null) {
  15982. toaster.pop('info', '提示', '风险承担方式未填写');
  15983. } else if ($scope.deOrder.taxpaymentmethod == null) {
  15984. toaster.pop('info', '提示', '运、税费承担方式');
  15985. } else if ($scope.deOrder.tervendaddress == null) {
  15986. toaster.pop('info', '提示', '终端供应商地址未填写');
  15987. } else if ($scope.deOrder.companyname == null) {
  15988. toaster.pop('info', '提示', '公司全称(英文)未填写');
  15989. } else if ($scope.deOrder.requirepaydate == null) {
  15990. toaster.pop('info', '提示', '要求付汇日期未选择');
  15991. } else if ($scope.deOrder.bankname == null) {
  15992. toaster.pop('info', '提示', '银行名称(英文)未填写');
  15993. } else if ($scope.deOrder.bankaccount == null) {
  15994. toaster.pop('info', '提示', '银行账号未填写');
  15995. } else if ($scope.deOrder.bankaddress == null) {
  15996. toaster.pop('info', '提示', '银行地址未填写');
  15997. } else if ($scope.deOrder.bankcode == null) {
  15998. toaster.pop('info', '提示', '银行代码未填写');
  15999. } else if ($scope.deOrder.salepocode == null) {
  16000. toaster.pop('info', '提示', '合同编号未填写');
  16001. } else if ($scope.deOrder.legalrepresent == null) {
  16002. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  16003. } else if ($scope.deOrder.paycomname == null) {
  16004. toaster.pop('info', '提示', '付款公司未填写');
  16005. } else if ($scope.deOrder.paycomaddress == null) {
  16006. toaster.pop('info', '提示', '付款公司地址未填写');
  16007. } else if ($scope.deOrder.enfax == null) {
  16008. toaster.pop('info', '提示', '供应商方法人电话未填写');
  16009. } else if ($scope.deOrder.paydate == null) {
  16010. toaster.pop('info', '提示', '货款支付时间未选择');
  16011. } else if ($scope.deOrder.paymethod == null) {
  16012. toaster.pop('info', '提示', '货款支付方式未填写');
  16013. } else if ($scope.deOrder.deliverydate == null) {
  16014. toaster.pop('info', '提示', '交货时间未选择');
  16015. } else if (!$scope.orderCodeEnable) {
  16016. toaster.pop('info', '提示', '采购单号重复');
  16017. } else if ($scope.deOrder.totalpayament >= 3000000) {
  16018. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金,');
  16019. } else {
  16020. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  16021. if (orderitem.prodname == null) {
  16022. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  16023. } else if (orderitem.prodcode == null) {
  16024. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  16025. } else if (orderitem.prodspec == null) {
  16026. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  16027. } else if (orderitem.prodbrand == null) {
  16028. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  16029. } else if (orderitem.amount == null) {
  16030. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  16031. } else if (orderitem.unitprice == null) {
  16032. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  16033. } else if (orderitem.purcprice == null) {
  16034. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  16035. } else {
  16036. $scope.checkresult = true;
  16037. $scope.isSave = true;
  16038. }
  16039. })
  16040. };
  16041. }
  16042. // 保存
  16043. $scope.isSave = false;
  16044. $scope.save = function (status) {
  16045. $scope.deOrder.entrystatus = status;
  16046. checkKeyword();
  16047. if ($scope.checkresult) {
  16048. $scope.deOrder.totalamount = 0;
  16049. $scope.deOrder.usdpayment = 0;
  16050. $scope.deOrder.orderamount = 0;
  16051. $scope.deOrder.totalpayament = 0;
  16052. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16053. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16054. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16055. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16056. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16057. });
  16058. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  16059. toaster.pop('info', '提示', '您还未填写任何商品信息');
  16060. } else {
  16061. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  16062. if (data.id) {
  16063. toaster.pop('success', '提示', status + '成功');
  16064. window.location.hash = "#/purc/deputy/" + data.id;
  16065. }
  16066. if (data.error) {
  16067. toaster.pop('error', '提示', status + '失败');
  16068. }
  16069. }, function (response) {
  16070. });
  16071. }
  16072. }
  16073. }
  16074. $scope.openDatePicker = function ($event, deOrder, openParam) {
  16075. $event.preventDefault();
  16076. $event.stopPropagation();
  16077. deOrder[openParam] = !deOrder[openParam];
  16078. };
  16079. }]);
  16080. // 代采企业供应商
  16081. app.controller('DbfindDeputyVendorInfoCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  16082. $scope.prod = false;
  16083. BaseService.scrollBackToTop();
  16084. // 搜索框回车
  16085. $scope.onSearch = function (keyword) {
  16086. $scope.keyword = keyword;
  16087. $scope.customerParams.page(1);
  16088. $scope.customerParams.reload();
  16089. };
  16090. $scope.customerParams = new ngTableParams({
  16091. page: 1,
  16092. count: 20
  16093. }, {
  16094. total: 0,
  16095. counts: [5, 10, 25, 50],
  16096. getData: function ($defer, params) {
  16097. $scope.loading = true;
  16098. var pageParams = params.url();
  16099. pageParams.keyword = $scope.keyword;
  16100. pageParams.enuu = deputyuu;
  16101. DeputyOrder.vendors.call(null, BaseService.parseParams(pageParams), function (page) {
  16102. $scope.loading = false;
  16103. if (page) {
  16104. params.total(page.totalElement);
  16105. $defer.resolve(page.content);
  16106. }
  16107. $scope.totalCount = page.totalElement;
  16108. }, function (response) {
  16109. $scope.loading = false;
  16110. toaster.pop('error', '数据加载失败', response.data);
  16111. });
  16112. }
  16113. });
  16114. $scope.cancel = function () {
  16115. $modalInstance.dismiss();
  16116. };
  16117. $scope.checkVendor = function (vendor) { // 直接选择
  16118. $modalInstance.close(vendor);
  16119. }
  16120. }]);
  16121. // 代采企业付款企业
  16122. app.controller('DbfindDeputyPayCompanyCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', 'deputyuu', 'DeputyOrder', 'BaseService', 'ngTableParams', function ($scope, toaster, $upload, $modalInstance, deputyuu, DeputyOrder, BaseService, ngTableParams) {
  16123. DeputyOrder.paycompanies({enuu: deputyuu}, {}, function (data) {
  16124. $scope.paycompanies = data;
  16125. }, function (response) {
  16126. toaster.pop('error', '提示', response.data);
  16127. });
  16128. $scope.cancel = function () {
  16129. $modalInstance.dismiss();
  16130. };
  16131. $scope.select = function (company) { // 直接选择
  16132. $modalInstance.close(company);
  16133. }
  16134. }]);
  16135. /**
  16136. * 代采订单批量导入
  16137. */
  16138. app.controller('DeputyOrderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  16139. // 通过excel批量上传物料
  16140. $scope.result = null;
  16141. $scope.upload = function () {
  16142. var file = $scope.myFiles[0];
  16143. $upload.upload({
  16144. url: 'deputyOrder/release/excel',
  16145. file: file,
  16146. method: 'POST'
  16147. }).success(function (data) {
  16148. $scope.result = data;
  16149. $scope.success = $scope.result.success;
  16150. $scope.total = $scope.result.total;
  16151. $scope.alters = $scope.result.alters;
  16152. }).error(function (response) {
  16153. toaster.pop('error', response.data || response);
  16154. });
  16155. };
  16156. // 查看范例
  16157. $scope.showImg = function () {
  16158. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  16159. box.show();
  16160. box.find('img').attr('src', src);
  16161. box.find('a').click(function () {
  16162. box.hide();
  16163. });
  16164. box.dblclick(function () {
  16165. box.hide();
  16166. });
  16167. };
  16168. // 下载模板
  16169. $scope.download = function () {
  16170. window.location.href = 'deputyOrder/upload/template';
  16171. };
  16172. $scope.enSure = function () {
  16173. $modalInstance.close($scope.result.items);
  16174. }
  16175. $scope.cancel = function () {
  16176. $modalInstance.dismiss();
  16177. }
  16178. }]);
  16179. /**
  16180. * 代采详情
  16181. */
  16182. app.controller('DeputyOrderDetailCtrl', ['$scope', 'toaster', 'DeputyOrder', '$stateParams', 'ngTableParams', 'BaseService', '$modal', 'DecimalNumber', 'CurrentRole', 'DekeyValue', function ($scope, toaster, DeputyOrder, $stateParams, ngTableParams, BaseService, $modal, DecimalNumber, CurrentRole, DekeyValue) {
  16183. BaseService.scrollBackToTop();
  16184. // 获取当前用户是否为普通用户
  16185. CurrentRole.isUser({}, {}, function (data) {
  16186. $scope.isUser = data.isUser;
  16187. });
  16188. var loadData = function () {
  16189. DeputyOrder.getOrderDetail({id: $stateParams.id}, {}, function (data) {
  16190. $scope.deOrder = data;
  16191. $scope.deOrder.$editing = true;
  16192. }, function (response) {
  16193. toaster.pop('error', '提示', response.data);
  16194. });
  16195. };
  16196. loadData();
  16197. //默认采购单号不重复
  16198. $scope.orderCodeEnable = true;
  16199. // 查询历史供应商
  16200. DeputyOrder.hisvendors({}, function (data) {
  16201. $scope.hisvendors = data;
  16202. }, function (response) {
  16203. toaster.pop('error', '提示', response.data);
  16204. });
  16205. // 代采企业列表
  16206. DeputyOrder.deputyEnterprise({}, function (data) {
  16207. $scope.deputyEnterprises = data;
  16208. $scope.deOrder.deputyname = $scope.deputyEnterprises[0].deputyenname;
  16209. $scope.deOrder.deputyuu = $scope.deputyEnterprises[0].deputyenuu;
  16210. getPayMethod($scope.deOrder.deputyuu, 'paymentmethod');
  16211. });
  16212. var getPayMethod = function(enuu, key) {
  16213. // 获取我方付款支付方式默认值
  16214. DekeyValue.getValue({enuu: enuu, key: key}, function(data) {
  16215. $scope.methods = data.content;
  16216. });
  16217. }
  16218. // 更新代采企业时更新费率
  16219. $scope.change = function (deputyname) {
  16220. DeputyOrder.deputyEnterprise({}, function (data) {
  16221. $scope.deputyEn = data;
  16222. angular.forEach($scope.deputyEn, function (en) {
  16223. if (deputyname == en.deputyenname) {
  16224. $scope.deputyuu = en.deputyenuu;
  16225. getPayMethod($scope.deputyuu, 'paymentmethod');
  16226. }
  16227. });
  16228. });
  16229. }
  16230. // 查找付款企业
  16231. $scope.dbfindPayCompany = function (deputyuu) {
  16232. var modalInstance = $modal.open({
  16233. templateUrl: 'static/tpl/index/purc/modal/payCompany.html',
  16234. controller: 'DbfindDeputyPayCompanyCtrl',
  16235. resolve: {
  16236. deputyuu: function () {
  16237. return deputyuu
  16238. }
  16239. }
  16240. });
  16241. modalInstance.result.then(function (data) {
  16242. $scope.deOrder.paycomname = data.enname;
  16243. $scope.deOrder.paycomaddress = data.address;
  16244. })
  16245. }
  16246. // 删除明细
  16247. $scope.del = function (index, id) {
  16248. DeputyOrder.deleteProdById({id: id}, {}, function (data) {
  16249. if (data.success) {
  16250. toaster.pop('success', '提示', data.success);
  16251. $scope.deOrder.deputyOrderItems.splice(index, 1)
  16252. }
  16253. if (data.error) {
  16254. toaster.pop('error', '提示', data.error);
  16255. }
  16256. $scope.deOrder.totalamount = 0;
  16257. $scope.deOrder.usdpayment = 0;
  16258. $scope.deOrder.orderamount = 0;
  16259. $scope.deOrder.totalpayament = 0;
  16260. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16261. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16262. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16263. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16264. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16265. });
  16266. }, function (response) {
  16267. toaster.pop('error', '提示', response.data);
  16268. });
  16269. }
  16270. //增加商品
  16271. $scope.add = function (index) {
  16272. if ($scope.deOrder.deputyOrderItems[index].prodcode == null) {
  16273. toaster.pop('info', '提示', '请先填写商品信息');
  16274. } else {
  16275. $scope.deOrder.deputyOrderItems.push(
  16276. {
  16277. prodname: null,
  16278. prodcode: null,
  16279. prodspec: null,
  16280. prodbrand: null,
  16281. amount: null,
  16282. unitprice: null,
  16283. remark: null,
  16284. orderprice: null
  16285. });
  16286. }
  16287. };
  16288. // 导入商品信息
  16289. $scope.uplodaByBatch = function () {
  16290. var modalInstance = $modal.open({
  16291. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  16292. controller: 'DeputyOrderUploadCtrl',
  16293. size: 'lg',
  16294. resolve: {}
  16295. });
  16296. modalInstance.result.then(function (data) {
  16297. angular.forEach(data, function (data) {
  16298. $scope.deOrder.deputyOrderItems.push(data);
  16299. for (var i = 0; i < $scope.deOrder.deputyOrderItems.length; i++) {
  16300. if ($scope.deOrder.deputyOrderItems[i].prodname == null) { // 如果没有填写就删除这行数据
  16301. $scope.deOrder.deputyOrderItems.splice(i, 1);
  16302. }
  16303. }
  16304. })
  16305. $scope.deOrder.totalamount = 0;
  16306. $scope.deOrder.usdpayment = 0;
  16307. $scope.deOrder.orderamount = 0;
  16308. $scope.deOrder.totalpayament = 0;
  16309. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16310. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16311. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16312. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16313. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16314. });
  16315. }, function () {
  16316. });
  16317. }
  16318. //删除商品
  16319. $scope.delItem = function (index) {
  16320. $scope.deOrder.deputyOrderItems.splice(index, 1);
  16321. };
  16322. var getService = function () {
  16323. return DeputyOrder.getProdList;
  16324. };
  16325. $scope.update = function () {
  16326. $scope.deOrder.$editing = true;
  16327. }
  16328. $scope.cancel = function () {
  16329. $scope.deOrder.$editing = false;
  16330. }
  16331. // 检验订单编号是否存在
  16332. $scope.checkOrder = function (salecode, deputyuu) {
  16333. DeputyOrder.checkOrders({salecode: salecode, deputyuu: deputyuu}, {}, function (data) {
  16334. $scope.orderCodeEnable = true;
  16335. if (data.info) {
  16336. toaster.pop('error', '提示', data.info);
  16337. $scope.orderCodeEnable = false;
  16338. }
  16339. }, function (response) {
  16340. toaster.pop('error', '提示', response.data);
  16341. })
  16342. }
  16343. //计算采购单价
  16344. $scope.checkPrice = function (rate) {
  16345. $scope.deOrder.totalamount = 0;
  16346. $scope.deOrder.usdpayment = 0;
  16347. $scope.deOrder.orderamount = 0;
  16348. $scope.deOrder.totalpayament = 0;
  16349. if (rate == null) {
  16350. toaster.pop('info', '提示', '请先填入税率');
  16351. } else {
  16352. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16353. item.purcprice = DecimalNumber.accMul(item.unitprice, (1 + rate / 100));
  16354. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16355. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16356. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16357. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16358. });
  16359. }
  16360. }
  16361. // 获取订单总价
  16362. $scope.totalPrice = function () {
  16363. $scope.deOrder.totalamount = 0;
  16364. $scope.deOrder.usdpayment = 0;
  16365. $scope.deOrder.orderamount = 0;
  16366. $scope.deOrder.totalpayament = 0;
  16367. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16368. if(item.amount != null && item.unitprice != null && item.purcprice != null) {
  16369. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16370. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16371. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16372. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16373. }
  16374. });
  16375. }
  16376. $scope.checkresult = false;
  16377. var checkKeyword = function () {
  16378. if ($scope.deOrder.madealdate == null) {
  16379. toaster.pop('info', '提示', '主协议签订日期未选择');
  16380. } else if ($scope.deOrder.madealcode == null) {
  16381. toaster.pop('info', '提示', '主协议签订编号未填写');
  16382. } else if ($scope.deOrder.tervendor == null) {
  16383. toaster.pop('info', '提示', '终端供应商名称未填写');
  16384. } else if ($scope.deOrder.vendtel == null) {
  16385. toaster.pop('info', '提示', '电话号码未填写');
  16386. } else if ($scope.deOrder.venduser == null) {
  16387. toaster.pop('info', '提示', '联系人未填写');
  16388. } else if ($scope.deOrder.shipdate == null) {
  16389. toaster.pop('info', '提示', '供应商发货时间未选择');
  16390. } else if ($scope.deOrder.goodspacking == null) {
  16391. toaster.pop('info', '提示', '货物包装要求未填写');
  16392. } else if ($scope.deOrder.deliverymethod == null) {
  16393. toaster.pop('info', '提示', '供应商交货方式未填写');
  16394. } else if ($scope.deOrder.pickupmethod == null) {
  16395. toaster.pop('info', '提示', '我方提货方式未填写');
  16396. } else if ($scope.deOrder.paymentmethod == null) {
  16397. toaster.pop('info', '提示', '我方付款方式未填写');
  16398. } else if ($scope.deOrder.pickupdate == null) {
  16399. toaster.pop('info', '提示', '我方提货时间未选择');
  16400. } else if ($scope.deOrder.currency == null) {
  16401. toaster.pop('info', '提示', '交易币别未选择');
  16402. } else if ($scope.deOrder.deputyuu == null) {
  16403. toaster.pop('info', '提示', '代采企业未选择');
  16404. } else if ($scope.deOrder.salecode == null) {
  16405. toaster.pop('info', '提示', '订单编号未填写');
  16406. } else if ($scope.deOrder.paydeldate == null) {
  16407. toaster.pop('info', '提示', '我方付款提货时间未选择');
  16408. } else if ($scope.deOrder.riskmethod == null) {
  16409. toaster.pop('info', '提示', '风险承担方式未填写');
  16410. } else if ($scope.deOrder.taxpaymentmethod == null) {
  16411. toaster.pop('info', '提示', '运、税费承担方式');
  16412. } else if ($scope.deOrder.tervendaddress == null) {
  16413. toaster.pop('info', '提示', '终端供应商地址未填写');
  16414. } else if ($scope.deOrder.companyname == null) {
  16415. toaster.pop('info', '提示', '公司全称(英文)未填写');
  16416. } else if ($scope.deOrder.requirepaydate == null) {
  16417. toaster.pop('info', '提示', '要求付汇日期未选择');
  16418. } else if ($scope.deOrder.bankname == null) {
  16419. toaster.pop('info', '提示', '银行名称(英文)未填写');
  16420. } else if ($scope.deOrder.bankaccount == null) {
  16421. toaster.pop('info', '提示', '银行账号未填写');
  16422. } else if ($scope.deOrder.bankaddress == null) {
  16423. toaster.pop('info', '提示', '银行地址未填写');
  16424. } else if ($scope.deOrder.bankcode == null) {
  16425. toaster.pop('info', '提示', '银行代码未填写');
  16426. } else if ($scope.deOrder.salepocode == null) {
  16427. toaster.pop('info', '提示', '合同编号未填写');
  16428. } else if ($scope.deOrder.legalrepresent == null) {
  16429. toaster.pop('info', '提示', '供应商方法定代表人未填写');
  16430. } else if ($scope.deOrder.paycomname == null) {
  16431. toaster.pop('info', '提示', '付款公司未填写');
  16432. } else if ($scope.deOrder.paycomaddress == null) {
  16433. toaster.pop('info', '提示', '付款公司地址未填写');
  16434. } else if ($scope.deOrder.enfax == null) {
  16435. toaster.pop('info', '提示', '供应商方法人电话未填写');
  16436. } else if ($scope.deOrder.paydate == null) {
  16437. toaster.pop('info', '提示', '货款支付时间未选择');
  16438. } else if ($scope.deOrder.paymethod == null) {
  16439. toaster.pop('info', '提示', '货款支付方式未填写');
  16440. } else if ($scope.deOrder.deliverydate == null) {
  16441. toaster.pop('info', '提示', '交货时间未选择');
  16442. } else if (!$scope.orderCodeEnable) {
  16443. toaster.pop('info', '提示', '采购单号重复');
  16444. } else if ($scope.deOrder.totalpayament >= 3000000) {
  16445. toaster.pop('error', '提示', '单张订单委托采购总金额不得超过300万美金,');
  16446. } else {
  16447. angular.forEach($scope.deOrder.deputyOrderItems, function (orderitem, index) {
  16448. if (orderitem.prodname == null) {
  16449. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品名称未填写');
  16450. } else if (orderitem.prodcode == null) {
  16451. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品编号未填写');
  16452. } else if (orderitem.prodspec == null) {
  16453. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品规格未填写');
  16454. } else if (orderitem.prodbrand == null) {
  16455. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行产品品牌未填写');
  16456. } else if (orderitem.amount == null) {
  16457. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行数量未填写');
  16458. } else if (orderitem.unitprice == null) {
  16459. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行单价未填写');
  16460. } else if (orderitem.purcprice == null) {
  16461. toaster.pop('info', '提示', '订单明细第' + (index + 1) + '行订单单价未填写');
  16462. } else {
  16463. $scope.checkresult = true;
  16464. $scope.isSave = true;
  16465. }
  16466. });
  16467. }
  16468. }
  16469. // 保存
  16470. $scope.isSave = false;
  16471. $scope.save = function (status) {
  16472. $scope.deOrder.entrystatus = status;
  16473. checkKeyword();
  16474. if ($scope.checkresult) {
  16475. $scope.deOrder.totalamount = 0;
  16476. $scope.deOrder.usdpayment = 0;
  16477. $scope.deOrder.orderamount = 0;
  16478. $scope.deOrder.totalpayament = 0;
  16479. angular.forEach($scope.deOrder.deputyOrderItems, function (item) {
  16480. $scope.deOrder.totalamount += DecimalNumber.accMul(item.amount, item.unitprice);
  16481. $scope.deOrder.usdpayment += DecimalNumber.accMul(item.amount, item.unitprice);
  16482. $scope.deOrder.totalpayament += DecimalNumber.accMul(item.amount, item.unitprice);
  16483. $scope.deOrder.orderamount += DecimalNumber.accMul(item.amount, item.purcprice);
  16484. });
  16485. if ($scope.deOrder.deputyOrderItems[0].prodcode == null) {
  16486. toaster.pop('info', '提示', '您还未填写任何商品信息');
  16487. } else {
  16488. DeputyOrder.saveDeOrder({}, $scope.deOrder, function (data) {
  16489. if (data.id) {
  16490. toaster.pop('success', '提示', '保存成功');
  16491. loadData();
  16492. window.location.reload();
  16493. }
  16494. if (data.error) {
  16495. toaster.pop('error', '提示', '保存失败');
  16496. }
  16497. }, function (response) {
  16498. toaster.pop('error', '保存失败', response.data);
  16499. });
  16500. }
  16501. }
  16502. }
  16503. $scope.openDatePicker = function ($event, deOrder, openParam) {
  16504. $event.preventDefault();
  16505. $event.stopPropagation();
  16506. deOrder[openParam] = !deOrder[openParam];
  16507. };
  16508. //复制采购单
  16509. $scope.copyorder = function (id) {
  16510. DeputyOrder.copyOrder({id: id}, {}, function (data) {
  16511. if (data.id) {
  16512. toaster.pop('success', '提示', '复制生成单据成功');
  16513. window.location.hash = "#/purc/deputy/" + data.id;
  16514. }
  16515. if (data.error) {
  16516. toaster.pop('error', '提示', '保存失败');
  16517. }
  16518. }, function (response) {
  16519. toaster.pop('error', '提示', response.data);
  16520. });
  16521. }
  16522. // 删除代采订单
  16523. $scope.clear = function (id) {
  16524. DeputyOrder.clearOrder({id: id}, {}, function (data) {
  16525. if (data.success) {
  16526. toaster.pop('success', '提示', data.success);
  16527. window.location.hash = "#/purc/deputy";
  16528. }
  16529. }, function (response) {
  16530. toaster.pop('error', '提示', response.data);
  16531. });
  16532. }
  16533. }]);
  16534. /**
  16535. * 代采错误日志
  16536. */
  16537. app.controller('DeputyOrderLogCtrl', ['$scope', 'DeputyOrder', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', function ($scope, DeputyOrder, ngTableParams, $filter, BaseService, toaster, $timeout) {
  16538. BaseService.scrollBackToTop();
  16539. var getService = function () {
  16540. return DeputyOrder.getRepetitions;
  16541. };
  16542. $scope.tableParams = new ngTableParams({
  16543. page: 1,
  16544. count: 20,
  16545. sorting: {}
  16546. }, {
  16547. total: 0,
  16548. counts: [5, 10, 25, 50],
  16549. getData: function ($defer, params) {
  16550. $scope.loading = true;
  16551. var pageParams = params.url();
  16552. pageParams.keyword = $scope.keyword;
  16553. pageParams.searchFilter = $scope.searchFilter;
  16554. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  16555. $scope.loading = false;
  16556. if (page) {
  16557. params.total(page.totalElement);
  16558. $defer.resolve(page.content);
  16559. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  16560. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  16561. }
  16562. }, function (response) {
  16563. $scope.loading = false;
  16564. toaster.pop('error', '数据加载失败', response.data);
  16565. });
  16566. }
  16567. });
  16568. // 搜索框回车
  16569. $scope.onSearch = function () {
  16570. $scope.tableParams.page(1);
  16571. $scope.tableParams.reload();
  16572. };
  16573. //删除
  16574. $scope.deleteById = function (id) {
  16575. GetProductInfo.deleteById({id: id}, function (data) {
  16576. if (data.error) {
  16577. toaster.pop("error", "提示", data.error);
  16578. } else {
  16579. toaster.pop("success", "提示", "删除成功");
  16580. $timeout(function () {
  16581. $scope.tableParams.reload();
  16582. }, 500);
  16583. }
  16584. }), function (response) {
  16585. toaster.pop("error", "删除失败", response.data);
  16586. };
  16587. }
  16588. }]);
  16589. /**
  16590. * 招标单
  16591. */
  16592. app.controller('PurcTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams',
  16593. '$modal', '$rootScope', 'PurcTenderInfo', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, PurcTenderInfo) {
  16594. BaseService.scrollBackToTop();
  16595. $scope.searchStatus = false;
  16596. if ($rootScope.tenderActive) {
  16597. $scope.active = $rootScope.tenderActive;
  16598. $rootScope.tenderActive = null;
  16599. } else {
  16600. $scope.active = 'todo';
  16601. }
  16602. $scope.dateZoneText = '不限';
  16603. $scope.deliveryZoneText = '不限';
  16604. $scope.condition = {dateZone: 1, deliveryZone: -1};
  16605. /* 时间筛选初始化*/
  16606. var fromDate = new Date();
  16607. var toDate = new Date();
  16608. fromDate.setMonth(fromDate.getMonth() - 1);
  16609. fromDate.setHours(0, 0, 0, 0);
  16610. toDate.setHours(23, 59, 59, 999);
  16611. $scope.condition.dateFrom = fromDate;
  16612. $scope.condition.dateTo = toDate;
  16613. $scope.changeDateZone = function (zone) {
  16614. $scope.condition.dateZone = zone;
  16615. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  16616. $scope.condition.$dateZoneOpen = false;
  16617. getDateCondition(zone, $scope.condition);
  16618. $scope.tableParams.reload();
  16619. };
  16620. $scope.changeDeliveryZone = function (zone) {
  16621. $scope.condition.deliveryZoneText = zone;
  16622. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  16623. $scope.condition.$delievryZoneOpen = false;
  16624. getDelveryCondition(zone, $scope.condition);
  16625. $scope.tableParams.page(1);
  16626. $scope.tableParams.reload();
  16627. };
  16628. $scope.setActive = function (state) {
  16629. if ($scope.active != state) {
  16630. $scope.active = state;
  16631. if ($scope.tableParams.page() == 1)
  16632. $scope.tableParams.reload();
  16633. else
  16634. $scope.tableParams.page(1);
  16635. }
  16636. };
  16637. var getTenderStatus = function (active) {
  16638. var fn = 'getMyAll';
  16639. switch (active) {
  16640. case 'done':
  16641. fn = 'getMyDone';
  16642. break;
  16643. case 'todo':
  16644. fn = 'getMyTodo';
  16645. break;
  16646. // case 'end':
  16647. // fn = 'getMyEnd';break;
  16648. case 'waiting':
  16649. fn = 'getMyWaiting';
  16650. break;
  16651. }
  16652. return fn;
  16653. };
  16654. var getService = function () {
  16655. if ($scope.searchStatus) {
  16656. return PurcTender;
  16657. }
  16658. return PurcTenderInfo;
  16659. };
  16660. $scope.tableParams = new ngTableParams({
  16661. page: 1,
  16662. count: 20,
  16663. sorting: {
  16664. 'id': 'desc'
  16665. }
  16666. }, {
  16667. total: 0,
  16668. counts: [5, 10, 25, 50],
  16669. getData: function ($defer, params) {
  16670. $scope.loading = true;
  16671. var pageParams = params.url();
  16672. var realActive = {};
  16673. pageParams.searchFilter = { // 筛选条件
  16674. keyword: $scope.keyword,
  16675. fromDate: getDateTime($scope.condition.dateFrom),
  16676. endDate: getDateTime($scope.condition.dateTo)
  16677. };
  16678. getService()[getTenderStatus($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16679. $scope.loading = false;
  16680. if (page) {
  16681. params.total(page.totalElement);
  16682. $defer.resolve(page.content);
  16683. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  16684. }
  16685. }, function (response) {
  16686. $scope.loading = false;
  16687. toaster.pop('error', '数据加载失败', response.data);
  16688. });
  16689. }
  16690. });
  16691. //获得各分类未阅读数量
  16692. var getUnreadCount = function () {
  16693. PurcTender.getPurcUnreadCount(null, function(data){
  16694. $scope.unread = data;
  16695. });
  16696. };
  16697. getUnreadCount();
  16698. //设置单据已读
  16699. $scope.setOrdersRead = function (id) {
  16700. // 如果单据本身已读,则不发送请求修改数据
  16701. if (!$scope.isUnread(id)){
  16702. return;
  16703. }
  16704. var sourceId = [];
  16705. sourceId.push(id);
  16706. PurcTender.setPurcRead({}, sourceId, function (message) {
  16707. // $scope.getUnreadIds();
  16708. getUnreadCount();
  16709. });
  16710. };
  16711. //获取未读单据id
  16712. var getUnreadIds = function (){
  16713. PurcTender.getPurcUnreadIds({}, "", function (message) {
  16714. $scope.unreadCode = message.content;
  16715. });
  16716. };
  16717. getUnreadIds();
  16718. //判断单据是否未读
  16719. $scope.isUnread = function (tender){
  16720. for (var i in $scope.unreadCode) {
  16721. if (tender.id == $scope.unreadCode[i]) {
  16722. var flag = tender.status == '待评标' && tender.overdue == 1 && tender.result != 1;
  16723. if (!flag) {
  16724. $scope.unreadCode.splice(i,1);
  16725. return false;
  16726. }
  16727. return true;
  16728. }
  16729. }
  16730. };
  16731. $scope.openDatePicker = function ($event, item, openParam) {
  16732. $event.preventDefault();
  16733. $event.stopPropagation();
  16734. item[openParam] = !item[openParam];
  16735. };
  16736. $scope.openFilterDatePicker = function ($event, item, openParam) {
  16737. $event.preventDefault();
  16738. $event.stopPropagation();
  16739. item[openParam] = !item[openParam];
  16740. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  16741. $scope.tableParams.reload();
  16742. }
  16743. };
  16744. $scope.parseDate = function (dateStr) {
  16745. if (dateStr)
  16746. return Date.parse(dateStr, 'yyyy-MM-dd');
  16747. return new Date();
  16748. };
  16749. // 选择查找日期
  16750. $scope.onDateCondition = function () {
  16751. $scope.tableParams.page(1);
  16752. $scope.tableParams.reload();
  16753. };
  16754. // 搜索框回车
  16755. $scope.onSearch = function () {
  16756. $scope.searchStatus = true;
  16757. $scope.tableParams.page(1);
  16758. $scope.tableParams.reload();
  16759. };
  16760. }]);
  16761. /**
  16762. * 新增招标单
  16763. */
  16764. 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) {
  16765. // 录入人
  16766. AuthenticationService.getAuthentication().success(function (data) {
  16767. $scope.user = data;
  16768. });
  16769. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  16770. $scope.searchMethod = false;
  16771. var getService = function () {
  16772. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  16773. };
  16774. // 物料信息
  16775. $scope.tableParams = new ngTableParams({
  16776. page: 1,
  16777. count: 20,
  16778. sorting: {}
  16779. }, {
  16780. total: 0,
  16781. counts: [5, 10, 25, 50],
  16782. getData: function ($defer, params) {
  16783. $scope.loading = true;
  16784. var pageParams = params.url();
  16785. pageParams.keyword = $scope.keyword;
  16786. $scope.tip = $scope.keyword;
  16787. pageParams.searchFilter = $scope.searchFilter;
  16788. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  16789. $scope.loading = false;
  16790. if (page) {
  16791. params.total(page.totalElement);
  16792. $scope.total = page.totalElement;
  16793. $defer.resolve(page.content);
  16794. }
  16795. }, function (response) {
  16796. $scope.loading = false;
  16797. toaster.pop('error', '数据加载失败', response.data);
  16798. });
  16799. }
  16800. });
  16801. // 搜索框回车
  16802. $scope.onSearch = function (keyword) {
  16803. // 每次搜索重置获取数据方法
  16804. $scope.searchMethod = false;
  16805. if(keyword != null && keyword != '') {
  16806. $scope.searchMethod = true;
  16807. }
  16808. $scope.tableParams.page(1);
  16809. $scope.tableParams.reload();
  16810. };
  16811. //在产品列表添加商品
  16812. $scope.check = function (product) {
  16813. $scope.tenderProd.push({
  16814. prodTitle: product.title,
  16815. prodCode: product.code,
  16816. brand: product.brand,
  16817. unit: product.unit,
  16818. qty: null
  16819. // 供应商企业信息
  16820. // enterpriseBaseInfo: [{}]
  16821. });
  16822. for (var i = 0; i < $scope.tenderProd.length; i++) {
  16823. if ($scope.tenderProd[i].prodCode === null && $scope.tenderProd[i].prodTitle === null) { // 如果没有填写就删除这行数据
  16824. $scope.tenderProd.splice(i, 1);
  16825. }
  16826. }
  16827. };
  16828. $scope.loading = false;
  16829. // 获取收货地址列表
  16830. var loadShipAddress = function () {
  16831. ShipAddress.shipAddList({}, function (data) {
  16832. $scope.ships = data;
  16833. $scope.tender.shipadd = $scope.ships[0];
  16834. });
  16835. };
  16836. loadShipAddress();
  16837. // 获取地址信息
  16838. $http.get('resources/citydata/city.json', {
  16839. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  16840. }).then(function (response) {
  16841. $scope.provinces = response.data;
  16842. });
  16843. // 新增收货地址保存
  16844. $scope.saveShipAddress = function (ship) {
  16845. ship.address = ship.province + ship.city + ship.district;
  16846. ShipAddress.saveAddress({}, ship, function (data) {
  16847. if (data.success) {
  16848. // 获取收货地址列表
  16849. loadShipAddress();
  16850. toaster.pop('success', '提示', data.success);
  16851. }
  16852. if (data.error) {
  16853. toaster.pop('error', '提示', data.error);
  16854. }
  16855. });
  16856. };
  16857. // 可选的证照要求
  16858. $scope.certificates = [{name: '三/五证合一'}, {name: '营业执照'}, {name: '组织机构代码证'}, {name: '一般纳税人证明材料'}, {name: '统计登记证'}, {name: '社会保险登记证'}];
  16859. // 处理证照要求
  16860. var parseCertificate = function (a) {
  16861. if (a) {
  16862. var arr = a.split(',');
  16863. angular.forEach(arr, function (app) {
  16864. var contained = false;
  16865. angular.forEach($scope.certificates, function ($app) {
  16866. if ($app.name == app) {
  16867. $app.checked = true;
  16868. contained = true;
  16869. }
  16870. });
  16871. if (!contained) {
  16872. $scope.certificates.push({name: app, checked: true});
  16873. }
  16874. });
  16875. }
  16876. };
  16877. // 联想词start
  16878. // 获取品牌联想词
  16879. $scope.getSimilarBrands = function (value) {
  16880. if (value) {
  16881. // 获取品牌联想词
  16882. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  16883. return data.map(function (item) {
  16884. return item;
  16885. });
  16886. });
  16887. }
  16888. };
  16889. // 获取产品型号联想词
  16890. $scope.getSimilarCodes = function (value) {
  16891. if (value) {
  16892. // 获取产品型号联想词
  16893. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  16894. return data.map(function (item) {
  16895. return item;
  16896. })
  16897. });
  16898. }
  16899. };
  16900. // 选择类目
  16901. $scope.selectKind = function (prod) {
  16902. var submit = [];
  16903. $modal.open({
  16904. animation: true,
  16905. size: 'lg',
  16906. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  16907. controller: 'ProdKindChooseCtrl',
  16908. resolve: {
  16909. actives: function () {
  16910. return $scope.actives;
  16911. }
  16912. }
  16913. }).result.then(function (data) {
  16914. $scope.actives = data.actives;
  16915. var size = data.actives.length;
  16916. submit.gradeOneKiName = '';
  16917. submit.gradeTwoKiName = '';
  16918. submit.gradeThreeKiName = '';
  16919. if (size > 0) {
  16920. submit.gradeOneKiName = $scope.actives[0].nameCn;
  16921. prod.prodTitle = submit.gradeOneKiName;
  16922. if (size > 1) {
  16923. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  16924. prod.prodTitle = submit.gradeTwoKiName;
  16925. if (size > 2) {
  16926. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  16927. prod.prodTitle = submit.gradeThreeKiName;
  16928. }
  16929. }
  16930. }
  16931. }, function () {
  16932. });
  16933. };
  16934. // 点击联想词获取品牌信息
  16935. $scope.onAssociateBrandClick = function (brand, prod) {
  16936. if (brand instanceof String) {
  16937. prod.brand = brand;
  16938. } else if (brand instanceof Object) {
  16939. prod.brand = brand.brandCn;
  16940. }
  16941. };
  16942. // 打开品牌选择的模态框
  16943. $scope.selectBrand = function (prod) { //打开模态
  16944. var modalInstance = $modal.open({
  16945. size: 'lg',
  16946. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  16947. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  16948. });
  16949. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  16950. });
  16951. modalInstance.result.then(function (brand) {
  16952. prod.brand = brand.nameCn;
  16953. }, function (reason) {
  16954. });
  16955. };
  16956. // 点击联想词获取器件信息 带入产品分类和品牌
  16957. $scope.onAssociateCmpClick = function (cmp, prod) {
  16958. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  16959. $scope.component = data;
  16960. prod.prodCode = data.code;
  16961. prod.prodTitle = data.kind.nameCn;
  16962. prod.brand = data.brand.nameCn;
  16963. }, function (res) {
  16964. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  16965. })
  16966. };
  16967. //联想词end
  16968. $scope.condition = {dateZone: 1};
  16969. $scope.tenderProd = [];
  16970. var prod = {
  16971. prodTitle: null,
  16972. prodCode: null,
  16973. brand: null,
  16974. unit: 'PCS',
  16975. qty: null
  16976. // 供应商企业信息
  16977. // enterpriseBaseInfo: [{}]
  16978. };
  16979. $scope.tender = {
  16980. date: new Date(),
  16981. unit: 'PCS',
  16982. currency: 'RMB',
  16983. ifOpen: 1,
  16984. ifTax: 1,
  16985. invoiceType: 2,
  16986. tenderAttachs: [{}]
  16987. };
  16988. //
  16989. $scope.tenderProd.push(prod);
  16990. //增加商品
  16991. $scope.add = function (index) {
  16992. $scope.tenderProd.push({
  16993. prodTitle: null,
  16994. prodCode: null,
  16995. brand: null,
  16996. unit: 'PCS',
  16997. qty: null
  16998. // 供应商企业信息
  16999. // enterpriseBaseInfo: [{}]
  17000. });
  17001. };
  17002. //删除商品
  17003. $scope.del = function (index) {
  17004. $scope.tenderProd.splice(index, 1);
  17005. };
  17006. // 批量导入
  17007. $scope.uplodaByBatch = function () {
  17008. var modalInstance = $modal.open({
  17009. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  17010. controller: 'PurcTenderUploadCtrl',
  17011. size: 'lg',
  17012. resolve: {}
  17013. });
  17014. modalInstance.result.then(function (data) {
  17015. // 获取上传的产品明细,前台展示
  17016. angular.forEach(data, function (data) {
  17017. $scope.tenderProd.push(data);
  17018. for (var i = 0; i < $scope.tenderProd.length; i++) {
  17019. if ($scope.tenderProd[i].prodTitle == null) { // 如果没有填写就删除这行数据
  17020. $scope.tenderProd.splice(i, 1);
  17021. }
  17022. }
  17023. });
  17024. }, function () {
  17025. });
  17026. };
  17027. $scope.isSave = false;
  17028. // 已存在id的为查看招标单(用于在录入的招标单的发布和删除)
  17029. if (!angular.isUndefined($stateParams.id)) {
  17030. $scope.isSave = true; // 用于判断是新增还是已保存
  17031. $scope.loading = true;
  17032. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17033. data.$editing = false;
  17034. $scope.tender = data;
  17035. $scope.tenderProd = data.purchaseTenderProds;
  17036. parseCertificate($scope.tender.certificate);
  17037. $scope.firstProd = data.purchaseTenderProds[0];
  17038. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  17039. // 获取供应商联系人
  17040. Vendor.contacts({venduu: item.saleTender.vendUU}, {}, function (data) {
  17041. item.saleTender.enterpriseBaseInfo.contacts = data;
  17042. // item.saleTender.enterpriseBaseInfo.contact = data[0];
  17043. angular.forEach(item.saleTender.enterpriseBaseInfo.contacts, function (contact) {
  17044. if (item.saleTender.userTel === contact.tel) {
  17045. item.saleTender.enterpriseBaseInfo.contact = contact;
  17046. }
  17047. });
  17048. });
  17049. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  17050. $scope.tenderProd.enterpriseBaseInfo = [{}];
  17051. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, item.saleTender.enterpriseBaseInfo);
  17052. } else {
  17053. $scope.tenderProd.enterpriseBaseInfo.push(item.saleTender.enterpriseBaseInfo);
  17054. }
  17055. });
  17056. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  17057. $scope.loading = false;
  17058. $scope.attaches = $scope.tender.tenderAttaches;
  17059. }, function (response) {
  17060. $scope.loading = false;
  17061. toaster.pop('error', '数据加载失败', response.data);
  17062. });
  17063. }
  17064. if (angular.isUndefined($stateParams.id)) { // 发布招标单之后,再次新增招标单时,新增供应商时不会勾选上一个单据选择的供应商
  17065. $rootScope.tenderVendor = [{}];
  17066. }
  17067. $scope.changeShipAddress = false;
  17068. $scope.changeAddress = function () {
  17069. if ($scope.changeShipAddress) {
  17070. $scope.changeShipAddress = false;
  17071. } else {
  17072. $scope.changeShipAddress = true;
  17073. }
  17074. };
  17075. $scope.changeContactInfo = function (en) {
  17076. if (en.changeContact) {
  17077. en.changeContact = false;
  17078. } else {
  17079. en.changeContact = true;
  17080. }
  17081. };
  17082. $scope.changeCurrency = function (tender) {
  17083. if (tender.currency !== 'RMB') {
  17084. $scope.notRMB = true;
  17085. tender.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  17086. tender.invoiceType = 0;
  17087. } else {
  17088. $scope.notRMB = false;
  17089. }
  17090. };
  17091. // 查找供应商
  17092. $scope.dbfindVendor = function () {
  17093. var modalInstance = $modal.open({
  17094. templateUrl: 'static/tpl/index/purc/tender_vendor.html',
  17095. controller: 'DbfindVendorCtrl',
  17096. size: 'lg',
  17097. resolve: {}
  17098. });
  17099. var ifPush = true;
  17100. modalInstance.result.then(function (data) {
  17101. angular.forEach(data, function (vendor) {
  17102. // 获取供应商联系人
  17103. Vendor.contacts({venduu: vendor.vendorEnterprise.uu}, {}, function (data) {
  17104. vendor.vendorEnterprise.contacts = data;
  17105. $scope.tenderProd.enterpriseBaseInfo.contact = vendor.vendorEnterprise.contacts[0];
  17106. });
  17107. if (!$scope.tenderProd.enterpriseBaseInfo) {// 不存在就先创建
  17108. $scope.tenderProd.enterpriseBaseInfo = [{}];
  17109. // 获取供应商联系人
  17110. $scope.tenderProd.enterpriseBaseInfo.splice(0, 1, vendor.vendorEnterprise);
  17111. } else {
  17112. for (var i = 0; i < $scope.tenderProd.enterpriseBaseInfo.length; i++) {
  17113. ifPush = true;
  17114. if ($scope.tenderProd.enterpriseBaseInfo[i].enName == vendor.vendorEnterprise.enName) {
  17115. ifPush = false;
  17116. break; // 判定到已存在供应商,就终止循环。
  17117. }
  17118. }
  17119. if (ifPush) {
  17120. $scope.tenderProd.enterpriseBaseInfo.push(vendor.vendorEnterprise);
  17121. }
  17122. }
  17123. });
  17124. $rootScope.tenderVendor = $scope.tenderProd.enterpriseBaseInfo;
  17125. }, function () {
  17126. });
  17127. };
  17128. // 新增供应商联系人
  17129. $scope.addContact = function (en) {
  17130. var modalInstance = $modal.open({
  17131. animation: true,
  17132. templateUrl: 'static/tpl/index/purc/modal/contact_person_modal.html',
  17133. controller: 'AddContacCtrl',
  17134. resolve: {}
  17135. });
  17136. modalInstance.result.then(function (data) {
  17137. en.contact = data;
  17138. en.contact.venduu = en.uu;
  17139. Vendor.saveContact({}, en.contact, function (data) {
  17140. Vendor.contacts({venduu: en.uu}, {}, function (data) {
  17141. en.contacts = data;
  17142. en.contact = data[0]; // 新增的作为联系人
  17143. });
  17144. toaster.pop('success', '提示', '联系人保存成功');
  17145. }, function (response) {
  17146. toaster.pop('error', '失败', response.data);
  17147. });
  17148. });
  17149. };
  17150. // 删除一个供应商
  17151. $scope.removeVendor = function (index) {
  17152. $scope.tenderProd.enterpriseBaseInfo.splice(index, 1);
  17153. };
  17154. // 删除供应商时,后台删除投标单
  17155. $scope.removeSaleTender = function (id, vendUU) {
  17156. var hasSaved = false;
  17157. angular.forEach($scope.tender.purchaseTenderProds[0].saleTenderItems, function (saleTenderItem) {
  17158. if (saleTenderItem.saleTender.vendUU === vendUU) { //有相等的说明是之前保存过的供应商
  17159. hasSaved = true;
  17160. }
  17161. });
  17162. if (hasSaved) {
  17163. PurcTender.removeSaleTender({id: id, vendUU: vendUU}, {}, function (data) {
  17164. }, function (response) {
  17165. toaster.pop('error', '提示', response.data);
  17166. });
  17167. }
  17168. };
  17169. // 删除产品明细时,后台删除产品明细
  17170. $scope.deleteProd = function (tenderProd) {
  17171. if (tenderProd.id) {
  17172. PurcTender.deleteProd({tenderProdId: tenderProd.id}, {}, function (data) {
  17173. }, function (response) {
  17174. toaster.pop('error', '提示', response.data);
  17175. });
  17176. }
  17177. };
  17178. if (!$scope.attaches) {
  17179. $scope.attaches = []; // 存放上传了的附件
  17180. }
  17181. $scope.upload = function (myFile) { // 上传附件
  17182. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  17183. $upload.upload({
  17184. url: 'tender/addTenderAttach',
  17185. file: file,
  17186. method: 'POST'
  17187. }).success(function (attach) {
  17188. $scope.attaches.push(attach);
  17189. });
  17190. };
  17191. $scope.removeAttach = function (id, index) {
  17192. $scope.attaches.splice(index, 1);
  17193. };
  17194. var sleep = function (d) {
  17195. for (var t = Date.now(); Date.now() - t <= d;);
  17196. };
  17197. // 保存和发布招标单
  17198. $scope.save = function (isPublish) {
  17199. if ($scope.tender.ifOpen == 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  17200. toaster.pop('info', '提示', '请先指定供应商');
  17201. } else {
  17202. $scope.loading = true;
  17203. // --组装证照要求
  17204. var myCertificate = [];
  17205. angular.forEach($scope.certificates, function (certificate) {
  17206. if (certificate.checked) {
  17207. myCertificate.push(certificate.name);
  17208. }
  17209. });
  17210. $scope.tender.certificate = myCertificate.join(',');
  17211. if (!$scope.tender.code) { //新增,设单号
  17212. $scope.tender.code = 'ZB' + $filter('date')(new Date(), 'yyMMddHHmmss');
  17213. }
  17214. if ($scope.tender.date instanceof Date) {
  17215. $scope.tender.date = $scope.tender.date.getTime();
  17216. }
  17217. if ($scope.tender.endDate instanceof Date) {
  17218. $scope.tender.endDate = $scope.tender.endDate.getTime();
  17219. }
  17220. if ($scope.tender.publishDate instanceof Date) {
  17221. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  17222. }
  17223. if ($scope.tender.questionEndDate instanceof Date) {
  17224. $scope.tender.questionEndDate = $scope.tender.questionEndDate.getTime();
  17225. }
  17226. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  17227. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  17228. $scope.tender.purchaseTenderProds[i].index = i + 1;
  17229. }
  17230. $scope.tender.tenderAttaches = $scope.attaches;
  17231. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  17232. var enInfos = [];
  17233. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  17234. var enInfo = {
  17235. uu: null,
  17236. contact: null,
  17237. contactTel: null
  17238. };
  17239. enInfo.uu = enterpriseBaseInfo.uu;
  17240. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17241. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17242. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17243. }
  17244. enInfos.push(enInfo);
  17245. });
  17246. if (isPublish) { // 发布
  17247. toaster.pop('info', '提示', '正在发布,请稍候');
  17248. $scope.tender.isPublish = 1;
  17249. PurcTender.publish({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17250. // sleep(1500); //当前方法暂停1.5秒
  17251. $scope.loading = false;
  17252. toaster.pop('success', '成功', '发布成功');
  17253. window.location.hash = '#/purc/tender';
  17254. }, function (response) {
  17255. $scope.loading = false;
  17256. toaster.pop('error', '发布失败', response.data);
  17257. });
  17258. } else { // 保存
  17259. toaster.pop('info', '提示', '正在保存,请稍候');
  17260. $scope.tender.isPublish = 0;
  17261. PurcTender.save({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17262. $scope.loading = false;
  17263. // sleep(1500); //当前方法暂停1.5秒 给更新索引留点时间
  17264. toaster.pop('success', '成功', '保存成功');
  17265. window.location.hash = '#/purc/tender';
  17266. }, function (response) {
  17267. $scope.loading = false;
  17268. toaster.pop('error', '保存失败', response.data);
  17269. });
  17270. }
  17271. }
  17272. };
  17273. // 切换为在平台公开招标时,清除掉已添加的供应商信息
  17274. $scope.removeChecked = function () {
  17275. if ($scope.tenderProd.enterpriseBaseInfo.size > 0) {
  17276. $scope.tenderProd.enterpriseBaseInfo = [];
  17277. }
  17278. };
  17279. // 删除(在录入状态)
  17280. $scope.deleteThis = function (id) {
  17281. PurcTender.deleteOne({id: id}, {}, function (data) {
  17282. toaster.pop('info', '提示', '删除成功');
  17283. window.location.hash = '#/purc/tender';
  17284. });
  17285. };
  17286. // 更新和发布(在录入状态)
  17287. $scope.updateSaved = function (isPublish) {
  17288. if (Number($scope.tender.ifOpen) === 0 && (!$scope.tenderProd.enterpriseBaseInfo || $scope.tenderProd.enterpriseBaseInfo.length === 0)) { // 指定供应商招标,而未选择供应商时
  17289. toaster.pop('info', '提示', '请先指定供应商');
  17290. } else {
  17291. $scope.loading = true;
  17292. // --组装证照要求
  17293. var myCertificate = [];
  17294. angular.forEach($scope.certificates, function (certificate) {
  17295. if (certificate.checked) {
  17296. myCertificate.push(certificate.name);
  17297. }
  17298. });
  17299. $scope.tender.certificate = myCertificate.join(',');
  17300. if ($scope.tender.endDate instanceof Date) {
  17301. $scope.tender.endDate = $scope.tender.endDate.getTime();
  17302. }
  17303. if ($scope.tender.publishDate instanceof Date) {
  17304. $scope.tender.publishDate = $scope.tender.publishDate.getTime();
  17305. }
  17306. $scope.tender.purchaseTenderProds = $scope.tenderProd;
  17307. for (var i = 0; i < $scope.tender.purchaseTenderProds.length; i++) {
  17308. $scope.tender.purchaseTenderProds[i].index = i + 1;
  17309. }
  17310. $scope.tender.tenderAttaches = $scope.attaches;
  17311. if ($scope.tender.shipadd) {
  17312. $scope.tender.shipAddress = $scope.tender.shipadd.address + $scope.tender.shipadd.addressdet + ' ' + $scope.tender.shipadd.receiver + ' ' + $scope.tender.shipadd.usertel;
  17313. }
  17314. angular.forEach($scope.tender.purchaseTenderProds, function (tenderProd) {
  17315. tenderProd.saleTenderItems = []; // 投标相关不用传参,否则会超长
  17316. });
  17317. var enInfos = [];
  17318. angular.forEach($scope.tenderProd.enterpriseBaseInfo, function (enterpriseBaseInfo) {
  17319. var enInfo = {
  17320. uu: null,
  17321. contact: null,
  17322. contactTel: null
  17323. };
  17324. enInfo.uu = enterpriseBaseInfo.uu;
  17325. if (typeof enterpriseBaseInfo.contact !== 'undefined') {
  17326. enInfo.contact = enterpriseBaseInfo.contact.venduser;
  17327. enInfo.contactTel = enterpriseBaseInfo.contact.tel;
  17328. }
  17329. enInfos.push(enInfo);
  17330. });
  17331. if (isPublish) { // 发布
  17332. toaster.pop('info', '提示', '正在发布,请稍候');
  17333. PurcTender.publishSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17334. $scope.loading = false;
  17335. toaster.pop('success', '成功', '发布成功');
  17336. window.location.hash = '#/purc/tender';
  17337. }, function (response) {
  17338. $scope.loading = false;
  17339. toaster.pop('error', '发布失败', response.data);
  17340. });
  17341. } else { // 保存
  17342. toaster.pop('info', '提示', '正在保存,请稍候');
  17343. PurcTender.updateSaved({tender: $scope.tender, enInfos: enInfos}, {}, function (data) {
  17344. $scope.loading = false;
  17345. toaster.pop('success', '成功', '保存成功');
  17346. window.location.reload();
  17347. }, function (response) {
  17348. $scope.loading = false;
  17349. toaster.pop('error', '保存失败', response.data);
  17350. });
  17351. }
  17352. }
  17353. };
  17354. $scope.currentDay = function () {
  17355. return $filter('date')(new Date(), 'yyyy-MM-dd');
  17356. };
  17357. $scope.getMinDate = function () {
  17358. if ($scope.tender.endDate instanceof Date) {
  17359. var minDate = new Date($scope.tender.endDate.getTime() + 2 * 24 * 60 * 60 * 1000 + 1); // 公布结果日期与截止报价日期至少隔一天
  17360. }
  17361. 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');
  17362. };
  17363. $scope.getMaxDate = function () {
  17364. // var maxDate = angular.copy($scope.tender.publishDate);
  17365. // maxDate = maxDate.setDate(maxDate.getDate() - 1);
  17366. if ($scope.tender.publishDate instanceof Date) {
  17367. var maxDate = new Date($scope.tender.publishDate.getTime() - 24 * 60 * 60 * 1000 - 1); // 至少提前两天
  17368. }
  17369. return $scope.tender.publishDate ? $filter('date')(maxDate, 'yyyy-MM-dd') : "";
  17370. };
  17371. $scope.openDatePicker = function ($event, item, openParam) {
  17372. $event.preventDefault();
  17373. $event.stopPropagation();
  17374. item[openParam] = !item[openParam];
  17375. };
  17376. }]);
  17377. //类目选择模态框(招标产品明细)
  17378. app.controller('ProdKindChooseCtrl', ['$scope', 'KindAPI', 'actives', 'toaster', '$modalInstance', function ($scope, KindAPI, actives, toaster, $modalInstance) {
  17379. $scope.actives = actives;
  17380. $scope.kinds = [[], [], [], []];
  17381. // 获取子类目
  17382. var getChildren = function (pid, deep) {
  17383. KindAPI.getChildren({parentId: pid}, function (data) {
  17384. $scope.kinds[deep] = data;
  17385. }, function (response) {
  17386. toaster.pop('error', '获取子类目失败', response.data);
  17387. });
  17388. };
  17389. // 改变节点选中状态
  17390. var changeStatus = function (item, deep) {
  17391. var actives = [], level = 0;
  17392. angular.forEach($scope.kinds, function (ks, i) {
  17393. if (i > deep) {
  17394. $scope.kinds[i] = [];
  17395. } else {
  17396. angular.forEach(ks, function (k, j) {
  17397. if (i == deep) {
  17398. if (k.id == item.id) {
  17399. $scope.kinds[i][j].$active = true;
  17400. actives.push(k);
  17401. } else {
  17402. k.$active = null;
  17403. }
  17404. } else {
  17405. if (k.$active) {
  17406. actives.push(k);
  17407. }
  17408. }
  17409. });
  17410. }
  17411. });
  17412. // 选择的节点
  17413. $scope.actives = actives;
  17414. $scope.active = item;
  17415. // 当前可操作的层级
  17416. if (deep < 3) {
  17417. $scope.activeDeep = deep + 1;
  17418. }
  17419. };
  17420. // 节点点击后获取子类目,节点被选中
  17421. $scope.onItemClick = function (item, deep) {
  17422. changeStatus(item, deep);
  17423. if (!item.isLeaf) {
  17424. getChildren(item.id, deep + 1);
  17425. }
  17426. };
  17427. // 重新加载数据
  17428. function reload(deep) {
  17429. var pid;
  17430. if (deep) {
  17431. pid = $scope.actives[deep - 1].id;
  17432. } else {
  17433. pid = 0;
  17434. deep = 0;
  17435. }
  17436. getChildren(pid, deep);
  17437. }
  17438. // 初始加载数据,获取第一层的类目
  17439. if ($scope.actives) {
  17440. angular.forEach($scope.actives, function (v, k) {
  17441. KindAPI.getChildren({parentId: v.parentid}, function (data) {
  17442. $scope.kinds[k] = data;
  17443. angular.forEach($scope.kinds[k], function (kind, i) {
  17444. if (kind.id == v.id) {
  17445. $scope.kinds[k][i].$active = true;
  17446. $scope.actives[k] = $scope.kinds[k][i];
  17447. }
  17448. })
  17449. }, function (response) {
  17450. toaster.pop('error', '获取子类目失败', response.data);
  17451. });
  17452. });
  17453. } else {
  17454. reload();
  17455. }
  17456. // 取消
  17457. $scope.cancel = function () {
  17458. $modalInstance.dismiss();
  17459. };
  17460. // 确认选择
  17461. $scope.check = function () {
  17462. var a = {
  17463. active: $scope.active,
  17464. actives: $scope.actives
  17465. };
  17466. $modalInstance.close(a);
  17467. };
  17468. }]);
  17469. //品牌选择模态框的controller
  17470. app.controller('BrandModalInstanceCtrl', ['$scope', '$modalInstance', 'ngTableParams', 'BrandActiveAPI', 'BaseService', function ($scope, $modalInstance, ngTableParams, BrandActiveAPI, BaseService) {
  17471. $scope.filter = {};
  17472. $scope.brandsTableParams = new ngTableParams({
  17473. page: 1,
  17474. count: 6,
  17475. sorting: {
  17476. nameCn: 'asc'
  17477. }
  17478. }, {
  17479. total: 0,
  17480. counts: [],
  17481. getData: function ($defer, params) {
  17482. var param = BaseService.parseParams(params.url());
  17483. param.keyword = $scope.filter.keyword;
  17484. var keyword = $scope.filter.keyword;
  17485. // param.keyword = $scope.filter.keyword;
  17486. BrandActiveAPI.getSimpleInfoPage(param, {}, function (page) {
  17487. if (page) {
  17488. params.total(page.totalElements);
  17489. $defer.resolve(page.content);
  17490. }
  17491. }, function () {
  17492. });
  17493. }
  17494. });
  17495. // 搜索
  17496. $scope.search = function () {
  17497. // $scope.brandsTableParams.filter({$: $scope.filter.keyword});
  17498. $scope.brandsTableParams.page(1);
  17499. $scope.brandsTableParams.reload();
  17500. };
  17501. // 选择
  17502. $scope.select = function (brand) {
  17503. $modalInstance.close(brand);
  17504. };
  17505. // 关闭
  17506. $scope.cancel = function () {
  17507. $modalInstance.dismiss();
  17508. };
  17509. }]);
  17510. /**
  17511. * 招标单批量导入
  17512. */
  17513. app.controller('PurcTenderUploadCtrl', ['$scope', 'toaster', '$upload', '$modalInstance', function ($scope, toaster, $upload, $modalInstance) {
  17514. // 通过excel批量上传物料
  17515. $scope.result = null;
  17516. $scope.upload = function () {
  17517. var file = $scope.myFiles[0];
  17518. $upload.upload({
  17519. url: 'tender/release/excel',
  17520. file: file,
  17521. method: 'POST'
  17522. }).success(function (data) {
  17523. $scope.result = data;
  17524. $scope.success = $scope.result.success;
  17525. $scope.total = $scope.result.total;
  17526. $scope.alters = $scope.result.alters;
  17527. }).error(function (response) {
  17528. toaster.pop('error', '提示', '上传失败,请检查填写格式');
  17529. });
  17530. };
  17531. // 查看范例
  17532. $scope.showImg = function () {
  17533. var src = "static/img/eg/uploadTenderProducts_example.png", box = $('#image-box');
  17534. box.show();
  17535. box.find('img').attr('src', src);
  17536. box.find('a').click(function () {
  17537. box.hide();
  17538. });
  17539. box.dblclick(function () {
  17540. box.hide();
  17541. });
  17542. };
  17543. // 下载模板
  17544. $scope.download = function () {
  17545. window.location.href = 'tender/upload/template';
  17546. };
  17547. $scope.enSure = function () {
  17548. $modalInstance.close($scope.result.items);
  17549. }
  17550. $scope.cancel = function () {
  17551. $modalInstance.dismiss();
  17552. }
  17553. }]);
  17554. /**
  17555. * 评标
  17556. */
  17557. app.controller('PurcEvaluationCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'CurrentRole', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, CurrentRole) {
  17558. BaseService.scrollBackToTop();
  17559. // 获取当前用户是否为普通用户
  17560. CurrentRole.isUser({}, {}, function (data) {
  17561. $scope.isUser = data.isUser;
  17562. });
  17563. $scope.tenderItems = [];
  17564. // 采购方获取评标单
  17565. var evaluation = function () {
  17566. $scope.loading = true;
  17567. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  17568. data.$editing = false;
  17569. $scope.tender = data;
  17570. $scope.tableParams = new ngTableParams({}, {dataset: data});
  17571. // $scope.tableParams.sorting($scope.sort.field, $scope.sort.desc);
  17572. $scope.loading = false;
  17573. }, function (response) {
  17574. $scope.loading = false;
  17575. toaster.pop('error', '数据加载失败', response.data);
  17576. });
  17577. };
  17578. evaluation();
  17579. $scope.orderType = '';
  17580. // $scope.dir = '-';
  17581. // 改变排序顺序
  17582. $scope.changeOrder = function (type) {
  17583. $scope.orderType = type;
  17584. };
  17585. $scope.submit = function (tender) {
  17586. var canSubmit = false;
  17587. var hasDecide = false;
  17588. angular.forEach(tender.purchaseTenderProds, function (tenderProd) {
  17589. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17590. if (saleTenderItem.price && 0 !== saleTenderItem.saleTender.auditStatus && typeof saleTenderItem.applyStatus !== 'undefined') { // 只要存在报价的行,就需要对其中一个定标
  17591. hasDecide = true;
  17592. }
  17593. });
  17594. if (hasDecide) {
  17595. canSubmit = true;
  17596. }
  17597. });
  17598. if (!canSubmit) {
  17599. toaster.pop('info', '提示', '您还有已投标未选定的产品!');
  17600. } else {
  17601. PurcTender.decide(tender, function () {
  17602. toaster.pop('success', '确认成功');
  17603. window.location.hash = '#/purc/tender';
  17604. }, function (response) {
  17605. toaster.pop('error', '确认失败', response.data);
  17606. });
  17607. }
  17608. }
  17609. }]);
  17610. /**
  17611. * 客户招标
  17612. *
  17613. */
  17614. app.controller('SaleTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', 'PurcTenderInfo',
  17615. function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise, PurcTenderInfo) {
  17616. BaseService.scrollBackToTop();
  17617. if ($rootScope.active) {
  17618. $scope.active = $rootScope.active;
  17619. $rootScope.active = null;
  17620. } else {
  17621. $scope.active = 'todo';
  17622. }
  17623. $scope.searchStatus = false;
  17624. /**
  17625. * 改变类型
  17626. */
  17627. var getTypeCondition = function (zone, condition) {
  17628. if (zone == -1) {
  17629. condition.ifOpen = null;
  17630. } else if (zone == 1) {
  17631. condition.ifOpen = 1;
  17632. } else {
  17633. condition.ifOpen = 0;
  17634. }
  17635. };
  17636. $scope.dateZoneText = '不限';
  17637. $scope.typeText = '全部';
  17638. $scope.deliveryZoneText = '不限';
  17639. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17640. /* 时间筛选初始化*/
  17641. var fromDate = new Date();
  17642. var toDate = new Date();
  17643. fromDate.setMonth(fromDate.getMonth() - 1);
  17644. fromDate.setHours(0, 0, 0, 0);
  17645. toDate.setHours(23, 59, 59, 999);
  17646. $scope.condition.dateFrom = fromDate;
  17647. $scope.condition.dateTo = toDate;
  17648. $scope.changeDateZone = function (zone) {
  17649. $scope.condition.dateZone = zone;
  17650. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17651. $scope.condition.$dateZoneOpen = false;
  17652. getDateCondition(zone, $scope.condition);
  17653. $scope.tableParams.page(1);
  17654. $scope.tableParams.reload();
  17655. };
  17656. $scope.changeDeliveryZone = function (zone) {
  17657. $scope.condition.deliveryZoneText = zone;
  17658. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17659. $scope.condition.$delievryZoneOpen = false;
  17660. getDelveryCondition(zone, $scope.condition);
  17661. $scope.tableParams.page(1);
  17662. $scope.tableParams.reload();
  17663. };
  17664. $scope.changeType = function (type) {
  17665. $scope.condition.type = type;
  17666. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17667. getTypeCondition(type, $scope.condition);
  17668. $scope.tableParams.reload();
  17669. };
  17670. $scope.setActive = function (state) {
  17671. if ($scope.active != state) {
  17672. $scope.active = state;
  17673. if ($scope.tableParams.page() == 1)
  17674. $scope.tableParams.reload();
  17675. else
  17676. $scope.tableParams.page(1);
  17677. }
  17678. };
  17679. var getService = function () {
  17680. if ($scope.searchStatus) {
  17681. return PurcTender;
  17682. }
  17683. return PurcTenderInfo;
  17684. };
  17685. $scope.tableParams = new ngTableParams({
  17686. page: 1,
  17687. count: 20,
  17688. sorting: {
  17689. 'id': 'desc'
  17690. }
  17691. }, {
  17692. total: 0,
  17693. counts: [5, 10, 25, 50],
  17694. getData: function ($defer, params) {
  17695. $scope.loading = true;
  17696. var pageParams = params.url();
  17697. var realActive = {};
  17698. pageParams.searchFilter = { // 筛选条件
  17699. keyword: $scope.keyword,
  17700. pt_ifopen: $scope.condition.ifOpen,
  17701. fromDate: getDateTime($scope.condition.dateFrom),
  17702. endDate: getDateTime($scope.condition.dateTo)
  17703. };
  17704. AccountEnterprise.get({}, function (data) {
  17705. $scope.currentEn = data;
  17706. });
  17707. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17708. $scope.loading = false;
  17709. if (page) {
  17710. params.total(page.totalElement);
  17711. $defer.resolve(page.content);
  17712. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17713. angular.forEach(page.content, function (purcTender) {
  17714. purcTender.vendorHasBid = false;
  17715. angular.forEach(purcTender.purchaseTenderProds, function (tenderProd) {
  17716. angular.forEach(tenderProd.saleTenderItems, function (saleTenderItem) {
  17717. if ($scope.currentEn.uu === saleTenderItem.saleTender.vendUU) {
  17718. tenderProd.currentItem = saleTenderItem;
  17719. if (saleTenderItem.price && saleTenderItem.saleTender.auditStatus != 0) { //TODO 如果存在当前企业的投标明细已投标且不在已提交状态,即判断为已投标
  17720. purcTender.vendorHasBid = true;
  17721. }
  17722. }
  17723. });
  17724. });
  17725. });
  17726. }
  17727. }, function (response) {
  17728. $scope.loading = false;
  17729. toaster.pop('error', '数据加载失败', response.data);
  17730. });
  17731. }
  17732. });
  17733. //获得各分类未阅读数量
  17734. var getUnreadCount = function () {
  17735. PurcTender.getUnreadCount(null, function (data) {
  17736. $scope.unread = data;
  17737. });
  17738. };
  17739. getUnreadCount();
  17740. //设置单据已读
  17741. $scope.setOrdersRead = function (id) {
  17742. // 如果单据本身已读,则不发送请求修改数据
  17743. if (!$scope.isUnread(id)){
  17744. return;
  17745. }
  17746. var sourceId = [];
  17747. sourceId.push(id);
  17748. PurcTender.setRead({}, sourceId, function (message) {
  17749. // $scope.getUnreadIds();
  17750. getUnreadCount();
  17751. });
  17752. };
  17753. var getUnreadIds = function () {
  17754. PurcTender.getUnreadIds({}, "", function (message) {
  17755. $scope.unreadCode = message.content;
  17756. });
  17757. };
  17758. getUnreadIds();
  17759. $scope.isUnread = function (id) {
  17760. for (var i in $scope.unreadCode) {
  17761. if (id == $scope.unreadCode[i]) {
  17762. return true;
  17763. }
  17764. }
  17765. };
  17766. $scope.openDatePicker = function ($event, item, openParam) {
  17767. $event.preventDefault();
  17768. $event.stopPropagation();
  17769. item[openParam] = !item[openParam];
  17770. };
  17771. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17772. $event.preventDefault();
  17773. $event.stopPropagation();
  17774. item[openParam] = !item[openParam];
  17775. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17776. $scope.tableParams.reload();
  17777. }
  17778. };
  17779. $scope.parseDate = function (dateStr) {
  17780. if (dateStr)
  17781. return Date.parse(dateStr, 'yyyy-MM-dd');
  17782. return new Date();
  17783. };
  17784. // 选择查找日期
  17785. $scope.onDateCondition = function () {
  17786. $scope.tableParams.page(1);
  17787. $scope.tableParams.reload();
  17788. };
  17789. // 搜索框回车
  17790. $scope.onSearch = function () {
  17791. $scope.searchStatus = true;
  17792. $scope.tableParams.page(1);
  17793. $scope.tableParams.reload();
  17794. };
  17795. }]);
  17796. /**
  17797. * 招标提问列表
  17798. *
  17799. */
  17800. app.controller('SaleTenderQuestionListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17801. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17802. BaseService.scrollBackToTop();
  17803. if ($rootScope.active) {
  17804. $scope.active = $rootScope.active;
  17805. $rootScope.active = null;
  17806. } else {
  17807. $scope.active = 'todo';
  17808. }
  17809. $scope.searchStatus = false;
  17810. /**
  17811. * 改变类型
  17812. */
  17813. var getTypeCondition = function (zone, condition) {
  17814. if (zone == -1) {
  17815. condition.ifOpen = null;
  17816. } else if (zone == 1) {
  17817. condition.ifOpen = 1;
  17818. } else {
  17819. condition.ifOpen = 0;
  17820. }
  17821. };
  17822. $scope.dateZoneText = '不限';
  17823. $scope.typeText = '全部';
  17824. $scope.deliveryZoneText = '不限';
  17825. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  17826. /* 时间筛选初始化*/
  17827. var fromDate = new Date();
  17828. var toDate = new Date();
  17829. fromDate.setMonth(fromDate.getMonth() - 1);
  17830. fromDate.setHours(0, 0, 0, 0);
  17831. toDate.setHours(23, 59, 59, 999);
  17832. $scope.condition.dateFrom = fromDate;
  17833. $scope.condition.dateTo = toDate;
  17834. $scope.changeDateZone = function (zone) {
  17835. $scope.condition.dateZone = zone;
  17836. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  17837. $scope.condition.$dateZoneOpen = false;
  17838. getDateCondition(zone, $scope.condition);
  17839. $scope.tableParams.page(1);
  17840. $scope.tableParams.reload();
  17841. };
  17842. $scope.changeDeliveryZone = function (zone) {
  17843. $scope.condition.deliveryZoneText = zone;
  17844. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  17845. $scope.condition.$delievryZoneOpen = false;
  17846. getDelveryCondition(zone, $scope.condition);
  17847. $scope.tableParams.page(1);
  17848. $scope.tableParams.reload();
  17849. };
  17850. $scope.changeType = function (type) {
  17851. $scope.condition.type = type;
  17852. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  17853. getTypeCondition(type, $scope.condition);
  17854. $scope.tableParams.reload();
  17855. };
  17856. $scope.setActive = function (state) {
  17857. if ($scope.active != state) {
  17858. $scope.active = state;
  17859. if ($scope.tableParams.page() == 1)
  17860. $scope.tableParams.reload();
  17861. else
  17862. $scope.tableParams.page(1);
  17863. }
  17864. };
  17865. //TODO 增加直接从数据库取方法之后修改
  17866. var getService = function () {
  17867. if ($scope.searchStatus) {
  17868. return SaleTenderQuestion;
  17869. }
  17870. return SaleTenderQuestion;
  17871. };
  17872. $scope.tableParams = new ngTableParams({
  17873. page: 1,
  17874. count: 20,
  17875. sorting: {
  17876. 'id': 'desc'
  17877. }
  17878. }, {
  17879. total: 0,
  17880. counts: [5, 10, 25, 50],
  17881. getData: function ($defer, params) {
  17882. $scope.loading = true;
  17883. var pageParams = params.url();
  17884. var realActive = {};
  17885. pageParams.searchFilter = { // 筛选条件
  17886. keyword: $scope.keyword,
  17887. fromDate: getDateTime($scope.condition.dateFrom),
  17888. endDate: getDateTime($scope.condition.dateTo)
  17889. };
  17890. AccountEnterprise.get({}, function (data) {
  17891. $scope.currentEn = data;
  17892. });
  17893. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  17894. $scope.loading = false;
  17895. params.total(page.totalElement);
  17896. $defer.resolve(page.content);
  17897. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  17898. }, function (response) {
  17899. $scope.loading = false;
  17900. toaster.pop('error', '数据加载失败', response.data);
  17901. });
  17902. }
  17903. });
  17904. //TODO 获得各分类未阅读数量
  17905. //TODO 设置单据已读
  17906. $scope.openDatePicker = function ($event, item, openParam) {
  17907. $event.preventDefault();
  17908. $event.stopPropagation();
  17909. item[openParam] = !item[openParam];
  17910. };
  17911. $scope.openFilterDatePicker = function ($event, item, openParam) {
  17912. $event.preventDefault();
  17913. $event.stopPropagation();
  17914. item[openParam] = !item[openParam];
  17915. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  17916. $scope.tableParams.reload();
  17917. }
  17918. };
  17919. $scope.parseDate = function (dateStr) {
  17920. if (dateStr)
  17921. return Date.parse(dateStr, 'yyyy-MM-dd');
  17922. return new Date();
  17923. };
  17924. // 选择查找日期
  17925. $scope.onDateCondition = function () {
  17926. $scope.tableParams.page(1);
  17927. $scope.tableParams.reload();
  17928. };
  17929. // 搜索框回车
  17930. $scope.onSearch = function (keyword) {
  17931. // 每次搜索重置获取数据方法
  17932. $scope.searchMethod = false;
  17933. if(keyword != null && keyword != '') {
  17934. $scope.searchMethod = true;
  17935. }
  17936. $scope.tableParams.page(1);
  17937. $scope.tableParams.reload();
  17938. };
  17939. }]);
  17940. /**
  17941. * 投标单提问单详情
  17942. */
  17943. app.controller('SaleTenderQuestionDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams'
  17944. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams){
  17945. BaseService.scrollBackToTop();
  17946. $scope.loading = true;
  17947. var loadData = function () {
  17948. SaleTenderQuestion.getDetail({id: $stateParams.id}, function(data){
  17949. $scope.loading = false;
  17950. $scope.question = data;
  17951. } , function (response) {
  17952. $scope.loading = false;
  17953. toaster.pop('error', '数据加载失败');
  17954. });
  17955. };
  17956. loadData();
  17957. }]);
  17958. /**
  17959. * 招标答疑列表
  17960. *
  17961. */
  17962. app.controller('PurcTenderAnswerListCtrl', ['$scope', '$filter', 'SaleTenderQuestion', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise',
  17963. function ($scope, $filter, SaleTenderQuestion, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  17964. BaseService.scrollBackToTop();
  17965. if ($rootScope.active) {
  17966. $scope.active = $rootScope.active;
  17967. $rootScope.active = null;
  17968. } else {
  17969. $scope.active = 'todo';
  17970. }
  17971. $scope.searchStatus = false;
  17972. /**
  17973. * 改变类型
  17974. */
  17975. var getTypeCondition = function (zone, condition) {
  17976. if (zone == -1) {
  17977. condition.ifOpen = null;
  17978. } else if (zone == 1) {
  17979. condition.ifOpen = 1;
  17980. } else {
  17981. condition.ifOpen = 0;
  17982. }
  17983. };
  17984. /**
  17985. * 当前页面状态按钮过滤
  17986. */
  17987. var getAnswer = function (active) {
  17988. var fn = 'getAllAnswer';
  17989. switch (active) {
  17990. case 'done':
  17991. fn = 'getDoneAnswer';
  17992. break;
  17993. case 'todo':
  17994. fn = 'getTodoAnswer';
  17995. break;
  17996. }
  17997. return fn;
  17998. };
  17999. $scope.dateZoneText = '不限';
  18000. $scope.typeText = '全部';
  18001. $scope.deliveryZoneText = '不限';
  18002. $scope.condition = {dateZone: 1, deliveryZone: -1, type: -1};
  18003. /* 时间筛选初始化*/
  18004. var fromDate = new Date();
  18005. var toDate = new Date();
  18006. fromDate.setMonth(fromDate.getMonth() - 1);
  18007. fromDate.setHours(0, 0, 0, 0);
  18008. toDate.setHours(23, 59, 59, 999);
  18009. $scope.condition.dateFrom = fromDate;
  18010. $scope.condition.dateTo = toDate;
  18011. $scope.changeDateZone = function (zone) {
  18012. $scope.condition.dateZone = zone;
  18013. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 6 ? '最近六个月' : '自定义'));
  18014. $scope.condition.$dateZoneOpen = false;
  18015. getDateCondition(zone, $scope.condition);
  18016. $scope.tableParams.page(1);
  18017. $scope.tableParams.reload();
  18018. };
  18019. $scope.changeDeliveryZone = function (zone) {
  18020. $scope.condition.deliveryZoneText = zone;
  18021. $scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
  18022. $scope.condition.$delievryZoneOpen = false;
  18023. getDelveryCondition(zone, $scope.condition);
  18024. $scope.tableParams.page(1);
  18025. $scope.tableParams.reload();
  18026. };
  18027. $scope.changeType = function (type) {
  18028. $scope.condition.type = type;
  18029. $scope.typeText = typeof type == 'undefined' ? '全部' : (type == -1 ? '全部' : (type == 1 ? '公开' : '指定'));
  18030. getTypeCondition(type, $scope.condition);
  18031. $scope.tableParams.reload();
  18032. };
  18033. $scope.setActive = function (state) {
  18034. if ($scope.active != state) {
  18035. $scope.active = state;
  18036. if ($scope.tableParams.page() == 1)
  18037. $scope.tableParams.reload();
  18038. else
  18039. $scope.tableParams.page(1);
  18040. }
  18041. };
  18042. //TODO 增加直接从数据库取方法之后修改
  18043. var getService = function () {
  18044. if ($scope.searchStatus) {
  18045. return SaleTenderQuestion;
  18046. }
  18047. return SaleTenderQuestion;
  18048. };
  18049. $scope.tableParams = new ngTableParams({
  18050. page: 1,
  18051. count: 20,
  18052. sorting: {
  18053. 'id': 'desc'
  18054. }
  18055. }, {
  18056. total: 0,
  18057. counts: [5, 10, 25, 50],
  18058. getData: function ($defer, params) {
  18059. $scope.loading = true;
  18060. var pageParams = params.url();
  18061. var realActive = {};
  18062. pageParams.searchFilter = { // 筛选条件
  18063. keyword: $scope.keyword,
  18064. fromDate: getDateTime($scope.condition.dateFrom),
  18065. endDate: getDateTime($scope.condition.dateTo)
  18066. };
  18067. AccountEnterprise.get({}, function (data) {
  18068. $scope.currentEn = data;
  18069. });
  18070. getService()[getAnswer($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18071. $scope.loading = false;
  18072. params.total(page.totalElement);
  18073. $defer.resolve(page.content);
  18074. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  18075. }, function (response) {
  18076. $scope.loading = false;
  18077. toaster.pop('error', '数据加载失败', response.data);
  18078. });
  18079. }
  18080. });
  18081. //TODO 获得各分类未阅读数量
  18082. //TODO 设置单据已读
  18083. $scope.openDatePicker = function ($event, item, openParam) {
  18084. $event.preventDefault();
  18085. $event.stopPropagation();
  18086. item[openParam] = !item[openParam];
  18087. };
  18088. $scope.openFilterDatePicker = function ($event, item, openParam) {
  18089. $event.preventDefault();
  18090. $event.stopPropagation();
  18091. item[openParam] = !item[openParam];
  18092. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  18093. $scope.tableParams.reload();
  18094. }
  18095. };
  18096. $scope.parseDate = function (dateStr) {
  18097. if (dateStr)
  18098. return Date.parse(dateStr, 'yyyy-MM-dd');
  18099. return new Date();
  18100. };
  18101. // 选择查找日期
  18102. $scope.onDateCondition = function () {
  18103. $scope.tableParams.page(1);
  18104. $scope.tableParams.reload();
  18105. };
  18106. // 搜索框回车
  18107. $scope.onSearch = function (keyword) {
  18108. // 每次搜索重置获取数据方法
  18109. $scope.searchMethod = false;
  18110. if(keyword != null && keyword != '') {
  18111. $scope.searchMethod = true;
  18112. }
  18113. $scope.tableParams.page(1);
  18114. $scope.tableParams.reload();
  18115. };
  18116. }]);
  18117. /**
  18118. * 招标答疑单详情
  18119. */
  18120. app.controller('PurcTenderAnswerDetailCtrl', ['$scope', 'toaster', 'BaseService', 'SaleTenderQuestion', '$stateParams', '$modal'
  18121. , function($scope, toaster, BaseService, SaleTenderQuestion, $stateParams, $modal){
  18122. BaseService.scrollBackToTop();
  18123. $scope.loading = true;
  18124. var loadData = function () {
  18125. SaleTenderQuestion.getAnswerDetail({id: $stateParams.id}, function(data){
  18126. $scope.loading = false;
  18127. $scope.answer = data;
  18128. var now = new Date();
  18129. if ($scope.answer.questionEndDate < now.getTime()) {
  18130. $scope.answer.questionEnd = 1;
  18131. } else {
  18132. $scope.answer.questionEnd = 0;
  18133. }
  18134. } , function (response) {
  18135. $scope.loading = false;
  18136. toaster.pop('error', '数据加载失败');
  18137. });
  18138. };
  18139. loadData();
  18140. // 回答
  18141. $scope.sendAnswer = function (){
  18142. var modalInstance = $modal.open({
  18143. animation: true,
  18144. templateUrl: 'static/tpl/index/purc/tender_answer.html',
  18145. controller: 'PurcTenderAnswerCtrl',
  18146. size: 'lg',
  18147. resolve: {
  18148. answer: function () {
  18149. return $scope.answer;
  18150. } //传递当前答疑单到模态框Controller
  18151. }
  18152. });
  18153. modalInstance.result.then(function () {
  18154. toaster.pop('success', '答疑成功');
  18155. }, function () {
  18156. });
  18157. };
  18158. }]);
  18159. /**
  18160. * 招标单答疑
  18161. */
  18162. app.controller('PurcTenderAnswerCtrl', ['$scope', 'answer','$modalInstance', '$upload', 'toaster', function($scope, answer, $modalInstance, $upload ,toaster){
  18163. $scope.answer = answer;
  18164. $scope.cancel = function() {
  18165. $modalInstance.dismiss();
  18166. };
  18167. //确认回答
  18168. $scope.ok = function (form) {
  18169. $scope.loading = true;
  18170. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18171. $upload.upload({
  18172. url: 'tender/question/answer/send',
  18173. method: 'POST',
  18174. file: file,
  18175. data: {
  18176. json: $scope.answer
  18177. }
  18178. }).success(function (data) {
  18179. $scope.loading = false;
  18180. $modalInstance.close('success');
  18181. }).error(function (data) {
  18182. $scope.loading = false;
  18183. toaster.pop('error', '错误', '出现异常,答疑失败');
  18184. });
  18185. };
  18186. }]);
  18187. /**
  18188. * 平台公开招标
  18189. *
  18190. */
  18191. app.controller('SaleOpenTenderCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', 'AccountEnterprise', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope, AccountEnterprise) {
  18192. BaseService.scrollBackToTop();
  18193. /**
  18194. * 改变单据日期范围
  18195. */
  18196. var getTenderDateCondition = function (zone, condition) {
  18197. var date = new Date();
  18198. if (zone == -1) {
  18199. condition.dateFrom = null;
  18200. condition.dateTo = null;
  18201. } else if (zone == 7) { // 一星期内
  18202. date.setDate(date.getDate() - 7);
  18203. condition.dateFrom = date;
  18204. condition.dateTo = new Date();
  18205. } else if (zone == 1) { // 一个月内
  18206. date.setMonth(date.getMonth() - 1);
  18207. condition.dateFrom = date;
  18208. condition.dateTo = new Date();
  18209. } else if (zone == 3) { // 三个月内
  18210. date.setMonth(date.getMonth() - 3);
  18211. condition.dateFrom = date;
  18212. condition.dateTo = new Date();
  18213. } else if (zone == 6) { // 半年内
  18214. date.setMonth(date.getMonth() - 6);
  18215. condition.dateFrom = date;
  18216. condition.dateTo = new Date();
  18217. } else { // 一年内
  18218. date.setYear(date.getYear() - 1);
  18219. condition.dateFrom = date;
  18220. condition.dateTo = new Date();
  18221. }
  18222. };
  18223. $scope.active = 'all';
  18224. $scope.dateZoneText = '不限';
  18225. $scope.deliveryZoneText = '不限';
  18226. $scope.condition = {dateZone: -1};
  18227. $scope.changeDateZone = function (zone) {
  18228. $scope.condition.dateZone = zone;
  18229. $scope.condition.$dateZoneOpen = false;
  18230. getTenderDateCondition(zone, $scope.condition);
  18231. $scope.tableParams.page(1);
  18232. $scope.tableParams.reload();
  18233. };
  18234. $scope.openDatePicker = function ($event, item, openParam) {
  18235. $event.preventDefault();
  18236. $event.stopPropagation();
  18237. item[openParam] = !item[openParam];
  18238. };
  18239. $scope.parseDate = function (dateStr) {
  18240. if (dateStr)
  18241. return Date.parse(dateStr, 'yyyy-MM-dd');
  18242. return new Date();
  18243. };
  18244. // 选择查找日期
  18245. $scope.onDateCondition = function () {
  18246. $scope.tableParams.page(1);
  18247. $scope.tableParams.reload();
  18248. };
  18249. var getOpenState = function (active) {
  18250. var fn = 'getOpenAll';
  18251. switch (active) {
  18252. case 'all':
  18253. fn = 'getOpenAll';
  18254. break;
  18255. // case 'done':
  18256. // fn = 'getOpenDone';break;
  18257. case 'todo':
  18258. fn = 'getOpenTodo';
  18259. break;
  18260. case 'end':
  18261. fn = 'getOpenEnd';
  18262. break;
  18263. // case 'waiting':
  18264. // fn = 'getOpenWaiting';break;
  18265. }
  18266. return fn;
  18267. };
  18268. $scope.tableParams = new ngTableParams({
  18269. page: 1,
  18270. count: 20,
  18271. sorting: {
  18272. 'tender.endDate': 'desc',
  18273. 'tender.enterprise.enName': 'asc',
  18274. 'tender.code': 'asc'
  18275. }
  18276. }, {
  18277. total: 0,
  18278. counts: [],
  18279. getData: function ($defer, params) {
  18280. $scope.loading = true;
  18281. var pageParams = params.url();
  18282. var realActive = {};
  18283. pageParams.searchFilter = { // 筛选条件
  18284. keyword: $scope.keyword,
  18285. fromDate: getDateTime($scope.condition.dateFrom),
  18286. endDate: getDateTime($scope.condition.dateTo)
  18287. };
  18288. AccountEnterprise.get({}, function (data) {
  18289. $scope.currentEn = data;
  18290. });
  18291. PurcTender[getOpenState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18292. $scope.loading = false;
  18293. if (page) {
  18294. params.total(page.totalElement);
  18295. $defer.resolve(page.content);
  18296. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  18297. }
  18298. }, function (response) {
  18299. $scope.loading = false;
  18300. toaster.pop('error', '数据加载失败', response.data);
  18301. });
  18302. }
  18303. });
  18304. $scope.toDetail = function (id) {
  18305. window.location.hash = '#/baseInfo/openTenderDetail/' + id;
  18306. };
  18307. // 搜索框回车
  18308. $scope.onSearch = function () {
  18309. $scope.tableParams.page(1);
  18310. $scope.tableParams.reload();
  18311. };
  18312. }]);
  18313. /**
  18314. * 采购方查看供应商投标单
  18315. */
  18316. app.controller('SaleVendorTenderDetailCtrl', ['$scope', '$filter', 'PurcTender', 'ngTableParams', 'toaster', 'BaseService', '$stateParams', '$modal', '$rootScope', function ($scope, $filter, PurcTender, ngTableParams, toaster, BaseService, $stateParams, $modal, $rootScope) {
  18317. $scope.loading = true;
  18318. PurcTender.getVendorSaleTenderDetail({tenderId: $stateParams.id, vendUU:$stateParams.vendUU}, function (data) {
  18319. $scope.saleTender = data.saleTender;
  18320. $scope.tender = data.tender;
  18321. $scope.loading = false;
  18322. }, function (response) {
  18323. $scope.loading = false;
  18324. toaster.pop('error', '数据加载失败', response.data);
  18325. });
  18326. }]);
  18327. /**
  18328. * 查看投标单详情
  18329. */
  18330. 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) {
  18331. BaseService.scrollBackToTop();
  18332. if (!$scope.attaches) {
  18333. $scope.attaches = []; // 存放上传了的附件
  18334. }
  18335. AccountEnterprise.get({}, function (data) {
  18336. $scope.currentEn = data;
  18337. });
  18338. // 获取当前用户是否为普通用户
  18339. CurrentRole.isUser({}, {}, function (data) {
  18340. $scope.isUser = data.isUser;
  18341. });
  18342. $scope.loading = true;
  18343. PurcTender.getSaleTenderDetail({tenderId: $stateParams.id}, function (data) {
  18344. $scope.saleTender = data.saleTender;
  18345. $scope.tender = data.tender;
  18346. $scope.loading = false;
  18347. }, function (response) {
  18348. $scope.loading = false;
  18349. toaster.pop('error', '数据加载失败', response.data);
  18350. });
  18351. // 提问
  18352. $scope.sendQuestion = function (){
  18353. var modalInstance = $modal.open({
  18354. animation: true,
  18355. templateUrl: 'static/tpl/index/sale/tender_question.html',
  18356. controller: 'SaleTenderQuestionCtrl',
  18357. size: 'lg',
  18358. resolve: {
  18359. saleTender: function () {
  18360. return $scope.saleTender;
  18361. } //传递当前投标单到模态框Controller
  18362. }
  18363. });
  18364. modalInstance.result.then(function () {
  18365. toaster.pop('success', '提问成功');
  18366. }, function () {
  18367. });
  18368. };
  18369. $scope.upload = function (myFile) { // 上传附件
  18370. var file = $scope.myFile, file = file && file.length > 0 ? file : null;
  18371. $upload.upload({
  18372. url: 'tender/addTenderItemAttach',
  18373. file: file,
  18374. method: 'POST'
  18375. }).success(function (attach) {
  18376. $scope.attaches.push(attach);
  18377. });
  18378. };
  18379. $scope.removeAttach = function (attachId, index) {
  18380. $scope.attaches.splice(index, 1);
  18381. };
  18382. var taxrateYes = false;
  18383. var cycleYes = false;
  18384. var priceYes = false;
  18385. $scope.canSave = false;
  18386. $scope.validateThis = function (value, type) {
  18387. if ("" != value) {
  18388. switch (type) {
  18389. case 'taxrate':
  18390. var regex = /^\+?[0-9][0-9]{0,1}$/;
  18391. if (regex.test(value)) {
  18392. taxrateYes = true;
  18393. } else {
  18394. toaster.pop('warning', '警告', '税率不合法,请重新填写');
  18395. }
  18396. break;
  18397. case 'cycle':
  18398. regex = /^\+?[1-9][0-9]*$/;
  18399. if (regex.test(value)) {
  18400. cycleYes = true;
  18401. } else {
  18402. toaster.pop('warning', '警告', '周期不合法,请重新填写');
  18403. }
  18404. break;
  18405. case 'price':
  18406. regex = /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18407. if (regex.test(value) && value !== 0) {
  18408. priceYes = true;
  18409. } else {
  18410. toaster.pop('warning', '警告', '请确认单价是否填写正确');
  18411. }
  18412. break;
  18413. }
  18414. }
  18415. };
  18416. $scope.emNumYes = true;
  18417. $scope.validEmNum = function (value) {
  18418. var regex = /^\+?[1-9][0-9]*$/;
  18419. if (!regex.test(value) || value === 0 || value !== null) {
  18420. $scope.emNumYes = false;
  18421. toaster.pop('warning', '警告', '人数不合法,请重新填写');
  18422. }
  18423. };
  18424. $scope.validateProds = function (saleTender) {
  18425. $scope.canSave = true;
  18426. var cycleRegex = /^\+?[1-9][0-9]*$/;
  18427. var taxrateRegex = /^\+?[0-9][0-9]{0,1}$/;
  18428. var priceRegex = /^(([0-9]+\.[0-9]{1,6})|([0-9]*[1-9][0-9]*\.[0-9]{1,6})|([0-9]*[1-9][0-9]*))$/; // 非零最多六位小数正实数
  18429. if ($scope.tender.ifAll == 1) { // 全包时需要所有信息都填写并合法才可以投标
  18430. // 全包全部需要填写,且需要符合正则式
  18431. angular.forEach(saleTender.saleTenderItems, function(item) {
  18432. if ((!item.cycle || !item.price) || (!cycleRegex.test(item.cycle) || !priceRegex.test(item.price))) {
  18433. $scope.canSave = false;
  18434. }
  18435. });
  18436. if (!saleTender.cycle || !saleTender.taxrate || !cycleRegex.test(saleTender.cycle) || !taxrateRegex.test(saleTender.taxrate)) {
  18437. $scope.canSave = false;
  18438. }
  18439. } else { // 非全包模式
  18440. angular.forEach(saleTender.saleTenderItems, function(item) {
  18441. if (item.cycle || item.taxrate || item.price) {
  18442. // /^(0|[0-9][0-9]{0,9})(\.[0-9]{1,6})?$/;
  18443. // 判断填写过的有为0或不符合正则式的,设置不能保存
  18444. if (!cycleRegex.test(item.cycle) || !taxrateRegex.test(item.taxrate) || !priceRegex.test(item.price)) {
  18445. $scope.canSave = false;
  18446. } else {
  18447. $scope.canSave = true;
  18448. }
  18449. }
  18450. });
  18451. }
  18452. };
  18453. // 投标
  18454. $scope.bidIt = function (saleTender) {
  18455. $scope.loading = true;
  18456. if (saleTender.enterpriseBaseInfo.enEstablishDate instanceof Date) {
  18457. saleTender.enterpriseBaseInfo.enEstablishDate = saleTender.enterpriseBaseInfo.enEstablishDate.getTime();
  18458. }
  18459. saleTender.bidAttaches.push.apply(saleTender.bidAttaches, $scope.attaches);
  18460. angular.forEach(saleTender.saleTenderItems, function (item) {
  18461. item.tenderProd = {};
  18462. if ("" == item.price && "" == item.taxrate && "" == item.cycle) {
  18463. item.price = 0;
  18464. item.cycle = 0;
  18465. item.taxrate = 0;
  18466. }
  18467. });
  18468. PurcTender.reply({}, saleTender, function (data) {
  18469. $scope.loading = false;
  18470. toaster.pop('info', '成功', '投标成功');
  18471. window.location.hash = '#/sale/tender';
  18472. }, function (response) {
  18473. $scope.loading = false;
  18474. toaster.pop('error', '投标失败', response.data);
  18475. });
  18476. };
  18477. $scope.condition = {
  18478. $fromOpened: false
  18479. };
  18480. $scope.getMaxDate = function () {
  18481. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18482. };
  18483. $scope.openDatePicker = function ($event, item, openParam) {
  18484. $event.preventDefault();
  18485. $event.stopPropagation();
  18486. item[openParam] = !item[openParam];
  18487. };
  18488. }]);
  18489. /**
  18490. * 投标单提问
  18491. */
  18492. app.controller('SaleTenderQuestionCtrl', ['$scope', 'saleTender','$modalInstance', '$upload', 'toaster', function($scope, saleTender, $modalInstance, $upload ,toaster){
  18493. $scope.saleTender = saleTender;
  18494. // 当前日期,用作新增提问
  18495. $scope.currentDay = new Date();
  18496. $scope.question = {
  18497. inDate : null,
  18498. replyDate : null,
  18499. topic : null,
  18500. status : null,
  18501. content : null,
  18502. questionAttaches : []
  18503. };
  18504. $scope.cancel = function() {
  18505. $modalInstance.dismiss();
  18506. };
  18507. //确认提问
  18508. $scope.ok = function (form) {
  18509. $scope.loading = true;
  18510. var files = form.attachFile.$viewValue, file = files && files.length > 0 ? files[0] : null;
  18511. $upload.upload({
  18512. url: 'tender/question/send/' + $scope.saleTender.id,
  18513. method: 'POST',
  18514. file: file,
  18515. data: {
  18516. json: $scope.question
  18517. }
  18518. }).success(function (data) {
  18519. $scope.loading = false;
  18520. $modalInstance.close('success');
  18521. }).error(function (data) {
  18522. $scope.loading = false;
  18523. toaster.pop('error', '错误', '出现异常,提问失败');
  18524. });
  18525. };
  18526. }]);
  18527. /**
  18528. * 公开招标转投标单
  18529. */
  18530. 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) {
  18531. BaseService.scrollBackToTop();
  18532. $scope.attaches = []; // 存放上传了的附件
  18533. var sleep = function (d) {
  18534. for (var t = Date.now(); Date.now() - t <= d;);
  18535. }
  18536. var getCurrentEn = function () {
  18537. AccountEnterprise.get({}, function (data) {
  18538. $scope.currentEn = data;
  18539. });
  18540. }
  18541. if (!angular.isUndefined($stateParams.id)) { // 获取招标单详情
  18542. $scope.loading = true;
  18543. getCurrentEn();
  18544. PurcTender.getPurcTenderDetail({id: $stateParams.id}, function (data) {
  18545. data.$editing = false;
  18546. $scope.tender = data;
  18547. $scope.tenderProd = data.purchaseTenderProds;
  18548. $scope.currentHasBid = false; // 默认当前企业未转投标单
  18549. angular.forEach(data.purchaseTenderProds[0].saleTenderItems, function (item) {
  18550. if ($scope.currentEn.uu === item.saleTender.vendUU) { // 存在当前企业为供应商的投标单,判断已转
  18551. $scope.currentHasBid = true;
  18552. }
  18553. });
  18554. $scope.loading = false;
  18555. $scope.attaches = $scope.tender.tenderAttaches;
  18556. }, function (response) {
  18557. $scope.loading = false;
  18558. toaster.pop('error', '数据加载失败', response.data);
  18559. });
  18560. }
  18561. $scope.hasClick = false;
  18562. $scope.iWantToBid = function (id) {
  18563. $scope.hasClick = true;
  18564. PurcTender.addItems({id: id}, {}, function (data) { // 添加明细
  18565. toaster.pop('success', '成功', '转投标单成功');
  18566. window.location.hash = "#/sale/tender/" + id;
  18567. }, function (response) {
  18568. toaster.pop('error', '操作失败', response.data);
  18569. });
  18570. };
  18571. }]);
  18572. // 基础资料客户详情
  18573. app.controller('CustomersInfoCtrl', ['$scope', 'VendorService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'VendorInfo', function ($scope, VendorService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, VendorInfo) {
  18574. BaseService.scrollBackToTop();
  18575. $scope.status = 'customer';
  18576. $scope.userInfoResult = true;
  18577. AuthenticationService.getAuthentication().success(function (data) {
  18578. $scope.loading = false;
  18579. $scope.thisUser = data;
  18580. });
  18581. $scope.customerParams = new ngTableParams({
  18582. page: 1,
  18583. count: 20
  18584. }, {
  18585. total: 0,
  18586. counts: [],
  18587. getData: function ($defer, params) {
  18588. $scope.loading = true;
  18589. var pageParams = params.url();
  18590. pageParams.keyword = $scope.keyword;
  18591. VendorService.customer.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18592. $scope.loading = false;
  18593. if (page) {
  18594. params.total(page.totalElement);
  18595. $scope.total = page.totalElement;
  18596. $defer.resolve(page.content);
  18597. }
  18598. $scope.totalCount = page.totalElement;
  18599. }, function (response) {
  18600. $scope.loading = false;
  18601. toaster.pop('error', '数据加载失败', response.data);
  18602. });
  18603. }
  18604. });
  18605. // 搜索框回车
  18606. $scope.onSearch = function (keyword) {
  18607. $scope.customerParams.page(1);
  18608. $scope.customerParams.reload();
  18609. $scope.tip = keyword;
  18610. };
  18611. // 查看详情
  18612. $scope.viewDetail = function (id) {
  18613. window.location.hash = "#/sale/customer/" + id;
  18614. }
  18615. // 取消合作关系
  18616. $scope.disableCust = function (id) {
  18617. VendorInfo.disableCust({id: id}, {}, function (data) {
  18618. if (data.success) {
  18619. toaster.pop('success', '提示', data.success);
  18620. }
  18621. // $scope.customerParams.page(1);
  18622. $scope.customerParams.reload();
  18623. }, function (response) {
  18624. toaster.pop('error', '提示', response.data);
  18625. });
  18626. }
  18627. // 解除禁用
  18628. $scope.activeCust = function (id) {
  18629. VendorInfo.activeCust({id: id}, {}, function (data) {
  18630. if (data.success) {
  18631. toaster.pop('success', '提示', data.success);
  18632. }
  18633. // $scope.customerParams.page(1);
  18634. $scope.customerParams.reload();
  18635. }, function (response) {
  18636. toaster.pop('error', '提示', response.data);
  18637. });
  18638. }
  18639. }]);
  18640. // 基础资料供应商
  18641. app.controller('VendorsInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18642. BaseService.scrollBackToTop();
  18643. $scope.status = 'vendor';
  18644. // 搜索框回车
  18645. $scope.onSearch = function () {
  18646. $scope.customerParams.page(1);
  18647. $scope.customerParams.reload();
  18648. };
  18649. $scope.customerParams = new ngTableParams({
  18650. page: 1,
  18651. count: 20
  18652. }, {
  18653. total: 0,
  18654. counts: [],
  18655. getData: function ($defer, params) {
  18656. $scope.loading = true;
  18657. var pageParams = params.url();
  18658. pageParams.keyword = $scope.keyword;
  18659. Vendor.getVendor.call(null, BaseService.parseParams(pageParams), function (page) {
  18660. $scope.loading = false;
  18661. if (page) {
  18662. params.total(page.totalElement);
  18663. $scope.total = page.totalElement;
  18664. $defer.resolve(page.content);
  18665. }
  18666. $scope.totalCount = page.totalElement;
  18667. }, function (response) {
  18668. $scope.loading = false;
  18669. toaster.pop('error', '数据加载失败', response.data);
  18670. });
  18671. }
  18672. });
  18673. // 查看供应商详情
  18674. $scope.VendorDetail = function (id, uu) {
  18675. $rootScope.vendorId = id;
  18676. $rootScope.vendoruu = uu;
  18677. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18678. }
  18679. // 向企业购买
  18680. $scope.purcByEn = function (businessCode) {
  18681. $rootScope.businessCode = businessCode;
  18682. window.location.hash = "#/purc/addOrder";
  18683. }
  18684. // 取消合作关系
  18685. $scope.relieve = function (id) {
  18686. VendorInfo.relieve({id: id}, {}, function (data) {
  18687. if (data.success) {
  18688. toaster.pop('success', '提示', data.success);
  18689. }
  18690. // $scope.customerParams.page(1);
  18691. $scope.customerParams.reload();
  18692. }, function (response) {
  18693. toaster.pop('error', '提示', response.data);
  18694. });
  18695. }
  18696. // 建立合作关系
  18697. $scope.activeVend = function (id) {
  18698. VendorInfo.activeVend({id: id}, {}, function (data) {
  18699. if (data.success) {
  18700. toaster.pop('success', '提示', data.success);
  18701. }
  18702. // $scope.customerParams.page(1);
  18703. $scope.customerParams.reload();
  18704. }, function (response) {
  18705. toaster.pop('error', '提示', response.data);
  18706. });
  18707. }
  18708. }]);
  18709. // 基础资料服务商
  18710. app.controller('ServicerInfoCtrl', ['$scope', 'Vendor', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', '$rootScope', 'VendorInfo', function ($scope, Vendor, BaseService, AuthenticationService, ngTableParams, $modal, toaster, $rootScope, VendorInfo) {
  18711. BaseService.scrollBackToTop();
  18712. $scope.status = 'servicer';
  18713. // 搜索框回车
  18714. $scope.onSearch = function () {
  18715. $scope.customerParams.page(1);
  18716. $scope.customerParams.reload();
  18717. };
  18718. $scope.customerParams = new ngTableParams({
  18719. page: 1,
  18720. count: 20
  18721. }, {
  18722. total: 0,
  18723. counts: [],
  18724. getData: function ($defer, params) {
  18725. $scope.loading = true;
  18726. var pageParams = params.url();
  18727. pageParams.keyword = $scope.keyword;
  18728. Vendor.getServicer.call(null, BaseService.parseParams(pageParams), function (page) {
  18729. $scope.loading = false;
  18730. if (page) {
  18731. params.total(page.totalElement);
  18732. $scope.total = page.totalElement;
  18733. $defer.resolve(page.content);
  18734. }
  18735. $scope.totalCount = page.totalElement;
  18736. }, function (response) {
  18737. $scope.loading = false;
  18738. toaster.pop('error', '数据加载失败', response.data);
  18739. });
  18740. }
  18741. });
  18742. // 查看服务商详情
  18743. $scope.VendorDetail = function (id, uu) {
  18744. $rootScope.vendorId = id;
  18745. $rootScope.vendoruu = uu;
  18746. window.location.hash = "#/purc/vendor/" + $rootScope.vendorId;
  18747. };
  18748. // 取消合作关系
  18749. $scope.relieveServicer = function (id) {
  18750. VendorInfo.relieveServicer({id: id}, {}, function (data) {
  18751. if (data.success) {
  18752. toaster.pop('success', '提示', data.success);
  18753. }
  18754. // $scope.customerParams.page(1);
  18755. $scope.customerParams.reload();
  18756. }, function (response) {
  18757. toaster.pop('error', '提示', response.data);
  18758. });
  18759. }
  18760. // 建立合作关系
  18761. $scope.activeServicer = function (id) {
  18762. VendorInfo.activeServicer({id: id}, {}, function (data) {
  18763. if (data.success) {
  18764. toaster.pop('success', '提示', data.success);
  18765. }
  18766. // $scope.customerParams.page(1);
  18767. $scope.customerParams.reload();
  18768. }, function (response) {
  18769. toaster.pop('error', '提示', response.data);
  18770. });
  18771. }
  18772. }]);
  18773. // 企业圈搜索界面
  18774. app.controller('AddPartnersCtrl', ['$scope', '$rootScope', function ($scope, $rootScope) {
  18775. $scope.onSearch = function (keyword) {
  18776. $rootScope.enterpriseKeyword = keyword;
  18777. window.location.hash = "#/baseInfo/search?keyword=" + $rootScope.enterpriseKeyword;
  18778. }
  18779. }]);
  18780. // 企业圈搜索结果
  18781. app.controller('EnterpriseSearchCtrl', ['$scope', 'getAccountUserSpace', 'ngTableParams', '$filter', 'BaseService', 'toaster', 'AddPartner', '$rootScope', '$modal', 'InvitationRecord', function ($scope, getAccountUserSpace, ngTableParams, $filter, BaseService, toaster, AddPartner, $rootScope, $modal, InvitationRecord) {
  18782. $scope.status = 'add';
  18783. BaseService.scrollBackToTop();
  18784. $scope.active = 'all';
  18785. $scope.agreedText = '全部';
  18786. $scope.dateZoneText = '一个月内';
  18787. $scope.condition = {dateZone: 1};
  18788. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  18789. $scope.changeAgreed = function (agreed) {
  18790. $scope.condition.agreed = agreed;
  18791. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  18792. $scope.condition.$agreedOpen = false;
  18793. };
  18794. $scope.changeDateZone = function (zone) {
  18795. $scope.condition.dateZone = zone;
  18796. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  18797. $scope.condition.$dateZoneOpen = false;
  18798. getDateCondition(zone, $scope.condition);
  18799. $scope.tableParams.reload();
  18800. };
  18801. $scope.setActive = function (state) {
  18802. if ($scope.active != state) {
  18803. $scope.active = state;
  18804. if ($scope.tableParams.page() == 1)
  18805. $scope.tableParams.reload();
  18806. else
  18807. $scope.tableParams.page(1);
  18808. }
  18809. };
  18810. var getService = function () {
  18811. return getAccountUserSpace;
  18812. };
  18813. $scope.tableParams = new ngTableParams({
  18814. page: 1,
  18815. count: 20,
  18816. sorting: {}
  18817. }, {
  18818. total: 0,
  18819. counts: [],
  18820. getData: function ($defer, params) {
  18821. $scope.loading = true;
  18822. var pageParams = params.url();
  18823. pageParams.keyword = $scope.keyword;
  18824. $scope.tip = $scope.keyword;
  18825. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  18826. $scope.loading = false;
  18827. if (page) {
  18828. params.total(page.totalElement);
  18829. $defer.resolve(page.content);
  18830. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  18831. }
  18832. }, function (response) {
  18833. $scope.loading = false;
  18834. toaster.pop('error', '数据加载失败', response.data);
  18835. });
  18836. }
  18837. });
  18838. // 搜索框回车
  18839. $scope.onSearch = function (keyword) {
  18840. if (keyword === '') {
  18841. keyword = null;
  18842. $rootScope.searchKeyword = keyword;
  18843. $scope.keyword = keyword;
  18844. $scope.tableParams.page(1);
  18845. $scope.tableParams.reload();
  18846. } else {
  18847. $rootScope.searchKeyword = keyword;
  18848. $scope.keyword = keyword;
  18849. $scope.tableParams.page(1);
  18850. $scope.tableParams.reload();
  18851. }
  18852. };
  18853. // 添加合作关系
  18854. $scope.addPartner = function (name, businessCode) {
  18855. AddPartner.addPartner({name: name, businessCode: businessCode}, {}, function (data) {
  18856. if (data.success) {
  18857. toaster.pop("success", '添加成功', data.success);
  18858. $scope.tableParams.reload();
  18859. }
  18860. if (data.error) {
  18861. toaster.pop("error", '添加失败', data.error);
  18862. }
  18863. }, function (response) {
  18864. toaster.pop('error', '失败', response.data);
  18865. });
  18866. }
  18867. /**
  18868. * 邀请注册商务平台
  18869. */
  18870. $scope.invite = function (name) {
  18871. var modalInstance = $modal.open({
  18872. animation: true,
  18873. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  18874. controller: 'InviteCtrl',
  18875. resolve: {
  18876. enname: function () {
  18877. return name
  18878. }
  18879. }
  18880. });
  18881. modalInstance.result.then(function (data) {
  18882. InvitationRecord.invite({formStore: data}, {}, function (data) {
  18883. if (data.success) {
  18884. toaster.pop('success', '提示', data.success);
  18885. $scope.tableParams.reload();
  18886. }
  18887. if (data.error) {
  18888. toaster.pop('error', '提示', data.error);
  18889. }
  18890. }, function (response) {
  18891. toaster.pop('error', '提示', response.data);
  18892. });
  18893. });
  18894. }
  18895. /**
  18896. * 立即查看
  18897. */
  18898. $scope.view = function (name) {
  18899. $rootScope.vendName = name;
  18900. window.location.hash = "#/baseInfo/newPartner";
  18901. }
  18902. }]);
  18903. // 平台新增的询价单(指定一个供应商)
  18904. 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) {
  18905. $scope.active = 'all';
  18906. // 供应商信息
  18907. var loadData = function () {
  18908. Vendor.enterpriseInfo({bussinessCode: $stateParams.bussinessCode}, {}, function (data) {
  18909. $scope.vendor = data;
  18910. Vendor.contacts({venduu: $scope.vendor.uu}, {}, function (data) {
  18911. $scope.vendorContacts = data;
  18912. });
  18913. // 物料信息
  18914. $scope.tableParams = new ngTableParams({
  18915. page: 1,
  18916. count: 20
  18917. }, {
  18918. total: 0,
  18919. counts: [5, 10, 25, 50],
  18920. getData: function ($defer, params) {
  18921. $scope.loading = true;
  18922. var pageParams = params.url();
  18923. pageParams.keyword = $scope.keyword;
  18924. $scope.tip = $scope.keyword;
  18925. pageParams.custUU = $scope.vendor.uu;
  18926. Product.get.call(null, BaseService.parseParams(pageParams), function (page) {
  18927. $scope.loading = false;
  18928. if (page) {
  18929. params.total(page.totalElement);
  18930. $scope.total = page.totalElement;
  18931. $defer.resolve(page.content);
  18932. $scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
  18933. }
  18934. }, function (response) {
  18935. $scope.loading = false;
  18936. toaster.pop('error', '数据加载失败', response.data);
  18937. });
  18938. }
  18939. });
  18940. });
  18941. };
  18942. loadData();
  18943. $rootScope.tenderVendor = null;// 清除掉已选择的
  18944. var getService = function () {
  18945. return GetProductInfo;
  18946. };
  18947. $scope.inquiry = {
  18948. code: 'XJ' + $filter('date')(new Date(), 'yyMMddsss'),
  18949. showdate: $filter('date')(new Date, 'yyyy-MM-dd'),
  18950. priceType: '采购',
  18951. isOpen: 0,
  18952. invoice: 0,
  18953. ifTax: 1,
  18954. currency: 'RMB'
  18955. };
  18956. $scope.changeCurrency = function (inquiry) {
  18957. if (inquiry.currency !== 'RMB') {
  18958. $scope.notRMB = true;
  18959. inquiry.ifTax = 0; // 非RMB时,默认不含税和不需要发票,且不可更改
  18960. inquiry.invoice = 0;
  18961. } else {
  18962. $scope.notRMB = false;
  18963. }
  18964. };
  18965. // 获取收货地址列表
  18966. var loadShipAddress = function () {
  18967. ShipAddress.shipAddList({}, function (data) {
  18968. $scope.ships = data;
  18969. $scope.inquiry.ship = $scope.ships[0].address + $scope.ships[0].addressdet + $scope.ships[0].receiver + $scope.ships[0].usertel;
  18970. });
  18971. };
  18972. loadShipAddress();
  18973. // 获取地址信息
  18974. $http.get('resources/citydata/city.json', {
  18975. "Accept": "application/json;charset=utf-8", "Accept-Charset": "charset=utf-8"
  18976. }).then(function (response) {
  18977. $scope.provinces = response.data;
  18978. });
  18979. // 新增收货地址保存
  18980. $scope.saveShipAddress = function (ship) {
  18981. ship.address = ship.province + ship.city + ship.district;
  18982. ShipAddress.saveAddress({}, ship, function (data) {
  18983. if (data.success) {
  18984. // 获取收货地址列表
  18985. loadShipAddress();
  18986. toaster.pop('success', '提示', data.success);
  18987. }
  18988. if (data.error) {
  18989. toaster.pop('error', '提示', data.error);
  18990. }
  18991. });
  18992. };
  18993. $scope.currentDay = function () {
  18994. return $filter('date')(new Date(), 'yyyy-MM-dd');
  18995. };
  18996. // 搜索框回车
  18997. $scope.onSearch = function (keyword) {
  18998. $scope.tableParams.page(1);
  18999. $scope.tableParams.reload();
  19000. };
  19001. $scope.inquiry.inquiryItems = [];
  19002. var prod = {
  19003. prodCode: null,
  19004. prodTitle: null,
  19005. inbrand: null,
  19006. currency: 'RMB',
  19007. toDate: null,
  19008. unit: 'PCS'
  19009. };
  19010. $scope.inquiry.inquiryItems.push(prod);
  19011. // 联想词start
  19012. // 获取品牌联想词
  19013. $scope.getSimilarBrands = function (value) {
  19014. if (value) {
  19015. // 获取品牌联想词
  19016. return Search.getSimilarBrands({keyword: value}).$promise.then(function (data) {
  19017. return data.map(function (item) {
  19018. return item;
  19019. });
  19020. });
  19021. }
  19022. };
  19023. // 获取产品型号联想词
  19024. $scope.getSimilarCodes = function (value) {
  19025. if (value) {
  19026. // 获取产品型号联想词
  19027. return Search.getSimilarComponents({keyword: value}).$promise.then(function (data) {
  19028. return data.map(function (item) {
  19029. return item;
  19030. })
  19031. });
  19032. }
  19033. };
  19034. $scope.selectKind = function (prod) {
  19035. var submit = [];
  19036. $modal.open({
  19037. animation: true,
  19038. size: 'lg',
  19039. templateUrl: 'static/tpl/index/purc/modal/product_kindChoose_modal.html',
  19040. controller: 'ProdKindChooseCtrl',
  19041. resolve: {
  19042. actives: function () {
  19043. return $scope.actives;
  19044. }
  19045. }
  19046. }).result.then(function (data) {
  19047. $scope.actives = data.actives;
  19048. var size = data.actives.length;
  19049. submit.gradeOneKiName = '';
  19050. submit.gradeTwoKiName = '';
  19051. submit.gradeThreeKiName = '';
  19052. if (size > 0) {
  19053. submit.gradeOneKiName = $scope.actives[0].nameCn;
  19054. prod.prodTitle = submit.gradeOneKiName;
  19055. if (size > 1) {
  19056. submit.gradeTwoKiName = $scope.actives[1].nameCn;
  19057. prod.prodTitle = submit.gradeTwoKiName;
  19058. if (size > 2) {
  19059. submit.gradeThreeKiName = $scope.actives[2].nameCn;
  19060. prod.prodTitle = submit.gradeThreeKiName;
  19061. }
  19062. }
  19063. }
  19064. }, function () {
  19065. });
  19066. };
  19067. // 点击联想词获取品牌信息
  19068. $scope.onAssociateBrandClick = function (brand, prod) {
  19069. if (brand instanceof String) {
  19070. prod.inbrand = brand;
  19071. } else if (brand instanceof Object) {
  19072. prod.inbrand = brand.brandCn;
  19073. }
  19074. };
  19075. // 打开品牌选择的模态框
  19076. $scope.selectBrand = function (prod) { //打开模态
  19077. var modalInstance = $modal.open({
  19078. templateUrl: 'static/tpl/index/purc/modal/product_brandChoose_modal.html', //指向上面创建的视图
  19079. controller: 'BrandModalInstanceCtrl' // 初始化模态范围
  19080. });
  19081. modalInstance.opened.then(function () {// 模态窗口打开之后执行的函数
  19082. });
  19083. modalInstance.result.then(function (brand) {
  19084. prod.inbrand = brand.nameCn;
  19085. }, function (reason) {
  19086. });
  19087. };
  19088. // 点击联想词获取器件信息 带入产品分类和品牌
  19089. $scope.onAssociateCmpClick = function (cmp, prod) {
  19090. ComponentActiveAPI.get({uuid: cmp.uuid}, {}, function (data) {
  19091. $scope.component = data;
  19092. prod.prodCode = data.code;
  19093. prod.prodTitle = data.kind.nameCn;
  19094. prod.inbrand = data.brand.nameCn;
  19095. }, function (res) {
  19096. toaster.pop('error', '提示', '产品信息加载失败,请刷新页面');
  19097. })
  19098. };
  19099. //联想词end
  19100. // 导入商品信息
  19101. $scope.uplodaByBatch = function () {
  19102. var modalInstance = $modal.open({
  19103. templateUrl: 'static/tpl/index/purc/modal/uplodaByBatch.html',
  19104. controller: 'PurcInquiryUploadCtrl',
  19105. size: 'lg',
  19106. resolve: {}
  19107. });
  19108. modalInstance.result.then(function (data) {
  19109. angular.forEach(data, function (prod) {
  19110. $scope.inquiry.inquiryItems.push(prod);
  19111. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19112. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19113. $scope.inquiry.inquiryItems.splice(i, 1);
  19114. }
  19115. }
  19116. })
  19117. }, function () {
  19118. });
  19119. }
  19120. //增加商品
  19121. $scope.add = function () {
  19122. $scope.inquiry.inquiryItems.push(
  19123. {
  19124. prodCode: null,
  19125. prodTitle: null,
  19126. unit: 'PCS',
  19127. ibrand: null,
  19128. currency: 'RMB',
  19129. toDate: null
  19130. });
  19131. };
  19132. //删除商品
  19133. $scope.del = function (index) {
  19134. $scope.inquiry.inquiryItems.splice(index, 1);
  19135. };
  19136. // 搜索结果询价
  19137. if ($rootScope.prodId) {
  19138. VendorInfo.getProdInfo({id: $rootScope.prodId}, {}, function (data) {
  19139. prod.prodCode = data.code;
  19140. prod.prodTitle = data.title;
  19141. prod.spec = data.spec;
  19142. prod.unit = data.unit;
  19143. prod.productId = data.id;
  19144. prod.inbrand = data.brand;
  19145. $scope.inquiry.inquiryItems.push(prod);
  19146. $rootScope.prodId = null;// 清除掉prodId
  19147. }, function (response) {
  19148. });
  19149. }
  19150. $scope.check = function (product) {
  19151. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19152. if ($scope.inquiry.inquiryItems[i].prodCode == null) { // 如果没有填写就删除这行数据
  19153. $scope.inquiry.inquiryItems.splice(i, 1);
  19154. }
  19155. }
  19156. $scope.inquiry.inquiryItems.push({
  19157. prodCode: product.code, prodTitle: product.title, spec: product.spec, unit: product.unit,
  19158. currency: null, toDate: null, productId: product.id, inbrand: product.brand
  19159. });
  19160. }
  19161. $scope.getMinDate = function (item) {
  19162. return $filter('date')(new Date, 'yyyy-MM-dd');
  19163. };
  19164. $scope.openDatePicker = function ($event, openParam, index) {
  19165. $event.preventDefault();
  19166. $event.stopPropagation();
  19167. $scope.inquiry.inquiryItems[index].$toDateOpen = !openParam;
  19168. };
  19169. $scope.openEndDatePicker = function ($event, item, openParam) {
  19170. $event.preventDefault();
  19171. $event.stopPropagation();
  19172. item[openParam] = !item[openParam];
  19173. };
  19174. $scope.ifrepeat = false;
  19175. // 保存并提交
  19176. $scope.submit = function () {
  19177. $scope.loading = true;
  19178. for (var i = 0; i < $scope.inquiry.inquiryItems.length; i++) {
  19179. $scope.item = $scope.inquiry.inquiryItems[i];
  19180. for (var j = 0; j < $scope.inquiry.inquiryItems.length; j++) {
  19181. $scope.otheritem = $scope.inquiry.inquiryItems[j];
  19182. if (i != j) {
  19183. if ($scope.item.prodCode = $scope.otheritem.prodCode && $scope.item.prodTitle == $scope.otheritem.prodTitle
  19184. && $scope.item.inbrand == $scope.otheritem.inbrand && $scope.item.needquantity == $scope.otheritem.needquantity
  19185. && $scope.item.toDate.getTime() == $scope.otheritem.toDate.getTime()) {
  19186. $scope.ifrepeat = true;
  19187. }
  19188. }
  19189. }
  19190. }
  19191. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  19192. $scope.vendors = [];
  19193. $scope.vendors.push({
  19194. enName: $scope.vendor.enName,
  19195. enuu: $scope.vendor.uu,
  19196. currency: $scope.vendor.currency,
  19197. rate: $scope.vendor.rate
  19198. });
  19199. if (!$scope.ifrepeat) {
  19200. $upload.upload({
  19201. url: 'purc/inquiry/submit/withVendor',
  19202. file: file,
  19203. method: 'POST',
  19204. data: {
  19205. inquiry: $scope.inquiry,
  19206. contacts: $scope.vendors
  19207. },
  19208. }).success(function (data) {
  19209. if (data.success) {
  19210. $scope.loading = false;
  19211. toaster.pop('success', '提示', data.success);
  19212. $timeout(function () {
  19213. window.location.hash = "#/purc/purchaseinquiry";
  19214. }, 500);
  19215. }
  19216. if (data.error) {
  19217. $scope.loading = false;
  19218. toaster.pop('error', '提示', data.error);
  19219. }
  19220. }).error(function (data) {
  19221. $scope.loadingShow = false;
  19222. toaster.pop('error', '操作失败', data.error);
  19223. });
  19224. } else {
  19225. $scope.loading = false;
  19226. toaster.pop('error', '提示', '存在条件相同的物料');
  19227. }
  19228. }
  19229. }]);
  19230. // 企业圈查询收到待处理的数目
  19231. app.controller('RequestAmountCtrl', ['$scope', 'AddPartnerMyRequest', '$modal', 'InvitationRecord', 'toaster', function ($scope, AddPartnerMyRequest, $modal, InvitationRecord, toaster) {
  19232. AddPartnerMyRequest.requestAmount({}, function (data) {
  19233. $scope.requestTodo = data;
  19234. });
  19235. /**
  19236. * 邀请注册商务平台
  19237. */
  19238. $scope.invite = function () {
  19239. var modalInstance = $modal.open({
  19240. animation: true,
  19241. templateUrl: 'static/tpl/index/search/enterpirseInfo.html',
  19242. controller: 'InviteCtrl',
  19243. resolve: {
  19244. enname: function () {
  19245. return null
  19246. }
  19247. }
  19248. });
  19249. modalInstance.result.then(function (data) {
  19250. InvitationRecord.invite({formStore: data}, {}, function (data) {
  19251. if (data.success) {
  19252. toaster.pop('success', '提示', data.success);
  19253. $scope.tableParams.reload();
  19254. }
  19255. if (data.error) {
  19256. toaster.pop('error', '提示', data.error);
  19257. }
  19258. }, function (response) {
  19259. toaster.pop('error', '提示', response.data);
  19260. });
  19261. });
  19262. }
  19263. }]);
  19264. // 当前企业所有的物料信息
  19265. 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) {
  19266. BaseService.scrollBackToTop();
  19267. $rootScope.ids = [];// 用来记录已经选择的物料
  19268. $scope.active = 'all';
  19269. $scope.agreedText = '全部';
  19270. $scope.dateZoneText = '一个月内';
  19271. $scope.condition = {dateZone: 1};
  19272. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19273. $scope.changeAgreed = function (agreed) {
  19274. $scope.condition.agreed = agreed;
  19275. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19276. $scope.condition.$agreedOpen = false;
  19277. };
  19278. $scope.changeDateZone = function (zone) {
  19279. $scope.condition.dateZone = zone;
  19280. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19281. $scope.condition.$dateZoneOpen = false;
  19282. getDateCondition(zone, $scope.condition);
  19283. $scope.tableParams.reload();
  19284. };
  19285. $scope.setActive = function (state) {
  19286. if ($scope.active != state) {
  19287. $scope.active = state;
  19288. if ($scope.tableParams.page() == 1)
  19289. $scope.tableParams.reload();
  19290. else
  19291. $scope.tableParams.page(1);
  19292. }
  19293. };
  19294. $scope.searchMethod = false;
  19295. var getService = function () {
  19296. return $scope.searchMethod ? ProductAll : ProductAllNewest;
  19297. };
  19298. $scope.tableParams = new ngTableParams({
  19299. page: 1,
  19300. count: 20,
  19301. sorting: {
  19302. standard: 'desc',
  19303. id: 'desc',
  19304. }
  19305. }, {
  19306. total: 0,
  19307. counts: [5, 10, 25, 50],
  19308. getData: function ($defer, params) {
  19309. $scope.loading = true;
  19310. var pageParams = params.url();
  19311. pageParams.keyword = $scope.keyword;
  19312. pageParams.searchFilter = $scope.searchFilter;
  19313. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  19314. $scope.loading = false;
  19315. if (page) {
  19316. params.total(page.totalElement);
  19317. $defer.resolve(page.content);
  19318. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19319. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19320. $scope.checkall = true;
  19321. if(page.content.length <= 2) {
  19322. $scope.checkall = false;
  19323. } else {
  19324. angular.forEach(page.content, function (prod) {
  19325. if ($rootScope.ids.indexOf(prod.id) > -1) {
  19326. prod.$selected = true;
  19327. } else {
  19328. $scope.checkall = false;
  19329. }
  19330. });
  19331. }
  19332. $scope.checkboxes = {
  19333. checked: $scope.checkall
  19334. };
  19335. }
  19336. }, function (response) {
  19337. $scope.loading = false;
  19338. toaster.pop('error', '数据加载失败', response.data);
  19339. });
  19340. }
  19341. });
  19342. // 搜索框回车
  19343. $scope.onSearch = function (keyword) {
  19344. // 每次搜索重置获取数据方法
  19345. $scope.searchMethod = false;
  19346. if(keyword != null && keyword != '') {
  19347. $scope.searchMethod = true;
  19348. }
  19349. $scope.tableParams.page(1);
  19350. $scope.tableParams.reload();
  19351. };
  19352. // 开启销售
  19353. $scope.unlock = function (id) {
  19354. $scope.loading = true;
  19355. Products.unlock({id: id}, {}, function (data) {
  19356. $scope.loading = false;
  19357. toaster.pop('success', '提示', '操作成功');
  19358. $scope.tableParams.reload();
  19359. }, function (response) {
  19360. toaster.pop('error', '提示', response.data);
  19361. })
  19362. }
  19363. // 关闭销售
  19364. $scope.lock = function (id) {
  19365. $scope.loading = true;
  19366. Products.lock({id: id}, {}, function (data) {
  19367. $scope.loading = false;
  19368. toaster.pop('success', '提示', '操作成功');
  19369. $scope.tableParams.reload();
  19370. }, function (response) {
  19371. toaster.pop('error', '提示', response.data);
  19372. })
  19373. }
  19374. // 开启购买
  19375. $scope.unlockPurc = function (id) {
  19376. $scope.loading = true;
  19377. Products.unlockPurc({id: id}, {}, function (data) {
  19378. $scope.loading = false;
  19379. toaster.pop('success', '提示', '操作成功');
  19380. $scope.tableParams.reload();
  19381. }, function (response) {
  19382. toaster.pop('error', '提示', response.data);
  19383. })
  19384. }
  19385. // 关闭购买
  19386. $scope.lockPurc = function (id) {
  19387. $scope.loading = true;
  19388. Products.lockPurc({id: id}, {}, function (data) {
  19389. $scope.loading = false;
  19390. toaster.pop('success', '提示', '操作成功');
  19391. $scope.tableParams.reload();
  19392. }, function (response) {
  19393. toaster.pop('error', '提示', response.data);
  19394. })
  19395. }
  19396. // 一键匹配
  19397. $scope.matchall = function () {
  19398. $scope.type = "all";
  19399. $scope.loading = true;
  19400. Products.matchbytype({type: $scope.type}, {}, function (data) {
  19401. if (data.error) {
  19402. $scope.loading = false;
  19403. toaster.pop('error', '提示', data.error);
  19404. } else {
  19405. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  19406. window.location.href = "#/approvalFlow/productmatches";
  19407. }
  19408. }, function (response) {
  19409. toaster.pop('error', '提示', response.data);
  19410. });
  19411. }
  19412. $scope.checkboxes = {
  19413. checked: false
  19414. };
  19415. angular.forEach($scope.tableParams.data, function (item) {
  19416. $scope.checkboxes.checked = false;
  19417. if($rootScope.ids.in_array(item.id)) {
  19418. $rootScope.ids.remove(item.id);
  19419. $scope.checkboxes.checked = true;
  19420. }
  19421. });
  19422. // 点击勾选全部的复选框
  19423. $scope.checkAll = function () {
  19424. angular.forEach($scope.tableParams.data, function (item) {
  19425. if (!item.waiting) {
  19426. item.$selected = $scope.checkboxes.checked;
  19427. if(item.$selected) {
  19428. if(!$rootScope.ids.in_array(item.id)) {
  19429. $rootScope.ids.push(item.id);
  19430. }
  19431. } else {
  19432. if($rootScope.ids.in_array(item.id)) {
  19433. $rootScope.ids.remove(item.id);
  19434. }
  19435. }
  19436. }
  19437. });
  19438. };
  19439. // 判断数组中是否存在某个对象
  19440. Array.prototype.S = String.fromCharCode(2);
  19441. Array.prototype.in_array = function(e) {
  19442. var r = new RegExp(this.S + e + this.S);
  19443. return (r.test(this.S + this.join(this.S) + this.S));
  19444. }
  19445. // 从数组中移除某个对象
  19446. Array.prototype.remove = function(val) {
  19447. var index = this.indexOf(val);
  19448. if (index > -1) {
  19449. this.splice(index, 1);
  19450. }
  19451. };
  19452. // 点击其中一个明细的复选框
  19453. $scope.checkOne = function (product) {
  19454. var result = true;
  19455. angular.forEach($scope.tableParams.data, function (item) {
  19456. if (item.$selected != true) {
  19457. result = false;
  19458. return;
  19459. }
  19460. });
  19461. if(product.$selected) {
  19462. if(!$rootScope.ids.in_array(product.id)) {
  19463. $rootScope.ids.push(product.id);
  19464. }
  19465. } else {
  19466. if($rootScope.ids.in_array(product.id)) {
  19467. $rootScope.ids.remove(product.id);
  19468. }
  19469. }
  19470. $scope.checkboxes = {
  19471. checked: result
  19472. };
  19473. };
  19474. // 批量转入我的产品库
  19475. $scope.addtoUserByCheck = function() {
  19476. var ids = angular.copy($rootScope.ids);
  19477. if($rootScope.ids.length == 0) {
  19478. toaster.pop('error', '提示', '请先选择产品');
  19479. } else {
  19480. prodUser.coverToUserByIds({}, ids, function(data) {
  19481. toaster.pop('success', '提示', '选择' + $rootScope.ids.length + '个产品,成功转入' + data.count + '个产品');
  19482. $rootScope.ids = [];
  19483. $scope.tableParams.page(1);
  19484. $scope.tableParams.reload();
  19485. }, function(res) {
  19486. toaster.pop('error', '提示', '转入失败');
  19487. });
  19488. }
  19489. }
  19490. // 转入我的产品库
  19491. $scope.addtoUser = function(id) {
  19492. $scope.loading = true;
  19493. prodUser.coverToUser({id: id}, {}, function(data) {
  19494. $scope.loading = false;
  19495. toaster.pop('success', '提示', '转入成功');
  19496. }, function(res) {
  19497. $scope.loading = false;
  19498. toaster.pop('error', '提示', '转入失败');
  19499. });
  19500. }
  19501. }]);
  19502. // 当前企业匹配的标准物料信息
  19503. 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) {
  19504. BaseService.scrollBackToTop();
  19505. $scope.active = 'all';
  19506. $scope.agreedText = '全部';
  19507. $scope.dateZoneText = '一个月内';
  19508. $scope.condition = {dateZone: 1};
  19509. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19510. $scope.changeAgreed = function (agreed) {
  19511. $scope.condition.agreed = agreed;
  19512. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19513. $scope.condition.$agreedOpen = false;
  19514. };
  19515. $scope.changeDateZone = function (zone) {
  19516. $scope.condition.dateZone = zone;
  19517. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19518. $scope.condition.$dateZoneOpen = false;
  19519. getDateCondition(zone, $scope.condition);
  19520. $scope.tableParams.reload();
  19521. };
  19522. $scope.setActive = function (state) {
  19523. if ($scope.active != state) {
  19524. $scope.active = state;
  19525. if ($scope.tableParams.page() == 1)
  19526. $scope.tableParams.reload();
  19527. else
  19528. $scope.tableParams.page(1);
  19529. }
  19530. };
  19531. $scope.searchMethod = false;
  19532. var getService = function () {
  19533. if ($rootScope.productMatchStatus === 'sale') {
  19534. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19535. } else if ($rootScope.productMatchStatus === 'purc') {
  19536. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19537. } else {
  19538. return $scope.searchMethod ? Products.matchResult : Products.newestMatchResult;
  19539. }
  19540. };
  19541. $scope.tableParams = new ngTableParams({
  19542. page: 1,
  19543. count: 20,
  19544. sorting: {
  19545. matchsize: 'asc',
  19546. id: 'desc'
  19547. }
  19548. }, {
  19549. total: 0,
  19550. counts: [5, 10, 25, 50],
  19551. getData: function ($defer, params) {
  19552. $scope.loading = true;
  19553. var pageParams = params.url();
  19554. pageParams.keyword = $scope.keyword;
  19555. pageParams.searchFilter = $scope.searchFilter;
  19556. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19557. if (page) {
  19558. $scope.loading = false;
  19559. params.total(page.totalElement);
  19560. $defer.resolve(page.content);
  19561. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19562. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19563. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19564. ids = [];
  19565. if (product.matchresults.length == 1) {
  19566. product.checked = $scope.checks.checked;
  19567. }
  19568. });
  19569. }
  19570. }, function (response) {
  19571. $scope.loading = false;
  19572. toaster.pop('error', '数据加载失败', response.data);
  19573. });
  19574. }
  19575. });
  19576. // 搜索框回车
  19577. $scope.onSearch = function (keyword) {
  19578. $scope.searchMethod = false;
  19579. if(keyword != null && keyword != '') {
  19580. $scope.searchMethod = true;
  19581. }
  19582. $scope.tableParams.page(1);
  19583. $scope.tableParams.reload();
  19584. };
  19585. var ids = [];
  19586. $scope.checks = {
  19587. checked: false
  19588. };
  19589. // 全选框
  19590. $scope.checkAll = function () {
  19591. ids = [];// 每次选择时先清空,防止重复
  19592. angular.forEach($scope.tableParams.data, function (product) {
  19593. if (product.matchresults.length == 1) {
  19594. product.checked = $scope.checks.checked;
  19595. }
  19596. });
  19597. };
  19598. // 单选
  19599. $scope.checkOne = function (product) {
  19600. ids = [];// 每次选择时先清空,防止重复
  19601. product.checked = !product.checked;
  19602. var result = true;
  19603. angular.forEach($scope.tableParams.data, function (item) {
  19604. if (item.$selected != true) {
  19605. result = false;
  19606. return;
  19607. }
  19608. });
  19609. $scope.checks.checked = result;
  19610. var checked = true;
  19611. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19612. if (!message.checked) {
  19613. checked = false;
  19614. }
  19615. });
  19616. $scope.checks.checked = checked;
  19617. };
  19618. $scope.product = {
  19619. checked: false
  19620. };
  19621. var checkResults = function (result) {
  19622. angular.forEach($scope.tableParams.data, function (product) {
  19623. if (product.id == result.prid) {
  19624. product.checked = false;
  19625. angular.forEach(product.matchresults, function (item) {
  19626. if (result.id == item.id) {
  19627. if (item.checked) {
  19628. product.checked = true;
  19629. return;
  19630. }
  19631. } else {
  19632. item.checked = false;
  19633. }
  19634. });
  19635. }
  19636. });
  19637. // checkProductCheck();
  19638. };
  19639. var checkProductCheck = function () {
  19640. var checked = true;
  19641. angular.forEach($scope.tableParams.data, function (product) {
  19642. if (!product.checked) {
  19643. checked = false;
  19644. }
  19645. });
  19646. $scope.product.checked = checked;
  19647. }
  19648. // 单选明细
  19649. $scope.checkItem = function (result) {
  19650. ids = [];
  19651. result.checked = !result.checked;
  19652. checkResults(result);
  19653. }
  19654. // 一键更新
  19655. $scope.updateAll = function () {
  19656. $scope.loading = true;
  19657. angular.forEach($scope.tableParams.data, function (product) {
  19658. if (product.checked) {
  19659. if (product.matchresults.length == 1) {
  19660. ids.push(product.matchresults[0].id);
  19661. }
  19662. if (product.matchresults.length > 1) {
  19663. angular.forEach(product.matchresults, function (item) {
  19664. if (item.checked) {
  19665. ids.push(item.id);
  19666. }
  19667. });
  19668. }
  19669. }
  19670. });
  19671. Products.updateall({status: $scope.checks.checked, type: 'all'}, ids, function (data) {
  19672. if (data.success) {
  19673. toaster.pop('success', '提示', data.success);
  19674. $timeout(function () {
  19675. $scope.tableParams.page(1);
  19676. $scope.tableParams.reload();
  19677. $scope.loading = false;
  19678. }, 500);
  19679. }
  19680. ids = []; // 清空ids,防止重复点击出现多余的数据
  19681. }, function (response) {
  19682. $scope.loading = false;
  19683. toaster.pop('error', '提示', response.data);
  19684. });
  19685. }
  19686. }]);
  19687. // 当前企业匹配的标准物料信息(销售)
  19688. 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) {
  19689. BaseService.scrollBackToTop();
  19690. $scope.active = 'all';
  19691. $scope.agreedText = '全部';
  19692. $scope.dateZoneText = '一个月内';
  19693. $scope.condition = {dateZone: 1};
  19694. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19695. $scope.changeAgreed = function (agreed) {
  19696. $scope.condition.agreed = agreed;
  19697. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19698. $scope.condition.$agreedOpen = false;
  19699. };
  19700. $scope.changeDateZone = function (zone) {
  19701. $scope.condition.dateZone = zone;
  19702. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19703. $scope.condition.$dateZoneOpen = false;
  19704. getDateCondition(zone, $scope.condition);
  19705. $scope.tableParams.reload();
  19706. };
  19707. $scope.setActive = function (state) {
  19708. if ($scope.active != state) {
  19709. $scope.active = state;
  19710. if ($scope.tableParams.page() == 1)
  19711. $scope.tableParams.reload();
  19712. else
  19713. $scope.tableParams.page(1);
  19714. }
  19715. };
  19716. $scope.searchMethod = false;
  19717. var getService = function () {
  19718. return $scope.searchMethod ? Products.matchResultforSale : Products.newestMatchResultforSale;
  19719. };
  19720. $scope.tableParams = new ngTableParams({
  19721. page: 1,
  19722. count: 20,
  19723. sorting: {
  19724. matchsize: 'asc',
  19725. id: 'desc'
  19726. }
  19727. }, {
  19728. total: 0,
  19729. counts: [5, 10, 25, 50],
  19730. getData: function ($defer, params) {
  19731. $scope.loading = true;
  19732. var pageParams = params.url();
  19733. pageParams.keyword = $scope.keyword;
  19734. pageParams.searchFilter = $scope.searchFilter;
  19735. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19736. if (page) {
  19737. $scope.loading = false;
  19738. params.total(page.totalElement);
  19739. $defer.resolve(page.content);
  19740. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19741. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19742. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19743. ids = [];
  19744. if (product.matchresults.length == 1) {
  19745. product.checked = $scope.checks.checked;
  19746. }
  19747. });
  19748. }
  19749. }, function (response) {
  19750. $scope.loading = false;
  19751. toaster.pop('error', '数据加载失败', response.data);
  19752. });
  19753. }
  19754. });
  19755. // 搜索框回车
  19756. $scope.onSearch = function (keyword) {
  19757. $scope.searchMethod = false;
  19758. if(keyword != null && keyword != '') {
  19759. $scope.searchMethod = true;
  19760. }
  19761. $scope.tableParams.page(1);
  19762. $scope.tableParams.reload();
  19763. };
  19764. var ids = [];
  19765. $scope.checks = {
  19766. checked: false
  19767. };
  19768. // 全选框
  19769. $scope.checkAll = function () {
  19770. ids = [];// 每次选择时先清空,防止重复
  19771. angular.forEach($scope.tableParams.data, function (product) {
  19772. if (product.matchresults.length == 1) {
  19773. product.checked = $scope.checks.checked;
  19774. }
  19775. });
  19776. };
  19777. // 单选
  19778. $scope.checkOne = function (product) {
  19779. ids = [];// 每次选择时先清空,防止重复
  19780. product.checked = !product.checked;
  19781. var result = true;
  19782. angular.forEach($scope.tableParams.data, function (item) {
  19783. if (item.$selected != true) {
  19784. result = false;
  19785. return;
  19786. }
  19787. });
  19788. $scope.checks.checked = result;
  19789. var checked = true;
  19790. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19791. if (!message.checked) {
  19792. checked = false;
  19793. }
  19794. });
  19795. $scope.checks.checked = checked;
  19796. };
  19797. $scope.product = {
  19798. checked: false
  19799. };
  19800. var checkResults = function (result) {
  19801. angular.forEach($scope.tableParams.data, function (product) {
  19802. if (product.id == result.prid) {
  19803. product.checked = false;
  19804. angular.forEach(product.matchresults, function (item) {
  19805. if (result.id == item.id) {
  19806. if (item.checked) {
  19807. product.checked = true;
  19808. return;
  19809. }
  19810. } else {
  19811. item.checked = false;
  19812. }
  19813. });
  19814. }
  19815. });
  19816. // checkProductCheck();
  19817. };
  19818. var checkProductCheck = function () {
  19819. var checked = true;
  19820. angular.forEach($scope.tableParams.data, function (product) {
  19821. if (!product.checked) {
  19822. checked = false;
  19823. }
  19824. });
  19825. $scope.product.checked = checked;
  19826. }
  19827. // 单选明细
  19828. $scope.checkItem = function (result) {
  19829. ids = [];
  19830. result.checked = !result.checked;
  19831. checkResults(result);
  19832. }
  19833. // 一键更新
  19834. $scope.updateAll = function () {
  19835. $scope.loading = true;
  19836. angular.forEach($scope.tableParams.data, function (product) {
  19837. if (product.checked) {
  19838. if (product.matchresults.length == 1) {
  19839. ids.push(product.matchresults[0].id);
  19840. }
  19841. if (product.matchresults.length > 1) {
  19842. angular.forEach(product.matchresults, function (item) {
  19843. if (item.checked) {
  19844. ids.push(item.id);
  19845. }
  19846. });
  19847. }
  19848. }
  19849. });
  19850. Products.updateall({status: $scope.checks.checked, type: 'sale'}, ids, function (data) {
  19851. if (data.success) {
  19852. toaster.pop('success', '提示', data.success);
  19853. $timeout(function () {
  19854. $scope.tableParams.page(1);
  19855. $scope.tableParams.reload();
  19856. $scope.loading = false;
  19857. }, 500);
  19858. }
  19859. ids = []; // 清空ids,防止重复点击出现多余的数据
  19860. }, function (response) {
  19861. $scope.loading = true;
  19862. toaster.pop('error', '提示', response.data);
  19863. });
  19864. }
  19865. }]);
  19866. // 当前企业匹配的标准物料信息(采购)
  19867. 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) {
  19868. BaseService.scrollBackToTop();
  19869. $scope.active = 'all';
  19870. $scope.agreedText = '全部';
  19871. $scope.dateZoneText = '一个月内';
  19872. $scope.condition = {dateZone: 1};
  19873. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  19874. $scope.changeAgreed = function (agreed) {
  19875. $scope.condition.agreed = agreed;
  19876. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  19877. $scope.condition.$agreedOpen = false;
  19878. };
  19879. $scope.changeDateZone = function (zone) {
  19880. $scope.condition.dateZone = zone;
  19881. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  19882. $scope.condition.$dateZoneOpen = false;
  19883. getDateCondition(zone, $scope.condition);
  19884. $scope.tableParams.reload();
  19885. };
  19886. $scope.setActive = function (state) {
  19887. if ($scope.active != state) {
  19888. $scope.active = state;
  19889. if ($scope.tableParams.page() == 1)
  19890. $scope.tableParams.reload();
  19891. else
  19892. $scope.tableParams.page(1);
  19893. }
  19894. };
  19895. $scope.searchMethod = false;
  19896. var getService = function () {
  19897. return $scope.searchMethod ? Products.matchResultforPurc : Products.newestMatchResultforPurc;
  19898. };
  19899. $scope.tableParams = new ngTableParams({
  19900. page: 1,
  19901. count: 20,
  19902. sorting: {
  19903. matchsize: 'asc',
  19904. id: 'desc'
  19905. }
  19906. }, {
  19907. total: 0,
  19908. counts: [5, 10, 25, 50],
  19909. getData: function ($defer, params) {
  19910. $scope.loading = true;
  19911. var pageParams = params.url();
  19912. pageParams.keyword = $scope.keyword;
  19913. pageParams.searchFilter = $scope.searchFilter;
  19914. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  19915. if (page) {
  19916. $scope.loading = false;
  19917. params.total(page.totalElement);
  19918. $defer.resolve(page.content);
  19919. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  19920. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  19921. angular.forEach(page.content, function (product) { // 每次进入判断全选状态,然后给单据赋状态
  19922. ids = [];
  19923. if (product.matchresults.length == 1) {
  19924. product.checked = $scope.checks.checked;
  19925. }
  19926. });
  19927. $scope.total = page.totalElement;
  19928. }
  19929. }, function (response) {
  19930. $scope.loading = false;
  19931. toaster.pop('error', '数据加载失败', response.data);
  19932. });
  19933. }
  19934. });
  19935. // 搜索框回车
  19936. $scope.onSearch = function (keyword) {
  19937. $scope.searchMethod = false;
  19938. if(keyword != null && keyword != '') {
  19939. $scope.searchMethod = true;
  19940. }
  19941. $scope.tableParams.page(1);
  19942. $scope.tableParams.reload();
  19943. };
  19944. var ids = [];
  19945. $scope.checks = {
  19946. checked: false
  19947. };
  19948. // 全选框
  19949. $scope.checkAll = function () {
  19950. ids = [];// 每次选择时先清空,防止重复
  19951. angular.forEach($scope.tableParams.data, function (product) {
  19952. if (product.matchresults.length == 1) {
  19953. product.checked = $scope.checks.checked;
  19954. }
  19955. });
  19956. };
  19957. // 单选
  19958. $scope.checkOne = function (product) {
  19959. ids = [];// 每次选择时先清空,防止重复
  19960. product.checked = !product.checked;
  19961. var result = true;
  19962. angular.forEach($scope.tableParams.data, function (item) {
  19963. if (item.$selected != true) {
  19964. result = false;
  19965. return;
  19966. }
  19967. });
  19968. $scope.checks.checked = result;
  19969. var checked = true;
  19970. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  19971. if (!message.checked) {
  19972. checked = false;
  19973. }
  19974. });
  19975. $scope.checks.checked = checked;
  19976. };
  19977. $scope.product = {
  19978. checked: false
  19979. };
  19980. var checkResults = function (result) {
  19981. angular.forEach($scope.tableParams.data, function (product) {
  19982. if (product.id == result.prid) {
  19983. product.checked = false;
  19984. angular.forEach(product.matchresults, function (item) {
  19985. if (result.id == item.id) {
  19986. if (item.checked) {
  19987. product.checked = true;
  19988. return;
  19989. }
  19990. } else {
  19991. item.checked = false;
  19992. }
  19993. });
  19994. }
  19995. });
  19996. // checkProductCheck();
  19997. };
  19998. var checkProductCheck = function () {
  19999. var checked = true;
  20000. angular.forEach($scope.tableParams.data, function (product) {
  20001. if (!product.checked) {
  20002. checked = false;
  20003. }
  20004. });
  20005. $scope.product.checked = checked;
  20006. }
  20007. // 单选明细
  20008. $scope.checkItem = function (result) {
  20009. ids = [];
  20010. result.checked = !result.checked;
  20011. checkResults(result);
  20012. }
  20013. // 一键更新
  20014. $scope.updateAll = function () {
  20015. $scope.loading = true;
  20016. angular.forEach($scope.tableParams.data, function (product) {
  20017. if (product.checked) {
  20018. if (product.matchresults.length == 1) {
  20019. ids.push(product.matchresults[0].id);
  20020. }
  20021. if (product.matchresults.length > 1) {
  20022. angular.forEach(product.matchresults, function (item) {
  20023. if (item.checked) {
  20024. ids.push(item.id);
  20025. }
  20026. });
  20027. }
  20028. }
  20029. });
  20030. Products.updateall({status: $scope.checks.checked, type: 'purc'}, ids, function (data) {
  20031. if (data.success) {
  20032. toaster.pop('success', '提示', data.success);
  20033. $timeout(function () {
  20034. $scope.tableParams.page(1);
  20035. $scope.tableParams.reload();
  20036. $scope.loading = false;
  20037. }, 500);
  20038. }
  20039. ids = []; // 清空ids,防止重复点击出现多余的数据
  20040. }, function (response) {
  20041. $scope.loading = false;
  20042. toaster.pop('error', '提示', response.data);
  20043. });
  20044. }
  20045. }]);
  20046. /**
  20047. * 采购物料资料
  20048. */
  20049. 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) {
  20050. BaseService.scrollBackToTop();
  20051. // 用来记录已经选择的id
  20052. $rootScope.ids = [];
  20053. var loadAccount = function () {
  20054. AccountEnterprise.get({}, function (data) {
  20055. $scope.enterprise = data;
  20056. $scope.purcStatus = $scope.enterprise.prodpurc;
  20057. });
  20058. }
  20059. loadAccount();
  20060. $scope.active = 'all';
  20061. $scope.agreedText = '全部';
  20062. $scope.dateZoneText = '一个月内';
  20063. $scope.condition = {dateZone: 1};
  20064. $scope.currency = Symbol.currency;//将币别转化为对应的符号
  20065. $scope.changeAgreed = function (agreed) {
  20066. $scope.condition.agreed = agreed;
  20067. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
  20068. $scope.condition.$agreedOpen = false;
  20069. };
  20070. $scope.changeDateZone = function (zone) {
  20071. $scope.condition.dateZone = zone;
  20072. $scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
  20073. $scope.condition.$dateZoneOpen = false;
  20074. getDateCondition(zone, $scope.condition);
  20075. $scope.tableParams.reload();
  20076. };
  20077. $scope.setActive = function (state) {
  20078. if ($scope.active != state) {
  20079. $scope.active = state;
  20080. if ($scope.tableParams.page() == 1)
  20081. $scope.tableParams.reload();
  20082. else
  20083. $scope.tableParams.page(1);
  20084. }
  20085. };
  20086. $scope.searchMethod = false;
  20087. var getService = function () {
  20088. return $scope.searchMethod ? PurcProduct : PurcProductNewest;
  20089. };
  20090. $scope.tableParams = new ngTableParams({
  20091. page: 1,
  20092. count: 20,
  20093. sorting: {
  20094. id: 'desc'
  20095. }
  20096. }, {
  20097. total: 0,
  20098. counts: [5, 10, 25, 50],
  20099. getData: function ($defer, params) {
  20100. $scope.loading = true;
  20101. var pageParams = params.url();
  20102. pageParams.keyword = $scope.keyword;
  20103. pageParams.searchFilter = $scope.searchFilter;
  20104. getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function (page) {
  20105. $scope.loading = false;
  20106. if (page) {
  20107. params.total(page.totalElement);
  20108. $defer.resolve(page.content);
  20109. $scope.keywordXls = angular.copy(pageParams.keyword);//保存当前取值的关键词
  20110. $scope.searchFilterXls = angular.copy(pageParams.searchFilter);
  20111. }
  20112. }, function (response) {
  20113. $scope.loading = false;
  20114. toaster.pop('error', '数据加载失败', response.data);
  20115. });
  20116. }
  20117. });
  20118. // //设置单据已读
  20119. // var setOrdersRead = function () {
  20120. // var ids = [];
  20121. // PurcProduct.setRead({}, ids, function (message) {
  20122. // // $scope.getUnreadIds();
  20123. // });
  20124. // };
  20125. // setOrdersRead();
  20126. // 搜索框回车
  20127. $scope.onSearch = function (keyword) {
  20128. $scope.searchMethod = false;
  20129. if(keyword != null && keyword != '') {
  20130. $scope.searchMethod = true;
  20131. }
  20132. $scope.tableParams.page(1);
  20133. $scope.tableParams.reload();
  20134. };
  20135. //删除
  20136. $scope.deleteById = function (id) {
  20137. GetProductInfo.deletePurcById({}, id, function (data) {
  20138. if (data.error) {
  20139. toaster.pop("error", "提示", data.error);
  20140. } else {
  20141. toaster.pop("success", "提示", "删除成功");
  20142. $timeout(function () {
  20143. $scope.tableParams.reload();
  20144. }, 500);
  20145. }
  20146. }), function (response) {
  20147. toaster.pop("error", "删除失败", response.data);
  20148. };
  20149. }
  20150. // 一键开启关闭
  20151. $scope.toggle = function (status) {
  20152. $scope.loading = true;
  20153. Products.toggle({status: status}, {}, function (data) {
  20154. $scope.loading = false;
  20155. toaster.pop('success', '提示', '操作成功');
  20156. loadAccount();
  20157. $scope.tableParams.reload();
  20158. if ($scope.purcStatus == 0) {
  20159. $scope.purcStatus = 1;
  20160. } else {
  20161. $scope.purcStatus = 0;
  20162. }
  20163. }, function (response) {
  20164. $scope.loading = false;
  20165. toaster.pop('error', '提示', response.data);
  20166. })
  20167. }
  20168. var products = [];
  20169. $scope.checks = {
  20170. checked: false
  20171. };
  20172. // 全选框
  20173. $scope.checkAll = function () {
  20174. products = [];// 每次选择时先清空,防止重复
  20175. angular.forEach($scope.tableParams.data, function (product) {
  20176. if (product.cmpUuId == null) {
  20177. product.checked = $scope.checks.checked;
  20178. }
  20179. });
  20180. };
  20181. // 单选
  20182. $scope.checkOne = function (product) {
  20183. products = [];// 每次选择时先清空,防止重复
  20184. var result = true;
  20185. angular.forEach($scope.tableParams.data, function (item) {
  20186. if (item.$selected != true) {
  20187. result = false;
  20188. return;
  20189. }
  20190. });
  20191. $scope.checks.checked = result;
  20192. var checked = true;
  20193. angular.forEach($scope.tableParams.data, function (message) { // 单选全部时,全选选中
  20194. if (!message.checked) {
  20195. checked = false;
  20196. }
  20197. });
  20198. $scope.checks.checked = checked;
  20199. };
  20200. $scope.updateByBatch = function (updatetype) {
  20201. var modalInstance = $modal.open({
  20202. templateUrl: 'static/tpl/index/baseInfo/modal/updateByBatch_modal.html',
  20203. controller: 'UpdateByBatchCtrl',
  20204. size: 'md',
  20205. resolve: {
  20206. updatetype: function () {
  20207. return updatetype;
  20208. },
  20209. active: function () {
  20210. return $scope.active;
  20211. },
  20212. type: function () {
  20213. return 'purchase';
  20214. }
  20215. }
  20216. });
  20217. modalInstance.result.then(function (data) {
  20218. toaster.pop('success', '提示', data.success);
  20219. $scope.tableParams.reload();
  20220. }, function () {
  20221. });
  20222. }
  20223. // 一键匹配
  20224. $scope.matchall = function () {
  20225. $scope.type = "purc";
  20226. $scope.loading = true;
  20227. PurcProduct.matchbytype({type: $scope.type}, {}, function (data) {
  20228. if (data.error) {
  20229. $scope.loading = false;
  20230. toaster.pop('error', '提示', data.error);
  20231. } else {
  20232. toaster.pop('info', '提示', '匹配成功' + data.size + '个标准器件');
  20233. window.location.href = "#/purc/productmatches";
  20234. }
  20235. }, function (response) {
  20236. $scope.loading = false;
  20237. toaster.pop('error', '提示', response.data);
  20238. });
  20239. }
  20240. // 导出
  20241. $scope.exportXls = function () {
  20242. PurcProduct.exportXls({}, {}, function (data) {
  20243. if (data.success){
  20244. window.location.href = 'purcProduct/xls?_state='+$scope.active+'&keyword='+ ($scope.keywordXls || "");
  20245. }
  20246. }, function (response) {
  20247. toaster.pop('error', '数据加载失败', response.data);
  20248. });
  20249. }
  20250. }]);
  20251. /**
  20252. * 采购物料批量上传
  20253. */
  20254. app.controller('UploadProductCtrl', ['$scope', '$upload', 'toaster', 'BaseService', function ($scope, $upload, toaster, BaseService) {
  20255. BaseService.scrollBackToTop();
  20256. $scope.$watch('myFiles', function () {
  20257. if ($scope.myFiles) {
  20258. var file = $scope.myFiles[0];
  20259. $scope.fileName = file.name;
  20260. }
  20261. })
  20262. // 通过excel批量上传物料
  20263. $scope.upload = function () {
  20264. $scope.loading = true;
  20265. if ($scope.myFiles) {
  20266. var file = $scope.myFiles[0];
  20267. if (file.name) {
  20268. $scope.loading = true;
  20269. $upload.upload({
  20270. url: 'purcProduct/edit/release/excel',
  20271. file: file,
  20272. method: 'POST'
  20273. }).success(function (data) {
  20274. $scope.loading = false;
  20275. if (data.error) {
  20276. toaster.pop('error', '提示', data.error);
  20277. }
  20278. $scope.result = data;
  20279. // $scope.products = $scope.result.products;
  20280. $scope.success = $scope.result.success;
  20281. $scope.total = $scope.result.total;
  20282. $scope.alters = $scope.result.alters;
  20283. $scope.infos = $scope.result.infos;
  20284. $scope.myFiles[0] = "";
  20285. $scope.fileName = "";
  20286. }).error(function (response) {
  20287. $scope.loading = false;
  20288. toaster.pop('error', response.data || response);
  20289. });
  20290. } else {
  20291. $scope.loading = false;
  20292. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  20293. }
  20294. } else {
  20295. $scope.loading = false;
  20296. }
  20297. };
  20298. // 查看范例
  20299. $scope.showImg = function () {
  20300. var src = "static/img/eg/uploadByBatch_example.png", box = $('#image-box');
  20301. box.show();
  20302. box.find('img').attr('src', src);
  20303. box.find('a').click(function () {
  20304. box.hide();
  20305. });
  20306. box.dblclick(function () {
  20307. box.hide();
  20308. });
  20309. };
  20310. // 下载模板
  20311. $scope.download = function () {
  20312. window.location.href = 'product/baseInfo/upload/template';
  20313. };
  20314. }]);
  20315. /**
  20316. * 新增物料(采购)
  20317. */
  20318. 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) {
  20319. BaseService.scrollBackToTop();
  20320. // 录入人
  20321. AuthenticationService.getAuthentication().success(function (data) {
  20322. $scope.loading = false;
  20323. $scope.user = data;
  20324. });
  20325. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20326. $scope.prodInfo = {};
  20327. // 选择类目
  20328. $scope.selectKind = function () {
  20329. $modal.open({
  20330. animation: true,
  20331. size: 'lg',
  20332. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20333. controller: 'KindChooseCtrl',
  20334. }).result.then(function (data) {
  20335. $scope.kindId = data;
  20336. var modalInstance = $modal.open({
  20337. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20338. controller: 'FindComponentCtrl',
  20339. size: 'lg',
  20340. resolve: {
  20341. KindId: function () {
  20342. return $scope.kindId;
  20343. }
  20344. }
  20345. });
  20346. modalInstance.result.then(function (data) {
  20347. $scope.prodInfo.cmpUuId = data.uuid;
  20348. $scope.prodInfo.pcmpcode = data.code;
  20349. $scope.prodInfo.pbranden = data.brand.nameEn;
  20350. $scope.prodInfo.pbrand = data.brand.nameCn;
  20351. }, function () {
  20352. });
  20353. }, function () {
  20354. });
  20355. };
  20356. // 联想词 start
  20357. // 获取类目
  20358. $scope.getSimilarKinds = function (value) {
  20359. if (value) {
  20360. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20361. return data.map(function (item) {
  20362. return item;
  20363. });
  20364. });
  20365. }
  20366. };
  20367. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20368. $scope.prodInfo.title = kind.kindName;
  20369. }
  20370. $scope.getSimilarBrands = function (value) {
  20371. if (value) {
  20372. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20373. return data.map(function (item) {
  20374. return item;
  20375. });
  20376. });
  20377. }
  20378. }
  20379. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20380. $scope.prodInfo.brand = brand.brandName;
  20381. }
  20382. $scope.getSimilarComponents = function (value) {
  20383. if (value) {
  20384. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20385. return data.map(function (item) {
  20386. return item;
  20387. });
  20388. });
  20389. }
  20390. }
  20391. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20392. $scope.prodInfo.cmpCode = cmp.code;
  20393. }
  20394. // 联想词 end
  20395. // 删除
  20396. $scope.clearfile = function () {
  20397. $scope.myFiles = null;
  20398. $scope.previewShow = false;
  20399. }
  20400. //提交
  20401. $scope.submit = function (prodInfo) {
  20402. $scope.loading = true;
  20403. $scope.prodInfo.isPurchase = 1;
  20404. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20405. $upload.upload({
  20406. url: 'purcProduct/edit/addNewProduct',
  20407. file: file,
  20408. method: 'POST',
  20409. data: {
  20410. prodInfo: prodInfo
  20411. },
  20412. }).success(function (data) {
  20413. $scope.loading = false;
  20414. if (data.success) {
  20415. toaster.pop('success', '提示', data.success);
  20416. $timeout(function () {
  20417. //提交后跳转到详情页面,防止重复提交
  20418. window.location.href = "#/purc/prodList/" + data.id;
  20419. // window.location.href="#/purc/product";
  20420. }, 500);
  20421. }
  20422. if (data.error) {
  20423. toaster.pop('error', '提示', data.error);
  20424. $timeout(function () {
  20425. //提交后跳转到详情页面,防止重复提交
  20426. window.location.href = "#/purc/prodList/" + data.id;
  20427. // window.location.href="#/purc/product";
  20428. }, 500);
  20429. }
  20430. }).error(function (data, status, headers, config) {
  20431. $scope.loading = false;
  20432. $scope.loadingShow = false;
  20433. if (status == 403) {
  20434. toaster.pop('error', '操作失败', data);
  20435. } else {
  20436. toaster.pop('error', '操作失败', data.error);
  20437. }
  20438. });
  20439. };
  20440. $scope.previewShow = false;
  20441. $scope.pdfShow = false;
  20442. $scope.noneFileShow = true;
  20443. $scope.$watch('myFiles', function () {
  20444. if ($scope.myFiles) {
  20445. $scope.noneFileShow = false;
  20446. var file = $scope.myFiles[0];
  20447. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20448. $scope.pdfShow = true;
  20449. $scope.previewShow = false;
  20450. $scope.imgPreviewName = file.name;
  20451. } else {
  20452. if (typeof(Worker) !== "undefined") {//支持HTML5
  20453. $scope.imgPreview = getObjectURL(file);
  20454. $scope.imgPreviewName = file.name;
  20455. } else {//不支持HTML5
  20456. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20457. $scope.imgPreviewName = file.name;
  20458. }
  20459. $scope.previewShow = true;
  20460. $scope.pdfShow = false;
  20461. }
  20462. } else {
  20463. $scope.noneFileShow = true;
  20464. $scope.previewShow = false;
  20465. $scope.pdfShow = false;
  20466. }
  20467. });
  20468. //建立一个可存取到该file的url
  20469. var imgurl = null;
  20470. var getObjectURL = function (file) {
  20471. var url = null;
  20472. if (window.createObjectURL != undefined) { // basic
  20473. url = window.createObjectURL(file);
  20474. } else if (window.URL != undefined) { // mozilla(firefox)
  20475. url = window.URL.createObjectURL(file);
  20476. } else if (window.webkitURL != undefined) { // webkit or chrome
  20477. url = window.webkitURL.createObjectURL(file);
  20478. }
  20479. imgurl = url;
  20480. return url;
  20481. };
  20482. // 取消
  20483. $scope.cancel = function () {
  20484. $scope.prodInfo = angular.copy($scope.prodInfo);
  20485. };
  20486. // 查看大图
  20487. $scope.showImg = function () {
  20488. var src = imgurl, box = $('#image-box');
  20489. box.show();
  20490. box.find('img').attr('src', src);
  20491. box.find('a').click(function () {
  20492. box.hide();
  20493. });
  20494. box.dblclick(function () {
  20495. box.hide();
  20496. });
  20497. };
  20498. }]);
  20499. /**
  20500. * 物料详情(采购)
  20501. */
  20502. 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) {
  20503. BaseService.scrollBackToTop();
  20504. // 录入人
  20505. AuthenticationService.getAuthentication().success(function (data) {
  20506. $scope.loading = false;
  20507. $scope.user = data;
  20508. });
  20509. $scope.time = $filter('date')(new Date, 'yyyy-MM-dd HH:mm');
  20510. $scope.editstatus = false;
  20511. var loadData = function () {
  20512. GetProductInfo.getPurcProduct({id: $stateParams.id}, function (data) {
  20513. if (data.attach) {
  20514. GetProductInfo.getAttach({id: data.attach.id}, function (data) {
  20515. $scope.imgPreview = data.url;
  20516. $scope.previewShow = true;
  20517. })
  20518. }
  20519. $scope.prodInfo = data;
  20520. if ($scope.prodInfo.isbusiness == 0) {
  20521. $scope.editstatus = true;
  20522. }
  20523. if ($scope.prodInfo.standard != 1) {// 非标准的先进行匹配
  20524. Products.matchone({id: $scope.prodInfo.id}, {}, function (data) {
  20525. $scope.matchresults = data;
  20526. }, function (response) {
  20527. toaster.pop('error', '提示', response.data);
  20528. });
  20529. }
  20530. $scope.loading = false;
  20531. }, function (response) {
  20532. toaster.pop('error', '数据加载失败', response.data);
  20533. });
  20534. };
  20535. loadData();
  20536. // 联想词 start
  20537. // 获取类目
  20538. $scope.getSimilarKinds = function (value) {
  20539. if (value) {
  20540. return Products.getSimilarKind({keyword: value}).$promise.then(function (data) {
  20541. return data.map(function (item) {
  20542. return item;
  20543. });
  20544. });
  20545. }
  20546. };
  20547. // 设置类目
  20548. $scope.onAssociateKindClick = function (kind, prodInfo) {
  20549. $scope.prodInfo.kind = kind.kindName;
  20550. }
  20551. // 设置名称
  20552. $scope.onAssociateTitleClick = function (kind, prodInfo) {
  20553. $scope.prodInfo.title = kind.kindName;
  20554. }
  20555. $scope.getSimilarBrands = function (value) {
  20556. if (value) {
  20557. return Products.getSimilarBrandByCode({keyword: value}).$promise.then(function (data) {
  20558. return data.map(function (item) {
  20559. return item;
  20560. });
  20561. });
  20562. }
  20563. }
  20564. // 设置导入品牌
  20565. $scope.onAssociateBrandClick = function (brand, prodInfo) {
  20566. $scope.prodInfo.brand = brand.brandName;
  20567. }
  20568. // 设置标准品牌
  20569. $scope.onAssociatePBrandClick = function (brand, prodInfo) {
  20570. $scope.prodInfo.pbranden = brand.brandName;
  20571. }
  20572. $scope.getSimilarComponents = function (value) {
  20573. if (value) {
  20574. return Products.getSimilarComponent({keyword: value}).$promise.then(function (data) {
  20575. return data.map(function (item) {
  20576. return item;
  20577. });
  20578. });
  20579. }
  20580. }
  20581. // 设置标准型号
  20582. $scope.onAssociateComponentClick = function (cmp, prodInfo) {
  20583. $scope.prodInfo.pcmpcode = cmp.code;
  20584. }
  20585. // 设置导入的型号
  20586. $scope.onAssociateCmpClick = function (cmp, prodInfo) {
  20587. $scope.prodInfo.cmpCode = cmp.code;
  20588. }
  20589. // 联想词 end
  20590. //更新为标准器件
  20591. $scope.updateone = function (id) {
  20592. Products.updateone({id: id}, {}, function (data) {
  20593. if (data.success) {
  20594. toaster.pop('success', '提示', data.success);
  20595. window.location.reload();
  20596. }
  20597. }, function (response) {
  20598. toaster.pop('error', '提示', response.data);
  20599. });
  20600. }
  20601. // 选择类目
  20602. $scope.selectKind = function (cmpcode) {
  20603. if (cmpcode == null) {
  20604. $modal.open({
  20605. animation: true,
  20606. size: 'lg',
  20607. templateUrl: 'static/tpl/index/baseInfo/modal/product_kindChoose_modal.html',
  20608. controller: 'KindChooseCtrl',
  20609. }).result.then(function (data) {
  20610. $scope.kindId = data;
  20611. var modalInstance = $modal.open({
  20612. templateUrl: 'static/tpl/index/baseInfo/modal/Component_KindChoose_modal.html',
  20613. controller: 'FindComponentCtrl',
  20614. size: 'lg',
  20615. resolve: {
  20616. KindId: function () {
  20617. return $scope.kindId;
  20618. }
  20619. }
  20620. });
  20621. modalInstance.result.then(function (data) {
  20622. $scope.prodInfo.cmpUuId = data.uuid;
  20623. $scope.prodInfo.pcmpcode = data.code;
  20624. $scope.prodInfo.pbranden = data.brand.nameEn;
  20625. $scope.prodInfo.pbrand = data.brand.nameCn;
  20626. }, function () {
  20627. });
  20628. }, function () {
  20629. });
  20630. }
  20631. };
  20632. $scope.isShow = true;
  20633. // 更新
  20634. $scope.update = function () {
  20635. $scope.prodInfo.$editing = true;
  20636. $scope.isShow = true;
  20637. };
  20638. // 取消
  20639. $scope.cancel = function () {
  20640. GetProductInfo.getOne({id: $stateParams.id}, function (data) {
  20641. $scope.prodInfo = data;
  20642. $scope.prodInfo.$editing = false;
  20643. $scope.isShow = false;
  20644. $scope.loading = false;
  20645. });
  20646. };
  20647. // 删除
  20648. $scope.clearfile = function () {
  20649. $scope.prodInfo.attach = null;
  20650. $scope.myFiles = null;
  20651. $scope.previewShow = false;
  20652. }
  20653. //删除
  20654. $scope.deleteById = function (id) {
  20655. GetProductInfo.deletePurcById({}, id, function (data) {
  20656. if (data.error) {
  20657. toaster.pop("error", "提示", data.error);
  20658. } else {
  20659. toaster.pop("success", "提示", "删除成功");
  20660. window.location.href = "#/purc/product";
  20661. }
  20662. }, function (response) {
  20663. toaster.pop("error", "删除失败", response.data);
  20664. });
  20665. }
  20666. $scope.submit = function (prodInfo) {
  20667. $scope.prodInfo.isPurchase = 1;
  20668. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  20669. $upload.upload({
  20670. url: 'purcProduct/edit/updateProdInfo',
  20671. file: file,
  20672. method: 'POST',
  20673. data: {
  20674. prodInfo: $scope.prodInfo
  20675. },
  20676. }).success(function (data) {
  20677. if (data.success) {
  20678. toaster.pop('success', '提示', data.success);
  20679. loadData();
  20680. // window.location.href="#/sale/prodList";
  20681. }
  20682. if (data.error) {
  20683. toaster.pop('error', '提示', data.error);
  20684. }
  20685. }).error(function (data, status) {
  20686. $scope.loadingShow = false;
  20687. if (status == 403) {
  20688. toaster.pop('error', '操作失败', data);
  20689. } else {
  20690. toaster.pop('error', '操作失败', data.error);
  20691. }
  20692. });
  20693. }
  20694. $scope.previewShow = false;
  20695. $scope.pdfShow = false;
  20696. $scope.noneFileShow = true;
  20697. $scope.$watch('myFiles', function () {
  20698. if ($scope.myFiles) {
  20699. $scope.noneFileShow = false;
  20700. var file = $scope.myFiles[0];
  20701. if (file.name.indexOf('.pdf') != -1 || file.name.indexOf('.PDF') != -1) {//pdf文件
  20702. $scope.pdfShow = true;
  20703. $scope.previewShow = false;
  20704. $scope.imgPreviewName = file.name;
  20705. } else {
  20706. if (typeof(Worker) !== "undefined") {//支持HTML5
  20707. $scope.imgPreview = getObjectURL(file);
  20708. $scope.imgPreviewName = file.name;
  20709. } else {//不支持HTML5
  20710. $scope.imgPreview = 'static/img/all/preview-error.jpg';
  20711. $scope.imgPreviewName = file.name;
  20712. }
  20713. $scope.previewShow = true;
  20714. $scope.pdfShow = false;
  20715. }
  20716. } else {
  20717. $scope.noneFileShow = true;
  20718. $scope.previewShow = false;
  20719. $scope.pdfShow = false;
  20720. }
  20721. });
  20722. //建立一个可存取到该file的url
  20723. var imgurl = null;
  20724. var getObjectURL = function (file) {
  20725. var url = null;
  20726. if (window.createObjectURL != undefined) { // basic
  20727. url = window.createObjectURL(file);
  20728. } else if (window.URL != undefined) { // mozilla(firefox)
  20729. url = window.URL.createObjectURL(file);
  20730. } else if (window.webkitURL != undefined) { // webkit or chrome
  20731. url = window.webkitURL.createObjectURL(file);
  20732. }
  20733. imgurl = url;
  20734. return url;
  20735. };
  20736. // 查看范例
  20737. $scope.showImg = function () {
  20738. if ($scope.prodInfo.attach) {
  20739. GetProductInfo.getAttach({id: $scope.prodInfo.attach.id}, function (data) {
  20740. var src = data.url, box = $('#image-box');
  20741. box.show();
  20742. box.find('img').attr('src', src);
  20743. box.find('a').click(function () {
  20744. box.hide();
  20745. });
  20746. box.dblclick(function () {
  20747. box.hide();
  20748. });
  20749. })
  20750. } else if (imgurl != null) {
  20751. var src = imgurl, box = $('#image-box');
  20752. box.show();
  20753. box.find('img').attr('src', src);
  20754. box.find('a').click(function () {
  20755. box.hide();
  20756. });
  20757. box.dblclick(function () {
  20758. box.hide();
  20759. });
  20760. }
  20761. };
  20762. }]);
  20763. // 供应商绩效考核
  20764. app.controller('VendorPerformanceAssessCtrl', ['$scope', 'VendorPerformanceAssessService', 'BaseService', 'AuthenticationService', 'ngTableParams', '$modal', 'toaster', 'Vendor', 'AccountUser', 'CurrentRole', function ($scope, VendorPerformanceAssessService, BaseService, AuthenticationService, ngTableParams, $modal, toaster, Vendor, AccountUser, CurrentRole) {
  20765. BaseService.scrollBackToTop();
  20766. $scope.vendorPerformanceAssessParams = new ngTableParams({
  20767. page: 1,
  20768. count: 20
  20769. }, {
  20770. total: 0,
  20771. counts: [5, 10, 25, 50],
  20772. getData: function ($defer, params) {
  20773. $scope.loading = true;
  20774. var pageParams = params.url();
  20775. pageParams.keyword = $scope.keyword;
  20776. VendorPerformanceAssessService.get(BaseService.parseParams(pageParams), function (page) {
  20777. $scope.loading = false;
  20778. if (page) {
  20779. params.total(page.totalElement);
  20780. $defer.resolve(page.content);
  20781. $scope.keywordXls = pageParams.keyword;
  20782. }
  20783. $scope.totalCount = page.totalElement;
  20784. }, function (response) {
  20785. $scope.loading = false;
  20786. toaster.pop('error', '数据加载失败', response.data);
  20787. });
  20788. }
  20789. });
  20790. //设置消息已读
  20791. var setOrdersRead = function () {
  20792. var sourceId = [];
  20793. VendorPerformanceAssessService.setRead({}, sourceId, function (message) {
  20794. // $scope.getUnreadIds();
  20795. });
  20796. };
  20797. setOrdersRead();
  20798. // 搜索框回车
  20799. $scope.onSearch = function (keyword) {
  20800. $scope.vendorPerformanceAssessParams.page(1);
  20801. $scope.vendorPerformanceAssessParams.reload();
  20802. $scope.tip = keyword;
  20803. };
  20804. // 查看详情
  20805. $scope.viewDetail = function (id) {
  20806. window.location.hash = "#/sale/vendorPerformanceAssess/" + id;
  20807. }
  20808. }]);
  20809. // 客户详情
  20810. app.controller('VendorPerformanceAssessDetailCtrl', ['$scope', 'toaster', '$stateParams', 'VendorPerformanceAssessService', '$modal', 'ngTableParams', 'BaseService', '$rootScope', 'AuthenticationService', function ($scope, toaster, $stateParams, VendorPerformanceAssessService, $modal, ngTableParams, BaseService, $rootScope, AuthenticationService) {
  20811. BaseService.scrollBackToTop();
  20812. var loadData = function () {
  20813. VendorPerformanceAssessService.getDetail({id: $stateParams.id}, {}, function (data) {
  20814. $scope.vendorPerformanceAssess = data;
  20815. }, function (response) {
  20816. $scope.loading = false;
  20817. toaster.pop('error', '数据加载失败', response.data);
  20818. });
  20819. };
  20820. loadData();
  20821. }]);
  20822. /**
  20823. * 个人产品库
  20824. */
  20825. app.controller('UserProductCtrl', ['$scope', 'prodUser', 'ngTableParams', '$filter', 'BaseService', 'toaster', '$timeout', '$modal', '$rootScope', function ($scope, prodUser, ngTableParams, $filter, BaseService, toaster, $timeout, $modal, $rootScope) {
  20826. BaseService.scrollBackToTop();
  20827. $rootScope.ids = [];// 每次加载先清空数据
  20828. $scope.searchMethod = false;
  20829. var getService = function () {
  20830. return $scope.searchMethod ? prodUser.getInfo : prodUser.info;
  20831. };
  20832. $scope.tableParams = new ngTableParams({ // ng-Table参数
  20833. page: 1,
  20834. count: 20,
  20835. sorting: {
  20836. 'date': 'desc',
  20837. 'id': 'desc'
  20838. }
  20839. }, {
  20840. total: 0,
  20841. counts: [],
  20842. getData: function ($defer, params) { // 获取数据的方法
  20843. $scope.loading = true;
  20844. var pageParams = params.url();
  20845. pageParams.keyword = $scope.keyword;
  20846. $scope.tip = $scope.keyword;
  20847. getService().call(null, BaseService.parseParams(pageParams), function (page) {
  20848. $scope.loading = false;
  20849. if (page) {
  20850. params.total(page.totalElement);
  20851. $defer.resolve(page.content);
  20852. $scope.checkall = true;
  20853. if(page.content.length <= 2) {
  20854. $scope.checkall = false;
  20855. } else {
  20856. angular.forEach(page.content, function (prod) {
  20857. if ($rootScope.ids.indexOf(prod.id) > -1) {
  20858. prod.$selected = true;
  20859. } else {
  20860. $scope.checkall = false;
  20861. }
  20862. });
  20863. }
  20864. $scope.checkboxes = {
  20865. checked: $scope.checkall
  20866. };
  20867. }
  20868. }, function (response) {
  20869. $scope.loading = false;
  20870. toaster.pop('error', '数据加载失败', response.data);
  20871. });
  20872. }
  20873. });
  20874. // 搜索框回车
  20875. $scope.onSearch = function (keyword) {
  20876. // 每次搜索重置获取数据方法
  20877. $scope.searchMethod = false;
  20878. if(keyword != null && keyword != '') {
  20879. $scope.searchMethod = true;
  20880. $scope.tip = keyword;
  20881. }
  20882. $scope.tableParams.page(1);
  20883. $scope.tableParams.reload();
  20884. };
  20885. // 新增产品信息
  20886. $scope.addProduct = function() {
  20887. $modal.open({
  20888. animation: true,
  20889. size: 'lg',
  20890. templateUrl: 'static/tpl/index/approvalFlow/modal/userprod_new_modal.html',
  20891. controller: 'UserProductNewCtrl',
  20892. }).result.then(function (data) {
  20893. $scope.tableParams.page(1);
  20894. $scope.tableParams.reload();
  20895. }, function () {
  20896. });
  20897. }
  20898. // 导入商品信息
  20899. $scope.uploadByBatch = function () {
  20900. var modalInstance = $modal.open({
  20901. templateUrl: 'static/tpl/index/approvalFlow/modal/uplodaByBatch.html',
  20902. controller: 'UserProdUploadCtrl',
  20903. backdrop: 'static',
  20904. keyboard: false,
  20905. size: 'lg',
  20906. resolve: {}
  20907. });
  20908. modalInstance.result.then(function (data) {
  20909. $scope.tableParams.page(1);
  20910. $scope.tableParams.reload();
  20911. }, function () {
  20912. });
  20913. }
  20914. // 删除
  20915. $scope.deleteById = function(id) {
  20916. prodUser.deleteById({}, id, function(data) {
  20917. toaster.pop('success', '提示', '删除成功');
  20918. $scope.tableParams.page(1);
  20919. $scope.tableParams.reload();
  20920. }, function(res) {
  20921. toaster.pop('error', '提示', '删除失败');
  20922. });
  20923. }
  20924. $scope.checkboxes = {
  20925. checked: false
  20926. };
  20927. angular.forEach($scope.tableParams.data, function (item) {
  20928. $scope.checkboxes.checked = false;
  20929. if($rootScope.ids.in_array(item.id)) {
  20930. $rootScope.ids.remove(item.id);
  20931. $scope.checkboxes.checked = true;
  20932. }
  20933. });
  20934. // 点击勾选全部的复选框
  20935. $scope.checkAll = function () {
  20936. angular.forEach($scope.tableParams.data, function (item) {
  20937. item.$selected = $scope.checkboxes.checked;
  20938. if(item.$selected) {
  20939. if(!$rootScope.ids.in_array(item.id)) {
  20940. $rootScope.ids.push(item.id);
  20941. }
  20942. } else {
  20943. if($rootScope.ids.in_array(item.id)) {
  20944. $rootScope.ids.remove(item.id);
  20945. }
  20946. }
  20947. });
  20948. };
  20949. // 判断数组中是否存在某个对象
  20950. Array.prototype.S = String.fromCharCode(2);
  20951. Array.prototype.in_array = function(e) {
  20952. var r = new RegExp(this.S + e + this.S);
  20953. return (r.test(this.S + this.join(this.S) + this.S));
  20954. }
  20955. // 从数组中移除某个对象
  20956. Array.prototype.remove = function(val) {
  20957. var index = this.indexOf(val);
  20958. if (index > -1) {
  20959. this.splice(index, 1);
  20960. }
  20961. };
  20962. // 点击其中一个明细的复选框
  20963. $scope.checkOne = function (product) {
  20964. var result = true;
  20965. angular.forEach($scope.tableParams.data, function (item) {
  20966. if (item.$selected != true) {
  20967. result = false;
  20968. return;
  20969. }
  20970. });
  20971. if(product.$selected) {
  20972. if(!$rootScope.ids.in_array(product.id)) {
  20973. $rootScope.ids.push(product.id);
  20974. }
  20975. } else {
  20976. if($rootScope.ids.in_array(product.id)) {
  20977. $rootScope.ids.remove(product.id);
  20978. }
  20979. }
  20980. $scope.checkboxes = {
  20981. checked: result
  20982. };
  20983. };
  20984. // 批量删除
  20985. $scope.deleteByBatch = function() {
  20986. var ids = angular.toJson($rootScope.ids);
  20987. if($rootScope.ids.length > 0) {
  20988. prodUser.deleteByBatch({ids: ids}, {}, function(data) {
  20989. toaster.pop('success', '提示', '成功移除' + $rootScope.ids.length + '个产品');
  20990. $rootScope.ids = [];
  20991. $scope.tableParams.page(1);
  20992. $scope.tableParams.reload();
  20993. }, function(res) {
  20994. toaster.pop('error', '提示', '移除失败');
  20995. });
  20996. } else {
  20997. toaster.pop('error', '提示', '请先选择产品');
  20998. }
  20999. }
  21000. }]);
  21001. /**
  21002. * 用户产品新增产品
  21003. */
  21004. app.controller('UserProductNewCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', function($scope, toaster, prodUser, $modalInstance) {
  21005. // 确定
  21006. $scope.submit = function(prodInfo) {
  21007. prodUser.addProduct({}, prodInfo, function(data) {
  21008. if(data.success) {
  21009. toaster.pop('success', '提示', data.success);
  21010. } else if(data.info) {
  21011. toaster.pop('info', '提示', data.info);
  21012. }
  21013. $modalInstance.close('success');
  21014. }, function(res) {
  21015. toaster.pop('error', '提示', '添加失败');
  21016. });
  21017. }
  21018. // 取消
  21019. $scope.cancel = function() {
  21020. $modalInstance.dismiss();
  21021. }
  21022. }]);
  21023. /**
  21024. * 用户产品批量导入产品
  21025. */
  21026. app.controller('UserProdUploadCtrl', ['$scope', 'toaster', 'prodUser', '$modalInstance', '$upload', function($scope, toaster, prodUser, $modalInstance, $upload) {
  21027. // 通过excel批量上传物料
  21028. $scope.upload = function () {
  21029. $scope.loading = true;
  21030. if ($scope.myFiles) {
  21031. var file = $scope.myFiles[0];
  21032. if (file.name) {
  21033. $upload.upload({
  21034. url: 'productuser/edit/release/excel',
  21035. file: file,
  21036. method: 'POST'
  21037. }).success(function (data) {
  21038. $scope.loading = false;
  21039. if (data.error) {
  21040. toaster.pop('error', '提示', data.error);
  21041. }
  21042. $scope.result = data;
  21043. $scope.success = $scope.result.success;
  21044. $scope.total = $scope.result.total;
  21045. $scope.myFiles[0] = "";
  21046. $scope.fileName = "";
  21047. }).error(function (response) {
  21048. $scope.loading = false;
  21049. toaster.pop('error', response.data || response);
  21050. });
  21051. } else {
  21052. $scope.loading = false;
  21053. toaster.pop('info', '提示', '当前文件不存在,请重新选择');
  21054. }
  21055. } else {
  21056. $scope.loading = false;
  21057. }
  21058. };
  21059. // 取消
  21060. $scope.cancel = function() {
  21061. $modalInstance.dismiss();
  21062. }
  21063. // 下载模板
  21064. $scope.download = function () {
  21065. window.location.href = 'productuser/upload/template';
  21066. };
  21067. // 确定
  21068. $scope.enSure = function() {
  21069. $modalInstance.close('success');
  21070. }
  21071. }]);
  21072. /**
  21073. * 针对卖家,已转询价的公共询价单列表
  21074. */
  21075. app.controller('SalePubInquiryCtrl', ['$scope', '$filter', 'PubInquirySearchInfo', 'ngTableParams', 'toaster', 'BaseService', 'PubInquiryNoSearchInfo', '$upload', '$rootScope', 'token', '$timeout', 'CurrentRole', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', function ($scope, $filter, PubInquirySearchInfo, ngTableParams, toaster, BaseService, PubInquiryNoSearchInfo, $upload, $rootScope, token, $timeout, CurrentRole, publicInquiry, $modal, AccountEnterprise, $http) {
  21076. BaseService.scrollBackToTop();
  21077. // 获取当前用户是否为普通用户
  21078. CurrentRole.isUser({}, {}, function (data) {
  21079. $scope.isUser = data.isUser;
  21080. });
  21081. if ($rootScope.active) {
  21082. $scope.active = $rootScope.active;
  21083. $rootScope.active = null;
  21084. } else {
  21085. $scope.active = 'all';
  21086. }
  21087. $scope.agreedText = '全部';
  21088. $scope.dateZoneText = '最近一个月';
  21089. $scope.condition = {dateZone: 1};
  21090. /* 时间筛选初始化*/
  21091. var fromDate = new Date();
  21092. var toDate = new Date();
  21093. fromDate.setMonth(fromDate.getMonth() - 1);
  21094. fromDate.setHours(0, 0, 0, 0);
  21095. toDate.setHours(23, 59, 59, 999);
  21096. $scope.condition.dateFrom = fromDate;
  21097. $scope.condition.dateTo = toDate;
  21098. $scope.changeAgreed = function (agreed) {
  21099. $scope.condition.agreed = agreed;
  21100. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  21101. $scope.condition.$agreedOpen = false;
  21102. };
  21103. $scope.changeDateZone = function (zone) {
  21104. $scope.condition.dateZone = zone;
  21105. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21106. $scope.condition.$dateZoneOpen = false;
  21107. getDateCondition(zone, $scope.condition);
  21108. $scope.tableParams.page(1);
  21109. $scope.tableParams.reload();
  21110. };
  21111. $scope.setActive = function (state) {
  21112. if ($scope.active != state) {
  21113. $scope.active = state;
  21114. if ($scope.tableParams.page() == 1)
  21115. $scope.tableParams.reload();
  21116. else
  21117. $scope.tableParams.page(1);
  21118. }
  21119. };
  21120. $scope.searchMethod = false;
  21121. var getService = function () {
  21122. return $scope.searchMethod ? PubInquirySearchInfo : PubInquiryNoSearchInfo;
  21123. };
  21124. $scope.tableParams = new ngTableParams({
  21125. page: 1,
  21126. count: 20,
  21127. sorting: {
  21128. 'inquiry.date': 'desc',
  21129. 'inquiry.enterprise.enName': 'asc',
  21130. 'inquiry.code': 'asc'
  21131. }
  21132. }, {
  21133. total: 0,
  21134. counts: [5, 10, 25, 50],
  21135. getData: function ($defer, params) {
  21136. $scope.loading = true;
  21137. var pageParams = params.url();
  21138. var realActive = {};
  21139. pageParams.searchFilter = { // 筛选条件
  21140. keyword: $scope.keyword,
  21141. fromDate: getDateTime($scope.condition.dateFrom),
  21142. endDate: getDateTime($scope.condition.dateTo)
  21143. };
  21144. if ($scope.active == 'overdue') {
  21145. $scope.active = 'end';
  21146. }
  21147. AccountEnterprise.get({}, function(data) {
  21148. $scope.currentEn = data;
  21149. publicInquiry.getUrl({}, function(data) {
  21150. var url = data.url;
  21151. var filter = {vendUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21152. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21153. $http({
  21154. method: 'get',
  21155. dataType: 'json',
  21156. url: url + '/inquiry/public/quotation/list',
  21157. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21158. }).success(function (response) {
  21159. $scope.loading = false;
  21160. if (response) {
  21161. params.total(response.totalElements);
  21162. $defer.resolve(response.content);
  21163. }
  21164. }).error(function (err) {
  21165. $scope.loading = false;
  21166. toaster.pop('error', '数据加载失败', err);
  21167. });
  21168. });
  21169. });
  21170. }
  21171. });
  21172. $scope.isUnread = function (id) {
  21173. for (var i in $scope.unreadCode) {
  21174. if (id == $scope.unreadCode[i]) {
  21175. return true;
  21176. }
  21177. }
  21178. };
  21179. $scope.getMinDate = function (item) {
  21180. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21181. };
  21182. $scope.replyPrices = [];
  21183. $scope.replylapQtys = [];
  21184. $scope.replyPrices.push(true);
  21185. $scope.replylapQtys.push(true);
  21186. $scope.addStep = function (inquiryItem) {
  21187. $scope.replyPrices.push(true);
  21188. if (inquiryItem.replies.length >= 10) {
  21189. toaster.pop('warning', '提示', '最多支持10个分段!');
  21190. } else {
  21191. inquiryItem.replies.push({});
  21192. if (inquiryItem.replies.length != 1) {
  21193. $scope.replyPrices.push(true);
  21194. $scope.replylapQtys.push(true);
  21195. }
  21196. }
  21197. };
  21198. $scope.removeStep = function (inquiryItem, stepIndex) {
  21199. inquiryItem.replies.splice(stepIndex, 1);
  21200. $scope.replyPrices.splice(stepIndex, 1);
  21201. $scope.replylapQtys.splice(stepIndex, 1);
  21202. };
  21203. $scope.openDatePicker = function ($event, item, openParam) {
  21204. $event.preventDefault();
  21205. $event.stopPropagation();
  21206. item[openParam] = !item[openParam];
  21207. };
  21208. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21209. $event.preventDefault();
  21210. $event.stopPropagation();
  21211. item[openParam] = !item[openParam];
  21212. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21213. $scope.tableParams.reload();
  21214. }
  21215. };
  21216. $scope.getHistory = function (item) {
  21217. if (!item.history) {
  21218. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21219. item.history = data;
  21220. });
  21221. }
  21222. };
  21223. // 报价
  21224. $scope.quote = function(inquiryItem) {
  21225. $modal.open({
  21226. animation: true,
  21227. templateUrl: 'static/tpl/index/sale/modal/quote_inquiry.html',
  21228. controller: 'QuoteInquiryCtrl',
  21229. resolve: {
  21230. inquiryItem: function () {
  21231. return inquiryItem
  21232. }
  21233. }
  21234. }).result.then(function (data) {
  21235. }, function () {})
  21236. };
  21237. $scope.deleteAttach = function (attaches, index) {
  21238. attaches.splice(index, 1);
  21239. };
  21240. $scope.onReplyClick = function (item, withSteps) {
  21241. if (item.vendFromDate instanceof Date) {
  21242. item.vendFromDate = item.vendFromDate.getTime();
  21243. }
  21244. if (item.vendToDate instanceof Date) {
  21245. item.vendToDate = item.vendToDate.getTime();
  21246. }
  21247. if (item.vendFromDate > item.vendToDate) {
  21248. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  21249. return;
  21250. }
  21251. var replies = [];
  21252. // 判断分段数是否合法
  21253. var valid = true;
  21254. var validLapQty = 0;
  21255. angular.forEach(item.replies, function (r, i) {
  21256. if ((i > 0 ? r.lapQty : 1) || r.price) {
  21257. replies.push(r);
  21258. }
  21259. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  21260. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  21261. valid = false;
  21262. validLapQty = r.lapQty;
  21263. }
  21264. });
  21265. item.replies = replies;
  21266. $scope.loading = true;
  21267. if (!valid) {
  21268. if (validLapQty) {
  21269. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  21270. } else {
  21271. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  21272. }
  21273. $scope.loading = false;
  21274. } else {
  21275. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  21276. if (withSteps) { // 保存并报价
  21277. if(null != file) {
  21278. $upload.upload({
  21279. url: 'sale/pubInquiry/addAttach',
  21280. file: file,
  21281. method: 'POST',
  21282. data: {
  21283. item: item,
  21284. method: 'reply'
  21285. }
  21286. }).success(function (data) {
  21287. if (data.item) {
  21288. item = data.item;
  21289. }
  21290. $scope.loading = false;
  21291. toaster.pop('info', '提示', '报价成功');
  21292. $scope.tableParams.reload();
  21293. }).error(function (data) {
  21294. $scope.loading = false;
  21295. toaster.pop('error', '附件上传失败');
  21296. });
  21297. } else {
  21298. publicInquiry.reply({itemId: item.id, token: $scope.token}, item, function (data) {
  21299. $scope.loading = false;
  21300. toaster.pop('info', '提示', '报价成功');
  21301. $scope.tableParams.reload();
  21302. }, function (response) {
  21303. $scope.loading = false;
  21304. toaster.pop('error', '询价失效', response.data);
  21305. });
  21306. }
  21307. } else { // 保存
  21308. if(null != file) {
  21309. $upload.upload({
  21310. url: 'sale/pubInquiry/addAttach',
  21311. file: file,
  21312. method: 'POST',
  21313. data: {
  21314. item: item,
  21315. method: 'save'
  21316. }
  21317. }).success(function (data) {
  21318. if (data.item) {
  21319. item = data.item;
  21320. }
  21321. $scope.loading = false;
  21322. toaster.pop('info', '提示', '保存成功');
  21323. $scope.tableParams.reload();
  21324. }).error(function (data) {
  21325. $scope.loading = false;
  21326. toaster.pop('error', '附件上传失败');
  21327. });
  21328. } else {
  21329. publicInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function (data) {
  21330. $scope.loading = false;
  21331. toaster.pop('info', '提示', '保存成功');
  21332. $scope.tableParams.reload();
  21333. }, function (response) {
  21334. $scope.loading = false;
  21335. toaster.pop('error', '保存失败', response.data);
  21336. });
  21337. }
  21338. }
  21339. }
  21340. };
  21341. $scope.isValid = function (item, withSteps) {
  21342. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  21343. if (!withSteps || !bool)
  21344. return bool;
  21345. angular.forEach(item.replies, function (r, i) {
  21346. $scope.verifylapQty(r.lapQty, i, item);
  21347. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  21348. });
  21349. return bool;
  21350. };
  21351. $scope.verifylapQty = function (value, index, inquiryItem) {
  21352. value = parseInt(value);
  21353. var regex = /^\d+(.\d{1,5})?$/;
  21354. var valid = true;
  21355. angular.forEach(inquiryItem.replies, function(reply, $index) {
  21356. if ($index < index && reply.lapQty >= value) {
  21357. valid = false;
  21358. }
  21359. });
  21360. $scope.replylapQtys[index] = regex.test(value) && valid;
  21361. };
  21362. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21363. $scope.verify = function (value, type) {
  21364. var regex = /^\d+(.\d{1,5})?$/;//
  21365. switch (type) {
  21366. case 'minOrderQty':
  21367. $scope.minOrderQtyVerify = regex.test(value);
  21368. break;
  21369. case 'minPackQty':
  21370. $scope.minPackQtyVerify = regex.test(value);
  21371. break;
  21372. case 'leadtime':
  21373. $scope.leadtimeVerify = regex.test(value);
  21374. break;
  21375. default:
  21376. $scope.replyPrices[type] = regex.test(value);
  21377. break;
  21378. }
  21379. }
  21380. // 搜索框回车
  21381. $scope.onSearch = function (keyword) {
  21382. // 每次搜索重置获取数据方法
  21383. $scope.searchMethod = false;
  21384. if(keyword != null && keyword != '') {
  21385. $scope.searchMethod = true;
  21386. }
  21387. $scope.tableParams.page(1);
  21388. $scope.tableParams.reload();
  21389. };
  21390. // 取消
  21391. $scope.cancel = function () {
  21392. $scope.tableParams.reload();
  21393. }
  21394. // 导出
  21395. $scope.exportXls = function () {
  21396. PurcInquiry.exportXls({}, {}, function (data) {
  21397. if (data.success) {
  21398. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21399. }
  21400. }, function (response) {
  21401. toaster.pop('error', '数据加载失败', response.data);
  21402. })
  21403. }
  21404. }]);
  21405. /**
  21406. * 针对卖家,已转询价单的客户公共询价单明细
  21407. */
  21408. app.controller('SalePubInquiryDetailCtrl', ['$scope', '$stateParams', 'PurcInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'publicInquiry', function ($scope, $stateParams, PurcInquiry, $filter, toaster, $upload, token, CurrentRole, publicInquiry) {
  21409. // 获取当前用户是否为普通用户
  21410. var loadData = function () {
  21411. publicInquiry.inquiryDetail({id: $stateParams.id}, function (data) {
  21412. $scope.inquiryItem = data;
  21413. var inquiry = data.inquiry;
  21414. angular.forEach(inquiry.attachs, function (attach) {
  21415. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21416. });
  21417. $scope.inquiry = inquiry;
  21418. $scope.attach = null;
  21419. if ($scope.inquiryItem.attaches.length > 0) {
  21420. $scope.attach = $scope.inquiryItem.attaches[0];
  21421. }
  21422. }, function (response) {
  21423. $scope.loading = false;
  21424. toaster.pop('error', '', response.data);
  21425. });
  21426. };
  21427. loadData();
  21428. $scope.getMinDate = function (item) {
  21429. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21430. };
  21431. $scope.replyPrices = [];
  21432. $scope.replylapQtys = [];
  21433. $scope.replyPrices.push(true);
  21434. $scope.replylapQtys.push(true);
  21435. $scope.addStep = function (inquiryItem) {
  21436. if (inquiryItem.replies.length >= 10) {
  21437. toaster.pop('warning', '提示', '最多支持10个分段!');
  21438. } else
  21439. inquiryItem.replies.push({});
  21440. };
  21441. $scope.removeStep = function (inquiryItem, stepIndex) {
  21442. inquiryItem.replies.splice(stepIndex, 1);
  21443. };
  21444. $scope.openDatePicker = function ($event, item, openParam) {
  21445. $event.preventDefault();
  21446. $event.stopPropagation();
  21447. item[openParam] = !item[openParam];
  21448. };
  21449. $scope.getHistory = function (item) {
  21450. if (!item.history) {
  21451. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21452. item.history = data;
  21453. });
  21454. }
  21455. };
  21456. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21457. $scope.verify = function (value, type) {
  21458. var regex = /^\d+(.\d{1,5})?$/;//
  21459. switch (type) {
  21460. case 'minOrderQty':
  21461. $scope.minOrderQtyVerify = regex.test(value);
  21462. break;
  21463. case 'minPackQty':
  21464. $scope.minPackQtyVerify = regex.test(value);
  21465. break;
  21466. case 'leadtime':
  21467. $scope.leadtimeVerify = regex.test(value);
  21468. break;
  21469. default:
  21470. $scope.replyPrices[type] = regex.test(value);
  21471. break;
  21472. }
  21473. }
  21474. $scope.verifylapQty = function (value, index, inquiryItem) {
  21475. value = parseInt(value);
  21476. var regex = /^\d+(.\d{1,5})?$/;
  21477. var valid = true;
  21478. angular.forEach(inquiryItem.replies, function(reply, $index) {
  21479. if ($index < index && reply.lapQty >= value) {
  21480. valid = false;
  21481. }
  21482. });
  21483. $scope.replylapQtys[index] = regex.test(value) && valid;
  21484. };
  21485. $scope.isValid = function (item, withSteps) {
  21486. var bool = item.leadtime && item.replies && item.replies[0].price > 0;
  21487. if (!withSteps || !bool)
  21488. return bool;
  21489. angular.forEach(item.replies, function (r, i) {
  21490. $scope.verifylapQty(r.lapQty, i, item);
  21491. bool = (i > 0 ? r.lapQty : 1) && r.price && $scope.replylapQtys[i];
  21492. });
  21493. return bool;
  21494. };
  21495. $scope.deleteAttach = function (attaches, index) {
  21496. attaches.splice(index, 1);
  21497. };
  21498. $scope.onReplyClick = function (item, withSteps) {
  21499. if (item.vendFromDate instanceof Date) {
  21500. item.vendFromDate = item.vendFromDate.getTime();
  21501. }
  21502. if (item.vendToDate instanceof Date) {
  21503. item.vendToDate = item.vendToDate.getTime();
  21504. }
  21505. if (item.vendFromDate > item.vendToDate) {
  21506. toaster.pop('warning', '警告', '有效开始日期不能超过有效截止日期');
  21507. return;
  21508. }
  21509. var replies = [];
  21510. var valid = true;
  21511. var validLapQty = 0;
  21512. angular.forEach(item.replies, function (r, i) {
  21513. // 直接比较是字符串比较,需要先转换再比较 2017年9月7日 15:05:51
  21514. if (i > 0 && parseInt(r.lapQty) <= parseInt(item.replies[i - 1].lapQty) || r.lapQty == null) {
  21515. valid = false;
  21516. validLapQty = r.lapQty;
  21517. }
  21518. if ((i > 0 ? r.lapQty : 1) || r.price)
  21519. replies.push(r);
  21520. });
  21521. item.replies = replies;
  21522. $scope.loading = true;
  21523. if (!valid) { // 不合法时给出提示
  21524. if (validLapQty) {
  21525. toaster.pop('info', '提示', '分段' + validLapQty + '小于等于了上一分段数,不能保存!');
  21526. } else {
  21527. toaster.pop('info', '提示', '分段数量不合法,不能保存!');
  21528. }
  21529. $scope.loading = false;
  21530. } else {
  21531. var file = item.myFiles, file = file && file.length > 0 ? file[0] : null;
  21532. if (withSteps) {
  21533. if(null != file) {
  21534. $upload.upload({
  21535. url: 'sale/pubInquiry/addAttach',
  21536. file: file,
  21537. method: 'POST',
  21538. data: {
  21539. item: item,
  21540. method: 'reply'
  21541. }
  21542. }).success(function (data) {
  21543. if (data.item) {
  21544. item = data.item;
  21545. }
  21546. toaster.pop('success', '提示', '报价成功');
  21547. loadData();
  21548. }).error(function () {
  21549. toaster.pop('error', '提示', '报价失败');
  21550. });
  21551. } else {
  21552. publicInquiry.reply({itemId: item.id, token: $scope.token}, item, function () {
  21553. $scope.loading = false;
  21554. toaster.pop('success', '提示', '报价成功');
  21555. loadData();
  21556. }, function (response) {
  21557. $scope.loading = false;
  21558. toaster.pop('error', '询价失效', response.data);
  21559. });
  21560. }
  21561. } else {
  21562. if(null != file) {
  21563. $upload.upload({
  21564. url: 'sale/pubInquiry/addAttach',
  21565. file: file,
  21566. method: 'POST',
  21567. data: {
  21568. item: item,
  21569. method: 'save'
  21570. }
  21571. }).success(function (data) {
  21572. if (data.item) {
  21573. item = data.item;
  21574. }
  21575. toaster.pop('success', '提示', '保存成功');
  21576. loadData();
  21577. }).error(function () {
  21578. toaster.pop('error', '提示', '保存失败');
  21579. });
  21580. } else {
  21581. publicInquiry.saveItem({itemId: item.id, token: $scope.token}, item, function () {
  21582. $scope.loading = false;
  21583. toaster.pop('info', '提示', '保存成功');
  21584. loadData();
  21585. }, function (response) {
  21586. $scope.loading = false;
  21587. toaster.pop('error', '保存失败', response.data);
  21588. });
  21589. }
  21590. }
  21591. }
  21592. };
  21593. // 取消
  21594. $scope.cancel = function () {
  21595. $scope.tableParams.reload();
  21596. }
  21597. }]);
  21598. /**
  21599. * 针对买家,已转询价的公共询价单列表
  21600. */
  21601. 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) {
  21602. BaseService.scrollBackToTop();
  21603. // 获取当前用户是否为普通用户
  21604. CurrentRole.isUser({}, {}, function (data) {
  21605. $scope.isUser = data.isUser;
  21606. });
  21607. if ($rootScope.active) {
  21608. $scope.active = $rootScope.active;
  21609. $rootScope.active = null;
  21610. } else {
  21611. $scope.active = 'all';
  21612. }
  21613. $scope.agreedText = '全部';
  21614. $scope.dateZoneText = '最近一个月';
  21615. $scope.condition = {dateZone: 1};
  21616. /* 时间筛选初始化*/
  21617. var fromDate = new Date();
  21618. var toDate = new Date();
  21619. fromDate.setMonth(fromDate.getMonth() - 1);
  21620. fromDate.setHours(0, 0, 0, 0);
  21621. toDate.setHours(23, 59, 59, 999);
  21622. $scope.condition.dateFrom = fromDate;
  21623. $scope.condition.dateTo = toDate;
  21624. $scope.changeAgreed = function (agreed) {
  21625. $scope.condition.agreed = agreed;
  21626. $scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已采纳' : '未采纳');
  21627. $scope.condition.$agreedOpen = false;
  21628. };
  21629. $scope.changeDateZone = function (zone) {
  21630. $scope.condition.dateZone = zone;
  21631. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21632. $scope.condition.$dateZoneOpen = false;
  21633. getDateCondition(zone, $scope.condition);
  21634. $scope.tableParams.page(1);
  21635. $scope.tableParams.reload();
  21636. };
  21637. $scope.setActive = function (state) {
  21638. if ($scope.active != state) {
  21639. $scope.active = state;
  21640. if ($scope.tableParams.page() == 1)
  21641. $scope.tableParams.reload();
  21642. else
  21643. $scope.tableParams.page(1);
  21644. }
  21645. };
  21646. $scope.searchMethod = false;
  21647. var getService = function () {
  21648. return $scope.searchMethod ? PurcPubInquirySearchInfo : PurcPubInquiryNoSearchInfo;
  21649. };
  21650. $scope.tableParams = new ngTableParams({
  21651. page: 1,
  21652. count: 20,
  21653. sorting: {
  21654. 'inquiry.date': 'desc',
  21655. 'inquiry.enterprise.enName': 'asc',
  21656. 'inquiry.code': 'asc'
  21657. }
  21658. }, {
  21659. total: 0,
  21660. counts: [5, 10, 25, 50],
  21661. getData: function ($defer, params) {
  21662. $scope.loading = true;
  21663. var pageParams = params.url();
  21664. var realActive = {};
  21665. pageParams.searchFilter = { // 筛选条件
  21666. keyword: $scope.keyword,
  21667. fromDate: getDateTime($scope.condition.dateFrom),
  21668. endDate: getDateTime($scope.condition.dateTo)
  21669. };
  21670. if ($scope.active == 'overdue') {
  21671. $scope.active = 'end';
  21672. }
  21673. AccountEnterprise.get({}, function(data) {
  21674. $scope.currentEn = data;
  21675. publicInquiry.getUrl({}, function(data) {
  21676. var url = data.url;
  21677. var filter = {enUU: $scope.currentEn.uu, keyword: $scope.keyword,
  21678. fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)};
  21679. $http({
  21680. method: 'get',
  21681. dataType: 'json',
  21682. url: url + '/inquiry/public/quotation/list',
  21683. params: {pageNumber: pageParams.page, pageSize: pageParams.count, filter: filter, _state: $scope.active}
  21684. }).success(function (response) {
  21685. $scope.loading = false;
  21686. if (response) {
  21687. params.total(response.totalElements);
  21688. $defer.resolve(response.content);
  21689. // $scope.keywordXls = angular.copy($scope.keyword); // 保存当前取值的关键词 做导出时需要的字段
  21690. }
  21691. }).error(function (err) {
  21692. $scope.loading = false;
  21693. toaster.pop('error', '数据加载失败', err);
  21694. });
  21695. });
  21696. });
  21697. }
  21698. });
  21699. $scope.isUnread = function (id) {
  21700. for (var i in $scope.unreadCode) {
  21701. if (id == $scope.unreadCode[i]) {
  21702. return true;
  21703. }
  21704. }
  21705. };
  21706. $scope.getMinDate = function (item) {
  21707. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21708. };
  21709. $scope.replyPrices = [];
  21710. $scope.replylapQtys = [];
  21711. $scope.replyPrices.push(true);
  21712. $scope.replylapQtys.push(true);
  21713. $scope.openFilterDatePicker = function ($event, item, openParam) {
  21714. $event.preventDefault();
  21715. $event.stopPropagation();
  21716. item[openParam] = !item[openParam];
  21717. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  21718. $scope.tableParams.reload();
  21719. }
  21720. };
  21721. $scope.getHistory = function (item) {
  21722. if (!item.history) {
  21723. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21724. item.history = data;
  21725. });
  21726. }
  21727. };
  21728. // 搜索框回车
  21729. $scope.onSearch = function (keyword) {
  21730. // 每次搜索重置获取数据方法
  21731. $scope.searchMethod = false;
  21732. if(keyword != null && keyword != '') {
  21733. $scope.searchMethod = true;
  21734. }
  21735. $scope.tableParams.page(1);
  21736. $scope.tableParams.reload();
  21737. };
  21738. // 采纳
  21739. $scope.accept = function (id) {
  21740. publicInquiry.accept({id: id}, {}, function (data) {
  21741. if (data.success) {
  21742. toaster.pop('success', '提示', data.success);
  21743. $scope.tableParams.page(1);
  21744. $scope.tableParams.reload();
  21745. }
  21746. if (data.error) {
  21747. toaster.pop('error', '提示', data.error);
  21748. $scope.tableParams.page(1);
  21749. $scope.tableParams.reload();
  21750. }
  21751. }, function (response) {
  21752. toaster.pop('error', '提示', '采纳失败');
  21753. $scope.tableParams.page(1);
  21754. $scope.tableParams.reload();
  21755. })
  21756. };
  21757. // 拒绝
  21758. $scope.refuse = function (id) {
  21759. publicInquiry.refuse({id: id}, {}, function (data) {
  21760. if (data.success) {
  21761. toaster.pop('success', '提示', data.success);
  21762. $scope.tableParams.page(1);
  21763. $scope.tableParams.reload();
  21764. }
  21765. if (data.error) {
  21766. toaster.pop('error', '提示', data.error);
  21767. $scope.tableParams.page(1);
  21768. $scope.tableParams.reload();
  21769. }
  21770. }, function (response) {
  21771. toaster.pop('error', '提示', '操作失败');
  21772. $scope.tableParams.page(1);
  21773. $scope.tableParams.reload();
  21774. })
  21775. }
  21776. // 导出
  21777. $scope.exportXls = function () {
  21778. PurcInquiry.exportXls({}, {}, function (data) {
  21779. if (data.success) {
  21780. window.location.href = 'sale/inquiry/xls?_state='+$scope.active+'&searchFilter='+encodeURIComponent(angular.toJson($scope.searchFilterXls));
  21781. }
  21782. }, function (response) {
  21783. toaster.pop('error', '数据加载失败', response.data);
  21784. })
  21785. }
  21786. }]);
  21787. /**
  21788. * 针对买家,已转询价单的客户公共询价单明细
  21789. */
  21790. app.controller('PurcPubInquiryDetailCtrl', ['$scope', '$stateParams', 'publicInquiry', '$filter', 'toaster', '$upload', 'token', 'CurrentRole', 'AccountEnterprise', '$http', function ($scope, $stateParams, publicInquiry, $filter, toaster, $upload, token, CurrentRole, AccountEnterprise, $http) {
  21791. // 获取当前用户是否为普通用户
  21792. CurrentRole.isUser({}, {}, function (data) {
  21793. $scope.isUser = data.isUser;
  21794. });
  21795. AccountEnterprise.get({}, function(data) {
  21796. $scope.currentEn = data;
  21797. publicInquiry.getUrl({}, function(data) {
  21798. var url = data.url;
  21799. $http({
  21800. method: 'get',
  21801. dataType: 'json',
  21802. url: url + '/inquiry/buyer/detail',
  21803. params: {id: $stateParams.id, enuu: $scope.currentEn.uu}
  21804. }).success(function (response) {
  21805. $scope.newinquiryItems = response;
  21806. var inquiry = response;
  21807. angular.forEach(inquiry.attachs, function (attach) {
  21808. attach.type = attach.name.substr(attach.name.lastIndexOf('.') + 1);
  21809. });
  21810. $scope.inquiry = inquiry;
  21811. });
  21812. });
  21813. });
  21814. $scope.getMinDate = function (item) {
  21815. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  21816. };
  21817. $scope.replyPrices = [];
  21818. $scope.replylapQtys = [];
  21819. $scope.replyPrices.push(true);
  21820. $scope.replylapQtys.push(true);
  21821. $scope.getHistory = function (item) {
  21822. if (!item.history) {
  21823. publicInquiry.getHistory({itemId: item.id}, function (data) {
  21824. item.history = data;
  21825. });
  21826. }
  21827. };
  21828. $scope.minOrderQtyVerify = $scope.minPackQtyVerify = $scope.leadtimeVerify = true;
  21829. $scope.verify = function (value, type) {
  21830. var regex = /^\d+(.\d{1,5})?$/;//
  21831. switch (type) {
  21832. case 'minOrderQty':
  21833. $scope.minOrderQtyVerify = regex.test(value);
  21834. break;
  21835. case 'minPackQty':
  21836. $scope.minPackQtyVerify = regex.test(value);
  21837. break;
  21838. case 'leadtime':
  21839. $scope.leadtimeVerify = regex.test(value);
  21840. break;
  21841. default:
  21842. $scope.replyPrices[type] = regex.test(value);
  21843. break;
  21844. }
  21845. }
  21846. // 采纳
  21847. $scope.accept = function (id) {
  21848. publicInquiry.accept({id: id}, {}, function (data) {
  21849. if (data.success) {
  21850. toaster.pop('success', '提示', data.success);
  21851. loadData();
  21852. }
  21853. if (data.error) {
  21854. toaster.pop('error', '提示', data.error);
  21855. }
  21856. }, function (response) {
  21857. toaster.pop('error', '提示', response.data);
  21858. })
  21859. };
  21860. // 拒绝
  21861. $scope.refuse = function (id) {
  21862. publicInquiry.refuse({id: id}, {}, function (data) {
  21863. if (data.success) {
  21864. toaster.pop('success', '提示', data.success);
  21865. loadData();
  21866. }
  21867. if (data.error) {
  21868. toaster.pop('error', '提示', data.error);
  21869. }
  21870. }, function (response) {
  21871. toaster.pop('error', '提示', response.data);
  21872. })
  21873. }
  21874. }]);
  21875. /**
  21876. * 公共询价模态框(供应商报价)
  21877. */
  21878. app.controller('QuoteInquiryCtrl', ['$scope', '$stateParams', 'toaster', 'inquiryItem', '$modalInstance', '$upload', function ($scope, $stateParams, toaster, inquiryItem, $modalInstance, $upload) {
  21879. $scope.inquiryItem = inquiryItem;
  21880. $scope.replyPrices = [];
  21881. $scope.replylapQtys = [];
  21882. $scope.replyPrices.push(true);
  21883. $scope.replylapQtys.push(true);
  21884. // 增加一列分段报价
  21885. $scope.addStep = function (inquiryItem) {
  21886. $scope.replyPrices.push(true);
  21887. if (inquiryItem.replies.length >= 5) {
  21888. toaster.pop('warning', '提示', '最多支持5个分段!');
  21889. } else {
  21890. inquiryItem.replies.push({});
  21891. if (inquiryItem.replies.length != 1) {
  21892. $scope.replyPrices.push(true);
  21893. $scope.replylapQtys.push(true);
  21894. }
  21895. }
  21896. };
  21897. // 删除一列分段报价
  21898. $scope.removeStep = function (inquiryItem, stepIndex) {
  21899. inquiryItem.replies.splice(stepIndex, 1);
  21900. $scope.replyPrices.splice(stepIndex, 1);
  21901. $scope.replylapQtys.splice(stepIndex, 1);
  21902. };
  21903. // 取消,关闭弹出框
  21904. $scope.cancel = function() {
  21905. $modalInstance.dismiss();
  21906. }
  21907. // 保存报价信息
  21908. $scope.save = function(inquiryItem, method) {
  21909. var file = $scope.myFiles, file = file && file.length > 0 ? file[0] : null;// 可以不传附件
  21910. $upload.upload({
  21911. url: 'pubInquiry/turnToQuotation',
  21912. file: file,
  21913. method: 'POST',
  21914. data: {
  21915. item: inquiryItem,
  21916. method: method
  21917. }
  21918. }).success(function (data) {
  21919. if (data.item) {
  21920. item = data.item;
  21921. }
  21922. $scope.loading = false;
  21923. toaster.pop('info', '提示', '报价成功');
  21924. $scope.tableParams.reload();
  21925. }).error(function (data) {
  21926. $scope.loading = false;
  21927. toaster.pop('error', '报价失败');
  21928. });
  21929. }
  21930. }]);
  21931. /**
  21932. * 首页侧边栏询价列表
  21933. */
  21934. app.controller('InquiryMessageListCtrl', ['$scope', 'publicInquiry', 'AccountEnterprise', '$http', function($scope, publicInquiry, AccountEnterprise, $http) {
  21935. AccountEnterprise.get({}, function(data) {
  21936. $scope.currentEn = data;
  21937. publicInquiry.getUrl({}, function (data) {
  21938. var url = data.url;
  21939. $http({
  21940. method: 'get',
  21941. url: url + '/inquiry/public/messageList',
  21942. params: {enuu: $scope.currentEn.uu, size: 7},
  21943. dataType: 'json'
  21944. }).success(function(data) {
  21945. $scope.message = data;
  21946. }).error(function(error) {
  21947. });
  21948. });
  21949. });
  21950. }]);
  21951. /**
  21952. * 针对卖家,询价推荐列表
  21953. */
  21954. app.controller('SaleInquiryRemindCtrl', ['$scope', '$filter', 'ngTableParams', 'toaster', 'BaseService', 'publicInquiry', '$modal', 'AccountEnterprise', '$http', 'AuthenticationService', function ($scope, $filter, ngTableParams, toaster, BaseService, publicInquiry, $modal, AccountEnterprise, $http, AuthenticationService) {
  21955. BaseService.scrollBackToTop();
  21956. $scope.agreedText = '全部';
  21957. $scope.dateZoneText = '最近一个月';
  21958. $scope.condition = {dateZone: 1};
  21959. /* 时间筛选初始化*/
  21960. var fromDate = new Date();
  21961. var toDate = new Date();
  21962. fromDate.setMonth(fromDate.getMonth() - 1);
  21963. fromDate.setHours(0, 0, 0, 0);
  21964. toDate.setHours(23, 59, 59, 999);
  21965. $scope.condition.dateFrom = fromDate;
  21966. $scope.condition.dateTo = toDate;
  21967. $scope.changeDateZone = function (zone) {
  21968. $scope.condition.dateZone = zone;
  21969. $scope.dateZoneText = zone == 1 ? '最近一个月' : (zone == 3 ? '最近三个月' : (zone == 3 ? '最近六个月' : '自定义'));
  21970. $scope.condition.$dateZoneOpen = false;
  21971. getDateCondition(zone, $scope.condition);
  21972. $scope.tableParams.page(1);
  21973. $scope.tableParams.reload();
  21974. };
  21975. $scope.tableParams = new ngTableParams({
  21976. page: 1,
  21977. count: 20,
  21978. sorting: {
  21979. 'date': 'desc'
  21980. }
  21981. }, {
  21982. total: 0,
  21983. counts: [5, 10, 25, 50],
  21984. getData: function ($defer, params) {
  21985. $scope.loading = true;
  21986. var pageParams = params.url();
  21987. var realActive = {};
  21988. pageParams.searchFilter = { // 筛选条件
  21989. keyword: $scope.keyword,
  21990. fromDate: getDateTime($scope.condition.dateFrom),
  21991. endDate: getDateTime($scope.condition.dateTo)
  21992. };
  21993. if ($scope.active == 'overdue') {
  21994. $scope.active = 'end';
  21995. }
  21996. AccountEnterprise.get({}, function(data) {
  21997. $scope.currentEn = data;
  21998. publicInquiry.getUrl({}, function(data) {
  21999. $scope.url = data.url;
  22000. AuthenticationService.getAuthentication().success(function (data) {
  22001. $scope.loading = false;
  22002. $scope.thisUser = data;
  22003. $http({
  22004. method: 'get',
  22005. dataType: 'json',
  22006. url: $scope.url + '/inquiry/sale/remind',
  22007. params: {pageNumber: pageParams.page, pageSize: pageParams.count, useruu: $scope.thisUser.userUU, enuu: $scope.currentEn.uu,
  22008. keyword: $scope.keyword, fromDate: getDateTime($scope.condition.dateFrom), endDate: getDateTime($scope.condition.dateTo)}
  22009. }).success(function (response) {
  22010. $scope.loading = false;
  22011. if (response) {
  22012. params.total(response.totalElements);
  22013. $defer.resolve(response.content);
  22014. }
  22015. }).error(function (err) {
  22016. $scope.loading = false;
  22017. toaster.pop('error', '数据加载失败', err);
  22018. });
  22019. });
  22020. });
  22021. });
  22022. }
  22023. });
  22024. $scope.getMinDate = function (item) {
  22025. return $filter('date')(item.inquiry.date, 'yyyy-MM-dd');
  22026. };
  22027. $scope.openDatePicker = function ($event, item, openParam) {
  22028. $event.preventDefault();
  22029. $event.stopPropagation();
  22030. item[openParam] = !item[openParam];
  22031. };
  22032. $scope.openFilterDatePicker = function ($event, item, openParam) {
  22033. $event.preventDefault();
  22034. $event.stopPropagation();
  22035. item[openParam] = !item[openParam];
  22036. if ($scope.condition.dateFrom && $scope.condition.dateTo && !item[openParam]) {
  22037. $scope.tableParams.reload();
  22038. }
  22039. };
  22040. // 搜索框回车
  22041. $scope.onSearch = function (keyword) {
  22042. // 每次搜索重置获取数据方法
  22043. $scope.searchMethod = false;
  22044. if(keyword != null && keyword != '') {
  22045. $scope.searchMethod = true;
  22046. }
  22047. $scope.tableParams.page(1);
  22048. $scope.tableParams.reload();
  22049. };
  22050. // 取消
  22051. $scope.cancel = function () {
  22052. $scope.tableParams.reload();
  22053. }
  22054. // 转客户询价
  22055. $scope.qute = function (remind) {
  22056. $http({
  22057. method: 'get',
  22058. dataType: 'json',
  22059. url: $scope.url + '/inquiry/sale/quote',
  22060. params: {id: remind.itemId, en_uu: $scope.currentEn.uu}
  22061. }).success(function (response) {
  22062. $scope.loading = false;
  22063. if (response.inquiry != null) {
  22064. toaster.pop('error', '该单据已报价');
  22065. } else {
  22066. $http({
  22067. method: 'get',
  22068. dataType: 'json',
  22069. url: $scope.url + '/inquiry/public/findItemByItemId',
  22070. params: {itemId: remind.itemId, enuu: $scope.currentEn.uu}
  22071. }).success(function (response) {
  22072. var inquiryItem = response;
  22073. var modalInstance = $modal.open({
  22074. templateUrl: 'static/tpl/index/baseInfo/modal/quotation_modal.html',
  22075. controller: 'QuoteCtrl',
  22076. size: 'lg',
  22077. resolve: {
  22078. inquiryItem: function () {
  22079. return inquiryItem
  22080. }
  22081. }
  22082. });
  22083. modalInstance.result.then(function (data) {
  22084. $scope.tableParams.reload();
  22085. }, function () {
  22086. });
  22087. }).error(function (error) {
  22088. toaster.pop('error', '数据加载失败', error);
  22089. });
  22090. }
  22091. }).error(function (err) {
  22092. toaster.pop('error', '数据加载失败', err);
  22093. });
  22094. }
  22095. // 跳转详情
  22096. $scope.toDetail = function(remind) {
  22097. if (remind.newId == null) {
  22098. window.location.hash = '#/baseInfo/inquiryList/' + remind.itemId;
  22099. } else {
  22100. window.open("#/sale/pubinquiry/" + remind.newId);
  22101. }
  22102. }
  22103. }]);
  22104. return app;
  22105. });