change_revise.js 309 KB

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