change_revise.js 313 KB

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