change_revise.js 278 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price', 'ex_qty1', 'ex_tp1'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'ex_qty1', 'ex_tp1'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. same_bills: { enable: 1 },
  51. };
  52. $(document).ready(() => {
  53. let stdXmj, stdGcl, searchLedger;
  54. autoFlashHeight();
  55. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  56. const billsIndex = _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) : (_.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) + 1 : billsSpreadSetting.cols.length - 1);
  57. console.log(billsSpreadSetting.cols);
  58. billsSpreadSetting.cols.splice(billsIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
  59. billsSpreadSetting.cols.splice(billsIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  60. billsSpreadSetting.cols.splice(billsIndex + 2, 0, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},);
  61. if (!billsSpreadSetting.readOnly) {
  62. for (const col of billsSpreadSetting.cols) {
  63. if (!col.readOnly || col.readOnly === false)
  64. col.readOnly = 'readOnly.isChangeAdd';
  65. }
  66. }
  67. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  68. const posIndex = _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) : posSpreadSetting.cols.length;
  69. posSpreadSetting.cols.splice(posIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
  70. posSpreadSetting.cols.splice(posIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  71. if (!posSpreadSetting.readOnly) {
  72. for (const col of posSpreadSetting.cols) {
  73. if (!col.readOnly || col.readOnly === false)
  74. col.readOnly = 'readOnly.isChangeAdd';
  75. }
  76. }
  77. const billsCol = {
  78. getValue: {
  79. isChange: function (data) {
  80. if (!data) return 0;
  81. if (!data.name) return 0;
  82. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  83. return cInfo ? 1 : 0;
  84. },
  85. isValuation: function (data) {
  86. if (!data) return 0;
  87. if (!data.name) return 0;
  88. const cList = _.filter(changeList, { gcl_id: data.id });
  89. if (cList.length === 0) return 0;
  90. return _.find(cList, { is_valuation: 0 }) ? 0 : 1;
  91. },
  92. camount: function (data) {
  93. const cInfo = _.find(changeList, {gcl_id: data.id, mx_id: ''});
  94. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(data.unit)) : ZhCalc.round(data.camount, findDecimal(data.unit));
  95. }
  96. },
  97. readOnly: {
  98. isChangeAdd: function (data) {
  99. return !readOnly && !data.formc;
  100. },
  101. isChangeList: function (data) {
  102. if (!data) return true;
  103. let edit = !readOnly && !(data.is_leaf && data.b_code);
  104. if (!edit && data.id) {
  105. const lPos = pos.getLedgerPos(data.id);
  106. if (lPos && lPos.length > 0) {
  107. edit = true;
  108. }
  109. }
  110. return edit;
  111. },
  112. isValuation: function (data) {
  113. if (!data) return true;
  114. return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.id, mx_id: '' }) !== -1);
  115. },
  116. isSettle: function (data) {
  117. if (!data) return true;
  118. return !readOnly && !(!billsCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  119. }
  120. }
  121. };
  122. const posCol = {
  123. getValue: {
  124. isChange: function (data) {
  125. if (!data) return 0;
  126. if (!data.name) return 0;
  127. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  128. return cInfo ? 1 : 0;
  129. },
  130. isValuation: function (data) {
  131. if (!data) return 0;
  132. if (!data.name) return 0;
  133. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  134. return cInfo ? cInfo.is_valuation : 0;
  135. },
  136. camount: function (data) {
  137. if (!data) return '';
  138. if (!data.name) return '';
  139. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  140. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)) : '';
  141. }
  142. },
  143. readOnly: {
  144. isChangeAdd: function (data) {
  145. return !readOnly && !data.formc && (!data.settle_status || (data.settle_status && data.settle_status === settleStatus.finish));
  146. },
  147. isChangeList: function (data) {
  148. if (!data) return true;
  149. // console.log(data.name);
  150. return !readOnly && !data.name;
  151. },
  152. isValuation: function (data) {
  153. if (!data) return true;
  154. return !readOnly && !posCol.getValue.isChange(data);
  155. },
  156. isSettle: function (data) {
  157. if (!data) return true;
  158. return !readOnly && !(!posCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  159. }
  160. }
  161. };
  162. console.log(posSpreadSetting);
  163. // 判断是否是已结算清单
  164. function checkIsSettle(data) {
  165. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  166. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  167. return true;
  168. }
  169. return false;
  170. }
  171. // 初始化spread
  172. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  173. const billsSheet = billsSpread.getActiveSheet();
  174. billsSpreadSetting.rowHeader = [
  175. {
  176. rowHeaderType: 'circle',
  177. setting: {
  178. size: 5,
  179. indent: 16,
  180. getColor: function (index, data) {
  181. if (!data) return;
  182. if(!data.formc && !data.cid) return;
  183. return '#dc3545';
  184. }
  185. },
  186. },
  187. ];
  188. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  189. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  190. return spreadColor.stage.settle;
  191. }
  192. if (data && data.is_change) {
  193. return '#c3e6cb';
  194. }
  195. return defaultColor;
  196. };
  197. billsSpreadSetting.localCache = {
  198. key: 'changes-ledger-spread',
  199. colWidth: true,
  200. };
  201. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  202. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  203. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  204. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  205. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  206. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  207. const posSheet = posSpread.getActiveSheet();
  208. posSpreadSetting.rowHeader = [
  209. {
  210. rowHeaderType: 'circle',
  211. setting: {
  212. size: 5,
  213. indent: 16,
  214. getColor: function (index, data) {
  215. if (!data) return;
  216. if(!data.formc) return;
  217. return '#dc3545';
  218. }
  219. },
  220. },
  221. ];
  222. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  223. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  224. return spreadColor.stage.settle;
  225. }
  226. return defaultColor;
  227. };
  228. posSpreadSetting.localCache = {
  229. key: 'changes-pos-spread',
  230. colWidth: true,
  231. };
  232. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  233. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  234. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  235. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  236. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  237. const errorList = $.cs_errorList({
  238. tabSelector: '#error-list-tab',
  239. selector: '#error-list',
  240. relaSpread: billsSpread,
  241. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  242. afterLocated: function () {
  243. posSpreadObj.loadCurPosData();
  244. },
  245. afterShow: function () {
  246. billsSpread.refresh();
  247. if (posSpread) posSpread.refresh();
  248. },
  249. });
  250. const checkList = $.ledger_checkList({
  251. id: 'check-list',
  252. tabSelector: '#check-list-tab',
  253. selector: '#check-list',
  254. relaSpread: billsSpread,
  255. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  256. checkType: getCheckType(checkOption),
  257. afterLocated: function () {
  258. posSpreadObj.loadCurPosData();
  259. },
  260. afterShow: function () {
  261. billsSpread.refresh();
  262. if (posSpread) posSpread.refresh();
  263. },
  264. });
  265. const sumLoadMiss = $.sumLoadMiss({
  266. tabSelector: '#sum-load-miss-tab',
  267. selector: '#sum-load-miss',
  268. relaSpread: billsSpread,
  269. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  270. id: 'revise-slm',
  271. afterLocated: function () {
  272. posSpreadObj.loadCurPosData();
  273. },
  274. afterShow: function () {
  275. billsSpread.refresh();
  276. if (posSpread) posSpread.refresh();
  277. },
  278. });
  279. // 初始化 节点树结构
  280. const treeSetting = {
  281. id: 'ledger_id',
  282. pid: 'ledger_pid',
  283. order: 'order',
  284. level: 'level',
  285. rootId: -1,
  286. keys: ['id', 'tender_id', 'ledger_id'],
  287. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'ca_tp', 'ex_tp1'],
  288. autoExpand: 3,
  289. markExpandKey: 'change-bills-expand',
  290. markExpandSubKey: window.location.pathname.split('/')[2],
  291. };
  292. if (!isTz) {
  293. treeSetting.calcFields.push('deal_tp');
  294. }
  295. treeSetting.calcFun = function (node) {
  296. if (node && node.b_code) {
  297. const posData = pos.getLedgerPos(node.id) || [];
  298. let camount = ZhCalc.round(node.camount, findDecimal(node.unit)) || 0;
  299. if (posData.length > 0) {
  300. let sgfh_qty = 0;
  301. let sjcl_qty = 0;
  302. let qtcl_qty = 0;
  303. let ex_qty1 = 0;
  304. camount = 0;
  305. for (const np of posData) {
  306. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  307. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  308. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  309. ex_qty1 = ZhCalc.add(ex_qty1, np.ex_qty1);
  310. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  311. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(node.unit))) : camount;
  312. }
  313. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  314. node.sgfh_qty = sgfh_qty;
  315. node.sjcl_qty = sjcl_qty;
  316. node.qtcl_qty = qtcl_qty;
  317. node.ex_qty1 = ex_qty1;
  318. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  319. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  320. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  321. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  322. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  323. }
  324. if (!_.isEqual(node.ex_qty1, ex_qty1)) {
  325. node.ex_qty1 = ex_qty1;
  326. node.ex_tp1 = ZhCalc.mul(node.ex_qty1, node.unit_price, decimal.tp) || 0;
  327. }
  328. }
  329. node.camount = camount;
  330. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  331. }
  332. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  333. };
  334. const billsTree = createNewPathTree('revise', treeSetting);
  335. console.log(billsTree, treeSetting);
  336. // 初始化 计量单元
  337. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  338. // 清单 相关方法&绑定spreadjs事件
  339. const billsTreeSpreadObj = {
  340. loadExprToInput(sheet) {
  341. const sel = sheet.getSelections()[0];
  342. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  343. if (col && col.field === 'camount') {
  344. const data = SpreadJsObj.getSelectObject(sheet);
  345. if (data) {
  346. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  347. if (!cInfo) {
  348. if (billsCol.readOnly.isChangeList(data)) {
  349. $('#bills-expr').val('').attr('readOnly', true);
  350. $('#bills-expr').removeAttr('data-row');
  351. } else {
  352. $('#bills-expr').val('').attr('field', col.field).attr('org', '')
  353. .attr('readOnly', false).attr('data-row', sel.row);
  354. }
  355. } else {
  356. const value = cInfo.camount_expr ? cInfo.camount_expr : ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit));
  357. $('#bills-expr').val(value).attr('field', col.field).attr('org', ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)))
  358. .attr('readOnly', billsCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  359. }
  360. } else {
  361. $('#bills-expr').val('').attr('readOnly', true);
  362. $('#bills-expr').removeAttr('data-row');
  363. }
  364. } else if (col && col.type === 'Number') {
  365. const data = SpreadJsObj.getSelectObject(sheet);
  366. if (data) {
  367. const exprInfo = getExprInfo(col.field);
  368. if (exprInfo) {
  369. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  370. .attr('field', col.field).attr('org', data[col.field]);
  371. } else {
  372. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  373. }
  374. if (col.field.indexOf('dgn') >= 0) {
  375. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  376. } else if (col.field === 'unit_price') {
  377. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  378. } else {
  379. const nodePos = pos.getLedgerPos(data.id);
  380. if (nodePos && nodePos.length > 0) {
  381. $('#bills-expr').val('').attr('readOnly', true);
  382. $('#bills-expr').removeAttr('data-row');
  383. } else {
  384. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  385. }
  386. }
  387. $('#bills-expr').attr('data-row', sel.row);
  388. } else {
  389. $('#bills-expr').val('').attr('readOnly', true);
  390. $('#bills-expr').removeAttr('data-row');
  391. }
  392. } else {
  393. $('#bills-expr').val('').attr('readOnly', true);
  394. $('#bills-expr').removeAttr('data-row');
  395. }
  396. },
  397. getDefaultSelectInfo: function (sheet) {
  398. const tree = sheet.zh_tree;
  399. if (!tree) return;
  400. const sel = sheet.getSelections()[0];
  401. const node = sheet.zh_tree.nodes[sel.row];
  402. if (!node) return;
  403. let count = 1;
  404. if (sel.rowCount > 1) {
  405. for (let r = 1; r < sel.rowCount; r++) {
  406. const rNode = sheet.zh_tree.nodes[sel.row + r];
  407. if (rNode.level > node.level) continue;
  408. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  409. toastr.warning('请选择同一节点下的节点,进行该操作');
  410. return;
  411. }
  412. count += 1;
  413. }
  414. }
  415. return [tree, node, count];
  416. },
  417. /**
  418. * 刷新顶部按钮是否可用
  419. * @param sheet
  420. * @param selections
  421. */
  422. refreshOperationValid: function (sheet, selection) {
  423. const setObjEnable = function (obj, enable) {
  424. if (enable) {
  425. obj.removeClass('disabled');
  426. } else {
  427. obj.addClass('disabled');
  428. }
  429. };
  430. const invalidAll = function () {
  431. setObjEnable($('a[name=base-opr][type=add]'), false);
  432. setObjEnable($('a[name=base-opr][type=delete]'), false);
  433. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  434. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  435. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  436. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  437. };
  438. const sel = selection ? selection[0] : sheet.getSelections()[0];
  439. const row = sel ? sel.row : -1;
  440. const tree = sheet.zh_tree;
  441. if (!tree) {
  442. invalidAll();
  443. return;
  444. }
  445. const first = sheet.zh_tree.nodes[row];
  446. if (!first) {
  447. invalidAll();
  448. return;
  449. }
  450. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  451. if (sel.rowCount > 1 && first) {
  452. for (let r = 1; r < sel.rowCount; r++) {
  453. const rNode = tree.nodes[sel.row + r];
  454. if (!rNode) {
  455. sameParent = false;
  456. break;
  457. }
  458. if (!rNode.formc) {
  459. sameParent = false;
  460. break;
  461. }
  462. nodeUsed = nodeUsed || rNode.used;
  463. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  464. if (rNode.level > first.level) continue;
  465. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  466. sameParent = false;
  467. break;
  468. }
  469. last = rNode;
  470. }
  471. }
  472. const preNode = tree.getPreSiblingNode(first);
  473. const siblings = tree.getChildren(tree.getParent(first));
  474. let upPower = true;
  475. for (let order = last.order; order < siblings.length - 1; order ++) {
  476. if (!siblings[order].formc) {
  477. upPower = false;
  478. break;
  479. }
  480. }
  481. const valid = !sheet.zh_setting.readOnly;
  482. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  483. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  484. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  485. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  486. const posRange = last ? pos.getLedgerPos(last.id) : [];
  487. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  488. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  489. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  490. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  491. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  492. setObjEnable($('#cut'), valid);
  493. setObjEnable($('#paste'), valid);
  494. },
  495. /**
  496. *
  497. * @param sheet
  498. * @param data
  499. */
  500. refreshTree: function (sheet, data) {
  501. SpreadJsObj.massOperationSheet(sheet, function () {
  502. const tree = sheet.zh_tree;
  503. // 处理删除
  504. if (data.delete) {
  505. data.delete.sort(function (a, b) {
  506. return b.deleteIndex - a.deleteIndex;
  507. });
  508. for (const d of data.delete) {
  509. sheet.deleteRows(d.deleteIndex, 1);
  510. }
  511. }
  512. // 处理新增
  513. if (data.create) {
  514. const newNodes = data.create;
  515. if (newNodes) {
  516. newNodes.sort(function (a, b) {
  517. return a.index - b.index;
  518. });
  519. for (const node of newNodes) {
  520. sheet.addRows(node.index, 1);
  521. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  522. }
  523. }
  524. }
  525. // 处理更新
  526. if (data.update) {
  527. const rows = [];
  528. for (const u of data.update) {
  529. rows.push(tree.nodes.indexOf(u));
  530. }
  531. SpreadJsObj.reLoadRowsData(sheet, rows);
  532. }
  533. // 处理展开
  534. if (data.expand) {
  535. const expanded = [];
  536. for (const e of data.expand) {
  537. if (expanded.indexOf(e) === -1) {
  538. const posterity = tree.getPosterity(e);
  539. for (const p of posterity) {
  540. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  541. expanded.push(p);
  542. }
  543. }
  544. }
  545. }
  546. });
  547. },
  548. selectionChanged: function (e, info) {
  549. if (info.newSelections) {
  550. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  551. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  552. billsTreeSpreadObj.refreshPosData();
  553. }
  554. }
  555. billsTreeSpreadObj.loadExprToInput(info.sheet);
  556. },
  557. refreshPosData: function() {
  558. SpreadJsObj.resetTopAndSelect(posSheet);
  559. posSpreadObj.loadCurPosData();
  560. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  561. posSearch.search($('#pos-keyword').val());
  562. },
  563. /**
  564. * 新增节点
  565. * @param spread
  566. */
  567. baseOpr: function (sheet, type, addCount = 1) {
  568. const self = this;
  569. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  570. if (!tree || !node || !count) return;
  571. if (type === 'delete') {
  572. const parent = tree.getParent(node);
  573. const children = parent ? parent.children : tree.children;
  574. const index = children.indexOf(node);
  575. for (let i = 0; i < count; i++) {
  576. const child = children[i+index];
  577. if (tree.checkNodeUsed(child, pos)) {
  578. toastr.warning('选中的节点已计量,不可删除');
  579. return;
  580. }
  581. if (child.settle_status === settleStatus.finish) {
  582. toastr.warning('选中的节点已结算,不可删除');
  583. return;
  584. }
  585. }
  586. } else if (type === 'up-level') {
  587. const parent = tree.getParent(node);
  588. const children = parent ? parent.children : tree.children;
  589. const index = children.indexOf(node);
  590. const lastSelect = children[index + count - 1];
  591. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  592. toastr.warning('选中的节点已计量,不可升级');
  593. return;
  594. }
  595. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  596. toastr.warning('选中的节点已结算,不可升级');
  597. return;
  598. }
  599. // for (let i = index; i < children.length; i++) {
  600. // const child = children[index];
  601. // if (tree.checkNodeUsed(child, pos)) {
  602. // if (i >= index + count) {
  603. // toastr.warning('其后节点已计量,选中的节点不可升级');
  604. // } else {
  605. // toastr.warning('选中的节点已计量,不可升级');
  606. // }
  607. // return;
  608. // }
  609. // }
  610. } else if (type === 'down-level') {
  611. const parent = tree.getParent(node);
  612. const children = parent ? parent.children : tree.children;
  613. const index = children.indexOf(node);
  614. if (index > 0 && children[index-1].used) {
  615. toastr.warning('其前节点已计量,选中的节点不可降级');
  616. return;
  617. }
  618. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  619. toastr.warning('其前节点已结算,选中的节点不可降级');
  620. return;
  621. }
  622. for (let i = index; i < count; i++) {
  623. const child = children[i+index];
  624. if (tree.checkNodeUsed(child, pos)) {
  625. toastr.warning('选中的节点已计量,不可降级');
  626. return;
  627. }
  628. if (tree.settle_status === settleStatus.finish) {
  629. toastr.warning('选中的节点已结算,不可降级');
  630. return;
  631. }
  632. }
  633. } else if (type === 'add') {
  634. if (node.settle_status === settleStatus.finish) {
  635. toastr.warning('选中的节点已结算,不可新增子项');
  636. return;
  637. }
  638. }
  639. if (type === 'delete') {
  640. deleteAfterHint(function () {
  641. postData(window.location.pathname + '/update', {
  642. postType: type,
  643. postData: {
  644. id: node.ledger_id,
  645. count: type === 'add' ? addCount : count,
  646. }
  647. }, function (result) {
  648. changeList = result.changeList;
  649. const refreshData = tree.loadPostData(result);
  650. self.refreshTree(sheet, refreshData);
  651. const sel = sheet.getSelections()[0];
  652. if (sel) {
  653. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  654. billsTreeSpreadObj.refreshPosData();
  655. }
  656. self.refreshOperationValid(sheet);
  657. });
  658. });
  659. } else {
  660. postData(window.location.pathname + '/update', {
  661. postType: type,
  662. postData: {
  663. id: node.ledger_id,
  664. count: type === 'add' ? addCount : count,
  665. }
  666. }, function (result) {
  667. changeList = result.changeList;
  668. const refreshData = tree.loadPostData(result);
  669. self.refreshTree(sheet, refreshData);
  670. if (['up-move', 'down-move'].indexOf(type) > -1) {
  671. const sel = sheet.getSelections()[0];
  672. if (sel) {
  673. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  674. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  675. }
  676. } else if (type === 'add') {
  677. const sel = sheet.getSelections()[0];
  678. if (sel) {
  679. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  680. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  681. billsTreeSpreadObj.refreshPosData();
  682. }
  683. }
  684. self.refreshOperationValid(sheet);
  685. });
  686. }
  687. },
  688. buttonClicked: function (e, info, v) {
  689. if (info.sheet.zh_setting) {
  690. const select = SpreadJsObj.getSelectObject(info.sheet);
  691. const col = info.sheet.zh_setting.cols[info.col];
  692. if (col.field === 'is_change') {
  693. if (billsCol.readOnly.isChangeList(select)) {
  694. return
  695. }
  696. if (info.sheet.isEditing()) {
  697. info.sheet.endEdit(true);
  698. }
  699. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  700. if (is_change) {
  701. makeGclGatherData();
  702. const gclInfo = _.find(gclGatherData, function (item) {
  703. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  704. });
  705. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  706. return item.gcl_id === select.id;
  707. });
  708. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  709. const data = {
  710. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  711. code: gclInfo.b_code,
  712. name: gclInfo.name || '',
  713. unit: gclInfo.unit || '',
  714. unit_price: gclInfo.unit_price,
  715. oamount: xmjInfo.quantity,
  716. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  717. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  718. xmj_code: xmjInfo.code || '',
  719. xmj_jldy: xmjInfo.jldy || '',
  720. xmj_dwgc: xmjInfo.dwgc || '',
  721. xmj_fbgc: xmjInfo.fbgc || '',
  722. xmj_fxgc: xmjInfo.fxgc || '',
  723. gcl_id: select.id,
  724. mx_id: '',
  725. };
  726. if (oldCInfo) {
  727. data.detail = oldCInfo.detail;
  728. data.camount = oldCInfo.camount;
  729. data.camount_expr = oldCInfo.camount_expr;
  730. data.spamount = oldCInfo.spamount;
  731. data.is_valuation = oldCInfo.is_valuation;
  732. data.delimit = oldCInfo.delimit;
  733. }
  734. // 更新至服务器
  735. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  736. changeList = result.changeList;
  737. select.is_change = 1;
  738. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  739. if (oldCInfo) {
  740. select.camount = data.camount;
  741. const refreshNode = billsTree.loadPostData({ update: [select] });
  742. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  743. }
  744. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  745. }, function () {
  746. info.sheet.setValue(info.row, info.col, 0);
  747. });
  748. } else {
  749. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  750. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  751. info.sheet.setValue(info.row, info.col, 1);
  752. return
  753. }
  754. const cInfo = _.find(changeList, { gcl_id: select.id });
  755. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  756. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  757. info.sheet.setValue(info.row, info.col, 1);
  758. return
  759. } else if (checkIsSettle(cInfo)) {
  760. toastr.warning('该清单计量单元已结算,无法取消勾选');
  761. info.sheet.setValue(info.row, info.col, 1);
  762. return
  763. } else {
  764. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  765. changeList = result.changeList;
  766. select.is_change = 0;
  767. select.is_valuation = 0;
  768. select.camount = null;
  769. const billsNode = select;
  770. billsTreeSpreadObj.reCalcCamount(billsNode);
  771. const loadResult = { update: [billsNode] };
  772. const refreshNode = billsTree.loadPostData(loadResult);
  773. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  774. // 重算申请数量金额
  775. // const refreshNode = billsTree.loadPostData(result);
  776. // billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  777. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  778. }, function () {
  779. info.sheet.setValue(info.row, info.col, 1);
  780. });
  781. }
  782. }
  783. } else if (col.field === 'is_valuation') {
  784. if (billsCol.readOnly.isChangeList(select)) {
  785. return;
  786. }
  787. if (!billsCol.getValue.isChange(select)) {
  788. toastr.warning('请先勾选变更清单才能勾选计价');
  789. info.sheet.setValue(info.row, info.col, 0);
  790. return;
  791. }
  792. if (info.sheet.isEditing()) {
  793. info.sheet.endEdit(true);
  794. }
  795. const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  796. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  797. toastr.warning('该变更清单已被调用,无法更改计价');
  798. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  799. return;
  800. }
  801. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  802. // select.is_valuation = is_valuation;
  803. cInfo.is_valuation = is_valuation;
  804. delete cInfo.waitingLoading;
  805. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  806. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  807. info.sheet.setValue(info.row, info.col, is_valuation);
  808. }, function () {
  809. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  810. cInfo.is_valuation = select.is_valuation;
  811. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  812. });
  813. }
  814. }
  815. },
  816. /**
  817. * 编辑单元格响应事件
  818. * @param {Object} e
  819. * @param {Object} info
  820. */
  821. editEnded: function (e, info) {
  822. if (info.sheet.zh_setting) {
  823. const col = info.sheet.zh_setting.cols[info.col];
  824. if (col.field === 'is_change' || col.field === 'is_valuation') {
  825. return;
  826. }
  827. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  828. const node = sortData[info.row];
  829. if (col.field === 'camount') {
  830. if (!node) {
  831. toastr.error('数据错误,请选择台账节点后再试');
  832. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  833. return;
  834. }
  835. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  836. if (!cInfo) {
  837. if (billsCol.readOnly.isSettle(node)) {
  838. toastr.error('清单数据未完善,无法编辑申请数量');
  839. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  840. return;
  841. }
  842. makeGclGatherData();
  843. const gclInfo = _.find(gclGatherData, function (item) {
  844. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  845. });
  846. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  847. return item.gcl_id === node.id;
  848. });
  849. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  850. const data = {
  851. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  852. code: gclInfo.b_code,
  853. name: gclInfo.name || '',
  854. unit: gclInfo.unit || '',
  855. unit_price: gclInfo.unit_price,
  856. oamount: xmjInfo.quantity,
  857. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  858. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  859. xmj_code: xmjInfo.code || '',
  860. xmj_jldy: xmjInfo.jldy || '',
  861. xmj_dwgc: xmjInfo.dwgc || '',
  862. xmj_fbgc: xmjInfo.fbgc || '',
  863. xmj_fxgc: xmjInfo.fxgc || '',
  864. gcl_id: node.id,
  865. mx_id: '',
  866. };
  867. if (oldCInfo) {
  868. data.detail = oldCInfo.detail;
  869. data.camount = oldCInfo.camount;
  870. data.camount_expr = oldCInfo.camount_expr;
  871. data.spamount = oldCInfo.spamount;
  872. data.is_valuation = oldCInfo.is_valuation;
  873. data.delimit = oldCInfo.delimit;
  874. }
  875. cInfo = data;
  876. // toastr.error('未勾选变更清单,无法编辑申请数量');
  877. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  878. // return;
  879. }
  880. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  881. const orgValue = validText && validText !== ''
  882. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  883. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  884. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  885. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  886. return;
  887. }
  888. const exprQuantity = {
  889. expr: '',
  890. quantity: 0,
  891. };
  892. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  893. if (!valid) {
  894. toastr.error(msg);
  895. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  896. return;
  897. }
  898. if (isNaN(exprQuantity.quantity)) {
  899. toastr.error('不能输入其它非数字类型字符');
  900. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  901. return;
  902. }
  903. validText = parseFloat(exprQuantity.quantity);
  904. if (cInfo.id) {
  905. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  906. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  907. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  908. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  909. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  910. return;
  911. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  912. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  913. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  914. return;
  915. }
  916. }
  917. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  918. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  919. cInfo.camount_expr = exprQuantity.expr;
  920. node[col.field] = cInfo[col.field];
  921. delete cInfo.waitingLoading;
  922. if (cInfo.id) {
  923. if (cInfo.camount === 0 && cInfo.camount_expr === '') {
  924. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  925. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  926. return
  927. }
  928. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  929. toastr.warning('清单计量单元已被使用,无法取消勾选');
  930. return
  931. } else if (checkIsSettle(cInfo)) {
  932. toastr.warning('清单计量单元已结算,无法取消勾选');
  933. info.sheet.setValue(info.row, info.col, 1);
  934. return
  935. }
  936. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  937. changeList = result.changeList;
  938. node.is_change = 0;
  939. node.is_valuation = 0;
  940. node.camount = null;
  941. const billsNode = node;
  942. billsTreeSpreadObj.reCalcCamount(billsNode);
  943. const loadResult = { update: [billsNode] };
  944. const refreshNode = billsTree.loadPostData(loadResult);
  945. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  946. billsTreeSpreadObj.loadExprToInput(billsSheet);
  947. });
  948. } else {
  949. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  950. type: 'update',
  951. updateData: cInfo
  952. }, function (result) {
  953. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  954. const billsNode = node;
  955. billsTreeSpreadObj.reCalcCamount(billsNode);
  956. const loadResult = {update: [billsNode]};
  957. const refreshNode = billsTree.loadPostData(loadResult);
  958. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  959. }, function () {
  960. cInfo[col.field] = orgValue;
  961. cInfo.spamount = orgValue;
  962. node[col.field] = orgValue;
  963. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  964. });
  965. }
  966. } else {
  967. // 更新至服务器
  968. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  969. changeList = result.changeList;
  970. node.is_change = 1;
  971. node.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  972. node.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  973. billsTreeSpreadObj.reCalcCamount(node);
  974. const refreshNode = billsTree.loadPostData({ update: [node] });
  975. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  976. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  977. }, function () {
  978. cInfo[col.field] = orgValue;
  979. cInfo.spamount = orgValue;
  980. node[col.field] = orgValue;
  981. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  982. });
  983. }
  984. return;
  985. }
  986. const data = {
  987. id: node.id,
  988. tender_id: node.tender_id,
  989. ledger_id: node.ledger_id
  990. };
  991. // 未改变值则不提交
  992. const orgValue = node[col.field];
  993. const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  994. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  995. return;
  996. }
  997. // 台账模式,检查计量单元相关
  998. if (isTz) {
  999. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1000. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1001. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  1002. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  1003. if (!node.children || node.children.length ===0) {
  1004. const lPos = pos.getLedgerPos(node.id);
  1005. if (lPos && lPos.length > 0) {
  1006. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  1007. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1008. return;
  1009. }
  1010. }
  1011. }
  1012. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  1013. const lPos = pos.getLedgerPos(node.id);
  1014. if (lPos && lPos.length > 0) {
  1015. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  1016. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1017. return;
  1018. }
  1019. }
  1020. }
  1021. // 获取更新数据
  1022. const exprInfo = getExprInfo(col.field);
  1023. if (info.editingText) {
  1024. const text = newValue;
  1025. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  1026. toastr.error('节点已计量,请勿删除编号');
  1027. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1028. return;
  1029. }
  1030. if (col.type === 'Number') {
  1031. const num = _.toNumber(text);
  1032. if (_.isFinite(num)) {
  1033. data[col.field] = num;
  1034. if (exprInfo) {
  1035. data[exprInfo.expr] = '';
  1036. }
  1037. } else {
  1038. try {
  1039. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1040. if (exprInfo) {
  1041. data[exprInfo.expr] = newValue;
  1042. }
  1043. } catch(err) {
  1044. toastr.error('输入的表达式非法');
  1045. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1046. return;
  1047. }
  1048. }
  1049. } else {
  1050. data[col.field] = text;
  1051. }
  1052. } else {
  1053. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  1054. toastr.error('节点已计量,请勿删除编号');
  1055. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1056. return;
  1057. }
  1058. data[col.field] = null;
  1059. if (exprInfo) {
  1060. data[exprInfo.expr] = '';
  1061. }
  1062. }
  1063. if (col.field === 'b_code' && newValue) {
  1064. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1065. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1066. });
  1067. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  1068. if (ledgerOneData) {
  1069. data.name = ledgerOneData.name;
  1070. data.unit = ledgerOneData.unit;
  1071. data.unit_price = ledgerOneData.unit_price;
  1072. }
  1073. }
  1074. // 更新至服务器
  1075. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1076. changeList = result.changeList;
  1077. const refreshNode = billsTree.loadPostData(result);
  1078. for (const u of refreshNode.update) {
  1079. billsTreeSpreadObj.reCalcCamount(u);
  1080. }
  1081. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1082. billsTreeSpreadObj.refreshPosData();
  1083. });
  1084. }
  1085. },
  1086. clipboardPasting: function (e, info) {
  1087. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  1088. info.cancel = true;
  1089. if (!setting || !tree) return;
  1090. // const range = info.cellRange;
  1091. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1092. // const node = tree.nodes[iRow];
  1093. // if (tree.checkNodeUsed(node, pos)) {
  1094. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  1095. // return;
  1096. // }
  1097. // }
  1098. const pasteData = info.pasteData.html
  1099. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  1100. : (info.pasteData.text === ''
  1101. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  1102. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  1103. const hint = {
  1104. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  1105. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  1106. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  1107. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  1108. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  1109. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  1110. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  1111. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  1112. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  1113. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  1114. };
  1115. const datas = [], filterNodes = [], camountData = [], insertCamountData = [];
  1116. let pid, level, filterRow = 0;
  1117. makeGclGatherData();
  1118. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1119. const curRow = info.cellRange.row + iRow;
  1120. const node = tree.nodes[curRow];
  1121. if (!node) continue;
  1122. if (!pid) pid = node.ledger_pid;
  1123. if (!level) level = node.level;
  1124. // if (node.ledger_pid !== pid) {
  1125. // toastMessageUniq(hint.sameParent);
  1126. // filterRow+=1;
  1127. // continue;
  1128. // }
  1129. if (node.level < level) break;
  1130. let bPaste = false;
  1131. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1132. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1133. const curCol = info.cellRange.col + iCol;
  1134. const colSetting = info.sheet.zh_setting.cols[curCol];
  1135. const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  1136. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  1137. toastMessageUniq(hint.parent);
  1138. continue;
  1139. }
  1140. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  1141. toastMessageUniq(hint.gcl);
  1142. continue;
  1143. }
  1144. const lPos = pos.getLedgerPos(node.id);
  1145. if (lPos && lPos.length > 0) {
  1146. if (value === '' && colSetting.field === 'b_code') {
  1147. toastMessageUniq(hint.posCode);
  1148. continue;
  1149. }
  1150. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1151. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1152. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1153. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1154. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1155. if (isTz) {
  1156. toastMessageUniq(hint.posQty);
  1157. continue;
  1158. }
  1159. }
  1160. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  1161. toastMessageUniq(hint.posXmj);
  1162. continue;
  1163. }
  1164. }
  1165. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  1166. toastMessageUniq (hint.usedUp);
  1167. continue;
  1168. }
  1169. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  1170. toastMessageUniq(hint.settle);
  1171. continue;
  1172. }
  1173. if (colSetting.field === 'camount') {
  1174. bPaste = true;
  1175. let validText = value;
  1176. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1177. if (!cInfo) {
  1178. const gclInfo = _.find(gclGatherData, function (item) {
  1179. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  1180. });
  1181. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1182. return item.gcl_id === node.id;
  1183. });
  1184. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  1185. const data = {
  1186. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  1187. code: gclInfo.b_code,
  1188. name: gclInfo.name || '',
  1189. unit: gclInfo.unit || '',
  1190. unit_price: gclInfo.unit_price,
  1191. oamount: xmjInfo.quantity,
  1192. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1193. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  1194. xmj_code: xmjInfo.code || '',
  1195. xmj_jldy: xmjInfo.jldy || '',
  1196. xmj_dwgc: xmjInfo.dwgc || '',
  1197. xmj_fbgc: xmjInfo.fbgc || '',
  1198. xmj_fxgc: xmjInfo.fxgc || '',
  1199. gcl_id: node.id,
  1200. mx_id: '',
  1201. };
  1202. if (oldCInfo) {
  1203. data.detail = oldCInfo.detail;
  1204. data.camount = oldCInfo.camount;
  1205. data.camount_expr = oldCInfo.camount_expr;
  1206. data.spamount = oldCInfo.spamount;
  1207. data.is_valuation = oldCInfo.is_valuation;
  1208. data.delimit = oldCInfo.delimit;
  1209. }
  1210. cInfo = data;
  1211. // bPaste = false;
  1212. // continue;
  1213. }
  1214. const exprQuantity = {
  1215. expr: '',
  1216. quantity: 0,
  1217. };
  1218. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1219. if (!valid) {
  1220. toastMessageUniq(hint.invalidExpr);
  1221. bPaste = false;
  1222. continue;
  1223. }
  1224. if (isNaN(exprQuantity.quantity)) {
  1225. toastMessageUniq(hint.invalidExpr);
  1226. bPaste = false;
  1227. continue;
  1228. }
  1229. validText = parseFloat(exprQuantity.quantity);
  1230. if (cInfo.id) {
  1231. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1232. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  1233. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1234. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1235. bPaste = false;
  1236. continue;
  1237. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1238. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1239. bPaste = false;
  1240. continue;
  1241. }
  1242. }
  1243. if (bPaste) {
  1244. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1245. filterNodes.push(node);
  1246. if (cInfo.id) {
  1247. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1248. } else {
  1249. cInfo.camount = node.camount;
  1250. cInfo.camount_expr = exprQuantity.expr;
  1251. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1252. insertCamountData.push(cInfo);
  1253. }
  1254. } else {
  1255. filterNodes.push(node);
  1256. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1257. }
  1258. continue;
  1259. }
  1260. if (colSetting.type === 'Number') {
  1261. const num = _.toNumber(value);
  1262. if (num) {
  1263. data[colSetting.field] = num;
  1264. } else {
  1265. try {
  1266. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1267. const exprInfo = getExprInfo(colSetting.field);
  1268. if (exprInfo) {
  1269. data[exprInfo.expr] = value;
  1270. }
  1271. bPaste = true;
  1272. } catch (err) {
  1273. toastMessageUniq(hint.invalidExpr);
  1274. continue;
  1275. }
  1276. }
  1277. } else {
  1278. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  1279. && data[colSetting.field] !== '' && value === '') {
  1280. toastMessageUniq(hint.usedCode);
  1281. continue;
  1282. }
  1283. data[colSetting.field] = value;
  1284. }
  1285. if (colSetting.field === 'b_code' && value) {
  1286. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1287. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1288. });
  1289. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1290. if (ledgerOneData) {
  1291. data.name = ledgerOneData.name;
  1292. data.unit = ledgerOneData.unit;
  1293. data.unit_price = ledgerOneData.unit_price;
  1294. }
  1295. }
  1296. bPaste = true;
  1297. }
  1298. if (bPaste) {
  1299. datas.push(data);
  1300. } else {
  1301. filterNodes.push(node);
  1302. }
  1303. }
  1304. if (camountData.length > 0 || insertCamountData.length > 0) {
  1305. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  1306. changeList = result;
  1307. // 给所有filterNodes 加上is_change=1
  1308. filterNodes.forEach(function (item) {
  1309. item.is_change = 1;
  1310. });
  1311. const loadResult = { update: filterNodes };
  1312. const refreshNode = billsTree.loadPostData(loadResult);
  1313. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1314. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1315. }, function () {
  1316. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1317. return;
  1318. });
  1319. return;
  1320. }
  1321. if (datas.length > 0) {
  1322. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1323. changeList = result.changeList;
  1324. const refreshNode = tree.loadPostData(result);
  1325. if (refreshNode.update) {
  1326. refreshNode.update = refreshNode.update.concat(filterNodes);
  1327. }
  1328. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1329. }, function () {
  1330. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1331. });
  1332. } else {
  1333. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1334. }
  1335. },
  1336. clipboardPasted: function (e, info) {
  1337. const hint = {
  1338. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  1339. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  1340. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  1341. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  1342. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  1343. };
  1344. const tree = info.sheet.zh_tree;
  1345. if (!tree) { return; }
  1346. const sortData = info.sheet.zh_tree.nodes;
  1347. const datas = [], filterNodes = [], camountData = [];
  1348. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1349. let bPaste = false;
  1350. const curRow = info.cellRange.row + iRow;
  1351. const node = sortData[curRow];
  1352. if (node) {
  1353. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1354. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1355. const curCol = info.cellRange.col + iCol;
  1356. const colSetting = info.sheet.zh_setting.cols[curCol];
  1357. const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  1358. const lPos = pos.getLedgerPos(node.id);
  1359. if (lPos && lPos.length > 0) {
  1360. if (value === '' && colSetting.field === 'b_code') {
  1361. toastMessageUniq(hint.posCode);
  1362. continue;
  1363. }
  1364. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1365. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1366. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1367. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1368. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1369. toastMessageUniq(hint.posQty);
  1370. continue;
  1371. }
  1372. }
  1373. if (node.used && colSetting.field === 'unit_price') {
  1374. toastMessageUniq (hint.usedUp);
  1375. continue;
  1376. }
  1377. if (colSetting.field === 'camount') {
  1378. bPaste = true;
  1379. let validText = value;
  1380. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1381. if (!cInfo) {
  1382. bPaste = false;
  1383. continue;
  1384. }
  1385. const exprQuantity = {
  1386. expr: '',
  1387. quantity: 0,
  1388. };
  1389. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1390. if (!valid) {
  1391. toastMessageUniq(hint.invalidExpr);
  1392. bPaste = false;
  1393. continue;
  1394. }
  1395. if (isNaN(exprQuantity.quantity)) {
  1396. toastMessageUniq(hint.invalidExpr);
  1397. bPaste = false;
  1398. continue;
  1399. }
  1400. validText = parseFloat(exprQuantity.quantity);
  1401. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1402. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1403. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1404. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1405. bPaste = false;
  1406. continue;
  1407. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1408. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1409. bPaste = false;
  1410. continue;
  1411. }
  1412. if (bPaste) {
  1413. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1414. filterNodes.push(node);
  1415. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1416. } else {
  1417. filterNodes.push(node);
  1418. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1419. }
  1420. continue;
  1421. }
  1422. if (colSetting.type === 'Number') {
  1423. const num = _.toNumber(value);
  1424. if (num) {
  1425. data[colSetting.field] = num;
  1426. } else {
  1427. try {
  1428. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1429. } catch (err) {
  1430. toastMessageUniq(hint.invalidExpr);
  1431. continue;
  1432. }
  1433. }
  1434. } else {
  1435. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  1436. && data[colSetting.field] !== '' && value === '') {
  1437. toastMessageUniq(hint.usedCode);
  1438. continue;
  1439. }
  1440. data[colSetting.field] = value;
  1441. }
  1442. if (colSetting.field === 'b_code' && value) {
  1443. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1444. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1445. });
  1446. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1447. if (ledgerOneData) {
  1448. data.name = ledgerOneData.name;
  1449. data.unit = ledgerOneData.unit;
  1450. data.unit_price = ledgerOneData.unit_price;
  1451. }
  1452. }
  1453. bPaste = true;
  1454. }
  1455. if (bPaste) {
  1456. datas.push(data);
  1457. } else {
  1458. filterNodes.push(node);
  1459. }
  1460. }
  1461. }
  1462. if (camountData.length > 0) {
  1463. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
  1464. changeList = result;
  1465. const loadResult = { update: filterNodes };
  1466. const refreshNode = billsTree.loadPostData(loadResult);
  1467. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1468. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1469. }, function () {
  1470. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1471. return;
  1472. });
  1473. return;
  1474. }
  1475. if (datas.length > 0) {
  1476. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1477. changeList = result.changeList;
  1478. const refreshNode = tree.loadPostData(result);
  1479. if (refreshNode.update) {
  1480. refreshNode.update = refreshNode.update.concat(filterNodes);
  1481. }
  1482. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1483. }, function () {
  1484. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1485. });
  1486. } else {
  1487. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1488. }
  1489. },
  1490. deletePress: function (sheet) {
  1491. if (!sheet.zh_setting) return;
  1492. const sel = sheet.getSelections()[0], datas = [], camountDatas = [];
  1493. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1494. let bDel = false;
  1495. const node = sheet.zh_tree.nodes[iRow];
  1496. const data = sheet.zh_tree.getNodeKeyData(node);
  1497. const cData = {};
  1498. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1499. const col = sheet.zh_setting.cols[iCol];
  1500. const style = sheet.getStyle(iRow, iCol);
  1501. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1502. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1503. if (['dgn_qty1', 'dgn_qty2', 'camount'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1504. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1505. return;
  1506. }
  1507. if (col.field === 'camount') {
  1508. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1509. if (!cInfo) continue;
  1510. cData.id = cInfo.id;
  1511. cData.camount = null;
  1512. cData.camount_expr = '';
  1513. cData.spamount = null;
  1514. data.camount = null;
  1515. } else {
  1516. data[col.field] = null;
  1517. const exprInfo = getExprInfo(col.field);
  1518. if (exprInfo) {
  1519. data[exprInfo.expr] = '';
  1520. }
  1521. }
  1522. bDel = true;
  1523. }
  1524. if (bDel) {
  1525. datas.push(data);
  1526. if (cData.id) camountDatas.push(cData);
  1527. }
  1528. }
  1529. if (camountDatas.length > 0) {
  1530. for (const cInfo of camountDatas) {
  1531. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  1532. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  1533. return
  1534. }
  1535. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  1536. toastr.warning('清单计量单元已被使用,无法取消勾选');
  1537. return
  1538. } else if (checkIsSettle(cInfo)) {
  1539. toastr.warning('清单计量单元已结算,无法取消勾选');
  1540. info.sheet.setValue(info.row, info.col, 1);
  1541. return
  1542. }
  1543. }
  1544. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: _.map(camountDatas, 'id') }, function (result) {
  1545. changeList = result.changeList;
  1546. for (const d of datas) {
  1547. d.is_change = 0;
  1548. billsTreeSpreadObj.reCalcCamount(d);
  1549. }
  1550. const loadResult = { update: datas };
  1551. const refreshNode = billsTree.loadPostData(loadResult);
  1552. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1553. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1554. });
  1555. // postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  1556. // changeList = result;
  1557. // for (const d of datas) {
  1558. // billsTreeSpreadObj.reCalcCamount(d);
  1559. // }
  1560. // const loadResult = { update: datas };
  1561. // const refreshNode = billsTree.loadPostData(loadResult);
  1562. // billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1563. // billsTreeSpreadObj.loadExprToInput(billsSheet);
  1564. // });
  1565. return;
  1566. }
  1567. if (datas.length > 0) {
  1568. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1569. changeList = result.changeList;
  1570. const refreshNode = sheet.zh_tree.loadPostData(result);
  1571. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1572. billsTreeSpreadObj.loadExprToInput(sheet);
  1573. });
  1574. }
  1575. },
  1576. pasteBlock: function (spread, copyInfo) {
  1577. const self = this;
  1578. const sheet = spread.getActiveSheet();
  1579. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1580. if (node.settle_status === settleStatus.finish) {
  1581. toastr.warning('选中的节点已结算,不可粘贴整块');
  1582. return;
  1583. }
  1584. postData(window.location.pathname + '/update', {
  1585. postType: 'paste-block',
  1586. postData: {
  1587. id: tree.getNodeKey(node),
  1588. tid: copyInfo.tid,
  1589. block: copyInfo.block,
  1590. }
  1591. }, function (data) {
  1592. changeList = data.changeList;
  1593. pos.updateDatas(data.pos);
  1594. const result = tree.loadPostData(data.ledger);
  1595. self.refreshTree(sheet, result);
  1596. const sel = sheet.getSelections()[0];
  1597. if (sel) {
  1598. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1599. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1600. }
  1601. self.refreshOperationValid(sheet);
  1602. removeLocalCache(copyBlockTag);
  1603. }, null, true);
  1604. },
  1605. topRowChanged: function (e, info) {
  1606. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1607. },
  1608. editStarting(e, info) {
  1609. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1610. const col = info.sheet.zh_setting.cols[info.col];
  1611. const node = info.sheet.zh_tree.nodes[info.row];
  1612. if (!node) {
  1613. info.cancel = true;
  1614. return;
  1615. }
  1616. if (col.field === 'camount') {
  1617. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1618. if (!cInfo) {
  1619. if (billsCol.readOnly.isSettle(node)) {
  1620. toastr.error('清单数据未完善,无法编辑申请数量');
  1621. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1622. return
  1623. }
  1624. return;
  1625. }
  1626. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  1627. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  1628. }
  1629. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1630. info.cancel = true;
  1631. }
  1632. } else {
  1633. const exprInfo = getExprInfo(col.field);
  1634. if (exprInfo) {
  1635. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1636. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1637. }
  1638. }
  1639. switch (col.field) {
  1640. case 'code':
  1641. const posRange = pos.getLedgerPos(node.id);
  1642. info.cancel = posRange && posRange.length > 0;
  1643. break;
  1644. case 'unit_price':
  1645. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1646. break;
  1647. case 'sgfh_qty':
  1648. case 'sgfh_tp':
  1649. case 'sjcl_qty':
  1650. case 'sjcl_tp':
  1651. case 'qtcl_qty':
  1652. case 'qtcl_tp':
  1653. case 'deal_qty':
  1654. case 'deal_tp':
  1655. case 'ex_qty1':
  1656. case 'ex_tp1':
  1657. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1658. break;
  1659. case 'dgn_qty1':
  1660. case 'dgn_qty2':
  1661. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1662. break;
  1663. }
  1664. }
  1665. },
  1666. cut: function (sheet, sel, callback) {
  1667. if (!sheet || !sel) return;
  1668. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1669. toastr.warning('请勿选中整行剪切');
  1670. return;
  1671. }
  1672. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1673. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1674. const node = sortData[iRow];
  1675. if (node) {
  1676. const data = sheet.zh_tree.getNodeKeyData(node);
  1677. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1678. const col = sheet.zh_setting.cols[iCol];
  1679. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1680. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1681. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  1682. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  1683. const lPos = pos.getLedgerPos(node.id);
  1684. if (lPos && lPos.length > 0) {
  1685. toastr.error('不可剪切');
  1686. return;
  1687. }
  1688. }
  1689. const style = sheet.getStyle(iRow, iCol);
  1690. if (style.locked) {
  1691. toastr.error('不可剪切');
  1692. return;
  1693. }
  1694. const colSetting = sheet.zh_setting.cols[iCol];
  1695. data[colSetting.field] = null;
  1696. const exprInfo = getExprInfo(colSetting.field);
  1697. if (exprInfo) {
  1698. data[exprInfo.expr] = '';
  1699. }
  1700. }
  1701. datas.push(data);
  1702. }
  1703. }
  1704. if (datas.length > 0) {
  1705. callback();
  1706. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1707. changeList = result.changeList;
  1708. const refreshNode = sheet.zh_tree.loadPostData(result);
  1709. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1710. });
  1711. }
  1712. },
  1713. sortCode: function (sheet) {
  1714. const tree = sheet.zh_tree;
  1715. if (!tree) return;
  1716. const select = SpreadJsObj.getSelectObject(sheet);
  1717. if (!select || !select.code || select.code === '') return;
  1718. const recursiveSortCode = function (data, parentCode, children) {
  1719. if (!children || children.length === 0) return;
  1720. for (const [i, child] of children.entries()) {
  1721. if (!child.b_code || child.b_code === '') {
  1722. const code = parentCode + '-' + (i + 1);
  1723. const cData = tree.getNodeKeyData(child);
  1724. cData.code = code;
  1725. data.push(cData);
  1726. if (!tree.isLeafXmj(child)) {
  1727. recursiveSortCode(data, code, child.children);
  1728. }
  1729. }
  1730. }
  1731. };
  1732. const data = [];
  1733. recursiveSortCode(data, select.code, select.children);
  1734. if (data.length > 0) {
  1735. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1736. changeList = result.changeList;
  1737. const refreshNode = tree.loadPostData(result);
  1738. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1739. })
  1740. }
  1741. },
  1742. reCalcCamount: function (node) {
  1743. if (node && node.b_code) {
  1744. const posData = pos.getLedgerPos(node.id) || [];
  1745. let camount = node.camount || 0;
  1746. let is_valuation = node.is_valuation || 0;
  1747. if (posData.length > 0) {
  1748. camount = 0;
  1749. for (const np of posData) {
  1750. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  1751. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit))) : camount;
  1752. if (cInfo && cInfo.is_valuation) {
  1753. is_valuation = 1;
  1754. }
  1755. }
  1756. }
  1757. node.camount = camount;
  1758. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  1759. node.is_valuation = is_valuation;
  1760. }
  1761. },
  1762. _checkExprValid(expr) {
  1763. if (!expr) return [true, null];
  1764. const param = [];
  1765. let num = '', base = '';
  1766. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1767. if (/^[\d\.%]+/.test(expr[i])) {
  1768. if (base !== '') {
  1769. param.push({type: 'base', value: base});
  1770. base = '';
  1771. }
  1772. num = num + expr[i];
  1773. } else if (expr[i] === '(') {
  1774. if (num !== '') {
  1775. param.push({type: 'num', value: num});
  1776. num = '';
  1777. }
  1778. if (base !== '') {
  1779. param.push({type: 'base', value: base});
  1780. base = '';
  1781. }
  1782. param.push({type: 'left', value: '('});
  1783. } else if (expr[i] === ')') {
  1784. if (num !== '') {
  1785. param.push({type: 'num', value: num});
  1786. num = '';
  1787. }
  1788. if (base !== '') {
  1789. param.push({type: 'base', value: base});
  1790. base = '';
  1791. }
  1792. param.push({type: 'right', value: ')'});
  1793. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1794. if (num !== '') {
  1795. param.push({type: 'num', value: num});
  1796. num = '';
  1797. }
  1798. if (base !== '') {
  1799. param.push({type: 'base', value: base});
  1800. base = '';
  1801. }
  1802. param.push({type: 'calc', value: expr[i]});
  1803. } else {
  1804. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1805. }
  1806. }
  1807. if (num !== '') {
  1808. param.push({type: 'num', value: num});
  1809. num = '';
  1810. }
  1811. if (base !== '') {
  1812. param.push({type: 'base', value: base});
  1813. base = '';
  1814. }
  1815. if (param.length === 0) return true;
  1816. if (param.length > 1) {
  1817. if (param[0].value === '-' && param[1].type === 'num') {
  1818. param[1].value = '-' + param[1].value;
  1819. param.shift();
  1820. }
  1821. }
  1822. const iLen = param.length;
  1823. let iLeftCount = 0, iRightCount = 0;
  1824. for (const [i, p] of param.entries()) {
  1825. if (p.type === 'calc') {
  1826. if (i === 0 || i === iLen - 1)
  1827. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1828. }
  1829. if (p.type === 'num') {
  1830. num = p.value.replace('%', '');
  1831. if (p.value.length - num.length > 1)
  1832. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1833. num = _.toNumber(num);
  1834. if (num === undefined || num === null || _.isNaN(num))
  1835. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1836. if (i > 0) {
  1837. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1838. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1839. } else if (param[i - 1].value === '/' && num === 0) {
  1840. return [false, '输入的表达式非法:请勿除0'];
  1841. }
  1842. }
  1843. }
  1844. if (p.type === 'base') {
  1845. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1846. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1847. }
  1848. if (p.type === 'left') {
  1849. iLeftCount += 1;
  1850. if (i !== 0 && param[i-1].type !== 'calc')
  1851. return [false, '输入的表达式非法:(前应有运算符'];
  1852. }
  1853. if (p.type === 'right') {
  1854. iRightCount += 1;
  1855. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1856. return [false, '输入的表达式非法:)后应有运算符'];
  1857. if (iRightCount > iLeftCount)
  1858. return [false, '输入的表达式非法:")"前无对应的"("'];
  1859. }
  1860. }
  1861. if (iLeftCount > iRightCount)
  1862. return [false, '输入的表达式非法:"("后无对应的")"'];
  1863. return [true, ''];
  1864. },
  1865. _checkExpr: function (text, data) {
  1866. if (text) {
  1867. const num = _.toNumber(text);
  1868. if (num) {
  1869. data.quantity = num;
  1870. data.expr = '';
  1871. } else {
  1872. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1873. const [valid, msg] = this._checkExprValid(expr);
  1874. if (!valid) return [valid, msg];
  1875. data.expr = expr;
  1876. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  1877. // const ce = new CalcEvalMin();
  1878. // data.quantity = ce.eval(expr);
  1879. // console.log(data.quantity);
  1880. }
  1881. } else {
  1882. data.quantity = 0;
  1883. data.expr = '';
  1884. }
  1885. return [true, ''];
  1886. },
  1887. };
  1888. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1889. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1890. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1891. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1892. if (!readOnly) {
  1893. // 增删上下移升降级
  1894. $('a[name="base-opr"]').click(function () {
  1895. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1896. });
  1897. $('a[name=cpc]').click(function () {
  1898. billsSpread.commandManager().execute({
  1899. cmd: this.getAttribute('type'),
  1900. sheetName: billsSheet.name()
  1901. });
  1902. });
  1903. $('#bills-expr').bind('change onblur', function () {
  1904. if (this.readOnly) return;
  1905. const expr = $(this);
  1906. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1907. const select = billsTree.getItemsByIndex(row);
  1908. if (!select) return;
  1909. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1910. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1911. if (field === 'camount') {
  1912. let cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  1913. if (!cInfo) {
  1914. if (billsCol.readOnly.isChangeList(select)) {
  1915. toastr.error('清单数据未完善,无法编辑申请数量');
  1916. SpreadJsObj.reLoadRowData(billsSheet, row);
  1917. return;
  1918. }
  1919. makeGclGatherData();
  1920. const gclInfo = _.find(gclGatherData, function (item) {
  1921. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  1922. });
  1923. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1924. return item.gcl_id === select.id;
  1925. });
  1926. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  1927. const data = {
  1928. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  1929. code: gclInfo.b_code,
  1930. name: gclInfo.name || '',
  1931. unit: gclInfo.unit || '',
  1932. unit_price: gclInfo.unit_price,
  1933. oamount: xmjInfo.quantity,
  1934. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1935. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  1936. xmj_code: xmjInfo.code || '',
  1937. xmj_jldy: xmjInfo.jldy || '',
  1938. xmj_dwgc: xmjInfo.dwgc || '',
  1939. xmj_fbgc: xmjInfo.fbgc || '',
  1940. xmj_fxgc: xmjInfo.fxgc || '',
  1941. gcl_id: select.id,
  1942. mx_id: '',
  1943. };
  1944. if (oldCInfo) {
  1945. data.detail = oldCInfo.detail;
  1946. data.camount = oldCInfo.camount;
  1947. data.camount_expr = oldCInfo.camount_expr;
  1948. data.spamount = oldCInfo.spamount;
  1949. data.is_valuation = oldCInfo.is_valuation;
  1950. data.delimit = oldCInfo.delimit;
  1951. }
  1952. cInfo = data;
  1953. // toastr.error('未勾选变更清单,无法编辑申请数量');
  1954. // return;
  1955. }
  1956. const exprQuantity = {
  1957. expr: '',
  1958. quantity: 0,
  1959. };
  1960. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  1961. if (!valid) {
  1962. toastr.error(msg);
  1963. return;
  1964. }
  1965. if (isNaN(exprQuantity.quantity)) {
  1966. toastr.error('不能输入其它非数字类型字符');
  1967. return;
  1968. }
  1969. const camount = parseFloat(exprQuantity.quantity);
  1970. if (cInfo.id) {
  1971. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1972. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1973. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1974. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1975. return;
  1976. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1977. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1978. return;
  1979. }
  1980. }
  1981. cInfo.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1982. select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1983. cInfo.spamount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1984. cInfo.camount_expr = exprQuantity.expr;
  1985. delete cInfo.waitingLoading;
  1986. if (cInfo.id) {
  1987. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  1988. SpreadJsObj.reLoadRowData(billsSheet, row);
  1989. billsTreeSpreadObj.reCalcCamount(select);
  1990. const loadResult = { update: [select] };
  1991. const refreshNode = billsTree.loadPostData(loadResult);
  1992. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1993. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1994. }, function () {
  1995. cInfo.camount = orgValue;
  1996. cInfo.spamount = orgValue;
  1997. select.camount = orgValue;
  1998. SpreadJsObj.reLoadRowData(billsSheet, row);
  1999. });
  2000. } else {
  2001. // 更新至服务器
  2002. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  2003. changeList = result.changeList;
  2004. select.is_change = 1;
  2005. select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  2006. select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  2007. billsTreeSpreadObj.reCalcCamount(select);
  2008. const refreshNode = billsTree.loadPostData({ update: [select] });
  2009. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2010. SpreadJsObj.reLoadRowData(billsSheet, row);
  2011. }, function () {
  2012. cInfo[col.field] = orgValue;
  2013. cInfo.spamount = orgValue;
  2014. node[col.field] = orgValue;
  2015. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2016. });
  2017. }
  2018. return;
  2019. }
  2020. const data = {
  2021. id: select.id,
  2022. tender_id: select.tender_id,
  2023. ledger_id: select.ledger_id
  2024. };
  2025. const exprInfo = getExprInfo(field);
  2026. if (newValue !== '') {
  2027. const num = _.toNumber(newValue);
  2028. if (num) {
  2029. data[field] = num;
  2030. if (exprInfo) {
  2031. data[exprInfo.expr] = '';
  2032. }
  2033. } else {
  2034. try {
  2035. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2036. if (exprInfo) {
  2037. data[exprInfo.expr] = newValue;
  2038. }
  2039. } catch (err) {
  2040. toastr.error('输入的表达式非法');
  2041. return;
  2042. }
  2043. }
  2044. } else {
  2045. data[field] = null;
  2046. if (exprInfo) {
  2047. data[exprInfo.expr] = '';
  2048. }
  2049. }
  2050. // 更新至服务器
  2051. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  2052. changeList = result.changeList;
  2053. const refreshNode = billsTree.loadPostData(result);
  2054. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2055. });
  2056. });
  2057. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  2058. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  2059. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  2060. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  2061. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  2062. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  2063. SpreadJsObj.Clipboard.setCopyData(copyText);
  2064. });
  2065. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  2066. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  2067. }
  2068. // 右键菜单
  2069. let batchInsertObj;
  2070. $.contextMenu.types.batchInsert = function (item, opt, root) {
  2071. const self = this;
  2072. if ($.isFunction(item.icon)) {
  2073. item._icon = item.icon.call(this, this, $t, key, item);
  2074. } else {
  2075. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  2076. // to enable font awesome
  2077. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  2078. } else {
  2079. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  2080. }
  2081. }
  2082. this.addClass(item._icon);
  2083. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  2084. .appendTo(this);
  2085. const $input = $obj.find('input');
  2086. const event = () => {
  2087. if (self.hasClass('context-menu-disabled')) return;
  2088. item.batchInsert($input[0], root);
  2089. };
  2090. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  2091. $input.click((e) => {e.stopPropagation();})
  2092. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  2093. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  2094. };
  2095. const billsContextMenuOptions = {
  2096. selector: '#bills-spread',
  2097. build: function ($trigger, e) {
  2098. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  2099. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2100. },
  2101. items: {}
  2102. };
  2103. if (!readOnly) {
  2104. billsContextMenuOptions.items.create = {
  2105. name: '新增',
  2106. icon: 'fa-sign-in',
  2107. callback: function (key, opt) {
  2108. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  2109. },
  2110. disabled: function (key, opt) {
  2111. const sheet = billsSheet;
  2112. const selection = sheet.getSelections();
  2113. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2114. const row = sel ? sel.row : -1;
  2115. const tree = sheet.zh_tree;
  2116. if (!tree) return true;
  2117. const first = sheet.zh_tree.nodes[row];
  2118. const valid = !sheet.zh_setting.readOnly;
  2119. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2120. }
  2121. };
  2122. billsContextMenuOptions.items.delete = {
  2123. name: '删除',
  2124. icon: 'fa-remove',
  2125. callback: function (key, opt) {
  2126. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  2127. },
  2128. disabled: function (key, opt) {
  2129. const sheet = billsSheet;
  2130. const selection = sheet.getSelections();
  2131. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2132. const row = sel ? sel.row : -1;
  2133. const tree = sheet.zh_tree;
  2134. if (!tree) return true;
  2135. const first = sheet.zh_tree.nodes[row];
  2136. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  2137. if (sel.rowCount > 1 && first) {
  2138. for (let r = 1; r < sel.rowCount; r++) {
  2139. const rNode = tree.nodes[sel.row + r];
  2140. if (!rNode) {
  2141. sameParent = false;
  2142. break;
  2143. }
  2144. if (!rNode.formc) {
  2145. return true;
  2146. }
  2147. nodeUsed = nodeUsed || rNode.used;
  2148. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  2149. if (rNode.level > first.level) continue;
  2150. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  2151. sameParent = false;
  2152. break;
  2153. }
  2154. last = rNode;
  2155. }
  2156. }
  2157. const valid = !sheet.zh_setting.readOnly;
  2158. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  2159. }
  2160. };
  2161. billsContextMenuOptions.items.sprBase = '----';
  2162. }
  2163. billsContextMenuOptions.items.copyBlock = {
  2164. name: '复制整块',
  2165. icon: 'fa-files-o',
  2166. callback: function (key, opt) {
  2167. const copyBlockList = [];
  2168. const sheet = billsSheet;
  2169. const sel = sheet.getSelections()[0];
  2170. let iRow = sel.row;
  2171. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2172. while (iRow < sel.row + sel.rowCount) {
  2173. const node = sheet.zh_tree.nodes[iRow];
  2174. if (node.ledger_pid !== pid) {
  2175. toastr.error('仅可同时选中同层节点');
  2176. return;
  2177. }
  2178. const posterity = sheet.zh_tree.getPosterity(node);
  2179. iRow += posterity.length + 1;
  2180. posterity.unshift(node);
  2181. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  2182. }
  2183. for (const cbl of copyBlockList) {
  2184. for (const b of cbl) {
  2185. const posRange = pos.getLedgerPos(b.id);
  2186. if (posRange && posRange.length > 0) b.pos = posRange;
  2187. }
  2188. }
  2189. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2190. },
  2191. visible: function (key, opt) {
  2192. const sheet = billsSheet;
  2193. const selection = sheet.getSelections();
  2194. const row = selection[0].row;
  2195. const select = billsTree.nodes[row];
  2196. return select;
  2197. },
  2198. disabled: function (key, opt) {
  2199. const sheet = billsSheet;
  2200. const selection = sheet.getSelections();
  2201. const row = selection[0].row;
  2202. const select = billsTree.nodes[row];
  2203. return select && select.level <= 1;
  2204. }
  2205. };
  2206. billsContextMenuOptions.items.copyBlockXmj = {
  2207. name: '复制整块(只复制项目节)',
  2208. icon: 'fa-files-o',
  2209. callback: function (key, opt) {
  2210. const copyBlockList = [];
  2211. const sheet = billsSheet;
  2212. const sel = sheet.getSelections()[0];
  2213. let iRow = sel.row;
  2214. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2215. while (iRow < sel.row + sel.rowCount) {
  2216. const node = sheet.zh_tree.nodes[iRow];
  2217. if (node.ledger_pid !== pid) {
  2218. toastr.error('仅可同时选中同层节点');
  2219. return;
  2220. }
  2221. const posterity = sheet.zh_tree.getPosterity(node);
  2222. iRow += posterity.length + 1;
  2223. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  2224. copyPosterity.unshift(node);
  2225. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  2226. for (const p of copyData) {
  2227. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  2228. p.is_leaf = children.length === 0;
  2229. }
  2230. copyBlockList.push(copyData);
  2231. }
  2232. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2233. },
  2234. visible: function (key, opt) {
  2235. const sheet = billsSheet;
  2236. const selection = sheet.getSelections();
  2237. const row = selection[0].row;
  2238. const select = billsTree.nodes[row];
  2239. return select;
  2240. },
  2241. disabled: function (key, opt) {
  2242. const sheet = billsSheet;
  2243. const selection = sheet.getSelections();
  2244. const row = selection[0].row;
  2245. const select = billsTree.nodes[row];
  2246. return select && select.level <= 1;
  2247. }
  2248. };
  2249. if (!readOnly) {
  2250. billsContextMenuOptions.items.pasteBlock = {
  2251. name: '粘贴整块',
  2252. icon: 'fa-clipboard',
  2253. disabled: function (key, opt) {
  2254. //const block = treeOperationObj.block || [];
  2255. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2256. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  2257. },
  2258. callback: function (key, opt) {
  2259. //const block = treeOperationObj.block || [];
  2260. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2261. if (copyInfo.block.length > 0) {
  2262. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  2263. } else {
  2264. document.execCommand('paste');
  2265. }
  2266. },
  2267. visible: function (key, opt) {
  2268. return !readOnly;
  2269. }
  2270. };
  2271. billsContextMenuOptions.items.sprBlock = '----';
  2272. }
  2273. if (!readOnly) {
  2274. billsContextMenuOptions.items.batchInsert = {
  2275. name: '批量插入',
  2276. type: 'batchInsert',
  2277. value: '2',
  2278. icon: 'fa-sign-in',
  2279. batchInsert: function (obj, root) {
  2280. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2281. obj.value = obj.max;
  2282. toastr.warning('批量插入不可多于' + obj.max);
  2283. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2284. obj.value = obj.min;
  2285. toastr.warning('批量插入不可少于' + obj.min);
  2286. } else {
  2287. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  2288. root.$menu.trigger('contextmenu:hide');
  2289. }
  2290. },
  2291. disabled: function (key, opt) {
  2292. const sheet = billsSheet;
  2293. const selection = sheet.getSelections();
  2294. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2295. const row = sel ? sel.row : -1;
  2296. const tree = sheet.zh_tree;
  2297. if (!tree) return true;
  2298. const first = sheet.zh_tree.nodes[row];
  2299. const valid = !sheet.zh_setting.readOnly;
  2300. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2301. }
  2302. };
  2303. billsContextMenuOptions.items.batchInsertBillsPos = {
  2304. name: '批量插入清单-计量单元',
  2305. icon: 'fa-sign-in',
  2306. visible: function (key, opt) {
  2307. return false;
  2308. },
  2309. disabled: function (key, opt) {
  2310. if (!isTz) return true;
  2311. const select = SpreadJsObj.getSelectObject(billsSheet);
  2312. if (select) {
  2313. if (select.code && select.code !== '') {
  2314. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  2315. } else {
  2316. const parent = billsTree.getParent(select);
  2317. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  2318. }
  2319. } else {
  2320. return false;
  2321. }
  2322. },
  2323. callback: function (key, opt) {
  2324. if (!batchInsertObj) {
  2325. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  2326. } else {
  2327. batchInsertObj.initView();
  2328. }
  2329. $('#batch').modal('show');
  2330. }
  2331. };
  2332. }
  2333. billsContextMenuOptions.items.sprTag = '----';
  2334. billsContextMenuOptions.items.showLast = {
  2335. name: '显示至最底层',
  2336. callback: function (key, opt, menu, e) {
  2337. const node = SpreadJsObj.getSelectObject(billsSheet);
  2338. setTimeout(() => {
  2339. showWaitingView();
  2340. billsTree.expandByCustom(x => {
  2341. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  2342. });
  2343. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  2344. closeWaitingView();
  2345. }, 100);
  2346. },
  2347. };
  2348. $.contextMenu(billsContextMenuOptions);
  2349. // 计量单元 相关方法&绑定spreadjs事件
  2350. const posSpreadObj = {
  2351. refreshOperationValid: function (sheet, selection) {
  2352. const setObjEnable = function (obj, enable) {
  2353. if (enable) {
  2354. obj.removeClass('disabled');
  2355. } else {
  2356. obj.addClass('disabled');
  2357. }
  2358. };
  2359. const invalidAll = function () {
  2360. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  2361. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  2362. };
  2363. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2364. const row = sel ? sel.row : -1;
  2365. const first = sheet.zh_data[row];
  2366. if (!first) {
  2367. invalidAll();
  2368. return;
  2369. }
  2370. let last = first;
  2371. if (sel.rowCount > 1 && first) {
  2372. for (let r = 1; r < sel.rowCount; r++) {
  2373. const rNode = sheet.zh_data[sel.row + r];
  2374. if (!rNode) break;
  2375. last = rNode;
  2376. }
  2377. }
  2378. const preNode = sheet.zh_data[row - 1];
  2379. const valid = !sheet.zh_setting.readOnly;
  2380. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  2381. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  2382. },
  2383. loadExprToInput: function () {
  2384. const sel = posSheet.getSelections()[0];
  2385. if (!sel) return;
  2386. const col = posSheet.zh_setting.cols[sel.col];
  2387. const cell = posSheet.getCell(sel.col, sel.col);
  2388. if (col && col.field === 'camount') {
  2389. const data = SpreadJsObj.getSelectObject(posSheet);
  2390. if (data) {
  2391. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  2392. if (!cInfo) {
  2393. if (posCol.readOnly.isChangeList(data)) {
  2394. $('#pos-expr').val('').attr('readOnly', true);
  2395. $('#pos-expr').removeAttr('data-row');
  2396. } else {
  2397. $('#pos-expr').val('').attr('field', col.field).attr('org', '')
  2398. .attr('readOnly', false).attr('data-row', sel.row);
  2399. }
  2400. } else {
  2401. const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
  2402. $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
  2403. .attr('readOnly', posCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  2404. }
  2405. } else {
  2406. $('#pos-expr').val('').attr('readOnly', true);
  2407. $('#pos-expr').removeAttr('data-row');
  2408. }
  2409. } else if (col && col.type === 'Number') {
  2410. const data = SpreadJsObj.getSelectObject(posSheet);
  2411. if (data) {
  2412. const exprInfo = getExprInfo(col.field);
  2413. const value = exprInfo
  2414. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  2415. : data[col.field];
  2416. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2417. .attr('readOnly', readOnly || !data.formc || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  2418. } else {
  2419. $('#pos-expr').val('').attr('readOnly', true);
  2420. $('#pos-expr').removeAttr('data-row');
  2421. }
  2422. } else {
  2423. $('#pos-expr').val('').attr('readOnly', true);
  2424. $('#pos-expr').removeAttr('data-row');
  2425. }
  2426. },
  2427. /**
  2428. * 加载计量单元 根据当前台账选择节点
  2429. */
  2430. loadCurPosData: function () {
  2431. const node = SpreadJsObj.getSelectObject(billsSheet);
  2432. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  2433. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  2434. if (node) {
  2435. const posData = pos.getLedgerPos(node.id) || [];
  2436. console.log(posData);
  2437. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  2438. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  2439. } else {
  2440. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  2441. posSheet.zh_setting.readOnly = true;
  2442. }
  2443. SpreadJsObj.massOperationSheet(posSheet, function () {
  2444. if (posSheet.zh_setting) {
  2445. posSheet.zh_setting.cols.forEach(function (col, i) {
  2446. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  2447. if (i !== 0 && col.field !== 'camount' && col.field !== 'is_valuation') {
  2448. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  2449. } else {
  2450. let lock = false;
  2451. if (!posSheet.zh_data[iRow]) {
  2452. lock = true;
  2453. }
  2454. if (col.field === 'camount' && posCol.readOnly.isSettle(posSheet.zh_data[iRow])) {
  2455. lock = true;
  2456. }
  2457. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  2458. }
  2459. }
  2460. });
  2461. }
  2462. });
  2463. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  2464. posSpreadObj.loadExprToInput();
  2465. posSpreadObj.refreshOperationValid(posSheet);
  2466. },
  2467. baseOpr: function (sheet, type) {
  2468. const data = {
  2469. postType: 'pos',
  2470. posPostType: type === 'delete' ? type : 'update',
  2471. postData: [],
  2472. };
  2473. const selection = sheet.getSelections();
  2474. const row = selection[0].row, count = selection[0].rowCount;
  2475. const first = sheet.zh_data[row];
  2476. if (type === 'delete') {
  2477. for (let iRow = 0; iRow < count; iRow++) {
  2478. const posData = sheet.zh_data[iRow + row];
  2479. if (posData) {
  2480. if (posData.used) {
  2481. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2482. return;
  2483. }
  2484. if (posData.settle_status) {
  2485. toastr.error('"' + posData.name + '"已结算,请勿删除');
  2486. return;
  2487. }
  2488. data.postData.push(sheet.zh_data[iRow + row].id);
  2489. }
  2490. }
  2491. } else if (type === 'up-move') {
  2492. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  2493. for (let iRow = 0; iRow < count; iRow++) {
  2494. const posData = sheet.zh_data[iRow + row];
  2495. if (posData) {
  2496. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  2497. preUpdate.porder = posData.porder;
  2498. }
  2499. }
  2500. data.postData.push(preUpdate);
  2501. } else if (type === 'down-move') {
  2502. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  2503. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2504. const posData = sheet.zh_data[iRow + row];
  2505. if (posData) {
  2506. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  2507. nextUpdate.porder = posData.porder;
  2508. }
  2509. }
  2510. data.postData.push(nextUpdate);
  2511. } else if (type === 'add') {
  2512. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2513. if (billsNode.settle_status === settleStatus.finish) {
  2514. toastr.warning('清单已结算,不可新增计量单元');
  2515. return;
  2516. }
  2517. }
  2518. if (data.postData.length > 0) {
  2519. postData(window.location.pathname + '/update', data, function (result) {
  2520. changeList = result.changeList;
  2521. if (type === 'delete') {
  2522. pos.removeDatas(result.pos);
  2523. sheet.deleteRows(row, count);
  2524. const loadResult = billsTree.loadPostData(result.ledger);
  2525. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2526. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2527. posSpreadObj.refreshOperationValid(posSheet);
  2528. } else {
  2529. pos.updateDatas(result.pos);
  2530. const sel = selection[0];
  2531. if (sel) {
  2532. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  2533. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  2534. }
  2535. posSpreadObj.loadCurPosData();
  2536. }
  2537. });
  2538. }
  2539. },
  2540. editStarting: function (e, info) {
  2541. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2542. const sel = info.sheet.getSelections();
  2543. if (!sel || !sel[0]) return;
  2544. const col = info.sheet.zh_setting.cols[sel[0].col];
  2545. const node = SpreadJsObj.getSelectObject(info.sheet);
  2546. const exprInfo = getExprInfo(col.field);
  2547. if (col.field === 'camount') {
  2548. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2549. if (!cInfo) {
  2550. if (posCol.readOnly.isSettle(node)) {
  2551. toastr.error('清单数据未完善,无法编辑申请数量');
  2552. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2553. return
  2554. }
  2555. return
  2556. }
  2557. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  2558. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  2559. }
  2560. } else if (node && exprInfo) {
  2561. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2562. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2563. }
  2564. }
  2565. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  2566. info.cancel = true;
  2567. }
  2568. },
  2569. buttonClicked: function (e, info) {
  2570. if (info.sheet.zh_setting) {
  2571. const select = SpreadJsObj.getSelectObject(info.sheet);
  2572. const col = info.sheet.zh_setting.cols[info.col];
  2573. if (col.field === 'is_change') {
  2574. if (posCol.readOnly.isChangeList(select)) {
  2575. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  2576. return
  2577. }
  2578. if (info.sheet.isEditing()) {
  2579. info.sheet.endEdit(true);
  2580. }
  2581. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2582. // const valutaionCol = _.findIndex(info.sheet.zh_setting.cols, { field: 'is_valuation' });
  2583. if (is_change) {
  2584. makeGclGatherData();
  2585. const gclInfo = _.find(gclGatherData, function (item) {
  2586. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  2587. });
  2588. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  2589. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  2590. const data = {
  2591. lid: select.lid,
  2592. code: gclInfo.b_code,
  2593. name: gclInfo.name || '',
  2594. unit: gclInfo.unit || '',
  2595. unit_price: gclInfo.unit_price,
  2596. oamount: xmjInfo.quantity,
  2597. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2598. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2599. xmj_code: xmjInfo.code || '',
  2600. xmj_jldy: xmjInfo.jldy || '',
  2601. xmj_dwgc: xmjInfo.dwgc || '',
  2602. xmj_fbgc: xmjInfo.fbgc || '',
  2603. xmj_fxgc: xmjInfo.fxgc || '',
  2604. gcl_id: select.lid,
  2605. mx_id: select.id,
  2606. }
  2607. if (oldCInfo) {
  2608. data.detail = oldCInfo.detail;
  2609. data.camount = oldCInfo.camount;
  2610. data.camount_expr = oldCInfo.camount_expr;
  2611. data.spamount = oldCInfo.spamount;
  2612. data.is_valuation = oldCInfo.is_valuation;
  2613. data.delimit = oldCInfo.delimit;
  2614. }
  2615. // 更新至服务器
  2616. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  2617. changeList = result.changeList;
  2618. select.is_change = 1;
  2619. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  2620. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2621. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2622. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  2623. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2624. billsNode.is_change = 1;
  2625. billsTreeSpreadObj.reCalcCamount(billsNode);
  2626. const loadResult = { update: [billsNode] };
  2627. const refreshNode = billsTree.loadPostData(loadResult);
  2628. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2629. }
  2630. }, function () {
  2631. info.sheet.setValue(info.row, info.col, 0);
  2632. });
  2633. } else {
  2634. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  2635. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2636. info.sheet.setValue(info.row, info.col, 1);
  2637. return
  2638. }
  2639. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2640. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  2641. toastr.warning('该计量单元已被使用,无法取消变更');
  2642. info.sheet.setValue(info.row, info.col, 1);
  2643. return
  2644. } else if (checkIsSettle(cInfo)) {
  2645. toastr.warning('该计量单元已结算,无法取消变更');
  2646. info.sheet.setValue(info.row, info.col, 1);
  2647. return
  2648. } else {
  2649. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2650. changeList = result.changeList;
  2651. select.is_change = 0;
  2652. select.is_valuation = 0;
  2653. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2654. // info.sheet.setValue(info.row, valutaionCol, 0);
  2655. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2656. billsTreeSpreadObj.reCalcCamount(billsNode);
  2657. // 判断是否只剩一个,并同步去勾
  2658. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  2659. billsNode.is_change = 0;
  2660. }
  2661. const loadResult = { update: [billsNode] };
  2662. const refreshNode = billsTree.loadPostData(loadResult);
  2663. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2664. }, function () {
  2665. info.sheet.setValue(info.row, info.col, 1);
  2666. });
  2667. }
  2668. }
  2669. } else if (col.field === 'is_valuation') {
  2670. if (!posCol.getValue.isChange(select)) {
  2671. toastr.warning('请先勾选变更清单才能勾选计价');
  2672. info.sheet.setValue(info.row, info.col, !select || !select.is_valuation ? 0 : 1);
  2673. return;
  2674. }
  2675. if (info.sheet.isEditing()) {
  2676. info.sheet.endEdit(true);
  2677. }
  2678. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2679. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  2680. toastr.warning('该变更清单已被调用,无法更改计价');
  2681. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  2682. return;
  2683. }
  2684. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2685. // select.is_valuation = is_valuation;
  2686. cInfo.is_valuation = is_valuation;
  2687. delete cInfo.waitingLoading;
  2688. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  2689. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2690. info.sheet.setValue(info.row, info.col, is_valuation);
  2691. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2692. SpreadJsObj.reLoadRowData(billsSheet, billsTree.getNodeIndex(billsNode));
  2693. }, function () {
  2694. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2695. cInfo.is_valuation = select.is_valuation;
  2696. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2697. });
  2698. }
  2699. }
  2700. },
  2701. /**
  2702. * 编辑单元格响应事件
  2703. * @param {Object} e
  2704. * @param {Object} info
  2705. */
  2706. editEnded: function (e, info) {
  2707. if (!info.sheet.zh_setting) {
  2708. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2709. return;
  2710. }
  2711. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  2712. const node = posSpreadObj.billsNode;
  2713. const col = info.sheet.zh_setting.cols[info.col];
  2714. if (col.field === 'is_change' || col.field === 'is_valuation') {
  2715. return;
  2716. }
  2717. if (col.field === 'camount') {
  2718. if (!node) {
  2719. toastr.error('数据错误,请选择台账节点后再试');
  2720. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2721. return;
  2722. }
  2723. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  2724. if (!cInfo) {
  2725. if (posCol.readOnly.isSettle(posData)) {
  2726. toastr.error('清单数据未完善,无法编辑申请数量');
  2727. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2728. return
  2729. }
  2730. makeGclGatherData();
  2731. const gclInfo = _.find(gclGatherData, function (item) {
  2732. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  2733. });
  2734. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  2735. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  2736. const data = {
  2737. lid: posData.lid,
  2738. code: gclInfo.b_code,
  2739. name: gclInfo.name || '',
  2740. unit: gclInfo.unit || '',
  2741. unit_price: gclInfo.unit_price,
  2742. oamount: xmjInfo.quantity,
  2743. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2744. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2745. xmj_code: xmjInfo.code || '',
  2746. xmj_jldy: xmjInfo.jldy || '',
  2747. xmj_dwgc: xmjInfo.dwgc || '',
  2748. xmj_fbgc: xmjInfo.fbgc || '',
  2749. xmj_fxgc: xmjInfo.fxgc || '',
  2750. gcl_id: posData.lid,
  2751. mx_id: posData.id,
  2752. }
  2753. if (oldCInfo) {
  2754. data.detail = oldCInfo.detail;
  2755. data.camount = oldCInfo.camount;
  2756. data.camount_expr = oldCInfo.camount_expr;
  2757. data.spamount = oldCInfo.spamount;
  2758. data.is_valuation = oldCInfo.is_valuation;
  2759. data.delimit = oldCInfo.delimit;
  2760. }
  2761. cInfo = data;
  2762. // toastr.error('未勾选变更清单,无法编辑申请数量');
  2763. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2764. // return;
  2765. }
  2766. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  2767. const orgValue = validText && validText !== ''
  2768. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  2769. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  2770. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2771. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2772. return;
  2773. }
  2774. const exprQuantity = {
  2775. expr: '',
  2776. quantity: 0,
  2777. };
  2778. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  2779. if (!valid) {
  2780. toastr.error(msg);
  2781. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2782. return;
  2783. }
  2784. if (isNaN(exprQuantity.quantity)) {
  2785. toastr.error('不能输入其它非数字类型字符');
  2786. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2787. return;
  2788. }
  2789. validText = parseFloat(exprQuantity.quantity);
  2790. if (cInfo.id) {
  2791. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2792. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  2793. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2794. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2795. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2796. return;
  2797. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2798. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2799. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2800. return;
  2801. }
  2802. }
  2803. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2804. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2805. cInfo.camount_expr = exprQuantity.expr;
  2806. delete cInfo.waitingLoading;
  2807. if (cInfo.id) {
  2808. if (cInfo.camount === 0 && cInfo.camount_expr === '') {
  2809. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  2810. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2811. return
  2812. }
  2813. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  2814. toastr.warning('清单计量单元已被使用,无法取消勾选');
  2815. return
  2816. } else if (checkIsSettle(cInfo)) {
  2817. toastr.warning('清单计量单元已结算,无法取消勾选');
  2818. info.sheet.setValue(info.row, info.col, 1);
  2819. return
  2820. }
  2821. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2822. changeList = result.changeList;
  2823. node.is_change = 0;
  2824. node.is_valuation = 0;
  2825. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2826. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2827. billsTreeSpreadObj.reCalcCamount(billsNode);
  2828. // 判断是否只剩一个,并同步去勾
  2829. if (_.findIndex(changeList, { gcl_id: node.lid }) === -1) {
  2830. billsNode.is_change = 0;
  2831. }
  2832. const loadResult = { update: [billsNode] };
  2833. const refreshNode = billsTree.loadPostData(loadResult);
  2834. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2835. });
  2836. } else {
  2837. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type: 'update', updateData: cInfo }, function (result) {
  2838. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2839. const billsNode = node;
  2840. billsTreeSpreadObj.reCalcCamount(billsNode);
  2841. const loadResult = {update: [billsNode]};
  2842. const refreshNode = billsTree.loadPostData(loadResult);
  2843. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2844. }, function () {
  2845. cInfo[col.field] = orgValue;
  2846. cInfo.spamount = orgValue;
  2847. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2848. });
  2849. }
  2850. } else {
  2851. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  2852. changeList = result.changeList;
  2853. posData.is_change = 1;
  2854. posData.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  2855. posData.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  2856. posData.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  2857. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2858. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2859. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2860. if (_.findIndex(changeList, { gcl_id: posData.lid }) !== -1) {
  2861. billsNode.is_change = 1;
  2862. }
  2863. billsTreeSpreadObj.reCalcCamount(billsNode);
  2864. const loadResult = { update: [billsNode] };
  2865. const refreshNode = billsTree.loadPostData(loadResult);
  2866. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2867. }, function () {
  2868. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2869. });
  2870. }
  2871. return;
  2872. }
  2873. const orgText = posData ? posData[col.field] : null;
  2874. const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  2875. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  2876. if (!node) {
  2877. toastr.error('数据错误,请选择台账节点后再试');
  2878. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2879. return;
  2880. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  2881. toastr.error('父节点不可插入计量单元');
  2882. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2883. return;
  2884. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  2885. toastr.error('项目节不可插入计量单元');
  2886. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2887. return;
  2888. }
  2889. const data = {postType: 'pos'};
  2890. if (col.field === 'name') {
  2891. if (newText === '' && posData) {
  2892. toastr.error('部位名称不可为空', 'error');
  2893. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2894. return;
  2895. } else if (!posData) {
  2896. if (newText && newText !== '') {
  2897. data.posPostType = 'add';
  2898. const sortData = info.sheet.zh_data;
  2899. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2900. data.postData = { name: newText, lid: node.id, porder: order};
  2901. if (node.settle_status === settleStatus.finish) {
  2902. toastr.error('已结算清单不可插入计量单元');
  2903. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2904. return;
  2905. }
  2906. } else {
  2907. return;
  2908. }
  2909. } else {
  2910. data.posPostType = 'update';
  2911. data.postData = {id: posData.id, name: newText};
  2912. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  2913. toastr.error('计量单元已结算,不可修改');
  2914. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2915. return;
  2916. }
  2917. }
  2918. } else if (!posData) {
  2919. toastr.warning('新增计量单元请先输入名称');
  2920. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2921. return;
  2922. } else {
  2923. data.posPostType = 'update';
  2924. data.postData = {id: posData.id};
  2925. if (col.type === 'Number') {
  2926. const exprInfo = getExprInfo(col.field);
  2927. const num = _.toNumber(newText);
  2928. if (_.isFinite(num)) {
  2929. data.postData[col.field] = num;
  2930. if (exprInfo) {
  2931. data.postData[exprInfo.expr] = '';
  2932. }
  2933. } else {
  2934. try {
  2935. data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2936. if (exprInfo) {
  2937. data.postData[exprInfo.expr] = newText;
  2938. }
  2939. } catch(err) {
  2940. toastr.error('输入的表达式非法');
  2941. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2942. return;
  2943. }
  2944. }
  2945. } else if (col.field.indexOf('_expr') > 0) {
  2946. const exprInfo = getExprInfo(col.field, true);
  2947. if (!exprInfo) return;
  2948. if (newText) {
  2949. try {
  2950. data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2951. data.postData[exprInfo.expr] = newText;
  2952. } catch(err) {
  2953. toastr.error('输入的表达式非法');
  2954. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2955. return;
  2956. }
  2957. } else {
  2958. data.postData[exprInfo.qty] = 0;
  2959. data.postData[exprInfo.expr] = '';
  2960. }
  2961. } else {
  2962. data.postData[col.field] = newText;
  2963. }
  2964. }
  2965. postData(window.location.pathname + '/update', data, function (result) {
  2966. changeList = result.changeList;
  2967. const updateRst = pos.updateDatas(result.pos);
  2968. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2969. if (updateRst.create.length > 0) {
  2970. posSpreadObj.loadCurPosData();
  2971. } else {
  2972. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2973. }
  2974. const loadResult = billsTree.loadPostData(result.ledger);
  2975. // 判断是否只剩一个,并同步去勾
  2976. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2977. // billsNode.is_change = ? 1 : 0;
  2978. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2979. billsNode.is_change = 1;
  2980. } else {
  2981. billsNode.is_change = 0;
  2982. billsNode.is_valuation = 0;
  2983. billsNode.camount = null;
  2984. billsNode.ca_tp = null;
  2985. }
  2986. if (loadResult.update) {
  2987. const r = _.find(loadResult.update, { id: billsNode.id });
  2988. r.is_change = billsNode.is_change;
  2989. } else {
  2990. loadResult.update = [billsNode];
  2991. }
  2992. const refreshNode = billsTree.loadPostData(loadResult);
  2993. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2994. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2995. }, function () {
  2996. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2997. });
  2998. },
  2999. /**
  3000. * 删除按钮响应事件
  3001. * @param sheet
  3002. */
  3003. deletePress: function (sheet) {
  3004. if (!sheet.zh_setting) return;
  3005. const sortData = sheet.zh_data;
  3006. const datas = [], posSelects = [], camountDatas = [];
  3007. const sel = sheet.getSelections()[0];
  3008. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3009. let bDel = false;
  3010. const node = sortData[iRow];
  3011. if (node) {
  3012. const data = {id: node.id};
  3013. const cData = {};
  3014. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3015. const colSetting = sheet.zh_setting.cols[iCol];
  3016. if (colSetting.field === 'name') {
  3017. toastr.error('部位名称不能为空');
  3018. return;
  3019. }
  3020. const style = sheet.getStyle(iRow, iCol);
  3021. if (!style.locked) {
  3022. const colSetting = sheet.zh_setting.cols[iCol];
  3023. if (colSetting.field === 'camount') {
  3024. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  3025. if (!cInfo) continue;
  3026. cData.id = cInfo.id;
  3027. cData.camount = null;
  3028. cData.camount_expr = '';
  3029. cData.spamount = null;
  3030. } else if (colSetting.field.indexOf('_expr') > 0) {
  3031. const exprInfo = getExprInfo(colSetting.field, true);
  3032. if (!exprInfo) continue;
  3033. data[exprInfo.expr] = '';
  3034. data[exprInfo.qty] = 0;
  3035. } else {
  3036. data[colSetting.field] = null;
  3037. const exprInfo = getExprInfo(colSetting.field);
  3038. if (exprInfo) data[exprInfo.expr] = '';
  3039. }
  3040. bDel = true;
  3041. }
  3042. }
  3043. if (bDel) {
  3044. datas.push(data);
  3045. if (cData.id) camountDatas.push(cData);
  3046. posSelects.push(node);
  3047. }
  3048. }
  3049. }
  3050. if (camountDatas.length > 0) {
  3051. for (const cInfo of camountDatas) {
  3052. if (changeOrder && _.findIndex(oldChangeList, {id: cInfo.id}) !== -1) {
  3053. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  3054. info.sheet.setValue(info.row, info.col, 1);
  3055. return
  3056. }
  3057. if (_.find(changeUsedData, {cbid: cInfo.id})) {
  3058. toastr.warning('该计量单元已被使用,无法取消变更');
  3059. info.sheet.setValue(info.row, info.col, 1);
  3060. return
  3061. } else if (checkIsSettle(cInfo)) {
  3062. toastr.warning('该计量单元已结算,无法取消变更');
  3063. info.sheet.setValue(info.row, info.col, 1);
  3064. return
  3065. }
  3066. }
  3067. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: _.map(camountDatas, 'id') }, function (result) {
  3068. changeList = result.changeList;
  3069. for (const d of datas) {
  3070. d.is_change = 0;
  3071. d.is_valuation = 0;
  3072. }
  3073. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3074. billsTreeSpreadObj.reCalcCamount(billsNode);
  3075. // 判断是否只剩一个,并同步去勾
  3076. if (_.findIndex(changeList, { gcl_id: posSelects[0].lid }) === -1) {
  3077. billsNode.is_change = 0;
  3078. }
  3079. const loadResult = { update: [billsNode] };
  3080. const refreshNode = billsTree.loadPostData(loadResult);
  3081. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3082. posSpreadObj.loadCurPosData();
  3083. }, function () {
  3084. posSpreadObj.loadCurPosData();
  3085. });
  3086. // postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  3087. // changeList = result;
  3088. // const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3089. // billsTreeSpreadObj.reCalcCamount(billsNode);
  3090. // const loadResult = { update: [billsNode] };
  3091. // const refreshNode = billsTree.loadPostData(loadResult);
  3092. // billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3093. // posSpreadObj.loadCurPosData();
  3094. // }, function () {
  3095. // posSpreadObj.loadCurPosData();
  3096. // });
  3097. return;
  3098. }
  3099. if (datas.length > 0) {
  3100. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  3101. changeList = result.changeList;
  3102. pos.updateDatas(result.pos);
  3103. posSpreadObj.loadCurPosData();
  3104. const loadResult = billsTree.loadPostData(result.ledger);
  3105. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3106. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3107. }, function () {
  3108. posSpreadObj.loadCurPosData();
  3109. });
  3110. }
  3111. },
  3112. /**
  3113. * 删除 计量单元
  3114. * @param sheet
  3115. */
  3116. deletePos: function (sheet) {
  3117. const selection = sheet.getSelections();
  3118. const data = {
  3119. postType: 'pos',
  3120. posPostType: 'delete',
  3121. postData: [],
  3122. };
  3123. const row = selection[0].row, count = selection[0].rowCount;
  3124. const sortData = sheet.zh_data;
  3125. for (let iRow = 0; iRow < count; iRow++) {
  3126. const posData = sortData[iRow + row];
  3127. if (posData) {
  3128. if (posData.used) {
  3129. toastr.error('"' + posData.name + '"已计量,请勿删除');
  3130. return;
  3131. }
  3132. if (posData.settle_status === settleStatus.finish) {
  3133. toastr.error(`"${posData.name}"已计量,请勿删除`);
  3134. return;
  3135. }
  3136. data.postData.push(sortData[iRow + row].id);
  3137. }
  3138. }
  3139. if (data.postData.length > 0) {
  3140. postData(window.location.pathname + '/update', data, function (result) {
  3141. changeList = result.changeList;
  3142. pos.removeDatas(result.pos);
  3143. sheet.deleteRows(row, count);
  3144. const loadResult = billsTree.loadPostData(result.ledger);
  3145. // 判断是否只剩一个,并同步去勾
  3146. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3147. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3148. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3149. billsNode.is_change = 1;
  3150. } else {
  3151. billsNode.is_change = 0;
  3152. billsNode.is_valuation = 0;
  3153. billsNode.camount = null;
  3154. billsNode.ca_tp = null;
  3155. }
  3156. if (loadResult.update) {
  3157. const r = _.find(loadResult.update, { id: billsNode.id });
  3158. r.is_change = billsNode.is_change;
  3159. } else {
  3160. loadResult.update = [billsNode];
  3161. }
  3162. billsTreeSpreadObj.reCalcCamount(billsNode);
  3163. const refreshNode = billsTree.loadPostData(loadResult);
  3164. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3165. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3166. });
  3167. }
  3168. },
  3169. /**
  3170. * 粘贴单元格响应事件
  3171. * @param e
  3172. * @param info
  3173. */
  3174. clipboardPasted: function (e, info) {
  3175. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  3176. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  3177. }
  3178. const node = SpreadJsObj.getSelectObject(billsSheet);
  3179. if (node.code && (node.code !== '')) {
  3180. toastr.error('项目节不可含有节点明细');
  3181. posSpreadObj.loadCurPosData();
  3182. return;
  3183. }
  3184. if (node.children && (node.children.length > 0)) {
  3185. toastr.error('仅节点子项可以含有计量单元');
  3186. posSpreadObj.loadCurPosData();
  3187. return;
  3188. }
  3189. if (node.settle_status === settleStatus.finish) {
  3190. toastr.error('清单已结算,请勿修改计量单元数据');
  3191. posSpread.loadCurPosData();
  3192. return;
  3193. }
  3194. if (!info.sheet.zh_setting) {
  3195. posSpreadObj.loadCurPosData();
  3196. return;
  3197. }
  3198. const data = [];
  3199. const camountData = [], insertCamountData = [];
  3200. const sortData = info.sheet.zh_data || [];
  3201. const hint = {
  3202. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  3203. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  3204. };
  3205. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  3206. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  3207. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  3208. toastr.warning('新增计量单元请先输入名称');
  3209. posSpreadObj.loadCurPosData();
  3210. return;
  3211. }
  3212. }
  3213. let bHint = false;
  3214. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3215. makeGclGatherData();
  3216. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3217. let bPaste = true;
  3218. const curRow = info.cellRange.row + iRow;
  3219. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  3220. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  3221. const curCol = info.cellRange.col + iCol;
  3222. const colSetting = info.sheet.zh_setting.cols[curCol];
  3223. if (!colSetting) continue;
  3224. posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  3225. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  3226. bPaste = false;
  3227. toastMessageUniq(hint.settle);
  3228. continue;
  3229. }
  3230. if (colSetting.field === 'camount') {
  3231. bPaste = true;
  3232. let validText = posData[colSetting.field];
  3233. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  3234. if (!cInfo) {
  3235. const gclInfo = _.find(gclGatherData, function (item) {
  3236. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  3237. });
  3238. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  3239. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  3240. const data = {
  3241. lid: posData.lid,
  3242. code: gclInfo.b_code,
  3243. name: gclInfo.name || '',
  3244. unit: gclInfo.unit || '',
  3245. unit_price: gclInfo.unit_price,
  3246. oamount: xmjInfo.quantity,
  3247. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3248. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3249. xmj_code: xmjInfo.code || '',
  3250. xmj_jldy: xmjInfo.jldy || '',
  3251. xmj_dwgc: xmjInfo.dwgc || '',
  3252. xmj_fbgc: xmjInfo.fbgc || '',
  3253. xmj_fxgc: xmjInfo.fxgc || '',
  3254. gcl_id: posData.lid,
  3255. mx_id: posData.id,
  3256. }
  3257. if (oldCInfo) {
  3258. data.detail = oldCInfo.detail;
  3259. data.camount = oldCInfo.camount;
  3260. data.camount_expr = oldCInfo.camount_expr;
  3261. data.spamount = oldCInfo.spamount;
  3262. data.is_valuation = oldCInfo.is_valuation;
  3263. data.delimit = oldCInfo.delimit;
  3264. }
  3265. cInfo = data;
  3266. // bPaste = false;
  3267. // continue;
  3268. }
  3269. const exprQuantity = {
  3270. expr: '',
  3271. quantity: 0,
  3272. };
  3273. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  3274. if (!valid) {
  3275. toastMessageUniq(hint.expr);
  3276. bPaste = false;
  3277. continue;
  3278. }
  3279. if (isNaN(exprQuantity.quantity)) {
  3280. toastMessageUniq(hint.expr);
  3281. bPaste = false;
  3282. continue;
  3283. }
  3284. validText = parseFloat(exprQuantity.quantity);
  3285. if (cInfo.id) {
  3286. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3287. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  3288. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3289. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3290. bPaste = false;
  3291. continue;
  3292. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3293. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3294. bPaste = false;
  3295. continue;
  3296. }
  3297. }
  3298. if (bPaste) {
  3299. if (cInfo.id) {
  3300. camountData.push({id: cInfo.id, camount: ZhCalc.round(validText, findDecimal(node.unit)) || 0, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  3301. } else {
  3302. cInfo.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3303. cInfo.camount_expr = exprQuantity.expr;
  3304. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3305. insertCamountData.push(cInfo);
  3306. }
  3307. } else {
  3308. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  3309. }
  3310. continue;
  3311. }
  3312. if (colSetting.type === 'Number') {
  3313. const num = _.toNumber(posData[colSetting.field]);
  3314. if (num) {
  3315. posData[colSetting.field] = num;
  3316. } else {
  3317. try {
  3318. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  3319. const exprInfo = getExprInfo(colSetting.field);
  3320. if (exprInfo) {
  3321. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3322. }
  3323. } catch (err) {
  3324. if (!bHint) {
  3325. toastr.warning('粘贴了非法表达式,已过滤');
  3326. bHint = true;
  3327. }
  3328. bPaste = false;
  3329. }
  3330. }
  3331. } else if (colSetting.field.indexOf('_expr') > 0) {
  3332. try {
  3333. const exprInfo = getExprInfo(colSetting.field, true);
  3334. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3335. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  3336. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  3337. }
  3338. bPaste = true;
  3339. } catch (err) {
  3340. toastMessageUniq(hint.expr);
  3341. }
  3342. } else {
  3343. bPaste = true;
  3344. }
  3345. }
  3346. if (bPaste) {
  3347. data.push(posData);
  3348. }
  3349. }
  3350. if (camountData.length > 0 || insertCamountData.length > 0) {
  3351. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  3352. changeList = result;
  3353. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3354. billsTreeSpreadObj.reCalcCamount(billsNode);
  3355. const loadResult = { update: [billsNode] };
  3356. const refreshNode = billsTree.loadPostData(loadResult);
  3357. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3358. posSpreadObj.loadCurPosData();
  3359. }, function () {
  3360. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3361. return;
  3362. });
  3363. return;
  3364. }
  3365. if (data.length === 0) {
  3366. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3367. return;
  3368. }
  3369. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  3370. changeList = result.changeList;
  3371. pos.updateDatas(result.pos);
  3372. posSpreadObj.loadCurPosData();
  3373. const loadResult = result.ledger;
  3374. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3375. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3376. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3377. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3378. billsNode.is_change = 1;
  3379. } else {
  3380. billsNode.is_change = 0;
  3381. billsNode.is_valuation = 0;
  3382. billsNode.camount = null;
  3383. billsNode.ca_tp = null;
  3384. }
  3385. if (loadResult.update && loadResult.update.length > 0) {
  3386. const r = _.find(loadResult.update, { id: billsNode.id });
  3387. console.log(r, billsNode, loadResult.update);
  3388. r.is_change = billsNode.is_change;
  3389. } else {
  3390. loadResult.update = [billsNode];
  3391. }
  3392. billsTreeSpreadObj.reCalcCamount(billsNode);
  3393. const refreshNode = billsTree.loadPostData(loadResult);
  3394. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3395. posSpreadObj.loadCurPosData();
  3396. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3397. }, function () {
  3398. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3399. });
  3400. },
  3401. selectionChanged: function (e, info) {
  3402. posSpreadObj.loadExprToInput();
  3403. posSpreadObj.refreshOperationValid(posSheet);
  3404. },
  3405. addPegs: function (pegs) {
  3406. if (!pegs || pegs.length <= 0) return;
  3407. const node = SpreadJsObj.getSelectObject(billsSheet);
  3408. if (!node) return;
  3409. const sheet = posSpread.getActiveSheet();
  3410. const sortData = sheet.zh_data || [];
  3411. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3412. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  3413. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  3414. changeList = result.changeList;
  3415. pos.updateDatas(result.pos);
  3416. posSpreadObj.loadCurPosData();
  3417. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3418. });
  3419. }
  3420. };
  3421. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  3422. if (!readOnly) {
  3423. $('a[name="pos-opr"]').click(function () {
  3424. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  3425. });
  3426. $('#pos-expr').bind('change onblur', function () {
  3427. if (this.readOnly) return;
  3428. const expr = $(this);
  3429. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  3430. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  3431. if (!select) return;
  3432. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3433. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  3434. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  3435. if (field === 'camount') {
  3436. let cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  3437. if (!cInfo) {
  3438. if (posCol.readOnly.isSettle(select)) {
  3439. toastr.error('清单数据未完善,无法编辑申请数量');
  3440. SpreadJsObj.reLoadRowData(posSheet, row);
  3441. return
  3442. }
  3443. makeGclGatherData();
  3444. const gclInfo = _.find(gclGatherData, function (item) {
  3445. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  3446. });
  3447. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  3448. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  3449. const data = {
  3450. lid: select.lid,
  3451. code: gclInfo.b_code,
  3452. name: gclInfo.name || '',
  3453. unit: gclInfo.unit || '',
  3454. unit_price: gclInfo.unit_price,
  3455. oamount: xmjInfo.quantity,
  3456. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3457. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3458. xmj_code: xmjInfo.code || '',
  3459. xmj_jldy: xmjInfo.jldy || '',
  3460. xmj_dwgc: xmjInfo.dwgc || '',
  3461. xmj_fbgc: xmjInfo.fbgc || '',
  3462. xmj_fxgc: xmjInfo.fxgc || '',
  3463. gcl_id: select.lid,
  3464. mx_id: select.id,
  3465. }
  3466. if (oldCInfo) {
  3467. data.detail = oldCInfo.detail;
  3468. data.camount = oldCInfo.camount;
  3469. data.camount_expr = oldCInfo.camount_expr;
  3470. data.spamount = oldCInfo.spamount;
  3471. data.is_valuation = oldCInfo.is_valuation;
  3472. data.delimit = oldCInfo.delimit;
  3473. }
  3474. cInfo = data;
  3475. // toastr.error('未勾选变更清单,无法编辑申请数量');
  3476. // return;
  3477. }
  3478. const exprQuantity = {
  3479. expr: '',
  3480. quantity: 0,
  3481. };
  3482. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  3483. if (!valid) {
  3484. toastr.error(msg);
  3485. return;
  3486. }
  3487. if (isNaN(exprQuantity.quantity)) {
  3488. toastr.error('不能输入其它非数字类型字符');
  3489. return;
  3490. }
  3491. const camount = parseFloat(exprQuantity.quantity);
  3492. if (cInfo.id) {
  3493. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3494. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  3495. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3496. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3497. return;
  3498. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3499. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3500. return;
  3501. }
  3502. }
  3503. cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3504. cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3505. cInfo.camount_expr = exprQuantity.expr;
  3506. delete cInfo.waitingLoading;
  3507. if (cInfo.id) {
  3508. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  3509. SpreadJsObj.reLoadRowData(posSheet, row);
  3510. billsTreeSpreadObj.reCalcCamount(billsNode);
  3511. const loadResult = { update: [billsNode] };
  3512. const refreshNode = billsTree.loadPostData(loadResult);
  3513. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3514. posSpreadObj.loadExprToInput(posSheet);
  3515. }, function () {
  3516. cInfo.camount = orgValue;
  3517. cInfo.spamount = orgValue;
  3518. SpreadJsObj.reLoadRowData(posSheet, row);
  3519. });
  3520. } else {
  3521. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  3522. changeList = result.changeList;
  3523. select.is_change = 1;
  3524. select.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  3525. select.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  3526. select.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  3527. SpreadJsObj.reLoadRowData(posSheet, row);
  3528. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3529. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  3530. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  3531. billsNode.is_change = 1;
  3532. }
  3533. billsTreeSpreadObj.reCalcCamount(billsNode);
  3534. const loadResult = { update: [billsNode] };
  3535. const refreshNode = billsTree.loadPostData(loadResult);
  3536. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3537. }, function () {
  3538. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3539. });
  3540. }
  3541. return;
  3542. }
  3543. const data = {id: select.id};
  3544. const exprInfo = getExprInfo(field);
  3545. if (newValue !== '') {
  3546. const num = _.toNumber(newValue);
  3547. if (num) {
  3548. data[field] = num;
  3549. if (exprInfo) data[exprInfo.expr] = '';
  3550. } else {
  3551. try {
  3552. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  3553. if (exprInfo) data[exprInfo.expr] = newValue;
  3554. } catch (err) {
  3555. toastr.error('输入的表达式非法');
  3556. return;
  3557. }
  3558. }
  3559. } else {
  3560. data[field] = null;
  3561. if (exprInfo) data[exprInfo.expr] = '';
  3562. }
  3563. // 更新至服务器
  3564. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  3565. changeList = result.changeList;
  3566. const updateRst = pos.updateDatas(result.pos);
  3567. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  3568. SpreadJsObj.reLoadRowData(posSheet, row);
  3569. const loadResult = billsTree.loadPostData(result.ledger);
  3570. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3571. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3572. });
  3573. });
  3574. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  3575. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  3576. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  3577. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  3578. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  3579. $.contextMenu({
  3580. selector: '#pos-spread',
  3581. build: function ($trigger, e) {
  3582. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  3583. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3584. },
  3585. items: {
  3586. 'delete': {
  3587. name: '删除',
  3588. icon: 'fa-remove',
  3589. disabled: function (key, opt) {
  3590. if (posSheet.zh_data) {
  3591. const selection = posSheet.getSelections();
  3592. const sel = selection ? selection[0] : sheet.getSelections()[0];
  3593. const row = sel ? sel.row : -1;
  3594. const rowCount = sel.rowCount;
  3595. let settleFinish = false;
  3596. for (let i = row; i < row + rowCount; i++) {
  3597. if (!posSheet.zh_data[i]) continue;
  3598. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  3599. }
  3600. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  3601. } else {
  3602. return true;
  3603. }
  3604. },
  3605. callback: function (key, opt) {
  3606. posSpreadObj.deletePos(posSheet);
  3607. }
  3608. },
  3609. }
  3610. });
  3611. }
  3612. // 加载清单&计量单元数据
  3613. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  3614. let gclGatherData;
  3615. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  3616. for (const b of result.bills) {
  3617. if (!(b.is_leaf && b.b_code)) {
  3618. b.is_change = 0;
  3619. b.is_valutaion = 0;
  3620. } else {
  3621. const cInfo = _.find(changeList, { gcl_id: b.id });
  3622. b.is_change = cInfo ? 1 : 0;
  3623. b.is_valuation = cInfo ? cInfo.is_valuation : 0;
  3624. b.camount = cInfo ? cInfo.camount : 0;
  3625. }
  3626. }
  3627. billsTree.loadDatas(result.bills);
  3628. pos.loadDatas(result.pos);
  3629. treeCalc.calculateAll(billsTree);
  3630. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  3631. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  3632. checkShowLast(result.bills.length);
  3633. posSpreadObj.loadCurPosData();
  3634. SpreadJsObj.resetTopAndSelect(posSheet);
  3635. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3636. billsTreeSpreadObj.loadExprToInput(billsSheet);
  3637. checkList.loadHisCheckData();
  3638. console.log(billsTree);
  3639. }, null);
  3640. $.divResizer({
  3641. select: '#revise-resize',
  3642. callback: function () {
  3643. billsSpread.refresh();
  3644. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  3645. $(".sp-wrap").height(bcontent-30);
  3646. posSpread.refresh();
  3647. }
  3648. });
  3649. function makeGclGatherData() {
  3650. gclGatherModel.loadLedgerData(billsTree.datas);
  3651. gclGatherModel.loadPosData(pos.datas);
  3652. gclGatherData = gclGatherModel.gatherGclData();
  3653. gclGatherData = _.filter(gclGatherData, function (item) {
  3654. return item.leafXmjs && item.leafXmjs.length !== 0;
  3655. });
  3656. gclGatherData = gclGatherData.sort(sortByCode);
  3657. }
  3658. class DealBills {
  3659. constructor (selector, spreadSetting) {
  3660. const self = this;
  3661. this.loaded = false;
  3662. this.obj = $(selector)[0];
  3663. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3664. this.spreadSetting = spreadSetting;
  3665. this.spread = SpreadJsObj.createNewSpread(this.obj);
  3666. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3667. if (!readOnly) {
  3668. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3669. const dealSheet = info.sheet;
  3670. const mainSheet = billsSheet;
  3671. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3672. if (!dealBills) { return; }
  3673. const mainTree = mainSheet.zh_tree;
  3674. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3675. if (!mainNode || !mainTree) { return; }
  3676. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3677. toastr.warning('非最底层项目下,不应添加节点');
  3678. return;
  3679. }
  3680. if (mainNode.settle_status === settleStatus.finish) {
  3681. toastr.warning('已结算节点下,不应添加签约清单');
  3682. return;
  3683. }
  3684. postData(window.location.pathname + '/update', {
  3685. postType: 'add-deal',
  3686. postData: {
  3687. id: mainNode.ledger_id,
  3688. type: mainNode.code ? 'child' : 'next',
  3689. dealBills: {
  3690. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3691. unit_price: dealBills.unit_price,
  3692. }
  3693. },
  3694. }, function (result) {
  3695. changeList = result.changeList;
  3696. const refreshData = mainTree.loadPostData(result);
  3697. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3698. const sel = mainSheet.getSelections()[0];
  3699. if (sel && refreshData.create[0]) {
  3700. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3701. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3702. }
  3703. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3704. billsSpread.focus();
  3705. posSpreadObj.loadCurPosData();
  3706. });
  3707. });
  3708. }
  3709. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3710. }
  3711. loadData (callback) {
  3712. if (this.loaded) {
  3713. if (callback) callback();
  3714. return;
  3715. }
  3716. const self = this;
  3717. postData(this.url+'/get-data', {}, function (data) {
  3718. self.data = data;
  3719. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3720. self.loaded = true;
  3721. if (callback) callback();
  3722. });
  3723. }
  3724. calculateData () {
  3725. if (this.data) {
  3726. for (const d of this.data) {
  3727. d.total_price = _.multiply(d.quantity, d.unit_price);
  3728. }
  3729. }
  3730. }
  3731. }
  3732. class BatchInsertBillsPosObj {
  3733. constructor (obj) {
  3734. const self = this;
  3735. this.obj = obj;
  3736. this.billsCount = 6;
  3737. this.posCount = 1000;
  3738. this.filter = getLocalCache('zh-calc-batch-filter');
  3739. if (!this.filter) {
  3740. this.filter = '1';
  3741. }
  3742. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3743. // 初始化 清单编号窗口 参数
  3744. this.qdSpreadSetting = {
  3745. cols: [
  3746. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3747. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3748. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3749. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3750. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3751. ],
  3752. emptyRows: this.billsCount,
  3753. headRows: 1,
  3754. headRowHeight: [32],
  3755. headerFont: '12px 微软雅黑',
  3756. font: '12px 微软雅黑',
  3757. };
  3758. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3759. // 初始化 部位数量复核表 参数
  3760. this.posSpreadSetting = {
  3761. cols: [
  3762. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3763. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3764. ],
  3765. emptyRows: this.posCount,
  3766. headRows: 1,
  3767. headRowHeight: [32],
  3768. headerFont: '12px 微软雅黑',
  3769. font: '12px 微软雅黑',
  3770. };
  3771. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3772. this.posSpreadSetting.cols.push(
  3773. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3774. )
  3775. }
  3776. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3777. // 初始化 签约节点 参数
  3778. this.dealSpreadSetting = {
  3779. cols: [
  3780. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3781. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3782. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3783. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3784. ],
  3785. emptyRows: 0,
  3786. headRows: 1,
  3787. headRowHeight: [32],
  3788. headerFont: '12px 微软雅黑',
  3789. font: '12px 微软雅黑',
  3790. };
  3791. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3792. // 初始化 清单编号、部位数量复核表 表格
  3793. this.initView();
  3794. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3795. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3796. // 拉取签约节点数据
  3797. dealBills.loadData(() => {
  3798. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3799. });
  3800. // 双击签约节点,自动添加到清单编号窗口
  3801. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  3802. const deal = info.sheet.zh_data[info.row];
  3803. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3804. const sel = qdSheet.getSelections()[0];
  3805. qdSheet.getCell(sel.row, 0).value(deal.code);
  3806. qdSheet.getCell(sel.row, 1).value(deal.name);
  3807. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3808. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3809. if (sel.row + 1 === qdSheet.getRowCount()) {
  3810. const count = sel.row + 2;
  3811. qdSheet.setRowCount(count);
  3812. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3813. const colCount = posSheet.getColumnCount() + 1;
  3814. posSheet.setColumnCount(colCount);
  3815. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3816. }
  3817. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3818. qdSheet.getParent().focus();
  3819. });
  3820. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3821. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  3822. const count = posSheet.getColumnCount() - 2;
  3823. if (billsCount > count) {
  3824. posSheet.setColumnCount(billsCount + 2);
  3825. for (let i = count + 1; i <= billsCount; i++) {
  3826. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3827. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3828. }
  3829. }
  3830. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  3831. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3832. if (dealBills && dealBills.length > 0) {
  3833. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3834. const curRow = iRow + info.cellRange.row;
  3835. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  3836. if (bills) {
  3837. info.sheet.getCell(curRow, 1).value(bills.name);
  3838. info.sheet.getCell(curRow, 2).value(bills.unit);
  3839. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  3840. }
  3841. }
  3842. }
  3843. }
  3844. });
  3845. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3846. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3847. const count = qdSheet.getRowCount();
  3848. if (billsCount > count) {
  3849. qdSheet.setRowCount(billsCount);
  3850. for (let i = count + 1; i <= billsCount; i++) {
  3851. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3852. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3853. }
  3854. }
  3855. });
  3856. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3857. if (info.col === 0) {
  3858. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3859. if (dealBills && dealBills.length > 0) {
  3860. const bills = _.find(dealBills, {code: info.editingText});
  3861. if (bills) {
  3862. info.sheet.getCell(info.row, 1).value(bills.name);
  3863. info.sheet.getCell(info.row, 2).value(bills.unit);
  3864. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3865. }
  3866. }
  3867. }
  3868. });
  3869. this.obj.bind('shown.bs.modal', function () {
  3870. self.qdSpread.refresh();
  3871. self.posSpread.refresh();
  3872. self.dealSpread.refresh();
  3873. });
  3874. $('#batch-ok').click(function () {
  3875. const selection = billsSheet.getSelections();
  3876. const sel = selection[0];
  3877. const row = selection[0].row;
  3878. const select = billsTree.nodes[row];
  3879. if (select) {
  3880. const insertData = {};
  3881. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3882. insertData.id = select[billsTree.setting.id];
  3883. insertData.batchData = self.getBatchData();
  3884. if (insertData.batchData.length > 0) {
  3885. postData(window.location.pathname + '/update', {
  3886. postType: 'batch-insert',
  3887. postData: insertData
  3888. }, function (data) {
  3889. changeList = result.changeList;
  3890. pos.updateDatas(data.pos);
  3891. const result = billsTree.loadPostData(data.ledger);
  3892. billsTreeSpreadObj.refreshTree(billsSheet, result);
  3893. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3894. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  3895. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  3896. posSpreadObj.loadCurPosData();
  3897. self.obj.modal('hide');
  3898. }, null, true);
  3899. } else {
  3900. self.obj.modal('hide');
  3901. }
  3902. }
  3903. });
  3904. $('input[name=batch-filter]').change(function () {
  3905. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3906. });
  3907. $.contextMenu({
  3908. selector: '.batch-l-t',
  3909. build: function ($trigger, e) {
  3910. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3911. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3912. },
  3913. items: {
  3914. 'create': {
  3915. name: '新增行',
  3916. icon: 'fa-sign-in',
  3917. callback: function (key, opt) {
  3918. const qdSheet = self.qdSpread.getActiveSheet();
  3919. const posSheet = self.posSpread.getActiveSheet();
  3920. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3921. const index = qdSheet.getRowCount();
  3922. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3923. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3924. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3925. },
  3926. },
  3927. 'delete': {
  3928. name: '删除行',
  3929. icon: 'fa-remove',
  3930. callback: function (key, opt) {
  3931. const qdSheet = self.qdSpread.getActiveSheet();
  3932. const posSheet = self.posSpread.getActiveSheet();
  3933. const sel = qdSheet.getSelections()[0];
  3934. qdSheet.deleteRows(sel.row, sel.rowCount);
  3935. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3936. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3937. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3938. }
  3939. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3940. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3941. }
  3942. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3943. },
  3944. },
  3945. }
  3946. });
  3947. }
  3948. // 初始化左侧表格
  3949. initView () {
  3950. // 初始化 清单编号
  3951. const qdSheet = this.qdSpread.getActiveSheet();
  3952. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3953. SpreadJsObj.refreshColumnAlign(qdSheet);
  3954. // 清理原有数据
  3955. SpreadJsObj.beginMassOperation(qdSheet);
  3956. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3957. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3958. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3959. }
  3960. qdSheet.setSelection(0, 0, 1 ,1);
  3961. SpreadJsObj.endMassOperation(qdSheet);
  3962. // 初始化 部位数量复核表
  3963. const posSheet = this.posSpread.getActiveSheet();
  3964. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3965. SpreadJsObj.refreshColumnAlign(posSheet);
  3966. // 清理原有数据
  3967. SpreadJsObj.beginMassOperation(posSheet);
  3968. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3969. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3970. posSheet.setSelection(0, 0, 1 ,1);
  3971. SpreadJsObj.endMassOperation(posSheet);
  3972. // 检查签约节点数据,以工具栏数据为准
  3973. if (dealBills) {
  3974. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3975. }
  3976. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3977. }
  3978. // 获取界面数据
  3979. getBatchData () {
  3980. const result = [];
  3981. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3982. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3983. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3984. const qd = {
  3985. b_code: qdSheet.getText(iRow, 0),
  3986. name: qdSheet.getText(iRow, 1),
  3987. unit: qdSheet.getText(iRow, 2),
  3988. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3989. pos: [],
  3990. };
  3991. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3992. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3993. if (value !== 0 && !isNaN(value)) {
  3994. qd.pos.push({
  3995. name: posSheet.getText(iPosRow, 0),
  3996. drawing_code: posSheet.getText(iPosRow, 1),
  3997. quantity: value, porder: qd.pos.length + 1,
  3998. });
  3999. }
  4000. }
  4001. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  4002. }
  4003. return result;
  4004. }
  4005. }
  4006. const dealBills = new DealBills('#deal-bills-spread', {
  4007. cols: [
  4008. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  4009. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4010. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  4011. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  4012. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  4013. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  4014. ],
  4015. emptyRows: 0,
  4016. headRows: 1,
  4017. headRowHeight: [32],
  4018. headColWidth: [30],
  4019. defaultRowHeight: 21,
  4020. headerFont: '12px 微软雅黑',
  4021. font: '12px 微软雅黑',
  4022. selectedBackColor: '#fffacd',
  4023. });
  4024. class Jlzf {
  4025. constructor (selector, spreadSetting) {
  4026. const self = this;
  4027. this.loaded = false;
  4028. this.obj = $(selector);
  4029. const relaSelect = {
  4030. showLevel: `cb-${spreadSetting.stdType}-sl`,
  4031. searchText: `cb-${spreadSetting.stdType}-st`,
  4032. searchResult: `cb-${spreadSetting.stdType}-sr`,
  4033. searchPre: `cb-${spreadSetting.stdType}-sp`,
  4034. searchNext: `cb-${spreadSetting.stdType}-sn`,
  4035. searchClose: `cb-${spreadSetting.stdType}-sc`,
  4036. };
  4037. this.obj.html(
  4038. '<div class="sjs-bar d-flex">\n' +
  4039. ' <div class="ml-1">\n' +
  4040. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  4041. ' <div class="d-inline-block">\n' +
  4042. ' <div class="input-group input-group-sm mr-1">' +
  4043. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  4044. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  4045. ' <div class="input-group-append" >\n' +
  4046. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  4047. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  4048. ' </div>\n' +
  4049. ' </div>\n' +
  4050. ' </div>\n' +
  4051. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  4052. ' </div>\n' +
  4053. ' </div>' +
  4054. '</div>\n' +
  4055. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  4056. );
  4057. autoFlashHeight();
  4058. const sh = `.cb-${spreadSetting.stdType}-sh`;
  4059. function getObjHeight(select) {
  4060. return select.length > 0 ? select.height() : 0;
  4061. }
  4062. const cHeader = getObjHeight($(".c-header"));
  4063. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  4064. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  4065. this.spreadSetting = spreadSetting;
  4066. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  4067. const searchSheet = this.spread.getActiveSheet();
  4068. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  4069. if (!readOnly) {
  4070. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  4071. const dealSheet = info.sheet;
  4072. const mainSheet = billsSheet;
  4073. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  4074. if (!dealBills) { return; }
  4075. const mainTree = mainSheet.zh_tree;
  4076. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  4077. if (!mainNode || !mainTree) { return; }
  4078. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4079. toastr.warning('非最底层项目下,不应添加节点');
  4080. return;
  4081. }
  4082. if (mainNode.settle_status === settleStatus.finish) {
  4083. toastr.warning('已结算节点下,不应添加签约清单');
  4084. return;
  4085. }
  4086. postData(window.location.pathname + '/update', {
  4087. postType: 'add-deal',
  4088. postData: {
  4089. id: mainNode.ledger_id,
  4090. type: mainNode.code ? 'child' : 'next',
  4091. dealBills: {
  4092. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  4093. unit_price: dealBills.unit_price,
  4094. }
  4095. },
  4096. }, function (result) {
  4097. changeList = result.changeList;
  4098. const refreshData = mainTree.loadPostData(result);
  4099. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  4100. const sel = mainSheet.getSelections()[0];
  4101. if (sel && refreshData.create[0]) {
  4102. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  4103. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  4104. }
  4105. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4106. billsSpread.focus();
  4107. posSpreadObj.loadCurPosData();
  4108. });
  4109. });
  4110. }
  4111. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  4112. const searchObj = {
  4113. result: [],
  4114. cur: 0,
  4115. searchStdNode: function() {
  4116. const keyword = $(`#${relaSelect.searchText}`).val();
  4117. const sortData = SpreadJsObj.getSortData(searchSheet);
  4118. searchObj.result = keyword ? sortData.filter(x => {
  4119. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4120. }) : [];
  4121. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4122. searchObj.cur = 0;
  4123. if (searchObj.result.length > 0) {
  4124. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4125. }
  4126. },
  4127. searchPre: function () {
  4128. if (searchObj.result.length === 0) return;
  4129. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4130. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4131. },
  4132. searchNext: function () {
  4133. if (searchObj.result.length === 0) return;
  4134. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4135. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  4136. },
  4137. clear: function () {
  4138. $(`#${relaSelect.searchText}`).val('');
  4139. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4140. searchObj.result = [];
  4141. searchObj.cur = 0;
  4142. }
  4143. };
  4144. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4145. $(`#${relaSelect.searchPre}`).click(function (e) {
  4146. searchObj.searchPre();
  4147. e.stopPropagation();
  4148. });
  4149. $(`#${relaSelect.searchNext}`).click(function (e) {
  4150. searchObj.searchNext();
  4151. e.stopPropagation();
  4152. });
  4153. $(`#${relaSelect.searchClose}`).click(function (e) {
  4154. searchObj.clear();
  4155. e.stopPropagation();
  4156. });
  4157. };
  4158. loadData (callback) {
  4159. // if (this.loaded) {
  4160. // if (callback) callback();
  4161. // return;
  4162. // }
  4163. const self = this;
  4164. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  4165. const showDatas = [];
  4166. for (const d of datas) {
  4167. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  4168. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  4169. }
  4170. }
  4171. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  4172. // self.loaded = true;
  4173. if (callback) callback();
  4174. }
  4175. }
  4176. const jlzfBills = new Jlzf('#jlzf-spread', {
  4177. cols: [
  4178. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  4179. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  4180. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4181. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4182. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4183. ],
  4184. emptyRows: 0,
  4185. headRows: 1,
  4186. headRowHeight: [32],
  4187. headColWidth: [30],
  4188. defaultRowHeight: 21,
  4189. headerFont: '12px 微软雅黑',
  4190. font: '12px 微软雅黑',
  4191. selectedBackColor: '#fffacd',
  4192. readOnly: true,
  4193. stdType: 'jlzf',
  4194. });
  4195. class Dsk {
  4196. constructor (selector, spreadSetting) {
  4197. const self = this;
  4198. this.loaded = false;
  4199. this.obj = $(selector);
  4200. const dskProjectHtml = spreadSetting.libs.map(l => {
  4201. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  4202. });
  4203. const relaSelect = {
  4204. showLevel: `cb-${spreadSetting.stdType}-sl`,
  4205. searchText: `cb-${spreadSetting.stdType}-st`,
  4206. searchResult: `cb-${spreadSetting.stdType}-sr`,
  4207. searchPre: `cb-${spreadSetting.stdType}-sp`,
  4208. searchNext: `cb-${spreadSetting.stdType}-sn`,
  4209. searchClose: `cb-${spreadSetting.stdType}-sc`,
  4210. };
  4211. this.obj.html(
  4212. '<div class="sjs-bar d-flex">\n' +
  4213. ' <div class="dropdown mr-1">\n' +
  4214. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  4215. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  4216. ' </button>\n' +
  4217. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  4218. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  4219. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  4220. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  4221. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  4222. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  4223. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  4224. ' </div>\n' +
  4225. ' </div>' +
  4226. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  4227. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  4228. ' <div class="ml-1">\n' +
  4229. ' <div class="dropdown">\n' +
  4230. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  4231. ' <i class="fa fa-search"></i>\n' +
  4232. ' </button>\n' +
  4233. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  4234. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  4235. ' <div class="d-inline-block">\n' +
  4236. ' <div class="input-group input-group-sm mr-1">' +
  4237. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  4238. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  4239. ' <div class="input-group-append" >\n' +
  4240. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  4241. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  4242. ' </div>\n' +
  4243. ' </div>\n' +
  4244. ' </div>\n' +
  4245. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  4246. ' </div>\n' +
  4247. ' </div>\n' +
  4248. ' </div>\n' +
  4249. ' </div>' +
  4250. '</div>\n' +
  4251. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  4252. );
  4253. autoFlashHeight();
  4254. const sh = `.cb-${spreadSetting.stdType}-sh`;
  4255. function getObjHeight(select) {
  4256. return select.length > 0 ? select.height() : 0;
  4257. }
  4258. const cHeader = getObjHeight($(".c-header"));
  4259. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  4260. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  4261. this.spreadSetting = spreadSetting;
  4262. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  4263. const searchSheet = this.spread.getActiveSheet();
  4264. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  4265. (function (select, sheet) {
  4266. $(select).click(function () {
  4267. if (!sheet.zh_tree) return;
  4268. const tag = $(this).attr('tag');
  4269. const tree = sheet.zh_tree;
  4270. setTimeout(() => {
  4271. switch (tag) {
  4272. case "1":
  4273. case "2":
  4274. case "3":
  4275. case "4":
  4276. case "5":
  4277. tree.expandByLevel(parseInt(tag));
  4278. SpreadJsObj.refreshTreeRowVisible(sheet);
  4279. break;
  4280. case "last":
  4281. tree.expandByCustom(() => { return true; });
  4282. SpreadJsObj.refreshTreeRowVisible(sheet);
  4283. break;
  4284. }
  4285. }, 100);
  4286. });
  4287. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  4288. if (!readOnly) {
  4289. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  4290. const dealSheet = info.sheet;
  4291. const mainSheet = billsSheet;
  4292. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  4293. if (!dealBills) { return; }
  4294. const mainTree = mainSheet.zh_tree;
  4295. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  4296. if (!mainNode || !mainTree) { return; }
  4297. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4298. toastr.warning('非最底层项目下,不应添加节点');
  4299. return;
  4300. }
  4301. if (mainNode.settle_status === settleStatus.finish) {
  4302. toastr.warning('已结算节点下,不应添加签约清单');
  4303. return;
  4304. }
  4305. const is_bill = dealBills.kind === 4;
  4306. // 判断dealBills.code以-开头,是则向上判断是否需要拼接code名称
  4307. function makeCode(dealBills) {
  4308. const originalCode = dealBills.code;
  4309. if (!originalCode || originalCode.charAt(0) !== '-') {
  4310. return originalCode;
  4311. }
  4312. const parents = dealSheet.zh_tree.getAllParents(dealBills);
  4313. if (!parents || parents.length === 0) {
  4314. return originalCode;
  4315. }
  4316. const kind4Parents = _.filter(parents, { kind: 4 });
  4317. if (!kind4Parents || kind4Parents.length === 0) {
  4318. return originalCode;
  4319. }
  4320. const firstParentCode = kind4Parents[0].code;
  4321. if (firstParentCode.charAt(0) === '-') {
  4322. return originalCode;
  4323. }
  4324. const codeParts = [];
  4325. for (const parent of kind4Parents.reverse()) {
  4326. codeParts.push(parent.code);
  4327. if (parent.code.charAt(0) !== '-') {
  4328. break;
  4329. }
  4330. }
  4331. if (codeParts.length > 0) {
  4332. return codeParts.reverse().join('') + originalCode;
  4333. }
  4334. return originalCode;
  4335. }
  4336. const oneBills = {
  4337. b_code: is_bill ? makeCode(dealBills) : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  4338. unit_price: is_bill ? dealBills.unitPrice : null, quantity: null, total_price: null,
  4339. sgfh_qty: null, sgfh_tp: null,
  4340. };
  4341. postData(window.location.pathname + '/update', {
  4342. postType: 'add-deal',
  4343. postData: {
  4344. id: mainNode.ledger_id,
  4345. type: mainNode.code ? 'child' : 'next',
  4346. dealBills: oneBills,
  4347. },
  4348. }, function (result) {
  4349. changeList = result.changeList;
  4350. const refreshData = mainTree.loadPostData(result);
  4351. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  4352. const sel = mainSheet.getSelections()[0];
  4353. if (sel && refreshData.create[0]) {
  4354. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  4355. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  4356. }
  4357. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4358. billsSpread.focus();
  4359. posSpreadObj.loadCurPosData();
  4360. });
  4361. });
  4362. }
  4363. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  4364. const searchObj = {
  4365. result: [],
  4366. cur: 0,
  4367. searchStdNode: function() {
  4368. const keyword = $(`#${relaSelect.searchText}`).val();
  4369. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  4370. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4371. }) : [];
  4372. // searchObj.result = [];
  4373. // for (const x of pathTree.nodes) {
  4374. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  4375. // searchObj.result.push(x);
  4376. // }
  4377. // }
  4378. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4379. searchObj.cur = 0;
  4380. if (searchObj.result.length > 0) {
  4381. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  4382. }
  4383. },
  4384. searchPre: function () {
  4385. if (searchObj.result.length === 0) return;
  4386. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4387. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4388. },
  4389. searchNext: function () {
  4390. if (searchObj.result.length === 0) return;
  4391. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4392. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4393. },
  4394. clear: function () {
  4395. $(`#${relaSelect.searchText}`).val('');
  4396. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4397. searchObj.result = [];
  4398. searchObj.cur = 0;
  4399. }
  4400. };
  4401. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4402. $(`#${relaSelect.searchPre}`).click(function (e) {
  4403. searchObj.searchPre();
  4404. e.stopPropagation();
  4405. });
  4406. $(`#${relaSelect.searchNext}`).click(function (e) {
  4407. searchObj.searchNext();
  4408. e.stopPropagation();
  4409. });
  4410. $(`#${relaSelect.searchClose}`).click(function (e) {
  4411. searchObj.clear();
  4412. e.stopPropagation();
  4413. });
  4414. };
  4415. loadData (callback) {
  4416. if (this.loaded) {
  4417. if (callback) callback();
  4418. return;
  4419. }
  4420. const self = this;
  4421. if (dskAccountData && dskAccountData.select_project) {
  4422. self.loaded = true;
  4423. changeDskProject(dskAccountData.select_project);
  4424. } else {
  4425. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  4426. self.loaded = true;
  4427. }
  4428. if (callback) callback();
  4429. }
  4430. }
  4431. $('body').on('change', '#change-dsk-project', function () {
  4432. const pid = $(this).val();
  4433. changeDskProject(pid);
  4434. });
  4435. $('body').on('change', '#change-dsk-project-tree', function () {
  4436. const treeId = $(this).val();
  4437. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  4438. changeDskProjectTree(projectInfo, treeId);
  4439. });
  4440. function setDskProjectTreeSelect(trees) {
  4441. let html = '';
  4442. for (const tree of trees) {
  4443. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  4444. }
  4445. $('#change-dsk-project-tree').html(html);
  4446. }
  4447. function changeDskProject(pid) {
  4448. const projectInfo = _.find(dskProjects, { pid });
  4449. if (!projectInfo) {
  4450. dskAccountData.select_project = null;
  4451. dskAccountData.select_tree = null;
  4452. const tree = dskProjectBills2Tree.convert([]);
  4453. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4454. return;
  4455. }
  4456. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  4457. const trees = _.filter(datas, x => x.type === 4);
  4458. dskAccountData.select_project = projectInfo.pid;
  4459. setDskProjectTreeSelect(trees);
  4460. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  4461. });
  4462. }
  4463. function changeDskProjectTree(projectInfo, treeId) {
  4464. dskAccountData.select_tree = treeId;
  4465. if (!treeId) {
  4466. const tree = dskProjectBills2Tree.convert([]);
  4467. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4468. return;
  4469. }
  4470. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  4471. const tree = dskProjectBills2Tree.convert(result);
  4472. console.log(tree);
  4473. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4474. });
  4475. }
  4476. const dskBills = new Dsk('#dsk-spread', {
  4477. cols: [
  4478. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  4479. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4480. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4481. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  4482. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  4483. ],
  4484. emptyRows: 0,
  4485. headRows: 1,
  4486. headRowHeight: [32],
  4487. headColWidth: [30],
  4488. defaultRowHeight: 21,
  4489. headerFont: '12px 微软雅黑',
  4490. font: '12px 微软雅黑',
  4491. selectedBackColor: '#fffacd',
  4492. readOnly: true,
  4493. stdType: 'dsk',
  4494. libs: dskProjects,
  4495. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  4496. });
  4497. const dskProjectBills2Tree = (function () {
  4498. const treeSetting = {
  4499. id: 'dpb_id',
  4500. pid: 'dpb_pid',
  4501. order: 'seq',
  4502. level: 'level',
  4503. rootId: '-1',
  4504. fullPath: 'full_path',
  4505. };
  4506. const tenderTree = createNewPathTree('gather', treeSetting);
  4507. function setChildrenNode(node, dxs, files, tenders) {
  4508. const dxchildren = _.filter(dxs, { parentID: node.bid });
  4509. const children = _.filter(files, { parentID: node.bid });
  4510. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  4511. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  4512. for (const t of checkChildren) {
  4513. const child = {
  4514. bid: t.ID,
  4515. parentID: t.parentID,
  4516. name: t.name,
  4517. kind: t.kind,
  4518. code: t.code,
  4519. quantity: t.quantity,
  4520. quantity2: t.quantity2,
  4521. unit: t.unit,
  4522. unitPrice: t.unitPrice,
  4523. totalPrice: t.totalPrice,
  4524. formulaCode: t.formulaCode,
  4525. flag: t.flag,
  4526. remark: t.remark,
  4527. };
  4528. tenderTree.addNode(child, node);
  4529. setChildrenNode(child, dxs, files, tenders);
  4530. }
  4531. }
  4532. function convert (projects) {
  4533. tenderTree.clearDatas();
  4534. // 区分文件夹及项目
  4535. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  4536. const dxs = _.filter(projects, { kind: 1 });
  4537. const files = _.filter(projects, { kind: 4 });
  4538. const tenders = _.filter(projects, { kind: 8 });
  4539. for (const t of topLevel) {
  4540. const node = {
  4541. bid: t.ID,
  4542. parentID: t.parentID,
  4543. name: t.name,
  4544. kind: t.kind,
  4545. code: t.code,
  4546. quantity: t.quantity,
  4547. quantity2: t.quantity2,
  4548. unit: t.unit,
  4549. unitPrice: t.unitPrice,
  4550. totalPrice: t.totalPrice,
  4551. formulaCode: t.formulaCode,
  4552. flag: t.flag,
  4553. remark: t.remark,
  4554. };
  4555. tenderTree.addNode(node, null);
  4556. setChildrenNode(node, dxs, files, tenders);
  4557. }
  4558. tenderTree.sortTreeNode(true);
  4559. return tenderTree;
  4560. }
  4561. return { tenderTree, convert }
  4562. })();
  4563. $.divResizer({
  4564. select: '#revise-right-spr',
  4565. callback: function () {
  4566. billsSpread.refresh();
  4567. if (posSpread) posSpread.refresh();
  4568. if (stdXmj) stdXmj.spread.refresh();
  4569. if (stdGcl) stdGcl.spread.refresh();
  4570. if (dealBills) dealBills.spread.refresh();
  4571. if (searchLedger) searchLedger.spread.refresh();
  4572. if (errorList) errorList.spread.refresh();
  4573. if (checkList) checkList.spread.refresh();
  4574. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4575. if (jlzfBills) jlzfBills.spread.refresh();
  4576. if (dskBills) dskBills.spread.refresh();
  4577. }
  4578. });
  4579. $.subMenu({
  4580. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  4581. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  4582. key: 'menu.1.0.0',
  4583. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  4584. callback: function (info) {
  4585. if (info.mini) {
  4586. $('.panel-title').addClass('fluid');
  4587. $('#sub-menu').removeClass('panel-sidebar');
  4588. } else {
  4589. $('.panel-title').removeClass('fluid');
  4590. $('#sub-menu').addClass('panel-sidebar');
  4591. }
  4592. autoFlashHeight();
  4593. billsSpread.refresh();
  4594. if (posSpread) posSpread.refresh();
  4595. if (stdXmj) stdXmj.spread.refresh();
  4596. if (stdGcl) stdGcl.spread.refresh();
  4597. if (dealBills) dealBills.spread.refresh();
  4598. if (searchLedger) searchLedger.spread.refresh();
  4599. if (errorList) errorList.spread.refresh();
  4600. if (checkList) checkList.spread.refresh();
  4601. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4602. if (jlzfBills) jlzfBills.spread.refresh();
  4603. if (dskBills) dskBills.spread.refresh();
  4604. }
  4605. });
  4606. // showSideTools(true);
  4607. billsSpread.refresh();
  4608. if (posSpread) posSpread.refresh();
  4609. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  4610. const mainSheet = billsSheet;
  4611. if (!stdTree || !mainSheet.zh_tree) { return; }
  4612. const mainTree = mainSheet.zh_tree;
  4613. const sel = mainSheet.getSelections()[0];
  4614. const mainNode = mainTree.nodes[sel.row];
  4615. if (!stdNode) return;
  4616. if (updateData.postData.stdType === 'gcl') {
  4617. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4618. toastr.warning('非最底层项目下,不应添加节点');
  4619. return;
  4620. }
  4621. if (mainNode.settle_status === settleStatus.finish) {
  4622. toastr.warning('已结算节点下,不可添加工程量清单');
  4623. return;
  4624. }
  4625. } else {
  4626. const stdNodes = stdTree.getAllParents(stdNode);
  4627. for (const node of stdNodes) {
  4628. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  4629. if (parent && parent.settle_status === settleStatus.finish) {
  4630. toastr.warning('项目节父项已结算,不可添加节点');
  4631. return;
  4632. }
  4633. }
  4634. }
  4635. postData(window.location.pathname + '/update', {
  4636. postType: 'add-std',
  4637. postData: {
  4638. id: mainTree.getNodeKey(mainNode),
  4639. tender_id: mainNode.tender_id,
  4640. stdType: updateData.postData.stdType,
  4641. stdLibId: stdNode.list_id,
  4642. stdNode: stdTree.getNodeKey(stdNode)
  4643. }
  4644. }, function (result) {
  4645. changeList = result.changeList;
  4646. const refreshNode = mainTree.loadPostData(result);
  4647. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  4648. if (sel) {
  4649. if (refreshNode.create && refreshNode.create.length > 0) {
  4650. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  4651. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  4652. } else {
  4653. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  4654. if (node) {
  4655. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  4656. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  4657. }
  4658. }
  4659. }
  4660. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4661. billsSpread.focus();
  4662. posSpreadObj.loadCurPosData();
  4663. });
  4664. };
  4665. const stdXmjSetting = {
  4666. selector: '#std-xmj',
  4667. stdType: 'xmj',
  4668. libs: stdChapters,
  4669. treeSetting: {
  4670. id: 'chapter_id',
  4671. pid: 'pid',
  4672. order: 'order',
  4673. level: 'level',
  4674. rootId: -1,
  4675. keys: ['id', 'list_id', 'chapter_id'],
  4676. },
  4677. spreadSetting: {
  4678. cols: [
  4679. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4680. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4681. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4682. ],
  4683. treeCol: 0,
  4684. emptyRows: 0,
  4685. headRows: 1,
  4686. headRowHeight: [32],
  4687. defaultRowHeight: 21,
  4688. headerFont: '12px 微软雅黑',
  4689. font: '12px 微软雅黑',
  4690. headColWidth: [30],
  4691. selectedBackColor: '#fffacd',
  4692. },
  4693. cellDoubleClick: stdLibCellDoubleClick,
  4694. page: 'revise',
  4695. tid: window.location.pathname.split('/')[2],
  4696. };
  4697. const stdGclSetting = {
  4698. selector: '#std-gcl',
  4699. stdType: 'gcl',
  4700. libs: stdBills,
  4701. treeSetting: {
  4702. id: 'bill_id',
  4703. pid: 'pid',
  4704. order: 'order',
  4705. level: 'level',
  4706. rootId: -1,
  4707. keys: ['id', 'list_id', 'bill_id']
  4708. },
  4709. spreadSetting: {
  4710. cols: [
  4711. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4712. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4713. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4714. ],
  4715. treeCol: 0,
  4716. emptyRows: 0,
  4717. headRows: 1,
  4718. headRowHeight: [32],
  4719. defaultRowHeight: 21,
  4720. headerFont: '12px 微软雅黑',
  4721. font: '12px 微软雅黑',
  4722. headColWidth: [30],
  4723. selectedBackColor: '#fffacd',
  4724. },
  4725. cellDoubleClick: stdLibCellDoubleClick,
  4726. page: 'revise',
  4727. tid: window.location.pathname.split('/')[2],
  4728. };
  4729. // 展开收起标准节点
  4730. $('a', '#side-menu').bind('click', function (e) {
  4731. e.preventDefault();
  4732. const tab = $(this), tabPanel = $(tab.attr('content'));
  4733. // 展开工具栏、切换标签
  4734. if (!tab.hasClass('active')) {
  4735. const close = $('.active', '#side-menu').length === 0;
  4736. $('a', '#side-menu').removeClass('active');
  4737. tab.addClass('active');
  4738. $('.tab-content .tab-pane').removeClass('active');
  4739. tabPanel.addClass('active');
  4740. showSideTools(tab.hasClass('active'));
  4741. if (tab.attr('content') === '#std-xmj') {
  4742. if (!stdXmj) {
  4743. stdXmj = $.stdLib(stdXmjSetting);
  4744. }
  4745. stdXmj.spread.refresh();
  4746. } else if (tab.attr('content') === '#std-gcl') {
  4747. if (!stdGcl) {
  4748. stdGcl = $.stdLib(stdGclSetting);
  4749. }
  4750. stdGcl.spread.refresh();
  4751. } else if (tab.attr('content') === '#deal-bills') {
  4752. dealBills.loadData();
  4753. dealBills.spread.refresh();
  4754. } else if (tab.attr('content') === '#search') {
  4755. if (!searchLedger) {
  4756. searchLedger = $.ledgerSearch({
  4757. selector: '#search',
  4758. ledger: { billsTree: billsTree, pos: pos },
  4759. searchOver: true,
  4760. searchEmpty: true,
  4761. resultSpreadSetting: {
  4762. cols: [
  4763. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4764. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4765. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4766. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4767. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4768. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4769. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4770. ],
  4771. emptyRows: 0,
  4772. headRows: 1,
  4773. headRowHeight: [32],
  4774. headColWidth: [30],
  4775. defaultRowHeight: 21,
  4776. headerFont: '12px 微软雅黑',
  4777. font: '12px 微软雅黑',
  4778. selectedBackColor: '#fffacd',
  4779. readOnly: true,
  4780. },
  4781. locate: function(cur) {
  4782. if (!cur.lid) return;
  4783. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  4784. posSpreadObj.loadCurPosData();
  4785. if (cur.pid && cur.pid !== -1) {
  4786. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4787. SpreadJsObj.locateRow(posSheet, pIndex);
  4788. }
  4789. },
  4790. customSearch: [
  4791. {
  4792. key: 'revise', title: '新增部位', valid: true, parent: true,
  4793. check: function (node) {
  4794. if (node.formc || node.cid) {
  4795. return true;
  4796. } else {
  4797. return false;
  4798. }
  4799. }
  4800. }
  4801. ],
  4802. });
  4803. }
  4804. searchLedger.spread.refresh();
  4805. } else if (tab.attr('content') === '#error-list') {
  4806. errorList.spread.refresh();
  4807. } else if (tab.attr('content') === '#check-list') {
  4808. checkList.spread.refresh();
  4809. } else if (tab.attr('content') === '#sum-load-miss') {
  4810. sumLoadMiss.spread.refresh();
  4811. } else if (tab.attr('content') === '#dsk-list') {
  4812. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  4813. $(dskActiveTab).addClass('active');
  4814. if (dskActiveTab === '#jlzf-spread') {
  4815. $('#get-dsk-btn').hide();
  4816. $('#get-dsk-bills-btn').hide();
  4817. jlzfBills.loadData();
  4818. jlzfBills.spread.refresh();
  4819. } else if (dskActiveTab === '#dsk-spread') {
  4820. $('#get-dsk-btn').show();
  4821. $('#get-dsk-bills-btn').show();
  4822. dskBills.loadData();
  4823. dskBills.spread.refresh();
  4824. }
  4825. }
  4826. }
  4827. else {// 收起工具栏
  4828. tab.removeClass('active');
  4829. tabPanel.removeClass('active');
  4830. showSideTools(tab.hasClass('active'));
  4831. }
  4832. billsSpread.refresh();
  4833. if (posSpread) posSpread.refresh();
  4834. });
  4835. // 新增清单切换tab
  4836. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  4837. e.preventDefault();
  4838. const dskActiveTab = $(this).attr('href');
  4839. if (dskActiveTab === '#jlzf-spread') {
  4840. $('#get-dsk-btn').hide();
  4841. $('#get-dsk-bills-btn').hide();
  4842. jlzfBills.loadData();
  4843. jlzfBills.spread.refresh();
  4844. } else if (dskActiveTab === '#dsk-spread') {
  4845. $('#get-dsk-btn').show();
  4846. $('#get-dsk-bills-btn').show();
  4847. dskBills.loadData();
  4848. dskBills.spread.refresh();
  4849. }
  4850. });
  4851. // 显示层次
  4852. (function (select, sheet) {
  4853. $(select).click(function () {
  4854. if (!sheet.zh_tree) return;
  4855. const tag = $(this).attr('tag');
  4856. const tree = sheet.zh_tree;
  4857. setTimeout(() => {
  4858. showWaitingView();
  4859. switch (tag) {
  4860. case "1":
  4861. case "2":
  4862. case "3":
  4863. case "4":
  4864. case "5":
  4865. tree.expandByLevel(parseInt(tag));
  4866. SpreadJsObj.refreshTreeRowVisible(sheet);
  4867. break;
  4868. case "last":
  4869. tree.expandByCustom(() => { return true; });
  4870. SpreadJsObj.refreshTreeRowVisible(sheet);
  4871. break;
  4872. case "leafXmj":
  4873. tree.expandToLeafXmj();
  4874. SpreadJsObj.refreshTreeRowVisible(sheet);
  4875. break;
  4876. }
  4877. closeWaitingView();
  4878. }, 100);
  4879. });
  4880. })('a[name=showLevel]', billsSheet);
  4881. const dataChecker = DataChecker({
  4882. checkUrl: window.location.pathname + '/check',
  4883. completeData: function (data) {
  4884. pos.updateDatas({update: data.source.pos});
  4885. const loadResult = billsTree.loadPostData({update: data.source.bills});
  4886. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  4887. posSpreadObj.loadCurPosData();
  4888. for (const e of data.error) {
  4889. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  4890. }
  4891. },
  4892. errorList: errorList,
  4893. });
  4894. $('#ledger-check2').click(() => {
  4895. ledgerCheck2({
  4896. ledgerTree: billsTree,
  4897. ledgerPos: pos,
  4898. checkList: checkList,
  4899. decimal: decimal,
  4900. checkOption: checkOption,
  4901. }).then(result => {
  4902. check2Viewing({
  4903. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  4904. randomWait: true,
  4905. prefix: 'check2-',
  4906. checks: result,
  4907. checkList: checkList,
  4908. });
  4909. });
  4910. });
  4911. if (isYb) {
  4912. let compilationList = [];
  4913. $('#get-dsk-btn').click(function () {
  4914. // 判断是否已绑定dsk用户
  4915. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  4916. if (result === 1) {
  4917. $('#error-dsk .modal-body').find('h5').eq(0).show();
  4918. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  4919. $('#error-dsk').modal('show');
  4920. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  4921. } else if (result === 2) {
  4922. $('#error-dsk .modal-body').find('h5').eq(1).show();
  4923. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  4924. $('#error-dsk').modal('show');
  4925. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  4926. } else {
  4927. postData('/profile/dsk/api', {
  4928. type: 'compilation',
  4929. getProject: 1,
  4930. compilationId: getLocalCache(dskCompilation)
  4931. }, function (result) {
  4932. let html = '';
  4933. for (const data of result.compilation) {
  4934. if (data.ID !== '5c66649650da2d000d8d37ba' && data.ID !== '5b52b027fd3bb0000b257cf8') {
  4935. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  4936. }
  4937. }
  4938. dskAccountData = result.dskAccountData;
  4939. compilationList = result.compilation;
  4940. console.log(compilationList);
  4941. $('#dsk-compilation-list').html(html);
  4942. $('#add-dsk').modal('show');
  4943. setLocalCache(dskCompilation, result.select_compilation);
  4944. makeDskProjectSjsHtml(result.project);
  4945. });
  4946. }
  4947. })
  4948. });
  4949. $('#get-dsk-bills-btn').click(function () {
  4950. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  4951. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  4952. });
  4953. $('body').on('change', '#dsk-compilation-list', function () {
  4954. const compilationId = $(this).val();
  4955. setLocalCache(dskCompilation, compilationId);
  4956. dskProjectSpreadObj.refreshSourceTree();
  4957. });
  4958. $('.hide-dsk-modal').click(function () {
  4959. $('#error-dsk').modal('hide');
  4960. });
  4961. let dp = false;
  4962. let gsObj = {
  4963. setting: null,
  4964. gsSheet: null,
  4965. grSheet: null,
  4966. tenderSourceTree: null,
  4967. grArray: dskProjects ? dskProjects : [],
  4968. orgSelect: null,
  4969. };
  4970. function makeDskProjectSjsHtml(datas) {
  4971. if (!dp) {
  4972. initDskProjectTree();
  4973. dp = true;
  4974. }
  4975. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  4976. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  4977. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  4978. if (datas.length === 0) {
  4979. $('#show-project-0').show();
  4980. } else {
  4981. $('#show-project-0').hide();
  4982. }
  4983. }
  4984. const dskProjectSpreadObj = {
  4985. _addTender: function (tender) {
  4986. const gr = gsObj.grArray.find(function (x) {
  4987. return x.pid === tender.pid;
  4988. });
  4989. const c_id = getLocalCache(dskCompilation);
  4990. const t = {
  4991. pid: tender.pid,
  4992. name: tender.name,
  4993. compilationId: c_id,
  4994. compilationName: _.find(compilationList, {ID: c_id}).name
  4995. };
  4996. if (!gr) gsObj.grArray.push(t);
  4997. return t;
  4998. },
  4999. _removeTender: function (tender) {
  5000. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  5001. return x.pid === tender.pid;
  5002. });
  5003. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  5004. },
  5005. reloadResultData: function () {
  5006. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  5007. },
  5008. refreshSourceTree: function () {
  5009. const c_id = getLocalCache(dskCompilation);
  5010. if (c_id) {
  5011. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  5012. makeDskProjectSjsHtml(result);
  5013. });
  5014. }
  5015. },
  5016. gsButtonClicked: function (e, info) {
  5017. if (!info.sheet.zh_setting) return;
  5018. const col = info.sheet.zh_setting.cols[info.col];
  5019. if (col.field !== 'selected') return;
  5020. const node = SpreadJsObj.getSelectObject(info.sheet);
  5021. node.selected = !node.selected;
  5022. if (node.children && node.children.length > 0) {
  5023. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  5024. for (const p of posterity) {
  5025. p.selected = node.selected;
  5026. if ((!p.children || p.children.length === 0) && p.type === 2) {
  5027. if (p.selected) {
  5028. dskProjectSpreadObj._addTender(p);
  5029. } else {
  5030. dskProjectSpreadObj._removeTender(p);
  5031. }
  5032. }
  5033. }
  5034. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  5035. } else if (node.type === 2) {
  5036. if (node.selected) {
  5037. dskProjectSpreadObj._addTender(node);
  5038. } else {
  5039. dskProjectSpreadObj._removeTender(node);
  5040. }
  5041. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  5042. }
  5043. dskProjectSpreadObj.reloadResultData();
  5044. },
  5045. deleteGr: function () {
  5046. if (gsObj.grArray.length === 0) return;
  5047. if (gsObj.grSheet.getSelections().length === 0) return;
  5048. const selections = gsObj.grSheet.getSelections();
  5049. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  5050. const row = sel && sel.row !== undefined ? sel.row : -1;
  5051. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  5052. return false;
  5053. }
  5054. const delList = [];
  5055. for (let r = 0; r < sel.rowCount; r++) {
  5056. const select = gsObj.grArray[row + r];
  5057. delList.push(select);
  5058. }
  5059. _.pullAll(gsObj.grArray, delList);
  5060. dskProjectSpreadObj.reloadResultData();
  5061. dskProjectSpreadObj.refreshSourceTree();
  5062. },
  5063. };
  5064. const initDskProjectTree = function () {
  5065. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  5066. gsObj.gsSheet = gsSpread.getActiveSheet();
  5067. const gsSpreadSetting = {
  5068. cols: [
  5069. {
  5070. title: '选择',
  5071. field: 'selected',
  5072. hAlign: 1,
  5073. width: 40,
  5074. formatter: '@',
  5075. cellType: 'checkbox',
  5076. readOnly: true,
  5077. },
  5078. {
  5079. title: '名称',
  5080. field: 'name',
  5081. hAlign: 0,
  5082. width: 400,
  5083. formatter: '@',
  5084. readOnly: true,
  5085. folderCell: true,
  5086. cellType: 'tree'
  5087. },
  5088. ],
  5089. emptyRows: 0,
  5090. headRows: 1,
  5091. headRowHeight: [32],
  5092. defaultRowHeight: 21,
  5093. headerFont: '12px 微软雅黑',
  5094. font: '12px 微软雅黑',
  5095. headColWidth: [0],
  5096. selectedBackColor: '#fffacd',
  5097. };
  5098. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  5099. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  5100. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  5101. gsObj.grSheet = grSpread.getActiveSheet();
  5102. const grSpreadSetting = {
  5103. cols: [
  5104. {
  5105. title: '名称',
  5106. colSpan: '1',
  5107. rowSpan: '1',
  5108. field: 'name',
  5109. hAlign: 0,
  5110. width: 250,
  5111. formatter: '@',
  5112. readOnly: true,
  5113. cellType: 'ellipsisAutoTip',
  5114. scrollHeightClass: '.modal-height-500'
  5115. },
  5116. {
  5117. title: '所属编办',
  5118. colSpan: '1',
  5119. rowSpan: '1',
  5120. field: 'compilationName',
  5121. hAlign: 0,
  5122. width: 150,
  5123. formatter: '@',
  5124. readOnly: true
  5125. },
  5126. ],
  5127. emptyRows: 0,
  5128. headRows: 1,
  5129. headRowHeight: [32],
  5130. defaultRowHeight: 21,
  5131. headerFont: '12px 微软雅黑',
  5132. font: '12px 微软雅黑',
  5133. headColWidth: []
  5134. };
  5135. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  5136. // 右键删除已选项目
  5137. const gsContextMenuOptions = {
  5138. selector: '#dsk-project-result-spread',
  5139. build: function ($trigger, e) {
  5140. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  5141. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  5142. },
  5143. items: {
  5144. delete: {
  5145. name: '删除',
  5146. icon: 'fa-remove',
  5147. callback: function (key, opt) {
  5148. dskProjectSpreadObj.deleteGr();
  5149. },
  5150. disabled: function (key, opt) {
  5151. const selection = gsObj.grSheet.getSelections();
  5152. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  5153. const row = sel && sel.row !== undefined ? sel.row : -1;
  5154. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  5155. return true;
  5156. }
  5157. return false;
  5158. }
  5159. },
  5160. }
  5161. };
  5162. $.contextMenu(gsContextMenuOptions);
  5163. $('#add-dsk').bind('shown.bs.modal', function () {
  5164. if (gsSpread) gsSpread.refresh();
  5165. if (grSpread) grSpread.refresh();
  5166. });
  5167. };
  5168. const dskProject2Tree = (function () {
  5169. const treeSetting = {
  5170. id: 'tmt_id',
  5171. pid: 'tmt_pid',
  5172. order: 'seq',
  5173. level: 'level',
  5174. rootId: '-1',
  5175. fullPath: 'full_path',
  5176. };
  5177. const tenderTree = createNewPathTree('gather', treeSetting);
  5178. function setChildrenNode(node, files, tenders) {
  5179. const children = _.filter(files, {parentID: node.pid});
  5180. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  5181. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  5182. for (const c of checkChildren) {
  5183. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  5184. // // 判断文件夹下有无东西,没有就不插入
  5185. // continue;
  5186. // }
  5187. const child = {
  5188. pid: c.ID,
  5189. parentID: c.parentID,
  5190. name: c.name,
  5191. type: c.type,
  5192. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  5193. };
  5194. tenderTree.addNode(child, node);
  5195. if (c.type === 1) setChildrenNode(child, files, tenders);
  5196. }
  5197. }
  5198. function convert(projects) {
  5199. tenderTree.clearDatas();
  5200. const result = filterFolders(projects);
  5201. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  5202. const files = _.filter(result, {type: 1});
  5203. const tenders = _.filter(result, {type: 2});
  5204. for (const t of topLevel) {
  5205. const node = {
  5206. pid: t.ID,
  5207. parentID: t.parentID,
  5208. name: t.name,
  5209. type: t.type,
  5210. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  5211. };
  5212. tenderTree.addNode(node, null);
  5213. if (t.type === 1) setChildrenNode(node, files, tenders);
  5214. }
  5215. tenderTree.sortTreeNode(true);
  5216. return tenderTree;
  5217. }
  5218. return {tenderTree, convert}
  5219. })();
  5220. function filterFolders(data) {
  5221. // 构建ID到节点的映射
  5222. const idMap = data.reduce((map, node) => {
  5223. map[node.ID] = node;
  5224. return map;
  5225. }, {});
  5226. // 建立父子关系映射
  5227. const parentMap = data.reduce((map, node) => {
  5228. if (node.parentID !== '-1') {
  5229. if (!map[node.parentID]) {
  5230. map[node.parentID] = [];
  5231. }
  5232. map[node.parentID].push(node.ID);
  5233. }
  5234. return map;
  5235. }, {});
  5236. // 检查节点及其子节点是否包含清单(type=1)
  5237. const hasChecklist = (id) => {
  5238. const node = idMap[id];
  5239. if (node.type === 2) {
  5240. return true;
  5241. }
  5242. if (!parentMap[id]) {
  5243. return false;
  5244. }
  5245. return parentMap[id].some(childID => hasChecklist(childID));
  5246. };
  5247. // 过滤节点
  5248. const filteredIDs = new Set();
  5249. data.forEach(node => {
  5250. if (node.type === 2 || hasChecklist(node.ID)) {
  5251. let currentID = node.ID;
  5252. while (currentID !== '-1') {
  5253. filteredIDs.add(currentID);
  5254. currentID = idMap[currentID].parentID;
  5255. }
  5256. }
  5257. });
  5258. // 返回过滤后的数据
  5259. return data.filter(node => filteredIDs.has(node.ID));
  5260. }
  5261. $('#set-dsk-project').click(function () {
  5262. postData('/profile/dsk/api', {
  5263. type: 'save_projects',
  5264. tid: window.location.pathname.split('/')[2],
  5265. project_list: gsObj.grArray
  5266. }, function (result) {
  5267. // dskAccountData.select_project = result;
  5268. dskProjects = gsObj.grArray;
  5269. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  5270. dskAccountData.select_project = result;
  5271. changeDskProject(result);
  5272. dskBills.spread.refresh();
  5273. }
  5274. setDskProjectSelect(gsObj.grArray);
  5275. $('#add-dsk').modal('hide');
  5276. });
  5277. });
  5278. $('#add-dsk').on('hide.bs.modal', function () {
  5279. $('#autoTip').hide();
  5280. });
  5281. function setDskProjectSelect(projects) {
  5282. let html = '';
  5283. for (const project of projects) {
  5284. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  5285. }
  5286. $('#change-dsk-project').html(html);
  5287. }
  5288. // 选中所有新增部位/清单
  5289. $('#add-all-revise').click(function() {
  5290. const this_cid = window.location.pathname.split('/')[4];
  5291. makeGclGatherData();
  5292. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5293. type: 'get-revise-list',
  5294. }, function (result) {
  5295. const addDatas = [];
  5296. for (const ggd in gclGatherData) {
  5297. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  5298. let hadcid = 0;
  5299. for (const xmj of gclGatherData[ggd].leafXmjs) {
  5300. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  5301. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  5302. if (changeLedger || changePos) {
  5303. xmj.cid = 1;
  5304. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  5305. hadcid = 1;
  5306. }
  5307. }
  5308. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  5309. }
  5310. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  5311. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  5312. if (leafXmjs.length > 0) {
  5313. gclInfo.is_change = 1;
  5314. for (const xmj of leafXmjs) {
  5315. if (_.findIndex(changeList, function (item) {
  5316. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  5317. }) === -1) {
  5318. addDatas.push({
  5319. lid: xmj.gcl_id,
  5320. code: gclInfo.code,
  5321. name: gclInfo.name || '',
  5322. unit: gclInfo.unit || '',
  5323. unit_price: gclInfo.unit_price,
  5324. oamount: xmj.quantity,
  5325. oamount2: xmj.quantity,
  5326. bwmx: xmj.bwmx || xmj.jldy || '',
  5327. xmj_code: xmj.code || '',
  5328. xmj_jldy: xmj.jldy || '',
  5329. xmj_dwgc: xmj.dwgc || '',
  5330. xmj_fbgc: xmj.fbgc || '',
  5331. xmj_fxgc: xmj.fxgc || '',
  5332. gcl_id: xmj.gcl_id,
  5333. mx_id: xmj.mx_id || '',
  5334. });
  5335. }
  5336. }
  5337. }
  5338. }
  5339. console.log(addDatas);
  5340. if (addDatas.length > 0) {
  5341. // 更新至服务器
  5342. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5343. type: 'add-change-list',
  5344. postData: addDatas,
  5345. }, function (result) {
  5346. toastr.success('已新增当前变更令新增的所有部位/清单');
  5347. changeList = result.changeList;
  5348. const sortData = SpreadJsObj.getSortData(billsSheet);
  5349. const billsNodes = _.filter(sortData, function (item) {
  5350. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  5351. });
  5352. for (const billsNode of billsNodes) {
  5353. billsNode.is_change = 1;
  5354. }
  5355. const loadResult = { update: billsNodes };
  5356. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  5357. posSpreadObj.loadCurPosData();
  5358. });
  5359. } else {
  5360. toastr.warning('未存在当前变更令新增的部位/清单');
  5361. }
  5362. });
  5363. });
  5364. }
  5365. });
  5366. function findDecimal(unit) {
  5367. let value = precision.other.value;
  5368. const changeUnits = precision;
  5369. for (const d in changeUnits) {
  5370. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  5371. value = changeUnits[d].value;
  5372. break;
  5373. }
  5374. }
  5375. return value;
  5376. }
  5377. // 编号排序,多重判断
  5378. function sortByCode(a, b, code = 'b_code') {
  5379. let code1 = a[code].split('-');
  5380. let code2 = b[code].split('-');
  5381. let code1length = code1.length;
  5382. let code2length = code2.length;
  5383. for (let i = 0; i < code1length; i ++) {
  5384. if (i+1 <= code2length) {
  5385. if (code1[i] != code2[i]) {
  5386. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  5387. return parseInt(code1[i]) - parseInt(code2[i]);
  5388. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  5389. return 1;
  5390. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  5391. return -1;
  5392. } else {
  5393. const str1length = code1[i].length;
  5394. const str2length = code2[i].length;
  5395. for (let j = 0; j < str1length; j++) {
  5396. if (j+1 <= str2length) {
  5397. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  5398. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  5399. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  5400. if (str1length == str2length) {
  5401. return 0;
  5402. } else {
  5403. return str1length - str2length;
  5404. }
  5405. }
  5406. } else {
  5407. if (j+1 >= str1length) {
  5408. return 1;
  5409. } else {
  5410. return -1;
  5411. }
  5412. }
  5413. }
  5414. }
  5415. } else if (i+1 == code1length && code1[i] == code2[i]) {
  5416. if (code1length == code2length) {
  5417. return 0;
  5418. } else {
  5419. return code1length - code2length;
  5420. }
  5421. }
  5422. } else {
  5423. if (i+1 >= code1length) {
  5424. return 1;
  5425. } else {
  5426. return -1;
  5427. }
  5428. }
  5429. }
  5430. }