ledger.js 218 KB

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