change_information.js 315 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + ' ledger-Select';
  10. const ckChangeSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + 'change-Select';
  11. const is_numeric = (value) => {
  12. if (typeof(value) === 'object') {
  13. return false;
  14. } else {
  15. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  16. }
  17. };
  18. function sortByCode(a, b) {
  19. let code1 = a.code.split('-');
  20. let code2 = b.code.split('-');
  21. let code1length = code1.length;
  22. let code2length = code2.length;
  23. for (let i = 0; i < code1length; i ++) {
  24. if (i+1 <= code2length) {
  25. if (code1[i] != code2[i]) {
  26. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  27. return parseInt(code1[i]) - parseInt(code2[i]);
  28. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  29. return 1;
  30. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  31. return -1;
  32. } else {
  33. const str1length = code1[i].length;
  34. const str2length = code2[i].length;
  35. for (let j = 0; j < str1length; j++) {
  36. if (j+1 <= str2length) {
  37. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  38. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  39. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  40. if (str1length == str2length) {
  41. return 0;
  42. } else {
  43. return str1length - str2length;
  44. }
  45. }
  46. } else {
  47. if (j+1 >= str1length) {
  48. return 1;
  49. } else {
  50. return -1;
  51. }
  52. }
  53. }
  54. }
  55. } else if (i+1 == code1length && code1[i] == code2[i]) {
  56. if (code1length == code2length) {
  57. return 0;
  58. } else {
  59. return code1length - code2length;
  60. }
  61. }
  62. } else {
  63. if (i+1 >= code1length) {
  64. return 1;
  65. } else {
  66. return -1;
  67. }
  68. }
  69. }
  70. }
  71. $.event.special.valuechange = {
  72. teardown: function (namespaces) {
  73. $(this).unbind('.valuechange');
  74. },
  75. handler: function (e) {
  76. $.event.special.valuechange.triggerChanged($(this));
  77. },
  78. add: function (obj) {
  79. $(this).on('keyup.valuechange cut.valuechange paste.valuechange input.valuechange', obj.selector, $.event.special.valuechange.handler)
  80. },
  81. triggerChanged: function (element) {
  82. var current = element[0].contentEditable === 'true' ? element.html() : element.val()
  83. , previous = typeof element.data('previous') === 'undefined' ? element[0].defaultValue : element.data('previous');
  84. if (current !== previous) {
  85. element.trigger('valuechange', [element.data('previous')]);
  86. element.data('previous', current);
  87. }
  88. }
  89. };
  90. function getPasteHint (str, row = '') {
  91. let returnObj = str;
  92. if (row) {
  93. returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
  94. }
  95. return returnObj;
  96. }
  97. $(document).ready(() => {
  98. //初始化所有附件列表
  99. getAllList();
  100. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  101. if (changeStatus !== auditConst.status.checked) {
  102. calcChangePrice();
  103. }
  104. //tab change
  105. $('a[data-toggle="tab"]').on('shown.bs.tab', function () {
  106. const tab = $(this).data('tab');
  107. if (tab === 'bgfujian') {
  108. $('#fujian_btn').show();
  109. $('#copy_btn').hide();
  110. } else {
  111. $('#fujian_btn').hide();
  112. $('#copy_btn').show();
  113. }
  114. });
  115. $('#add-bj').on('click', 'input[type="checkbox"]', function () {
  116. const isCheck = $(this).prop('checked');
  117. if (isCheck) {
  118. $('#add-bj input[type="checkbox"]').each(function () {
  119. $(this).prop('checked', false)
  120. });
  121. $(this).prop('checked', true)
  122. }
  123. });
  124. $('#bg-copy').click(function() {
  125. const cid = $('#add-bj input:checked').data('id');
  126. postData(window.location.pathname + '/copy', cid, function () {
  127. window.location.reload();
  128. })
  129. });
  130. // 上传附件
  131. $('#upload-file-btn').click(function () {
  132. const files = $('#upload-file')[0].files;
  133. const formData = new FormData();
  134. formData.append('cid', $('#changeId').val());
  135. formData.append('tid', $('#tenderId').val());
  136. for (const file of files) {
  137. if (file === undefined) {
  138. toastr.error('未选择上传文件!');
  139. return false;
  140. }
  141. const filesize = file.size;
  142. if (filesize > 30 * 1024 * 1024) {
  143. toastr.error('文件大小过大!');
  144. return false;
  145. }
  146. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  147. if (whiteList.indexOf(fileext) === -1) {
  148. toastr.error('只能上传指定格式的附件!');
  149. return false;
  150. }
  151. formData.append('size', filesize);
  152. formData.append('file[]', file);
  153. }
  154. // if (!(change_uid === accountId || (auditors2 && auditors2.findIndex(item => item.uid === parseInt(accountId)) !== -1) || touristPermission)) {
  155. if (!filePermission) {
  156. return toastr.error('暂无权限上传!');
  157. }
  158. postDataWithFile(window.location.pathname + '/file/upload', formData, function (data) {
  159. attData = data.concat(attData);
  160. // 重新生成List
  161. getAllList();
  162. $('#addfujian').modal('hide');
  163. // let html = '';
  164. // let index = $('#attList tr').length + 1;
  165. // for (const fileInfo of data) {
  166. // html += '<tr> ' +
  167. // `<td width="20"><input type="checkbox" class="check-file" file-id=${fileInfo.id}></td>` +
  168. // '<td>' + index + '</td> ' +
  169. // `<td><a href="javascript: void(0);" class="file-atn" f-id="${fileInfo.id}">${fileInfo.filename}${fileInfo.fileext}</a></td>`+
  170. // '<td>' + fileInfo.in_time + '<br>' + fileInfo.filesize + '</td> ' +
  171. // `<td><a href="/change/download/file/${fileInfo.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`+
  172. // ( auditStatus === 4 ?
  173. // fileInfo.extra_upload ? `<a class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : ''
  174. // : ` <a href="javascript:void(0);" class="mr-2 delete-file" data-attid="${fileInfo.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>`)+
  175. // `</td>`+
  176. // // '<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> ' +
  177. // '</tr>';
  178. // ++index;
  179. // }
  180. // $('#attList').append(html);
  181. }, function () {
  182. });
  183. $('#upload-file').val('');
  184. });
  185. // 删除附件
  186. $('body').on('click', '.delete-file', function () {
  187. let attid = $(this).data('attid');
  188. let self = $(this);
  189. const data = {id: attid};
  190. postData(window.location.pathname + '/file/delete', data, function (result) {
  191. // self.parents('tr').remove();
  192. // // 重新排序
  193. // let newsort = 1;
  194. // $('#attList tr').each(function(){
  195. // $(this).children('td').eq(1).text(newsort);
  196. // newsort++;
  197. // });
  198. // 删除到attData中
  199. const att_index = attData.findIndex(function (item) {
  200. return item.id === parseInt(attid);
  201. });
  202. attData.splice(att_index, 1);
  203. // 重新生成List
  204. if ($('#attList tr').length === 1) {
  205. getAllList(parseInt($('#currentPage').text()) - 1);
  206. } else {
  207. getAllList(parseInt($('#currentPage').text()));
  208. }
  209. });
  210. });
  211. // /change/download/file/
  212. $('#attList').on('click', '.file-atn', function() {
  213. const id = $(this).attr('f-id');
  214. postData(`/change/download/file/${id}`, {}, (data) => {
  215. const { filepath } = data;
  216. $('#file-upload').attr('href', filepath);
  217. $('#file-upload')[0].click();
  218. })
  219. });
  220. $('#attList').on('click', '.check-file', function() {
  221. const checkedList = $('#attList').find('input:checked');
  222. const childs = $('#attList').children().length;
  223. const checkBox = $('#check-all-file');
  224. if (checkedList.length === childs) {
  225. checkBox.prop("checked", true);
  226. } else {
  227. checkBox.prop("checked", false);
  228. }
  229. });
  230. $('#check-all-file').click(function() {
  231. const isCheck = $(this).is(':checked');
  232. $('#attList').children().each(function() {
  233. $(this).find('input:checkbox').prop("checked", isCheck);
  234. })
  235. });
  236. $('#bach-download').click(function() {
  237. const fileIds = [];
  238. $( '#attList .check-file:checked').each(function() {
  239. const fileId = $(this).attr('file-id');
  240. fileId && fileIds.push(fileId);
  241. });
  242. if (fileIds.length) {
  243. // const tid = $('#tenderId').val();
  244. // const cid = $('#changeId').val();
  245. // $('#downloadZip').attr('href', `/tender/${tid}/change/${cid}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`);
  246. // $('#downloadZip')[0].click();
  247. if (fileIds.length > 20) {
  248. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`);
  249. }
  250. const tid = $('#tenderId').val();
  251. const cid = $('#changeId').val();
  252. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0});
  253. $(this).attr('disabled', "true");
  254. const btn = $(this);
  255. const fileArr = [];
  256. for (const id of fileIds) {
  257. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  258. fileArr.push({
  259. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  260. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  261. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  262. });
  263. }
  264. const packageName = `${tenderName}-工程变更-${changeName}-附件.zip`;
  265. try {
  266. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  267. } catch (e) {
  268. btn.removeAttr('disabled');
  269. toastr.clear();
  270. toastr.error('批量下载失败');
  271. }
  272. // postCompressFile(`/tender/${tid}/change/${cid}/download/compresse-file`, {fileIds}, function(result) {
  273. // toastr.clear();
  274. // toastr.success('压缩文件成功');
  275. // btn.removeAttr('disabled');
  276. // const href = window.URL.createObjectURL(result);
  277. // $('#zipDown').attr('href', href);
  278. // $('#zipDown').attr('download', `${tenderName}-工程变更-${changeName}-附件.zip`);
  279. // $("#zipDown")[0].click();
  280. // }, () => {
  281. // btn.removeAttr('disabled');
  282. // toastr.clear();
  283. // toastr.error('批量下载失败');
  284. // });
  285. }
  286. });
  287. // 差值对比信息获取
  288. let czSpread = null;
  289. const czSpreadSetting = {
  290. cols: [
  291. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
  292. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  293. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
  294. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  295. {title: '变更方案|数量', colSpan: '2|1', rowSpan: '1|1', field: 'pamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.pamount'},
  296. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'pa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.pa_tp'},
  297. {title: '变更令|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  298. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
  299. {title: '差值对比|数量', colSpan: '2|1', rowSpan: '1|1', field: 'czamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.czamount'},
  300. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'cz_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.cz_tp'},
  301. ],
  302. emptyRows: 0,
  303. headRows: 2,
  304. headRowHeight: [25, 25],
  305. defaultRowHeight: 21,
  306. headerFont: '12px 微软雅黑',
  307. font: '12px 微软雅黑',
  308. readOnly: true,
  309. localCache: {
  310. key: 'changes-cz',
  311. colWidth: true,
  312. }
  313. };
  314. const czCol = {
  315. getValue: {
  316. unit_price: function(data) {
  317. return ZhCalc.round(data.unit_price, unitPriceUnit);
  318. },
  319. pa_tp: function (data) {
  320. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.pamount, findDecimal(data.unit))), totalPriceUnit);
  321. },
  322. ca_tp: function (data) {
  323. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  324. },
  325. pamount: function (data) {
  326. return ZhCalc.round(data.pamount, findDecimal(data.unit));
  327. },
  328. camount: function (data) {
  329. return ZhCalc.round(data.camount, findDecimal(data.unit));
  330. },
  331. czamount: function (data) {
  332. return ZhCalc.sub(ZhCalc.round(data.camount, findDecimal(data.unit)), ZhCalc.round(data.pamount, findDecimal(data.unit)));
  333. },
  334. cz_tp: function (data) {
  335. 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);
  336. },
  337. }
  338. };
  339. const czSpreadObj = {
  340. makeBackColor: function () {
  341. const rowCount = czSpread.getActiveSheet().getRowCount();
  342. for (let i = 0; i < rowCount; i++) {
  343. if (czSpread.getActiveSheet().zh_data[i].color) czSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#f5c6cb');
  344. }
  345. },
  346. makeSjsFooter: function () {
  347. // 增加汇总行并设为锁定禁止编辑状态
  348. czSpread.getActiveSheet().addRows(czSpread.getActiveSheet().getRowCount(), 1);
  349. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
  350. czSpread.getActiveSheet().setStyle(czSpread.getActiveSheet().getRowCount() - 1, -1, style1);
  351. czSpreadObj.countSum();
  352. },
  353. countSum: function () {
  354. const rowCount = czSpread.getActiveSheet().getRowCount();
  355. let pSum = 0,
  356. cSum = 0,
  357. czSum = 0;
  358. for (let i = 0; i < rowCount - 1; i++) {
  359. pSum = ZhCalc.add(pSum, czSpread.getActiveSheet().getValue(i, 5));
  360. cSum = ZhCalc.add(cSum, czSpread.getActiveSheet().getValue(i, 7));
  361. czSum = ZhCalc.add(czSum, czSpread.getActiveSheet().getValue(i, 9));
  362. }
  363. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 5, pSum !== 0 ? pSum : null);
  364. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
  365. czSpread.getActiveSheet().setValue(czSpread.getActiveSheet().getRowCount() - 1, 9, czSum !== 0 ? czSum : null);
  366. },
  367. };
  368. $('#bgfadb').on('shown.bs.modal', function () {
  369. if (!czSpread) {
  370. czSpread = SpreadJsObj.createNewSpread($('#cz-spread')[0]);
  371. SpreadJsObj.initSpreadSettingEvents(czSpreadSetting, czCol);
  372. SpreadJsObj.initSheet(czSpread.getActiveSheet(), czSpreadSetting);
  373. }
  374. const cList = [];
  375. const newChangeList = _.cloneDeep(changeList);
  376. for (const cl of newChangeList) {
  377. const cIndex = _.findIndex(cList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
  378. if (cIndex !== -1) {
  379. cList[cIndex].spamount = ZhCalc.add(cList[cIndex].spamount, cl.spamount);
  380. } else {
  381. cList.push(cl);
  382. }
  383. }
  384. // 生成差值对比数据列表
  385. const czList = [];
  386. const newPlanList = _.cloneDeep(planList);
  387. for (const c of cList) {
  388. const planInfo = _.find(newPlanList, { code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price });
  389. const pamount = planInfo ? planInfo.spamount : null;
  390. let color = true;
  391. if (planInfo) {
  392. _.remove(newPlanList, (item) => item === planInfo);
  393. if ((pamount ? pamount : 0) === (c.spamount ? c.spamount : 0)) {
  394. color = false;
  395. }
  396. }
  397. czList.push({ code: c.code, name: c.name, unit: c.unit, unit_price: c.unit_price, camount: c.spamount, pamount, color });
  398. }
  399. if (newPlanList.length > 0) {
  400. for (const np of newPlanList) {
  401. czList.push({ code: np.code, name: np.name, unit: np.unit, unit_price: np.unit_price, camount: null, pamount: np.spamount, color: true });
  402. }
  403. }
  404. if (czList.length > 0) {
  405. // 按清单编号排序
  406. czList.sort(sortByCode);
  407. }
  408. console.log(czList);
  409. // sjs设置
  410. SpreadJsObj.loadSheetData(czSpread.getActiveSheet(), SpreadJsObj.DataType.Data, czList);
  411. czSpreadObj.makeBackColor();
  412. czSpreadObj.makeSjsFooter();
  413. });
  414. // 清单汇总信息获取
  415. let hzSpread = null;
  416. const hzSpreadSetting = {
  417. cols: [
  418. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80},
  419. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  420. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60},
  421. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price'},
  422. {title: '申报变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount'},
  423. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp'},
  424. {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'amount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.amount', visible: readOnly && !shenpiPower},
  425. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'a_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.a_tp', visible: readOnly && !shenpiPower},
  426. {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'spamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.spamount', visible: readOnly && shenpiPower},
  427. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'spa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.spa_tp', visible: readOnly && shenpiPower},
  428. {title: '审批变更|数量', colSpan: '2|1', rowSpan: '1|1', hAlign: 2, width: 60, type: 'Number', getValue: '', visible: !readOnly},
  429. {title: '|金额', colSpan: '|1', rowSpan: '|1', hAlign: 2, width: 80, type: 'Number', getValue: '', visible: !readOnly},
  430. ],
  431. emptyRows: 0,
  432. headRows: 2,
  433. headRowHeight: [25, 25],
  434. defaultRowHeight: 21,
  435. headerFont: '12px 微软雅黑',
  436. font: '12px 微软雅黑',
  437. readOnly: true,
  438. localCache: {
  439. key: 'changes-hz',
  440. colWidth: true,
  441. }
  442. };
  443. const hzCol = {
  444. getValue: {
  445. unit_price: function(data) {
  446. return ZhCalc.round(data.unit_price, unitPriceUnit);
  447. },
  448. camount: function (data) {
  449. return ZhCalc.round(data.camount, findDecimal(data.unit));
  450. },
  451. ca_tp: function (data) {
  452. return ZhCalc.round(data.ca_tp, totalPriceUnit);
  453. },
  454. amount: function (data) {
  455. return ZhCalc.round(data.amount, findDecimal(data.unit));
  456. },
  457. a_tp: function (data) {
  458. return ZhCalc.round(data.a_tp, totalPriceUnit);
  459. },
  460. spamount: function (data) {
  461. return ZhCalc.round(data.spamount, findDecimal(data.unit));
  462. },
  463. spa_tp: function (data) {
  464. return ZhCalc.round(data.spa_tp, totalPriceUnit);
  465. },
  466. }
  467. };
  468. const hzSpreadObj = {
  469. makeBackColor: function () {
  470. const rowCount = hzSpread.getActiveSheet().getRowCount();
  471. for (let i = 0; i < rowCount; i++) {
  472. if (readOnly && shenpiPower && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].spamount) {
  473. hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
  474. } else if (readOnly && !shenpiPower && hzSpread.getActiveSheet().zh_data[i].camount != hzSpread.getActiveSheet().zh_data[i].amount) {
  475. hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
  476. } else if (!readOnly && !(hzSpread.getActiveSheet().zh_data[i].camount === '' || hzSpread.getActiveSheet().zh_data[i].camount === 0 || hzSpread.getActiveSheet().zh_data[i].camount === null)) {
  477. hzSpread.getActiveSheet().getRange(i, -1, 1, -1).backColor('#ffeeba');
  478. }
  479. }
  480. },
  481. makeSjsFooter: function () {
  482. // 增加汇总行并设为锁定禁止编辑状态
  483. hzSpread.getActiveSheet().addRows(hzSpread.getActiveSheet().getRowCount(), 1);
  484. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 0, '合计');
  485. hzSpread.getActiveSheet().setStyle(hzSpread.getActiveSheet().getRowCount() - 1, -1, style1);
  486. hzSpreadObj.countSum();
  487. },
  488. countSum: function () {
  489. const rowCount = hzSpread.getActiveSheet().getRowCount();
  490. let cSum = 0,
  491. sSum = 0,
  492. spSum = 0;
  493. for (let i = 0; i < rowCount - 1; i++) {
  494. cSum = ZhCalc.add(cSum, hzSpread.getActiveSheet().getValue(i, 5));
  495. sSum = ZhCalc.add(sSum, hzSpread.getActiveSheet().getValue(i, 7));
  496. spSum = ZhCalc.add(spSum, hzSpread.getActiveSheet().getValue(i, 9));
  497. }
  498. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 5, cSum !== 0 ? cSum : null);
  499. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 7, sSum !== 0 ? sSum : null);
  500. hzSpread.getActiveSheet().setValue(hzSpread.getActiveSheet().getRowCount() - 1, 9, spSum !== 0 ? spSum : null);
  501. },
  502. };
  503. $('#qdgather').on('shown.bs.modal', function () {
  504. if (!hzSpread) {
  505. hzSpread = SpreadJsObj.createNewSpread($('#hz-spread')[0]);
  506. SpreadJsObj.initSpreadSettingEvents(hzSpreadSetting, hzCol);
  507. SpreadJsObj.initSheet(hzSpread.getActiveSheet(), hzSpreadSetting);
  508. }
  509. const hzList = [];
  510. const newChangeList = _.cloneDeep(changeList);
  511. for (const cl of newChangeList) {
  512. const hzIndex = _.findIndex(hzList, { code: cl.code, name: cl.name, unit: cl.unit, unit_price: cl.unit_price});
  513. const audit_amount = cl.audit_amount ? cl.audit_amount.split(',') : '';
  514. const amount = audit_amount ? parseFloat(audit_amount[audit_amount.length - 1]) : 0;
  515. cl.ca_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.camount, findDecimal(cl.unit))), totalPriceUnit);
  516. cl.spa_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.spamount, findDecimal(cl.unit))), totalPriceUnit);
  517. cl.amount = amount;
  518. cl.a_tp = ZhCalc.round(ZhCalc.mul(ZhCalc.round(cl.unit_price, unitPriceUnit), ZhCalc.round(cl.amount, findDecimal(cl.unit))), totalPriceUnit);
  519. if (hzIndex !== -1) {
  520. hzList[hzIndex].camount = ZhCalc.add(hzList[hzIndex].camount, cl.camount);
  521. hzList[hzIndex].ca_tp = ZhCalc.add(hzList[hzIndex].ca_tp, cl.ca_tp);
  522. hzList[hzIndex].spamount = ZhCalc.add(hzList[hzIndex].spamount, cl.spamount);
  523. hzList[hzIndex].spa_tp = ZhCalc.add(hzList[hzIndex].spa_tp, cl.spa_tp);
  524. hzList[hzIndex].amount = ZhCalc.add(hzList[hzIndex].amount, amount);
  525. hzList[hzIndex].a_tp = ZhCalc.add(hzList[hzIndex].a_tp, cl.a_tp);
  526. } else {
  527. hzList.push(cl);
  528. }
  529. }
  530. if (hzList.length > 0) {
  531. // 按清单编号排序
  532. hzList.sort(sortByCode);
  533. }
  534. console.log(hzList);
  535. // // sjs设置
  536. SpreadJsObj.loadSheetData(hzSpread.getActiveSheet(), SpreadJsObj.DataType.Data, hzList);
  537. hzSpreadObj.makeBackColor();
  538. hzSpreadObj.makeSjsFooter();
  539. });
  540. // 切换页数
  541. $('.page-select').on('click', function () {
  542. const totalPageNum = parseInt($('#totalPage').text());
  543. const lastPageNum = parseInt($('#currentPage').text());
  544. const status = $(this).attr('content');
  545. if (status === 'pre' && lastPageNum > 1) {
  546. getAllList(lastPageNum-1);
  547. $('#showAttachment').hide();
  548. $('#syfujian .check-all-file').prop('checked', false)
  549. } else if (status === 'next' && lastPageNum < totalPageNum) {
  550. getAllList(lastPageNum+1);
  551. $('#showAttachment').hide();
  552. $('#syfujian .check-all-file').prop('checked', false)
  553. }
  554. });
  555. // 数字只判断几个值(unit_price, oamount)
  556. const numField = ['unit_price', 'oamount2'];
  557. const changeSpreadSetting = {
  558. cols: [
  559. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
  560. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
  561. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  562. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  563. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  564. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  565. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isSettle2'},
  566. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
  567. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  568. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  569. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  570. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  571. // {title: '变更后|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},
  572. // {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'},
  573. // {title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'},
  574. ],
  575. emptyRows: 0,
  576. headRows: 2,
  577. headRowHeight: [25, 25],
  578. defaultRowHeight: 21,
  579. headerFont: '12px 微软雅黑',
  580. font: '12px 微软雅黑',
  581. rowHeader:[
  582. {
  583. rowHeaderType: 'circle',
  584. setting: {
  585. size: 5,
  586. indent: 16,
  587. getColor: function (index, data) {
  588. if (!data) return;
  589. if (data.ccid && data.ccid === 1) {
  590. return '#dc3545';
  591. }
  592. if (data.id && data.lid != 0 && !data.children) {
  593. return '#ffc107';
  594. }
  595. if(data.lid != 0) return;
  596. return '#007bff';
  597. }
  598. },
  599. },
  600. ],
  601. localCache: {
  602. key: 'changes-spread',
  603. colWidth: true,
  604. }
  605. };
  606. if (readOnly) {
  607. changeSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
  608. changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
  609. for (const aid of aidList) {
  610. // const userinfo = _.find(auditList2, { 'uid': aid });
  611. const audit = _.find(auditors2, function(item){
  612. return _.findIndex(item, { audit_order: aid }) !== -1;
  613. });
  614. const newColcount = {
  615. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  616. colSpan: '2|1', rowSpan: '1|1',
  617. field: 'audit_amount_' + aid,
  618. hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
  619. };
  620. const newColTp = {
  621. title: '|金额',
  622. colSpan: '|1', rowSpan: '|1',
  623. field: 'sa_tp_' + aid,
  624. hAlign: 2, width: 80, type: 'Number',
  625. };
  626. changeSpreadSetting.cols.push(newColcount);
  627. changeSpreadSetting.cols.push(newColTp);
  628. }
  629. }
  630. 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'});
  631. changeSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
  632. // if (!readOnly) {
  633. // changeSpreadSetting.cols.push({title: '操作', colSpan: '1', rowSpan: '2', field: 'del_list', hAlign: 1, width: 40, readOnly: true, cellType: 'mouseTouch', getValue: 'getValue.del_list'});
  634. // }
  635. changeSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  636. return checkIsSettle(data) ? spreadColor.stage.settle : defaultColor;
  637. }
  638. const changeCol = {
  639. getValue: {
  640. unit_price: function(data) {
  641. return ZhCalc.round(data.unit_price, unitPriceUnit);
  642. },
  643. oa_tp: function (data) {
  644. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit);
  645. },
  646. ca_tp: function (data) {
  647. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  648. },
  649. oamount2: function (data) {
  650. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  651. },
  652. camount: function (data) {
  653. return ZhCalc.round(data.camount, findDecimal(data.unit));
  654. },
  655. changed_amount: function (data) {
  656. return ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
  657. },
  658. changed_tp: function (data) {
  659. return ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
  660. ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit));
  661. },
  662. // del_list: function (data) {
  663. // return !_.find(changeUsedData, { cbid: data.id }) && !checkIsSettle(data) ? '移除' : '';
  664. // }
  665. },
  666. readOnly: {
  667. isValuation: function (data) {
  668. return !(!readOnly && ((data.id && _.findIndex(changeUsedData, { cbid: data.id }) !== -1) || (data.children && data.children.length === 1 && _.findIndex(changeUsedData, { cbid: data.children[0].id }) !== -1)));
  669. },
  670. isEdit: function (data) {
  671. return !(!readOnly && data.lid == 0 && data.id && !checkIsSettle(data));
  672. },
  673. isSettle: function (data) {
  674. return !((!readOnly || shenpiPower) && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
  675. },
  676. isSettle2: function (data) {
  677. return !(!readOnly && ((data.id && !checkIsSettle(data)) || (data.children && data.children.length === 1 && !checkIsSettle(data.children[0]))));
  678. }
  679. },
  680. };
  681. const changeSpreadObj = {
  682. makeSjsFooter: function () {
  683. // 增加汇总行并设为锁定禁止编辑状态
  684. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  685. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  686. const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
  687. changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
  688. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  689. changeSpreadObj.countSum();
  690. },
  691. setAuditValue: function () {
  692. if (readOnly) {
  693. for (const c of changeList) {
  694. for (const j of aidList) {
  695. c['audit_amount_' + j] = ZhCalc.round(c['audit_amount_' + j], findDecimal(c.unit));
  696. c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
  697. }
  698. }
  699. }
  700. },
  701. loadExprToInput: function () {
  702. const sel = changeSpreadSheet.getSelections()[0];
  703. if (!sel) return;
  704. const col = changeSpreadSheet.zh_setting.cols[sel.col];
  705. const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
  706. if (col && col.field === 'camount' && data && (!data.gcl_id || (data.children && data.children.length === 1))) {
  707. if (readOnly) {
  708. $('#camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  709. } else {
  710. $('#camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
  711. }
  712. } else {
  713. $('#camount-expr').attr('readonly', true).val('');
  714. }
  715. },
  716. topRowChanged: function (e, info) {
  717. SpreadJsObj.saveTopAndSelect(info.sheet, ckChangeSpread);
  718. },
  719. selectionChanged: function (e, info) {
  720. if (info.newSelections) {
  721. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  722. const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
  723. if (info.oldSelections && info.oldSelections[0].row !== changeSpreadSheet.getRowCount() - 1) {
  724. info.sheet.getRange(info.oldSelections[0].row, -1, 1, -1).backColor('#fff');
  725. }
  726. if (!data) {
  727. SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, []);
  728. return;
  729. }
  730. changeSpreadObj.refreshXmjData();
  731. if (!readOnly) changeSpreadObj.refreshActn();
  732. }
  733. }
  734. changeSpreadObj.loadExprToInput();
  735. },
  736. showHideAudit: function (show = false) {
  737. if (shenpiPower) {
  738. show = true;
  739. }
  740. if (readOnly) {
  741. const count = changeSpreadSetting.cols.length;
  742. for (let i = startLimit + 5; i < count - 2; i++) {
  743. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  744. }
  745. changeSpreadSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
  746. changeSpreadSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
  747. }
  748. },
  749. calcOneSum: function (node) {
  750. if (node.children && node.children.length > 0) {
  751. if (readOnly) {
  752. for (const aid of aidList) {
  753. let audit_amount = 0;
  754. for (const c of node.children) {
  755. audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(c['audit_amount_' + aid], findDecimal(node.unit)));
  756. }
  757. if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
  758. node['audit_amount_' + aid] = audit_amount;
  759. }
  760. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
  761. }
  762. }
  763. let is_valuation = 1;
  764. let ccid = 0;
  765. let oamount2 = 0;
  766. let camount = 0;
  767. let samount = 0;
  768. let spamount = 0;
  769. for (const c of node.children) {
  770. oamount2 = ZhCalc.add(oamount2, ZhCalc.round(c.oamount2, findDecimal(node.unit)));
  771. camount = ZhCalc.add(camount, ZhCalc.round(c.camount, findDecimal(node.unit)));
  772. samount = ZhCalc.add(samount, ZhCalc.round(c.samount, findDecimal(node.unit)));
  773. spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(node.unit)));
  774. if (c.is_valuation === 0) is_valuation = 0;
  775. if (_.findIndex(changeLedgerList, { id: c.gcl_id }) !== -1 || _.findIndex(changePosList, { id: c.mx_id }) !== -1) {
  776. ccid = 1;
  777. }
  778. c.order = node.order;
  779. }
  780. if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
  781. node.oamount2 = oamount2;
  782. node.camount = camount;
  783. node.samount = samount;
  784. node.spamount = spamount;
  785. node.change_amount = ZhCalc.add(oamount2, camount);
  786. }
  787. node.is_valuation = is_valuation;
  788. node.ccid = ccid;
  789. this.calcNodeTp(node);
  790. } else {
  791. if (readOnly) {
  792. for (const aid of aidList) {
  793. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
  794. }
  795. }
  796. this.calcNodeTp(node);
  797. }
  798. return node;
  799. },
  800. calcNodeTp: function (node) {
  801. node.change_amount = ZhCalc.add(node.oamount2, node.camount);
  802. node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  803. node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  804. node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  805. const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  806. node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
  807. },
  808. refreshXmjData: function() {
  809. SpreadJsObj.resetTopAndSelect(xmjSheet);
  810. xmjSpreadObj.loadCurXmjData();
  811. SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
  812. // posSearch.search($('#pos-keyword').val());
  813. },
  814. makeNewChangeList: function(newOrder = changeOrder) {
  815. // 先加载台账数据
  816. if (!newOrder) {
  817. const newChangeList2 = [];
  818. for (const gcl of changeListData) {
  819. if (!newOrder) {
  820. if (gcl.leafXmjs !== undefined && gcl.leafXmjs !== null) {
  821. const cl = _.filter(changeList, function (item) {
  822. return _.findIndex(gcl.leafXmjs, { gcl_id: item.gcl_id }) !== -1;
  823. });
  824. if (cl.length > 0) {
  825. for (const l of gcl.leafXmjs) {
  826. const c = _.find(cl, { gcl_id: l.gcl_id, mx_id: l.mx_id || '' });
  827. if (c) newChangeList2.push(c);
  828. }
  829. }
  830. } else {
  831. // 签约清单
  832. const c = _.find(changeList, { lid: gcl.id });
  833. if (c) newChangeList2.push(c);
  834. }
  835. }
  836. }
  837. // 按台账去重新排序changeList,空白清单居后
  838. const sycList = _.difference(changeList, newChangeList2);
  839. changeList = newChangeList2.concat(sycList);
  840. }
  841. const newChangeList = [];
  842. for (const cl of changeList) {
  843. const newCl = _.cloneDeep(cl);
  844. if (cl.gcl_id && _.findIndex(newChangeList, { gcl_id: cl.gcl_id }) === -1) {
  845. // delete newCl.id;
  846. // newCl.bwmx = '';
  847. // newCl.detail = '';
  848. // newCl.delimit = null;
  849. newCl.children = [];
  850. newCl.children.push(cl);
  851. if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
  852. newCl.ccid = 1;
  853. }
  854. newChangeList.push(newCl);
  855. } else if (!cl.gcl_id) {
  856. newChangeList.push(newCl);
  857. } else {
  858. const newCl2 = _.find(newChangeList, { gcl_id: cl.gcl_id });
  859. if (newCl2) {
  860. if (_.findIndex(changeLedgerList, { id: newCl.gcl_id }) !== -1 || _.findIndex(changePosList, { id: newCl.mx_id }) !== -1) {
  861. newCl2.ccid = 1;
  862. }
  863. delete newCl2.id;
  864. newCl2.bwmx = '';
  865. newCl2.detail = '';
  866. newCl2.delimit = null;
  867. newCl2.children.push(newCl);
  868. }
  869. }
  870. }
  871. const updateOrderList = [];
  872. // order如果不同,则修改并提交
  873. let i = 0;
  874. // 重算金额和数量汇总
  875. for (const node of newChangeList) {
  876. if (node.children && node.children.length > 0) {
  877. changeSpreadObj.calcOneSum(node);
  878. node.order = i + 1;
  879. const cls = node.gcl_id ? _.filter(changeList, { gcl_id: node.gcl_id }) : [];
  880. for (const c of cls) {
  881. if (node.order !== c.order) {
  882. c.order = node.order;
  883. updateOrderList.push({ id: c.id, order: node.order });
  884. }
  885. }
  886. } else {
  887. if (node.order !== i + 1) {
  888. node.order = i + 1;
  889. updateOrderList.push({ id: node.id, order: node.order });
  890. }
  891. changeSpreadObj.calcOneSum(node);
  892. if (readOnly) {
  893. for (const aid of aidList) {
  894. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  895. }
  896. }
  897. }
  898. i++;
  899. }
  900. return [newChangeList, updateOrderList];
  901. },
  902. countSum: function () {
  903. const rowCount = changeSpreadSheet.getRowCount();
  904. let oa_tp = 0,
  905. ca_tp = 0,
  906. sa_tp = 0,
  907. changed_tp = 0;
  908. const aidLength = readOnly ? aidList.length : 0;
  909. for (const data of changeSpreadSheet.zh_data) {
  910. oa_tp = ZhCalc.add(oa_tp, data.oa_tp);
  911. ca_tp = ZhCalc.add(ca_tp, data.ca_tp);
  912. sa_tp = ZhCalc.add(sa_tp, data.sa_tp);
  913. changed_tp = ZhCalc.add(changed_tp, data.changed_tp);
  914. }
  915. changeSpreadSheet.setValue(rowCount - 1, startLimit, oa_tp !== 0 ? oa_tp : null);
  916. changeSpreadSheet.setValue(rowCount - 1, startLimit + 2, ca_tp !== 0 ? ca_tp : null);
  917. if (readOnly) {
  918. changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), sa_tp !== 0 ? sa_tp : null);
  919. changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4 + aidLength * 2 + 2), changed_tp !== 0 ? changed_tp : null);
  920. } else {
  921. changeSpreadSheet.setValue(rowCount - 1, (startLimit + 4), changed_tp !== 0 ? changed_tp : null);
  922. }
  923. if (readOnly) {
  924. // 用户的数据合计
  925. for (const j in aidList) {
  926. let audit_sum = 0;
  927. for (const data of changeSpreadSheet.zh_data) {
  928. audit_sum = ZhCalc.add(audit_sum, data['sa_tp_' + aidList[j]]);
  929. }
  930. changeSpreadSheet.setValue(rowCount - 1, startLimit + 6 + j * 2, audit_sum !== 0 ? audit_sum : null);
  931. }
  932. }
  933. },
  934. reloadRow: function (sheet, row, rowCount = 0, clearAll = false) {
  935. if (rowCount) {
  936. SpreadJsObj.reLoadRowData(sheet, row, rowCount);
  937. } else {
  938. SpreadJsObj.reLoadRowData(sheet, row);
  939. }
  940. if (clearAll) {
  941. for (const i in sheet.zh_data) {
  942. const data = sheet.zh_data[i];
  943. if (data) {
  944. sheet.getRange(i, -1, 1, -1).backColor('#fff');
  945. }
  946. }
  947. }
  948. sheet.getRange(row, -1, 1, -1).backColor('#fffacd');
  949. },
  950. reloadSheet: function (newChangeList) {
  951. changeSpreadObj.setAuditValue();
  952. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, newChangeList);
  953. SpreadJsObj.loadTopAndSelect(changeSpreadSheet, ckChangeSpread);
  954. changeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  955. changeSpreadObj.makeSjsFooter();
  956. xmjSpreadObj.loadCurXmjData();
  957. changeSpreadObj.loadExprToInput();
  958. if (!readOnly) changeSpreadObj.refreshActn();
  959. }
  960. };
  961. // sjsSettingObj.setGridSelectStyle(changeSpreadSetting);
  962. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  963. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  964. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  965. let changeListData;
  966. let gclGatherData;
  967. postData(preUrl + '/defaultBills', {}, function (result) {
  968. ledgerList = result.bills;
  969. posList = result.pos;
  970. gclGatherModel.loadLedgerData(result.bills);
  971. gclGatherModel.loadPosData(result.pos);
  972. gclGatherData = gclGatherModel.gatherGclData();
  973. gclGatherData = _.filter(gclGatherData, function (item) {
  974. return item.leafXmjs && item.leafXmjs.length !== 0;
  975. });
  976. for (const ggd in gclGatherData) {
  977. if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
  978. gclGatherData.splice(ggd, 1);
  979. }
  980. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  981. let hadcid = 0;
  982. for (const xmj of gclGatherData[ggd].leafXmjs) {
  983. const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
  984. const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
  985. if (changeLedger || changePos) {
  986. xmj.cid = 1;
  987. xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
  988. hadcid = 1;
  989. }
  990. }
  991. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  992. }
  993. console.log(gclGatherData);
  994. // 数组去重
  995. const dealBillList = result.dealBills;
  996. for (const db of gclGatherData) {
  997. const exist_index = dealBillList.findIndex(function (item) {
  998. return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  999. });
  1000. if (exist_index !== -1) {
  1001. dealBillList.splice(exist_index, 1);
  1002. }
  1003. }
  1004. changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
  1005. if (!readOnly || shenpiPower) {
  1006. checkAndChange(changeListData);
  1007. }
  1008. showMode(changeMode);
  1009. });
  1010. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  1011. changeSpread.bind(spreadNS.Events.topRowChanged, changeSpreadObj.topRowChanged);
  1012. // 项目节信息获取
  1013. const xmjSpreadSetting = {
  1014. cols: [
  1015. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
  1016. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80, readOnly: true},
  1017. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
  1018. {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100, readOnly: true},
  1019. {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100, readOnly: true},
  1020. {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100, readOnly: true},
  1021. {title: '分项工程', colSpan: '1', rowSpan: '2', field: 'xmj_fxgc', hAlign: 0, width: 100, readOnly: true},
  1022. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 100, readOnly: true},
  1023. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  1024. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
  1025. {title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  1026. {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  1027. // {title: '数量', colSpan: '1', rowSpan: '2', field: 'oamount', hAlign: 2, width: 80},
  1028. ],
  1029. emptyRows: 0,
  1030. headRows: 2,
  1031. headRowHeight: [25, 25],
  1032. defaultRowHeight: 21,
  1033. headerFont: '12px 微软雅黑',
  1034. font: '12px 微软雅黑',
  1035. // readOnly: true,
  1036. rowHeader:[
  1037. {
  1038. rowHeaderType: 'circle',
  1039. setting: {
  1040. size: 5,
  1041. indent: 16,
  1042. getColor: function (index, data) {
  1043. if (!data) return;
  1044. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  1045. return '#dc3545';
  1046. }
  1047. }
  1048. },
  1049. },
  1050. ],
  1051. localCache: {
  1052. key: 'changes-xmj',
  1053. colWidth: true,
  1054. }
  1055. };
  1056. if (readOnly) {
  1057. xmjSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
  1058. for (const aid of aidList) {
  1059. const audit = _.find(auditors2, function(item){
  1060. return _.findIndex(item, { audit_order: aid }) !== -1;
  1061. });
  1062. const newColcount = {
  1063. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  1064. colSpan: '1|1', rowSpan: '|1',
  1065. field: 'audit_amount_' + aid,
  1066. hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
  1067. };
  1068. xmjSpreadSetting.cols.push(newColcount);
  1069. }
  1070. }
  1071. xmjSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
  1072. const xmjCol = {
  1073. getValue: {
  1074. oamount2: function (data) {
  1075. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  1076. },
  1077. camount: function (data) {
  1078. return ZhCalc.round(data.camount, findDecimal(data.unit));
  1079. },
  1080. samount: function (data) {
  1081. return ZhCalc.round(data.samount, findDecimal(data.unit));
  1082. },
  1083. changed_amount: function (data) {
  1084. return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
  1085. },
  1086. },
  1087. readOnly: {
  1088. isEdit: function (data) {
  1089. return readOnly;
  1090. },
  1091. isValuation: function (data) {
  1092. return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
  1093. },
  1094. isSettle: function (data) {
  1095. return !((!readOnly || shenpiPower) && !checkIsSettle(data));
  1096. },
  1097. isSettle2: function (data) {
  1098. return !(!readOnly && !checkIsSettle(data));
  1099. }
  1100. },
  1101. }
  1102. sjsSettingObj.setGridSelectStyle(xmjSpreadSetting);
  1103. SpreadJsObj.initSpreadSettingEvents(xmjSpreadSetting, xmjCol);
  1104. SpreadJsObj.initSheet(xmjSpread.getActiveSheet(), xmjSpreadSetting);
  1105. const xmjSheet = xmjSpread.getActiveSheet();
  1106. const xmjSpreadObj = {
  1107. loadExprToInput: function () {
  1108. const sel = xmjSheet.getSelections()[0];
  1109. if (!sel) return;
  1110. const col = xmjSheet.zh_setting.cols[sel.col];
  1111. const data = SpreadJsObj.getSelectObject(xmjSheet);
  1112. if (col && col.field === 'camount' && data) {
  1113. if (readOnly) {
  1114. $('#xmj-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  1115. } else {
  1116. $('#xmj-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
  1117. }
  1118. } else {
  1119. $('#xmj-camount-expr').attr('readonly', true).val('');
  1120. }
  1121. },
  1122. /**
  1123. * 加载计量单元 根据当前台账选择节点
  1124. */
  1125. loadCurXmjData: function () {
  1126. const data = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1127. changeSpreadSheet.getRange(changeSpreadSheet.getSelections()[0].row, -1, 1, -1).backColor('#fffacd');
  1128. const xmj = [];
  1129. if (data && data.children && data.children.length > 0) {
  1130. for (const child of data.children) {
  1131. if (child.bwmx === child.xmj_jldy) {
  1132. child.bwmx = '';
  1133. }
  1134. xmj.push(child);
  1135. }
  1136. }
  1137. SpreadJsObj.loadSheetData(xmjSheet, SpreadJsObj.DataType.Data, xmj);
  1138. xmjSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  1139. SpreadJsObj.resetTopAndSelect(xmjSheet);
  1140. xmjSpreadObj.loadExprToInput();
  1141. },
  1142. selectionChanged: function (e, info) {
  1143. xmjSpreadObj.loadExprToInput();
  1144. },
  1145. showHideAudit: function (show = false) {
  1146. if (shenpiPower) {
  1147. show = true;
  1148. }
  1149. if (readOnly) {
  1150. const xmjStartLimit = 9;
  1151. const count = xmjSpreadSetting.cols.length;
  1152. for (let i = xmjStartLimit + 2; i < count - 1; i++) {
  1153. xmjSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  1154. }
  1155. xmjSheet.setColumnVisible(xmjStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
  1156. }
  1157. },
  1158. };
  1159. xmjSpread.bind(spreadNS.Events.SelectionChanged, xmjSpreadObj.selectionChanged);
  1160. if (!readOnly) {
  1161. $('.dropdown-menu input[name="paixu"]').on('click', function () {
  1162. const newChangeOrder = parseInt($(this).val());
  1163. if (newChangeOrder !== changeOrder) {
  1164. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList(newChangeOrder);
  1165. // 更新至服务器
  1166. postData(window.location.pathname + '/save', { type:'order_by', updateData: newChangeOrder, updateOrderList }, function (result) {
  1167. if (newChangeOrder === 0) {
  1168. $('#bpaixu').text('清单排序:清单编号');
  1169. $('#upAndMoveBtn').attr('style', 'display: none !important');
  1170. $('.order_text').text('添加');
  1171. changeOrder = newChangeOrder;
  1172. } else if (newChangeOrder === 1) {
  1173. $('#bpaixu').text('清单排序:添加顺序');
  1174. $('#upAndMoveBtn').show();
  1175. $('.order_text').text('插入');
  1176. changeOrder = newChangeOrder;
  1177. }
  1178. changeList = result.changeList;
  1179. changeUsedData = result.usedList;
  1180. const [newChangeList] = changeSpreadObj.makeNewChangeList();
  1181. changeSpreadObj.reloadSheet(newChangeList);
  1182. });
  1183. }
  1184. });
  1185. $('#set-site-btn').click(async function () {
  1186. if (changeOrder && !changeMode) {
  1187. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1188. if (!select && changeSpreadSheet.zh_data.length > 0) {
  1189. toastr.error('请选择清单再插入');
  1190. return;
  1191. }
  1192. 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) {
  1193. window.location.href = window.location.pathname + '/revise';
  1194. });
  1195. } else {
  1196. window.location.href = window.location.pathname + '/revise';
  1197. }
  1198. });
  1199. changeSpreadObj.refreshActn = function (rowCount = 1) {
  1200. const setObjEnable = function (obj, enable) {
  1201. if (enable) {
  1202. obj.removeClass('disabled');
  1203. } else {
  1204. obj.addClass('disabled');
  1205. }
  1206. };
  1207. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1208. // 还需判断是否已被调差清单调用
  1209. const selection = changeSpreadSheet.getSelections();
  1210. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  1211. const row = sel ? sel.row : -1;
  1212. const first = changeSpreadSheet.zh_data[row];
  1213. let last = first;
  1214. if (sel.rowCount > 1 && first) {
  1215. for (let r = 1; r < sel.rowCount; r++) {
  1216. const rNode = changeSpreadSheet.zh_data[sel.row + r];
  1217. if (!rNode) break;
  1218. last = rNode;
  1219. }
  1220. }
  1221. const preNode = changeSpreadSheet.zh_data[row - 1];
  1222. setObjEnable($('#up-move'), !readOnly && first && preNode && changeSpreadSheet.zh_data.indexOf(last) > 0 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
  1223. setObjEnable($('#down-move'), !readOnly && first && changeSpreadSheet.zh_data.indexOf(last) < changeSpreadSheet.zh_data.length - 1 && sel.row + sel.rowCount <= changeSpreadSheet.zh_data.length);
  1224. // setObjEnable($('#open-list-modal'), !readOnly && select && changeList.indexOf(select) !== -1);
  1225. // setObjEnable($('#add-white-btn'), !readOnly && select && changeList.indexOf(select) !== -1);
  1226. };
  1227. changeSpreadObj.add = function () {
  1228. let select = null;
  1229. if (changeOrder) {
  1230. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1231. }
  1232. postData(window.location.pathname + '/save', {type: 'add', postData: select ? select.order : null}, function (result) {
  1233. if (result) {
  1234. if (changeOrder === 1 && select) {
  1235. // 批量更新changeList的order值
  1236. _.forEach(changeList, function (item) {
  1237. item.order = item.order > select.order ? item.order + 1 : item.order;
  1238. });
  1239. _.forEach(changeSpreadSheet.zh_data, function (item) {
  1240. item.order = item.order > select.order ? item.order + 1 : item.order;
  1241. });
  1242. changeList.splice(select.order, 0, result);
  1243. changeSpreadSheet.addRows(select.order, 1);
  1244. changeSpreadSheet.zh_data.splice(select.order, 0, _.cloneDeep(result));
  1245. changeSpreadSheet.getRange(select.order - 1, -1, 1, -1).backColor('#fff');
  1246. changeSpreadSheet.setSelection(select.order, 1, 1, 1);
  1247. changeSpreadObj.reloadRow(changeSpreadSheet, select.order);
  1248. } else {
  1249. changeList.push(result);
  1250. changeSpreadSheet.zh_data.push(_.cloneDeep(result));
  1251. changeSpreadSheet.addRows(changeSpreadSheet.zh_data.length - 1, 1);
  1252. changeSpreadSheet.setSelection(changeSpreadSheet.zh_data.length - 1, 1, 1, 1);
  1253. changeSpreadObj.reloadRow(changeSpreadSheet, changeSpreadSheet.zh_data.length - 1, 0, true);
  1254. }
  1255. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  1256. changeSpreadObj.refreshXmjData();
  1257. changeSpreadObj.refreshActn();
  1258. }
  1259. });
  1260. };
  1261. changeSpreadObj.batchAdd = function(num) {
  1262. let select = null;
  1263. if (changeOrder) {
  1264. select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1265. }
  1266. postData(window.location.pathname + '/save', {type: 'batchadd', num, postData: select ? select.order : null}, function (result) {
  1267. if (result) {
  1268. changeList = result;
  1269. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  1270. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  1271. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1272. changeSpreadObj.reloadSheet(newChangeList);
  1273. }
  1274. });
  1275. };
  1276. // 计量单元修改
  1277. changeSpreadObj.del = function () {
  1278. const selection = changeSpreadSheet.getSelections();
  1279. const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
  1280. const row = sel && sel.row !== undefined ? sel.row : -1;
  1281. const count = sel.rowCount;
  1282. if (readOnly || row === -1 || row + count > changeSpreadSheet.zh_data.length) {
  1283. return false;
  1284. }
  1285. const delList = [];
  1286. let lastSelect = null;
  1287. for (let r = 0; r < count; r++) {
  1288. const select = changeSpreadSheet.zh_data[row + r];
  1289. if (!select || !select.id) {
  1290. toastr.error('变更清单不存在或者该清单存在项目节');
  1291. return;
  1292. }
  1293. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  1294. toastr.error('已调用的变更清单不能删除');
  1295. return false;
  1296. }
  1297. if (checkIsSettle(select)) {
  1298. toastr.error('已结算的变更清单不能删除');
  1299. return false;
  1300. }
  1301. if (r === count - 1 && changeOrder) {
  1302. lastSelect = select;
  1303. }
  1304. delList.push(select.id);
  1305. }
  1306. if (delList.length) {
  1307. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
  1308. changeSpreadSheet.deleteRows(row, count);
  1309. changeSpreadSheet.zh_data.splice(row, count);
  1310. changeSpreadObj.countSum();
  1311. changeSpreadSheet.setSelection(0, 0, 1, 1);
  1312. changeSpreadObj.refreshXmjData();
  1313. changeSpreadObj.refreshActn();
  1314. });
  1315. }
  1316. };
  1317. changeSpreadObj.editStarting = function (e, info) {
  1318. const select = SpreadJsObj.getSelectObject(info.sheet);
  1319. if (select && select.id) {
  1320. const col = info.sheet.zh_setting.cols[info.col];
  1321. if (col.field === 'camount') {
  1322. if (select.camount_expr && select.camount_expr !== '') {
  1323. info.sheet.getCell(info.row, info.col).text(select.camount_expr);
  1324. }
  1325. }
  1326. }
  1327. };
  1328. changeSpreadObj.editEnded = function (e, info) {
  1329. if (!info.sheet.zh_setting) {
  1330. changeSpreadObj.reloadRow(info.sheet, info.row);
  1331. return;
  1332. }
  1333. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1334. if (!select || !select.id) {
  1335. toastr.error('该变更清单无法编辑');
  1336. changeSpreadObj.reloadRow(info.sheet, info.row);
  1337. return;
  1338. }
  1339. const cInfo = _.find(changeList, { id: select.id });
  1340. if (!cInfo) {
  1341. toastr.error('数据错误,请刷新页面重试');
  1342. changeSpreadObj.reloadRow(info.sheet, info.row);
  1343. return;
  1344. }
  1345. const col = info.sheet.zh_setting.cols[info.col];
  1346. if (col.field === 'is_valuation') {
  1347. return;
  1348. }
  1349. let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  1350. let orgValue;
  1351. if (col.field === 'camount') {
  1352. orgValue = validText && validText !== ''
  1353. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  1354. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  1355. } else {
  1356. orgValue = select[col.field];
  1357. }
  1358. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1359. changeSpreadObj.reloadRow(info.sheet, info.row);
  1360. return;
  1361. }
  1362. if(col.field === 'camount') {
  1363. const exprQuantity = {
  1364. expr: '',
  1365. quantity: 0,
  1366. };
  1367. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  1368. if (!valid) {
  1369. toastr.error(msg);
  1370. changeSpreadObj.reloadRow(info.sheet, info.row);
  1371. return;
  1372. }
  1373. if (isNaN(exprQuantity.quantity)) {
  1374. toastr.error('不能输入其它非数字类型字符');
  1375. changeSpreadObj.reloadRow(info.sheet, info.row);
  1376. return;
  1377. }
  1378. validText = parseFloat(exprQuantity.quantity);
  1379. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1380. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  1381. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1382. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1383. changeSpreadObj.reloadRow(info.sheet, info.row);
  1384. return;
  1385. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1386. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1387. changeSpreadObj.reloadRow(info.sheet, info.row);
  1388. return;
  1389. }
  1390. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  1391. select.camount_expr = exprQuantity.expr;
  1392. cInfo.spamount = select.spamount;
  1393. cInfo.camount_expr = exprQuantity.expr;
  1394. }
  1395. if (col.type === 'Number') {
  1396. if (isNaN(validText)) {
  1397. toastr.error('不能输入其它非数字类型字符');
  1398. changeSpreadObj.reloadRow(info.sheet, info.row);
  1399. return;
  1400. }
  1401. if (col.field === 'unit_price') {
  1402. validText = ZhCalc.round(validText, unitPriceUnit);
  1403. } else {
  1404. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  1405. }
  1406. if (col.field === 'delimit') {
  1407. const reg = /^(\d{1,2}|100)$/;
  1408. if (!(_.isNumber(validText) && reg.test(validText))) {
  1409. toastr.error('计量上限默认值只能输入0-100之间的整数');
  1410. changeSpreadObj.reloadRow(info.sheet, info.row);
  1411. return;
  1412. }
  1413. // 需要判断是否已调用,已调用的则不能低于原有值大小
  1414. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  1415. if (usedInfo && usedInfo.qty) {
  1416. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
  1417. if (validText < minLimit) {
  1418. toastr.error('计量上限值至少大于等于 ' + minLimit);
  1419. changeSpreadObj.reloadRow(info.sheet, info.row);
  1420. return;
  1421. }
  1422. }
  1423. }
  1424. }
  1425. cInfo[col.field] = validText;
  1426. select[col.field] = validText;
  1427. console.log(cInfo);
  1428. delete cInfo.waitingLoading;
  1429. // 更新至服务器
  1430. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  1431. if (select.children && select.children.length === 1) {
  1432. const child = select.children[0];
  1433. child[col.field] = validText;
  1434. }
  1435. changeSpreadObj.calcOneSum(select);
  1436. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1437. changeSpreadObj.refreshXmjData();
  1438. changeSpreadObj.countSum();
  1439. changeSpreadObj.refreshActn();
  1440. if (info.row === info.sheet.zh_data.length - 1) {
  1441. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1442. changeSpreadObj.reloadSheet(newChangeList);
  1443. }
  1444. }, function () {
  1445. select[col.field] = orgValue;
  1446. cInfo[col.field] = orgValue;
  1447. if(col.field === 'camount') {
  1448. select.spamount = orgValue;
  1449. cInfo.spamount = orgValue;
  1450. }
  1451. changeSpreadObj.reloadRow(info.sheet, info.row);
  1452. });
  1453. };
  1454. changeSpreadObj.clipboardPasted = function (e, info) {
  1455. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1456. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1457. }
  1458. const hint = {
  1459. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1460. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1461. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  1462. };
  1463. const range = info.cellRange;
  1464. const sortData = info.sheet.zh_data || [];
  1465. const data = [];
  1466. // const rowData = [];
  1467. let needCopyIgnore = !$('#customCheck1').is(':checked');
  1468. let needColAdd = false;
  1469. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1470. let bPaste = true;
  1471. const curRow = range.row + iRow;
  1472. if (!sortData[curRow].id) {
  1473. bPaste = false;
  1474. continue;
  1475. }
  1476. const cLData = { id: sortData[curRow].id };
  1477. const hintRow = range.rowCount >= 1 ? curRow : '';
  1478. let sameCol = 0;
  1479. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1480. const curCol = range.col + iCol;
  1481. let colSetting = info.sheet.zh_setting.cols[curCol];
  1482. if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  1483. const newCurCol = curCol + 1;
  1484. needColAdd = true;
  1485. colSetting = info.sheet.zh_setting.cols[newCurCol];
  1486. }
  1487. if (!colSetting) continue;
  1488. let validText = info.sheet.getText(curRow, curCol);
  1489. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  1490. let orgValue;
  1491. if (colSetting.field === 'camount') {
  1492. orgValue = validText && validText !== ''
  1493. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  1494. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  1495. } else {
  1496. orgValue = sortData[curRow][colSetting.field];
  1497. }
  1498. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1499. sameCol++;
  1500. if (range.colCount === sameCol) {
  1501. bPaste = false;
  1502. }
  1503. continue;
  1504. }
  1505. if(colSetting.field === 'camount') {
  1506. const exprQuantity = {
  1507. expr: '',
  1508. quantity: 0,
  1509. };
  1510. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  1511. if (!valid) {
  1512. toastMessageUniq(getPasteHint(msg, hintRow));
  1513. bPaste = false;
  1514. continue;
  1515. }
  1516. if (isNaN(exprQuantity.quantity)) {
  1517. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1518. bPaste = false;
  1519. continue;
  1520. }
  1521. validText = parseFloat(exprQuantity.quantity);
  1522. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1523. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  1524. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1525. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1526. bPaste = false;
  1527. continue;
  1528. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1529. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1530. bPaste = false;
  1531. continue;
  1532. }
  1533. cLData.camount_expr = exprQuantity.expr;
  1534. sortData[curRow].camount_expr = exprQuantity.expr;
  1535. }
  1536. if (colSetting.type === 'Number') {
  1537. if (isNaN(validText)) {
  1538. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1539. bPaste = false;
  1540. continue;
  1541. }
  1542. if (colSetting.field === 'unit_price') {
  1543. validText = ZhCalc.round(validText, unitPriceUnit);
  1544. } else {
  1545. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  1546. }
  1547. if (colSetting.field === 'delimit') {
  1548. const reg = /^(\d{1,2}|100)$/;
  1549. if (!(_.isNumber(validText) && reg.test(validText))) {
  1550. toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  1551. bPaste = false;
  1552. continue;
  1553. }
  1554. // 需要判断是否已调用,已调用的则不能低于原有值大小
  1555. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  1556. if (usedInfo && usedInfo.qty) {
  1557. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  1558. if (validText < minLimit) {
  1559. toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  1560. bPaste = false;
  1561. continue;
  1562. }
  1563. }
  1564. }
  1565. }
  1566. let unitdecimal = validText;
  1567. cLData[colSetting.field] = validText;
  1568. sortData[curRow][colSetting.field] = validText;
  1569. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  1570. }
  1571. if (bPaste) {
  1572. data.push(cLData);
  1573. // rowData.push(curRow);
  1574. } else {
  1575. changeSpreadObj.reloadRow(info.sheet, curRow);
  1576. }
  1577. }
  1578. if (data.length === 0) {
  1579. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1580. return;
  1581. }
  1582. console.log(data);
  1583. // 更新至服务器
  1584. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1585. changeList = result;
  1586. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1587. changeSpreadObj.reloadSheet(newChangeList);
  1588. }, function () {
  1589. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1590. return;
  1591. });
  1592. };
  1593. changeSpreadObj.buttonClicked = function(e, info) {
  1594. if (info.sheet.zh_setting) {
  1595. const select = SpreadJsObj.getSelectObject(info.sheet);
  1596. if (!select || !select.id) {
  1597. changeSpreadObj.reloadRow(info.sheet, info.row);
  1598. return;
  1599. }
  1600. const cInfo = _.find(changeList, { id: select.id });
  1601. if (!cInfo) {
  1602. toastr.error('数据错误,请刷新页面重试');
  1603. changeSpreadObj.reloadRow(info.sheet, info.row);
  1604. return;
  1605. }
  1606. const col = info.sheet.zh_setting.cols[info.col];
  1607. if (col.field === 'is_valuation') {
  1608. if (info.sheet.isEditing()) {
  1609. info.sheet.endEdit(true);
  1610. }
  1611. if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
  1612. return;
  1613. }
  1614. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  1615. cInfo.is_valuation = select.is_valuation;
  1616. delete cInfo.waitingLoading;
  1617. // 更新至服务器
  1618. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  1619. changeSpreadObj.reloadRow(info.sheet, info.row);
  1620. if (select.children && select.children.length === 1) {
  1621. const child = select.children[0];
  1622. child[col.field] = select.is_valuation;
  1623. changeSpreadObj.refreshXmjData();
  1624. }
  1625. }, function () {
  1626. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  1627. cInfo.is_valuation = select.is_valuation;
  1628. changeSpreadObj.reloadRow(info.sheet, info.row);
  1629. });
  1630. }
  1631. }
  1632. };
  1633. changeSpreadObj.valueChanged = function(e, info) {
  1634. // 防止ctrl+z撤销数据
  1635. changeSpreadObj.reloadRow(info.sheet, info.row);
  1636. };
  1637. changeSpreadObj.setAllValuation = function (is_valuation) {
  1638. if (changeList.length === 0) {
  1639. toastr.warning('暂无清单无法设置清单计价');
  1640. return;
  1641. }
  1642. const needChangeList = _.filter(changeList, { is_valuation: is_valuation ? 0 : 1 });
  1643. if (needChangeList.length === 0) {
  1644. toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
  1645. return;
  1646. }
  1647. const realNeedChangeList = [];
  1648. for (const nc of needChangeList) {
  1649. if (_.findIndex(changeUsedData, { cbid: nc.id }) === -1) {
  1650. realNeedChangeList.push(nc.id);
  1651. }
  1652. }
  1653. if (realNeedChangeList.length === 0) {
  1654. toastr.warning('全部清单已设置清单'+ (is_valuation ? '' : '不') +'计价');
  1655. return;
  1656. }
  1657. postData(window.location.pathname + '/save', { type:'set_all_valuation', ids: realNeedChangeList, is_valuation }, function (result) {
  1658. changeList = result;
  1659. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1660. changeSpreadObj.reloadSheet(newChangeList);
  1661. });
  1662. };
  1663. changeSpreadObj.deletePress = function (sheet) {
  1664. if (!sheet.zh_setting) return;
  1665. // 暂时仅支持移除数量
  1666. const sel = sheet.getSelections()[0], datas = [];
  1667. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1668. let bDel = false;
  1669. const node = sheet.zh_data[iRow];
  1670. if (!node || !node.id) continue;
  1671. const cInfo = _.find(changeList, { id: node.id });
  1672. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1673. const col = sheet.zh_setting.cols[iCol];
  1674. if (col.field === 'camount' || col.field === 'oamount2') {
  1675. node[col.field] = null;
  1676. cInfo[col.field] = null;
  1677. if (col.field === 'camount') {
  1678. node.camount_expr = '';
  1679. node.spamount = null;
  1680. cInfo.camount_expr = '';
  1681. cInfo.spamount = null;
  1682. }
  1683. delete cInfo.waitingLoading;
  1684. bDel = true;
  1685. }
  1686. }
  1687. if (bDel) datas.push(cInfo);
  1688. }
  1689. if (datas.length > 0) {
  1690. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  1691. changeList = result;
  1692. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1693. changeSpreadObj.reloadSheet(newChangeList);
  1694. }, function () {
  1695. changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
  1696. return;
  1697. });
  1698. }
  1699. return;
  1700. };
  1701. changeSpreadObj.upMove = function () {
  1702. const data = {
  1703. type: 'changeOrder',
  1704. postData: [],
  1705. };
  1706. const selection = changeSpreadSheet.getSelections();
  1707. const row = selection[0].row, count = selection[0].rowCount;
  1708. const first = changeSpreadSheet.zh_data[row];
  1709. const firstRow = row;
  1710. if (!first) {
  1711. changeSpreadObj.refreshActn();
  1712. return false;
  1713. }
  1714. const pre = changeSpreadSheet.zh_data[row - 1];
  1715. const preUpdates = [];
  1716. if (pre && pre.id) {
  1717. preUpdates.push({ id: pre.id });
  1718. } else if (pre && pre.children && pre.children.length > 0) {
  1719. for (const item of pre.children) {
  1720. preUpdates.push({ id: item.id });
  1721. }
  1722. }
  1723. for (let iRow = 0; iRow < count; iRow++) {
  1724. const posData = changeSpreadSheet.zh_data[iRow + row];
  1725. if (posData) {
  1726. for (const item of preUpdates) {
  1727. item.order = posData.order;
  1728. }
  1729. if (posData.id) {
  1730. data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
  1731. } else if (posData && posData.children && posData.children.length > 0) {
  1732. for (const item of posData.children) {
  1733. data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row - 1].order});
  1734. }
  1735. }
  1736. }
  1737. }
  1738. data.postData.push(...preUpdates);
  1739. console.log(data);
  1740. if (data.postData.length > 0) {
  1741. postData(window.location.pathname + '/save', data, function () {
  1742. _.forEach(data.postData, function (item) {
  1743. const cl = _.find(changeList, { id: item.id });
  1744. cl.order = item.order;
  1745. });
  1746. changeList.sort(function (a, b) {
  1747. return a.order - b.order
  1748. });
  1749. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1750. const sel = selection[0];
  1751. if (sel) {
  1752. changeSpreadSheet.setSelection(row - 1, sel.col, sel.rowCount, sel.colCount);
  1753. changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
  1754. SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
  1755. }
  1756. changeSpreadObj.reloadSheet(newChangeList);
  1757. });
  1758. }
  1759. };
  1760. changeSpreadObj.downMove = function () {
  1761. const data = {
  1762. type: 'changeOrder',
  1763. postData: [],
  1764. };
  1765. const selection = changeSpreadSheet.getSelections();
  1766. const row = selection[0].row, count = selection[0].rowCount;
  1767. const first = changeSpreadSheet.zh_data[row];
  1768. if (!first) {
  1769. changeSpreadObj.refreshActn();
  1770. return false;
  1771. }
  1772. const next = changeSpreadSheet.zh_data[row + count];
  1773. const nextUpdates = [];
  1774. if (next && next.id) {
  1775. nextUpdates.push({ id: next.id });
  1776. } else if (next && next.children && next.children.length > 0) {
  1777. for (const item of next.children) {
  1778. nextUpdates.push({ id: item.id });
  1779. }
  1780. }
  1781. for (let iRow = count - 1; iRow >= 0; iRow--) {
  1782. const posData = changeSpreadSheet.zh_data[iRow + row];
  1783. if (posData) {
  1784. for (const item of nextUpdates) {
  1785. item.order = posData.order;
  1786. }
  1787. if (posData.id) {
  1788. data.postData.push({id: posData.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
  1789. } else if (posData && posData.children && posData.children.length > 0) {
  1790. for (const item of posData.children) {
  1791. data.postData.push({id: item.id, order: changeSpreadSheet.zh_data[iRow + row + 1].order});
  1792. }
  1793. }
  1794. }
  1795. }
  1796. data.postData.push(...nextUpdates);
  1797. console.log(data);
  1798. if (data.postData.length > 0) {
  1799. postData(window.location.pathname + '/save', data, function () {
  1800. _.forEach(data.postData, function (item) {
  1801. const cl = _.find(changeList, { id: item.id });
  1802. cl.order = item.order;
  1803. });
  1804. changeList.sort(function (a, b) {
  1805. return a.order - b.order
  1806. });
  1807. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  1808. const sel = selection[0];
  1809. if (sel) {
  1810. changeSpreadSheet.setSelection(row + 1, sel.col, sel.rowCount, sel.colCount);
  1811. changeSpreadSheet.getRange(row, -1, 1, -1).backColor('#fff');
  1812. SpreadJsObj.saveTopAndSelect(changeSpreadSheet, ckChangeSpread);
  1813. }
  1814. changeSpreadObj.reloadSheet(newChangeList);
  1815. });
  1816. }
  1817. };
  1818. // 表达式判断
  1819. $('#camount-expr').change(function () {
  1820. if (this.readOnly) return;
  1821. let validText = $(this).val();
  1822. const sel = changeSpreadSheet.getSelections()[0];
  1823. const row = sel ? sel.row : -1;
  1824. const col = changeSpreadSheet.zh_setting.cols[sel.col];
  1825. if (row === -1 || !(col && col.field === 'camount')) return;
  1826. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1827. if (!select || !select.id) return;
  1828. const cInfo = _.find(changeList, { id: select.id });
  1829. if (!cInfo) return;
  1830. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  1831. let orgValue = validText && validText !== ''
  1832. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  1833. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  1834. const orgExprValue = _.clone(select.camount_expr);
  1835. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1836. return;
  1837. }
  1838. const exprQuantity = {
  1839. expr: '',
  1840. quantity: 0,
  1841. };
  1842. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  1843. if (!valid) {
  1844. toastr.error(msg);
  1845. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1846. return;
  1847. }
  1848. if (isNaN(exprQuantity.quantity)) {
  1849. toastr.error('不能输入其它非数字类型字符');
  1850. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1851. return;
  1852. }
  1853. validText = parseFloat(exprQuantity.quantity);
  1854. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1855. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1856. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1857. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1858. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1859. return;
  1860. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1861. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1862. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  1863. return;
  1864. }
  1865. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  1866. select.camount_expr = exprQuantity.expr;
  1867. select.camount = validText;
  1868. cInfo.spamount = select.spamount;
  1869. cInfo.camount_expr = select.camount_expr;
  1870. cInfo.camount = validText;
  1871. // console.log(select);
  1872. delete cInfo.waitingLoading;
  1873. // 更新至服务器
  1874. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  1875. changeSpreadObj.reloadRow(changeSpreadSheet, row);
  1876. changeSpreadObj.calcOneSum(select);
  1877. changeSpreadObj.countSum();
  1878. changeSpreadObj.refreshActn();
  1879. }, function () {
  1880. select.camount = orgValue;
  1881. select.camount_expr = orgExprValue;
  1882. select.spamount = orgValue;
  1883. cInfo.camount = orgValue;
  1884. cInfo.camount_expr = orgExprValue;
  1885. cInfo.spamount = orgValue;
  1886. changeSpreadObj.reloadRow(changeSpreadSheet, row);
  1887. });
  1888. });
  1889. $('#add-white-btn').click(changeSpreadObj.add);
  1890. $('#up-move').click(changeSpreadObj.upMove);
  1891. $('#down-move').click(changeSpreadObj.downMove);
  1892. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  1893. changeSpread.bind(spreadNS.Events.EditStarting, changeSpreadObj.editStarting);
  1894. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  1895. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  1896. changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
  1897. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  1898. // 计量单元修改
  1899. xmjSpreadObj.del = function () {
  1900. const selection = xmjSheet.getSelections();
  1901. const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
  1902. const row = sel && sel.row !== undefined ? sel.row : -1;
  1903. const count = sel.rowCount;
  1904. if (readOnly || row === -1 || row + count > xmjSheet.zh_data.length) {
  1905. return false;
  1906. }
  1907. const delList = [];
  1908. let lastSelect = null;
  1909. for (let r = 0; r < count; r++) {
  1910. const select = xmjSheet.zh_data[row + r];
  1911. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  1912. toastr.error('已调用的变更清单不能删除');
  1913. return false;
  1914. }
  1915. if (checkIsSettle(select)) {
  1916. toastr.error('已结算的变更清单不能删除');
  1917. return false;
  1918. }
  1919. if (r === count - 1 && xmjSheet.zh_data.length === count && changeOrder) {
  1920. lastSelect = select;
  1921. }
  1922. delList.push(select.id);
  1923. }
  1924. if (delList.length) {
  1925. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null, delLength: 1}, function (result) {
  1926. xmjSheet.deleteRows(row, count);
  1927. xmjSheet.zh_data.splice(row, count);
  1928. // 同步删除changeList值
  1929. _.forEach(delList, function (id) {
  1930. _.remove(changeList, { id: id });
  1931. });
  1932. const billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1933. const billIndex = _.indexOf(changeSpreadSheet.zh_data, billsNode);
  1934. let allDel = false;
  1935. // 判断是移除还是更新数量和金额
  1936. if (xmjSheet.zh_data.length === 0) {
  1937. changeSpreadSheet.deleteRows(billIndex, 1);
  1938. changeSpreadSheet.zh_data.splice(billIndex, 1);
  1939. allDel = true;
  1940. } else {
  1941. billsNode.children = xmjSheet.zh_data;
  1942. if (billsNode.children.length === 1) {
  1943. billsNode.id = billsNode.children[0].id;
  1944. billsNode.bwmx = billsNode.children[0].bwmx || billsNode.children[0].xmj_jldy;
  1945. billsNode.detail = billsNode.children[0].detail;
  1946. billsNode.delimit = billsNode.children[0].delimit;
  1947. }
  1948. changeSpreadObj.calcOneSum(billsNode);
  1949. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  1950. }
  1951. changeSpreadObj.countSum();
  1952. if (allDel) {
  1953. changeSpreadSheet.setSelection(0, 0, 1, 1);
  1954. changeSpreadObj.refreshXmjData();
  1955. changeSpreadObj.refreshActn();
  1956. }
  1957. });
  1958. }
  1959. };
  1960. xmjSpreadObj.editStarting = function (e, info) {
  1961. xmjSpreadObj.billsNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  1962. const col = info.sheet.zh_setting.cols[info.col];
  1963. const select = SpreadJsObj.getSelectObject(info.sheet);
  1964. if (col.field === 'camount') {
  1965. if (select.camount_expr && select.camount_expr !== '') {
  1966. info.sheet.getCell(info.row, info.col).text(select.camount_expr);
  1967. }
  1968. }
  1969. };
  1970. xmjSpreadObj.editEnded = function (e, info) {
  1971. if (!info.sheet.zh_setting) {
  1972. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1973. return;
  1974. }
  1975. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  1976. const cInfo = _.find(changeList, { id: select.id });
  1977. if (!cInfo) {
  1978. toastr.error('数据错误,请刷新页面重试');
  1979. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1980. return;
  1981. }
  1982. const col = info.sheet.zh_setting.cols[info.col];
  1983. if (col.field === 'is_valuation') {
  1984. return;
  1985. }
  1986. let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  1987. let orgValue;
  1988. if (col.field === 'camount') {
  1989. orgValue = validText && validText !== ''
  1990. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  1991. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  1992. } else {
  1993. orgValue = select[col.field];
  1994. }
  1995. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1996. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1997. return;
  1998. }
  1999. const node = xmjSpreadObj.billsNode;
  2000. if (!node) {
  2001. toastr.error('数据错误,请选择清单节点后再试');
  2002. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2003. return;
  2004. }
  2005. if(col.field === 'camount') {
  2006. const exprQuantity = {
  2007. expr: '',
  2008. quantity: 0,
  2009. };
  2010. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  2011. if (!valid) {
  2012. toastr.error(msg);
  2013. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2014. return;
  2015. }
  2016. if (isNaN(exprQuantity.quantity)) {
  2017. toastr.error('不能输入其它非数字类型字符');
  2018. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2019. return;
  2020. }
  2021. validText = parseFloat(exprQuantity.quantity);
  2022. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2023. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  2024. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2025. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2026. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2027. return;
  2028. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2029. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2030. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2031. return;
  2032. }
  2033. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  2034. select.camount_expr = exprQuantity.expr;
  2035. cInfo.spamount = select.spamount;
  2036. cInfo.camount_expr = exprQuantity.expr;
  2037. }
  2038. if (col.type === 'Number') {
  2039. if (isNaN(validText)) {
  2040. toastr.error('不能输入其它非数字类型字符');
  2041. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2042. return;
  2043. }
  2044. if (col.field === 'unit_price') {
  2045. validText = ZhCalc.round(validText, unitPriceUnit);
  2046. } else {
  2047. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  2048. }
  2049. if (col.field === 'delimit') {
  2050. const reg = /^(\d{1,2}|100)$/;
  2051. if (!(_.isNumber(validText) && reg.test(validText))) {
  2052. toastr.error('计量上限默认值只能输入0-100之间的整数');
  2053. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2054. return;
  2055. }
  2056. // 需要判断是否已调用,已调用的则不能低于原有值大小
  2057. const usedInfo = _.find(changeUsedData, { cbid: select.id });
  2058. if (usedInfo && usedInfo.qty) {
  2059. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
  2060. if (validText < minLimit) {
  2061. toastr.error('计量上限值至少大于等于 ' + minLimit);
  2062. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2063. return;
  2064. }
  2065. }
  2066. }
  2067. }
  2068. cInfo[col.field] = validText;
  2069. select[col.field] = validText;
  2070. console.log(cInfo);
  2071. delete cInfo.waitingLoading;
  2072. // 更新至服务器
  2073. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  2074. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2075. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2076. node.children = info.sheet.zh_data;
  2077. if (node.children && node.children.length === 1) {
  2078. node[col.field] = validText;
  2079. }
  2080. xmjSpreadObj.loadExprToInput();
  2081. changeSpreadObj.calcOneSum(node);
  2082. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2083. changeSpreadObj.countSum();
  2084. }, function () {
  2085. select[col.field] = orgValue;
  2086. cInfo[col.field] = orgValue;
  2087. if(col.field === 'camount') {
  2088. select.spamount = orgValue;
  2089. cInfo.spamount = orgValue;
  2090. }
  2091. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2092. });
  2093. };
  2094. xmjSpreadObj.clipboardPasted = function (e, info) {
  2095. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2096. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2097. }
  2098. const hint = {
  2099. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  2100. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  2101. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2102. };
  2103. const range = info.cellRange;
  2104. const sortData = info.sheet.zh_data || [];
  2105. if (range.row + range.rowCount > sortData.length) {
  2106. toastMessageUniq(hint.cellError);
  2107. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  2108. xmjSpreadObj.loadCurXmjData();
  2109. return;
  2110. }
  2111. if (sortData.length > 0 && range.col + range.colCount > 12) {
  2112. toastMessageUniq(hint.cellError);
  2113. xmjSpreadObj.loadCurXmjData();
  2114. return;
  2115. }
  2116. if (!info.sheet.zh_setting) {
  2117. xmjSpreadObj.loadCurXmjData();
  2118. return;
  2119. }
  2120. const data = [];
  2121. // const rowData = [];
  2122. let needCopyIgnore = !$('#customCheck1').is(':checked');
  2123. let needColAdd = false;
  2124. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  2125. let bPaste = true;
  2126. const curRow = range.row + iRow;
  2127. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  2128. const cLData = { id: sortData[curRow].id };
  2129. const hintRow = range.rowCount >= 1 ? curRow : '';
  2130. let sameCol = 0;
  2131. for (let iCol = 0; iCol < range.colCount; iCol++) {
  2132. const curCol = range.col + iCol;
  2133. let colSetting = info.sheet.zh_setting.cols[curCol];
  2134. if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  2135. const newCurCol = curCol + 1;
  2136. needColAdd = true;
  2137. colSetting = info.sheet.zh_setting.cols[newCurCol];
  2138. }
  2139. if (!colSetting) continue;
  2140. let validText = info.sheet.getText(curRow, curCol);
  2141. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  2142. let orgValue;
  2143. if (colSetting.field === 'camount') {
  2144. orgValue = validText && validText !== ''
  2145. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  2146. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  2147. } else {
  2148. orgValue = sortData[curRow][colSetting.field];
  2149. }
  2150. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  2151. sameCol++;
  2152. if (range.colCount === sameCol) {
  2153. bPaste = false;
  2154. }
  2155. continue;
  2156. }
  2157. if(colSetting.field === 'camount') {
  2158. const exprQuantity = {
  2159. expr: '',
  2160. quantity: 0,
  2161. };
  2162. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  2163. if (!valid) {
  2164. toastMessageUniq(getPasteHint(msg, hintRow));
  2165. bPaste = false;
  2166. continue;
  2167. }
  2168. if (isNaN(exprQuantity.quantity)) {
  2169. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  2170. bPaste = false;
  2171. continue;
  2172. }
  2173. validText = parseFloat(exprQuantity.quantity);
  2174. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2175. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  2176. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2177. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2178. bPaste = false;
  2179. continue;
  2180. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2181. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2182. bPaste = false;
  2183. continue;
  2184. }
  2185. cLData.camount_expr = exprQuantity.expr;
  2186. sortData[curRow].camount_expr = exprQuantity.expr;
  2187. }
  2188. if (colSetting.type === 'Number') {
  2189. if (isNaN(validText)) {
  2190. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  2191. bPaste = false;
  2192. continue;
  2193. }
  2194. if (colSetting.field === 'unit_price') {
  2195. validText = ZhCalc.round(validText, unitPriceUnit);
  2196. } else {
  2197. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  2198. }
  2199. if (colSetting.field === 'delimit') {
  2200. const reg = /^(\d{1,2}|100)$/;
  2201. if (!(_.isNumber(validText) && reg.test(validText))) {
  2202. toastr.error('项目节第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  2203. bPaste = false;
  2204. continue;
  2205. }
  2206. // 需要判断是否已调用,已调用的则不能低于原有值大小
  2207. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].id });
  2208. if (usedInfo && usedInfo.qty) {
  2209. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  2210. if (validText < minLimit) {
  2211. toastr.error('项目节第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  2212. bPaste = false;
  2213. continue;
  2214. }
  2215. }
  2216. }
  2217. }
  2218. let unitdecimal = validText;
  2219. cLData[colSetting.field] = validText;
  2220. sortData[curRow][colSetting.field] = validText;
  2221. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  2222. }
  2223. if (bPaste) {
  2224. data.push(cLData);
  2225. // rowData.push(curRow);
  2226. } else {
  2227. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  2228. }
  2229. }
  2230. if (data.length === 0) {
  2231. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2232. return;
  2233. }
  2234. console.log(data);
  2235. // 更新至服务器
  2236. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  2237. changeList = result;
  2238. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2239. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2240. node.children = info.sheet.zh_data;
  2241. if (node.children && node.children.length === 1) {
  2242. for (const col in data[0]) {
  2243. node[col] = data[0][col];
  2244. }
  2245. }
  2246. changeSpreadObj.calcOneSum(node);
  2247. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2248. changeSpreadObj.countSum();
  2249. xmjSpreadObj.loadCurXmjData();
  2250. }, function () {
  2251. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2252. return;
  2253. });
  2254. };
  2255. xmjSpreadObj.buttonClicked = function(e, info) {
  2256. if (info.sheet.zh_setting) {
  2257. const select = SpreadJsObj.getSelectObject(info.sheet);
  2258. const cInfo = _.find(changeList, { id: select.id });
  2259. if (!cInfo) {
  2260. toastr.error('数据错误,请刷新页面重试');
  2261. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2262. return;
  2263. }
  2264. const col = info.sheet.zh_setting.cols[info.col];
  2265. if (col.field === 'is_valuation') {
  2266. if (info.sheet.isEditing()) {
  2267. info.sheet.endEdit(true);
  2268. }
  2269. if (_.findIndex(changeUsedData, { cbid: select.id }) !== -1) {
  2270. return;
  2271. }
  2272. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  2273. cInfo.is_valuation = select.is_valuation;
  2274. delete cInfo.waitingLoading;
  2275. // 更新至服务器
  2276. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  2277. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2278. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2279. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2280. node.children = info.sheet.zh_data;
  2281. changeSpreadObj.calcOneSum(node);
  2282. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2283. }, function () {
  2284. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2285. cInfo.is_valuation = select.is_valuation;
  2286. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2287. });
  2288. }
  2289. }
  2290. };
  2291. xmjSpreadObj.valueChanged = function(e, info) {
  2292. // 防止ctrl+z撤销数据
  2293. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2294. };
  2295. xmjSpreadObj.deletePress = function (sheet) {
  2296. if (!sheet.zh_setting) return;
  2297. // 暂时仅支持移除数量
  2298. const sel = sheet.getSelections()[0], datas = [];
  2299. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2300. let bDel = false;
  2301. const node = sheet.zh_data[iRow];
  2302. const cInfo = _.find(changeList, { id: node.id });
  2303. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2304. const col = sheet.zh_setting.cols[iCol];
  2305. if (col.field === 'camount' || col.field === 'oamount2') {
  2306. node[col.field] = null;
  2307. cInfo[col.field] = null;
  2308. if (col.field === 'camount') {
  2309. node.camount_expr = '';
  2310. node.spamount = null;
  2311. cInfo.camount_expr = '';
  2312. cInfo.spamount = null;
  2313. }
  2314. delete cInfo.waitingLoading;
  2315. bDel = true;
  2316. }
  2317. }
  2318. if (bDel) datas.push(cInfo);
  2319. }
  2320. if (datas.length > 0) {
  2321. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  2322. changeList = result;
  2323. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2324. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2325. node.children = xmjSheet.zh_data;
  2326. changeSpreadObj.calcOneSum(node);
  2327. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2328. changeSpreadObj.countSum();
  2329. xmjSpreadObj.loadCurXmjData();
  2330. }, function () {
  2331. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2332. return;
  2333. });
  2334. }
  2335. return;
  2336. };
  2337. // 表达式判断
  2338. $('#xmj-camount-expr').change(function () {
  2339. if (this.readOnly) return;
  2340. let validText = $(this).val();
  2341. const sel = xmjSheet.getSelections()[0];
  2342. const row = sel ? sel.row : -1;
  2343. const col = xmjSheet.zh_setting.cols[sel.col];
  2344. if (row === -1 || !(col && col.field === 'camount')) return;
  2345. const select = SpreadJsObj.getSelectObject(xmjSheet);
  2346. if (!select) return;
  2347. const cInfo = _.find(changeList, { id: select.id });
  2348. if (!cInfo) return;
  2349. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  2350. let orgValue = validText && validText !== ''
  2351. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  2352. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  2353. const orgExprValue = _.clone(select.camount_expr);
  2354. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2355. return;
  2356. }
  2357. const exprQuantity = {
  2358. expr: '',
  2359. quantity: 0,
  2360. };
  2361. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  2362. if (!valid) {
  2363. toastr.error(msg);
  2364. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2365. return;
  2366. }
  2367. if (isNaN(exprQuantity.quantity)) {
  2368. toastr.error('不能输入其它非数字类型字符');
  2369. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2370. return;
  2371. }
  2372. validText = parseFloat(exprQuantity.quantity);
  2373. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2374. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  2375. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2376. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2377. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2378. return;
  2379. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2380. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2381. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  2382. return;
  2383. }
  2384. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  2385. select.camount_expr = exprQuantity.expr;
  2386. select.camount = validText;
  2387. cInfo.spamount = select.spamount;
  2388. cInfo.camount_expr = select.camount_expr;
  2389. cInfo.camount = validText;
  2390. // console.log(select);
  2391. delete cInfo.waitingLoading;
  2392. // 更新至服务器
  2393. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  2394. SpreadJsObj.reLoadRowData(xmjSheet, row);
  2395. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2396. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  2397. node.children = xmjSheet.zh_data;
  2398. changeSpreadObj.calcOneSum(node);
  2399. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  2400. changeSpreadObj.countSum();
  2401. }, function () {
  2402. select.camount = orgValue;
  2403. select.camount_expr = orgExprValue;
  2404. select.spamount = orgValue;
  2405. cInfo.camount = orgValue;
  2406. cInfo.camount_expr = orgExprValue;
  2407. cInfo.spamount = orgValue;
  2408. SpreadJsObj.reLoadRowData(posSheet, row);
  2409. });
  2410. });
  2411. xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
  2412. xmjSpread.bind(spreadNS.Events.EditStarting, xmjSpreadObj.editStarting);
  2413. xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
  2414. xmjSpread.bind(spreadNS.Events.ValueChanged, xmjSpreadObj.valueChanged);
  2415. xmjSpread.bind(spreadNS.Events.ButtonClicked, xmjSpreadObj.buttonClicked);
  2416. SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
  2417. let batchInsertObj;
  2418. $.contextMenu.types.batchInsert = function (item, opt, root) {
  2419. const self = this;
  2420. if ($.isFunction(item.icon)) {
  2421. item._icon = item.icon.call(this, this, $t, key, item);
  2422. } else {
  2423. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  2424. // to enable font awesome
  2425. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  2426. } else {
  2427. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  2428. }
  2429. }
  2430. this.addClass(item._icon);
  2431. 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>')
  2432. .appendTo(this);
  2433. const $input = $obj.find('input');
  2434. const event = () => {
  2435. if (self.hasClass('context-menu-disabled')) return;
  2436. item.batchInsert($input[0], root);
  2437. };
  2438. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  2439. $input.click((e) => {e.stopPropagation();})
  2440. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  2441. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  2442. };
  2443. // 右键菜单
  2444. $.contextMenu({
  2445. selector: '#change-spread',
  2446. build: function ($trigger, e) {
  2447. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  2448. // console.log(e, target);
  2449. // const range = SpreadJsObj.getTargetSelection(changeSpreadSheet, target);
  2450. // console.log(range);
  2451. let ts = getLocalCache(ckChangeSpread);
  2452. if (ts !== '') {
  2453. ts = JSON.parse(ts);
  2454. if (ts === undefined || ts === null) return;
  2455. if (ts.sel) {
  2456. changeSpreadSheet.getRange(ts.sel.row, -1, 1, -1).backColor('#fff');
  2457. }
  2458. }
  2459. changeSpreadObj.refreshXmjData();
  2460. changeSpreadObj.refreshActn();
  2461. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2462. },
  2463. items: {
  2464. 'createList': {
  2465. name: '添加台账清单',
  2466. icon: 'fa-sign-in',
  2467. visible: function () {
  2468. return changeOrder === 0;
  2469. },
  2470. callback: function (key, opt) {
  2471. // $('#addlist').modal('show');
  2472. $('#set-site-btn').click();
  2473. },
  2474. },
  2475. 'createAdd': {
  2476. name: '添加空白清单',
  2477. icon: 'fa-sign-in',
  2478. visible: function () {
  2479. return changeOrder === 0 && openChangeWhiteList;
  2480. },
  2481. callback: function (key, opt) {
  2482. changeSpreadObj.add();
  2483. },
  2484. },
  2485. 'batchInsert': {
  2486. name: '批量添加空白清单',
  2487. type: 'batchInsert',
  2488. value: '2',
  2489. icon: 'fa-sign-in',
  2490. visible: function () {
  2491. return changeOrder === 0 && openChangeWhiteList;
  2492. },
  2493. batchInsert: function (obj, root) {
  2494. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2495. obj.value = obj.max;
  2496. toastr.warning('批量添加不可多于' + obj.max);
  2497. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2498. obj.value = obj.min;
  2499. toastr.warning('批量添加不可少于' + obj.min);
  2500. } else {
  2501. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  2502. changeSpreadObj.batchAdd(obj.value);
  2503. root.$menu.trigger('contextmenu:hide');
  2504. }
  2505. },
  2506. },
  2507. 'createList1': {
  2508. name: '插入台账清单',
  2509. icon: 'fa-sign-in',
  2510. visible: function () {
  2511. return changeOrder === 1;
  2512. },
  2513. // disabled: function (key, opt) {
  2514. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2515. // const sel = changeSpreadSheet.getSelections()[0];
  2516. // changeSpreadObj.resetXmjSpread(select);
  2517. // // console.log(select, sel);
  2518. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  2519. // return false;
  2520. // } else {
  2521. // return true;
  2522. // }
  2523. // },
  2524. callback: function (key, opt) {
  2525. // $('#addlist').modal('show');
  2526. $('#set-site-btn').click();
  2527. },
  2528. },
  2529. 'createAdd1': {
  2530. name: '插入空白清单',
  2531. icon: 'fa-sign-in',
  2532. visible: function () {
  2533. return changeOrder === 1 && openChangeWhiteList;
  2534. },
  2535. // disabled: function (key, opt) {
  2536. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2537. // const sel = changeSpreadSheet.getSelections()[0];
  2538. // changeSpreadObj.resetXmjSpread(select);
  2539. // // console.log(select, sel);
  2540. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  2541. // return false;
  2542. // } else {
  2543. // return true;
  2544. // }
  2545. // },
  2546. callback: function (key, opt) {
  2547. changeSpreadObj.add();
  2548. },
  2549. },
  2550. 'batchInsert1': {
  2551. name: '批量插入空白清单',
  2552. type: 'batchInsert',
  2553. value: '2',
  2554. icon: 'fa-sign-in',
  2555. visible: function () {
  2556. return changeOrder === 1 && openChangeWhiteList;
  2557. },
  2558. // disabled: function (key, opt) {
  2559. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  2560. // const sel = changeSpreadSheet.getSelections()[0];
  2561. // changeSpreadObj.resetXmjSpread(select);
  2562. // // console.log(select, sel);
  2563. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  2564. // return false;
  2565. // } else {
  2566. // return true;
  2567. // }
  2568. // },
  2569. batchInsert: function (obj, root) {
  2570. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2571. obj.value = obj.max;
  2572. toastr.warning('批量插入不可多于' + obj.max);
  2573. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2574. obj.value = obj.min;
  2575. toastr.warning('批量插入不可少于' + obj.min);
  2576. } else {
  2577. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  2578. changeSpreadObj.batchAdd(obj.value);
  2579. root.$menu.trigger('contextmenu:hide');
  2580. }
  2581. },
  2582. },
  2583. 'delete': {
  2584. name: '删除',
  2585. icon: 'fa-remove',
  2586. callback: function (key, opt) {
  2587. changeSpreadObj.del();
  2588. },
  2589. disabled: function (key, opt) {
  2590. const selection = changeSpreadSheet.getSelections();
  2591. const sel = selection ? selection[0] : changeSpreadSheet.getSelections()[0];
  2592. const row = sel ? sel.row : -1;
  2593. if (readOnly || row === -1 || sel.row + sel.rowCount > changeSpreadSheet.zh_data.length) {
  2594. return true;
  2595. }
  2596. const first = changeSpreadSheet.zh_data[row];
  2597. let valid = true;
  2598. if (sel.rowCount > 1 && first) {
  2599. for (let r = 1; r < sel.rowCount; r++) {
  2600. const rNode = changeSpreadSheet.zh_data[sel.row + r];
  2601. if (!rNode || !rNode.id) {
  2602. valid = false;
  2603. break;
  2604. }
  2605. if (_.find(changeUsedData, { cbid: rNode.id }) || checkIsSettle(rNode)) {
  2606. valid = false;
  2607. break;
  2608. }
  2609. }
  2610. }
  2611. return !(first && first.id && !_.find(changeUsedData, { cbid: first.id }) && !checkIsSettle(first) && valid);
  2612. }
  2613. },
  2614. sprEdit: '----',
  2615. 'allNotValuation': {
  2616. name: '设置全部清单不计价',
  2617. icon: 'fa-magic',
  2618. callback: function (key, opt) {
  2619. changeSpreadObj.setAllValuation(0);
  2620. },
  2621. },
  2622. 'allValuation': {
  2623. name: '设置全部清单计价',
  2624. icon: 'fa-magic',
  2625. callback: function (key, opt) {
  2626. changeSpreadObj.setAllValuation(1);
  2627. },
  2628. },
  2629. }
  2630. });
  2631. // 右键菜单
  2632. $.contextMenu({
  2633. selector: '#xmj-spread',
  2634. build: function ($trigger, e) {
  2635. const target = SpreadJsObj.safeRightClickSelection($trigger, e, xmjSpread);
  2636. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2637. },
  2638. items: {
  2639. 'delete': {
  2640. name: '删除',
  2641. icon: 'fa-remove',
  2642. callback: function (key, opt) {
  2643. xmjSpreadObj.del();
  2644. },
  2645. disabled: function (key, opt) {
  2646. const selection = xmjSheet.getSelections();
  2647. const sel = selection ? selection[0] : xmjSheet.getSelections()[0];
  2648. const row = sel && sel.row !== undefined ? sel.row : -1;
  2649. if (readOnly || row === -1 || sel.row + sel.rowCount > xmjSheet.zh_data.length) {
  2650. return true;
  2651. }
  2652. let isUsed = false;
  2653. for (let r = 0; r < sel.rowCount; r++) {
  2654. const select = xmjSheet.zh_data[row + r];
  2655. if(!select || _.find(changeUsedData, { cbid: select.id })) {
  2656. isUsed = true;
  2657. }
  2658. if (checkIsSettle(select)) {
  2659. isUsed = true;
  2660. }
  2661. }
  2662. return isUsed;
  2663. }
  2664. },
  2665. sprEdit: '----',
  2666. 'allNotValuation': {
  2667. name: '设置全部清单不计价',
  2668. icon: 'fa-magic',
  2669. callback: function (key, opt) {
  2670. changeSpreadObj.setAllValuation(0);
  2671. },
  2672. },
  2673. 'allValuation': {
  2674. name: '设置全部清单计价',
  2675. icon: 'fa-magic',
  2676. callback: function (key, opt) {
  2677. changeSpreadObj.setAllValuation(1);
  2678. },
  2679. },
  2680. }
  2681. });
  2682. }
  2683. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  2684. const ledgerSheet = ledgerSpread.getActiveSheet();
  2685. const ledgerSpreadSetting = {
  2686. cols: [
  2687. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', getValue: 'getValue.is_valuation', readOnly: 'readOnly.isValuation'},
  2688. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree' },
  2689. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit2'},
  2690. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit2'},
  2691. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit2', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  2692. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: 'readOnly.isEdit2'},
  2693. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  2694. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', visible: openChangeState},
  2695. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount2', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  2696. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  2697. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  2698. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  2699. ],
  2700. emptyRows: 0,
  2701. headRows: 2,
  2702. headRowHeight: [25, 25],
  2703. defaultRowHeight: 21,
  2704. headerFont: '12px 微软雅黑',
  2705. font: '12px 微软雅黑',
  2706. // readOnly: true,
  2707. rowHeader:[
  2708. {
  2709. rowHeaderType: 'circle',
  2710. setting: {
  2711. size: 5,
  2712. indent: 16,
  2713. getColor: function (index, data) {
  2714. if (!data) return;
  2715. if ((!data.clid && data.cid) || (data.clid && data.gcl_id && _.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1)) {
  2716. return '#dc3545';
  2717. }
  2718. if (data.lid == 0) {
  2719. return '#007bff';
  2720. }
  2721. if (data.clid && data.gcl_id) {
  2722. return '#28a745';
  2723. }
  2724. if (data.clid && !data.gcl_id && data.lid != 0) {
  2725. return '#ffc107';
  2726. }
  2727. if(data.lid != 0) return;
  2728. return '#007bff';
  2729. }
  2730. },
  2731. },
  2732. ],
  2733. // localCache: {
  2734. // key: 'changes-ledger-spread',
  2735. // colWidth: true,
  2736. // }
  2737. };
  2738. if (readOnly) {
  2739. ledgerSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
  2740. ledgerSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'});
  2741. for (const aid of aidList) {
  2742. // const userinfo = _.find(auditList2, { 'uid': aid });
  2743. const audit = _.find(auditors2, function(item){
  2744. return _.findIndex(item, { audit_order: aid }) !== -1;
  2745. });
  2746. const newColcount = {
  2747. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  2748. colSpan: '2|1', rowSpan: '1|1',
  2749. field: 'audit_amount_' + aid,
  2750. hAlign: 2, width: 60, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle',
  2751. };
  2752. const newColTp = {
  2753. title: '|金额',
  2754. colSpan: '|1', rowSpan: '|1',
  2755. field: 'sa_tp_' + aid,
  2756. hAlign: 2, width: 80, type: 'Number',
  2757. };
  2758. ledgerSpreadSetting.cols.push(newColcount);
  2759. ledgerSpreadSetting.cols.push(newColTp);
  2760. }
  2761. }
  2762. 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'});
  2763. ledgerSpreadSetting.cols.push({title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'changed_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.changed_tp'});
  2764. const ledgerCol = {
  2765. getValue: {
  2766. is_valuation: function (data) {
  2767. return data.is_valuation === 1;
  2768. },
  2769. unit_price: function(data) {
  2770. return ZhCalc.round(data.unit_price, unitPriceUnit);
  2771. },
  2772. oa_tp: function (data) {
  2773. return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit) : data.oa_tp;
  2774. },
  2775. ca_tp: function (data) {
  2776. return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit) : data.ca_tp;
  2777. },
  2778. oamount2: function (data) {
  2779. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  2780. },
  2781. camount: function (data) {
  2782. return ZhCalc.round(data.camount, findDecimal(data.unit));
  2783. },
  2784. samount: function (data) {
  2785. return ZhCalc.round(data.samount, findDecimal(data.unit));
  2786. },
  2787. sa_tp: function (data) {
  2788. return data.clid ? ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit) : data.sa_tp;
  2789. },
  2790. changed_amount: function (data) {
  2791. return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
  2792. },
  2793. changed_tp: function (data) {
  2794. return data.clid ? ZhCalc.add(ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount2, findDecimal(data.unit))), totalPriceUnit),
  2795. ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit)) : data.changed_tp;
  2796. },
  2797. },
  2798. readOnly: {
  2799. isEdit: function (data) {
  2800. return !(!readOnly && data.clid);
  2801. },
  2802. isEdit2: function (data) {
  2803. return !(!readOnly && data.lid == 0 && data.clid);
  2804. },
  2805. isValuation: function (data) {
  2806. return !(!readOnly && data.clid && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
  2807. },
  2808. isSettle: function (data) {
  2809. return !((!readOnly || shenpiPower) && data.clid && !checkIsSettle(data));
  2810. },
  2811. isSettle2: function (data) {
  2812. return !(!readOnly && data.clid && !checkIsSettle(data));
  2813. }
  2814. },
  2815. };
  2816. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  2817. SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
  2818. SpreadJsObj.initSheet(ledgerSheet, ledgerSpreadSetting);
  2819. // 初始化 节点树结构
  2820. const treeSetting = {
  2821. id: 'ledger_id',
  2822. pid: 'ledger_pid',
  2823. order: 'order',
  2824. level: 'level',
  2825. rootId: -1,
  2826. keys: ['id', 'tender_id', 'ledger_id'],
  2827. calcFields: ['oa_tp', 'ca_tp', 'sa_tp', 'changed_tp', 'total_price'],
  2828. autoExpand: 3,
  2829. markExpandKey: 'change-bills-expand',
  2830. markExpandSubKey: window.location.pathname.split('/')[2],
  2831. };
  2832. if (readOnly) {
  2833. for (const aid of aidList) {
  2834. treeSetting.calcFields.push('sa_tp_' + aid);
  2835. }
  2836. }
  2837. treeSetting.calcFun = function (node) {
  2838. if (node && node.b_code) {
  2839. const posData = pos.getLedgerPos(node.id) || [];
  2840. if (!node.clid && posData.length > 0) {
  2841. let is_valuation = 1;
  2842. let oamount2 = 0;
  2843. let camount = 0;
  2844. let samount = 0;
  2845. let spamount = 0;
  2846. if (readOnly) {
  2847. for (const aid of aidList) {
  2848. let audit_amount = 0;
  2849. for (const np of posData) {
  2850. audit_amount = ZhCalc.add(audit_amount, ZhCalc.round(np['audit_amount_' + aid], findDecimal(node.unit)));
  2851. }
  2852. if (!_.isEqual(node['audit_amount_' + aid], audit_amount)) {
  2853. node['audit_amount_' + aid] = audit_amount;
  2854. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(audit_amount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit);
  2855. }
  2856. }
  2857. }
  2858. for (const np of posData) {
  2859. oamount2 = ZhCalc.add(oamount2, ZhCalc.round(np.oamount2, findDecimal(node.unit)));
  2860. camount = ZhCalc.add(camount, ZhCalc.round(np.camount, findDecimal(node.unit)));
  2861. samount = ZhCalc.add(samount, ZhCalc.round(np.samount, findDecimal(node.unit)));
  2862. spamount = ZhCalc.add(spamount, ZhCalc.round(np.spamount, findDecimal(node.unit)));
  2863. if (np.is_valuation === 0) is_valuation = 0;
  2864. }
  2865. if (!_.isEqual(node.oamount2, oamount2) || !_.isEqual(node.camount, camount) || !_.isEqual(node.samount, samount)) {
  2866. node.oamount2 = oamount2;
  2867. node.camount = camount;
  2868. node.samount = samount;
  2869. node.spamount = spamount;
  2870. node.change_amount = ZhCalc.add(oamount2, camount);
  2871. node.oa_tp = ZhCalc.round(ZhCalc.mul(oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2872. node.ca_tp = ZhCalc.round(ZhCalc.mul(camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2873. node.sa_tp = ZhCalc.round(ZhCalc.mul(samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2874. const spa_tp = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2875. node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
  2876. }
  2877. node.is_valuation = is_valuation;
  2878. } else if (node.clid) {
  2879. // node.oamount2 = ZhCalc.round(node.oamount2, findDecimal(node.unit));
  2880. // node.camount = ZhCalc.round(node.camount, findDecimal(node.unit));
  2881. // node.change_amount = ZhCalc.add(node.oamount2, node.camount);
  2882. node.oa_tp = ZhCalc.round(ZhCalc.mul(node.oamount2, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2883. node.ca_tp = ZhCalc.round(ZhCalc.mul(node.camount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2884. node.sa_tp = ZhCalc.round(ZhCalc.mul(node.samount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2885. const spa_tp = ZhCalc.round(ZhCalc.mul(node.spamount, ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2886. node.changed_tp = readOnly ? ZhCalc.add(node.oa_tp, spa_tp) || null : ZhCalc.add(node.oa_tp, node.ca_tp) || null;
  2887. if (readOnly) {
  2888. for (const aid of aidList) {
  2889. node['sa_tp_' + aid] = ZhCalc.round(ZhCalc.mul(node['audit_amount_' + aid], ZhCalc.round(node.unit_price, unitPriceUnit)), totalPriceUnit) || null;
  2890. }
  2891. }
  2892. }
  2893. }
  2894. };
  2895. const ledgerTree = createNewPathTree('revise', treeSetting);
  2896. const ledgerTreeSpreadObj = {
  2897. loadExprToInput: function () {
  2898. const sel = ledgerSheet.getSelections()[0];
  2899. if (!sel) return;
  2900. const col = ledgerSheet.zh_setting.cols[sel.col];
  2901. const data = SpreadJsObj.getSelectObject(ledgerSheet);
  2902. if (col && col.field === 'camount' && data && data.clid) {
  2903. if (!readOnly) {
  2904. $('#ledger-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
  2905. } else {
  2906. $('#ledger-camount-expr').attr('readonly', true).val(data.camount_expr ? data.camount_expr : data.camount);
  2907. }
  2908. } else {
  2909. $('#ledger-camount-expr').attr('readonly', true).val('');
  2910. }
  2911. },
  2912. showHideAudit: function (show = false) {
  2913. if (shenpiPower) {
  2914. show = true;
  2915. }
  2916. if (readOnly) {
  2917. const count = ledgerSpreadSetting.cols.length;
  2918. for (let i = startLimit + 5; i < count - 2; i++) {
  2919. ledgerSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  2920. }
  2921. ledgerSheet.setColumnVisible(startLimit + 3, !show, GC.Spread.Sheets.SheetArea.viewport);
  2922. ledgerSheet.setColumnVisible(startLimit + 4, !show, GC.Spread.Sheets.SheetArea.viewport);
  2923. }
  2924. },
  2925. /**
  2926. *
  2927. * @param sheet
  2928. * @param data
  2929. */
  2930. refreshTree: function (sheet, data) {
  2931. SpreadJsObj.massOperationSheet(sheet, function () {
  2932. const tree = sheet.zh_tree;
  2933. // 处理删除
  2934. if (data.delete) {
  2935. data.delete.sort(function (a, b) {
  2936. return b.deleteIndex - a.deleteIndex;
  2937. });
  2938. for (const d of data.delete) {
  2939. sheet.deleteRows(d.deleteIndex, 1);
  2940. }
  2941. }
  2942. // 处理新增
  2943. if (data.create) {
  2944. const newNodes = data.create;
  2945. if (newNodes) {
  2946. newNodes.sort(function (a, b) {
  2947. return a.index - b.index;
  2948. });
  2949. for (const node of newNodes) {
  2950. sheet.addRows(node.index, 1);
  2951. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  2952. }
  2953. }
  2954. }
  2955. // 处理更新
  2956. if (data.update) {
  2957. const rows = [];
  2958. for (const u of data.update) {
  2959. rows.push(tree.nodes.indexOf(u));
  2960. }
  2961. SpreadJsObj.reLoadRowsData(sheet, rows);
  2962. }
  2963. // 处理展开
  2964. if (data.expand) {
  2965. const expanded = [];
  2966. for (const e of data.expand) {
  2967. if (expanded.indexOf(e) === -1) {
  2968. const posterity = tree.getPosterity(e);
  2969. for (const p of posterity) {
  2970. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  2971. expanded.push(p);
  2972. }
  2973. }
  2974. }
  2975. }
  2976. });
  2977. },
  2978. topRowChanged: function (e, info) {
  2979. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  2980. },
  2981. selectionChanged: function (e, info) {
  2982. if (info.newSelections) {
  2983. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  2984. // ledgerTreeSpreadObj.refreshOperationValid(info.sheet);
  2985. ledgerTreeSpreadObj.refreshPosData();
  2986. }
  2987. }
  2988. ledgerTreeSpreadObj.loadExprToInput(info.sheet);
  2989. },
  2990. refreshPosData: function() {
  2991. SpreadJsObj.resetTopAndSelect(posSheet);
  2992. posSpreadObj.loadCurPosData();
  2993. SpreadJsObj.saveTopAndSelect(ledgerSheet, ckBillsSpread);
  2994. // posSearch.search($('#pos-keyword').val());
  2995. },
  2996. getDefaultSelectInfo: function (sheet) {
  2997. const tree = sheet.zh_tree;
  2998. if (!tree) return;
  2999. const sel = sheet.getSelections()[0];
  3000. const node = sheet.zh_tree.nodes[sel.row];
  3001. if (!node) return;
  3002. let count = 1;
  3003. if (sel.rowCount > 1) {
  3004. for (let r = 1; r < sel.rowCount; r++) {
  3005. const rNode = sheet.zh_tree.nodes[sel.row + r];
  3006. if (rNode.level > node.level) continue;
  3007. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  3008. toastr.warning('请选择同一节点下的节点,进行该操作');
  3009. return;
  3010. }
  3011. count += 1;
  3012. }
  3013. }
  3014. return [tree, node, count];
  3015. },
  3016. _checkExprValid(expr) {
  3017. if (!expr) return [true, null];
  3018. const param = [];
  3019. let num = '', base = '';
  3020. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  3021. if (/^[\d\.%]+/.test(expr[i])) {
  3022. if (base !== '') {
  3023. param.push({type: 'base', value: base});
  3024. base = '';
  3025. }
  3026. num = num + expr[i];
  3027. } else if (expr[i] === '(') {
  3028. if (num !== '') {
  3029. param.push({type: 'num', value: num});
  3030. num = '';
  3031. }
  3032. if (base !== '') {
  3033. param.push({type: 'base', value: base});
  3034. base = '';
  3035. }
  3036. param.push({type: 'left', value: '('});
  3037. } else if (expr[i] === ')') {
  3038. if (num !== '') {
  3039. param.push({type: 'num', value: num});
  3040. num = '';
  3041. }
  3042. if (base !== '') {
  3043. param.push({type: 'base', value: base});
  3044. base = '';
  3045. }
  3046. param.push({type: 'right', value: ')'});
  3047. } else if (/^[\+\-*\/]/.test(expr[i])) {
  3048. if (num !== '') {
  3049. param.push({type: 'num', value: num});
  3050. num = '';
  3051. }
  3052. if (base !== '') {
  3053. param.push({type: 'base', value: base});
  3054. base = '';
  3055. }
  3056. param.push({type: 'calc', value: expr[i]});
  3057. } else {
  3058. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  3059. }
  3060. }
  3061. if (num !== '') {
  3062. param.push({type: 'num', value: num});
  3063. num = '';
  3064. }
  3065. if (base !== '') {
  3066. param.push({type: 'base', value: base});
  3067. base = '';
  3068. }
  3069. if (param.length === 0) return true;
  3070. if (param.length > 1) {
  3071. if (param[0].value === '-' && param[1].type === 'num') {
  3072. param[1].value = '-' + param[1].value;
  3073. param.shift();
  3074. }
  3075. }
  3076. const iLen = param.length;
  3077. let iLeftCount = 0, iRightCount = 0;
  3078. for (const [i, p] of param.entries()) {
  3079. if (p.type === 'calc') {
  3080. if (i === 0 || i === iLen - 1)
  3081. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  3082. }
  3083. if (p.type === 'num') {
  3084. num = p.value.replace('%', '');
  3085. if (p.value.length - num.length > 1)
  3086. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  3087. num = _.toNumber(num);
  3088. if (num === undefined || num === null || _.isNaN(num))
  3089. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  3090. if (i > 0) {
  3091. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  3092. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  3093. } else if (param[i - 1].value === '/' && num === 0) {
  3094. return [false, '输入的表达式非法:请勿除0'];
  3095. }
  3096. }
  3097. }
  3098. if (p.type === 'base') {
  3099. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  3100. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  3101. }
  3102. if (p.type === 'left') {
  3103. iLeftCount += 1;
  3104. if (i !== 0 && param[i-1].type !== 'calc')
  3105. return [false, '输入的表达式非法:(前应有运算符'];
  3106. }
  3107. if (p.type === 'right') {
  3108. iRightCount += 1;
  3109. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  3110. return [false, '输入的表达式非法:)后应有运算符'];
  3111. if (iRightCount > iLeftCount)
  3112. return [false, '输入的表达式非法:")"前无对应的"("'];
  3113. }
  3114. }
  3115. if (iLeftCount > iRightCount)
  3116. return [false, '输入的表达式非法:"("后无对应的")"'];
  3117. return [true, ''];
  3118. },
  3119. _checkExpr: function (text, data) {
  3120. if (text) {
  3121. const num = _.toNumber(text);
  3122. if (num) {
  3123. data.quantity = num;
  3124. data.expr = '';
  3125. } else {
  3126. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  3127. const [valid, msg] = this._checkExprValid(expr);
  3128. if (!valid) return [valid, msg];
  3129. data.expr = expr;
  3130. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  3131. // const ce = new CalcEvalMin();
  3132. // data.quantity = ce.eval(expr);
  3133. // console.log(data.quantity);
  3134. }
  3135. } else {
  3136. data.quantity = 0;
  3137. data.expr = '';
  3138. }
  3139. return [true, ''];
  3140. },
  3141. }
  3142. ledgerSpread.bind(spreadNS.Events.SelectionChanged, ledgerTreeSpreadObj.selectionChanged);
  3143. ledgerSpread.bind(spreadNS.Events.topRowChanged, ledgerTreeSpreadObj.topRowChanged);
  3144. // 初始化 计量单元
  3145. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  3146. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  3147. const posSheet = posSpread.getActiveSheet();
  3148. const posSpreadSetting = {
  3149. cols: [
  3150. {title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 50, cellType: 'checkbox', readOnly: 'readOnly.isValuation'},
  3151. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  3152. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  3153. {title: '计量上限(%)', colSpan: '1', rowSpan: '2', field: 'delimit', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isSettle2', visible: openChangeState},
  3154. {title: '原设计|数量', colSpan: '1|1', rowSpan: '|1', field: 'oamount2', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.isSettle', getValue: 'getValue.oamount2'},
  3155. {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle2', getValue: 'getValue.camount'},
  3156. ],
  3157. emptyRows: 0,
  3158. headRows: 2,
  3159. headRowHeight: [25, 25],
  3160. defaultRowHeight: 21,
  3161. headerFont: '12px 微软雅黑',
  3162. font: '12px 微软雅黑',
  3163. rowHeader:[
  3164. {
  3165. rowHeaderType: 'circle',
  3166. setting: {
  3167. size: 5,
  3168. indent: 16,
  3169. getColor: function (index, data) {
  3170. if (!data) return;
  3171. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  3172. return '#dc3545';
  3173. }
  3174. if(data.lid != 0) return;
  3175. return '#007bff';
  3176. }
  3177. },
  3178. },
  3179. ],
  3180. };
  3181. if (readOnly) {
  3182. posSpreadSetting.cols.push({title: '批复变更|数量', colSpan: '1|1', rowSpan: '|1', field: 'samount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.samount'});
  3183. for (const aid of aidList) {
  3184. // const userinfo = _.find(auditList2, { 'uid': aid });
  3185. const audit = _.find(auditors2, function(item){
  3186. return _.findIndex(item, { audit_order: aid }) !== -1;
  3187. });
  3188. const newColcount = {
  3189. title: (audit && audit.length > 1 ? (aid + '审') : audit[0].name) + ' 审批|数量',
  3190. colSpan: '1|1', rowSpan: '|1',
  3191. field: 'audit_amount_' + aid,
  3192. hAlign: 2, width: 120, type: 'Number', readOnly: _.findIndex(audit, { uid: parseInt(accountId) }) === -1 ? true : 'readOnly.isSettle' ,
  3193. };
  3194. posSpreadSetting.cols.push(newColcount);
  3195. }
  3196. }
  3197. posSpreadSetting.cols.push({title: '变更后|数量', colSpan: '1|1', rowSpan: '|1', field: 'changed_amount', hAlign: 2, width: 120, type: 'Number', readOnly: true, getValue: 'getValue.changed_amount'},);
  3198. const posCol = {
  3199. getValue: {
  3200. oamount2: function (data) {
  3201. return ZhCalc.round(data.oamount2, findDecimal(data.unit));
  3202. },
  3203. camount: function (data) {
  3204. return ZhCalc.round(data.camount, findDecimal(data.unit));
  3205. },
  3206. samount: function (data) {
  3207. return ZhCalc.round(data.samount, findDecimal(data.unit));
  3208. },
  3209. changed_amount: function (data) {
  3210. return readOnly ? ZhCalc.round(ZhCalc.add(data.oamount2, data.spamount), findDecimal(data.unit)) : ZhCalc.round(ZhCalc.add(data.oamount2, data.camount), findDecimal(data.unit));
  3211. },
  3212. },
  3213. readOnly: {
  3214. isEdit: function (data) {
  3215. return readOnly;
  3216. },
  3217. isValuation: function (data) {
  3218. return !(!readOnly && _.findIndex(changeUsedData, { cbid: data.clid }) !== -1);
  3219. },
  3220. isSettle: function (data) {
  3221. return !((!readOnly || shenpiPower) && !checkIsSettle(data));
  3222. },
  3223. isSettle2: function (data) {
  3224. return !(!readOnly && !checkIsSettle(data));
  3225. }
  3226. },
  3227. }
  3228. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  3229. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  3230. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  3231. // 计量单元 相关方法&绑定spreadjs事件
  3232. const posSpreadObj = {
  3233. loadExprToInput: function () {
  3234. const sel = posSheet.getSelections()[0];
  3235. if (!sel) return;
  3236. const col = posSheet.zh_setting.cols[sel.col];
  3237. const data = SpreadJsObj.getSelectObject(posSheet);
  3238. if (col && col.field === 'camount' && data) {
  3239. if (readOnly) {
  3240. $('#pos-camount-expr').val(data.camount_expr ? data.camount_expr : data.camount);
  3241. } else {
  3242. $('#pos-camount-expr').removeAttr('readonly').val(data.camount_expr ? data.camount_expr : data.camount);
  3243. }
  3244. } else {
  3245. $('#pos-camount-expr').attr('readonly', true).val('');
  3246. }
  3247. },
  3248. /**
  3249. * 加载计量单元 根据当前台账选择节点
  3250. */
  3251. loadCurPosData: function () {
  3252. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  3253. if (node) {
  3254. const posData = pos.getLedgerPos(node.id) || [];
  3255. console.log(posData);
  3256. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  3257. } else {
  3258. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  3259. }
  3260. posSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  3261. SpreadJsObj.resetTopAndSelect(posSheet);
  3262. posSpreadObj.loadExprToInput();
  3263. },
  3264. selectionChanged: function (e, info) {
  3265. posSpreadObj.loadExprToInput();
  3266. },
  3267. showHideAudit: function (show = false) {
  3268. if (shenpiPower) {
  3269. show = true;
  3270. }
  3271. if (readOnly) {
  3272. const posStartLimit = 4;
  3273. const count = posSpreadSetting.cols.length;
  3274. for (let i = posStartLimit + 2; i < count - 1; i++) {
  3275. posSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  3276. }
  3277. posSheet.setColumnVisible(posStartLimit + 2, !show, GC.Spread.Sheets.SheetArea.viewport);
  3278. }
  3279. },
  3280. }
  3281. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  3282. if (!readOnly) {
  3283. // 台账修改
  3284. ledgerTreeSpreadObj.del = function () {
  3285. const self = this;
  3286. const [tree, node, count] = this.getDefaultSelectInfo(ledgerSheet);
  3287. if (!tree || !node || !count) return;
  3288. const delList = [];
  3289. let lastSelect = null;
  3290. let hadTaiZhang = false;
  3291. const selects = [];
  3292. const parent = tree.getParent(node);
  3293. const children = parent ? parent.children : tree.children;
  3294. const index = children.indexOf(node);
  3295. for (let r = 0; r < count; r++) {
  3296. const select = children[r+index];
  3297. if (!select || _.find(changeUsedData, { cbid: select.clid })) {
  3298. toastr.error('已调用的变更清单不能删除');
  3299. return false;
  3300. }
  3301. if (checkIsSettle(select)) {
  3302. toastr.error('已结算的变更清单不能删除');
  3303. return false;
  3304. }
  3305. if (r === count - 1 && changeOrder) {
  3306. lastSelect = select;
  3307. }
  3308. if (select.lid != 0) {
  3309. hadTaiZhang = true;
  3310. }
  3311. delList.push(select.clid);
  3312. selects.push(select);
  3313. }
  3314. if (delList.length) {
  3315. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
  3316. const loadResult = {
  3317. delete: selects,
  3318. }
  3319. // 判断父节点是否也要移除
  3320. if (children.length === count) {
  3321. loadResult.delete.push(parent);
  3322. const parentNodes = _.reverse(ledgerTree.getAllParents(parent));
  3323. for (const node of parentNodes) {
  3324. if (node.children && node.children.length === 1) {
  3325. loadResult.delete.push(node);
  3326. } else {
  3327. break;
  3328. }
  3329. }
  3330. }
  3331. const refreshData = ledgerTree.loadPostData(loadResult);
  3332. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3333. ledgerSheet.setSelection(0, 0, 1, 1);
  3334. ledgerTreeSpreadObj.refreshPosData();
  3335. });
  3336. }
  3337. };
  3338. ledgerTreeSpreadObj.editStarting = function (e, info) {
  3339. const select = SpreadJsObj.getSelectObject(ledgerSheet);
  3340. const col = info.sheet.zh_setting.cols[info.col];
  3341. if (col.field === 'camount') {
  3342. if (select.camount_expr && select.camount_expr !== '') {
  3343. info.sheet.getCell(info.row, info.col).text(select.camount_expr);
  3344. }
  3345. }
  3346. };
  3347. ledgerTreeSpreadObj.editEnded = function (e, info) {
  3348. if (!info.sheet.zh_setting) {
  3349. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3350. return;
  3351. }
  3352. const col = info.sheet.zh_setting.cols[info.col];
  3353. if (col.field === 'is_valuation') {
  3354. return;
  3355. }
  3356. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3357. const select = sortData[info.row];
  3358. if (!select || !select.clid) {
  3359. toastr.error('数据错误,请刷新页面重试');
  3360. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3361. return;
  3362. }
  3363. const cInfo = _.find(changeList, { id: select.clid });
  3364. if (!cInfo) {
  3365. toastr.error('数据错误,请刷新页面重试');
  3366. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3367. return;
  3368. }
  3369. let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  3370. let orgValue;
  3371. if (col.field === 'camount') {
  3372. orgValue = validText && validText !== ''
  3373. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  3374. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  3375. } else {
  3376. orgValue = select[col.field];
  3377. }
  3378. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  3379. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3380. return;
  3381. }
  3382. if(col.field === 'camount') {
  3383. const exprQuantity = {
  3384. expr: '',
  3385. quantity: 0,
  3386. };
  3387. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  3388. if (!valid) {
  3389. toastr.error(msg);
  3390. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3391. return;
  3392. }
  3393. if (isNaN(exprQuantity.quantity)) {
  3394. toastr.error('不能输入其它非数字类型字符');
  3395. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3396. return;
  3397. }
  3398. validText = parseFloat(exprQuantity.quantity);
  3399. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3400. const usedInfo = _.find(changeUsedData, { cbid: select.clid });
  3401. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3402. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3403. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3404. return;
  3405. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3406. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3407. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3408. return;
  3409. }
  3410. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  3411. select.camount_expr = exprQuantity.expr;
  3412. cInfo.spamount = select.spamount;
  3413. cInfo.camount_expr = exprQuantity.expr;
  3414. }
  3415. if (col.type === 'Number') {
  3416. if (isNaN(validText)) {
  3417. toastr.error('不能输入其它非数字类型字符');
  3418. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3419. return;
  3420. }
  3421. if (col.field === 'unit_price') {
  3422. validText = ZhCalc.round(validText, unitPriceUnit);
  3423. } else {
  3424. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  3425. }
  3426. if (col.field === 'delimit') {
  3427. const reg = /^(\d{1,2}|100)$/;
  3428. if (!(_.isNumber(validText) && reg.test(validText))) {
  3429. toastr.error('计量上限默认值只能输入0-100之间的整数');
  3430. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3431. return;
  3432. }
  3433. // 需要判断是否已调用,已调用的则不能低于原有值大小
  3434. const usedInfo = _.find(changeUsedData, { cbid: select.clid });
  3435. if (usedInfo && usedInfo.qty) {
  3436. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
  3437. if (validText < minLimit) {
  3438. toastr.error('计量上限值至少大于等于 ' + minLimit);
  3439. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3440. return;
  3441. }
  3442. }
  3443. }
  3444. }
  3445. if (col.field === 'unit') {
  3446. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  3447. select.oamount2 = ZhCalc.round(select.oamount2, findDecimal(validText)) || 0;
  3448. cInfo.camount = select.camount;
  3449. cInfo.oamount2 = select.oamount2;
  3450. }
  3451. if (col.field === 'b_code') {
  3452. cInfo.code = validText;
  3453. } else {
  3454. cInfo[col.field] = validText;
  3455. }
  3456. cInfo[col.field] = validText;
  3457. select[col.field] = validText;
  3458. console.log(cInfo);
  3459. delete cInfo.waitingLoading;
  3460. // 更新至服务器
  3461. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  3462. const loadResult = {
  3463. update: [select],
  3464. };
  3465. const refreshData = ledgerTree.loadPostData(loadResult);
  3466. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3467. }, function () {
  3468. select[col.field] = orgValue;
  3469. if (col.field === 'b_code') {
  3470. cInfo.code = orgValue;
  3471. } else {
  3472. cInfo[col.field] = orgValue;
  3473. }
  3474. if(col.field === 'camount') {
  3475. select.spamount = orgValue;
  3476. cInfo.spamount = orgValue;
  3477. }
  3478. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3479. });
  3480. };
  3481. ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
  3482. const tree = info.sheet.zh_tree;
  3483. if (!tree) { return; }
  3484. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  3485. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  3486. }
  3487. const hint = {
  3488. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  3489. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  3490. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  3491. };
  3492. const range = info.cellRange;
  3493. const sortData = info.sheet.zh_tree.nodes;
  3494. const selects = [];
  3495. const data = [];
  3496. let needCopyIgnore = !$('#customCheck1').is(':checked');
  3497. let needColAdd = false;
  3498. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  3499. let bPaste = true;
  3500. const curRow = range.row + iRow;
  3501. const node = sortData[curRow];
  3502. if (!node) {
  3503. continue;
  3504. }
  3505. const cLData = { id: sortData[curRow].clid };
  3506. const hintRow = range.rowCount >= 1 ? curRow : '';
  3507. let sameCol = 0;
  3508. for (let iCol = 0; iCol < range.colCount; iCol++) {
  3509. const curCol = range.col + iCol;
  3510. let colSetting = info.sheet.zh_setting.cols[curCol];
  3511. if ((needColAdd && curCol > 6) || (needCopyIgnore && curCol === 6)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  3512. const newCurCol = curCol + 1;
  3513. needColAdd = true;
  3514. colSetting = info.sheet.zh_setting.cols[newCurCol];
  3515. }
  3516. if (!colSetting) continue;
  3517. let validText = info.sheet.getText(curRow, curCol);
  3518. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  3519. let orgValue;
  3520. if (colSetting.field === 'camount') {
  3521. orgValue = validText && validText !== ''
  3522. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  3523. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  3524. } else {
  3525. orgValue = sortData[curRow][colSetting.field];
  3526. }
  3527. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  3528. sameCol++;
  3529. if (range.colCount === sameCol) {
  3530. bPaste = false;
  3531. }
  3532. continue;
  3533. }
  3534. if(colSetting.field === 'camount') {
  3535. const exprQuantity = {
  3536. expr: '',
  3537. quantity: 0,
  3538. };
  3539. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  3540. if (!valid) {
  3541. toastMessageUniq(getPasteHint(msg, hintRow));
  3542. bPaste = false;
  3543. continue;
  3544. }
  3545. if (isNaN(exprQuantity.quantity)) {
  3546. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  3547. bPaste = false;
  3548. continue;
  3549. }
  3550. validText = parseFloat(exprQuantity.quantity);
  3551. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3552. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
  3553. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3554. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3555. bPaste = false;
  3556. continue;
  3557. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3558. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3559. bPaste = false;
  3560. continue;
  3561. }
  3562. cLData.camount_expr = exprQuantity.expr;
  3563. sortData[curRow].camount_expr = exprQuantity.expr;
  3564. }
  3565. if (colSetting.type === 'Number') {
  3566. if (isNaN(validText)) {
  3567. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  3568. bPaste = false;
  3569. continue;
  3570. }
  3571. if (colSetting.field === 'unit_price') {
  3572. validText = ZhCalc.round(validText, unitPriceUnit);
  3573. } else {
  3574. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  3575. }
  3576. if (colSetting.field === 'delimit') {
  3577. const reg = /^(\d{1,2}|100)$/;
  3578. if (!(_.isNumber(validText) && reg.test(validText))) {
  3579. toastr.error('清单第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  3580. bPaste = false;
  3581. continue;
  3582. }
  3583. // 需要判断是否已调用,已调用的则不能低于原有值大小
  3584. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
  3585. if (usedInfo && usedInfo.qty) {
  3586. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  3587. if (validText < minLimit) {
  3588. toastr.error('清单第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  3589. bPaste = false;
  3590. continue;
  3591. }
  3592. }
  3593. }
  3594. }
  3595. let unitdecimal = validText;
  3596. if (colSetting.field === 'unit') {
  3597. //粘贴内容要为下拉列表里所有的单位,不然为空
  3598. if (changeUnits.indexOf(validText) === -1) {
  3599. unitdecimal = '';
  3600. }
  3601. cLData.camount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  3602. cLData.oamount2 = ZhCalc.round(sortData[curRow].oamount2, findDecimal(unitdecimal)) || 0;
  3603. }
  3604. if (colSetting.field === 'b_code') {
  3605. cLData.code = validText;
  3606. } else {
  3607. cLData[colSetting.field] = validText;
  3608. }
  3609. sortData[curRow][colSetting.field] = validText;
  3610. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  3611. sortData[curRow].spamount = cLData.spamount;
  3612. }
  3613. if (bPaste) {
  3614. data.push(cLData);
  3615. selects.push(sortData[curRow]);
  3616. } else {
  3617. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  3618. }
  3619. }
  3620. if (data.length === 0) {
  3621. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3622. return;
  3623. }
  3624. console.log(data, selects);
  3625. // 更新至服务器
  3626. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  3627. changeList = result;
  3628. const loadResult = {
  3629. update: selects,
  3630. };
  3631. const refreshData = ledgerTree.loadPostData(loadResult);
  3632. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3633. ledgerTreeSpreadObj.loadExprToInput();
  3634. }, function () {
  3635. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3636. return;
  3637. });
  3638. };
  3639. ledgerTreeSpreadObj.buttonClicked = function(e, info) {
  3640. if (info.sheet.zh_setting) {
  3641. const select = SpreadJsObj.getSelectObject(info.sheet);
  3642. if (!select || !select.clid) {
  3643. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3644. return;
  3645. }
  3646. const cInfo = _.find(changeList, { id: select.clid });
  3647. if (!cInfo) {
  3648. toastr.error('数据错误,请刷新页面重试');
  3649. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3650. return;
  3651. }
  3652. const col = info.sheet.zh_setting.cols[info.col];
  3653. if (col.field === 'is_valuation') {
  3654. if (info.sheet.isEditing()) {
  3655. info.sheet.endEdit(true);
  3656. }
  3657. if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
  3658. return;
  3659. }
  3660. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  3661. cInfo.is_valuation = select.is_valuation;
  3662. delete cInfo.waitingLoading;
  3663. // 更新至服务器
  3664. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  3665. const loadResult = {
  3666. update: [select],
  3667. };
  3668. const refreshData = ledgerTree.loadPostData(loadResult);
  3669. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3670. }, function () {
  3671. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  3672. cInfo.is_valuation = select.is_valuation;
  3673. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3674. });
  3675. }
  3676. }
  3677. };
  3678. ledgerTreeSpreadObj.valueChanged = function(e, info) {
  3679. // 防止ctrl+z撤销数据
  3680. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3681. };
  3682. ledgerTreeSpreadObj.deletePress = function (sheet) {
  3683. if (!sheet.zh_setting) return;
  3684. // 暂时仅支持移除数量
  3685. const sel = sheet.getSelections()[0], datas = [];
  3686. const selects = [];
  3687. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3688. let bDel = false;
  3689. const node = sheet.zh_tree.nodes[iRow];
  3690. const cInfo = _.find(changeList, { id: node.clid });
  3691. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3692. const col = sheet.zh_setting.cols[iCol];
  3693. if (col.field === 'camount' || col.field === 'oamount2') {
  3694. node[col.field] = null;
  3695. cInfo[col.field] = null;
  3696. if (col.field === 'camount') {
  3697. node.camount_expr = '';
  3698. node.spamount = null;
  3699. cInfo.camount_expr = '';
  3700. cInfo.spamount = null;
  3701. }
  3702. delete cInfo.waitingLoading;
  3703. bDel = true;
  3704. }
  3705. }
  3706. if (bDel) {
  3707. datas.push(cInfo);
  3708. selects.push(node);
  3709. }
  3710. }
  3711. console.log(datas, selects);
  3712. if (datas.length > 0) {
  3713. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  3714. changeList = result;
  3715. const loadResult = {
  3716. update: selects,
  3717. };
  3718. const refreshData = ledgerTree.loadPostData(loadResult);
  3719. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3720. ledgerTreeSpreadObj.loadExprToInput();
  3721. }, function () {
  3722. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3723. return;
  3724. });
  3725. }
  3726. return;
  3727. };
  3728. // 表达式判断
  3729. $('#ledger-camount-expr').change(function () {
  3730. if (this.readOnly) return;
  3731. let validText = $(this).val();
  3732. const sel = ledgerSheet.getSelections()[0];
  3733. const row = sel ? sel.row : -1;
  3734. const col = ledgerSheet.zh_setting.cols[sel.col];
  3735. if (row === -1 || !(col && col.field === 'camount')) return;
  3736. const select = SpreadJsObj.getSelectObject(ledgerSheet);
  3737. if (!select || !select.clid) return;
  3738. const cInfo = _.find(changeList, { id: select.clid });
  3739. if (!cInfo) return;
  3740. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  3741. let orgValue = validText && validText !== ''
  3742. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  3743. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  3744. const orgExprValue = _.clone(select.camount_expr);
  3745. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  3746. return;
  3747. }
  3748. const exprQuantity = {
  3749. expr: '',
  3750. quantity: 0,
  3751. };
  3752. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  3753. if (!valid) {
  3754. toastr.error(msg);
  3755. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  3756. return;
  3757. }
  3758. if (isNaN(exprQuantity.quantity)) {
  3759. toastr.error('不能输入其它非数字类型字符');
  3760. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  3761. return;
  3762. }
  3763. validText = parseFloat(exprQuantity.quantity);
  3764. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3765. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  3766. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3767. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3768. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  3769. return;
  3770. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3771. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3772. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  3773. return;
  3774. }
  3775. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  3776. select.camount_expr = exprQuantity.expr;
  3777. select.camount = validText;
  3778. cInfo.spamount = select.spamount;
  3779. cInfo.camount_expr = select.camount_expr;
  3780. cInfo.camount = validText;
  3781. // console.log(select);
  3782. delete cInfo.waitingLoading;
  3783. // 更新至服务器
  3784. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  3785. const loadResult = {
  3786. update: [select],
  3787. };
  3788. const refreshData = ledgerTree.loadPostData(loadResult);
  3789. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3790. }, function () {
  3791. select.camount = orgValue;
  3792. select.camount_expr = orgExprValue;
  3793. select.spamount = orgValue;
  3794. cInfo.camount = orgValue;
  3795. cInfo.camount_expr = orgExprValue;
  3796. cInfo.spamount = orgValue;
  3797. SpreadJsObj.reLoadRowData(posSheet, row);
  3798. });
  3799. });
  3800. ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
  3801. ledgerSpread.bind(spreadNS.Events.EditStarting, ledgerTreeSpreadObj.editStarting);
  3802. ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
  3803. ledgerSpread.bind(spreadNS.Events.ValueChanged, ledgerTreeSpreadObj.valueChanged);
  3804. ledgerSpread.bind(spreadNS.Events.ButtonClicked, ledgerTreeSpreadObj.buttonClicked);
  3805. SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
  3806. // 计量单元修改
  3807. posSpreadObj.del = function () {
  3808. const selection = posSheet.getSelections();
  3809. const sel = selection ? selection[0] : posSheet.getSelections()[0];
  3810. const row = sel && sel.row !== undefined ? sel.row : -1;
  3811. const count = sel.rowCount;
  3812. if (readOnly || row === -1 || row + count > posSheet.zh_data.length) {
  3813. return false;
  3814. }
  3815. const delList = [];
  3816. let lastSelect = null;
  3817. let hadTaiZhang = false;
  3818. const selects = [];
  3819. for (let r = 0; r < count; r++) {
  3820. const select = posSheet.zh_data[row + r];
  3821. if(!select || _.find(changeUsedData, { cbid: select.clid })) {
  3822. toastr.error('已调用的变更清单不能删除');
  3823. return false;
  3824. }
  3825. if (checkIsSettle(select)) {
  3826. toastr.error('已结算的变更清单不能删除');
  3827. return false;
  3828. }
  3829. if (r === count - 1 && changeOrder) {
  3830. lastSelect = select;
  3831. }
  3832. if (select.lid != 0) {
  3833. hadTaiZhang = true;
  3834. }
  3835. delList.push(select.clid);
  3836. selects.push(select.id);
  3837. }
  3838. if (delList.length) {
  3839. postData(window.location.pathname + '/save', {type: 'del', ids: delList, postData: lastSelect ? lastSelect.order : null}, function (result) {
  3840. pos.removeDatas(selects);
  3841. posSheet.deleteRows(row, count);
  3842. const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
  3843. const loadResult = {};
  3844. // 判断是移除还是更新数量和金额
  3845. if (posSheet.zh_data.length === 0) {
  3846. // 判断父节点是否也要移除
  3847. const parentNodes = _.reverse(ledgerTree.getAllParents(billsNode));
  3848. loadResult.delete = [billsNode];
  3849. for (const node of parentNodes) {
  3850. if (node.children && node.children.length === 1) {
  3851. loadResult.delete.push(node);
  3852. } else {
  3853. break;
  3854. }
  3855. }
  3856. } else {
  3857. loadResult.update = [billsNode];
  3858. }
  3859. if (loadResult.update || loadResult.delete) {
  3860. const refreshData = ledgerTree.loadPostData(loadResult);
  3861. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3862. if (loadResult.delete) {
  3863. ledgerSheet.setSelection(0, 0, 1, 1);
  3864. ledgerTreeSpreadObj.refreshPosData();
  3865. }
  3866. }
  3867. });
  3868. }
  3869. };
  3870. posSpreadObj.editStarting = function (e, info) {
  3871. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
  3872. const col = info.sheet.zh_setting.cols[info.col];
  3873. const select = SpreadJsObj.getSelectObject(info.sheet);
  3874. if (col.field === 'camount') {
  3875. if (select.camount_expr && select.camount_expr !== '') {
  3876. info.sheet.getCell(info.row, info.col).text(select.camount_expr);
  3877. }
  3878. }
  3879. };
  3880. posSpreadObj.editEnded = function (e, info) {
  3881. if (!info.sheet.zh_setting) {
  3882. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3883. return;
  3884. }
  3885. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  3886. const cInfo = _.find(changeList, { id: select.clid });
  3887. if (!cInfo) {
  3888. toastr.error('数据错误,请刷新页面重试');
  3889. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3890. return;
  3891. }
  3892. const col = info.sheet.zh_setting.cols[info.col];
  3893. if (col.field === 'is_valuation') {
  3894. return;
  3895. }
  3896. let validText = is_numeric(info.editingText) && _.indexOf(numField, col.field) !== -1 ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  3897. let orgValue;
  3898. if (col.field === 'camount') {
  3899. orgValue = validText && validText !== ''
  3900. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  3901. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  3902. } else {
  3903. orgValue = select[col.field];
  3904. }
  3905. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  3906. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3907. return;
  3908. }
  3909. const node = posSpreadObj.billsNode;
  3910. if (!node) {
  3911. toastr.error('数据错误,请选择台账节点后再试');
  3912. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3913. return;
  3914. }
  3915. if(col.field === 'camount') {
  3916. const exprQuantity = {
  3917. expr: '',
  3918. quantity: 0,
  3919. };
  3920. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  3921. if (!valid) {
  3922. toastr.error(msg);
  3923. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3924. return;
  3925. }
  3926. if (isNaN(exprQuantity.quantity)) {
  3927. toastr.error('不能输入其它非数字类型字符');
  3928. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3929. return;
  3930. }
  3931. validText = parseFloat(exprQuantity.quantity);
  3932. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3933. const usedInfo = _.find(changeUsedData, { cbid: select.clid });
  3934. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3935. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3936. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3937. return;
  3938. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3939. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3940. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3941. return;
  3942. }
  3943. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  3944. select.camount_expr = exprQuantity.expr;
  3945. cInfo.spamount = select.spamount;
  3946. cInfo.camount_expr = exprQuantity.expr;
  3947. }
  3948. if (col.type === 'Number') {
  3949. if (isNaN(validText)) {
  3950. toastr.error('不能输入其它非数字类型字符');
  3951. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3952. return;
  3953. }
  3954. if (col.field === 'unit_price') {
  3955. validText = ZhCalc.round(validText, unitPriceUnit);
  3956. } else {
  3957. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  3958. }
  3959. if (col.field === 'delimit') {
  3960. const reg = /^(\d{1,2}|100)$/;
  3961. if (!(_.isNumber(validText) && reg.test(validText))) {
  3962. toastr.error('计量上限默认值只能输入0-100之间的整数');
  3963. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3964. return;
  3965. }
  3966. // 需要判断是否已调用,已调用的则不能低于原有值大小
  3967. const usedInfo = _.find(changeUsedData, { cbid: select.clid });
  3968. if (usedInfo && usedInfo.qty) {
  3969. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, select.camount), 100));
  3970. if (validText < minLimit) {
  3971. toastr.error('计量上限值至少大于等于 ' + minLimit);
  3972. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3973. return;
  3974. }
  3975. }
  3976. }
  3977. }
  3978. cInfo[col.field] = validText;
  3979. select[col.field] = validText;
  3980. console.log(cInfo);
  3981. delete cInfo.waitingLoading;
  3982. // 更新至服务器
  3983. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  3984. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3985. const loadResult = {
  3986. update: [node],
  3987. };
  3988. const refreshData = ledgerTree.loadPostData(loadResult);
  3989. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  3990. }, function () {
  3991. select[col.field] = orgValue;
  3992. cInfo[col.field] = orgValue;
  3993. if(col.field === 'camount') {
  3994. select.spamount = orgValue;
  3995. cInfo.spamount = orgValue;
  3996. }
  3997. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3998. });
  3999. };
  4000. posSpreadObj.clipboardPasted = function (e, info) {
  4001. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4002. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4003. }
  4004. const hint = {
  4005. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4006. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4007. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4008. };
  4009. const range = info.cellRange;
  4010. const sortData = info.sheet.zh_data || [];
  4011. if (range.row + range.rowCount > sortData.length) {
  4012. toastMessageUniq(hint.cellError);
  4013. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  4014. posSpreadObj.loadCurPosData();
  4015. return;
  4016. }
  4017. if (sortData.length > 0 && range.col + range.colCount > 6) {
  4018. toastMessageUniq(hint.cellError);
  4019. posSpreadObj.loadCurPosData();
  4020. return;
  4021. }
  4022. if (!info.sheet.zh_setting) {
  4023. posSpreadObj.loadCurPosData();
  4024. return;
  4025. }
  4026. const data = [];
  4027. // const rowData = [];
  4028. let needCopyIgnore = !$('#customCheck1').is(':checked');
  4029. let needColAdd = false;
  4030. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4031. let bPaste = true;
  4032. const curRow = range.row + iRow;
  4033. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  4034. const cLData = { id: sortData[curRow].clid };
  4035. const hintRow = range.rowCount >= 1 ? curRow : '';
  4036. let sameCol = 0;
  4037. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4038. const curCol = range.col + iCol;
  4039. let colSetting = info.sheet.zh_setting.cols[curCol];
  4040. if ((needColAdd && curCol > 2) || (needCopyIgnore && curCol === 2)) { // 要判断是否已隐藏了变更详情,是则变更详情后面的curCol要+1
  4041. const newCurCol = curCol + 1;
  4042. needColAdd = true;
  4043. colSetting = info.sheet.zh_setting.cols[newCurCol];
  4044. }
  4045. if (!colSetting) continue;
  4046. let validText = info.sheet.getText(curRow, curCol);
  4047. validText = is_numeric(validText) && _.indexOf(numField, colSetting.field) !== -1 ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4048. let orgValue;
  4049. if (colSetting.field === 'camount') {
  4050. orgValue = validText && validText !== ''
  4051. ? (_.toNumber(validText) ? sortData[curRow].camount : sortData[curRow].camount_expr)
  4052. : (sortData[curRow].camount_expr && sortData[curRow].camount_expr !== '' ? sortData[curRow].camount_expr : sortData[curRow].camount);
  4053. } else {
  4054. orgValue = sortData[curRow][colSetting.field];
  4055. }
  4056. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4057. sameCol++;
  4058. if (range.colCount === sameCol) {
  4059. bPaste = false;
  4060. }
  4061. continue;
  4062. }
  4063. if(colSetting.field === 'camount') {
  4064. const exprQuantity = {
  4065. expr: '',
  4066. quantity: 0,
  4067. };
  4068. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  4069. if (!valid) {
  4070. toastMessageUniq(getPasteHint(msg, hintRow));
  4071. bPaste = false;
  4072. continue;
  4073. }
  4074. if (isNaN(exprQuantity.quantity)) {
  4075. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4076. bPaste = false;
  4077. continue;
  4078. }
  4079. validText = parseFloat(exprQuantity.quantity);
  4080. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4081. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
  4082. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4083. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4084. bPaste = false;
  4085. continue;
  4086. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4087. toastr.error(hintRow ? '清单第' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4088. bPaste = false;
  4089. continue;
  4090. }
  4091. cLData.camount_expr = exprQuantity.expr;
  4092. sortData[curRow].camount_expr = exprQuantity.expr;
  4093. }
  4094. if (colSetting.type === 'Number') {
  4095. if (isNaN(validText)) {
  4096. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4097. bPaste = false;
  4098. continue;
  4099. }
  4100. if (colSetting.field === 'unit_price') {
  4101. validText = ZhCalc.round(validText, unitPriceUnit);
  4102. } else {
  4103. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  4104. }
  4105. if (colSetting.field === 'delimit') {
  4106. const reg = /^(\d{1,2}|100)$/;
  4107. if (!(_.isNumber(validText) && reg.test(validText))) {
  4108. toastr.error('计量单元第' + (hintRow+1) + '行计量上限默认值只能粘贴0-100之间的整数');
  4109. bPaste = false;
  4110. continue;
  4111. }
  4112. // 需要判断是否已调用,已调用的则不能低于原有值大小
  4113. const usedInfo = _.find(changeUsedData, { cbid: sortData[curRow].clid });
  4114. if (usedInfo && usedInfo.qty) {
  4115. const minLimit = Math.ceil(ZhCalc.mul(ZhCalc.div(usedInfo.qty, sortData[curRow].camount), 100));
  4116. if (validText < minLimit) {
  4117. toastr.error('计量单元第' + (hintRow+1) + '行计量上限值至少大于等于 ' + minLimit);
  4118. bPaste = false;
  4119. continue;
  4120. }
  4121. }
  4122. }
  4123. }
  4124. let unitdecimal = validText;
  4125. cLData[colSetting.field] = validText;
  4126. sortData[curRow][colSetting.field] = validText;
  4127. cLData.spamount = ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  4128. }
  4129. if (bPaste) {
  4130. data.push(cLData);
  4131. // rowData.push(curRow);
  4132. } else {
  4133. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  4134. }
  4135. }
  4136. if (data.length === 0) {
  4137. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4138. return;
  4139. }
  4140. console.log(data);
  4141. // 更新至服务器
  4142. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  4143. changeList = result;
  4144. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  4145. const loadResult = {
  4146. update: [node],
  4147. };
  4148. const refreshData = ledgerTree.loadPostData(loadResult);
  4149. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4150. posSpreadObj.loadCurPosData();
  4151. }, function () {
  4152. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4153. return;
  4154. });
  4155. };
  4156. posSpreadObj.buttonClicked = function(e, info) {
  4157. if (info.sheet.zh_setting) {
  4158. const select = SpreadJsObj.getSelectObject(info.sheet);
  4159. const cInfo = _.find(changeList, { id: select.clid });
  4160. if (!cInfo) {
  4161. toastr.error('数据错误,请刷新页面重试');
  4162. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4163. return;
  4164. }
  4165. const col = info.sheet.zh_setting.cols[info.col];
  4166. if (col.field === 'is_valuation') {
  4167. if (info.sheet.isEditing()) {
  4168. info.sheet.endEdit(true);
  4169. }
  4170. if (_.findIndex(changeUsedData, { cbid: select.clid }) !== -1) {
  4171. return;
  4172. }
  4173. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  4174. cInfo.is_valuation = select.is_valuation;
  4175. delete cInfo.waitingLoading;
  4176. // 更新至服务器
  4177. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  4178. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4179. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  4180. const loadResult = {
  4181. update: [node],
  4182. };
  4183. const refreshData = ledgerTree.loadPostData(loadResult);
  4184. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4185. }, function () {
  4186. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  4187. cInfo.is_valuation = select.is_valuation;
  4188. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4189. });
  4190. }
  4191. }
  4192. };
  4193. posSpreadObj.valueChanged = function(e, info) {
  4194. // 防止ctrl+z撤销数据
  4195. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4196. };
  4197. posSpreadObj.deletePress = function (sheet) {
  4198. if (!sheet.zh_setting) return;
  4199. // 暂时仅支持移除数量
  4200. const sel = sheet.getSelections()[0], datas = [];
  4201. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  4202. let bDel = false;
  4203. const node = sheet.zh_data[iRow];
  4204. const cInfo = _.find(changeList, { id: node.clid });
  4205. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  4206. const col = sheet.zh_setting.cols[iCol];
  4207. if (col.field === 'camount' || col.field === 'oamount2') {
  4208. node[col.field] = null;
  4209. cInfo[col.field] = null;
  4210. if (col.field === 'camount') {
  4211. node.camount_expr = '';
  4212. node.spamount = null;
  4213. cInfo.camount_expr = '';
  4214. cInfo.spamount = null;
  4215. }
  4216. delete cInfo.waitingLoading;
  4217. bDel = true;
  4218. }
  4219. }
  4220. if (bDel) datas.push(cInfo);
  4221. }
  4222. if (datas.length > 0) {
  4223. postData(window.location.pathname + '/save', { type:'paste', updateData: datas }, function (result) {
  4224. changeList = result;
  4225. const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
  4226. const loadResult = {
  4227. update: [billsNode],
  4228. };
  4229. const refreshData = ledgerTree.loadPostData(loadResult);
  4230. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4231. posSpreadObj.loadCurPosData();
  4232. }, function () {
  4233. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  4234. return;
  4235. });
  4236. }
  4237. return;
  4238. };
  4239. // 表达式判断
  4240. $('#pos-camount-expr').change(function () {
  4241. if (this.readOnly) return;
  4242. let validText = $(this).val();
  4243. const sel = posSheet.getSelections()[0];
  4244. const row = sel ? sel.row : -1;
  4245. const col = posSheet.zh_setting.cols[sel.col];
  4246. if (row === -1 || !(col && col.field === 'camount')) return;
  4247. const select = SpreadJsObj.getSelectObject(posSheet);
  4248. if (!select) return;
  4249. const cInfo = _.find(changeList, { id: select.clid });
  4250. if (!cInfo) return;
  4251. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4252. let orgValue = validText && validText !== ''
  4253. ? (_.toNumber(validText) ? select.camount : select.camount_expr)
  4254. : (select.camount_expr && select.camount_expr !== '' ? select.camount_expr : select.camount);
  4255. const orgExprValue = _.clone(select.camount_expr);
  4256. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4257. return;
  4258. }
  4259. const exprQuantity = {
  4260. expr: '',
  4261. quantity: 0,
  4262. };
  4263. const [valid, msg] = ledgerTreeSpreadObj._checkExpr(validText, exprQuantity);
  4264. if (!valid) {
  4265. toastr.error(msg);
  4266. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4267. return;
  4268. }
  4269. if (isNaN(exprQuantity.quantity)) {
  4270. toastr.error('不能输入其它非数字类型字符');
  4271. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4272. return;
  4273. }
  4274. validText = parseFloat(exprQuantity.quantity);
  4275. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4276. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  4277. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4278. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4279. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4280. return;
  4281. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4282. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4283. $(this).val(select.camount_expr ? select.camount_expr : select.camount);
  4284. return;
  4285. }
  4286. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4287. select.camount_expr = exprQuantity.expr;
  4288. select.camount = validText;
  4289. cInfo.spamount = select.spamount;
  4290. cInfo.camount_expr = select.camount_expr;
  4291. cInfo.camount = validText;
  4292. // console.log(select);
  4293. delete cInfo.waitingLoading;
  4294. // 更新至服务器
  4295. postData(window.location.pathname + '/save', { type:'update', updateData: cInfo }, function (result) {
  4296. SpreadJsObj.reLoadRowData(posSheet, row);
  4297. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  4298. const loadResult = {
  4299. update: [node],
  4300. };
  4301. const refreshData = ledgerTree.loadPostData(loadResult);
  4302. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4303. }, function () {
  4304. select.camount = orgValue;
  4305. select.camount_expr = orgExprValue;
  4306. select.spamount = orgValue;
  4307. cInfo.camount = orgValue;
  4308. cInfo.camount_expr = orgExprValue;
  4309. cInfo.spamount = orgValue;
  4310. SpreadJsObj.reLoadRowData(posSheet, row);
  4311. });
  4312. });
  4313. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  4314. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  4315. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  4316. posSpread.bind(spreadNS.Events.ValueChanged, posSpreadObj.valueChanged);
  4317. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  4318. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  4319. // 右键菜单
  4320. $.contextMenu({
  4321. selector: '#ledger-spread',
  4322. build: function ($trigger, e) {
  4323. const target = SpreadJsObj.safeRightClickSelection($trigger, e, ledgerSpread);
  4324. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  4325. },
  4326. items: {
  4327. 'delete': {
  4328. name: '删除',
  4329. icon: 'fa-remove',
  4330. callback: function (key, opt) {
  4331. ledgerTreeSpreadObj.del();
  4332. },
  4333. disabled: function (key, opt) {
  4334. const selection = ledgerSheet.getSelections();
  4335. const sel = selection ? selection[0] : ledgerSheet.getSelections()[0];
  4336. const row = sel ? sel.row : -1;
  4337. const tree = ledgerSheet.zh_tree;
  4338. if (!tree) return true;
  4339. const first = ledgerSheet.zh_tree.nodes[row];
  4340. let last = first, sameParent = true, listValid = true;
  4341. if (sel.rowCount > 1 && first) {
  4342. for (let r = 1; r < sel.rowCount; r++) {
  4343. const rNode = tree.nodes[sel.row + r];
  4344. if (!rNode) {
  4345. sameParent = false;
  4346. break;
  4347. }
  4348. if (!rNode.clid) {
  4349. listValid = false;
  4350. break;
  4351. }
  4352. if (_.find(changeUsedData, { cbid: rNode.clid }) || checkIsSettle(rNode)) {
  4353. listValid = false;
  4354. break;
  4355. }
  4356. if (rNode.level > first.level) continue;
  4357. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  4358. sameParent = false;
  4359. break;
  4360. }
  4361. last = rNode;
  4362. }
  4363. }
  4364. const valid = !ledgerSheet.zh_setting.readOnly;
  4365. return !(valid && first && first.clid && !_.find(changeUsedData, { cbid: first.clid }) && !checkIsSettle(first) && sameParent && listValid);
  4366. }
  4367. },
  4368. // sprEdit: '----',
  4369. // 'allNotValuation': {
  4370. // name: '设置全部清单不计价',
  4371. // icon: 'fa-magic',
  4372. // callback: function (key, opt) {
  4373. // changeSpreadObj.setAllValuation(0);
  4374. // },
  4375. // },
  4376. // 'allValuation': {
  4377. // name: '设置全部清单计价',
  4378. // icon: 'fa-magic',
  4379. // callback: function (key, opt) {
  4380. // changeSpreadObj.setAllValuation(1);
  4381. // },
  4382. // },
  4383. }
  4384. });
  4385. // 右键菜单
  4386. $.contextMenu({
  4387. selector: '#pos-spread',
  4388. build: function ($trigger, e) {
  4389. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  4390. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  4391. },
  4392. items: {
  4393. 'delete': {
  4394. name: '删除',
  4395. icon: 'fa-remove',
  4396. callback: function (key, opt) {
  4397. posSpreadObj.del();
  4398. },
  4399. disabled: function (key, opt) {
  4400. const selection = posSheet.getSelections();
  4401. const sel = selection ? selection[0] : posSheet.getSelections()[0];
  4402. const row = sel && sel.row !== undefined ? sel.row : -1;
  4403. if (readOnly || row === -1 || sel.row + sel.rowCount > posSheet.zh_data.length) {
  4404. return true;
  4405. }
  4406. let isUsed = false;
  4407. for (let r = 0; r < sel.rowCount; r++) {
  4408. const select = posSheet.zh_data[row + r];
  4409. if(!select || _.find(changeUsedData, { cbid: select.clid })) {
  4410. isUsed = true;
  4411. }
  4412. if (checkIsSettle(select)) {
  4413. isUsed = true;
  4414. }
  4415. }
  4416. return isUsed;
  4417. }
  4418. },
  4419. // sprEdit: '----',
  4420. // 'allNotValuation': {
  4421. // name: '设置全部清单不计价',
  4422. // icon: 'fa-magic',
  4423. // callback: function (key, opt) {
  4424. // changeSpreadObj.setAllValuation(0);
  4425. // },
  4426. // },
  4427. // 'allValuation': {
  4428. // name: '设置全部清单计价',
  4429. // icon: 'fa-magic',
  4430. // callback: function (key, opt) {
  4431. // changeSpreadObj.setAllValuation(1);
  4432. // },
  4433. // },
  4434. }
  4435. });
  4436. }
  4437. if (shenpiPower) {
  4438. changeSpreadObj.editEnded = function (e, info) {
  4439. if (!info.sheet.zh_setting) {
  4440. changeSpreadObj.reloadRow(info.sheet, info.row);
  4441. return;
  4442. }
  4443. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  4444. if (!select || !select.id) {
  4445. toastr.error('该变更清单无法编辑');
  4446. changeSpreadObj.reloadRow(info.sheet, info.row);
  4447. return;
  4448. }
  4449. const cInfo = _.find(changeList, { id: select.id });
  4450. if (!cInfo) {
  4451. toastr.error('数据错误,请刷新页面重试');
  4452. changeSpreadObj.reloadRow(info.sheet, info.row);
  4453. return;
  4454. }
  4455. const col = info.sheet.zh_setting.cols[info.col];
  4456. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  4457. const orgValue = select[col.field];
  4458. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4459. changeSpreadObj.reloadRow(info.sheet, info.row);
  4460. return;
  4461. }
  4462. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4463. if (!node) {
  4464. toastr.error('数据错误,请选择清单节点后再试');
  4465. changeSpreadObj.reloadRow(info.sheet, info.row);
  4466. return;
  4467. }
  4468. if (col.type === 'Number') {
  4469. if (isNaN(validText)) {
  4470. toastr.error('不能输入其它非数字类型字符');
  4471. changeSpreadObj.reloadRow(info.sheet, info.row);
  4472. return;
  4473. }
  4474. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4475. if (col.field !== 'oamount2') {
  4476. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4477. const usedInfo = _.find(changeUsedData, {cbid: select.id});
  4478. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  4479. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4480. changeSpreadObj.reloadRow(info.sheet, info.row);
  4481. return;
  4482. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  4483. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4484. changeSpreadObj.reloadRow(info.sheet, info.row);
  4485. return;
  4486. }
  4487. }
  4488. }
  4489. cInfo[col.field] = validText;
  4490. select[col.field] = validText;
  4491. if (col.field !== 'oamount2') {
  4492. cInfo.spamount = validText;
  4493. select.spamount = validText;
  4494. }
  4495. const data = {
  4496. id: select.id,
  4497. };
  4498. if (col.field === 'oamount2') {
  4499. data[col.field] = select[col.field];
  4500. } else {
  4501. data.spamount = select.spamount;
  4502. }
  4503. console.log(data, col.field);
  4504. // 更新至服务器
  4505. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  4506. changeSpreadObj.calcOneSum(select);
  4507. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4508. changeSpreadObj.refreshXmjData();
  4509. changeSpreadObj.countSum();
  4510. if (info.row === info.sheet.zh_data.length - 1) {
  4511. // console.log(info);
  4512. // changeSpreadSheet.setSelection(info.row, info.col, 1, 1);
  4513. // changeSpreadObj.reloadRow(changeSpreadSheet, info.row, 0, true);
  4514. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  4515. changeSpreadObj.reloadSheet(newChangeList);
  4516. }
  4517. }, function () {
  4518. select[col.field] = orgValue;
  4519. cInfo[col.field] = orgValue;
  4520. if (col.field !== 'oamount2') {
  4521. select.spamount = orgValue;
  4522. cInfo.spamount = orgValue;
  4523. }
  4524. changeSpreadObj.reloadRow(info.sheet, info.row);
  4525. });
  4526. };
  4527. changeSpreadObj.clipboardPasted = function (e, info) {
  4528. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4529. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4530. }
  4531. const hint = {
  4532. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4533. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4534. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4535. };
  4536. const range = info.cellRange;
  4537. const sortData = info.sheet.zh_data || [];
  4538. const data = [];
  4539. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4540. let bPaste = true;
  4541. const curRow = range.row + iRow;
  4542. if (!sortData[curRow] || !sortData[curRow].id) {
  4543. bPaste = false;
  4544. }
  4545. const cLData = { id: sortData[curRow].id };
  4546. const hintRow = range.rowCount >= 1 ? curRow : '';
  4547. let sameCol = 0;
  4548. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4549. const curCol = range.col + iCol;
  4550. let colSetting = info.sheet.zh_setting.cols[curCol];
  4551. if (!colSetting) continue;
  4552. let validText = info.sheet.getText(curRow, curCol);
  4553. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4554. const orgValue = sortData[curRow][colSetting.field];
  4555. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4556. sameCol++;
  4557. if (range.colCount === sameCol) {
  4558. bPaste = false;
  4559. }
  4560. continue;
  4561. }
  4562. if (colSetting.type === 'Number') {
  4563. if (isNaN(validText)) {
  4564. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4565. bPaste = false;
  4566. continue;
  4567. }
  4568. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  4569. if (colSetting.field !== 'oamount2') {
  4570. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4571. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
  4572. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4573. toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4574. bPaste = false;
  4575. continue;
  4576. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4577. toastr.error(hintRow ? '清单' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4578. bPaste = false;
  4579. continue;
  4580. }
  4581. }
  4582. }
  4583. sortData[curRow][colSetting.field] = validText;
  4584. if (colSetting.field === 'oamount2') {
  4585. cLData[colSetting.field] = validText;
  4586. } else {
  4587. cLData.spamount = validText;
  4588. sortData[curRow].spamount = validText;
  4589. }
  4590. }
  4591. if (bPaste) {
  4592. data.push(cLData);
  4593. // rowData.push(curRow);
  4594. } else {
  4595. changeSpreadObj.reloadRow(info.sheet, curRow);
  4596. }
  4597. }
  4598. if (data.length === 0) {
  4599. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4600. return;
  4601. }
  4602. console.log(data);
  4603. // 更新至服务器
  4604. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  4605. changeList = result;
  4606. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  4607. changeSpreadObj.reloadSheet(newChangeList);
  4608. }, function () {
  4609. changeSpreadObj.reloadRow(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4610. return;
  4611. });
  4612. };
  4613. changeSpreadObj.deletePress = function (sheet) {
  4614. if (!sheet.zh_setting) return;
  4615. // 暂时仅支持移除数量
  4616. const sel = sheet.getSelections()[0], datas = [];
  4617. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  4618. let bDel = false;
  4619. const node = sheet.zh_data[iRow];
  4620. const cInfo = _.find(changeList, { id: node.id });
  4621. const data = { id: node.id };
  4622. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  4623. const col = sheet.zh_setting.cols[iCol];
  4624. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  4625. node[col.field] = null;
  4626. cInfo[col.field] = null;
  4627. if (col.field !== 'oamount2') {
  4628. data.spamount = null;
  4629. cInfo.spamount = null;
  4630. node.spamount = null;
  4631. } else {
  4632. data[col.field] = null;
  4633. }
  4634. bDel = true;
  4635. }
  4636. }
  4637. if (bDel) datas.push(data);
  4638. }
  4639. if (datas.length > 0) {
  4640. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  4641. changeList = result;
  4642. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  4643. changeSpreadObj.reloadSheet(newChangeList);
  4644. }, function () {
  4645. changeSpreadObj.reloadRow(sheet, sel.row, sel.rowCount);
  4646. return;
  4647. });
  4648. }
  4649. return;
  4650. };
  4651. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  4652. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  4653. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  4654. xmjSpreadObj.editEnded = function (e, info) {
  4655. if (!info.sheet.zh_setting) {
  4656. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4657. return;
  4658. }
  4659. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  4660. const cInfo = _.find(changeList, { id: select.id });
  4661. if (!cInfo) {
  4662. toastr.error('数据错误,请刷新页面重试');
  4663. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4664. return;
  4665. }
  4666. const col = info.sheet.zh_setting.cols[info.col];
  4667. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  4668. const orgValue = select[col.field];
  4669. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4670. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4671. return;
  4672. }
  4673. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4674. if (!node) {
  4675. toastr.error('数据错误,请选择清单节点后再试');
  4676. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4677. return;
  4678. }
  4679. if (col.type === 'Number') {
  4680. if (isNaN(validText)) {
  4681. toastr.error('不能输入其它非数字类型字符');
  4682. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4683. return;
  4684. }
  4685. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4686. if (col.field !== 'oamount2') {
  4687. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4688. const usedInfo = _.find(changeUsedData, {cbid: select.id});
  4689. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  4690. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4691. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4692. return;
  4693. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  4694. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4695. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4696. return;
  4697. }
  4698. }
  4699. }
  4700. cInfo[col.field] = validText;
  4701. select[col.field] = validText;
  4702. if (col.field !== 'oamount2') {
  4703. cInfo.spamount = validText;
  4704. select.spamount = validText;
  4705. }
  4706. const data = {
  4707. id: select.id,
  4708. };
  4709. if (col.field === 'oamount2') {
  4710. data[col.field] = select[col.field];
  4711. } else {
  4712. data.spamount = select.spamount;
  4713. }
  4714. console.log(data);
  4715. // 更新至服务器
  4716. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  4717. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4718. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  4719. node.children = info.sheet.zh_data;
  4720. changeSpreadObj.calcOneSum(node);
  4721. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  4722. changeSpreadObj.countSum();
  4723. }, function () {
  4724. select[col.field] = orgValue;
  4725. cInfo[col.field] = orgValue;
  4726. if (col.field !== 'oamount2') {
  4727. select.spamount = orgValue;
  4728. cInfo.spamount = orgValue;
  4729. }
  4730. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4731. });
  4732. };
  4733. xmjSpreadObj.clipboardPasted = function (e, info) {
  4734. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4735. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4736. }
  4737. const node = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4738. if (!node) {
  4739. toastr.error('数据错误,请选择清单节点后再试');
  4740. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4741. return;
  4742. }
  4743. const hint = {
  4744. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4745. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4746. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4747. };
  4748. const range = info.cellRange;
  4749. const sortData = info.sheet.zh_data || [];
  4750. const data = [];
  4751. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4752. let bPaste = true;
  4753. const curRow = range.row + iRow;
  4754. const cLData = { id: sortData[curRow].id };
  4755. const hintRow = range.rowCount >= 1 ? curRow : '';
  4756. let sameCol = 0;
  4757. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4758. const curCol = range.col + iCol;
  4759. let colSetting = info.sheet.zh_setting.cols[curCol];
  4760. if (!colSetting) continue;
  4761. let validText = info.sheet.getText(curRow, curCol);
  4762. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4763. const orgValue = sortData[curRow][colSetting.field];
  4764. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4765. sameCol++;
  4766. if (range.colCount === sameCol) {
  4767. bPaste = false;
  4768. }
  4769. continue;
  4770. }
  4771. if (colSetting.type === 'Number') {
  4772. if (isNaN(validText)) {
  4773. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4774. bPaste = false;
  4775. continue;
  4776. }
  4777. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  4778. if (colSetting.field !== 'oamount2') {
  4779. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4780. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].id});
  4781. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  4782. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4783. bPaste = false;
  4784. continue;
  4785. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  4786. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4787. bPaste = false;
  4788. continue;
  4789. }
  4790. }
  4791. }
  4792. sortData[curRow][colSetting.field] = validText;
  4793. if (colSetting.field === 'oamount2') {
  4794. cLData[colSetting.field] = validText;
  4795. } else {
  4796. cLData.spamount = validText;
  4797. sortData[curRow].spamount = validText;
  4798. }
  4799. }
  4800. if (bPaste) {
  4801. data.push(cLData);
  4802. // rowData.push(curRow);
  4803. } else {
  4804. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  4805. }
  4806. }
  4807. if (data.length === 0) {
  4808. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4809. return;
  4810. }
  4811. console.log(data);
  4812. // 更新至服务器
  4813. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  4814. changeList = result;
  4815. const billIndex = _.indexOf(changeSpreadSheet.zh_data, node);
  4816. node.children = info.sheet.zh_data;
  4817. changeSpreadObj.calcOneSum(node);
  4818. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  4819. changeSpreadObj.countSum();
  4820. xmjSpreadObj.loadCurXmjData();
  4821. }, function () {
  4822. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  4823. return;
  4824. });
  4825. };
  4826. xmjSpreadObj.deletePress = function (sheet) {
  4827. if (!sheet.zh_setting) return;
  4828. const changeNode = SpreadJsObj.getSelectObject(changeSpreadSheet);
  4829. if (!changeNode) {
  4830. toastr.error('数据错误,请选择清单节点后再试');
  4831. SpreadJsObj.reLoadRowData(sheet, info.row);
  4832. return;
  4833. }
  4834. // 暂时仅支持移除数量
  4835. const sel = sheet.getSelections()[0], datas = [];
  4836. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  4837. let bDel = false;
  4838. const node = sheet.zh_data[iRow];
  4839. const cInfo = _.find(changeList, { id: node.id });
  4840. const data = { id: node.id };
  4841. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  4842. const col = sheet.zh_setting.cols[iCol];
  4843. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  4844. node[col.field] = null;
  4845. cInfo[col.field] = null;
  4846. if (col.field !== 'oamount2') {
  4847. data.spamount = null;
  4848. cInfo.spamount = null;
  4849. node.spamount = null;
  4850. } else {
  4851. data[col.field] = null;
  4852. }
  4853. bDel = true;
  4854. }
  4855. }
  4856. if (bDel) datas.push(data);
  4857. }
  4858. if (datas.length > 0) {
  4859. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  4860. changeList = result;
  4861. const billIndex = _.indexOf(changeSpreadSheet.zh_data, changeNode);
  4862. changeNode.children = sheet.zh_data;
  4863. changeSpreadObj.calcOneSum(changeNode);
  4864. console.log(changeNode);
  4865. changeSpreadObj.reloadRow(changeSpreadSheet, billIndex);
  4866. changeSpreadObj.countSum();
  4867. xmjSpreadObj.loadCurXmjData();
  4868. }, function () {
  4869. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  4870. return;
  4871. });
  4872. }
  4873. return;
  4874. };
  4875. xmjSpread.bind(spreadNS.Events.EditEnded, xmjSpreadObj.editEnded);
  4876. xmjSpread.bind(spreadNS.Events.ClipboardPasted, xmjSpreadObj.clipboardPasted);
  4877. SpreadJsObj.addDeleteBind(xmjSpread, xmjSpreadObj.deletePress);
  4878. ledgerTreeSpreadObj.editEnded = function (e, info) {
  4879. if (!info.sheet.zh_setting) {
  4880. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4881. return;
  4882. }
  4883. const col = info.sheet.zh_setting.cols[info.col];
  4884. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  4885. const select = sortData[info.row];
  4886. if (!select || !select.clid) {
  4887. toastr.error('数据错误,请刷新页面重试');
  4888. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4889. return;
  4890. }
  4891. const cInfo = _.find(changeList, { id: select.clid });
  4892. if (!cInfo) {
  4893. toastr.error('数据错误,请刷新页面重试');
  4894. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4895. return;
  4896. }
  4897. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  4898. const orgValue = select[col.field];
  4899. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  4900. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4901. return;
  4902. }
  4903. if (col.type === 'Number') {
  4904. if (isNaN(validText)) {
  4905. toastr.error('不能输入其它非数字类型字符');
  4906. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4907. return;
  4908. }
  4909. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4910. if (col.field !== 'oamount2') {
  4911. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  4912. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  4913. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  4914. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  4915. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4916. return;
  4917. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  4918. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  4919. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4920. return;
  4921. }
  4922. }
  4923. }
  4924. cInfo[col.field] = validText;
  4925. select[col.field] = validText;
  4926. if (col.field !== 'oamount2') {
  4927. cInfo.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4928. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  4929. }
  4930. const data = {
  4931. id: cInfo.id,
  4932. };
  4933. if (col.field === 'oamount2') {
  4934. data[col.field] = select[col.field];
  4935. } else {
  4936. data.spamount = select.spamount;
  4937. }
  4938. // 更新至服务器
  4939. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  4940. const loadResult = {
  4941. update: [select],
  4942. };
  4943. const refreshData = ledgerTree.loadPostData(loadResult);
  4944. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  4945. }, function () {
  4946. select[col.field] = orgValue;
  4947. cInfo[col.field] = orgValue;
  4948. if(col.field !== 'oamount2') {
  4949. select.spamount = orgValue;
  4950. cInfo.spamount = orgValue;
  4951. }
  4952. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  4953. });
  4954. };
  4955. ledgerTreeSpreadObj.clipboardPasted = function (e, info) {
  4956. const tree = info.sheet.zh_tree;
  4957. if (!tree) { return; }
  4958. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  4959. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  4960. }
  4961. const hint = {
  4962. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  4963. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  4964. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  4965. };
  4966. const range = info.cellRange;
  4967. const sortData = info.sheet.zh_tree.nodes;
  4968. const selects = [];
  4969. const data = [];
  4970. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  4971. let bPaste = true;
  4972. const curRow = range.row + iRow;
  4973. const node = sortData[curRow];
  4974. if (!node) {
  4975. continue;
  4976. }
  4977. const cLData = { id: sortData[curRow].clid };
  4978. const hintRow = range.rowCount >= 1 ? curRow : '';
  4979. let sameCol = 0;
  4980. for (let iCol = 0; iCol < range.colCount; iCol++) {
  4981. const curCol = range.col + iCol;
  4982. let colSetting = info.sheet.zh_setting.cols[curCol];
  4983. if (!colSetting) continue;
  4984. let validText = info.sheet.getText(curRow, curCol);
  4985. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  4986. const orgValue = sortData[curRow][colSetting.field];
  4987. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  4988. sameCol++;
  4989. if (range.colCount === sameCol) {
  4990. bPaste = false;
  4991. }
  4992. continue;
  4993. }
  4994. if (colSetting.type === 'Number') {
  4995. if (isNaN(validText)) {
  4996. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  4997. bPaste = false;
  4998. continue;
  4999. }
  5000. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  5001. if (colSetting.field !== 'oamount2') {
  5002. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  5003. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
  5004. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  5005. toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  5006. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5007. bPaste = false;
  5008. continue;
  5009. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  5010. toastr.error(hintRow ? '台账' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  5011. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5012. bPaste = false;
  5013. continue;
  5014. }
  5015. }
  5016. }
  5017. sortData[curRow][colSetting.field] = validText;
  5018. if (colSetting.field === 'oamount2') {
  5019. cLData[colSetting.field] = validText;
  5020. } else {
  5021. cLData.spamount = validText;
  5022. sortData[curRow].spamount = cLData.spamount;
  5023. }
  5024. }
  5025. if (bPaste) {
  5026. data.push(cLData);
  5027. selects.push(sortData[curRow]);
  5028. } else {
  5029. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5030. }
  5031. }
  5032. if (data.length === 0) {
  5033. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5034. return;
  5035. }
  5036. console.log(data, selects);
  5037. // 更新至服务器
  5038. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  5039. changeList = result;
  5040. const loadResult = {
  5041. update: selects,
  5042. };
  5043. const refreshData = ledgerTree.loadPostData(loadResult);
  5044. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5045. ledgerTreeSpreadObj.loadExprToInput();
  5046. }, function () {
  5047. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5048. return;
  5049. });
  5050. };
  5051. ledgerTreeSpreadObj.deletePress = function (sheet) {
  5052. if (!sheet.zh_setting) return;
  5053. // 暂时仅支持移除数量
  5054. const sel = sheet.getSelections()[0], datas = [];
  5055. const selects = [];
  5056. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  5057. let bDel = false;
  5058. const node = sheet.zh_tree.nodes[iRow];
  5059. const cInfo = _.find(changeList, { id: node.clid });
  5060. const data = { id: node.clid };
  5061. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  5062. const col = sheet.zh_setting.cols[iCol];
  5063. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  5064. node[col.field] = null;
  5065. cInfo[col.field] = null;
  5066. if (col.field !== 'oamount2') {
  5067. data.spamount = null;
  5068. cInfo.spamount = null;
  5069. node.spamount = null;
  5070. } else {
  5071. data[col.field] = null;
  5072. }
  5073. bDel = true;
  5074. }
  5075. }
  5076. if (bDel) {
  5077. datas.push(data);
  5078. selects.push(node);
  5079. }
  5080. }
  5081. if (datas.length > 0) {
  5082. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  5083. changeList = result;
  5084. const loadResult = {
  5085. update: selects,
  5086. };
  5087. const refreshData = ledgerTree.loadPostData(loadResult);
  5088. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5089. ledgerTreeSpreadObj.loadExprToInput();
  5090. }, function () {
  5091. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  5092. return;
  5093. });
  5094. }
  5095. return;
  5096. };
  5097. ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerTreeSpreadObj.editEnded);
  5098. ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerTreeSpreadObj.clipboardPasted);
  5099. SpreadJsObj.addDeleteBind(ledgerSpread, ledgerTreeSpreadObj.deletePress);
  5100. posSpreadObj.editEnded = function (e, info) {
  5101. if (!info.sheet.zh_setting) {
  5102. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5103. return;
  5104. }
  5105. const select = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  5106. const cInfo = _.find(changeList, { id: select.clid });
  5107. if (!cInfo) {
  5108. toastr.error('数据错误,请刷新页面重试');
  5109. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5110. return;
  5111. }
  5112. const col = info.sheet.zh_setting.cols[info.col];
  5113. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  5114. const orgValue = select[col.field];
  5115. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  5116. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5117. return;
  5118. }
  5119. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  5120. if (!node) {
  5121. toastr.error('数据错误,请选择台账节点后再试');
  5122. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5123. return;
  5124. }
  5125. if (col.type === 'Number') {
  5126. if (isNaN(validText)) {
  5127. toastr.error('不能输入其它非数字类型字符');
  5128. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5129. return;
  5130. }
  5131. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  5132. if (col.field !== 'oamount2') {
  5133. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  5134. const usedInfo = _.find(changeUsedData, {cbid: select.clid});
  5135. if (usedInfo && validText >= 0 && validText < usedInfo.qty) {
  5136. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  5137. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5138. return;
  5139. } else if (usedInfo && validText < 0 && validText > usedInfo.qty) {
  5140. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  5141. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5142. return;
  5143. }
  5144. }
  5145. }
  5146. cInfo[col.field] = validText;
  5147. select[col.field] = validText;
  5148. if (col.field !== 'oamount2') {
  5149. cInfo.spamount = validText;
  5150. select.spamount = validText;
  5151. }
  5152. const data = {
  5153. id: select.clid,
  5154. };
  5155. if (col.field === 'oamount2') {
  5156. data[col.field] = select[col.field];
  5157. } else {
  5158. data.spamount = select.spamount;
  5159. }
  5160. // 更新至服务器
  5161. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  5162. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5163. const loadResult = {
  5164. update: [node],
  5165. };
  5166. const refreshData = ledgerTree.loadPostData(loadResult);
  5167. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5168. }, function () {
  5169. select[col.field] = orgValue;
  5170. cInfo[col.field] = orgValue;
  5171. if (col.field !== 'oamount2') {
  5172. select.spamount = orgValue;
  5173. cInfo.spamount = orgValue;
  5174. }
  5175. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  5176. });
  5177. };
  5178. posSpreadObj.clipboardPasted = function (e, info) {
  5179. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  5180. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  5181. }
  5182. const hint = {
  5183. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  5184. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  5185. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  5186. };
  5187. const range = info.cellRange;
  5188. const sortData = info.sheet.zh_data || [];
  5189. const data = [];
  5190. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  5191. let bPaste = true;
  5192. const curRow = range.row + iRow;
  5193. const cLData = { id: sortData[curRow].clid };
  5194. const hintRow = range.rowCount >= 1 ? curRow : '';
  5195. let sameCol = 0;
  5196. for (let iCol = 0; iCol < range.colCount; iCol++) {
  5197. const curCol = range.col + iCol;
  5198. let colSetting = info.sheet.zh_setting.cols[curCol];
  5199. if (!colSetting) continue;
  5200. let validText = info.sheet.getText(curRow, curCol);
  5201. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  5202. const orgValue = sortData[curRow][colSetting.field];
  5203. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  5204. sameCol++;
  5205. if (range.colCount === sameCol) {
  5206. bPaste = false;
  5207. }
  5208. continue;
  5209. }
  5210. if (colSetting.type === 'Number') {
  5211. if (isNaN(validText)) {
  5212. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  5213. bPaste = false;
  5214. continue;
  5215. }
  5216. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  5217. if (colSetting.field !== 'oamount2') {
  5218. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  5219. const usedInfo = _.find(changeUsedData, {id: sortData[curRow].clid});
  5220. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  5221. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  5222. bPaste = false;
  5223. continue;
  5224. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  5225. toastr.error(hintRow ? '计量单元' + (hintRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  5226. bPaste = false;
  5227. continue;
  5228. }
  5229. }
  5230. }
  5231. sortData[curRow][colSetting.field] = validText;
  5232. if (colSetting.field === 'oamount2') {
  5233. cLData[colSetting.field] = validText;
  5234. } else {
  5235. cLData.spamount = validText;
  5236. sortData[curRow].spamount = validText;
  5237. }
  5238. }
  5239. if (bPaste) {
  5240. data.push(cLData);
  5241. // rowData.push(curRow);
  5242. } else {
  5243. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  5244. }
  5245. }
  5246. if (data.length === 0) {
  5247. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5248. return;
  5249. }
  5250. console.log(data);
  5251. // 更新至服务器
  5252. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  5253. changeList = result;
  5254. const node = SpreadJsObj.getSelectObject(ledgerSheet);
  5255. const loadResult = {
  5256. update: [node],
  5257. };
  5258. const refreshData = ledgerTree.loadPostData(loadResult);
  5259. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5260. posSpreadObj.loadCurPosData();
  5261. }, function () {
  5262. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  5263. return;
  5264. });
  5265. };
  5266. posSpreadObj.deletePress = function (sheet) {
  5267. if (!sheet.zh_setting) return;
  5268. // 暂时仅支持移除数量
  5269. const sel = sheet.getSelections()[0], datas = [];
  5270. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  5271. let bDel = false;
  5272. const node = sheet.zh_data[iRow];
  5273. const cInfo = _.find(changeList, { id: node.clid });
  5274. const data = { id: node.clid };
  5275. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  5276. const col = sheet.zh_setting.cols[iCol];
  5277. if (col.field === 'oamount2' || (col.readOnly !== true && _.includes(col.field, 'audit_amount_') && !checkIsSettle(node))) {
  5278. node[col.field] = null;
  5279. cInfo[col.field] = null;
  5280. if (col.field !== 'oamount2') {
  5281. data.spamount = null;
  5282. cInfo.spamount = null;
  5283. node.spamount = null;
  5284. } else {
  5285. data[col.field] = null;
  5286. }
  5287. bDel = true;
  5288. }
  5289. }
  5290. if (bDel) datas.push(data);
  5291. }
  5292. if (datas.length > 0) {
  5293. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: datas }, function (result) {
  5294. changeList = result;
  5295. const billsNode = SpreadJsObj.getSelectObject(ledgerSheet);
  5296. const loadResult = {
  5297. update: [billsNode],
  5298. };
  5299. const refreshData = ledgerTree.loadPostData(loadResult);
  5300. ledgerTreeSpreadObj.refreshTree(ledgerSheet, refreshData);
  5301. posSpreadObj.loadCurPosData();
  5302. }, function () {
  5303. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  5304. return;
  5305. });
  5306. }
  5307. return;
  5308. };
  5309. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  5310. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  5311. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  5312. }
  5313. // 切换清单模式
  5314. $('.change-mode').on('click', async function () {
  5315. if ($(this).hasClass('active')) {
  5316. return;
  5317. }
  5318. $('.change-mode').removeClass('active');
  5319. $(this).addClass('active');
  5320. const type = parseInt($(this).data('type'));
  5321. postData(window.location.pathname + '/save', { type:'change_mode', updateData: type }, function (result) {
  5322. changeList = result;
  5323. changeMode = type;
  5324. showMode(type);
  5325. });
  5326. });
  5327. function showMode(type) {
  5328. if (type === 0) {
  5329. $('.judge-hide').show();
  5330. $('.judge-show').attr("style","display:none !important");
  5331. if (changeOrder === 0) {
  5332. $('#upAndMoveBtn').attr("style","display:none !important");
  5333. }
  5334. const [newChangeList, updateOrderList] = changeSpreadObj.makeNewChangeList();
  5335. if (updateOrderList.length > 0) {
  5336. postData(window.location.pathname + '/save', { type:'changeOrder', postData: updateOrderList }, function (result) {
  5337. });
  5338. }
  5339. changeSpreadObj.reloadSheet(newChangeList);
  5340. changeSpread.refresh();
  5341. xmjSpread.refresh();
  5342. } else {
  5343. $('.judge-hide').attr("style","display:none !important");
  5344. $('.judge-show').show();
  5345. const {changeLedgers, changePoss} = makeLedgerAndPosData();
  5346. ledgerTree.loadDatas(changeLedgers);
  5347. pos.loadDatas(changePoss);
  5348. treeCalc.calculateAll(ledgerTree);
  5349. console.log(ledgerTree);
  5350. SpreadJsObj.loadSheetData(ledgerSheet, SpreadJsObj.DataType.Tree, ledgerTree);
  5351. ledgerTree.expandByCustom(() => { return true; });
  5352. SpreadJsObj.refreshTreeRowVisible(ledgerSheet);
  5353. SpreadJsObj.loadTopAndSelect(ledgerSheet, ckBillsSpread);
  5354. ledgerTreeSpreadObj.showHideAudit($('#show-table-detail').is(':checked'));
  5355. posSpreadObj.loadCurPosData();
  5356. SpreadJsObj.resetTopAndSelect(posSheet);
  5357. ledgerTreeSpreadObj.loadExprToInput();
  5358. ledgerSpread.refresh();
  5359. posSpread.refresh();
  5360. }
  5361. }
  5362. // 显示层次
  5363. (function (select, sheet) {
  5364. $(select).click(function () {
  5365. if (!sheet.zh_tree) return;
  5366. const tag = $(this).attr('tag');
  5367. const tree = sheet.zh_tree;
  5368. setTimeout(() => {
  5369. showWaitingView();
  5370. switch (tag) {
  5371. case "1":
  5372. case "2":
  5373. case "3":
  5374. case "4":
  5375. case "5":
  5376. tree.expandByLevel(parseInt(tag));
  5377. SpreadJsObj.refreshTreeRowVisible(sheet);
  5378. break;
  5379. case "last":
  5380. tree.expandByCustom(() => { return true; });
  5381. SpreadJsObj.refreshTreeRowVisible(sheet);
  5382. break;
  5383. case "leafXmj":
  5384. tree.expandToLeafXmj();
  5385. SpreadJsObj.refreshTreeRowVisible(sheet);
  5386. break;
  5387. }
  5388. closeWaitingView();
  5389. }, 100);
  5390. });
  5391. })('a[name=showLevel]', ledgerSheet);
  5392. function makeLedgerAndPosData() {
  5393. const changeLedgers = _.filter(ledgerList, function (item) {
  5394. return _.findIndex(changeList, { gcl_id: item.id}) !== -1;
  5395. });
  5396. // 找出所有父节点
  5397. if (changeLedgers.length > 0) {
  5398. const parentLedgers = [];
  5399. for (const node of changeLedgers) {
  5400. const cl = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  5401. if (cl) {
  5402. const cloneCl = _.cloneDeep(cl);
  5403. delete cloneCl.id;
  5404. delete cloneCl.name;
  5405. delete cloneCl.code;
  5406. node.clid = cl.id;
  5407. // cloneCl 合并到node中
  5408. Object.assign(node, cloneCl);
  5409. }
  5410. if (node.full_path && node.full_path !== '') {
  5411. const parentIds = node.full_path.split('-');
  5412. parentIds.length = parentIds.length - 1;
  5413. for (const id of parentIds) {
  5414. const lid = parseInt(id);
  5415. if (lid !== node.ledger_id && _.findIndex(parentLedgers, { ledger_id: lid }) === -1) {
  5416. parentLedgers.push(_.find(ledgerList, { ledger_id: lid }));
  5417. }
  5418. }
  5419. }
  5420. }
  5421. changeLedgers.push(...parentLedgers);
  5422. }
  5423. // 找出空白清单和签约清单
  5424. const otherChangeList = _.filter(changeList, function (item) {
  5425. return item.gcl_id === '' || item.gcl_id === null || item.gcl_id == 0;
  5426. });
  5427. if (otherChangeList.length > 0) {
  5428. // 判断changeLedgers中是否已经存在第一部分
  5429. let firstChangeLedger = _.find(changeLedgers, { order: 1, level: 1 });
  5430. let firstOrder = 1;
  5431. if (firstChangeLedger) {
  5432. const firstChilds = _.filter(changeLedgers, { ledger_pid: firstChangeLedger.ledger_id });
  5433. firstOrder = _.maxBy(firstChilds, 'order').order + 1;
  5434. }
  5435. let maxLedgerId = changeLedgers.length > 0 ? _.maxBy(changeLedgers, 'ledger_id').ledger_id + 1 : 2;
  5436. if (!firstChangeLedger) {
  5437. const firstLedger = _.find(ledgerList, { order: 1, level: 1 });
  5438. if (firstLedger) {
  5439. changeLedgers.push(firstLedger);
  5440. firstChangeLedger = firstLedger;
  5441. } else {
  5442. 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 };
  5443. changeLedgers.push(firstChangeLedger);
  5444. }
  5445. }
  5446. for (const cl of otherChangeList) {
  5447. const cloneCl = _.cloneDeep(cl);
  5448. cloneCl.b_code = cloneCl.code;
  5449. cloneCl.code = null;
  5450. cloneCl.clid = cl.id;
  5451. cloneCl.level = 2;
  5452. cloneCl.order = firstOrder;
  5453. cloneCl.is_leaf = 1;
  5454. cloneCl.ledger_pid = firstChangeLedger.ledger_id;
  5455. cloneCl.ledger_id = maxLedgerId;
  5456. cloneCl.full_path = firstChangeLedger.full_path + '-' + maxLedgerId;
  5457. console.log(cloneCl);
  5458. changeLedgers.push(cloneCl);
  5459. maxLedgerId++;
  5460. firstOrder++;
  5461. }
  5462. }
  5463. const changePoss = _.filter(posList, function (item) {
  5464. return _.findIndex(changeList, { mx_id: item.id }) !== -1;
  5465. });
  5466. for (const cp of changePoss) {
  5467. const cl = _.find(changeList, { mx_id: cp.id });
  5468. if (cl) {
  5469. const cloneCl = _.cloneDeep(cl);
  5470. delete cloneCl.id;
  5471. delete cloneCl.lid;
  5472. delete cloneCl.name;
  5473. cp.clid = cl.id;
  5474. // cloneCl 合并到cp中
  5475. Object.assign(cp, cloneCl);
  5476. }
  5477. }
  5478. return { changeLedgers, changePoss };
  5479. }
  5480. // 审批流程展示与隐藏
  5481. $('#show-table-detail').on('click', function (e) {
  5482. if($(e.target).is('label')){
  5483. return;
  5484. }
  5485. ledgerTreeSpreadObj.showHideAudit($(this).is(':checked'));
  5486. posSpreadObj.showHideAudit($(this).is(':checked'));
  5487. changeSpreadObj.showHideAudit($(this).is(':checked'));
  5488. xmjSpreadObj.showHideAudit($(this).is(':checked'));
  5489. });
  5490. const cca = getLocalCache('change-checkbox-account-' + accountId);
  5491. if (cca !== null && cca !== undefined) {
  5492. $('#customCheck1').prop('checked', cca !== 'false');
  5493. }
  5494. changeSpreadSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5495. xmjSheet.setColumnVisible(7,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5496. ledgerSheet.setColumnVisible(6,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5497. posSheet.setColumnVisible(2,$('#customCheck1').is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5498. // 变更详情展示和隐藏
  5499. $('.change-detail-checkbox').on('click', function (e) {
  5500. if($(e.target).is('label')){
  5501. return;
  5502. }
  5503. // // 设置用户项目本地记录展示和隐藏情况
  5504. setLocalCache('change-checkbox-account-'+ accountId, $(this).is(':checked'));
  5505. changeSpreadSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5506. xmjSheet.setColumnVisible(7,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5507. ledgerSheet.setColumnVisible(6,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5508. posSheet.setColumnVisible(2,$(this).is(':checked'), GC.Spread.Sheets.SheetArea.viewport);
  5509. });
  5510. $.subMenu({
  5511. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  5512. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  5513. key: 'menu.1.0.0',
  5514. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  5515. callback: function (info) {
  5516. if (info.mini) {
  5517. $('.panel-title').addClass('fluid');
  5518. $('#sub-menu').removeClass('panel-sidebar');
  5519. } else {
  5520. $('.panel-title').removeClass('fluid');
  5521. $('#sub-menu').addClass('panel-sidebar');
  5522. }
  5523. autoFlashHeight();
  5524. changeSpread.refresh();
  5525. xmjSpread.refresh();
  5526. ledgerSpread.refresh();
  5527. posSpread.refresh();
  5528. }
  5529. });
  5530. $.divResizer({
  5531. select: '#right-spr',
  5532. callback: function () {
  5533. changeSpread.refresh();
  5534. xmjSpread.refresh();
  5535. ledgerSpread.refresh();
  5536. posSpread.refresh();
  5537. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  5538. setLocalCache('change_information_width', width);
  5539. $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  5540. }
  5541. });
  5542. $('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
  5543. changeSpread.refresh();
  5544. xmjSpread.refresh();
  5545. ledgerSpread.refresh();
  5546. posSpread.refresh();
  5547. // 根据浏览器记录展开收起
  5548. if (getLocalCache('change_information_width')) {
  5549. $('#left-view').css('width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  5550. $('#right-view').css('width', getLocalCache('change_information_width') + '%');
  5551. $('#left-header').css('min-width', (100 - parseFloat(getLocalCache('change_information_width'))) + '%');
  5552. changeSpread.refresh();
  5553. xmjSpread.refresh();
  5554. ledgerSpread.refresh();
  5555. posSpread.refresh();
  5556. } else {
  5557. $('#left-header').css('min-width', '33.33%');
  5558. }
  5559. $.divResizer({
  5560. select: '#change-pos-resize',
  5561. callback: function () {
  5562. $('.sjs-height-change').height($('.sjs-height-1').height() - $('#list-tab').outerHeight() - 10);
  5563. changeSpread.refresh();
  5564. ledgerSpread.refresh();
  5565. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  5566. $(".sp-wrap").height(bcontent-30);
  5567. posSpread.refresh();
  5568. xmjSpread.refresh();
  5569. }
  5570. });
  5571. if (!readOnly) {
  5572. // 自动编号
  5573. $('.reduction-code').click(function () {
  5574. const code = $(this).attr('data-code');
  5575. $('input[name="code"]').val(code);
  5576. changeInfo.code = $('input[name="code"]').val();
  5577. judgeChange();
  5578. });
  5579. // 记录变更信息操作
  5580. $('body').on('valuechange', '#change_form input[type="text"]', function (e, previous) {
  5581. changeInfo[$(this).attr('name')] = $(this).val();
  5582. judgeChange();
  5583. });
  5584. $('body').on('valuechange', '#change_form textarea', function (e, previous) {
  5585. changeInfo[$(this).attr('name')] = $(this).val().replace(/[\r\n]/g, '<br><br>');
  5586. judgeChange();
  5587. });
  5588. $('body').on('change', '#change_form select', function (e, previous) {
  5589. changeInfo[$(this).attr('name')] = $(this).val();
  5590. judgeChange();
  5591. });
  5592. $('body').on('click', '#change_form input[type="radio"]', function (e, previous) {
  5593. changeInfo[$(this).attr('name')] = $(this).val();
  5594. judgeChange();
  5595. });
  5596. $('body').on('click', '#change_form input[type="checkbox"]', function (e, previous) {
  5597. const typecheck = [];
  5598. $.each($('#change_form input[name="type[]"]:checked'), function () {
  5599. typecheck.push($(this).val());
  5600. });
  5601. changeInfo.type = typecheck.join(',');
  5602. judgeChange();
  5603. });
  5604. // 保存修改ajax提交(不刷新页面)
  5605. $('.save_change_btn').on('click', function () {
  5606. // 保存修改modal
  5607. if ($('input[name="code"]').val() === '') {
  5608. toastr.error('申请编号不能为空!');
  5609. return;
  5610. }
  5611. if ($('input[name="name"]').val() === '') {
  5612. toastr.error('变更工程名称不能为空!');
  5613. return;
  5614. }
  5615. // 换行更改并提交
  5616. changeInfo.content = changeInfo.content.replace(/<br><br>/g, '\r\n');
  5617. changeInfo.basis = changeInfo.basis.replace(/<br><br>/g, '\r\n');
  5618. changeInfo.expr = changeInfo.expr.replace(/<br><br>/g, '\r\n');
  5619. changeInfo.memo = changeInfo.memo.replace(/<br><br>/g, '\r\n');
  5620. changeInfo.company = $('#change_form select[name="company"]').val();
  5621. // 后改为br
  5622. // 更新至服务器
  5623. postData(window.location.pathname + '/save', { type:'info', updateData: changeInfo }, function (result) {
  5624. $('.reduction-code').attr('data-code', $('input[name="code"]').val());
  5625. toastr.success(result ? result.msg : '');
  5626. $('#show-save-btn').hide();
  5627. $('#sp-btn').show();
  5628. $('.title-main').removeClass('bg-warning');
  5629. changeInfo.content = changeInfo.content.replace(/[\r\n]/g, '<br>');
  5630. changeInfo.basis = changeInfo.basis.replace(/[\r\n]/g, '<br>');
  5631. changeInfo.expr = changeInfo.expr.replace(/[\r\n]/g, '<br>');
  5632. changeInfo.memo = changeInfo.memo.replace(/[\r\n]/g, '<br>');
  5633. back_changeInfo = Object.assign({}, changeInfo);
  5634. if (result.changeList) {
  5635. deLimit = result.deLimit;
  5636. changeList = result.changeList;
  5637. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  5638. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  5639. const [newChangeList] = changeSpreadObj.makeNewChangeList();
  5640. changeSpreadObj.reloadSheet(newChangeList);
  5641. }
  5642. });
  5643. return false;
  5644. });
  5645. $('#cancel_change').on('click', function () {
  5646. $('#show-save-btn').hide();
  5647. $('#sp-btn').show();
  5648. $('.title-main').removeClass('bg-warning');
  5649. if (!isObjEqual(changeInfo, back_changeInfo)) {
  5650. changeFormRemake();
  5651. }
  5652. toastr.success('已还原到上次保存状态');
  5653. });
  5654. // 判断是否有更改过
  5655. function judgeChange() {
  5656. let change = false;
  5657. console.log(changeInfo, back_changeInfo);
  5658. if (!isObjEqual(changeInfo, back_changeInfo)) {
  5659. change = true;
  5660. }
  5661. if (change) {
  5662. $('#show-save-btn').show();
  5663. $('#sp-btn').hide();
  5664. $('.title-main').addClass('bg-warning');
  5665. } else {
  5666. $('#show-save-btn').hide();
  5667. $('#sp-btn').show();
  5668. $('.title-main').removeClass('bg-warning');
  5669. }
  5670. }
  5671. function changeFormRemake() {
  5672. changeInfo = Object.assign({}, back_changeInfo);
  5673. $('#change_form input[name="code"]').val(changeInfo.code);
  5674. $('#change_form input[name="name"]').val(changeInfo.name);
  5675. $('#change_form input[name="peg"]').val(changeInfo.peg);
  5676. $('#change_form input[name="org_name"]').val(changeInfo.org_name);
  5677. $('#change_form input[name="org_code"]').val(changeInfo.org_code);
  5678. $('#change_form input[name="new_name"]').val(changeInfo.new_name);
  5679. $('#change_form input[name="new_code"]').val(changeInfo.new_code);
  5680. $('#change_form textarea[name="content"]').val(changeInfo.content.replace(/<br><br>/g, '\r\n'));
  5681. $('#change_form textarea[name="basis"]').val(changeInfo.basis.replace(/<br><br>/g, '\r\n'));
  5682. $('#change_form textarea[name="expr"]').val(changeInfo.expr.replace(/<br><br>/g, '\r\n'));
  5683. $('#change_form textarea[name="memo"]').val(changeInfo.memo.replace(/<br><br>/g, '\r\n'));
  5684. $('#change_form select[name="type"]').val(changeInfo.type);
  5685. $('#change_form select[name="class"]').val(changeInfo.class);
  5686. $('#change_form select[name="quality"]').val(changeInfo.quality);
  5687. $('#change_form select[name="company"]').val(changeInfo.company);
  5688. $('#change_form input[name="charge"][value="'+ changeInfo.charge +'"]').prop('checked', true);
  5689. $('#change_form input[name="state"][value="'+ changeInfo.state +'"]').prop('checked', true);
  5690. $('#change_form input[name="type[]"]').prop('checked', false);
  5691. const typecheck = changeInfo.type.split(',');
  5692. for (const type of typecheck) {
  5693. $('#change_form input[name="type[]"][value="'+ type +'"]').prop('checked', true);
  5694. }
  5695. }
  5696. $('.checkChangeFrom').on('click', function () {
  5697. let returnFlag = false;
  5698. // 表单判断
  5699. if ($('input[name="code"]').val() === '') {
  5700. toastr.error('申请编号不能为空!');
  5701. returnFlag = true;
  5702. }
  5703. if ($('input[name="name"]').val() === '') {
  5704. toastr.error('变更工程名称不能为空!');
  5705. returnFlag = true;
  5706. }
  5707. if ($('textarea[name="content"]').val() === '') {
  5708. toastr.error('工程变更理由及内容不能为空!');
  5709. returnFlag = true;
  5710. }
  5711. if (changeList.length === 0) {
  5712. toastr.error('请添加变更清单!');
  5713. returnFlag = true;
  5714. } else {
  5715. for (const [i,cl] of changeSpreadSheet.zh_data.entries()) {
  5716. if (cl.name === '') {
  5717. toastr.error('清单第' + (i+1) + '行未完整填写数据(名称不可为空)');
  5718. returnFlag = true;
  5719. }
  5720. }
  5721. }
  5722. if(!checkAuditorFrom ()) {
  5723. returnFlag = true;
  5724. }
  5725. // 判断非空白变更清单是否有重复值(gcl_id及mx_id),如果存在完全相同则需要提示并删除,上报失败,这功能主要是因为清单数据过多服务器处理不过来偶然出现
  5726. const doubleList = findDuplicates(_.filter(changeList, item => item.lid != 0));
  5727. console.log(doubleList);
  5728. if (doubleList.length > 0) {
  5729. for (const double of doubleList) {
  5730. const msgIndex = [];
  5731. for (const one of double) {
  5732. const index = _.findIndex(changeSpreadSheet.zh_data[double[0].order - 1].children, { id: one.id });
  5733. if (index !== -1) msgIndex.push(index+1);
  5734. }
  5735. if (msgIndex.length > 0) {
  5736. toastr.error('第 ' + double[0].order + ' 行' + double[0].code + '清单项目节第 ' + msgIndex.splice(',') + '行重复,请只保留一条数据');
  5737. }
  5738. }
  5739. returnFlag = true;
  5740. }
  5741. if (returnFlag) {
  5742. return false;
  5743. }
  5744. postData(window.location.pathname + '/audit/start', {}, function (result) {
  5745. window.location.reload();
  5746. })
  5747. });
  5748. // 检查上报情况
  5749. function checkAuditorFrom () {
  5750. if ($('#auditList li').length === 0) {
  5751. if(shenpi_status === shenpiConst.sp_status.gdspl) {
  5752. toastr.error('请联系管理员添加审批人');
  5753. } else {
  5754. toastr.error('请先选择审批人,再上报数据');
  5755. }
  5756. return false;
  5757. }
  5758. return true;
  5759. }
  5760. // 找出数组中相同的清单
  5761. function findDuplicates(arr, keys = ['lid', 'gcl_id', 'mx_id']) {
  5762. const groupedData = _.groupBy(arr, item => JSON.stringify(_.pick(item, keys)));
  5763. const duplicates = _.filter(groupedData, group => group.length > 1);
  5764. return _.values(duplicates);
  5765. }
  5766. }
  5767. if (shenpiPower) {
  5768. // 审批提交与判断
  5769. $('.approval-btn').on('click', function () {
  5770. // 判断审批状态
  5771. let returnflag = true;
  5772. const pData = {
  5773. change_id: $('#changeId').val(),
  5774. w_code: $.trim($('#w_code').val()),
  5775. }
  5776. if ($(this).hasClass('btn-success')) {
  5777. const sdesc = $('#success-approval').find('textarea').val();
  5778. if (sdesc === '') {
  5779. toastr.error('审批意见不能为空!');
  5780. returnflag = false;
  5781. }
  5782. if ($('input[name="p_code"]').val() === '') {
  5783. toastr.error('变更令号(批复编号)不能为空!');
  5784. returnflag = false;
  5785. } else if ($('input[name="p_code"]').val() !== undefined) {
  5786. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  5787. const postData2 = {
  5788. p_code: $('input[name="p_code"]').val(),
  5789. };
  5790. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData2, function (result) {
  5791. }, function (data) {
  5792. returnflag = false;
  5793. });
  5794. pData.p_code = $('input[name="p_code"]').val();
  5795. }
  5796. if(returnflag) {
  5797. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  5798. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  5799. if ($('#warning-text').length) $('#warning-text').remove();
  5800. // $('#success-approval').submit();
  5801. pData.status = auditConst.status.checked;
  5802. pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  5803. }
  5804. } else {
  5805. const sdesc = $('#fail-approval').find('textarea').val();
  5806. if (sdesc === '') {
  5807. toastr.error('审批意见不能为空!');
  5808. returnflag = false;
  5809. }
  5810. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  5811. if (type === undefined) {
  5812. // toastr.error('请选择退回类型!');
  5813. if (!$('#warning-text').length) {
  5814. $('#change-back-content').append('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5815. }
  5816. returnflag = false;
  5817. }
  5818. if(returnflag) {
  5819. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  5820. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  5821. // $('#fail-approval').submit();
  5822. pData.status = type;
  5823. pData.sdesc = sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  5824. }
  5825. }
  5826. if (pData.status) {
  5827. console.log(pData);
  5828. postData('/tender/' + $('#tenderId').val() + '/change/approval', pData, function (result) {
  5829. window.location.reload();
  5830. });
  5831. }
  5832. });
  5833. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  5834. if (showWaiting) showWaitingView();
  5835. $.ajax({
  5836. type:"POST",
  5837. url: url,
  5838. data: {'data': JSON.stringify(data)},
  5839. dataType: 'json',
  5840. cache: false,
  5841. async: false,
  5842. timeout: 60000,
  5843. beforeSend: function(xhr) {
  5844. let csrfToken = Cookies.get('csrfToken_j');
  5845. xhr.setRequestHeader('x-csrf-token', csrfToken);
  5846. },
  5847. success: function(result){
  5848. if (result.err === 0) {
  5849. if (successCallback) {
  5850. successCallback(result.data);
  5851. }
  5852. } else {
  5853. toastr.error(result.msg);
  5854. if (errorCallBack) {
  5855. errorCallBack(result.msg);
  5856. }
  5857. }
  5858. if (showWaiting) closeWaitingView();
  5859. },
  5860. error: function(jqXHR, textStatus, errorThrown){
  5861. toastr.error('error: ' + textStatus + " " + errorThrown);
  5862. if (errorCallBack) {
  5863. errorCallBack();
  5864. }
  5865. if (showWaiting) closeWaitingView();
  5866. }
  5867. });
  5868. };
  5869. }
  5870. });
  5871. function calcChangePrice() {
  5872. let positive_tp = 0;
  5873. let negative_tp = 0;
  5874. let valuation_tp = 0;
  5875. let unvaluation_tp = 0;
  5876. let new_tp = 0;
  5877. // 先汇总再统计金额
  5878. const gclChangeList = _.uniq(_.map(changeList, 'gcl_id'));
  5879. for (const g of gclChangeList) {
  5880. if (g) {
  5881. const list = _.filter(changeList, { gcl_id: g });
  5882. let spamount = 0;
  5883. let valuation_amount = 0;
  5884. let unvaluation_amount = 0;
  5885. let unitPrice = 0;
  5886. for (const c of list) {
  5887. if (c.spamount) {
  5888. spamount = ZhCalc.add(spamount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
  5889. unitPrice = c.unit_price;
  5890. if (c.is_valuation) {
  5891. valuation_amount = ZhCalc.add(valuation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
  5892. } else {
  5893. unvaluation_amount = ZhCalc.add(unvaluation_amount, ZhCalc.round(c.spamount, findDecimal(c.unit)));
  5894. }
  5895. }
  5896. }
  5897. const price = ZhCalc.round(ZhCalc.mul(spamount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit);
  5898. const valuation_price = ZhCalc.round(ZhCalc.mul(valuation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
  5899. const unvaluation_price = ZhCalc.round(ZhCalc.mul(unvaluation_amount, ZhCalc.round(unitPrice, unitPriceUnit)), totalPriceUnit) || 0;
  5900. valuation_tp = ZhCalc.add(valuation_tp, valuation_price);
  5901. unvaluation_tp = ZhCalc.add(unvaluation_tp, unvaluation_price);
  5902. new_tp = ZhCalc.add(new_tp, price);
  5903. if (price >= 0) {
  5904. positive_tp = ZhCalc.add(positive_tp, price);
  5905. } else {
  5906. negative_tp = ZhCalc.add(negative_tp, price);
  5907. }
  5908. } else {
  5909. const list = _.filter(changeList, { gcl_id: g });
  5910. for (const c of list) {
  5911. if (c.spamount) {
  5912. const price = ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit) || 0;
  5913. new_tp = ZhCalc.add(new_tp, price);
  5914. if (price >= 0) {
  5915. positive_tp = ZhCalc.add(positive_tp, price);
  5916. } else {
  5917. negative_tp = ZhCalc.add(negative_tp, price);
  5918. }
  5919. if (c.is_valuation) {
  5920. valuation_tp = ZhCalc.add(valuation_tp, price);
  5921. } else {
  5922. unvaluation_tp = ZhCalc.add(unvaluation_tp, price);
  5923. }
  5924. }
  5925. }
  5926. }
  5927. }
  5928. const updateTpList = {};
  5929. let updateFlag = false;
  5930. if (changeTp !== new_tp) {
  5931. updateTpList.total_price = new_tp;
  5932. updateFlag = true;
  5933. }
  5934. if (positive_tp !== changePp) {
  5935. updateTpList.positive_tp = positive_tp;
  5936. updateFlag = true;
  5937. }
  5938. if (negative_tp !== changeNp) {
  5939. updateTpList.negative_tp = negative_tp;
  5940. updateFlag = true;
  5941. }
  5942. if (valuation_tp !== changeVp) {
  5943. updateTpList.valuation_tp = valuation_tp;
  5944. updateFlag = true;
  5945. }
  5946. if (unvaluation_tp !== changeUp) {
  5947. updateTpList.unvaluation_tp = unvaluation_tp;
  5948. updateFlag = true;
  5949. }
  5950. if (updateFlag) {
  5951. console.log(updateTpList);
  5952. postData(window.location.pathname + '/save', { type:'update_tp', updateData: updateTpList }, function () {
  5953. changePp = positive_tp;
  5954. changeNp = negative_tp;
  5955. changeVp = valuation_tp;
  5956. changeUp = unvaluation_tp;
  5957. changeTp = new_tp;
  5958. });
  5959. }
  5960. }
  5961. function checkAndChange(changeListData) {
  5962. // 根据已添加的清单显示
  5963. if (changeList.length > 0 && changeList[0]) {
  5964. const removeList = [];
  5965. const updateList = [];
  5966. const updateGclIdList = [];
  5967. for (const [index,clinfo] of changeList.entries()) {
  5968. if (clinfo.lid != 0) {
  5969. let listinfo = changeListData.find(function (item) {
  5970. return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
  5971. });
  5972. if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
  5973. // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
  5974. const newlistinfo = changeListData.find(function (item) {
  5975. return (item.id !== undefined && item.id == clinfo.gcl_id) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id }));
  5976. });
  5977. if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
  5978. listinfo = newlistinfo;
  5979. updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
  5980. // 更新lid
  5981. changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
  5982. }
  5983. }
  5984. if (listinfo === undefined) {
  5985. // 针对旧数据获取清单信息
  5986. listinfo = changeListData[clinfo.lid - 1];
  5987. if (listinfo === undefined) {
  5988. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  5989. if (changeStatus !== auditConst.status.revise) {
  5990. removeList.push(clinfo);
  5991. } else {
  5992. updateList.push(makeWhiteList(clinfo));
  5993. }
  5994. continue;
  5995. }
  5996. }
  5997. const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
  5998. if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
  5999. // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
  6000. const updateInfo = {};
  6001. if (info.code !== clinfo.xmj_code) {
  6002. updateInfo.xmj_code = info.code;
  6003. changeList[index].xmj_code = info.code;
  6004. }
  6005. if (info.jldy !== clinfo.xmj_jldy) {
  6006. updateInfo.xmj_jldy = info.jldy;
  6007. changeList[index].xmj_jldy = info.jldy;
  6008. }
  6009. if (info.dwgc !== clinfo.xmj_dwgc) {
  6010. updateInfo.xmj_dwgc = info.dwgc;
  6011. changeList[index].xmj_dwgc = info.dwgc;
  6012. }
  6013. if (info.fbgc !== clinfo.xmj_fbgc) {
  6014. updateInfo.xmj_fbgc = info.fbgc;
  6015. changeList[index].xmj_fbgc = info.fbgc;
  6016. }
  6017. if (info.fxgc !== clinfo.xmj_fxgc) {
  6018. updateInfo.xmj_fxgc = info.fxgc;
  6019. changeList[index].xmj_fxgc = info.fxgc;
  6020. }
  6021. if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
  6022. updateGclIdList.push(clinfo.gcl_id);
  6023. // updateInfo.gcl_id = info.id;
  6024. updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
  6025. }
  6026. }
  6027. }
  6028. }
  6029. if(updateList.length > 0) {
  6030. console.log(updateList);
  6031. postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
  6032. }, function () {
  6033. });
  6034. }
  6035. if(removeList.length > 0) {
  6036. _.pullAll(changeList, removeList);
  6037. postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
  6038. }, function () {
  6039. });
  6040. }
  6041. }
  6042. }
  6043. function makePushBwmx(clinfo, listinfo, removeList, updateList) {
  6044. let info = '';
  6045. const checkKey = ['name', 'code', 'unit', 'unit_price'];
  6046. const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
  6047. if (listinfo.leafXmjs !== undefined) {
  6048. const leafInfo = listinfo.leafXmjs.find(function (item) {
  6049. // 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));
  6050. const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
  6051. if (flag && item.code === clinfo.xmj_code) {
  6052. return flag && item.code === clinfo.xmj_code;
  6053. }
  6054. return flag;
  6055. });
  6056. if (leafInfo) {
  6057. const oneUpdate = { id: clinfo.id };
  6058. let needUpdate = false;
  6059. // 判断要不要更新名称,单位,原数量,单价
  6060. checkKey.forEach(function (key) {
  6061. if ((key === 'name' || key === 'unit') && listinfo[key] === null) {
  6062. listinfo[key] = '';
  6063. }
  6064. if (listinfo[key] !== clinfo[key]) {
  6065. oneUpdate[key] = listinfo[key];
  6066. clinfo[key] = listinfo[key];
  6067. if (key === 'unit') {
  6068. const changeKey = ['oamount', 'oamount2', 'camount'];
  6069. changeKey.forEach(function (key) {
  6070. const value = ZhCalc.round(clinfo[key], findDecimal(listinfo[key]));
  6071. if (value !== clinfo[key]) {
  6072. oneUpdate[key] = value;
  6073. clinfo[key] = value;
  6074. }
  6075. });
  6076. }
  6077. // else if (key === 'unit_price') {
  6078. // // 可能要更新总金额了
  6079. // oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  6080. // clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
  6081. // }
  6082. needUpdate = true;
  6083. }
  6084. });
  6085. checkLeafKey.forEach(function (key) {
  6086. // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
  6087. if (key === 'oamount') {
  6088. if (leafInfo.quantity !== clinfo[key]) {
  6089. oneUpdate[key] = leafInfo.quantity;
  6090. clinfo[key] = leafInfo.quantity;
  6091. needUpdate = true;
  6092. }
  6093. } else if (key === 'bwmx') {
  6094. if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
  6095. oneUpdate[key] = leafInfo[key];
  6096. clinfo[key] = leafInfo[key];
  6097. needUpdate = true;
  6098. } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
  6099. oneUpdate[key] = leafInfo.jldy;
  6100. clinfo[key] = leafInfo.jldy;
  6101. needUpdate = true;
  6102. }
  6103. } else {
  6104. if (leafInfo[key] !== clinfo['xmj_' + key]) {
  6105. oneUpdate['xmj_' + key] = leafInfo[key];
  6106. clinfo['xmj_' + key] = leafInfo[key];
  6107. needUpdate = true;
  6108. }
  6109. }
  6110. });
  6111. if (needUpdate) {
  6112. updateList.push(oneUpdate);
  6113. }
  6114. info = leafInfo;
  6115. } else {
  6116. toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
  6117. if (changeStatus !== auditConst.status.revise) {
  6118. removeList.push(clinfo);
  6119. } else {
  6120. updateList.push(makeWhiteList(clinfo));
  6121. }
  6122. return false;
  6123. }
  6124. }
  6125. return info;
  6126. }
  6127. function makeWhiteList(clinfo) {
  6128. clinfo.lid = 0;
  6129. clinfo.xmj_code = null;
  6130. clinfo.xmj_jldy = null;
  6131. clinfo.xmj_dwgc = null;
  6132. clinfo.xmj_fbgc = null;
  6133. clinfo.xmj_fxgc = null;
  6134. clinfo.gcl_id = '';
  6135. clinfo.mx_id = '';
  6136. return clinfo;
  6137. }
  6138. function isObjEqual(o1,o2){
  6139. var props1 = Object.getOwnPropertyNames(o1);
  6140. var props2 = Object.getOwnPropertyNames(o2);
  6141. if (props1.length != props2.length) {
  6142. return false;
  6143. }
  6144. for (var i = 0,max = props1.length; i < max; i++) {
  6145. var propName = props1[i];
  6146. if (o1[propName] !== o2[propName]) {
  6147. return false;
  6148. }
  6149. }
  6150. return true;
  6151. }
  6152. function findDecimal(unit) {
  6153. let value = precision.other.value;
  6154. const changeUnits = precision;
  6155. for (const d in changeUnits) {
  6156. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  6157. value = changeUnits[d].value;
  6158. break;
  6159. }
  6160. }
  6161. return value;
  6162. }
  6163. // 生成附件列表
  6164. function getAllList(currPageNum = 1) {
  6165. // 每页最多几个附件
  6166. const pageCount = 20;
  6167. // 附件总数
  6168. const total = attData.length;
  6169. // 总页数
  6170. const pageNum = Math.ceil(total/pageCount);
  6171. $('#totalPage').text(pageNum);
  6172. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  6173. // 当前页附件内容
  6174. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  6175. currPageFileData = currPageAttData;
  6176. let html = '';
  6177. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  6178. for(const [index,att] of currPageAttData.entries()) {
  6179. html += `<tr>
  6180. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  6181. <td>${((currPageNum-1)*pageCount)+index+1}</td>
  6182. <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>
  6183. <td>${moment(att.in_time * 1000).format('YYYY-MM-DD')}<br>${bytesToSize(att.filesize)}</td>
  6184. <td>
  6185. <a href="/change/download/file/${att.id}" class="mr-2" title="下载"><span class="fa fa-download text-primary"></span></a>`
  6186. html += (att.uid === accountId && ((changeStatus === auditConst.status.checked ? Boolean(att.extra_upload) : true) || deleteFilePermission)) ?
  6187. `<a href="javascript:void(0)" class="mr-2 delete-file" data-attid="${att.id}" title="删除附件"><span class="fa fa-trash text-danger"></span></a>` : '';
  6188. html += `</td>`;
  6189. }
  6190. $('#attList').html(html);
  6191. $('#attList').on('click', 'tr', function() {
  6192. $('#attList tr').removeClass('bg-light');
  6193. $(this).addClass('bg-light');
  6194. })
  6195. }
  6196. function bytesToSize(bytes) {
  6197. if (parseInt(bytes) === 0) return '0 B';
  6198. const k = 1024;
  6199. const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  6200. const i = Math.floor(Math.log(bytes) / Math.log(k));
  6201. // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
  6202. return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
  6203. }
  6204. // 判断是否是已结算清单
  6205. function checkIsSettle(data) {
  6206. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  6207. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  6208. return true;
  6209. }
  6210. return false;
  6211. }