ledger.js 244 KB

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