change_revise.js 311 KB

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