change_information.js 322 KB

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