ledger.js 240 KB

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