1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511 |
- 'use strict';
- /**
- * 变更令详细页js
- *
- * @author EllisRan.
- * @date 2018/11/22
- * @version
- */
- const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + ' ledger-Select';
- const ckChangeSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + 'change-Select';
- const is_numeric = (value) => {
- if (typeof(value) === 'object') {
- return false;
- } else {
- return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
- }
- };
- function sortByCode(a, b) {
- let code1 = a.code.split('-');
- let code2 = b.code.split('-');
- let code1length = code1.length;
- let code2length = code2.length;
- for (let i = 0; i < code1length; i ++) {
- if (i+1 <= code2length) {
- if (code1[i] != code2[i]) {
- if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
- return parseInt(code1[i]) - parseInt(code2[i]);
- } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
- return 1;
- } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
- return -1;
- } else {
- const str1length = code1[i].length;
- const str2length = code2[i].length;
- for (let j = 0; j < str1length; j++) {
- if (j+1 <= str2length) {
- if (code1[i].charAt(j) != code2[i].charAt(j)) {
- return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
- } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
- if (str1length == str2length) {
- return 0;
- } else {
- return str1length - str2length;
- }
- }
- } else {
- if (j+1 >= str1length) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- }
- } else if (i+1 == code1length && code1[i] == code2[i]) {
- if (code1length == code2length) {
- return 0;
- } else {
- return code1length - code2length;
- }
- }
- } else {
- if (i+1 >= code1length) {
- return 1;
- } else {
- return -1;
- }
- }
- }
- }
- $.event.special.valuechange = {
- teardown: function (namespaces) {
- $(this).unbind('.valuechange');
- },
- handler: function (e) {
- $.event.special.valuechange.triggerChanged($(this));
- },
- add: function (obj) {
- $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
- },
- triggerChanged: function (element) {
- var current = element[0].contentEditable === 'true' ? element.html() : element.val()
- , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
- if (current !== previous) {
- element.trigger('valuechange', [element.data('previous')]);
- element.data('previous', current);
- }
- }
- };
- function getPasteHint (str, row = '') {
- let returnObj = str;
- if (row) {
- returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
- }
- return returnObj;
- }
- $(document).ready(() => {
- //初始化所有附件列表
- getAllList();
- // 计算最新的变更总额和change的total_price是否一致,不一致则更新
- // if (changeStatus !== auditConst.status.checked) {
- calcChangePrice();
- // }
- //tab change
- $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
- const tab = $(this).data('tab');
- if (tab === 'bgfujian') {
- $('#fujian_btn').show();
- $('#copy_btn').hide();
- } else {
- $('#fujian_btn').hide();
- $('#copy_btn').show();
- }
- });
- $('#add-bj').on('click', 'input[type="checkbox"]', function () {
- const isCheck = $(this).prop('checked');
- if (isCheck) {
- $('#add-bj input[type="checkbox"]').each(function () {
- $(this).prop('checked', false)
- });
- $(this).prop('checked', true)
- }
- });
- $('#bg-copy').click(function() {
- const cid = $('#add-bj input:checked').data('id');
- postData(window.location.pathname + '/copy', cid, function () {
- window.location.reload();
- })
- });
- // 上传附件
- $('#upload-file-btn').click(function () {
- const files = $('#upload-file')[0].files;
- const formData = new FormData();
- formData.append('cid', $('#changeId').val());
- formData.append('tid', $('#tenderId').val());
- for (const file of files) {
- if (file === undefined) {
- toastr.error('未选择上传文件!');
- return false;
- }
- const filesize = file.size;
- if (filesize > 50 * 1024 * 1024) {
- toastr.error('文件大小过大!');
- return false;
- }
- const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
- if (whiteList.indexOf(fileext) === -1) {
- toastr.error('只能上传指定格式的附件!');
- return false;
- }
- formData.append('size', filesize);
- formData.append('file[]', file);
- }
- // if (!(change_uid === accountId || (auditors2 && auditors2.findIndex(item => item.uid === parseInt(accountId)) !== -1) || touristPermission)) {
- if (!filePermission) {
- return toastr.error('暂无权限上传!');
- }
- postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
- attData = data.concat(attData);
- // 重新生成List
- getAllList();
- $('#addfujian').modal('hide');
- // let html = '';
- // let index = $('#attList tr').length + 1;
- // for (const fileInfo of data) {
- // html += '<tr> ' +
- // `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
- // '<td>' + index + '</td> ' +
- // `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
- // '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
- // `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
- // ( auditStatus === 4 ?
- // fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
- // : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
- // `</td>`+
- // // '<td> <a class="btn btn-light btn-sm delete-file" data-attid="' + fileInfo.id + '" title="删除附件"><span class="fa fa-trash text-danger"></span></a> </td> ' +
- // '</tr>';
- // ++index;
- // }
- // $('#attList').append(html);
- }, function () {
- });
- $('#upload-file').val('');
- });
- // 删除附件
- $('body').on('click', '.delete-file', function () {
- let attid = $(this).data('attid');
- let self = $(this);
- const data = {id: attid};
- postData(window.location.pathname + '/file/delete', data, function (result) {
- // self.parents('tr').remove();
- // // 重新排序
- // let newsort = 1;
- // $('#attList tr').each(function(){
- // $(this).children('td').eq(1).text(newsort);
- // newsort++;
- // });
- // 删除到attData中
- const att_index = attData.findIndex(function (item) {
- return item.id === parseInt(attid);
- });
- attData.splice(att_index, 1);
- // 重新生成List
- if ($('#attList tr').length === 1) {
- getAllList(parseInt($('#currentPage').text()) - 1);
- } else {
- getAllList(parseInt($('#currentPage').text()));
- }
- });
- });
- // /change/download/file/
- $('#attList').on('click', '.file-atn', function() {
- const id = $(this).attr('f-id');
- postData(`/change/download/file/${id}`, {}, (data) => {
- const { filepath } = data;
- $('#file-upload').attr('href', filepath);
- $('#file-upload')[0].click();
- })
- });
- $('#attList').on('click', '.check-file', function() {
- const checkedList = $('#attList').find('input:checked');
- const childs = $('#attList').children().length;
- const checkBox = $('#check-all-file');
- if (checkedList.length === childs) {
- checkBox.prop("checked", true);
- } else {
- checkBox.prop("checked", false);
- }
- });
- $('#check-all-file').click(function() {
- const isCheck = $(this).is(':checked');
- $('#attList').children().each(function() {
- $(this).find('input:checkbox').prop("checked", isCheck);
- })
- });
- $('#bach-download').click(function() {
- const fileIds = [];
- $( '#attList .check-file:checked').each(function() {
- const fileId = $(this).attr('file-id');
- fileId && fileIds.push(fileId);
- });
- if (fileIds.length) {
- // const tid = $('#tenderId').val();
- // const cid = $('#changeId').val();
- // $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
- // $('#downloadZip')[0].click();
- if (fileIds.length > 20) {
- return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
- }
- const tid = $('#tenderId').val();
- const cid = $('#changeId').val();
- toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
- $(this).attr('disabled', "true");
- const btn = $(this);
- const fileArr = [];
- for (const id of fileIds) {
- const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
- fileArr.push({
- url: fileInfo.orginpath, //文件的oss存储路径 (必填)
- name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
- foldPath: '' // (可选, 文件在压缩包中的存储路径)
- });
- }
- const packageName = `${tenderName}-工程变更-${changeName}-附件.zip`;
- try {
- zipOss.downloadFromAliOss(fileArr, packageName, btn);
- } catch (e) {
- btn.removeAttr('disabled');
- toastr.clear();
- toastr.error('批量下载失败');
- }
- // postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
- // toastr.clear();
- // toastr.success('压缩文件成功');
- // btn.removeAttr('disabled');
- // const href = window.URL.createObjectURL(result);
- // $('#zipDown').attr('href', href);
- // $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
- // $("#zipDown")[0].click();
- // }, () => {
- // btn.removeAttr('disabled');
- // toastr.clear();
- // toastr.error('批量下载失败');
- // });
- }
- });
- // 差值对比信息获取
- let czSpread = null;
- const czSpreadSetting = {
- cols: [
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
- {title: '变更方案|数量', colSpan: '2|1', rowSpan: '1|1', field: 'pamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.pamount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'pa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.pa_tp'},
- {title: '变更令|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
- {title: '差值对比|数量', colSpan: '2|1', rowSpan: '1|1', field: 'czamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.czamount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cz_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.cz_tp'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- localCache: {
- key: 'changes-cz',
- colWidth: true,
- }
- };
- const czCol = {
- getValue: {
- unit_price: function(data) {
- return ZhCalc.round(data.unit_price, unitPriceUnit);
- },
- pa_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.pamount, findDecimal(data.unit))), totalPriceUnit);
- },
- ca_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
- },
- pamount: function (data) {
- return ZhCalc.round(data.pamount, findDecimal(data.unit));
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- czamount: function (data) {
- return ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit)));
- },
- cz_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit))), findDecimal(data.unit))), totalPriceUnit);
- },
- }
- };
- const czSpreadObj = {
- makeBackColor: function () {
- const rowCount = czSpread.getActiveSheet().getRowCount();
- for (let i = 0; i < rowCount; i++) {
- if (czSpread.getActiveSheet().zh_data[i].color) czSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#f5c6cb');
- }
- },
- makeSjsFooter: function () {
- // 增加汇总行并设为锁定禁止编辑状态
- czSpread.getActiveSheet().addRows(czSpread.getActiveSheet().getRowCount(), 1);
- czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
- czSpread.getActiveSheet().setStyle(czSpread.getActiveSheet().getRowCount() - 1, -1, style1);
- czSpreadObj.countSum();
- },
- countSum: function () {
- const rowCount = czSpread.getActiveSheet().getRowCount();
- let pSum = 0,
- cSum = 0,
- czSum = 0;
- for (let i = 0; i < rowCount - 1; i++) {
- pSum = ZhCalc.add(pSum, czSpread.getActiveSheet().getValue(i, 5));
- cSum = ZhCalc.add(cSum, czSpread.getActiveSheet().getValue(i, 7));
- czSum = ZhCalc.add(czSum, czSpread.getActiveSheet().getValue(i, 9));
- }
- czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 5, pSum !== 0 ? pSum : null);
- czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
- czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 9, czSum !== 0 ? czSum : null);
- },
- };
- $('#bgfadb').on('shown.bs.modal', function () {
- if (!czSpread) {
- czSpread = SpreadJsObj.createNewSpread($('#cz-spread')[0]);
- SpreadJsObj.initSpreadSettingEvents(czSpreadSetting, czCol);
- SpreadJsObj.initSheet(czSpread.getActiveSheet(), czSpreadSetting);
- }
- const cList = [];
- const newChangeList = _.cloneDeep(changeList);
- for (const cl of newChangeList) {
- const cIndex = _.findIndex(cList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
- if (cIndex !== -1) {
- cList[cIndex].spamount = ZhCalc.add(cList[cIndex].spamount, cl.spamount);
- } else {
- cList.push(cl);
- }
- }
- // 生成差值对比数据列表
- const czList = [];
- const newPlanList = _.cloneDeep(planList);
- for (const c of cList) {
- const planInfo = _.find(newPlanList, { code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price });
- const pamount = planInfo ? planInfo.spamount : null;
- let color = true;
- if (planInfo) {
- _.remove(newPlanList, (item) => item === planInfo);
- if ((pamount ? pamount : 0) === (c.spamount ? c.spamount : 0)) {
- color = false;
- }
- }
- czList.push({ code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price, camount: c.spamount, pamount, color });
- }
- if (newPlanList.length > 0) {
- for (const np of newPlanList) {
- czList.push({ code: np.code, name: np.name, unit: np.unit, unit_price: np.unit_price, camount: null, pamount: np.spamount, color: true });
- }
- }
- if (czList.length > 0) {
- // 按清单编号排序
- czList.sort(sortByCode);
- }
- console.log(czList);
- // sjs设置
- SpreadJsObj.loadSheetData(czSpread.getActiveSheet(), SpreadJsObj.DataType.Data, czList);
- czSpreadObj.makeBackColor();
- czSpreadObj.makeSjsFooter();
- });
- // 清单汇总信息获取
- let hzSpread = null;
- const hzSpreadSetting = {
- cols: [
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
- {title: '申报变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
- {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'amount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.amount', visible: readOnly && !shenpiPower},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'a_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.a_tp', visible: readOnly && !shenpiPower},
- {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'spamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.spamount', visible: readOnly && shenpiPower},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'spa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.spa_tp', visible: readOnly && shenpiPower},
- {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', hAlign: 2, width: 60, type: 'Number', getValue: '', visible: !readOnly},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', hAlign: 2, width: 80, type: 'Number', getValue: '', visible: !readOnly},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- readOnly: true,
- localCache: {
- key: 'changes-hz',
- colWidth: true,
- }
- };
- const hzCol = {
- getValue: {
- unit_price: function(data) {
- return ZhCalc.round(data.unit_price, unitPriceUnit);
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- ca_tp: function (data) {
- return ZhCalc.round(data.ca_tp, totalPriceUnit);
- },
- amount: function (data) {
- return ZhCalc.round(data.amount, findDecimal(data.unit));
- },
- a_tp: function (data) {
- return ZhCalc.round(data.a_tp, totalPriceUnit);
- },
- spamount: function (data) {
- return ZhCalc.round(data.spamount, findDecimal(data.unit));
- },
- spa_tp: function (data) {
- return ZhCalc.round(data.spa_tp, totalPriceUnit);
- },
- }
- };
- const hzSpreadObj = {
- makeBackColor: function () {
- const rowCount = hzSpread.getActiveSheet().getRowCount();
- for (let i = 0; i < rowCount; i++) {
- if (readOnly && shenpiPower && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].spamount) {
- hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
- } else if (readOnly && !shenpiPower && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].amount) {
- hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
- } else if (!readOnly && !(hzSpread.getActiveSheet().zh_data[i].camount === '' || hzSpread.getActiveSheet().zh_data[i].camount === 0 || hzSpread.getActiveSheet().zh_data[i].camount === null)) {
- hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
- }
- }
- },
- makeSjsFooter: function () {
- // 增加汇总行并设为锁定禁止编辑状态
- hzSpread.getActiveSheet().addRows(hzSpread.getActiveSheet().getRowCount(), 1);
- hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
- hzSpread.getActiveSheet().setStyle(hzSpread.getActiveSheet().getRowCount() - 1, -1, style1);
- hzSpreadObj.countSum();
- },
- countSum: function () {
- const rowCount = hzSpread.getActiveSheet().getRowCount();
- let cSum = 0,
- sSum = 0,
- spSum = 0;
- for (let i = 0; i < rowCount - 1; i++) {
- cSum = ZhCalc.add(cSum, hzSpread.getActiveSheet().getValue(i, 5));
- sSum = ZhCalc.add(sSum, hzSpread.getActiveSheet().getValue(i, 7));
- spSum = ZhCalc.add(spSum, hzSpread.getActiveSheet().getValue(i, 9));
- }
- hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 5, cSum !== 0 ? cSum : null);
- hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 7, sSum !== 0 ? sSum : null);
- hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 9, spSum !== 0 ? spSum : null);
- },
- };
- $('#qdgather').on('shown.bs.modal', function () {
- if (!hzSpread) {
- hzSpread = SpreadJsObj.createNewSpread($('#hz-spread')[0]);
- SpreadJsObj.initSpreadSettingEvents(hzSpreadSetting, hzCol);
- SpreadJsObj.initSheet(hzSpread.getActiveSheet(), hzSpreadSetting);
- }
- const hzList = [];
- const newChangeList = _.cloneDeep(changeSpreadSheet.zh_data);
- for (const cl of newChangeList) {
- const hzIndex = _.findIndex(hzList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
- const count4Amount = cl.audit_amount ? cl.audit_amount.split(',').length : 0;
- cl.spa_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.spamount, findDecimal(cl.unit))), totalPriceUnit);
- // 根据count4Amoun得出audit_amount_X值
- cl.amount = count4Amount ? cl['audit_amount_' + count4Amount + ''] : 0;
- cl.a_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.amount, findDecimal(cl.unit))), totalPriceUnit);
- if (hzIndex !== -1) {
- hzList[hzIndex].camount = ZhCalc.add(hzList[hzIndex].camount, cl.camount);
- hzList[hzIndex].ca_tp = ZhCalc.add(hzList[hzIndex].ca_tp, cl.ca_tp);
- hzList[hzIndex].spamount = ZhCalc.add(hzList[hzIndex].spamount, cl.spamount);
- hzList[hzIndex].spa_tp = ZhCalc.add(hzList[hzIndex].spa_tp, cl.spa_tp);
- hzList[hzIndex].amount = ZhCalc.add(hzList[hzIndex].amount, cl.amount);
- hzList[hzIndex].a_tp = ZhCalc.add(hzList[hzIndex].a_tp, cl.a_tp);
- } else {
- hzList.push(cl);
- }
- }
- if (hzList.length > 0) {
- // 按清单编号排序
- hzList.sort(sortByCode);
- }
- console.log(hzList);
- // // sjs设置
- SpreadJsObj.loadSheetData(hzSpread.getActiveSheet(), SpreadJsObj.DataType.Data, hzList);
- hzSpreadObj.makeBackColor();
- hzSpreadObj.makeSjsFooter();
- });
- // 切换页数
- $('.page-select').on('click', function () {
- const totalPageNum = parseInt($('#totalPage').text());
- const lastPageNum = parseInt($('#currentPage').text());
- const status = $(this).attr('content');
- if (status === 'pre' && lastPageNum > 1) {
- getAllList(lastPageNum-1);
- $('#showAttachment').hide();
- $('#syfujian .check-all-file').prop('checked', false)
- } else if (status === 'next' && lastPageNum < totalPageNum) {
- getAllList(lastPageNum+1);
- $('#showAttachment').hide();
- $('#syfujian .check-all-file').prop('checked', false)
- }
- });
- // 数字只判断几个值(unit_price, oamount)
- const numField = ['unit_price', 'oamount2'];
- const changeSpreadSetting = {
- cols: [
- {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
- {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isSettle2'},
- {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
- {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
- {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
- // {title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},
- // {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'},
- // {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if (data.ccid && data.ccid === 1) {
- return '#dc3545';
- }
- if (data.id && data.lid != 0 && !data.children) {
- return '#ffc107';
- }
- if(data.lid != 0) return;
- return '#007bff';
- }
- },
- },
- ],
- localCache: {
- key: 'changes-spread',
- colWidth: true,
- }
- };
- if (readOnly) {
- changeSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
- changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
- for (const aid of aidList) {
- // const userinfo = _.find(auditList2, { 'uid': aid });
- const audit = _.find(auditors2, function(item){
- return _.findIndex(item, { audit_order: aid }) !== -1;
- });
- const newColcount = {
- title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
- colSpan: '2|1', rowSpan: '1|1',
- field: 'audit_amount_' + aid,
- hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
- };
- const newColTp = {
- title: '|金额',
- colSpan: '|1', rowSpan: '|1',
- field: 'sa_tp_' + aid,
- hAlign: 2, width: 80, type: 'Number',
- };
- changeSpreadSetting.cols.push(newColcount);
- changeSpreadSetting.cols.push(newColTp);
- }
- }
- changeSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'changed_amount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'});
- changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
- // if (!readOnly) {
- // changeSpreadSetting.cols.push({title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'});
- // }
- changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
- return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;
- }
- const changeCol = {
- getValue: {
- unit_price: function(data) {
- return ZhCalc.round(data.unit_price, unitPriceUnit);
- },
- oa_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit);
- },
- ca_tp: function (data) {
- return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
- },
- oamount2: function (data) {
- return ZhCalc.round(data.oamount2, findDecimal(data.unit));
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- changed_amount: function (data) {
- return ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
- },
- changed_tp: function (data) {
- return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
- ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit));
- },
- // del_list: function (data) {
- // return !_.find(changeUsedData, { cbid: data.id }) && !checkIsSettle(data) ? '移除' : '';
- // }
- },
- readOnly: {
- isValuation: function (data) {
- return !(!readOnly && ((data.id && _.findIndex(changeUsedData, { cbid: data.id }) !== -1) || (data.children && data.children.length === 1 && _.findIndex(changeUsedData, { cbid: data.children[0].id }) !== -1)));
- },
- isEdit: function (data) {
- return !(!readOnly && data.lid == 0 && data.id && !checkIsSettle(data));
- },
- isSettle: function (data) {
- return !((!readOnly || shenpiPower) && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
- },
- isSettle2: function (data) {
- return !(!readOnly && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
- }
- },
- };
- const changeSpreadObj = {
- makeSjsFooter: function () {
- // 增加汇总行并设为锁定禁止编辑状态
- changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
- changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
- const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
- changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
- changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
- changeSpreadObj.countSum();
- },
- setAuditValue: function () {
- if (readOnly) {
- for (const c of changeList) {
- for (const j of aidList) {
- c['audit_amount_' + j] = ZhCalc.round(c['audit_amount_' + j], findDecimal(c.unit));
- c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
- }
- }
- }
- },
- loadExprToInput: function () {
- const sel = changeSpreadSheet.getSelections()[0];
- if (!sel) return;
- const col = changeSpreadSheet.zh_setting.cols[sel.col];
- const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (col && col.field === 'camount' && data && (!data.gcl_id || (data.children && data.children.length === 1))) {
- if (readOnly) {
- $('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
- } else {
- $('#camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
- }
- } else {
- $('#camount-expr').attr('readonly', true).val('');
- }
- },
- topRowChanged: function (e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, ckChangeSpread);
- },
- selectionChanged: function (e, info) {
- if (info.newSelections) {
- if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
- const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (info.oldSelections && info.oldSelections[0].row !== changeSpreadSheet.getRowCount() - 1) {
- info.sheet.getRange(info.oldSelections[0].row, -1, 1, -1).backColor('#fff');
- }
- if (!data) {
- SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, []);
- return;
- }
- console.log(info);
- changeSpreadObj.refreshXmjData();
- if (!readOnly) changeSpreadObj.refreshActn();
- }
- }
- changeSpreadObj.loadExprToInput();
- },
- showHideAudit: function (show = false) {
- if (shenpiPower) {
- show = true;
- }
- if (readOnly) {
- const count = changeSpreadSetting.cols.length;
- for (let i = startLimit + 5; i < count - 2; i++) {
- changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
- }
- changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
- changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
- }
- },
- calcOneSum: function (node) {
- if (node.children && node.children.length > 0) {
- if (readOnly) {
- for (const aid of aidList) {
- let audit_amount = 0;
- for (const c of node.children) {
- audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(c['audit_amount_' + aid], findDecimal(node.unit)));
- }
- if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
- node['audit_amount_' + aid] = audit_amount;
- }
- node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
- }
- }
- let is_valuation = 1;
- let ccid = 0;
- let oamount2 = 0;
- let camount = 0;
- let samount = 0;
- let spamount = 0;
- for (const c of node.children) {
- oamount2 = ZhCalc.add(oamount2, ZhCalc.round(c.oamount2, findDecimal(node.unit)));
- camount = ZhCalc.add(camount, ZhCalc.round(c.camount, findDecimal(node.unit)));
- samount = ZhCalc.add(samount, ZhCalc.round(c.samount, findDecimal(node.unit)));
- spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(node.unit)));
- if (c.is_valuation === 0) is_valuation = 0;
- if (_.findIndex(changeLedgerList, { id: c.gcl_id }) !== -1 || _.findIndex(changePosList, { id: c.mx_id }) !== -1) {
- ccid = 1;
- }
- c.order = node.order;
- }
- if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
- node.oamount2 = oamount2;
- node.camount = camount;
- node.samount = samount;
- node.spamount = spamount;
- node.change_amount = ZhCalc.add(oamount2, camount);
- }
- node.is_valuation = is_valuation;
- node.ccid = ccid;
- this.calcNodeTp(node);
- } else {
- if (readOnly) {
- for (const aid of aidList) {
- node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
- }
- }
- this.calcNodeTp(node);
- }
- return node;
- },
- calcNodeTp: function (node) {
- node.change_amount = ZhCalc.add(node.oamount2, node.camount);
- node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
- },
- refreshXmjData: function() {
- SpreadJsObj.resetTopAndSelect(xmjSheet);
- xmjSpreadObj.loadCurXmjData();
- SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
- // posSearch.search($('#pos-keyword').val());
- },
- makeNewChangeList: function(newOrder = changeOrder) {
- // 先加载台账数据
- if (!newOrder) {
- const newChangeList2 = [];
- for (const gcl of changeListData) {
- if (!newOrder) {
- if (gcl.leafXmjs !== undefined && gcl.leafXmjs !== null) {
- const cl = _.filter(changeList, function (item) {
- return _.findIndex(gcl.leafXmjs, { gcl_id: item.gcl_id }) !== -1;
- });
- if (cl.length > 0) {
- for (const l of gcl.leafXmjs) {
- const c = _.find(cl, { gcl_id: l.gcl_id, mx_id: l.mx_id || '' });
- if (c) newChangeList2.push(c);
- }
- }
- } else {
- // 签约清单
- const c = _.find(changeList, { lid: gcl.id });
- if (c) newChangeList2.push(c);
- }
- }
- }
- // 按台账去重新排序changeList,空白清单居后
- const sycList = _.difference(changeList, newChangeList2);
- changeList = newChangeList2.concat(sycList);
- }
- const newChangeList = [];
- for (const cl of changeList) {
- const newCl = _.cloneDeep(cl);
- if (cl.gcl_id && _.findIndex(newChangeList, { gcl_id: cl.gcl_id }) === -1) {
- // delete newCl.id;
- // newCl.bwmx = '';
- // newCl.detail = '';
- // newCl.delimit = null;
- newCl.children = [];
- newCl.children.push(cl);
- if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
- newCl.ccid = 1;
- }
- newChangeList.push(newCl);
- } else if (!cl.gcl_id) {
- newChangeList.push(newCl);
- } else {
- const newCl2 = _.find(newChangeList, { gcl_id: cl.gcl_id });
- if (newCl2) {
- if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
- newCl2.ccid = 1;
- }
- delete newCl2.id;
- newCl2.bwmx = '';
- newCl2.detail = '';
- newCl2.delimit = null;
- newCl2.children.push(newCl);
- }
- }
- }
- const updateOrderList = [];
- // order如果不同,则修改并提交
- let i = 0;
- // 重算金额和数量汇总
- for (const node of newChangeList) {
- if (node.children && node.children.length > 0) {
- changeSpreadObj.calcOneSum(node);
- node.order = i + 1;
- const cls = node.gcl_id ? _.filter(changeList, { gcl_id: node.gcl_id }) : [];
- for (const c of cls) {
- if (node.order !== c.order) {
- c.order = node.order;
- updateOrderList.push({ id: c.id, order: node.order });
- }
- }
- } else {
- if (node.order !== i + 1) {
- node.order = i + 1;
- updateOrderList.push({ id: node.id, order: node.order });
- }
- changeSpreadObj.calcOneSum(node);
- if (readOnly) {
- for (const aid of aidList) {
- node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- }
- }
- }
- i++;
- }
- return [newChangeList, updateOrderList];
- },
- countSum: function () {
- const rowCount = changeSpreadSheet.getRowCount();
- let oa_tp = 0,
- ca_tp = 0,
- sa_tp = 0,
- changed_tp = 0;
- const aidLength = readOnly ? aidList.length : 0;
- for (const data of changeSpreadSheet.zh_data) {
- oa_tp = ZhCalc.add(oa_tp, data.oa_tp);
- ca_tp = ZhCalc.add(ca_tp, data.ca_tp);
- sa_tp = ZhCalc.add(sa_tp, data.sa_tp);
- changed_tp = ZhCalc.add(changed_tp, data.changed_tp);
- }
- changeSpreadSheet.setValue(rowCount - 1, startLimit, oa_tp !== 0 ? oa_tp : null);
- changeSpreadSheet.setValue(rowCount - 1, startLimit + 2, ca_tp !== 0 ? ca_tp : null);
- if (readOnly) {
- changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), sa_tp !== 0 ? sa_tp : null);
- changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4 + aidLength * 2 + 2), changed_tp !== 0 ? changed_tp : null);
- } else {
- changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), changed_tp !== 0 ? changed_tp : null);
- }
- if (readOnly) {
- // 用户的数据合计
- for (const j in aidList) {
- let audit_sum = 0;
- for (const data of changeSpreadSheet.zh_data) {
- audit_sum = ZhCalc.add(audit_sum, data['sa_tp_' + aidList[j]]);
- }
- changeSpreadSheet.setValue(rowCount - 1, startLimit + 6 + j * 2, audit_sum !== 0 ? audit_sum : null);
- }
- }
- },
- reloadRow: function (sheet, row, rowCount = 0, clearAll = false) {
- if (rowCount) {
- SpreadJsObj.reLoadRowData(sheet, row, rowCount);
- } else {
- SpreadJsObj.reLoadRowData(sheet, row);
- }
- if (clearAll) {
- for (const i in sheet.zh_data) {
- const data = sheet.zh_data[i];
- if (data) {
- sheet.getRange(i, -1, 1, -1).backColor('#fff');
- }
- }
- }
- sheet.getRange(row, -1, 1, -1).backColor('#fffacd');
- },
- reloadSheet: function (newChangeList) {
- changeSpreadObj.setAuditValue();
- SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, newChangeList);
- SpreadJsObj.loadTopAndSelect(changeSpreadSheet, ckChangeSpread);
- changeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
- changeSpreadObj.makeSjsFooter();
- xmjSpreadObj.loadCurXmjData();
- changeSpreadObj.loadExprToInput();
- if (!readOnly) changeSpreadObj.refreshActn();
- }
- };
- // sjsSettingObj.setGridSelectStyle(changeSpreadSetting);
- SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
- SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
- const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
- let changeListData;
- let gclGatherData;
- postData(preUrl + '/defaultBills', {}, function (result) {
- ledgerList = result.bills;
- posList = result.pos;
- gclGatherModel.loadLedgerData(result.bills);
- gclGatherModel.loadPosData(result.pos);
- gclGatherData = gclGatherModel.gatherGclData();
- gclGatherData = _.filter(gclGatherData, function (item) {
- return item.leafXmjs && item.leafXmjs.length !== 0;
- });
- for (const ggd in gclGatherData) {
- if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
- gclGatherData.splice(ggd, 1);
- }
- gclGatherData[ggd].code = gclGatherData[ggd].b_code;
- let hadcid = 0;
- for (const xmj of gclGatherData[ggd].leafXmjs) {
- const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
- const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
- if (changeLedger || changePos) {
- xmj.cid = 1;
- xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
- hadcid = 1;
- }
- }
- if (hadcid !== 0) gclGatherData[ggd].cid = 1;
- }
- console.log(gclGatherData);
- // 数组去重
- const dealBillList = result.dealBills;
- for (const db of gclGatherData) {
- const exist_index = dealBillList.findIndex(function (item) {
- return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
- });
- if (exist_index !== -1) {
- dealBillList.splice(exist_index, 1);
- }
- }
- changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
- if (!readOnly || shenpiPower) {
- checkAndChange(changeListData);
- }
- showMode(changeMode);
- });
- changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
- changeSpread.bind(spreadNS.Events.topRowChanged, changeSpreadObj.topRowChanged);
- // 项目节信息获取
- const xmjSpreadSetting = {
- cols: [
- {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80, readOnly: true},
- // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
- {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100, readOnly: true},
- {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100, readOnly: true},
- {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100, readOnly: true},
- {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100, readOnly: true},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100, readOnly: true},
- {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
- {title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
- {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', type: 'Number', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
- // {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- // readOnly: true,
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
- return '#dc3545';
- }
- }
- },
- },
- ],
- localCache: {
- key: 'changes-xmj',
- colWidth: true,
- }
- };
- if (readOnly) {
- xmjSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
- for (const aid of aidList) {
- const audit = _.find(auditors2, function(item){
- return _.findIndex(item, { audit_order: aid }) !== -1;
- });
- const newColcount = {
- title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
- colSpan: '1|1', rowSpan: '|1',
- field: 'audit_amount_' + aid,
- hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
- };
- xmjSpreadSetting.cols.push(newColcount);
- }
- }
- xmjSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
- const xmjCol = {
- getValue: {
- oamount2: function (data) {
- return ZhCalc.round(data.oamount2, findDecimal(data.unit));
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- samount: function (data) {
- return ZhCalc.round(data.samount, findDecimal(data.unit));
- },
- changed_amount: function (data) {
- return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
- },
- },
- readOnly: {
- isEdit: function (data) {
- return readOnly;
- },
- isValuation: function (data) {
- return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
- },
- isSettle: function (data) {
- return !((!readOnly || shenpiPower) && !checkIsSettle(data));
- },
- isSettle2: function (data) {
- return !(!readOnly && !checkIsSettle(data));
- }
- },
- }
- sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
- SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
- SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
- const xmjSheet = xmjSpread.getActiveSheet();
- const xmjSpreadObj = {
- loadExprToInput: function () {
- const sel = xmjSheet.getSelections()[0];
- if (!sel) return;
- const col = xmjSheet.zh_setting.cols[sel.col];
- const data = SpreadJsObj.getSelectObject(xmjSheet);
- if (col && col.field === 'camount' && data) {
- if (readOnly) {
- $('#xmj-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
- } else {
- $('#xmj-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
- }
- } else {
- $('#xmj-camount-expr').attr('readonly', true).val('');
- }
- },
- /**
- * 加载计量单元 根据当前台账选择节点
- */
- loadCurXmjData: function () {
- const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
- changeSpreadSheet.getRange(changeSpreadSheet.getSelections()[0].row, -1, 1, -1).backColor('#fffacd');
- const xmj = [];
- if (data && data.children && data.children.length > 0) {
- for (const child of data.children) {
- if (child.bwmx === child.xmj_jldy) {
- child.bwmx = '';
- }
- xmj.push(child);
- }
- }
- SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, xmj);
- xmjSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
- SpreadJsObj.resetTopAndSelect(xmjSheet);
- xmjSpreadObj.loadExprToInput();
- },
- selectionChanged: function (e, info) {
- xmjSpreadObj.loadExprToInput();
- },
- showHideAudit: function (show = false) {
- if (shenpiPower) {
- show = true;
- }
- if (readOnly) {
- const xmjStartLimit = 9;
- const count = xmjSpreadSetting.cols.length;
- for (let i = xmjStartLimit + 2; i < count - 1; i++) {
- xmjSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
- }
- xmjSheet.setColumnVisible(xmjStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
- }
- },
- };
- xmjSpread.bind(spreadNS.Events.SelectionChanged, xmjSpreadObj.selectionChanged);
- if (!readOnly) {
- $('.dropdown-menu input[name="paixu"]').on('click', function () {
- const newChangeOrder = parseInt($(this).val());
- if (newChangeOrder !== changeOrder) {
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList(newChangeOrder);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'order_by', updateData: newChangeOrder, updateOrderList }, function (result) {
- if (newChangeOrder === 0) {
- $('#bpaixu').text('清单排序:清单编号');
- $('#upAndMoveBtn').attr('style', 'display: none !important');
- $('.order_text').text('添加');
- changeOrder = newChangeOrder;
- } else if (newChangeOrder === 1) {
- $('#bpaixu').text('清单排序:添加顺序');
- $('#upAndMoveBtn').show();
- $('.order_text').text('插入');
- changeOrder = newChangeOrder;
- }
- changeList = result.changeList;
- changeUsedData = result.usedList;
- const [newChangeList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- });
- }
- });
- $('#set-site-btn').click(async function () {
- if (changeOrder && !changeMode) {
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (!select && changeSpreadSheet.zh_data.length > 0) {
- toastr.error('请选择清单再插入');
- return;
- }
- postData(window.location.pathname + '/save', { type:'order_site', listid: select && select.id ? select.id : (select && select.children && select.children.length > 0 ? select.children[0].id : null) }, function (result) {
- window.location.href = window.location.pathname + '/revise';
- });
- } else {
- window.location.href = window.location.pathname + '/revise';
- }
- });
- changeSpreadObj.refreshActn = function (rowCount = 1) {
- const setObjEnable = function (obj, enable) {
- if (enable) {
- obj.removeClass('disabled');
- } else {
- obj.addClass('disabled');
- }
- };
- // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- // 还需判断是否已被调差清单调用
- const selection = changeSpreadSheet.getSelections();
- const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const first = changeSpreadSheet.zh_data[row];
- let last = first;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = changeSpreadSheet.zh_data[sel.row + r];
- if (!rNode) break;
- last = rNode;
- }
- }
- const preNode = changeSpreadSheet.zh_data[row - 1];
- setObjEnable($('#up-move'), !readOnly && first && preNode && changeSpreadSheet.zh_data.indexOf(last) > 0 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
- setObjEnable($('#down-move'), !readOnly && first && changeSpreadSheet.zh_data.indexOf(last) < changeSpreadSheet.zh_data.length - 1 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
- // setObjEnable($('#open-list-modal'), !readOnly && select && changeList.indexOf(select) !== -1);
- // setObjEnable($('#add-white-btn'), !readOnly && select && changeList.indexOf(select) !== -1);
- };
- changeSpreadObj.add = function () {
- let select = null;
- if (changeOrder) {
- select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- }
- postData(window.location.pathname + '/save', {type: 'add', postData: select ? select.order : null}, function (result) {
- if (result) {
- if (changeOrder === 1 && select) {
- // 批量更新changeList的order值
- _.forEach(changeList, function (item) {
- item.order = item.order > select.order ? item.order + 1 : item.order;
- });
- _.forEach(changeSpreadSheet.zh_data, function (item) {
- item.order = item.order > select.order ? item.order + 1 : item.order;
- });
- changeList.splice(select.order, 0, result);
- changeSpreadSheet.addRows(select.order, 1);
- changeSpreadSheet.zh_data.splice(select.order, 0, _.cloneDeep(result));
- changeSpreadSheet.getRange(select.order - 1, -1, 1, -1).backColor('#fff');
- changeSpreadSheet.setSelection(select.order, 1, 1, 1);
- changeSpreadObj.reloadRow(changeSpreadSheet, select.order);
- } else {
- changeList.push(result);
- changeSpreadSheet.zh_data.push(_.cloneDeep(result));
- changeSpreadSheet.addRows(changeSpreadSheet.zh_data.length - 1, 1);
- changeSpreadSheet.setSelection(changeSpreadSheet.zh_data.length - 1, 1, 1, 1);
- changeSpreadObj.reloadRow(changeSpreadSheet, changeSpreadSheet.zh_data.length - 1, 0, true);
- }
- changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
- changeSpreadObj.refreshXmjData();
- changeSpreadObj.refreshActn();
- }
- });
- };
- changeSpreadObj.batchAdd = function(num) {
- let select = null;
- if (changeOrder) {
- select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- }
- postData(window.location.pathname + '/save', {type: 'batchadd', num, postData: select ? select.order : null}, function (result) {
- if (result) {
- changeList = result;
- SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
- SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }
- });
- };
- // 计量单元修改
- changeSpreadObj.del = function () {
- const selection = changeSpreadSheet.getSelections();
- const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- const count = sel.rowCount;
- if (readOnly || row === -1 || row + count > changeSpreadSheet.zh_data.length) {
- return false;
- }
- const delList = [];
- let lastSelect = null;
- for (let r = 0; r < count; r++) {
- const select = changeSpreadSheet.zh_data[row + r];
- if (!select || !select.id) {
- toastr.error('变更清单不存在或者该清单存在项目节');
- return;
- }
- if(!select || _.find(changeUsedData, { cbid: select.id })) {
- toastr.error('已调用的变更清单不能删除');
- return false;
- }
- if (checkIsSettle(select)) {
- toastr.error('已结算的变更清单不能删除');
- return false;
- }
- if (r === count - 1 && changeOrder) {
- lastSelect = select;
- }
- delList.push(select.id);
- }
- if (delList.length) {
- postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
- changeSpreadSheet.deleteRows(row, count);
- changeSpreadSheet.zh_data.splice(row, count);
- changeSpreadObj.countSum();
- changeSpreadSheet.setSelection(0, 0, 1, 1);
- changeSpreadObj.refreshXmjData();
- changeSpreadObj.refreshActn();
- });
- }
- };
- changeSpreadObj.editStarting = function (e, info) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- if (select && select.id) {
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'camount') {
- if (select.camount_expr && select.camount_expr !== '') {
- info.sheet.getCell(info.row, info.col).text(select.camount_expr);
- }
- }
- }
- };
- changeSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- if (!select || !select.id) {
- toastr.error('该变更清单无法编辑');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- return;
- }
- let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- let orgValue;
- if (col.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- } else {
- orgValue = select[col.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- if(col.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: select.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = exprQuantity.expr;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- if (col.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- if (col.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('计量上限默认值只能输入0-100之间的整数');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: select.id });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
- if (validText < minLimit) {
- toastr.error('计量上限值至少大于等于 ' + minLimit);
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- console.log(cInfo);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- if (select.children && select.children.length === 1) {
- const child = select.children[0];
- child[col.field] = validText;
- }
- changeSpreadObj.calcOneSum(select);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- changeSpreadObj.refreshXmjData();
- changeSpreadObj.countSum();
- changeSpreadObj.refreshActn();
- if (info.row === info.sheet.zh_data.length - 1) {
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if(col.field === 'camount') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- changeSpreadObj.reloadRow(info.sheet, info.row);
- });
- };
- changeSpreadObj.clipboardPasted = function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- const data = [];
- // const rowData = [];
- let needCopyIgnore = !$('#customCheck1').is(':checked');
- let needColAdd = false;
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- if (!sortData[curRow].id) {
- bPaste = false;
- continue;
- }
- const cLData = { id: sortData[curRow].id };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
- const newCurCol = curCol + 1;
- needColAdd = true;
- colSetting = info.sheet.zh_setting.cols[newCurCol];
- }
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue;
- if (colSetting.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
- : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
- } else {
- orgValue = sortData[curRow][colSetting.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if(colSetting.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(getPasteHint(msg, hintRow));
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- cLData.camount_expr = exprQuantity.expr;
- sortData[curRow].camount_expr = exprQuantity.expr;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- if (colSetting.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- }
- if (colSetting.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
- bPaste = false;
- continue;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
- if (validText < minLimit) {
- toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
- bPaste = false;
- continue;
- }
- }
- }
- }
- let unitdecimal = validText;
- cLData[colSetting.field] = validText;
- sortData[curRow][colSetting.field] = validText;
- cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- changeSpreadObj.reloadRow(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
- changeList = result;
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }, function () {
- changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- changeSpreadObj.buttonClicked = function(e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- if (!select || !select.id) {
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
- return;
- }
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
- cInfo.is_valuation = select.is_valuation;
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- changeSpreadObj.reloadRow(info.sheet, info.row);
- if (select.children && select.children.length === 1) {
- const child = select.children[0];
- child[col.field] = select.is_valuation;
- changeSpreadObj.refreshXmjData();
- }
- }, function () {
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- cInfo.is_valuation = select.is_valuation;
- changeSpreadObj.reloadRow(info.sheet, info.row);
- });
- }
- }
- };
- changeSpreadObj.valueChanged = function(e, info) {
- // 防止ctrl+z撤销数据
- changeSpreadObj.reloadRow(info.sheet, info.row);
- };
- changeSpreadObj.setAllValuation = function (is_valuation) {
- if (changeList.length === 0) {
- toastr.warning('暂无清单无法设置清单计价');
- return;
- }
- const needChangeList = _.filter(changeList, { is_valuation: is_valuation ? 0 : 1 });
- if (needChangeList.length === 0) {
- toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
- return;
- }
- const realNeedChangeList = [];
- for (const nc of needChangeList) {
- if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
- realNeedChangeList.push(nc.id);
- }
- }
- if (realNeedChangeList.length === 0) {
- toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
- return;
- }
- postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
- changeList = result;
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- });
- };
- changeSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_data[iRow];
- if (!node || !node.id) continue;
- const cInfo = _.find(changeList, { id: node.id });
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'camount' || col.field === 'oamount2') {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field === 'camount') {
- node.camount_expr = '';
- node.spamount = null;
- cInfo.camount_expr = '';
- cInfo.spamount = null;
- }
- delete cInfo.waitingLoading;
- bDel = true;
- }
- }
- if (bDel) datas.push(cInfo);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
- changeList = result;
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }, function () {
- changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- changeSpreadObj.upMove = function () {
- const data = {
- type: 'changeOrder',
- postData: [],
- };
- const selection = changeSpreadSheet.getSelections();
- const row = selection[0].row, count = selection[0].rowCount;
- const first = changeSpreadSheet.zh_data[row];
- const firstRow = row;
- if (!first) {
- changeSpreadObj.refreshActn();
- return false;
- }
- const pre = changeSpreadSheet.zh_data[row - 1];
- const preUpdates = [];
- if (pre && pre.id) {
- preUpdates.push({ id: pre.id });
- } else if (pre && pre.children && pre.children.length > 0) {
- for (const item of pre.children) {
- preUpdates.push({ id: item.id });
- }
- }
- for (let iRow = 0; iRow < count; iRow++) {
- const posData = changeSpreadSheet.zh_data[iRow + row];
- if (posData) {
- for (const item of preUpdates) {
- item.order = posData.order;
- }
- if (posData.id) {
- data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
- } else if (posData && posData.children && posData.children.length > 0) {
- for (const item of posData.children) {
- data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
- }
- }
- }
- }
- data.postData.push(...preUpdates);
- console.log(data);
- if (data.postData.length > 0) {
- postData(window.location.pathname + '/save', data, function () {
- _.forEach(data.postData, function (item) {
- const cl = _.find(changeList, { id: item.id });
- cl.order = item.order;
- });
- changeList.sort(function (a, b) {
- return a.order - b.order
- });
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- const sel = selection[0];
- if (sel) {
- changeSpreadSheet.setSelection(row - 1, sel.col, sel.rowCount, sel.colCount);
- changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
- SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
- }
- changeSpreadObj.reloadSheet(newChangeList);
- });
- }
- };
- changeSpreadObj.downMove = function () {
- const data = {
- type: 'changeOrder',
- postData: [],
- };
- const selection = changeSpreadSheet.getSelections();
- const row = selection[0].row, count = selection[0].rowCount;
- const first = changeSpreadSheet.zh_data[row];
- if (!first) {
- changeSpreadObj.refreshActn();
- return false;
- }
- const next = changeSpreadSheet.zh_data[row + count];
- const nextUpdates = [];
- if (next && next.id) {
- nextUpdates.push({ id: next.id });
- } else if (next && next.children && next.children.length > 0) {
- for (const item of next.children) {
- nextUpdates.push({ id: item.id });
- }
- }
- for (let iRow = count - 1; iRow >= 0; iRow--) {
- const posData = changeSpreadSheet.zh_data[iRow + row];
- if (posData) {
- for (const item of nextUpdates) {
- item.order = posData.order;
- }
- if (posData.id) {
- data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
- } else if (posData && posData.children && posData.children.length > 0) {
- for (const item of posData.children) {
- data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
- }
- }
- }
- }
- data.postData.push(...nextUpdates);
- console.log(data);
- if (data.postData.length > 0) {
- postData(window.location.pathname + '/save', data, function () {
- _.forEach(data.postData, function (item) {
- const cl = _.find(changeList, { id: item.id });
- cl.order = item.order;
- });
- changeList.sort(function (a, b) {
- return a.order - b.order
- });
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- const sel = selection[0];
- if (sel) {
- changeSpreadSheet.setSelection(row + 1, sel.col, sel.rowCount, sel.colCount);
- changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
- SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
- }
- changeSpreadObj.reloadSheet(newChangeList);
- });
- }
- };
- // 表达式判断
- $('#camount-expr').change(function () {
- if (this.readOnly) return;
- let validText = $(this).val();
- const sel = changeSpreadSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const col = changeSpreadSheet.zh_setting.cols[sel.col];
- if (row === -1 || !(col && col.field === 'camount')) return;
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (!select || !select.id) return;
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) return;
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- const orgExprValue = _.clone(select.camount_expr);
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- select.camount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = select.camount_expr;
- cInfo.camount = validText;
- // console.log(select);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- changeSpreadObj.reloadRow(changeSpreadSheet, row);
- changeSpreadObj.calcOneSum(select);
- changeSpreadObj.countSum();
- changeSpreadObj.refreshActn();
- if (SpreadJsObj.getSelectObject(changeSpreadSheet) === select) {
- if (select.children && select.children.length === 1) {
- changeSpreadObj.refreshXmjData();
- }
- }
- changeSpreadObj.loadExprToInput(changeSpreadSheet);
- }, function () {
- select.camount = orgValue;
- select.camount_expr = orgExprValue;
- select.spamount = orgValue;
- cInfo.camount = orgValue;
- cInfo.camount_expr = orgExprValue;
- cInfo.spamount = orgValue;
- changeSpreadObj.reloadRow(changeSpreadSheet, row);
- });
- });
- $('#add-white-btn').click(changeSpreadObj.add);
- $('#up-move').click(changeSpreadObj.upMove);
- $('#down-move').click(changeSpreadObj.downMove);
- changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
- changeSpread.bind(spreadNS.Events.EditStarting, changeSpreadObj.editStarting);
- changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
- changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
- changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
- SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
- // 计量单元修改
- xmjSpreadObj.del = function () {
- const selection = xmjSheet.getSelections();
- const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- const count = sel.rowCount;
- if (readOnly || row === -1 || row + count > xmjSheet.zh_data.length) {
- return false;
- }
- const delList = [];
- let lastSelect = null;
- for (let r = 0; r < count; r++) {
- const select = xmjSheet.zh_data[row + r];
- if(!select || _.find(changeUsedData, { cbid: select.id })) {
- toastr.error('已调用的变更清单不能删除');
- return false;
- }
- if (checkIsSettle(select)) {
- toastr.error('已结算的变更清单不能删除');
- return false;
- }
- if (r === count - 1 && xmjSheet.zh_data.length === count && changeOrder) {
- lastSelect = select;
- }
- delList.push(select.id);
- }
- if (delList.length) {
- postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null, delLength: 1}, function (result) {
- xmjSheet.deleteRows(row, count);
- xmjSheet.zh_data.splice(row, count);
- // 同步删除changeList值
- _.forEach(delList, function (id) {
- _.remove(changeList, { id: id });
- });
- const billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, billsNode);
- let allDel = false;
- // 判断是移除还是更新数量和金额
- if (xmjSheet.zh_data.length === 0) {
- changeSpreadSheet.deleteRows(billIndex, 1);
- changeSpreadSheet.zh_data.splice(billIndex, 1);
- allDel = true;
- } else {
- billsNode.children = xmjSheet.zh_data;
- if (billsNode.children.length === 1) {
- billsNode.id = billsNode.children[0].id;
- billsNode.bwmx = billsNode.children[0].bwmx || billsNode.children[0].xmj_jldy;
- billsNode.detail = billsNode.children[0].detail;
- billsNode.delimit = billsNode.children[0].delimit;
- }
- changeSpreadObj.calcOneSum(billsNode);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- }
- changeSpreadObj.countSum();
- if (allDel) {
- changeSpreadSheet.setSelection(0, 0, 1, 1);
- changeSpreadObj.refreshXmjData();
- changeSpreadObj.refreshActn();
- }
- });
- }
- };
- xmjSpreadObj.editStarting = function (e, info) {
- xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const col = info.sheet.zh_setting.cols[info.col];
- const select = SpreadJsObj.getSelectObject(info.sheet);
- if (col.field === 'camount') {
- if (select.camount_expr && select.camount_expr !== '') {
- info.sheet.getCell(info.row, info.col).text(select.camount_expr);
- }
- }
- };
- xmjSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- console.log(info.sheet.zh_data);
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- return;
- }
- let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- let orgValue;
- if (col.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- } else {
- orgValue = select[col.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const node = xmjSpreadObj.billsNode;
- if (!node) {
- toastr.error('数据错误,请选择清单节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if(col.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: select.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = exprQuantity.expr;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- if (col.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('计量上限默认值只能输入0-100之间的整数');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: select.id });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
- if (validText < minLimit) {
- toastr.error('计量上限值至少大于等于 ' + minLimit);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- console.log(cInfo);
- delete cInfo.waitingLoading;
- const children = info.sheet.zh_data;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = children;
- if (node.children && node.children.length === 1) {
- node[col.field] = validText;
- if (col.field === 'camount') {
- node.spamount = select.spamount;
- node.camount_expr = select.camount_expr;
- }
- }
- xmjSpreadObj.loadExprToInput();
- changeSpreadObj.calcOneSum(node);
- console.log(node);
- if (SpreadJsObj.getSelectObject(changeSpreadSheet) !== node) {
- SpreadJsObj.reLoadRowData(changeSpreadSheet, billIndex);
- } else {
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- }
- changeSpreadObj.countSum();
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if(col.field === 'camount') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- };
- xmjSpreadObj.clipboardPasted = function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- if (range.row + range.rowCount > sortData.length) {
- toastMessageUniq(hint.cellError);
- // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
- xmjSpreadObj.loadCurXmjData();
- return;
- }
- if (sortData.length > 0 && range.col + range.colCount > 12) {
- toastMessageUniq(hint.cellError);
- xmjSpreadObj.loadCurXmjData();
- return;
- }
- if (!info.sheet.zh_setting) {
- xmjSpreadObj.loadCurXmjData();
- return;
- }
- const data = [];
- // const rowData = [];
- let needCopyIgnore = !$('#customCheck1').is(':checked');
- let needColAdd = false;
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
- const cLData = { id: sortData[curRow].id };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
- const newCurCol = curCol + 1;
- needColAdd = true;
- colSetting = info.sheet.zh_setting.cols[newCurCol];
- }
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue;
- if (colSetting.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
- : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
- } else {
- orgValue = sortData[curRow][colSetting.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if(colSetting.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(getPasteHint(msg, hintRow));
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- cLData.camount_expr = exprQuantity.expr;
- sortData[curRow].camount_expr = exprQuantity.expr;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- if (colSetting.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- }
- if (colSetting.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('项目节第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
- bPaste = false;
- continue;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
- if (validText < minLimit) {
- toastr.error('项目节第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
- bPaste = false;
- continue;
- }
- }
- }
- }
- let unitdecimal = validText;
- cLData[colSetting.field] = validText;
- sortData[curRow][colSetting.field] = validText;
- cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
- changeList = result;
- const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = info.sheet.zh_data;
- if (node.children && node.children.length === 1) {
- for (const col in data[0]) {
- node[col] = data[0][col];
- }
- }
- changeSpreadObj.calcOneSum(node);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- changeSpreadObj.countSum();
- xmjSpreadObj.loadCurXmjData();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- xmjSpreadObj.buttonClicked = function(e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
- return;
- }
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
- cInfo.is_valuation = select.is_valuation;
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = info.sheet.zh_data;
- changeSpreadObj.calcOneSum(node);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- }, function () {
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- cInfo.is_valuation = select.is_valuation;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- }
- };
- xmjSpreadObj.valueChanged = function(e, info) {
- // 防止ctrl+z撤销数据
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- };
- xmjSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_data[iRow];
- const cInfo = _.find(changeList, { id: node.id });
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'camount' || col.field === 'oamount2') {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field === 'camount') {
- node.camount_expr = '';
- node.spamount = null;
- cInfo.camount_expr = '';
- cInfo.spamount = null;
- }
- delete cInfo.waitingLoading;
- bDel = true;
- }
- }
- if (bDel) datas.push(cInfo);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
- changeList = result;
- const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = xmjSheet.zh_data;
- changeSpreadObj.calcOneSum(node);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- changeSpreadObj.countSum();
- xmjSpreadObj.loadCurXmjData();
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- xmjSpreadObj.setAllValuation = function (is_valuation) {
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (!select) {
- toastr.error('未选中清单');
- return;
- }
- if (!select.children || select.children.length === 0) {
- toastr.warning('暂无清单无法设置清单计价');
- return;
- }
- const needChangeList = _.filter(select.children, { is_valuation: is_valuation ? 0 : 1 });
- if (needChangeList.length === 0) {
- toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
- return;
- }
- const realNeedChangeList = [];
- for (const nc of needChangeList) {
- if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
- realNeedChangeList.push(nc.id);
- }
- }
- if (realNeedChangeList.length === 0) {
- toastr.warning('全部已设置清单'+ (is_valuation ? '' : '不') +'计价');
- return;
- }
- postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
- changeList = result;
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- });
- };
- // 表达式判断
- $('#xmj-camount-expr').change(function () {
- if (this.readOnly) return;
- let validText = $(this).val();
- const sel = xmjSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const col = xmjSheet.zh_setting.cols[sel.col];
- if (row === -1 || !(col && col.field === 'camount')) return;
- const select = SpreadJsObj.getSelectObject(xmjSheet);
- if (!select) return;
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) return;
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- const orgExprValue = _.clone(select.camount_expr);
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- select.camount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = select.camount_expr;
- cInfo.camount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- // console.log(select);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(xmjSheet, row);
- const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = xmjSheet.zh_data;
- changeSpreadObj.calcOneSum(node);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- changeSpreadObj.countSum();
- xmjSpreadObj.loadExprToInput(xmjSheet);
- }, function () {
- select.camount = orgValue;
- select.camount_expr = orgExprValue;
- select.spamount = orgValue;
- cInfo.camount = orgValue;
- cInfo.camount_expr = orgExprValue;
- cInfo.spamount = orgValue;
- SpreadJsObj.reLoadRowData(posSheet, row);
- });
- });
- xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
- xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
- xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
- xmjSpread.bind(spreadNS.Events.ValueChanged, xmjSpreadObj.valueChanged);
- xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked);
- SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
- let batchInsertObj;
- $.contextMenu.types.batchInsert = function (item, opt, root) {
- const self = this;
- if ($.isFunction(item.icon)) {
- item._icon = item.icon.call(this, this, $t, key, item);
- } else {
- if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
- // to enable font awesome
- item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
- } else {
- item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
- }
- }
- this.addClass(item._icon);
- const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
- .appendTo(this);
- const $input = $obj.find('input');
- const event = () => {
- if (self.hasClass('context-menu-disabled')) return;
- item.batchInsert($input[0], root);
- };
- $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
- $input.click((e) => {e.stopPropagation();})
- .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
- .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
- };
- // 右键菜单
- $.contextMenu({
- selector: '#change-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
- // console.log(e, target);
- // const range = SpreadJsObj.getTargetSelection(changeSpreadSheet, target);
- // console.log(range);
- let ts = getLocalCache(ckChangeSpread);
- if (ts !== '') {
- ts = JSON.parse(ts);
- if (ts === undefined || ts === null) return;
- if (ts.sel) {
- changeSpreadSheet.getRange(ts.sel.row, -1, 1, -1).backColor('#fff');
- }
- }
- changeSpreadObj.refreshXmjData();
- changeSpreadObj.refreshActn();
- return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
- },
- items: {
- 'createList': {
- name: '添加台账清单',
- icon: 'fa-sign-in',
- visible: function () {
- return changeOrder === 0;
- },
- callback: function (key, opt) {
- // $('#addlist').modal('show');
- $('#set-site-btn').click();
- },
- },
- 'createAdd': {
- name: '添加空白清单',
- icon: 'fa-sign-in',
- visible: function () {
- return changeOrder === 0 && openChangeWhiteList;
- },
- callback: function (key, opt) {
- changeSpreadObj.add();
- },
- },
- 'batchInsert': {
- name: '批量添加空白清单',
- type: 'batchInsert',
- value: '2',
- icon: 'fa-sign-in',
- visible: function () {
- return changeOrder === 0 && openChangeWhiteList;
- },
- batchInsert: function (obj, root) {
- if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
- obj.value = obj.max;
- toastr.warning('批量添加不可多于' + obj.max);
- } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
- obj.value = obj.min;
- toastr.warning('批量添加不可少于' + obj.min);
- } else {
- // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
- changeSpreadObj.batchAdd(obj.value);
- root.$menu.trigger('contextmenu:hide');
- }
- },
- },
- 'createList1': {
- name: '插入台账清单',
- icon: 'fa-sign-in',
- visible: function () {
- return changeOrder === 1;
- },
- // disabled: function (key, opt) {
- // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- // const sel = changeSpreadSheet.getSelections()[0];
- // changeSpreadObj.resetXmjSpread(select);
- // // console.log(select, sel);
- // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
- // return false;
- // } else {
- // return true;
- // }
- // },
- callback: function (key, opt) {
- // $('#addlist').modal('show');
- $('#set-site-btn').click();
- },
- },
- 'createAdd1': {
- name: '插入空白清单',
- icon: 'fa-sign-in',
- visible: function () {
- return changeOrder === 1 && openChangeWhiteList;
- },
- // disabled: function (key, opt) {
- // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- // const sel = changeSpreadSheet.getSelections()[0];
- // changeSpreadObj.resetXmjSpread(select);
- // // console.log(select, sel);
- // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
- // return false;
- // } else {
- // return true;
- // }
- // },
- callback: function (key, opt) {
- changeSpreadObj.add();
- },
- },
- 'batchInsert1': {
- name: '批量插入空白清单',
- type: 'batchInsert',
- value: '2',
- icon: 'fa-sign-in',
- visible: function () {
- return changeOrder === 1 && openChangeWhiteList;
- },
- // disabled: function (key, opt) {
- // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- // const sel = changeSpreadSheet.getSelections()[0];
- // changeSpreadObj.resetXmjSpread(select);
- // // console.log(select, sel);
- // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
- // return false;
- // } else {
- // return true;
- // }
- // },
- batchInsert: function (obj, root) {
- if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
- obj.value = obj.max;
- toastr.warning('批量插入不可多于' + obj.max);
- } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
- obj.value = obj.min;
- toastr.warning('批量插入不可少于' + obj.min);
- } else {
- // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
- changeSpreadObj.batchAdd(obj.value);
- root.$menu.trigger('contextmenu:hide');
- }
- },
- },
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- changeSpreadObj.del();
- },
- disabled: function (key, opt) {
- const selection = changeSpreadSheet.getSelections();
- const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- if (readOnly || row === -1 || sel.row + sel.rowCount > changeSpreadSheet.zh_data.length) {
- return true;
- }
- const first = changeSpreadSheet.zh_data[row];
- let valid = true;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = changeSpreadSheet.zh_data[sel.row + r];
- if (!rNode || !rNode.id) {
- valid = false;
- break;
- }
- if (_.find(changeUsedData, { cbid: rNode.id }) || checkIsSettle(rNode)) {
- valid = false;
- break;
- }
- }
- }
- return !(first && first.id && !_.find(changeUsedData, { cbid: first.id }) && !checkIsSettle(first) && valid);
- }
- },
- sprEdit: '----',
- 'allNotValuation': {
- name: '设置全部清单不计价',
- icon: 'fa-magic',
- callback: function (key, opt) {
- changeSpreadObj.setAllValuation(0);
- },
- },
- 'allValuation': {
- name: '设置全部清单计价',
- icon: 'fa-magic',
- callback: function (key, opt) {
- changeSpreadObj.setAllValuation(1);
- },
- },
- }
- });
- // 右键菜单
- $.contextMenu({
- selector: '#xmj-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, xmjSpread);
- return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
- },
- items: {
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- xmjSpreadObj.del();
- },
- disabled: function (key, opt) {
- const selection = xmjSheet.getSelections();
- const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- if (readOnly || row === -1 || sel.row + sel.rowCount > xmjSheet.zh_data.length) {
- return true;
- }
- let isUsed = false;
- for (let r = 0; r < sel.rowCount; r++) {
- const select = xmjSheet.zh_data[row + r];
- if(!select || _.find(changeUsedData, { cbid: select.id })) {
- isUsed = true;
- }
- if (checkIsSettle(select)) {
- isUsed = true;
- }
- }
- return isUsed;
- }
- },
- sprEdit: '----',
- 'allNotValuation': {
- name: '设置全部不计价',
- icon: 'fa-magic',
- callback: function (key, opt) {
- xmjSpreadObj.setAllValuation(0);
- },
- disabled: function (key, opt) {
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (select.children && select.children.length > 0) {
- return false;
- } else {
- return true;
- }
- }
- },
- 'allValuation': {
- name: '设置全部计价',
- icon: 'fa-magic',
- callback: function (key, opt) {
- xmjSpreadObj.setAllValuation(1);
- },
- disabled: function (key, opt) {
- const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (select.children && select.children.length > 0) {
- return false;
- } else {
- return true;
- }
- }
- },
- }
- });
- }
- const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
- const ledgerSheet = ledgerSpread.getActiveSheet();
- const ledgerSpreadSetting = {
- cols: [
- {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', getValue: 'getValue.is_valuation', readOnly: 'readOnly.isValuation'},
- {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree' },
- {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
- {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
- {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
- {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: 'readOnly.isEdit2'},
- {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', visible: openChangeState},
- {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
- {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
- {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- // readOnly: true,
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if ((!data.clid && data.id && (_.findIndex(changeLedgerList, { id: data.id }) !== -1 || _.findIndex(changePosList, { lid: data.id }) !== -1))
- || (data.clid && data.gcl_id && _.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1)) {
- return '#dc3545';
- }
- if (data.lid == 0) {
- return '#007bff';
- }
- if (data.clid && data.gcl_id) {
- return '#28a745';
- }
- if (data.clid && !data.gcl_id && data.lid != 0) {
- return '#ffc107';
- }
- if(data.lid != 0) return;
- return '#007bff';
- }
- },
- },
- ],
- // localCache: {
- // key: 'changes-ledger-spread',
- // colWidth: true,
- // }
- };
- if (readOnly) {
- ledgerSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
- ledgerSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
- for (const aid of aidList) {
- // const userinfo = _.find(auditList2, { 'uid': aid });
- const audit = _.find(auditors2, function(item){
- return _.findIndex(item, { audit_order: aid }) !== -1;
- });
- const newColcount = {
- title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
- colSpan: '2|1', rowSpan: '1|1',
- field: 'audit_amount_' + aid,
- hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
- };
- const newColTp = {
- title: '|金额',
- colSpan: '|1', rowSpan: '|1',
- field: 'sa_tp_' + aid,
- hAlign: 2, width: 80, type: 'Number',
- };
- ledgerSpreadSetting.cols.push(newColcount);
- ledgerSpreadSetting.cols.push(newColTp);
- }
- }
- ledgerSpreadSetting.cols.push({title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'changed_amount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'});
- ledgerSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
- const ledgerCol = {
- getValue: {
- is_valuation: function (data) {
- return data.is_valuation === 1;
- },
- unit_price: function(data) {
- return ZhCalc.round(data.unit_price, unitPriceUnit);
- },
- oa_tp: function (data) {
- return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit) : data.oa_tp;
- },
- ca_tp: function (data) {
- return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit) : data.ca_tp;
- },
- oamount2: function (data) {
- return ZhCalc.round(data.oamount2, findDecimal(data.unit));
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- samount: function (data) {
- return ZhCalc.round(data.samount, findDecimal(data.unit));
- },
- sa_tp: function (data) {
- return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit) : data.sa_tp;
- },
- changed_amount: function (data) {
- return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
- },
- changed_tp: function (data) {
- return data.clid ? ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
- ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit)) : data.changed_tp;
- },
- },
- readOnly: {
- isEdit: function (data) {
- return !(!readOnly && data.clid);
- },
- isEdit2: function (data) {
- return !(!readOnly && data.lid == 0 && data.clid);
- },
- isValuation: function (data) {
- return !(!readOnly && data.clid && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
- },
- isSettle: function (data) {
- return !((!readOnly || shenpiPower) && data.clid && !checkIsSettle(data));
- },
- isSettle2: function (data) {
- return !(!readOnly && data.clid && !checkIsSettle(data));
- }
- },
- };
- sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
- SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
- SpreadJsObj.initSheet(ledgerSheet, ledgerSpreadSetting);
- // 初始化 节点树结构
- const treeSetting = {
- id: 'ledger_id',
- pid: 'ledger_pid',
- order: 'order',
- level: 'level',
- rootId: -1,
- keys: ['id', 'tender_id', 'ledger_id'],
- calcFields: ['oa_tp', 'ca_tp', 'sa_tp', 'changed_tp', 'total_price'],
- autoExpand: 3,
- markExpandKey: 'change-bills-expand',
- markExpandSubKey: window.location.pathname.split('/')[2],
- };
- if (readOnly) {
- for (const aid of aidList) {
- treeSetting.calcFields.push('sa_tp_' + aid);
- }
- }
- treeSetting.calcFun = function (node) {
- if (node && node.b_code) {
- const posData = pos.getLedgerPos(node.id) || [];
- if (!node.clid && posData.length > 0) {
- let is_valuation = 1;
- let oamount2 = 0;
- let camount = 0;
- let samount = 0;
- let spamount = 0;
- if (readOnly) {
- for (const aid of aidList) {
- let audit_amount = 0;
- for (const np of posData) {
- audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(np['audit_amount_' + aid], findDecimal(node.unit)));
- }
- if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
- node['audit_amount_' + aid] = audit_amount;
- node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
- }
- }
- }
- for (const np of posData) {
- oamount2 = ZhCalc.add(oamount2, ZhCalc.round(np.oamount2, findDecimal(node.unit)));
- camount = ZhCalc.add(camount, ZhCalc.round(np.camount, findDecimal(node.unit)));
- samount = ZhCalc.add(samount, ZhCalc.round(np.samount, findDecimal(node.unit)));
- spamount = ZhCalc.add(spamount, ZhCalc.round(np.spamount, findDecimal(node.unit)));
- if (np.is_valuation === 0) is_valuation = 0;
- }
- if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
- node.oamount2 = oamount2;
- node.camount = camount;
- node.samount = samount;
- node.spamount = spamount;
- node.change_amount = ZhCalc.add(oamount2, camount);
- node.oa_tp = ZhCalc.round(ZhCalc.mul(oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.ca_tp = ZhCalc.round(ZhCalc.mul(camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.sa_tp = ZhCalc.round(ZhCalc.mul(samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- const spa_tp = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
- }
- node.is_valuation = is_valuation;
- } else if (node.clid) {
- // node.oamount2 = ZhCalc.round(node.oamount2, findDecimal(node.unit));
- // node.camount = ZhCalc.round(node.camount, findDecimal(node.unit));
- // node.change_amount = ZhCalc.add(node.oamount2, node.camount);
- node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
- if (readOnly) {
- for (const aid of aidList) {
- node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
- }
- }
- }
- }
- };
- const ledgerTree = createNewPathTree('revise', treeSetting);
- const ledgerTreeSpreadObj = {
- loadExprToInput: function () {
- const sel = ledgerSheet.getSelections()[0];
- if (!sel) return;
- const col = ledgerSheet.zh_setting.cols[sel.col];
- const data = SpreadJsObj.getSelectObject(ledgerSheet);
- if (col && col.field === 'camount' && data && data.clid) {
- if (!readOnly) {
- $('#ledger-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
- } else {
- $('#ledger-camount-expr').attr('readonly', true).val(data.camount_expr ? data.camount_expr : data.camount);
- }
- } else {
- $('#ledger-camount-expr').attr('readonly', true).val('');
- }
- },
- showHideAudit: function (show = false) {
- if (shenpiPower) {
- show = true;
- }
- if (readOnly) {
- const count = ledgerSpreadSetting.cols.length;
- for (let i = startLimit + 5; i < count - 2; i++) {
- ledgerSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
- }
- ledgerSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
- ledgerSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
- }
- },
- /**
- *
- * @param sheet
- * @param data
- */
- refreshTree: function (sheet, data) {
- SpreadJsObj.massOperationSheet(sheet, function () {
- const tree = sheet.zh_tree;
- // 处理删除
- if (data.delete) {
- data.delete.sort(function (a, b) {
- return b.deleteIndex - a.deleteIndex;
- });
- for (const d of data.delete) {
- sheet.deleteRows(d.deleteIndex, 1);
- }
- }
- // 处理新增
- if (data.create) {
- const newNodes = data.create;
- if (newNodes) {
- newNodes.sort(function (a, b) {
- return a.index - b.index;
- });
- for (const node of newNodes) {
- sheet.addRows(node.index, 1);
- SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
- }
- }
- }
- // 处理更新
- if (data.update) {
- const rows = [];
- for (const u of data.update) {
- rows.push(tree.nodes.indexOf(u));
- }
- SpreadJsObj.reLoadRowsData(sheet, rows);
- }
- // 处理展开
- if (data.expand) {
- const expanded = [];
- for (const e of data.expand) {
- if (expanded.indexOf(e) === -1) {
- const posterity = tree.getPosterity(e);
- for (const p of posterity) {
- sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
- expanded.push(p);
- }
- }
- }
- }
- });
- },
- topRowChanged: function (e, info) {
- SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
- },
- selectionChanged: function (e, info) {
- if (info.newSelections) {
- if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
- // ledgerTreeSpreadObj.refreshOperationValid(info.sheet);
- ledgerTreeSpreadObj.refreshPosData();
- }
- }
- ledgerTreeSpreadObj.loadExprToInput(info.sheet);
- },
- refreshPosData: function() {
- SpreadJsObj.resetTopAndSelect(posSheet);
- posSpreadObj.loadCurPosData();
- SpreadJsObj.saveTopAndSelect(ledgerSheet, ckBillsSpread);
- // posSearch.search($('#pos-keyword').val());
- },
- getDefaultSelectInfo: function (sheet) {
- const tree = sheet.zh_tree;
- if (!tree) return;
- const sel = sheet.getSelections()[0];
- const node = sheet.zh_tree.nodes[sel.row];
- if (!node) return;
- let count = 1;
- if (sel.rowCount > 1) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = sheet.zh_tree.nodes[sel.row + r];
- if (rNode.level > node.level) continue;
- if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
- toastr.warning('请选择同一节点下的节点,进行该操作');
- return;
- }
- count += 1;
- }
- }
- return [tree, node, count];
- },
- _checkExprValid(expr) {
- if (!expr) return [true, null];
- const param = [];
- let num = '', base = '';
- for (let i = 0, iLen = expr.length; i < iLen; i++) {
- if (/^[\d\.%]+/.test(expr[i])) {
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- num = num + expr[i];
- } else if (expr[i] === '(') {
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- param.push({type: 'left', value: '('});
- } else if (expr[i] === ')') {
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- param.push({type: 'right', value: ')'});
- } else if (/^[\+\-*\/]/.test(expr[i])) {
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- param.push({type: 'calc', value: expr[i]});
- } else {
- return [false, '输入的表达式含有非法字符: ' + expr[i]];
- }
- }
- if (num !== '') {
- param.push({type: 'num', value: num});
- num = '';
- }
- if (base !== '') {
- param.push({type: 'base', value: base});
- base = '';
- }
- if (param.length === 0) return true;
- if (param.length > 1) {
- if (param[0].value === '-' && param[1].type === 'num') {
- param[1].value = '-' + param[1].value;
- param.shift();
- }
- }
- const iLen = param.length;
- let iLeftCount = 0, iRightCount = 0;
- for (const [i, p] of param.entries()) {
- if (p.type === 'calc') {
- if (i === 0 || i === iLen - 1)
- return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
- }
- if (p.type === 'num') {
- num = p.value.replace('%', '');
- if (p.value.length - num.length > 1)
- return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
- num = _.toNumber(num);
- if (num === undefined || num === null || _.isNaN(num))
- return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
- if (i > 0) {
- if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
- return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
- } else if (param[i - 1].value === '/' && num === 0) {
- return [false, '输入的表达式非法:请勿除0'];
- }
- }
- }
- if (p.type === 'base') {
- if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
- return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
- }
- if (p.type === 'left') {
- iLeftCount += 1;
- if (i !== 0 && param[i-1].type !== 'calc')
- return [false, '输入的表达式非法:(前应有运算符'];
- }
- if (p.type === 'right') {
- iRightCount += 1;
- if (i !== iLen - 1 && param[i+1].type !== 'calc')
- return [false, '输入的表达式非法:)后应有运算符'];
- if (iRightCount > iLeftCount)
- return [false, '输入的表达式非法:")"前无对应的"("'];
- }
- }
- if (iLeftCount > iRightCount)
- return [false, '输入的表达式非法:"("后无对应的")"'];
- return [true, ''];
- },
- _checkExpr: function (text, data) {
- if (text) {
- const num = _.toNumber(text);
- if (num) {
- data.quantity = num;
- data.expr = '';
- } else {
- const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
- const [valid, msg] = this._checkExprValid(expr);
- if (!valid) return [valid, msg];
- data.expr = expr;
- data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
- // const ce = new CalcEvalMin();
- // data.quantity = ce.eval(expr);
- // console.log(data.quantity);
- }
- } else {
- data.quantity = 0;
- data.expr = '';
- }
- return [true, ''];
- },
- }
- ledgerSpread.bind(spreadNS.Events.SelectionChanged, ledgerTreeSpreadObj.selectionChanged);
- ledgerSpread.bind(spreadNS.Events.topRowChanged, ledgerTreeSpreadObj.topRowChanged);
- // 初始化 计量单元
- const pos = new PosData({ id: 'id', ledgerId: 'lid' });
- const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
- const posSheet = posSpread.getActiveSheet();
- const posSpreadSetting = {
- cols: [
- {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
- {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true},
- {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
- {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
- {title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
- {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
- ],
- emptyRows: 0,
- headRows: 2,
- headRowHeight: [25, 25],
- defaultRowHeight: 21,
- headerFont: '12px 微软雅黑',
- font: '12px 微软雅黑',
- rowHeader:[
- {
- rowHeaderType: 'circle',
- setting: {
- size: 5,
- indent: 16,
- getColor: function (index, data) {
- if (!data) return;
- if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
- return '#dc3545';
- }
- if(data.lid != 0) return;
- return '#007bff';
- }
- },
- },
- ],
- };
- if (readOnly) {
- posSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
- for (const aid of aidList) {
- // const userinfo = _.find(auditList2, { 'uid': aid });
- const audit = _.find(auditors2, function(item){
- return _.findIndex(item, { audit_order: aid }) !== -1;
- });
- const newColcount = {
- title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
- colSpan: '1|1', rowSpan: '|1',
- field: 'audit_amount_' + aid,
- hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
- };
- posSpreadSetting.cols.push(newColcount);
- }
- }
- posSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
- const posCol = {
- getValue: {
- oamount2: function (data) {
- return ZhCalc.round(data.oamount2, findDecimal(data.unit));
- },
- camount: function (data) {
- return ZhCalc.round(data.camount, findDecimal(data.unit));
- },
- samount: function (data) {
- return ZhCalc.round(data.samount, findDecimal(data.unit));
- },
- changed_amount: function (data) {
- return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
- },
- },
- readOnly: {
- isEdit: function (data) {
- return readOnly;
- },
- isValuation: function (data) {
- return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
- },
- isSettle: function (data) {
- return !((!readOnly || shenpiPower) && !checkIsSettle(data));
- },
- isSettle2: function (data) {
- return !(!readOnly && !checkIsSettle(data));
- }
- },
- }
- sjsSettingObj.setGridSelectStyle(posSpreadSetting);
- SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
- SpreadJsObj.initSheet(posSheet, posSpreadSetting);
- // 计量单元 相关方法&绑定spreadjs事件
- const posSpreadObj = {
- loadExprToInput: function () {
- const sel = posSheet.getSelections()[0];
- if (!sel) return;
- const col = posSheet.zh_setting.cols[sel.col];
- const data = SpreadJsObj.getSelectObject(posSheet);
- if (col && col.field === 'camount' && data) {
- if (readOnly) {
- $('#pos-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
- } else {
- $('#pos-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
- }
- } else {
- $('#pos-camount-expr').attr('readonly', true).val('');
- }
- },
- /**
- * 加载计量单元 根据当前台账选择节点
- */
- loadCurPosData: function () {
- const node = SpreadJsObj.getSelectObject(ledgerSheet);
- if (node) {
- const posData = pos.getLedgerPos(node.id) || [];
- console.log(posData);
- SpreadJsObj.loadSheetData(posSheet, 'data', posData);
- } else {
- SpreadJsObj.loadSheetData(posSheet, 'data', []);
- }
- posSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
- SpreadJsObj.resetTopAndSelect(posSheet);
- posSpreadObj.loadExprToInput();
- },
- selectionChanged: function (e, info) {
- posSpreadObj.loadExprToInput();
- },
- showHideAudit: function (show = false) {
- if (shenpiPower) {
- show = true;
- }
- if (readOnly) {
- const posStartLimit = 4;
- const count = posSpreadSetting.cols.length;
- for (let i = posStartLimit + 2; i < count - 1; i++) {
- posSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
- }
- posSheet.setColumnVisible(posStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
- }
- },
- }
- posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
- if (!readOnly) {
- // 台账修改
- ledgerTreeSpreadObj.del = function () {
- const self = this;
- const [tree, node, count] = this.getDefaultSelectInfo(ledgerSheet);
- if (!tree || !node || !count) return;
- const delList = [];
- let lastSelect = null;
- let hadTaiZhang = false;
- const selects = [];
- const parent = tree.getParent(node);
- const children = parent ? parent.children : tree.children;
- const index = children.indexOf(node);
- for (let r = 0; r < count; r++) {
- const select = children[r+index];
- if (!select || _.find(changeUsedData, { cbid: select.clid })) {
- toastr.error('已调用的变更清单不能删除');
- return false;
- }
- if (checkIsSettle(select)) {
- toastr.error('已结算的变更清单不能删除');
- return false;
- }
- if (r === count - 1 && changeOrder) {
- lastSelect = select;
- }
- if (select.lid != 0) {
- hadTaiZhang = true;
- }
- delList.push(select.clid);
- selects.push(select);
- }
- if (delList.length) {
- postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
- const loadResult = {
- delete: selects,
- }
- // 判断父节点是否也要移除
- if (children.length === count) {
- loadResult.delete.push(parent);
- const parentNodes = _.reverse(ledgerTree.getAllParents(parent));
- for (const node of parentNodes) {
- if (node.children && node.children.length === 1) {
- loadResult.delete.push(node);
- } else {
- break;
- }
- }
- }
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- ledgerSheet.setSelection(0, 0, 1, 1);
- ledgerTreeSpreadObj.refreshPosData();
- });
- }
- };
- ledgerTreeSpreadObj.editStarting = function (e, info) {
- const select = SpreadJsObj.getSelectObject(ledgerSheet);
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'camount') {
- if (select.camount_expr && select.camount_expr !== '') {
- info.sheet.getCell(info.row, info.col).text(select.camount_expr);
- }
- }
- };
- ledgerTreeSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- return;
- }
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const select = sortData[info.row];
- if (!select || !select.clid) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- let orgValue;
- if (col.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- } else {
- orgValue = select[col.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if(col.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: select.clid });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = exprQuantity.expr;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- if (col.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('计量上限默认值只能输入0-100之间的整数');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: select.clid });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
- if (validText < minLimit) {
- toastr.error('计量上限值至少大于等于 ' + minLimit);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- }
- if (col.field === 'unit') {
- select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
- select.oamount2 = ZhCalc.round(select.oamount2, findDecimal(validText)) || 0;
- cInfo.camount = select.camount;
- cInfo.oamount2 = select.oamount2;
- }
- if (col.field === 'b_code') {
- cInfo.code = validText;
- } else {
- cInfo[col.field] = validText;
- }
- select[col.field] = validText;
- console.log(cInfo);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- const loadResult = {
- update: [select],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- ledgerTreeSpreadObj.loadExprToInput();
- }, function () {
- select[col.field] = orgValue;
- if (col.field === 'b_code') {
- cInfo.code = orgValue;
- } else {
- cInfo[col.field] = orgValue;
- }
- if(col.field === 'camount') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- };
- ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
- const tree = info.sheet.zh_tree;
- if (!tree) { return; }
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_tree.nodes;
- const selects = [];
- const data = [];
- let needCopyIgnore = !$('#customCheck1').is(':checked');
- let needColAdd = false;
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- const node = sortData[curRow];
- if (!node) {
- continue;
- }
- const cLData = { id: sortData[curRow].clid };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if ((needColAdd && curCol > 6) || (needCopyIgnore && curCol === 6)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
- const newCurCol = curCol + 1;
- needColAdd = true;
- colSetting = info.sheet.zh_setting.cols[newCurCol];
- }
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue;
- if (colSetting.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
- : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
- } else {
- orgValue = sortData[curRow][colSetting.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if(colSetting.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(getPasteHint(msg, hintRow));
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- cLData.camount_expr = exprQuantity.expr;
- sortData[curRow].camount_expr = exprQuantity.expr;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- if (colSetting.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- }
- if (colSetting.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
- bPaste = false;
- continue;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
- if (validText < minLimit) {
- toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
- bPaste = false;
- continue;
- }
- }
- }
- }
- let unitdecimal = validText;
- if (colSetting.field === 'unit') {
- //粘贴内容要为下拉列表里所有的单位,不然为空
- if (changeUnits.indexOf(validText) === -1) {
- unitdecimal = '';
- }
- cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- cLData.oamount2 = ZhCalc.round(sortData[curRow].oamount2, findDecimal(unitdecimal)) || 0;
- }
- if (colSetting.field === 'b_code') {
- cLData.code = validText;
- } else {
- cLData[colSetting.field] = validText;
- }
- sortData[curRow][colSetting.field] = validText;
- cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- sortData[curRow].spamount = cLData.spamount;
- }
- if (bPaste) {
- data.push(cLData);
- selects.push(sortData[curRow]);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data, selects);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
- changeList = result;
- const loadResult = {
- update: selects,
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- ledgerTreeSpreadObj.loadExprToInput();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- ledgerTreeSpreadObj.buttonClicked = function(e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- if (!select || !select.clid) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
- return;
- }
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
- cInfo.is_valuation = select.is_valuation;
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- const loadResult = {
- update: [select],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- }, function () {
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- cInfo.is_valuation = select.is_valuation;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- }
- };
- ledgerTreeSpreadObj.valueChanged = function(e, info) {
- // 防止ctrl+z撤销数据
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- };
- ledgerTreeSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- const selects = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_tree.nodes[iRow];
- const cInfo = _.find(changeList, { id: node.clid });
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'camount' || col.field === 'oamount2') {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field === 'camount') {
- node.camount_expr = '';
- node.spamount = null;
- cInfo.camount_expr = '';
- cInfo.spamount = null;
- }
- delete cInfo.waitingLoading;
- bDel = true;
- }
- }
- if (bDel) {
- datas.push(cInfo);
- selects.push(node);
- }
- }
- console.log(datas, selects);
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
- changeList = result;
- const loadResult = {
- update: selects,
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- ledgerTreeSpreadObj.loadExprToInput();
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- // 表达式判断
- $('#ledger-camount-expr').change(function () {
- if (this.readOnly) return;
- let validText = $(this).val();
- const sel = ledgerSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const col = ledgerSheet.zh_setting.cols[sel.col];
- if (row === -1 || !(col && col.field === 'camount')) return;
- const select = SpreadJsObj.getSelectObject(ledgerSheet);
- if (!select || !select.clid) return;
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) return;
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- const orgExprValue = _.clone(select.camount_expr);
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- select.camount = validText;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = select.camount_expr;
- cInfo.camount = validText;
- // console.log(select);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- const loadResult = {
- update: [select],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- }, function () {
- select.camount = orgValue;
- select.camount_expr = orgExprValue;
- select.spamount = orgValue;
- cInfo.camount = orgValue;
- cInfo.camount_expr = orgExprValue;
- cInfo.spamount = orgValue;
- SpreadJsObj.reLoadRowData(posSheet, row);
- });
- });
- ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
- ledgerSpread.bind(spreadNS.Events.EditStarting, ledgerTreeSpreadObj.editStarting);
- ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
- ledgerSpread.bind(spreadNS.Events.ValueChanged, ledgerTreeSpreadObj.valueChanged);
- ledgerSpread.bind(spreadNS.Events.ButtonClicked, ledgerTreeSpreadObj.buttonClicked);
- SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
- // 计量单元修改
- posSpreadObj.del = function () {
- const selection = posSheet.getSelections();
- const sel = selection ? selection[0] : posSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- const count = sel.rowCount;
- if (readOnly || row === -1 || row + count > posSheet.zh_data.length) {
- return false;
- }
- const delList = [];
- let lastSelect = null;
- let hadTaiZhang = false;
- const selects = [];
- for (let r = 0; r < count; r++) {
- const select = posSheet.zh_data[row + r];
- if(!select || _.find(changeUsedData, { cbid: select.clid })) {
- toastr.error('已调用的变更清单不能删除');
- return false;
- }
- if (checkIsSettle(select)) {
- toastr.error('已结算的变更清单不能删除');
- return false;
- }
- if (r === count - 1 && changeOrder) {
- lastSelect = select;
- }
- if (select.lid != 0) {
- hadTaiZhang = true;
- }
- delList.push(select.clid);
- selects.push(select.id);
- }
- if (delList.length) {
- postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
- pos.removeDatas(selects);
- posSheet.deleteRows(row, count);
- const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {};
- // 判断是移除还是更新数量和金额
- if (posSheet.zh_data.length === 0) {
- // 判断父节点是否也要移除
- const parentNodes = _.reverse(ledgerTree.getAllParents(billsNode));
- loadResult.delete = [billsNode];
- for (const node of parentNodes) {
- if (node.children && node.children.length === 1) {
- loadResult.delete.push(node);
- } else {
- break;
- }
- }
- } else {
- loadResult.update = [billsNode];
- }
- if (loadResult.update || loadResult.delete) {
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- if (loadResult.delete) {
- ledgerSheet.setSelection(0, 0, 1, 1);
- ledgerTreeSpreadObj.refreshPosData();
- }
- }
- });
- }
- };
- posSpreadObj.editStarting = function (e, info) {
- posSpreadObj.billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
- const col = info.sheet.zh_setting.cols[info.col];
- const select = SpreadJsObj.getSelectObject(info.sheet);
- if (col.field === 'camount') {
- if (select.camount_expr && select.camount_expr !== '') {
- info.sheet.getCell(info.row, info.col).text(select.camount_expr);
- }
- }
- };
- posSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- return;
- }
- let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- let orgValue;
- if (col.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- } else {
- orgValue = select[col.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const node = posSpreadObj.billsNode;
- if (!node) {
- toastr.error('数据错误,请选择台账节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if(col.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: select.clid });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = exprQuantity.expr;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- if (col.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('计量上限默认值只能输入0-100之间的整数');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: select.clid });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
- if (validText < minLimit) {
- toastr.error('计量上限值至少大于等于 ' + minLimit);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- console.log(cInfo);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const loadResult = {
- update: [node],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- posSpreadObj.loadExprToInput();
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if(col.field === 'camount') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- };
- posSpreadObj.clipboardPasted = function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- if (range.row + range.rowCount > sortData.length) {
- toastMessageUniq(hint.cellError);
- // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
- posSpreadObj.loadCurPosData();
- return;
- }
- if (sortData.length > 0 && range.col + range.colCount > 6) {
- toastMessageUniq(hint.cellError);
- posSpreadObj.loadCurPosData();
- return;
- }
- if (!info.sheet.zh_setting) {
- posSpreadObj.loadCurPosData();
- return;
- }
- const data = [];
- // const rowData = [];
- let needCopyIgnore = !$('#customCheck1').is(':checked');
- let needColAdd = false;
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
- const cLData = { id: sortData[curRow].clid };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
- const newCurCol = curCol + 1;
- needColAdd = true;
- colSetting = info.sheet.zh_setting.cols[newCurCol];
- }
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue;
- if (colSetting.field === 'camount') {
- orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
- : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
- } else {
- orgValue = sortData[curRow][colSetting.field];
- }
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if(colSetting.field === 'camount') {
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastMessageUniq(getPasteHint(msg, hintRow));
- bPaste = false;
- continue;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- cLData.camount_expr = exprQuantity.expr;
- sortData[curRow].camount_expr = exprQuantity.expr;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- if (colSetting.field === 'unit_price') {
- validText = ZhCalc.round(validText, unitPriceUnit);
- } else {
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- }
- if (colSetting.field === 'delimit') {
- const reg = /^(\d{1,2}|100)$/;
- if (!(_.isNumber(validText) && reg.test(validText))) {
- toastr.error('计量单元第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
- bPaste = false;
- continue;
- }
- // 需要判断是否已调用,已调用的则不能低于原有值大小
- const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
- if (usedInfo && usedInfo.qty) {
- const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
- if (validText < minLimit) {
- toastr.error('计量单元第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
- bPaste = false;
- continue;
- }
- }
- }
- }
- let unitdecimal = validText;
- cLData[colSetting.field] = validText;
- sortData[curRow][colSetting.field] = validText;
- cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
- changeList = result;
- const node = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {
- update: [node],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- posSpreadObj.loadCurPosData();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- posSpreadObj.buttonClicked = function(e, info) {
- if (info.sheet.zh_setting) {
- const select = SpreadJsObj.getSelectObject(info.sheet);
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- if (col.field === 'is_valuation') {
- if (info.sheet.isEditing()) {
- info.sheet.endEdit(true);
- }
- if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
- return;
- }
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
- cInfo.is_valuation = select.is_valuation;
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const node = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {
- update: [node],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- }, function () {
- select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
- cInfo.is_valuation = select.is_valuation;
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- }
- }
- };
- posSpreadObj.valueChanged = function(e, info) {
- // 防止ctrl+z撤销数据
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- };
- posSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_data[iRow];
- const cInfo = _.find(changeList, { id: node.clid });
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'camount' || col.field === 'oamount2') {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field === 'camount') {
- node.camount_expr = '';
- node.spamount = null;
- cInfo.camount_expr = '';
- cInfo.spamount = null;
- }
- delete cInfo.waitingLoading;
- bDel = true;
- }
- }
- if (bDel) datas.push(cInfo);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
- changeList = result;
- const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {
- update: [billsNode],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- posSpreadObj.loadCurPosData();
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- // 表达式判断
- $('#pos-camount-expr').change(function () {
- if (this.readOnly) return;
- let validText = $(this).val();
- const sel = posSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const col = posSheet.zh_setting.cols[sel.col];
- if (row === -1 || !(col && col.field === 'camount')) return;
- const select = SpreadJsObj.getSelectObject(posSheet);
- if (!select) return;
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) return;
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- let orgValue = validText && validText !== ''
- ? (_.toNumber(validText) ? select.camount : select.camount_expr)
- : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
- const orgExprValue = _.clone(select.camount_expr);
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- return;
- }
- const exprQuantity = {
- expr: '',
- quantity: 0,
- };
- const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
- if (!valid) {
- toastr.error(msg);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- if (isNaN(exprQuantity.quantity)) {
- toastr.error('不能输入其它非数字类型字符');
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- validText = parseFloat(exprQuantity.quantity);
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- $(this).val(select.camount_expr ? select.camount_expr : select.camount);
- return;
- }
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.camount_expr = exprQuantity.expr;
- select.camount = validText;
- cInfo.spamount = select.spamount;
- cInfo.camount_expr = select.camount_expr;
- cInfo.camount = validText;
- // console.log(select);
- delete cInfo.waitingLoading;
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
- SpreadJsObj.reLoadRowData(posSheet, row);
- const node = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {
- update: [node],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- }, function () {
- select.camount = orgValue;
- select.camount_expr = orgExprValue;
- select.spamount = orgValue;
- cInfo.camount = orgValue;
- cInfo.camount_expr = orgExprValue;
- cInfo.spamount = orgValue;
- SpreadJsObj.reLoadRowData(posSheet, row);
- });
- });
- posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
- posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
- posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
- posSpread.bind(spreadNS.Events.ValueChanged, posSpreadObj.valueChanged);
- posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
- SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
- // 右键菜单
- $.contextMenu({
- selector: '#ledger-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
- return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
- },
- items: {
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- ledgerTreeSpreadObj.del();
- },
- disabled: function (key, opt) {
- const selection = ledgerSheet.getSelections();
- const sel = selection ? selection[0] : ledgerSheet.getSelections()[0];
- const row = sel ? sel.row : -1;
- const tree = ledgerSheet.zh_tree;
- if (!tree) return true;
- const first = ledgerSheet.zh_tree.nodes[row];
- let last = first, sameParent = true, listValid = true;
- if (sel.rowCount > 1 && first) {
- for (let r = 1; r < sel.rowCount; r++) {
- const rNode = tree.nodes[sel.row + r];
- if (!rNode) {
- sameParent = false;
- break;
- }
- if (!rNode.clid) {
- listValid = false;
- break;
- }
- if (_.find(changeUsedData, { cbid: rNode.clid }) || checkIsSettle(rNode)) {
- listValid = false;
- break;
- }
- if (rNode.level > first.level) continue;
- if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
- sameParent = false;
- break;
- }
- last = rNode;
- }
- }
- const valid = !ledgerSheet.zh_setting.readOnly;
- return !(valid && first && first.clid && !_.find(changeUsedData, { cbid: first.clid }) && !checkIsSettle(first) && sameParent && listValid);
- }
- },
- // sprEdit: '----',
- // 'allNotValuation': {
- // name: '设置全部清单不计价',
- // icon: 'fa-magic',
- // callback: function (key, opt) {
- // changeSpreadObj.setAllValuation(0);
- // },
- // },
- // 'allValuation': {
- // name: '设置全部清单计价',
- // icon: 'fa-magic',
- // callback: function (key, opt) {
- // changeSpreadObj.setAllValuation(1);
- // },
- // },
- }
- });
- // 右键菜单
- $.contextMenu({
- selector: '#pos-spread',
- build: function ($trigger, e) {
- const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
- return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
- },
- items: {
- 'delete': {
- name: '删除',
- icon: 'fa-remove',
- callback: function (key, opt) {
- posSpreadObj.del();
- },
- disabled: function (key, opt) {
- const selection = posSheet.getSelections();
- const sel = selection ? selection[0] : posSheet.getSelections()[0];
- const row = sel && sel.row !== undefined ? sel.row : -1;
- if (readOnly || row === -1 || sel.row + sel.rowCount > posSheet.zh_data.length) {
- return true;
- }
- let isUsed = false;
- for (let r = 0; r < sel.rowCount; r++) {
- const select = posSheet.zh_data[row + r];
- if(!select || _.find(changeUsedData, { cbid: select.clid })) {
- isUsed = true;
- }
- if (checkIsSettle(select)) {
- isUsed = true;
- }
- }
- return isUsed;
- }
- },
- // sprEdit: '----',
- // 'allNotValuation': {
- // name: '设置全部清单不计价',
- // icon: 'fa-magic',
- // callback: function (key, opt) {
- // changeSpreadObj.setAllValuation(0);
- // },
- // },
- // 'allValuation': {
- // name: '设置全部清单计价',
- // icon: 'fa-magic',
- // callback: function (key, opt) {
- // changeSpreadObj.setAllValuation(1);
- // },
- // },
- }
- });
- }
- if (shenpiPower) {
- changeSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- if (!select || !select.id) {
- toastr.error('该变更清单无法编辑');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- const orgValue = select[col.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (!node) {
- toastr.error('数据错误,请选择清单节点后再试');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- if (col.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {cbid: select.id});
- if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- changeSpreadObj.reloadRow(info.sheet, info.row);
- return;
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- if (col.field !== 'oamount2') {
- cInfo.spamount = validText;
- select.spamount = validText;
- }
- const data = {
- id: select.id,
- };
- if (col.field === 'oamount2') {
- data[col.field] = select[col.field];
- } else {
- data.spamount = select.spamount;
- }
- console.log(data, col.field);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
- changeSpreadObj.calcOneSum(select);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- changeSpreadObj.refreshXmjData();
- changeSpreadObj.countSum();
- if (info.row === info.sheet.zh_data.length - 1) {
- // console.log(info);
- // changeSpreadSheet.setSelection(info.row, info.col, 1, 1);
- // changeSpreadObj.reloadRow(changeSpreadSheet, info.row, 0, true);
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if (col.field !== 'oamount2') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- changeSpreadObj.reloadRow(info.sheet, info.row);
- });
- };
- changeSpreadObj.clipboardPasted = function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- const data = [];
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- if (!sortData[curRow] || !sortData[curRow].id) {
- bPaste = false;
- }
- const cLData = { id: sortData[curRow].id };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- const orgValue = sortData[curRow][colSetting.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- if (colSetting.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- }
- }
- sortData[curRow][colSetting.field] = validText;
- if (colSetting.field === 'oamount2') {
- cLData[colSetting.field] = validText;
- } else {
- cLData.spamount = validText;
- sortData[curRow].spamount = validText;
- }
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- changeSpreadObj.reloadRow(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
- changeList = result;
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }, function () {
- changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- changeSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_data[iRow];
- const cInfo = _.find(changeList, { id: node.id });
- const data = { id: node.id };
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field !== 'oamount2') {
- data.spamount = null;
- cInfo.spamount = null;
- node.spamount = null;
- } else {
- data[col.field] = null;
- }
- bDel = true;
- }
- }
- if (bDel) datas.push(data);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
- changeList = result;
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }, function () {
- changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
- changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
- xmjSpreadObj.editStarting = function (e, info) {
- xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
- };
- xmjSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- const cInfo = _.find(changeList, { id: select.id });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- const orgValue = select[col.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const node = xmjSpreadObj.billsNode;
- if (!node) {
- toastr.error('数据错误,请选择清单节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- if (col.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {cbid: select.id});
- if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- if (col.field !== 'oamount2') {
- cInfo.spamount = validText;
- select.spamount = validText;
- }
- const data = {
- id: select.id,
- };
- if (col.field === 'oamount2') {
- data[col.field] = select[col.field];
- } else {
- data.spamount = select.spamount;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = info.sheet.zh_data;
- changeSpreadObj.calcOneSum(node);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- changeSpreadObj.countSum();
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if (col.field !== 'oamount2') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- };
- xmjSpreadObj.clipboardPasted = function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (!node) {
- toastr.error('数据错误,请选择清单节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- const data = [];
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- const cLData = { id: sortData[curRow].id };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- const orgValue = sortData[curRow][colSetting.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- if (colSetting.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- }
- }
- sortData[curRow][colSetting.field] = validText;
- if (colSetting.field === 'oamount2') {
- cLData[colSetting.field] = validText;
- } else {
- cLData.spamount = validText;
- sortData[curRow].spamount = validText;
- }
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
- changeList = result;
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
- node.children = info.sheet.zh_data;
- changeSpreadObj.calcOneSum(node);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- changeSpreadObj.countSum();
- xmjSpreadObj.loadCurXmjData();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- xmjSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- const changeNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
- if (!changeNode) {
- toastr.error('数据错误,请选择清单节点后再试');
- SpreadJsObj.reLoadRowData(sheet, info.row);
- return;
- }
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_data[iRow];
- const cInfo = _.find(changeList, { id: node.id });
- const data = { id: node.id };
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field !== 'oamount2') {
- data.spamount = null;
- cInfo.spamount = null;
- node.spamount = null;
- } else {
- data[col.field] = null;
- }
- bDel = true;
- }
- }
- if (bDel) datas.push(data);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
- changeList = result;
- const billIndex = _.indexOf(changeSpreadSheet.zh_data, changeNode);
- changeNode.children = sheet.zh_data;
- changeSpreadObj.calcOneSum(changeNode);
- console.log(changeNode);
- changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
- changeSpreadObj.countSum();
- xmjSpreadObj.loadCurXmjData();
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
- xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
- xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
- ledgerTreeSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
- const select = sortData[info.row];
- if (!select || !select.clid) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- const orgValue = select[col.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- if (col.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
- if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- if (col.field !== 'oamount2') {
- cInfo.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- }
- const data = {
- id: cInfo.id,
- };
- if (col.field === 'oamount2') {
- data[col.field] = select[col.field];
- } else {
- data.spamount = select.spamount;
- }
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
- const loadResult = {
- update: [select],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if(col.field !== 'oamount2') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- };
- ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
- const tree = info.sheet.zh_tree;
- if (!tree) { return; }
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_tree.nodes;
- const selects = [];
- const data = [];
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- const node = sortData[curRow];
- if (!node) {
- continue;
- }
- const cLData = { id: sortData[curRow].clid };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- const orgValue = sortData[curRow][colSetting.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- if (colSetting.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- bPaste = false;
- continue;
- }
- }
- }
- sortData[curRow][colSetting.field] = validText;
- if (colSetting.field === 'oamount2') {
- cLData[colSetting.field] = validText;
- } else {
- cLData.spamount = validText;
- sortData[curRow].spamount = cLData.spamount;
- }
- }
- if (bPaste) {
- data.push(cLData);
- selects.push(sortData[curRow]);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data, selects);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
- changeList = result;
- const loadResult = {
- update: selects,
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- ledgerTreeSpreadObj.loadExprToInput();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- ledgerTreeSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- const selects = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_tree.nodes[iRow];
- const cInfo = _.find(changeList, { id: node.clid });
- const data = { id: node.clid };
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field !== 'oamount2') {
- data.spamount = null;
- cInfo.spamount = null;
- node.spamount = null;
- } else {
- data[col.field] = null;
- }
- bDel = true;
- }
- }
- if (bDel) {
- datas.push(data);
- selects.push(node);
- }
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
- changeList = result;
- const loadResult = {
- update: selects,
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- ledgerTreeSpreadObj.loadExprToInput();
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
- ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
- posSpreadObj.editEnded = function (e, info) {
- if (!info.sheet.zh_setting) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
- const cInfo = _.find(changeList, { id: select.clid });
- if (!cInfo) {
- toastr.error('数据错误,请刷新页面重试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const col = info.sheet.zh_setting.cols[info.col];
- let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
- const orgValue = select[col.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- const node = SpreadJsObj.getSelectObject(ledgerSheet);
- if (!node) {
- toastr.error('数据错误,请选择台账节点后再试');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- if (col.type === 'Number') {
- if (isNaN(validText)) {
- toastr.error('不能输入其它非数字类型字符');
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
- if (col.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {cbid: select.clid});
- if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
- toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
- toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- return;
- }
- }
- }
- cInfo[col.field] = validText;
- select[col.field] = validText;
- if (col.field !== 'oamount2') {
- cInfo.spamount = validText;
- select.spamount = validText;
- }
- const data = {
- id: select.clid,
- };
- if (col.field === 'oamount2') {
- data[col.field] = select[col.field];
- } else {
- data.spamount = select.spamount;
- }
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- const loadResult = {
- update: [node],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- }, function () {
- select[col.field] = orgValue;
- cInfo[col.field] = orgValue;
- if (col.field !== 'oamount2') {
- select.spamount = orgValue;
- cInfo.spamount = orgValue;
- }
- SpreadJsObj.reLoadRowData(info.sheet, info.row);
- });
- };
- posSpreadObj.clipboardPasted = function (e, info) {
- if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
- info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
- }
- const hint = {
- cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
- numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
- expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
- };
- const range = info.cellRange;
- const sortData = info.sheet.zh_data || [];
- const data = [];
- for (let iRow = 0; iRow < range.rowCount; iRow++) {
- let bPaste = true;
- const curRow = range.row + iRow;
- const cLData = { id: sortData[curRow].clid };
- const hintRow = range.rowCount >= 1 ? curRow : '';
- let sameCol = 0;
- for (let iCol = 0; iCol < range.colCount; iCol++) {
- const curCol = range.col + iCol;
- let colSetting = info.sheet.zh_setting.cols[curCol];
- if (!colSetting) continue;
- let validText = info.sheet.getText(curRow, curCol);
- validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
- const orgValue = sortData[curRow][colSetting.field];
- if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
- sameCol++;
- if (range.colCount === sameCol) {
- bPaste = false;
- }
- continue;
- }
- if (colSetting.type === 'Number') {
- if (isNaN(validText)) {
- toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
- bPaste = false;
- continue;
- }
- validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
- if (colSetting.field !== 'oamount2') {
- // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
- const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
- if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
- toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
- toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
- bPaste = false;
- continue;
- }
- }
- }
- sortData[curRow][colSetting.field] = validText;
- if (colSetting.field === 'oamount2') {
- cLData[colSetting.field] = validText;
- } else {
- cLData.spamount = validText;
- sortData[curRow].spamount = validText;
- }
- }
- if (bPaste) {
- data.push(cLData);
- // rowData.push(curRow);
- } else {
- SpreadJsObj.reLoadRowData(info.sheet, curRow);
- }
- }
- if (data.length === 0) {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- }
- console.log(data);
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
- changeList = result;
- const node = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {
- update: [node],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- posSpreadObj.loadCurPosData();
- }, function () {
- SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
- return;
- });
- };
- posSpreadObj.deletePress = function (sheet) {
- if (!sheet.zh_setting) return;
- // 暂时仅支持移除数量
- const sel = sheet.getSelections()[0], datas = [];
- for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
- let bDel = false;
- const node = sheet.zh_data[iRow];
- const cInfo = _.find(changeList, { id: node.clid });
- const data = { id: node.clid };
- for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
- const col = sheet.zh_setting.cols[iCol];
- if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
- node[col.field] = null;
- cInfo[col.field] = null;
- if (col.field !== 'oamount2') {
- data.spamount = null;
- cInfo.spamount = null;
- node.spamount = null;
- } else {
- data[col.field] = null;
- }
- bDel = true;
- }
- }
- if (bDel) datas.push(data);
- }
- if (datas.length > 0) {
- postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
- changeList = result;
- const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
- const loadResult = {
- update: [billsNode],
- };
- const refreshData = ledgerTree.loadPostData(loadResult);
- ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
- posSpreadObj.loadCurPosData();
- }, function () {
- SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
- return;
- });
- }
- return;
- };
- posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
- posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
- SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
- }
- // 切换清单模式
- $('.change-mode').on('click', async function () {
- if ($(this).hasClass('active')) {
- return;
- }
- $('.change-mode').removeClass('active');
- $(this).addClass('active');
- const type = parseInt($(this).data('type'));
- postData(window.location.pathname + '/save', { type:'change_mode', updateData: type }, function (result) {
- changeList = result;
- changeMode = type;
- showMode(type);
- });
- });
- let firstLoad = true;
- function showMode(type) {
- if (type === 0) {
- $('.judge-hide').show();
- $('.judge-show').attr("style","display:none !important");
- if (changeOrder === 0) {
- $('#upAndMoveBtn').attr("style","display:none !important");
- }
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- if (updateOrderList.length > 0) {
- postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
- });
- }
- changeSpreadObj.reloadSheet(newChangeList);
- changeSpread.refresh();
- xmjSpread.refresh();
- } else {
- $('.judge-hide').attr("style","display:none !important");
- $('.judge-show').show();
- if (firstLoad) {
- const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
- if (updateOrderList.length > 0) {
- postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
- });
- }
- firstLoad = false;
- }
- const {changeLedgers, changePoss} = makeLedgerAndPosData();
- ledgerTree.loadDatas(changeLedgers);
- pos.loadDatas(changePoss);
- treeCalc.calculateAll(ledgerTree);
- console.log(ledgerTree);
- SpreadJsObj.loadSheetData(ledgerSheet, SpreadJsObj.DataType.Tree, ledgerTree);
- ledgerTree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(ledgerSheet);
- SpreadJsObj.loadTopAndSelect(ledgerSheet, ckBillsSpread);
- ledgerTreeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
- posSpreadObj.loadCurPosData();
- SpreadJsObj.resetTopAndSelect(posSheet);
- ledgerTreeSpreadObj.loadExprToInput();
- ledgerSpread.refresh();
- posSpread.refresh();
- }
- }
- // 显示层次
- (function (select, sheet) {
- $(select).click(function () {
- if (!sheet.zh_tree) return;
- const tag = $(this).attr('tag');
- const tree = sheet.zh_tree;
- setTimeout(() => {
- showWaitingView();
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- tree.expandByLevel(parseInt(tag));
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "last":
- tree.expandByCustom(() => { return true; });
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- case "leafXmj":
- tree.expandToLeafXmj();
- SpreadJsObj.refreshTreeRowVisible(sheet);
- break;
- }
- closeWaitingView();
- }, 100);
- });
- })('a[name=showLevel]', ledgerSheet);
- function makeLedgerAndPosData() {
- const changeLedgers = _.filter(ledgerList, function (item) {
- return _.findIndex(changeList, { gcl_id: item.id}) !== -1;
- });
- // 找出所有父节点
- if (changeLedgers.length > 0) {
- const parentLedgers = [];
- for (const node of changeLedgers) {
- const cl = _.find(changeList, { gcl_id: node.id, mx_id: '' });
- if (cl) {
- const cloneCl = _.cloneDeep(cl);
- delete cloneCl.id;
- delete cloneCl.name;
- delete cloneCl.code;
- node.clid = cl.id;
- // cloneCl 合并到node中
- Object.assign(node, cloneCl);
- }
- if (node.full_path && node.full_path !== '') {
- const parentIds = node.full_path.split('-');
- parentIds.length = parentIds.length - 1;
- for (const id of parentIds) {
- const lid = parseInt(id);
- if (lid !== node.ledger_id && _.findIndex(parentLedgers, { ledger_id: lid }) === -1) {
- parentLedgers.push(_.find(ledgerList, { ledger_id: lid }));
- }
- }
- }
- }
- changeLedgers.push(...parentLedgers);
- }
- // 找出空白清单和签约清单
- const otherChangeList = _.filter(changeList, function (item) {
- return item.gcl_id === '' || item.gcl_id === null || item.gcl_id == 0;
- });
- if (otherChangeList.length > 0) {
- // 判断changeLedgers中是否已经存在第一部分
- let firstChangeLedger = _.find(changeLedgers, { order: 1, level: 1 });
- let firstOrder = 1;
- if (firstChangeLedger) {
- const firstChilds = _.filter(changeLedgers, { ledger_pid: firstChangeLedger.ledger_id });
- firstOrder = _.maxBy(firstChilds, 'order').order + 1;
- }
- let maxLedgerId = changeLedgers.length > 0 ? _.maxBy(changeLedgers, 'ledger_id').ledger_id + 1 : 2;
- if (!firstChangeLedger) {
- const firstLedger = _.find(ledgerList, { order: 1, level: 1 });
- if (firstLedger) {
- changeLedgers.push(firstLedger);
- firstChangeLedger = firstLedger;
- } else {
- firstChangeLedger = { id: 'new-tree-ledger-1', ledger_id: 1, ledger_pid: -1, name: '第一部分 建筑安装工程费', unit: '公路公里', unit_price: 0, b_code: null, code: '1', order: 1, level: 1, full_path: '1', is_leaf: 0 };
- changeLedgers.push(firstChangeLedger);
- }
- }
- for (const cl of otherChangeList) {
- const cloneCl = _.cloneDeep(cl);
- cloneCl.b_code = cloneCl.code;
- cloneCl.code = null;
- cloneCl.clid = cl.id;
- cloneCl.level = 2;
- cloneCl.order = firstOrder;
- cloneCl.is_leaf = 1;
- cloneCl.ledger_pid = firstChangeLedger.ledger_id;
- cloneCl.ledger_id = maxLedgerId;
- cloneCl.full_path = firstChangeLedger.full_path + '-' + maxLedgerId;
- changeLedgers.push(cloneCl);
- maxLedgerId++;
- firstOrder++;
- }
- }
- const changePoss = _.filter(posList, function (item) {
- return _.findIndex(changeList, { mx_id: item.id }) !== -1;
- });
- for (const cp of changePoss) {
- const cl = _.find(changeList, { mx_id: cp.id });
- if (cl) {
- const cloneCl = _.cloneDeep(cl);
- delete cloneCl.id;
- delete cloneCl.lid;
- delete cloneCl.name;
- cp.clid = cl.id;
- // cloneCl 合并到cp中
- Object.assign(cp, cloneCl);
- }
- }
- return { changeLedgers, changePoss };
- }
- // 审批流程展示与隐藏
- $('#show-table-detail').on('click', function (e) {
- if($(e.target).is('label')){
- return;
- }
- ledgerTreeSpreadObj.showHideAudit($(this).is(':checked'));
- posSpreadObj.showHideAudit($(this).is(':checked'));
- changeSpreadObj.showHideAudit($(this).is(':checked'));
- xmjSpreadObj.showHideAudit($(this).is(':checked'));
- });
- const cca = getLocalCache('change-checkbox-account-' + accountId);
- if (cca !== null && cca !== undefined) {
- $('#customCheck1').prop('checked', cca !== 'false');
- }
- changeSpreadSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- xmjSheet.setColumnVisible(7,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- ledgerSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- posSheet.setColumnVisible(2,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- // 变更详情展示和隐藏
- $('.change-detail-checkbox').on('click', function (e) {
- if($(e.target).is('label')){
- return;
- }
- // // 设置用户项目本地记录展示和隐藏情况
- setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
- changeSpreadSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- xmjSheet.setColumnVisible(7,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- ledgerSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- posSheet.setColumnVisible(2,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
- });
- $.subMenu({
- menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
- toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
- key: 'menu.1.0.0',
- miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
- callback: function (info) {
- if (info.mini) {
- $('.panel-title').addClass('fluid');
- $('#sub-menu').removeClass('panel-sidebar');
- } else {
- $('.panel-title').removeClass('fluid');
- $('#sub-menu').addClass('panel-sidebar');
- }
- autoFlashHeight();
- changeSpread.refresh();
- xmjSpread.refresh();
- ledgerSpread.refresh();
- posSpread.refresh();
- }
- });
- $.divResizer({
- select: '#right-spr',
- callback: function () {
- changeSpread.refresh();
- xmjSpread.refresh();
- ledgerSpread.refresh();
- posSpread.refresh();
- const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
- setLocalCache('change_information_width', width);
- $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
- }
- });
- $('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
- changeSpread.refresh();
- xmjSpread.refresh();
- ledgerSpread.refresh();
- posSpread.refresh();
- // 根据浏览器记录展开收起
- if (getLocalCache('change_information_width')) {
- $('#left-view').css('width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
- $('#right-view').css('width', getLocalCache('change_information_width') + '%');
- $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
- changeSpread.refresh();
- xmjSpread.refresh();
- ledgerSpread.refresh();
- posSpread.refresh();
- } else {
- $('#left-header').css('min-width', '33.33%');
- }
- $.divResizer({
- select: '#change-pos-resize',
- callback: function () {
- $('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
- changeSpread.refresh();
- ledgerSpread.refresh();
- let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
- $(".sp-wrap").height(bcontent-30);
- posSpread.refresh();
- xmjSpread.refresh();
- }
- });
- if (!readOnly || shenpiPower) {
- // 自动编号
- $('.reduction-code').click(function () {
- const code = $(this).attr('data-code');
- $('input[name="code"]').val(code);
- changeInfo.code = $('input[name="code"]').val();
- judgeChange();
- });
- // 记录变更信息操作
- $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val();
- judgeChange();
- });
- $('body').on('valuechange', '#change_form textarea', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
- judgeChange();
- });
- $('body').on('change', '#change_form select', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val();
- judgeChange();
- });
- $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
- changeInfo[$(this).attr('name')] = $(this).val();
- judgeChange();
- });
- $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
- const typecheck = [];
- $.each($('#change_form input[name="type[]"]:checked'), function () {
- typecheck.push($(this).val());
- });
- changeInfo.type = typecheck.join(',');
- judgeChange();
- });
- // 保存修改ajax提交(不刷新页面)
- $('.save_change_btn').on('click', function () {
- // 保存修改modal
- if ($('input[name="code"]').val() === '') {
- toastr.error('申请编号不能为空!');
- return;
- }
- if ($('input[name="name"]').val() === '') {
- toastr.error('变更工程名称不能为空!');
- return;
- }
- // 换行更改并提交
- changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
- changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
- changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
- changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
- changeInfo.company = $('#change_form select[name="company"]').val();
- // 后改为br
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
- $('.reduction-code').attr('data-code', $('input[name="code"]').val());
- toastr.success(result ? result.msg : '');
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
- changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
- changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
- changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
- back_changeInfo = Object.assign({}, changeInfo);
- if (result.changeList) {
- deLimit = result.deLimit;
- changeList = result.changeList;
- SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
- SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
- const [newChangeList] = changeSpreadObj.makeNewChangeList();
- changeSpreadObj.reloadSheet(newChangeList);
- }
- });
- return false;
- });
- $('#cancel_change').on('click', function () {
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- if (!isObjEqual(changeInfo, back_changeInfo)) {
- changeFormRemake();
- }
- toastr.success('已还原到上次保存状态');
- });
- function changeFormRemake() {
- changeInfo = Object.assign({}, back_changeInfo);
- $('#change_form input[name="code"]').val(changeInfo.code);
- $('#change_form input[name="name"]').val(changeInfo.name);
- $('#change_form input[name="peg"]').val(changeInfo.peg);
- $('#change_form input[name="org_name"]').val(changeInfo.org_name);
- $('#change_form input[name="org_code"]').val(changeInfo.org_code);
- $('#change_form input[name="new_name"]').val(changeInfo.new_name);
- $('#change_form input[name="new_code"]').val(changeInfo.new_code);
- $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
- $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
- $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
- $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
- $('#change_form select[name="type"]').val(changeInfo.type);
- $('#change_form select[name="class"]').val(changeInfo.class);
- $('#change_form select[name="quality"]').val(changeInfo.quality);
- $('#change_form select[name="company"]').val(changeInfo.company);
- $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
- $('#change_form input[name="state"][value="'+ changeInfo.state +'"]').prop('checked', true);
- $('#change_form input[name="type[]"]').prop('checked', false);
- $('#change_form input[name="w_code"]').val(changeInfo.w_code);
- const typecheck = changeInfo.type.split(',');
- for (const type of typecheck) {
- $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
- }
- }
- if (!readOnly) {
- $('.checkChangeFrom').on('click', function () {
- let returnFlag = false;
- // 表单判断
- if ($('input[name="code"]').val() === '') {
- toastr.error('申请编号不能为空!');
- returnFlag = true;
- }
- if ($('input[name="name"]').val() === '') {
- toastr.error('变更工程名称不能为空!');
- returnFlag = true;
- }
- if ($('textarea[name="content"]').val() === '') {
- toastr.error('工程变更理由及内容不能为空!');
- returnFlag = true;
- }
- if (changeList.length === 0) {
- toastr.error('请添加变更清单!');
- returnFlag = true;
- } else {
- const whiteList = _.filter(changeList, item => item.lid == 0 && (item.name === '' || item.name === null));
- if (whiteList.length > 0) {
- toastr.error('存在空白清单未完整填写数据(名称不可为空)');
- returnFlag = true;
- }
- // for (const [i,cl] of changeSpreadSheet.zh_data.entries()) {
- // if (cl.name === '') {
- // toastr.error('清单第' + (i+1) + '行未完整填写数据(名称不可为空)');
- // returnFlag = true;
- // }
- // }
- }
- if(!checkAuditorFrom ()) {
- returnFlag = true;
- }
- // 判断非空白变更清单是否有重复值(gcl_id及mx_id),如果存在完全相同则需要提示并删除,上报失败,这功能主要是因为清单数据过多服务器处理不过来偶然出现
- const doubleList = findDuplicates(_.filter(changeList, item => item.lid != 0));
- console.log(doubleList);
- if (doubleList.length > 0) {
- for (const double of doubleList) {
- const msgIndex = [];
- for (const one of double) {
- const index = _.findIndex(changeSpreadSheet.zh_data[double[0].order - 1].children, { id: one.id });
- if (index !== -1) msgIndex.push(index+1);
- }
- if (msgIndex.length > 0) {
- toastr.error('第 ' + double[0].order + ' 行' + double[0].code + '清单项目节第 ' + msgIndex.splice(',') + '行重复,请只保留一条数据');
- }
- }
- returnFlag = true;
- }
- if (returnFlag) {
- return false;
- }
- postData(window.location.pathname + '/audit/start', {}, function (result) {
- window.location.reload();
- })
- });
- // 检查上报情况
- function checkAuditorFrom () {
- if ($('#auditList li').length === 0) {
- if(shenpi_status === shenpiConst.sp_status.gdspl) {
- toastr.error('请联系管理员添加审批人');
- } else {
- toastr.error('请先选择审批人,再上报数据');
- }
- return false;
- }
- return true;
- }
- // 找出数组中相同的清单
- function findDuplicates(arr, keys = ['lid', 'gcl_id', 'mx_id']) {
- const groupedData = _.groupBy(arr, item => JSON.stringify(_.pick(item, keys)));
- const duplicates = _.filter(groupedData, group => group.length > 1);
- return _.values(duplicates);
- }
- }
- }
- if (shenpiPower) {
- // 审批提交与判断
- $('.approval-btn').on('click', function () {
- // 判断审批状态
- let returnflag = true;
- const pData = {
- change_id: $('#changeId').val(),
- w_code: $.trim($('#w_code').val()),
- }
- if ($(this).hasClass('btn-success')) {
- const sdesc = $('#success-approval').find('textarea').val();
- if (sdesc === '') {
- toastr.error('审批意见不能为空!');
- returnflag = false;
- }
- if ($('input[name="p_code"]').val() === '') {
- toastr.error('变更令号(批复编号)不能为空!');
- returnflag = false;
- } else if ($('input[name="p_code"]').val() !== undefined) {
- $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
- const postData2 = {
- p_code: $('input[name="p_code"]').val(),
- };
- postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData2, function (result) {
- }, function (data) {
- returnflag = false;
- });
- pData.p_code = $('input[name="p_code"]').val();
- }
- if(returnflag) {
- $('input[name="w_code"]').val($.trim($('#w_code').val()));
- $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
- if ($('#warning-text').length) $('#warning-text').remove();
- // $('#success-approval').submit();
- pData.status = auditConst.status.checked;
- pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
- }
- } else {
- const sdesc = $('#fail-approval').find('textarea').val();
- if (sdesc === '') {
- toastr.error('审批意见不能为空!');
- returnflag = false;
- }
- const type = $('#fail-approval').find('input[name="status"]:checked').val();
- if (type === undefined) {
- // toastr.error('请选择退回类型!');
- if (!$('#warning-text').length) {
- $('#change-back-content').append('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
- }
- returnflag = false;
- }
- if(returnflag) {
- $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
- $('input[name="w_code"]').val($.trim($('#w_code').val()));
- // $('#fail-approval').submit();
- pData.status = type;
- pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
- }
- }
- if (pData.status) {
- console.log(pData);
- postData('/tender/' + $('#tenderId').val() + '/change/approval', pData, function (result) {
- window.location.reload();
- });
- }
- });
- const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
- if (showWaiting) showWaitingView();
- $.ajax({
- type:"POST",
- url: url,
- data: {'data': JSON.stringify(data)},
- dataType: 'json',
- cache: false,
- async: false,
- timeout: 60000,
- beforeSend: function(xhr) {
- let csrfToken = Cookies.get('csrfToken_j');
- xhr.setRequestHeader('x-csrf-token', csrfToken);
- },
- success: function(result){
- if (result.err === 0) {
- if (successCallback) {
- successCallback(result.data);
- }
- } else {
- toastr.error(result.msg);
- if (errorCallBack) {
- errorCallBack(result.msg);
- }
- }
- if (showWaiting) closeWaitingView();
- },
- error: function(jqXHR, textStatus, errorThrown){
- toastr.error('error: ' + textStatus + " " + errorThrown);
- if (errorCallBack) {
- errorCallBack();
- }
- if (showWaiting) closeWaitingView();
- }
- });
- };
- }
- // 重新审批获取手机验证码
- // 获取验证码
- let isPosting = false;
- $(".get-code").on('click', function() {
- if (isPosting) {
- return false;
- }
- const btn = $(this);
- $.ajax({
- url: '/profile/code?_csrf_j=' + csrf,
- type: 'post',
- data: { mobile: authMobile, type: 'shenpi' },
- dataTye: 'json',
- error: function() {
- isPosting = false;
- },
- beforeSend: function() {
- isPosting = true;
- },
- success: function(response) {
- isPosting = false;
- if (response.err === 0) {
- codeSuccess(btn);
- $("input[name='code']").removeAttr('readonly');
- $("#re-shenpi-btn").removeAttr('disabled');
- $("#re-shenpi-btn2").removeAttr('disabled');
- } else {
- toast(response.msg, 'error');
- }
- }
- });
- });
- if (readOnly && !shenpiPower) {
- // 记录变更信息操作
- $('body').on('valuechange', '#w_code', function (e, previous) {
- const new_w_code = $(this).val();
- if (new_w_code !== w_code) {
- $('#show-save-btn').show();
- $('#sp-btn').hide();
- $('.title-main').addClass('bg-warning');
- } else {
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- }
- });
- // 保存修改ajax提交(不刷新页面)
- $('.save_change_btn').on('click', function () {
- const new_w_code = $('#w_code').val();
- // 后改为br
- // 更新至服务器
- postData(window.location.pathname + '/save', { type:'info', updateData: { w_code: new_w_code } }, function (result) {
- toastr.success(result ? result.msg : '');
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- w_code = new_w_code;
- });
- return false;
- });
- $('#cancel_change').on('click', function () {
- $('#show-save-btn').hide();
- $('#sp-btn').show();
- $('.title-main').removeClass('bg-warning');
- $('#w_code').val(w_code);
- // toastr.success('已还原到上次保存状态');
- });
- }
- });
- /**
- * 获取成功后的操作
- *
- * @param {Object} btn - 点击的按钮
- * @return {void}
- */
- function codeSuccess(btn) {
- let counter = 60;
- btn.addClass('disabled').text('重新获取 ' + counter + 'S');
- btn.parent().siblings('input').removeAttr('readonly').attr('placeholder', '输入短信中的6位验证码');
- const bindBtn = $("#bind-btn");
- bindBtn.removeClass('btn-secondary disabled').addClass('btn-primary');
- const countDown = setInterval(function() {
- const countString = counter - 1 <= 0 ? '' : ' ' + (counter - 1) + 'S';
- // 倒数结束后
- if (countString === '') {
- clearInterval(countDown);
- btn.removeClass('disabled');
- }
- const text = '重新获取' + countString;
- btn.text(text);
- counter -= 1;
- }, 1000);
- }
- function calcChangePrice() {
- let positive_tp = 0;
- let negative_tp = 0;
- let valuation_tp = 0;
- let unvaluation_tp = 0;
- let new_tp = 0;
- // 先汇总再统计金额
- const gclChangeList = _.uniq(_.map(changeList, 'gcl_id'));
- for (const g of gclChangeList) {
- if (g) {
- const list = _.filter(changeList, { gcl_id: g });
- let spamount = 0;
- let valuation_amount = 0;
- let unvaluation_amount = 0;
- let unitPrice = 0;
- for (const c of list) {
- if (c.spamount) {
- spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
- unitPrice = c.unit_price;
- if (c.is_valuation) {
- valuation_amount = ZhCalc.add(valuation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
- } else {
- unvaluation_amount = ZhCalc.add(unvaluation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
- }
- const posOrNePrice = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
- if (posOrNePrice >= 0) {
- positive_tp = ZhCalc.add(positive_tp, posOrNePrice);
- } else {
- negative_tp = ZhCalc.add(negative_tp, posOrNePrice);
- }
- }
- }
- const price = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit);
- const valuation_price = ZhCalc.round(ZhCalc.mul(valuation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
- const unvaluation_price = ZhCalc.round(ZhCalc.mul(unvaluation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
- valuation_tp = ZhCalc.add(valuation_tp, valuation_price);
- unvaluation_tp = ZhCalc.add(unvaluation_tp, unvaluation_price);
- new_tp = ZhCalc.add(new_tp, price);
- // if (price >= 0) {
- // positive_tp = ZhCalc.add(positive_tp, price);
- // } else {
- // negative_tp = ZhCalc.add(negative_tp, price);
- // }
- } else {
- const list = _.filter(changeList, { gcl_id: g });
- for (const c of list) {
- if (c.spamount) {
- const price = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
- new_tp = ZhCalc.add(new_tp, price);
- if (price >= 0) {
- positive_tp = ZhCalc.add(positive_tp, price);
- } else {
- negative_tp = ZhCalc.add(negative_tp, price);
- }
- if (c.is_valuation) {
- valuation_tp = ZhCalc.add(valuation_tp, price);
- } else {
- unvaluation_tp = ZhCalc.add(unvaluation_tp, price);
- }
- }
- }
- }
- }
- const updateTpList = {};
- let updateFlag = false;
- if (changeTp !== new_tp) {
- updateTpList.total_price = new_tp;
- updateFlag = true;
- }
- if (positive_tp !== changePp) {
- updateTpList.positive_tp = positive_tp;
- updateFlag = true;
- }
- if (negative_tp !== changeNp) {
- updateTpList.negative_tp = negative_tp;
- updateFlag = true;
- }
- if (valuation_tp !== changeVp) {
- updateTpList.valuation_tp = valuation_tp;
- updateFlag = true;
- }
- if (unvaluation_tp !== changeUp) {
- updateTpList.unvaluation_tp = unvaluation_tp;
- updateFlag = true;
- }
- if (updateFlag) {
- console.log(updateTpList);
- postData(window.location.pathname + '/save', { type:'update_tp', updateData: updateTpList }, function () {
- changePp = positive_tp;
- changeNp = negative_tp;
- changeVp = valuation_tp;
- changeUp = unvaluation_tp;
- changeTp = new_tp;
- });
- }
- }
- function checkAndChange(changeListData) {
- // 根据已添加的清单显示
- if (changeList.length > 0 && changeList[0]) {
- const removeList = [];
- const updateList = [];
- const updateGclIdList = [];
- for (const [index,clinfo] of changeList.entries()) {
- if (clinfo.lid != 0) {
- let listinfo = changeListData.find(function (item) {
- return (item.leafXmjs && item.leafXmjs.length > 0 && _.find(item.leafXmjs, {gcl_id: clinfo.lid })) || (item.id && item.id == clinfo.lid);
- });
- if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
- // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
- const newlistinfo = changeListData.find(function (item) {
- return (item.leafXmjs && item.leafXmjs.length > 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id })) || (item.id && item.id == clinfo.gcl_id);
- });
- if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
- listinfo = newlistinfo;
- updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
- // 更新lid
- changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
- }
- }
- if (listinfo === undefined) {
- // 针对旧数据获取清单信息
- listinfo = changeListData[clinfo.lid - 1];
- if (listinfo === undefined) {
- toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
- if (changeStatus !== auditConst.status.revise) {
- removeList.push(clinfo);
- } else {
- updateList.push(makeWhiteList(clinfo));
- }
- continue;
- }
- }
- const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
- if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
- // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
- const updateInfo = {};
- if (info.code !== clinfo.xmj_code) {
- updateInfo.xmj_code = info.code;
- changeList[index].xmj_code = info.code;
- }
- if (info.jldy !== clinfo.xmj_jldy) {
- updateInfo.xmj_jldy = info.jldy;
- changeList[index].xmj_jldy = info.jldy;
- }
- if (info.dwgc !== clinfo.xmj_dwgc) {
- updateInfo.xmj_dwgc = info.dwgc;
- changeList[index].xmj_dwgc = info.dwgc;
- }
- if (info.fbgc !== clinfo.xmj_fbgc) {
- updateInfo.xmj_fbgc = info.fbgc;
- changeList[index].xmj_fbgc = info.fbgc;
- }
- if (info.fxgc !== clinfo.xmj_fxgc) {
- updateInfo.xmj_fxgc = info.fxgc;
- changeList[index].xmj_fxgc = info.fxgc;
- }
- if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
- updateGclIdList.push(clinfo.gcl_id);
- // updateInfo.gcl_id = info.id;
- updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
- }
- }
- }
- }
- if(updateList.length > 0) {
- console.log(updateList);
- postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
- }, function () {
- });
- }
- if(removeList.length > 0) {
- console.log(removeList);
- _.pullAll(changeList, removeList);
- postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
- }, function () {
- });
- }
- }
- }
- function makePushBwmx(clinfo, listinfo, removeList, updateList) {
- let info = '';
- const checkKey = ['name', 'code', 'unit', 'unit_price'];
- const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
- if (listinfo.leafXmjs !== undefined) {
- const leafInfo = listinfo.leafXmjs.find(function (item) {
- // const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id)) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
- const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
- if (flag && item.code === clinfo.xmj_code) {
- return flag && item.code === clinfo.xmj_code;
- }
- return flag;
- });
- if (leafInfo) {
- const oneUpdate = { id: clinfo.id };
- let needUpdate = false;
- // 判断要不要更新名称,单位,原数量,单价
- checkKey.forEach(function (key) {
- if ((key === 'name' || key === 'unit') && listinfo[key] === null) {
- listinfo[key] = '';
- }
- if (listinfo[key] !== clinfo[key]) {
- oneUpdate[key] = listinfo[key];
- clinfo[key] = listinfo[key];
- if (key === 'unit') {
- const changeKey = ['oamount', 'oamount2', 'camount'];
- changeKey.forEach(function (key) {
- const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
- if (value !== clinfo[key]) {
- oneUpdate[key] = value;
- clinfo[key] = value;
- }
- });
- }
- // else if (key === 'unit_price') {
- // // 可能要更新总金额了
- // oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
- // clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
- // }
- needUpdate = true;
- }
- });
- checkLeafKey.forEach(function (key) {
- // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
- if (key === 'oamount') {
- if (leafInfo.quantity !== clinfo[key]) {
- oneUpdate[key] = leafInfo.quantity;
- clinfo[key] = leafInfo.quantity;
- needUpdate = true;
- }
- } else if (key === 'bwmx') {
- if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
- oneUpdate[key] = leafInfo[key];
- clinfo[key] = leafInfo[key];
- needUpdate = true;
- } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
- oneUpdate[key] = leafInfo.jldy;
- clinfo[key] = leafInfo.jldy;
- needUpdate = true;
- }
- } else {
- if (leafInfo[key] !== clinfo['xmj_' + key]) {
- oneUpdate['xmj_' + key] = leafInfo[key];
- clinfo['xmj_' + key] = leafInfo[key];
- needUpdate = true;
- }
- }
- });
- if (needUpdate) {
- updateList.push(oneUpdate);
- }
- info = leafInfo;
- } else {
- toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
- if (changeStatus !== auditConst.status.revise) {
- removeList.push(clinfo);
- } else {
- updateList.push(makeWhiteList(clinfo));
- }
- return false;
- }
- }
- return info;
- }
- function makeWhiteList(clinfo) {
- clinfo.lid = 0;
- clinfo.xmj_code = null;
- clinfo.xmj_jldy = null;
- clinfo.xmj_dwgc = null;
- clinfo.xmj_fbgc = null;
- clinfo.xmj_fxgc = null;
- clinfo.gcl_id = '';
- clinfo.mx_id = '';
- return clinfo;
- }
- function isObjEqual(o1,o2){
- var props1 = Object.getOwnPropertyNames(o1);
- var props2 = Object.getOwnPropertyNames(o2);
- if (props1.length != props2.length) {
- return false;
- }
- for (var i = 0,max = props1.length; i < max; i++) {
- var propName = props1[i];
- if (o1[propName] !== o2[propName]) {
- return false;
- }
- }
- return true;
- }
- function findDecimal(unit) {
- let value = precision.other.value;
- const changeUnits = precision;
- for (const d in changeUnits) {
- if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
- value = changeUnits[d].value;
- break;
- }
- }
- return value;
- }
- // 生成附件列表
- function getAllList(currPageNum = 1) {
- // 每页最多几个附件
- const pageCount = 20;
- // 附件总数
- const total = attData.length;
- // 总页数
- const pageNum = Math.ceil(total/pageCount);
- $('#totalPage').text(pageNum);
- $('#currentPage').text(total === 0 ? 0 : currPageNum);
- // 当前页附件内容
- const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
- currPageFileData = currPageAttData;
- let html = '';
- // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
- for(const [index,att] of currPageAttData.entries()) {
- html += `<tr>
- <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
- <td>${((currPageNum-1)*pageCount)+index+1}</td>
- <td><a href="${att.filepath}" target="_blank" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a></td>
- <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
- <td>
- <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
- html += (att.uid === accountId && ((changeStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true) || deleteFilePermission)) ?
- `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
- html += `</td>`;
- }
- $('#attList').html(html);
- $('#attList').on('click', 'tr', function() {
- $('#attList tr').removeClass('bg-light');
- $(this).addClass('bg-light');
- })
- }
- function bytesToSize(bytes) {
- if (parseInt(bytes) === 0) return '0 B';
- const k = 1024;
- const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
- const i = Math.floor(Math.log(bytes) / Math.log(k));
- // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
- return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
- }
- // 判断是否是已结算清单
- function checkIsSettle(data) {
- const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
- if (info && info.settle_status && info.settle_status === settleStatus.finish) {
- return true;
- }
- return false;
- }
|