ledger.js 239 KB

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