ledger.js 235 KB

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