ledger.js 241 KB

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