change_information.js 329 KB

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