change_information.js 318 KB

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