ledger.js 218 KB

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