change_revise.js 250 KB

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