ledger.js 238 KB

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