change_information.js 323 KB

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