change_revise.js 279 KB

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