change_information.js 336 KB

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