change_information.js 324 KB

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