ledger.js 243 KB

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