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