ledger.js 239 KB

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