ledger.js 215 KB

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