change_information.js 334 KB

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