ledger.js 241 KB

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