ledger.js 306 KB

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