stage.js 291 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  15. }
  16. function getExprInfo (field, converse = false) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. if (converse) return _.find(exprField, { expr: field });
  24. return _.find(exprField, {qty: field});
  25. }
  26. /**
  27. * 从cookie中读取缓存的列显示设置,没有则取默认
  28. * @returns {*[]}
  29. */
  30. function customColDisplay () {
  31. const defaultSetting = [
  32. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  33. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl', 'qc_minus_qty'], visible: true },
  34. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  35. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  36. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl', 'end_qc_minus_qty'], visible: true },
  37. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent', 'end_final_1_precent'], visible: true },
  38. { title: '本期批注', fields: ['postil'], visible: true },
  39. { title: '图册号', fields: ['drawing_code'], visible: true },
  40. { title: '备注', fields: ['memo'], visible: true },
  41. { title: '总额计量', fields: ['is_tp'], visible: true},
  42. ];
  43. if (!checkTzMeasureType()) {
  44. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  45. }
  46. const settingStr = Cookies.get(ckColSetting);
  47. if (settingStr) {
  48. const customSetting = JSON.parse(settingStr);
  49. for (const ds of defaultSetting) {
  50. const cs = customSetting.find(x => {return x.title === ds.title});
  51. if (cs) ds.visible = cs.visible;
  52. }
  53. }
  54. return defaultSetting;
  55. }
  56. /**
  57. * 根据列显示设置,调整setting中的列是否显示
  58. * @param setting
  59. * @param customDisplay
  60. */
  61. function customizeStageTreeSetting(setting, customDisplay) {
  62. for (const cd of customDisplay) {
  63. for (const c of setting.cols) {
  64. if (cd.fields.indexOf(c.field) !== -1) {
  65. c.visible = c.defaultVisible === undefined ? cd.visible : c.defaultVisible && cd.visible;
  66. }
  67. }
  68. }
  69. }
  70. /**
  71. * 初始化 树结构 列事件
  72. * @param setting
  73. */
  74. function initTreeColSettingEvents(setting) {
  75. const Events = {
  76. readOnly: {
  77. measureData: function (node) {
  78. return node.children && node.children.length > 0;
  79. },
  80. },
  81. };
  82. const getEvent = function (eventName) {
  83. const names = eventName.split('.');
  84. let event = Events;
  85. for (let name of names) {
  86. if (event[name]) {
  87. event = event[name];
  88. } else {
  89. return null;
  90. }
  91. }
  92. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  93. return null;
  94. } else {
  95. return event;
  96. }
  97. };
  98. for (const col of setting.cols) {
  99. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  100. col.readOnly = getEvent(col.readOnly);
  101. }
  102. }
  103. }
  104. // 生成所有附件列表
  105. function getAllList(currPageNum = 1) {
  106. // 每页最多几个附件
  107. const pageCount = 20;
  108. // 附件总数
  109. const total = attData.length;
  110. // 总页数
  111. const pageNum = Math.ceil(total/pageCount);
  112. $('#totalPage').text(pageNum);
  113. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  114. // 当前页附件内容
  115. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  116. currPageFileData = currPageAttData;
  117. let html = '';
  118. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  119. for(const att of currPageAttData) {
  120. const delHtml = deleteFilePermission && parseInt(cur_uid) === att.uid
  121. ? `<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>`
  122. : '';
  123. html += `<tr>
  124. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  125. <td>
  126. <div class="d-flex">
  127. <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  128. <div class="att-file-btn col-2"><a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="pl-0"><i class="fa fa-download"></i></a>${delHtml}</div>
  129. </div>
  130. </td><td>${att.username}</td></tr>`
  131. }
  132. $('#alllist-table').html(html);
  133. $('#alllist-table').on('click', 'tr', function() {
  134. $('#alllist-table tr').removeClass('bg-light')
  135. $(this).addClass('bg-light')
  136. });
  137. }
  138. // 生成当前节点列表
  139. function getNodeList(node) {
  140. let html = '';
  141. for(const att of attData) {
  142. if (node === att.lid) {
  143. const delHtml = deleteFilePermission && parseInt(cur_uid) === att.uid
  144. ? `<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>`
  145. : '';
  146. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  147. html += `<tr>
  148. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  149. <td>
  150. <div class="d-flex">
  151. <a href="javascript:void(0)" class="pl-0 col-10 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  152. <div class="att-file-btn col-2"><a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="pl-0"><i class="fa fa-download"></i></a>${delHtml}</div>
  153. </div>
  154. </td><td>${att.username}</td></tr>`
  155. }
  156. }
  157. $('#nodelist-table').html(html);
  158. $('#nodelist-table').on('click', 'tr', function() {
  159. $('#nodelist-table tr').removeClass('bg-light');
  160. $(this).addClass('bg-light');
  161. })
  162. }
  163. function getGxbyText(data) {
  164. const def = thirdParty.gxby.find(function (x) {
  165. return x.value === data.gxby_status;
  166. });
  167. return def ? def.name : '';
  168. }
  169. function getDaglText(data) {
  170. const def = thirdParty.dagl.find(function (x) {
  171. return x.value === data.dagl_status;
  172. });
  173. return def ? def.name : '';
  174. }
  175. function getWbsText(data) {
  176. return '';
  177. }
  178. function getHintMsg () {
  179. return {
  180. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  181. disableChange: {type: 'error', msg: '不可修改此数据'},
  182. }
  183. }
  184. let ledgerData, posData = '';
  185. $(document).ready(() => {
  186. const completePerField = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  187. const exportExcelSetting = {
  188. cols: [
  189. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  190. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  191. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  192. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  193. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  194. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  196. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  197. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  198. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  199. {title: '本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  200. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  201. {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 60, type: 'Number'},
  202. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  203. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  204. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  205. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  206. {title: '截止本期数量变更|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  207. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  208. {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'end_qc_minus_qty', hAlign: 2, width: 60, type: 'Number'},
  209. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  210. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  211. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_final_1_percent', hAlign: 2, width: 80, type: 'Number'},
  212. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  213. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  214. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  215. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  216. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  217. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  218. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  219. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  220. {title: '位置', colSpan: '1', rowSpan: '2', field: 'position', hAlign: 0, width: 80, formatter: '@'},
  221. ],
  222. headRows: 2,
  223. headRowHeight: [25, 25],
  224. defaultRowHeight: 21,
  225. headerFont: 'bold 10px 微软雅黑',
  226. font: '10px 微软雅黑'
  227. };
  228. let detail, searchLedger, checkedChanges;
  229. const tpCalcFields = [{qty: 'qc_qty', tp: 'qc_tp'}];
  230. if (tenderInfo.calc_type === 'up' && !correctCalcContractTp) tpCalcFields.unshift({qty: 'contract_qty', tp: 'contract_tp'});
  231. const checkOption = {
  232. sibling: { enable: 0 },
  233. empty_code: { enable: 0 },
  234. calc: {
  235. enable: 1,
  236. fields: ['contract_qty', 'qc_qty', 'qc_minus_qty'],
  237. },
  238. zero: { enable: 0 },
  239. tp: {
  240. enable: 1,
  241. fields: tpCalcFields,
  242. filter: function (node) {
  243. return node.is_tp;
  244. }
  245. },
  246. over: { enable: 1, isTz: checkTzMeasureType(), checkInfo: tenderInfo.checkOverInfo },
  247. limit3f: { enable: 1, checkType: [], status: thirdParty, },
  248. minus_cb: { enable: hintMinusCb },
  249. change_detail: { enable: is_debug },
  250. // change_over: { enable: 1 },
  251. };
  252. if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
  253. if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
  254. if (tender.s2b_multi_check) checkOption.multiLimit3f = { enable: 1, limits };
  255. // 界面布局
  256. autoFlashHeight();
  257. let featureDisplay;
  258. const changeFeaturesDisplay = function (show, init = false) {
  259. $('#features-show').html(show ? '<i class="fa fa-eye-slash"></i> 隐藏特征' : '<i class="fa fa-eye"></i> 显示特征');
  260. const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
  261. if (!featureCols) return;
  262. featureCols.visible = show ? true : false;
  263. if (!init) {
  264. featureDisplay = show;
  265. setLocalCache(featureShowCache, show ? 1 : 0);
  266. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet(), 1);
  267. }
  268. };
  269. const reloadFeaturesDisplayCache = function () {
  270. const featureCols = ledgerSpreadSetting.cols.find(x => { return x.field === 'features'; });
  271. if (featureCols) {
  272. $('#features-show').show();
  273. featureDisplay = getLocalCache(featureShowCache);
  274. featureDisplay = featureDisplay ? parseInt(featureDisplay) : 1;
  275. changeFeaturesDisplay(featureDisplay, true);
  276. } else {
  277. $('#features-show').hide();
  278. }
  279. };
  280. reloadFeaturesDisplayCache();
  281. $('#features-show').click(function() {
  282. changeFeaturesDisplay(!featureDisplay);
  283. });
  284. // 初始化 台账树结构 数据结构
  285. removeLocalCache('bills-fold');
  286. const stageTreeSetting = {
  287. id: 'ledger_id',
  288. pid: 'ledger_pid',
  289. order: 'order',
  290. level: 'level',
  291. rootId: -1,
  292. keys: ['id', 'tender_id', 'ledger_id'],
  293. stageId: 'id',
  294. autoExpand: 3,
  295. // markFoldKey: 'bills-fold',
  296. // markFoldSubKey: window.location.pathname.split('/')[2],
  297. markExpandKey: 'stage-bills-expand',
  298. markExpandSubKey: window.location.pathname.split('/')[2],
  299. };
  300. // 台账树结构计算相关设置
  301. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'qc_minus_qty', 'postil', 'used', 'contract_expr', 'ex_stage_qty1', 'ex_stage_tp1'];
  302. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp', 'contract_pc_tp', 'qc_pc_tp', 'pc_tp',
  303. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp',
  304. 'final_1_tp', 'end_final_1_tp', 'due_qc_tp', 'due_final_tp', 'ex_tp1', 'ex_stage_tp1', 'end_ex_stage_tp1', 'tz2_tp', 'tz_qc_tp', 'tz_qc_minus_tp'];
  305. stageTreeSetting.calcFun = function (node) {
  306. if (!node.children || node.children.length === 0) {
  307. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  308. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  309. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  310. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  311. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  312. node.end_qc_minus_qty = ZhCalc.add(node.pre_qc_minus_qty, node.qc_minus_qty);
  313. node.final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.quantity);
  314. node.final_1_tp = ZhCalc.mul(node.final_1_qty, node.unit_price, tenderInfo.decimal.tp);
  315. node.deal_final_1_qty = ZhCalc.add(node.end_qc_minus_qty, node.deal_qty);
  316. node.end_final_1_qty = ZhCalc.add(node.end_qc_qty, node.final_1_qty);
  317. node.due_final_qty = ZhCalc.add(node.quantity, node.due_qc_qty);
  318. node.end_ex_stage_qty1 = ZhCalc.add(node.ex_stage_qty1, node.pre_ex_stage_qty1);
  319. node.tz2_qty = ZhCalc.sum([node.quantity, node.tz_qc_qty, node.tz_qc_minus_qty]);
  320. }
  321. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  322. node.gather_tp = ZhCalc.sum([node.contract_tp, node.qc_tp, node.pc_tp]);
  323. node.end_contract_tp = ZhCalc.sum([node.pre_contract_tp, node.contract_tp, node.contract_pc_tp]);
  324. node.end_qc_tp = ZhCalc.sum([node.pre_qc_tp, node.qc_tp, node.qc_pc_tp]);
  325. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  326. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  327. node.end_final_1_tp = ZhCalc.add(node.end_qc_tp, node.final_1_tp);
  328. node.due_final_tp = ZhCalc.add(node.total_price, node.due_qc_tp);
  329. node.end_ex_stage_tp1 = ZhCalc.add(node.ex_stage_tp1, node.pre_ex_stage_tp1);
  330. if (!node.children || node.children.length === 0) {
  331. if (node.end_contract_qty) {
  332. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  333. } else {
  334. node.end_correct_tp = node.end_gather_tp;
  335. }
  336. }
  337. if (tenderInfo.calc_type === 'tp') {
  338. node.tz2_tp = ZhCalc.sum([node.total_price, node.tz_qc_tp]);
  339. } else if (tenderInfo.calc_type === 'up') {
  340. node.tz2_tp = ZhCalc.sum([node.total_price, node.tz_qc_tp, node.tz_qc_minus_tp]);
  341. }
  342. // node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  343. // node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  344. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  345. // node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_1_tp), 100, 2);
  346. // node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_1_tp), 100, 2);
  347. // Task #5256要求修改
  348. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.tz2_tp), 100, 2);
  349. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.tz2_tp), 100, 2);
  350. node.end_final_1_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.tz2_tp), 100, 2);
  351. node.end_correct_1_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.tz2_tp), 100, 2);
  352. };
  353. const stageTree = createNewPathTree('stage', stageTreeSetting);
  354. // 初始化 计量单元 数据结构
  355. const stagePosSetting = {
  356. id: 'id', ledgerId: 'lid',
  357. updateFields: ['contract_qty', 'qc_qty', 'qc_minus_qty', 'postil', 'contract_expr', 'ex_stage_qty1'],
  358. };
  359. stagePosSetting.calcFun = function (pos) {
  360. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  361. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  362. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  363. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  364. pos.end_qc_minus_qty = ZhCalc.add(pos.pre_qc_minus_qty, pos.qc_minus_qty);
  365. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  366. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  367. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  368. pos.end_contract_percent = ZhCalc.mul(ZhCalc.div(pos.end_contract_qty, pos.quantity), 100, 2);
  369. pos.estimate_qty = !checkZero(pos.real_qty)
  370. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  371. : null;
  372. pos.final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.quantity);
  373. pos.deal_final_1_qty = ZhCalc.add(pos.end_qc_minus_qty, pos.deal_qty);
  374. pos.end_final_1_qty = ZhCalc.add(pos.end_qc_qty, pos.final_1_qty);
  375. pos.end_ex_stage_qty1 = ZhCalc.add(pos.pre_ex_stage_qty1, pos.ex_stage_qty1);
  376. pos.due_final_qty = ZhCalc.add(pos.quantity, pos.due_qc_qty);
  377. pos.tz2_qty = ZhCalc.sum([pos.quantity, pos.tz_qc_qty, pos.tz_qc_minus_qty]);
  378. };
  379. const stagePos = new StagePosData(stagePosSetting);
  380. function checkUsed(tree, pos, node) {
  381. if (node.children && node.children.length > 0) {
  382. const posterity = tree.getPosterity(node);
  383. for (const p of posterity) {
  384. if (p.children && p.children.length > 0) continue;
  385. if (!checkZero(p.contract_qty) || !checkZero(p.contract_tp) ||
  386. !checkZero(p.qc_qty) || !checkZero(p.qc_tp) || !checkZero(p.qc_minus_qty))
  387. return true;
  388. const pPos = pos.getLedgerPos(p.id);
  389. if (!pPos || pPos.length === 0) continue;
  390. for (const pp of pPos) {
  391. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  392. }
  393. }
  394. return false;
  395. } else {
  396. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) ||
  397. !checkZero(node.qc_qty) || !checkZero(node.qc_tp) || !checkZero(node.qc_minus_qty))
  398. return true;
  399. const pPos = pos.getLedgerPos(node.id);
  400. if (!pPos || pPos.length === 0) return false;
  401. for (const pp of pPos) {
  402. if (!checkZero(pp.contract_qty) || !checkZero(pp.qc_qty) || !checkZero(pp.qc_minus_qty)) return true;
  403. }
  404. }
  405. };
  406. class Changes {
  407. constructor(obj) {
  408. const self = this;
  409. this.obj = obj;
  410. // 初始化 清单编号窗口 参数
  411. this.spreadSetting = {
  412. cols: [
  413. {title: '已用', field: 'select', width: 45, formatter: '@', cellType: 'checkbox', hAlign: 1, indent: 14, getValue: function (data) {return data.uamount && !checkZero(data.uamount);}},
  414. {title: '变更令号', field: 'p_code', width: 100, formatter: '@', readOnly: true, hAlign: 0, },
  415. {title: '名称', field: 'name', width: 120, formatter: '@', readOnly: true, hAlign: 0,},
  416. {title: '变更部位', field: 'b_bwmx', width: 100, formatter: '@', readOnly: true, hAlign: 0,},
  417. {title: '批复数量', field: 'b_amount', width: 60, readOnly: true, hAlign: 2, },
  418. {title: '可变更数量', field: 'vamount', width: 60, readOnly: true, hAlign: 2, type: 'Number', getValue: function (data) {return data.vamount ? data.vamount + '' : '0';}},
  419. {title: '本期计量', field: 'uamount', width: 60, hAlign: 2, type: 'Number', },
  420. ],
  421. emptyRows: 0,
  422. headRows: 1,
  423. headRowHeight: [32],
  424. headerFont: '12px 微软雅黑',
  425. font: '12px 微软雅黑',
  426. getColor: function (sheet, data, row, col, defaultColor) {
  427. if (col.field === 'uamount') {
  428. if (data.bamount > 0) {
  429. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  430. return usedAmount < 0 || usedAmount > data.limitAmount ? spreadColor.stage.over : defaultColor;
  431. } else if (data.bamount < 0) {
  432. const usedAmount = ZhCalc.add(data.uamount, data.pre_amount);
  433. return usedAmount > 0 || usedAmount < data.limitAmount ? spreadColor.stage.over : defaultColor;
  434. } else {
  435. return data.uamount ? spreadColor.stage.over : defaultColor;
  436. }
  437. } else {
  438. return defaultColor;
  439. }
  440. }
  441. };
  442. this.curChangeId = '';
  443. this.spread = SpreadJsObj.createNewSpread($('#change-spread')[0]);
  444. this.firstView = true;
  445. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  446. // 初次显示,需刷新spread界面,保证界面绘制正确
  447. this.obj.bind('shown.bs.modal', function () {
  448. if (self.firstView) {
  449. self.firstView = false;
  450. self.spread.refresh();
  451. }
  452. });
  453. // 切换变更令,加载右侧明细数据
  454. this.spread.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  455. const change = SpreadJsObj.getSelectObject(info.sheet);
  456. if(change) self._loadChangeDetail(change);
  457. });
  458. // 填写本期计量
  459. this.spread.bind(spreadNS.Events.EditEnded, function (e, info) {
  460. if (info.sheet.zh_setting) {
  461. const col = info.sheet.zh_setting.cols[info.col];
  462. if (col.cellType === 'checkbox') return;
  463. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  464. const node = sortData[info.row];
  465. if (col.type === 'Number') {
  466. const num = _.toNumber(info.editingText);
  467. if (_.isFinite(num)) {
  468. node[col.field] = num;
  469. } else {
  470. try {
  471. node[col.field] = ZhCalc.mathCalcExpr(transExpr(info.editingText));
  472. } catch(err) {
  473. toastr.error('输入的表达式非法');
  474. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  475. return;
  476. }
  477. }
  478. } else {
  479. node[col.field] = info.editingText;
  480. }
  481. // 刷新界面
  482. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  483. }
  484. });
  485. this.spread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  486. if (info.sheet.zh_setting) {
  487. const sortData = SpreadJsObj.getSortData(info.sheet);
  488. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  489. const curRow = iRow + info.cellRange.row;
  490. const curCol = info.cellRange.col;
  491. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  492. if (col.type === 'Number') {
  493. const num = _.toNumber(info.sheet.getText(curRow, curCol));
  494. if (_.isFinite(num)) {
  495. sortData[curRow][col.field] = num;
  496. } else {
  497. try {
  498. sortData[curRow][col.field] = ZhCalc.mathCalcExpr(transExpr(info.sheet.getText(curRow, curCol)));
  499. } catch(err) {
  500. // toastr.error('输入的表达式非法');
  501. }
  502. }
  503. } else {
  504. sortData[curRow][col.field] = info.sheet.getText(curRow, curCol);
  505. }
  506. }
  507. SpreadJsObj.reLoadRowData(sheet, info.cellRange.row, sel.cellRange.rowCount);
  508. }
  509. });
  510. this.spread.bind(spreadNS.Events.ButtonClicked, function(e, info) {
  511. if (!info.sheet.zh_setting) return;
  512. const col = info.sheet.zh_setting.cols[info.col];
  513. if (col.cellType === 'checkbox') {
  514. if (info.sheet.isEditing()) {
  515. info.sheet.endEdit(true);
  516. }
  517. const select = info.sheet.zh_data[info.row];
  518. select.uamount = select.uamount ? 0 : select.vamount;
  519. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  520. }
  521. });
  522. SpreadJsObj.addDeleteBind(this.spread, function (sheet) {
  523. if (sheet.zh_setting) {
  524. const sel = sheet.getSelections()[0];
  525. const sortData = SpreadJsObj.getSortData(sheet);
  526. // 仅本期计量可删除
  527. if (sel.col === 5 && sel.colCount === 1) {
  528. const col = sheet.zh_setting.cols[sel.col];
  529. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  530. const data = sortData[iRow];
  531. data[col.field] = null;
  532. }
  533. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  534. }
  535. }
  536. });
  537. // 过滤可变更数量为0
  538. $('#filterEmpty').click(function () {
  539. self._filterChange(!this.checked, $('#matchPos')[0].checked);
  540. });
  541. // 匹配编号
  542. $('#matchPos').click(function () {
  543. self._filterChange(!$('#filterEmpty')[0].checked, this.checked);
  544. });
  545. // 展开收起 变更令详细信息
  546. $('#show-bgl-detail').bind('click', function () {
  547. const detail = $('#bgl-detail'), bgl=$('#bgl'), obj=$(this);
  548. if (detail.hasClass('col-4')) {
  549. detail.attr('class', 'col').hide();
  550. bgl.attr('class', 'col-12');
  551. $('a', obj).attr('title', '展开侧栏');
  552. $('i', obj).attr('class', 'fa fa-chevron-left');
  553. self.spread.refresh();
  554. } else {
  555. detail.attr('class', 'col-4').show();
  556. bgl.attr('class', 'col-8');
  557. $('a', obj).attr('title', '收起侧栏');
  558. $('i', obj).attr('class', 'fa fa-chevron-right');
  559. self.spread.refresh();
  560. }
  561. });
  562. // 添加调用变更令
  563. $('#usg-bg-ok').click(function () {
  564. const data = { target: self.callData, change: [] };
  565. for (const c of self.displayChanges) {
  566. if (c.uamount) {
  567. if (c.bamount > 0) {
  568. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  569. if (usedAmount < 0 || usedAmount > c.limitAmount) {
  570. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  571. return;
  572. }
  573. } else if (c.bamount < 0) {
  574. const usedAmount = ZhCalc.add(c.uamount, c.pre_amount);
  575. if (usedAmount > 0 || usedAmount < c.limitAmount) {
  576. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  577. return;
  578. }
  579. } else {
  580. toastr.error('变更令:' + c.code + ' 超计,请修改本期计量后,再提交');
  581. return;
  582. }
  583. data.change.push({ cid: c.cid, cbid: c.cbid, qty: c.uamount, minus: c.bamount < 0 });
  584. }
  585. }
  586. // 提交数据到后端
  587. postData(window.location.pathname + '/use-change', data, function(result) {
  588. if (result.pos) {
  589. stagePos.loadCurStageData(result.pos.curStageData);
  590. }
  591. const nodes = stageTree.loadPostStageData(result.bills);
  592. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  593. stagePosSpreadObj.loadCurPosData();
  594. if (detail) {
  595. detail.loadStageChangeUpdateData(result, nodes);
  596. } else {
  597. stageIm.loadUpdateChangeData(result, nodes)
  598. }
  599. self.obj.modal('hide');
  600. });
  601. })
  602. }
  603. findDecimal(unit) {
  604. let value = 3;
  605. if (unit !== '') {
  606. value = precision.other.value;
  607. const changeUnits = precision;
  608. for (const d in changeUnits) {
  609. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  610. value = changeUnits[d].value;
  611. break;
  612. }
  613. }
  614. }
  615. return value;
  616. }
  617. _calculateAmount() {
  618. for (const c of this.changes) {
  619. c.bamount = _.toNumber(c.b_amount);
  620. const qtyDecimal = this.findDecimal(c.b_unit);
  621. c.limitAmount = ZhCalc.mul(c.bamount, ZhCalc.div(c.delimit, 100, 2), qtyDecimal);
  622. c.vamount = ZhCalc.sub(ZhCalc.sub(c.limitAmount, c.used_amount), c.stage_used_amount);
  623. const uc = _.find(this.useChanges, {cid: c.cid, cbid: c.cbid, no_value: this.callData.noValue});
  624. if (uc) {
  625. c.org_uamount = uc.qty;
  626. c.uamount = uc.qty;
  627. c.vamount = ZhCalc.add(c.vamount, uc.qty);
  628. }
  629. c.pre_amount = ZhCalc.sub(ZhCalc.add(c.used_amount, c.stage_used_amount), c.uamount);
  630. }
  631. }
  632. _loadChangeDetail(change) {
  633. if (change) {
  634. if (change.cid === this.curChangeId) { return; }
  635. this.curChangeId = change.cid;
  636. const inputs = $('input[type!=checkbox][type!=radio]', this.obj);
  637. for (const i of inputs) {
  638. const field = $(i).attr('name');
  639. const text = (field && change[field]) ? change[field] : '';
  640. $(i).val(text);
  641. }
  642. const textareas = $('textarea', this.obj);
  643. for (const ta of textareas) {
  644. const field = $(ta).attr('name');
  645. const text = (field && change[field]) ? change[field].replace(/<br><br>/g, '\r\n') : '';
  646. ta.textContent = text;
  647. }
  648. const html = [];
  649. for (const a of change.attachments) {
  650. html.push('<tr>');
  651. html.push('<td>', '<a href="/change/download/file/' + a.id + '">', a.filename + a.fileext, '</a>', '</td>');
  652. html.push('<td>', a.u_name, '</td>');
  653. html.push('</tr>');
  654. }
  655. // 变更类型
  656. if (change.type) {
  657. const cType = change.type.split(',');
  658. $('input[name="type"]').prop("checked", false);
  659. for (const c of cType) {
  660. $('input[name="type"][value='+ c +']').prop("checked", true);
  661. }
  662. }
  663. // 变更类别
  664. $('select[name=class]').val(change.class);
  665. // 变更性质
  666. $('select[name=quality]').val(change.quality);
  667. // 变更单位
  668. $('select[name=company]').html('<option>' + (change.company ? change.company : '') + '</option>');
  669. // 费用承担方
  670. $('input[name=charge][value=' + change.charge + ']').prop('checked', true);
  671. // 附件
  672. $('#attachment').html(html.join(''));
  673. } else {
  674. const inputs = $('input', this.obj);
  675. for (const i of inputs) {
  676. $(i).val('');
  677. }
  678. const textareas = $('textarea', this.obj);
  679. for (const ta of textareas) {
  680. ta.innerText = '';
  681. }
  682. $('#attachment').html('');
  683. }
  684. }
  685. _viewChanges() {
  686. const sheet = this.spread.getActiveSheet();
  687. if (this.changes) {
  688. sheet.setSelection(0, 0, 1, 1);
  689. this._filterChange(!$('#filterEmpty')[0].checked, $('#matchPos')[0].checked);
  690. this._loadChangeDetail(this.displayChanges[0]);
  691. } else {
  692. toastr.error('查询变更令有误,请刷新页面后重试');
  693. }
  694. }
  695. _matchPos(match, change) {
  696. return match && this.callData.pos
  697. ? (change.gcl_id === this.callData.bills.id && change.b_bwmx === this.callData.pos.name)
  698. : true;
  699. }
  700. _matchBillsParent(match, change) {
  701. return match ? (!change.b_bwmx || change.b_bwmx === (this.callData.leafXmj ? this.callData.leafXmj.name : '')) : true;
  702. }
  703. _filterChange(filterEmpty, matchPosName) {
  704. this.displayChanges = [];
  705. for (const c of this.changes) {
  706. const filterVisible = filterEmpty ? (c.vamount ? !checkZero(c.vamount) : false) : true;
  707. const matchVisible = this.callData.pos ? this._matchPos(matchPosName, c) : this._matchBillsParent(matchPosName, c);
  708. if ((filterVisible && matchVisible) || (c.org_uamount)) {
  709. this.displayChanges.push(c);
  710. }
  711. }
  712. SpreadJsObj.loadSheetData(this.spread.getActiveSheet(), SpreadJsObj.DataType.Data, this.displayChanges);
  713. this._loadChangeDetail(this.displayChanges[0]);
  714. }
  715. loadChanges(data) {
  716. this.callData = data;
  717. // if (this.callData.pos) {
  718. // $('#matchPos').parent().show();
  719. // } else {
  720. // $('#matchPos').parent().hide();
  721. // }
  722. $('#matchPos').parent().show();
  723. const self = this;
  724. $('#b-code-hint').text('当前变更清单:' + data.bills.b_code);
  725. postData(window.location.pathname + '/valid-change', data, function (result) {
  726. self.changes = result.changes;
  727. self.useChanges = result.useChanges;
  728. self._calculateAmount();
  729. self._viewChanges();
  730. self.obj.modal('show');
  731. });
  732. }
  733. }
  734. const changesObj = new Changes($('#use-bg'));
  735. // 初始化 台账 spread
  736. const slSpread = SpreadJsObj.createNewSpread($('#stage-ledger')[0]);
  737. const slSheet = slSpread.getActiveSheet();
  738. customizeStageTreeSetting(ledgerSpreadSetting, customColDisplay());
  739. // 数量变更列,添加按钮
  740. const qcColShowImage = function (data) {
  741. if (!data || (data.children && data.children.length > 0) || !(data.b_code && data.b_code !== '')) {
  742. return false;
  743. } else {
  744. const nodePos = stagePos.getLedgerPos(data.id);
  745. return !(nodePos && nodePos.length > 0);
  746. }
  747. };
  748. sjsSettingObj.setQcCols(ledgerSpreadSetting.cols, [
  749. {field: 'qc_qty', showImage: qcColShowImage},
  750. {field: 'qc_minus_qty', showImage: qcColShowImage},
  751. ]);
  752. sjsSettingObj.setOrgPriceCol(ledgerSpreadSetting.cols, [ {field: 'org_price'} ]);
  753. // const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_gather_percent' || x.field === 'end_correct_percent'});
  754. // if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_percent' : 'end_gather_percent';
  755. const ratioCol = ledgerSpreadSetting.cols.find(x => {return x.field === 'end_final_1_percent' || x.field === 'end_correct_1_percent'});
  756. if (ratioCol) ratioCol.field = tenderInfo.display.stage.correct ? 'end_correct_1_percent' : 'end_final_1_percent';
  757. ledgerSpreadSetting.imageClick = function (data, hitinfo) {
  758. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  759. switch (col.field) {
  760. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  761. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  762. case 'wbs_url': data.wbs_url && window.open(data.wbs_url, '_target'); break;
  763. case 'qc_qty':
  764. case 'qc_minus_qty':
  765. if (data.children && data.children.length > 0 || data.lock || data.is_import || data.settle_status === settleStatus.finish) return;
  766. const nodePos = stagePos.getLedgerPos(data.id);
  767. if (nodePos && nodePos.length > 0) return;
  768. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  769. const leafXmj = stageTree.getLeafXmjParent(data);
  770. changesObj.loadChanges({bills: data, minus, noValue: minus, leafXmj: leafXmj});
  771. break;
  772. default: return;
  773. }
  774. };
  775. ledgerSpreadSetting.dgnUpFields = ['deal_dgn_qty1', 'deal_dgn_qty2', 'c_dgn_qty1', 'c_dgn_qty2'];
  776. ledgerSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  777. if (data) {
  778. if (col.field === 'gxby') {
  779. const def = thirdParty.gxby.find(function (x) {
  780. return x.value === data.gxby_status;
  781. });
  782. if (def && def.color) return def.color;
  783. } else if (col.field === 'dagl') {
  784. const def = thirdParty.dagl.find(function (x) {
  785. return x.value === data.dagl_status;
  786. });
  787. if (def && def.color) return def.color;
  788. }
  789. if (data.settle_status === settleStatus.finish) {
  790. return spreadColor.stage.settle;
  791. }
  792. return hintOver && checkUtils.billsOver(data, stagePos, tenderInfo.checkOverInfo) ? spreadColor.stage.over : defaultColor;
  793. } else {
  794. return defaultColor;
  795. }
  796. };
  797. sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  798. sjsSettingObj.set3FCols(ledgerSpreadSetting.cols, [
  799. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  800. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  801. {field: 'wbs_url', getValue: getWbsText, url_field: 'wbs_url', cellType: 'imageBtn', indent: 20},
  802. ]);
  803. if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);
  804. ledgerSpreadSetting.headColWidth = [50];
  805. ledgerSpreadSetting.rowHeader = [
  806. {
  807. rowHeaderType: 'tag',
  808. setting: {
  809. indent: 14,
  810. tagSize: 0.8,
  811. tagFont: '8px 微软雅黑',
  812. getColor: function (index, data) {
  813. if (!data) return;
  814. return billsTag.getBillsTagsColor(data.id);
  815. },
  816. getTagHtml: function (index, data) {
  817. if (!data) return;
  818. const getHtml = function (list) {
  819. if (!list || list.length === 0) return '';
  820. const html = [];
  821. for (const l of list) {
  822. html.push('<div class="mr-1">');
  823. html.push(`<div class="float-left ${l.tagClass}">`, '<i class="fa fa-tag"></i>', '</div>');
  824. html.push('<div class="ml-4">', '<p style="word-wrap: break-word">', l.comment, '</p>', '</div>');
  825. html.push('</div>');
  826. }
  827. return html.join('');
  828. };
  829. return getHtml(billsTag.getBillsTagsInfo(data.id));
  830. }
  831. },
  832. },
  833. ];
  834. // sjsSettingObj.setIsTpCol(ledgerSpreadSetting.cols, [ {field: 'is_tp'} ]);
  835. ledgerSpreadSetting.readOnly = function (data) {
  836. if (!data) return false;
  837. return data.lock || stageTreeSpreadObj.assistReadOnly;
  838. };
  839. SpreadJsObj.initSheet(slSpread.getActiveSheet(), ledgerSpreadSetting);
  840. //初始化所有附件列表
  841. getAllList();
  842. // 初始化 计量单元 Spread
  843. const spSpread = SpreadJsObj.createNewSpread($('#stage-pos')[0]);
  844. const spSheet = spSpread.getActiveSheet();
  845. const posQcColShowImage = function (data) {
  846. return data !== undefined && data !== null;
  847. };
  848. sjsSettingObj.setQcCols(posSpreadSetting.cols, [
  849. { field: 'qc_qty', showImage: posQcColShowImage },
  850. { field: 'qc_minus_qty', showImage: posQcColShowImage }
  851. ]);
  852. posSpreadSetting.imageClick = function (data, hitinfo) {
  853. const col = hitinfo.sheet.zh_setting.cols[hitinfo.col];
  854. switch (col.field) {
  855. case 'gxby': data.gxby_url && window.open(data.gxby_url); break;
  856. case 'dagl': data.dagl_url && window.open(data.dagl_url); break;
  857. case 'wbs_url': data.wbs_url && window.open(data.wbs_url, '_blank'); break;
  858. case 'qc_qty':
  859. case 'qc_minus_qty':
  860. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  861. if (node.lock || node.settle_status === settleStatus.finish) return;
  862. const minus = col.field === 'qc_minus_qty' ? 1 : 0;
  863. changesObj.loadChanges({bills: node, pos: data, minus, noValue: minus});
  864. break;
  865. default: return;
  866. }
  867. };
  868. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  869. if (data) {
  870. if (col.field === 'gxby') {
  871. const def = thirdParty.gxby.find(function (x) {
  872. return x.value === data.gxby_status;
  873. });
  874. if (def && def.color) return def.color;
  875. } else if (col.field === 'dagl') {
  876. const def = thirdParty.dagl.find(function (x) {
  877. return x.value === data.dagl_status;
  878. });
  879. if (def && def.color) return def.color;
  880. }
  881. if (data.settle_status === settleStatus.finish) {
  882. return spreadColor.stage.settle;
  883. }
  884. }
  885. return hintOver && checkUtils.posOver(data, tenderInfo.checkOverInfo) ? spreadColor.stage.over : defaultColor;
  886. };
  887. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  888. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  889. sjsSettingObj.set3FCols(posSpreadSetting.cols, [
  890. {field: 'gxby', getValue: getGxbyText, url_field: 'gxby_url'},
  891. {field: 'dagl', getValue: getDaglText, url_field: 'dagl_url'},
  892. {field: 'wbs_url', getValue: getWbsText, url_field: 'wbs_url', cellType: 'imageBtn', indent: 20},
  893. ]);
  894. SpreadJsObj.initSheet(spSpread.getActiveSheet(), posSpreadSetting);
  895. const billsTag = $.billsTag({
  896. relaTree: stageTree,
  897. selector: '#bills-tag',
  898. relaSpread: slSpread,
  899. updateUrl: window.location.pathname + '/tag',
  900. afterModify: function (nodes) {
  901. SpreadJsObj.repaintNodesRowHeader(slSpread.getActiveSheet(), nodes);
  902. },
  903. afterLocated: function () {
  904. stagePosSpreadObj.loadCurPosData();
  905. },
  906. afterShow: function () {
  907. slSpread.refresh();
  908. if (spSpread) spSpread.refresh();
  909. },
  910. });
  911. const errorList = $.cs_errorList({
  912. tabSelector: '#error-list-tab',
  913. selector: '#error-list',
  914. relaSpread: slSpread,
  915. storeKey: 'stage-error-' + stage.id,
  916. afterLocated: function () {
  917. stagePosSpreadObj.loadCurPosData();
  918. },
  919. afterShow: function () {
  920. slSpread.refresh();
  921. if (spSpread) spSpread.refresh();
  922. },
  923. });
  924. const checkList = $.ledger_checkList({
  925. id: 'check-list',
  926. tabSelector: '#check-list-tab',
  927. selector: '#check-list',
  928. relaSpread: slSpread,
  929. storeKey: 'stage-check-' + window.location.pathname.split('/')[2] + '-' + window.location.pathname.split('/')[4],
  930. checkType: getCheckType(checkOption),
  931. afterLocated: function () {
  932. stagePosSpreadObj.loadCurPosData();
  933. },
  934. afterShow: function () {
  935. slSpread.refresh();
  936. if (spSpread) spSpread.refresh();
  937. },
  938. });
  939. const sumLoadMiss = $.sumLoadMiss({
  940. tabSelector: '#sum-load-miss-tab',
  941. selector: '#sum-load-miss',
  942. relaSpread: slSpread,
  943. storeKey: 'stage-slm-' + stage.id,
  944. id: 'stage-slm',
  945. type: 'stage',
  946. afterLocated: function () {
  947. stagePosSpreadObj.loadCurPosData();
  948. },
  949. afterShow: function () {
  950. slSpread.refresh();
  951. if (spSpread) spSpread.refresh();
  952. },
  953. });
  954. const stageTreeSpreadObj = {
  955. cut: function (sheet, sel, callback) {
  956. callback(true);
  957. },
  958. loadExprToInput(sheet) {
  959. const sel = sheet.getSelections()[0];
  960. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  961. if (col.type === 'Number') {
  962. const data = SpreadJsObj.getSelectObject(sheet);
  963. if (!data) {
  964. $('#bills-expr').val('').attr('readOnly', true);
  965. $('#bills-expr').removeAttr('data-row');
  966. return;
  967. }
  968. const nodePos = stagePos.getLedgerPos(data.id);
  969. if (nodePos && nodePos.length > 0) {
  970. $('#bills-expr').val('').attr('readOnly', true);
  971. } else {
  972. if ((!data.is_tp && col.field.indexOf('tp') >= 0) || (data.is_tp && col.field.indexOf('tp') < 0)) {
  973. $('#bills-expr').val('').attr('readOnly', true);
  974. $('#bills-expr').removeAttr('data-row');
  975. return;
  976. }
  977. const exprInfo = getExprInfo(col.field);
  978. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  979. $('#bills-expr').val(value).attr('field', col.field).attr('org', data[col.field]);
  980. if (col.field.indexOf('tp') >= 0) {
  981. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp !== 1);
  982. } else {
  983. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || data.is_tp === 1)
  984. }
  985. }
  986. $('#bills-expr').attr('data-row', sel.row);
  987. } else {
  988. $('#bills-expr').val('').attr('readOnly', true);
  989. $('#bills-expr').removeAttr('data-row');
  990. }
  991. },
  992. refreshTreeNodes: function (sheet, nodes) {
  993. const tree = sheet.zh_tree;
  994. if (!tree) { return }
  995. const rows = [];
  996. for (const node of nodes) {
  997. rows.push(tree.nodes.indexOf(node));
  998. }
  999. SpreadJsObj.reLoadRowsData(sheet, rows);
  1000. },
  1001. editEnded: function (e, info) {
  1002. if (info.sheet.zh_setting) {
  1003. const col = info.sheet.zh_setting.cols[info.col];
  1004. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  1005. const node = sortData[info.row], updateData = {};
  1006. const orgValue = node[col.field];
  1007. let newValue = trimInvalidChar(info.editingText);
  1008. if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
  1009. return;
  1010. }
  1011. if (col.type === 'Number' && newValue && newValue !== '') {
  1012. const num = _.toNumber(newValue);
  1013. if (_.isFinite(num)) {
  1014. newValue = num;
  1015. } else {
  1016. try {
  1017. newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
  1018. } catch(err) {
  1019. toastr.error('输入的表达式非法');
  1020. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1021. return;
  1022. }
  1023. }
  1024. }
  1025. if (col.field.indexOf('_dgn_') > 0) {
  1026. if (node.b_code && node.b_code !== '') {
  1027. toastr.error('仅项目节可输入项目节数量');
  1028. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1029. return;
  1030. }
  1031. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1032. if (node.children && node.children.length > 0) {
  1033. toastr.error('清单父项不可计量');
  1034. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1035. return;
  1036. } else {
  1037. const nodePos = stagePos.getLedgerPos(node.id);
  1038. if (nodePos && nodePos.length > 0) {
  1039. toastr.error('该清单有计量单元,请在计量单元处计量');
  1040. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1041. return;
  1042. }
  1043. }
  1044. }
  1045. if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1046. updateData.main = {
  1047. id: node.id
  1048. };
  1049. updateData.main[col.field] = newValue;
  1050. } else if (col.field.indexOf('_dgn_') > 0) {
  1051. updateData.dgn = {
  1052. id: node.id
  1053. };
  1054. updateData.dgn[col.field] = newValue;
  1055. } else if (col.field !== 'is_tp') {
  1056. updateData.stage = {
  1057. lid: node.id
  1058. };
  1059. updateData.stage[col.field] = newValue;
  1060. const exprInfo = getExprInfo(col.field);
  1061. if (exprInfo) {
  1062. updateData.stage[exprInfo.expr] = info.editingText !== newValue+ '' ? trimInvalidChar(info.editingText) : '';
  1063. }
  1064. }
  1065. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1066. // tag update
  1067. const nodes = stageTree.loadPostStageData(data);
  1068. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1069. if (detail) {
  1070. detail.loadStageLedgerUpdateData(data, nodes);
  1071. } else {
  1072. stageIm.loadUpdateLedgerData(data, nodes);
  1073. }
  1074. }, function () {
  1075. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1076. });
  1077. }
  1078. },
  1079. updateNodeData: function(data) {
  1080. postData(window.location.href + '/update', { bills: data }, function(data) {
  1081. const nodes = stageTree.loadPostStageData(data);
  1082. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1083. if (detail) {
  1084. detail.loadStageLedgerUpdateData(data, nodes);
  1085. } else {
  1086. stageIm.loadUpdateLedgerData(data, nodes);
  1087. }
  1088. });
  1089. },
  1090. loadRelaData: function () {
  1091. const billsSheet = slSpread.getActiveSheet();
  1092. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  1093. const posSheet = spSpread.getActiveSheet();
  1094. SpreadJsObj.resetTopAndSelect(posSheet);
  1095. stagePosSpreadObj.loadCurPosData();
  1096. if (posSearch) posSearch.search();
  1097. },
  1098. selectionChanged: function (e, info) {
  1099. if (!info.oldSelections || !info.oldSelections[0] || info.newSelections[0].row !== info.oldSelections[0].row) {
  1100. stageTreeSpreadObj.loadRelaData();
  1101. // 全选去除
  1102. $('#dqjiedian').find('.check-all-file').prop('checked', false);
  1103. }
  1104. stageTreeSpreadObj.loadExprToInput(info.sheet);
  1105. },
  1106. deletePress(sheet) {
  1107. if (sheet.zh_setting && sheet.zh_dataType === 'tree') {
  1108. const tree = sheet.zh_tree;
  1109. if (!tree) { return; }
  1110. const sel = sheet.getSelections()[0];
  1111. const validCols = [];
  1112. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1113. const colSetting = sheet.zh_setting.cols[iCol];
  1114. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  1115. validCols.push(iCol);
  1116. }
  1117. }
  1118. if (validCols.length === 0) { return; }
  1119. const sortData = sheet.zh_tree.nodes;
  1120. const datas = [], dgnDatas = [], mainDatas = [];
  1121. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1122. const node = sortData[iRow];
  1123. if (node && !node.lock) {
  1124. const data = { lid: node.id }, dgnData = { id: node.id }, mainData = { id: node.id };
  1125. let filter = true, filterDgn = true, filterMain = true;
  1126. for (const iCol of validCols) {
  1127. const colSetting = sheet.zh_setting.cols[iCol];
  1128. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1129. if (node.b_code && node.b_code !== '') continue;
  1130. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) < 0) {
  1131. if (colSetting.field === 'contract_qty') {
  1132. if (node.is_tp || node.settle_status === settleStatus.finish) continue;
  1133. } else if (colSetting.field === 'contract_tp') {
  1134. if (!node.is_tp || node.settle_status === settleStatus.finish) continue;
  1135. }
  1136. if (node.children && node.children.length > 0) {
  1137. continue;
  1138. }
  1139. const nodePos = stagePos.getLedgerPos(node.id);
  1140. if (nodePos && nodePos.length > 0) {
  1141. continue;
  1142. }
  1143. }
  1144. if (sheet.zh_setting.dgnUpFields.indexOf(colSetting.field) !== -1) {
  1145. if (node[colSetting.field] && node[colSetting.field] !== 0) {
  1146. dgnData[colSetting.field] = 0;
  1147. filterDgn = false;
  1148. }
  1149. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(colSetting.field) >= 0) {
  1150. mainData[colSetting.field] = null;
  1151. filterMain = false;
  1152. } else {
  1153. data[colSetting.field] = colSetting.type === 'Number' ? 0 : '';
  1154. const exprInfo = getExprInfo(colSetting.field);
  1155. if (exprInfo) {
  1156. data[exprInfo.expr] = '';
  1157. }
  1158. filter = false;
  1159. }
  1160. }
  1161. if (!filter) datas.push(data);
  1162. if (!filterDgn) dgnDatas.push(dgnData);
  1163. if (!filterMain) mainDatas.push(mainData);
  1164. }
  1165. }
  1166. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1167. const bills = {};
  1168. if (datas.length > 0) bills.stage = datas;
  1169. if (dgnDatas.length > 0) bills.dgn = dgnDatas;
  1170. if (mainDatas.length > 0) bills.main = mainDatas;
  1171. postData(window.location.href + '/update', {bills: bills}, function (result) {
  1172. const nodes = stageTree.loadPostStageData(result);
  1173. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1174. if (detail) {
  1175. detail.loadStageLedgerUpdateData(result, nodes);
  1176. } else {
  1177. stageIm.loadUpdateLedgerData(result, nodes);
  1178. }
  1179. stageTreeSpreadObj.loadExprToInput(sheet);
  1180. });
  1181. }
  1182. }
  1183. },
  1184. clipboardPasting(e, info) {
  1185. if (info.sheet.zh_setting) {
  1186. const setting = info.sheet.zh_setting;
  1187. const range = info.cellRange;
  1188. const validField = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_minus_qty', 'postil', 'ex_stage_qty1', 'ex_stage_tp1'].concat(['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'], setting.dgnUpFields);
  1189. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1190. const col = info.sheet.zh_setting.cols[iCol];
  1191. if ((validField.indexOf(col.field) === -1)) {
  1192. toastr.error('不可修改此数据');
  1193. info.cancel = true;
  1194. return;
  1195. }
  1196. }
  1197. }
  1198. },
  1199. clipboardPasted(e, info) {
  1200. const pasteHint = getHintMsg();
  1201. if (info.sheet.zh_setting && info.sheet.zh_tree) {
  1202. const sheet = info.sheet, setting = info.sheet.zh_setting;
  1203. const filterNodes = [], datas = [], dgnDatas = [], mainDatas = [];
  1204. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1205. const curRow = iRow + info.cellRange.row;
  1206. const node = sheet.zh_tree.getItemsByIndex(curRow);
  1207. const data = {lid: node.id}, dgnData = {id: node.id}, mainData = {id: node.id};
  1208. let filter = true, filterDgn = true, filterMain = true;
  1209. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1210. const curCol = info.cellRange.col + iCol;
  1211. const col = info.sheet.zh_setting.cols[curCol];
  1212. if (col.field === 'contract_tp') {
  1213. if (!node.is_tp || node.settle_status === settleStatus.finish) continue;
  1214. } else if (col.field === 'contract_qty') {
  1215. if (node.is_tp || node.settle_status === settleStatus.finish) continue;
  1216. }
  1217. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1218. if (node.b_code && node.b_code !== '') continue;
  1219. } else if (['postil', 'memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) === -1) {
  1220. if (node.children && node.children.length > 0) continue;
  1221. const nodePos = stagePos.getLedgerPos(node.id);
  1222. if (nodePos && nodePos.length > 0) continue;
  1223. }
  1224. const text = trimInvalidChar(sheet.getText(curRow, curCol));
  1225. if (setting.dgnUpFields.indexOf(col.field) !== -1) {
  1226. const num = _.toNumber(text);
  1227. if (num) {
  1228. dgnData[col.field] = num;
  1229. filterDgn = false;
  1230. } else {
  1231. try {
  1232. dgnData[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1233. filterDgn = false;
  1234. } catch(err) {
  1235. toastMessageUniq(pasteHint.invalidExpr);
  1236. }
  1237. }
  1238. } else if (['memo', 'ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1239. mainData[col.field] = text;
  1240. filterMain = false;
  1241. } else {
  1242. if (col.type === 'Number') {
  1243. const exprInfo = getExprInfo(col.field);
  1244. if (text) {
  1245. const num = _.toNumber(text);
  1246. data[col.field] = num;
  1247. if (exprInfo) data[exprInfo.expr] = '';
  1248. if (_.isFinite(num)) {
  1249. filter = false;
  1250. } else {
  1251. try {
  1252. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1253. if (exprInfo) data[exprInfo.expr] = text;
  1254. filter = false;
  1255. } catch(err) {
  1256. toastMessageUniq(pasteHint.invalidExpr);
  1257. }
  1258. }
  1259. } else {
  1260. data[col.field] = null;
  1261. if (exprInfo) data[exprInfo.expr] = '';
  1262. filter = false;
  1263. }
  1264. } else {
  1265. data[col.field] = text;
  1266. }
  1267. }
  1268. }
  1269. if (filter && filterDgn && filterMain) {
  1270. filterNodes.push(node);
  1271. } else {
  1272. if (!filter) datas.push(data);
  1273. if (!filterDgn) dgnDatas.push(dgnData);
  1274. if (!filterMain) mainDatas.push(mainData);
  1275. }
  1276. }
  1277. if (datas.length > 0 || dgnDatas.length > 0 || mainDatas.length > 0) {
  1278. const updateData = {};
  1279. if (datas.length > 0) updateData.stage = datas;
  1280. if (dgnDatas.length > 0) updateData.dgn = dgnDatas;
  1281. if (mainDatas.length > 0) updateData.main = mainDatas;
  1282. postData(window.location.href + '/update', {bills: updateData}, function (data) {
  1283. const nodes = stageTree.loadPostStageData(data);
  1284. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes.concat(filterNodes));
  1285. if (detail) {
  1286. detail.loadStageLedgerUpdateData(data, nodes);
  1287. } else {
  1288. stageIm.loadUpdateLedgerData(data, nodes);
  1289. }
  1290. stageTreeSpreadObj.loadExprToInput(sheet);
  1291. }, function () {
  1292. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1293. });
  1294. } else {
  1295. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), filterNodes);
  1296. }
  1297. }
  1298. },
  1299. measureAllPosInNode(node, ratio = 1) {
  1300. const posterity = stageTree.getPosterity(node);
  1301. const data = {updateType: 'update', updateData: []};
  1302. for (const p of posterity) {
  1303. if (p.children && p.children.length > 0) continue;
  1304. const posRange = stagePos.getLedgerPos(p.id);
  1305. if (posRange && posRange.length > 0) {
  1306. for (const pr of posRange) {
  1307. if (pr.contract_qty && !checkZero(pr.contract_qty)) continue;
  1308. const validValue = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1309. if (validValue <= 0) continue;
  1310. const value = ratio !== 1 ? ZhCalc.mul(pr.quantity, ratio) : pr.quantity;
  1311. const pData = {
  1312. pid: pr.id,
  1313. lid: pr.lid,
  1314. contract_qty: validValue > 0 ? (value > validValue ? validValue : value) : (value < validValue ? validValue : value),
  1315. };
  1316. data.updateData.push(pData);
  1317. }
  1318. }
  1319. if (data.updateData.length > 1000 || _.map(data.updateData, 'lid').length > 500) {
  1320. toastr.warning('选中的数据过多,仅计量' + data.updateData.length + '条,请稍后');
  1321. break;
  1322. }
  1323. }
  1324. if (data.updateData.length === 0) {
  1325. toastr.info('其下全部计量单元均已计量');
  1326. return;
  1327. }
  1328. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1329. if (result.pos) {
  1330. stagePos.updateDatas(result.pos.pos);
  1331. stagePos.loadCurStageData(result.pos.curStageData);
  1332. }
  1333. const nodes = stageTree.loadPostStageData(result.ledger);
  1334. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1335. stagePosSpreadObj.loadCurPosData();
  1336. if (detail) {
  1337. detail.loadStagePosUpdateData(result, nodes);
  1338. } else {
  1339. stageIm.loadUpdatePosData(result, nodes);
  1340. }
  1341. toastr.success('已计量' + data.updateData.length + '条');
  1342. }, function () {
  1343. stagePosSpreadObj.loadCurPosData();
  1344. });
  1345. },
  1346. topRowChanged(e, info) {
  1347. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1348. },
  1349. editStarting(e, info) {
  1350. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1351. const col = info.sheet.zh_setting.cols[info.col];
  1352. const node = info.sheet.zh_tree.nodes[info.row];
  1353. switch (col.field) {
  1354. case 'contract_qty':
  1355. case 'qc_qty':
  1356. case 'qc_minus_qty':
  1357. info.cancel = node.is_tp || node.settle_status === settleStatus.finish;
  1358. break;
  1359. case 'ex_stage_qty1':
  1360. info.cancel = node.is_tp;
  1361. break;
  1362. case 'contract_tp':
  1363. info.cancel = !node.is_tp || node.settle_status === settleStatus.finish;
  1364. break;
  1365. case 'qc_tp':
  1366. info.cancel = !node.is_tp || node.settle_status === settleStatus.finish || qcTpReadOnly || node.qc_qty || node.qc_minus_qty;
  1367. break;
  1368. case 'is_tp':
  1369. info.cancel = true;
  1370. break;
  1371. }
  1372. if (!info.cancel) {
  1373. const exprInfo = getExprInfo(col.field);
  1374. if (exprInfo) {
  1375. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1376. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1377. }
  1378. }
  1379. }
  1380. },
  1381. buttonClicked: function (e, info) {
  1382. if (info.sheet.zh_setting) {
  1383. const node = SpreadJsObj.getSelectObject(info.sheet);
  1384. const col = info.sheet.zh_setting.cols[info.col];
  1385. const posRange = stagePos.getLedgerPos(node.id);
  1386. const tpUnit = ['总额', '元', '台', '个', '处', '月', '棵', '套', '组', '辆', '项', '座', '根', '块', '系统'];
  1387. if (node.pre_used === 1 ||
  1388. (node.children && node.children.length > 0) ||
  1389. // (tpUnit.indexOf(node.unit) < 0) ||
  1390. (posRange && posRange.length > 0) /*|| !checkZero(node.qc_qty)*/) {
  1391. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1392. return;
  1393. }
  1394. const postIsTp = function () {
  1395. const data = { calcType: {id: node.id} };
  1396. data.calcType.is_tp = info.sheet.getValue(info.row, info.col) || false;
  1397. // 更新至服务器
  1398. postData(window.location.pathname + '/update', {bills: data}, function (result) {
  1399. const nodes = stageTree.loadPostStageData(result);
  1400. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1401. if (detail) {
  1402. detail.loadStageLedgerUpdateData(result, nodes);
  1403. } else {
  1404. stageIm.loadUpdateLedgerData(result, nodes);
  1405. }
  1406. });
  1407. };
  1408. if (col.field === 'is_tp') {
  1409. if (info.sheet.isEditing()) {
  1410. info.sheet.endEdit(true);
  1411. }
  1412. if (!checkZero(node.contract_qty) || !checkZero(node.contract_tp) || !checkZero(node.ex_stage_qty1) || !checkZero(node.ex_stage_tp1)) {
  1413. $.msgBox({
  1414. id: 'calc-type',
  1415. title: '提示',
  1416. message: '切换计量模式,已计量数据会被清空。',
  1417. ok: {
  1418. caption: '确定',
  1419. callback: postIsTp,
  1420. },
  1421. cancel: {
  1422. caption: '取消',
  1423. callback: function () {
  1424. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1425. }
  1426. }
  1427. });
  1428. } else {
  1429. postIsTp();
  1430. }
  1431. }
  1432. }
  1433. },
  1434. measureByBatch: function (posNames, ratio, apply2sibling) {
  1435. if (posNames.length <= 0) return;
  1436. if (ratio <= 0) return;
  1437. const fRatio = ZhCalc.div(ratio, 100);
  1438. const sheet = slSpread.getActiveSheet();
  1439. const node = SpreadJsObj.getSelectObject(sheet);
  1440. const parent = stageTree.getParent(node);
  1441. const nodes = apply2sibling === true ? (parent ? parent.children : stageTree.children) : [node];
  1442. const data = {updateType: 'batchUpdate', updateData: []};
  1443. for (const node of nodes) {
  1444. const posRange = stagePos.getLedgerPos(node.id);
  1445. if (!posRange || posRange <= 0) continue;
  1446. for (const p of posRange) {
  1447. if (posNames.indexOf(p.name) < 0) continue;
  1448. data.updateData.push({
  1449. pid: p.id, lid: p.lid,
  1450. contract_qty: ZhCalc.mul(p.quantity, fRatio),
  1451. contract_expr: `${p.quantity}*${ratio}%`,
  1452. });
  1453. }
  1454. }
  1455. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1456. if (result.pos) {
  1457. stagePos.updateDatas(result.pos.pos);
  1458. stagePos.loadCurStageData(result.pos.curStageData);
  1459. }
  1460. const nodes = stageTree.loadPostStageData(result.ledger);
  1461. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1462. stagePosSpreadObj.loadCurPosData();
  1463. if (detail) {
  1464. detail.loadStagePosUpdateData(result, nodes);
  1465. } else {
  1466. stageIm.loadUpdatePosData(result, nodes);
  1467. }
  1468. $('#calc-by-ratio').modal('hide');
  1469. }, function () {
  1470. stagePosSpreadObj.loadCurPosData();
  1471. $('#calc-by-ratio').modal('hide');
  1472. });
  1473. },
  1474. exportExcel: function (filename, nodes, withPos = true) {
  1475. stageTree.recursiveExe(function(node) {
  1476. if (node.children && node.children.length > 0) {
  1477. node._export_group = _.sum(node.children.map(x => { return x._export_group; })) + node.children.length;
  1478. } else {
  1479. const posRange = stagePos.getLedgerPos(node.id);
  1480. node._export_group = posRange ? posRange.length : 0;
  1481. }
  1482. });
  1483. const exportNodesData = function (data, nodes, groupData) {
  1484. for (const node of nodes) {
  1485. data.push({
  1486. code: node.code, b_code: node.b_code, name: node.name, unit: node.unit,
  1487. unit_price: node.unit_price, quantity: node.quantity, total_price: node.total_price,
  1488. contract_qty: node.contract_qty, contract_tp: node.contract_tp,
  1489. qc_qty: node.qc_qty, qc_tp: node.qc_tp, qc_minus_qty: node.qc_minus_qty,
  1490. gather_qty: node.gather_qty, gather_tp: node.gather_tp,
  1491. end_contract_qty: node.end_contract_qty, end_contract_tp: node.end_contract_tp,
  1492. end_qc_qty: node.end_qc_qty, end_qc_tp: node.end_qc_tp, end_qc_minus_qty: node.end_qc_minus_qty,
  1493. end_gather_qty: node.end_gather_qty, end_gather_tp: node.end_gather_tp, end_final_1_percent: node.end_final_1_percent,
  1494. deal_dgn_qty1: node.deal_dgn_qty1, deal_dgn_qty2: node.deal_dgn_qty2,
  1495. c_dgn_qty1: node.c_dgn_qty1, c_dgn_qty2: node.c_dgn_qty2,
  1496. final_dgn_price: node.final_dgn_price,
  1497. postil: node.postil, drawing_code: node.drawing_code, memo: node.memo,
  1498. contract_expr_str: node.calc_expr ? TreeExprCalc.expr2ExprStr(node.calc_expr) : '',
  1499. });
  1500. if (node.children && node.children.length > 0) {
  1501. exportNodesData(data, node.children, groupData);
  1502. } else {
  1503. if (!withPos) continue;
  1504. const posRange = stagePos.getLedgerPos(node.id);
  1505. if (!posRange || posRange.length === 0) continue;
  1506. if (node._export_group) groupData.push({ code: node.code, b_code: node.b_code, start: data.length, count: node._export_group });
  1507. for (const [i, p] of posRange.entries()) {
  1508. data.push({
  1509. pos_code: (i + 1) + '', name: p.name,
  1510. quantity: p.quantity,
  1511. contract_qty: p.contract_qty, qc_qty: p.qc_qty, gather_qty: p.gather_qty,
  1512. end_contract_qty: p.end_contract_qty, end_qc_qty: p.end_qc_qty, end_gather_qty: p.end_gather_qty,
  1513. qc_minus_qty: p.qc_minus_qty, end_qc_minus_qty: p.end_qc_minus_qty,
  1514. drawing_code: p.drawing_code, memo: p.memo, postil: p.postil, position: p.position,
  1515. });
  1516. }
  1517. }
  1518. }
  1519. };
  1520. const data = [], groupData = [];
  1521. exportNodesData(data, nodes ? nodes : stageTree.children, groupData);
  1522. SpreadExcelObj.exportSimpleXlsxSheet(exportExcelSetting, data, filename, groupData);
  1523. },
  1524. loadChangeData: function(tree, pos, changes) {
  1525. const findEmptyBills = function(tree, change, changeBills) {
  1526. const cb = {
  1527. b_code: changeBills.code || '',
  1528. name: changeBills.name || '',
  1529. unit: changeBills.unit || '',
  1530. unit_price: changeBills.unit_price || 0,
  1531. };
  1532. for (const node of tree.nodes) {
  1533. if (node.children && node.children.length > 0) continue;
  1534. const b = {
  1535. b_code: node.b_code || '',
  1536. name: node.name || '',
  1537. unit: node.unit || '',
  1538. unit_price: node.unit_price || 0,
  1539. };
  1540. if (_.isMatch(cb, b)) return node;
  1541. }
  1542. return null;
  1543. };
  1544. for (const change of changes) {
  1545. for (const changeBills of change.bills) {
  1546. const node = changeBills.gcl_id
  1547. ? tree.nodes.find(x => {return x.id === changeBills.gcl_id})
  1548. : findEmptyBills(tree, change, changeBills);
  1549. if (!node) continue;
  1550. if (!node.changeBills) node.changeBills = [];
  1551. node.tz_qc_qty = ZhCalc.add(node.tz_qc_qty, changeBills.checked_amount);
  1552. if (tenderInfo.calc_type === 'up') {
  1553. node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.checked_price);
  1554. } else {
  1555. node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.tp);
  1556. }
  1557. const posData = pos.getLedgerPos(node.id);
  1558. if (posData && posData.length > 0) {
  1559. for (const p of changeBills.pos) {
  1560. const changePos = p.bwmx ? posData.find(x => { return x.name === p.bwmx; }) : posData[0];
  1561. if (changePos) {
  1562. changePos.tz_qc_qty = ZhCalc.add(changePos.tz_qc_qty, p.checked_amount);
  1563. if (!changePos.changeBills) changePos.changeBills = [];
  1564. changePos.changeBills.push({
  1565. code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
  1566. qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
  1567. });
  1568. node.changeBills.push({
  1569. code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
  1570. qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: changePos.name,
  1571. });
  1572. }
  1573. }
  1574. } else {
  1575. for (const p of changeBills.pos) {
  1576. node.changeBills.push({
  1577. code: change.code || '', name: change.name || '', is_valuation: p.is_valuation,
  1578. qty: p.checked_amount || 0, tp: p.checked_price || 0, pos: '',
  1579. });
  1580. }
  1581. }
  1582. }
  1583. }
  1584. }
  1585. };
  1586. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1587. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1588. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1589. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1590. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1591. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1592. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1593. SpreadJsObj.addCutEvents(slSpread, stageTreeSpreadObj.cut);
  1594. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1595. if (!readOnly) {
  1596. $('#bills-expr').bind('change onblur', function () {
  1597. if (this.readOnly) return;
  1598. const expr = $(this);
  1599. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1600. const select = stageTree.getItemsByIndex(row);
  1601. if (!select) return;
  1602. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1603. let newValue = expr.val();
  1604. const num = _.toNumber(newValue);
  1605. if (_.isFinite(num)) {
  1606. newValue = num;
  1607. } else {
  1608. try {
  1609. newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
  1610. } catch(err) {
  1611. toastr.error('输入的表达式非法');
  1612. return;
  1613. }
  1614. }
  1615. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1616. if (field.indexOf('_dgn_') > 0) {
  1617. updateData.dgn = {
  1618. id: select.id
  1619. };
  1620. updateData.dgn[field] = newValue;
  1621. } else {
  1622. updateData.stage = {
  1623. lid: select.id
  1624. };
  1625. updateData.stage[field] = newValue;
  1626. const exprInfo = getExprInfo(field);
  1627. if (exprInfo) {
  1628. updateData.stage[exprInfo.expr] = expr.val();
  1629. }
  1630. }
  1631. // 更新至服务器
  1632. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1633. const nodes = stageTree.loadPostStageData(result);
  1634. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1635. if (detail) {
  1636. detail.loadStageLedgerUpdateData(result, nodes);
  1637. } else {
  1638. stageIm.loadUpdateLedgerData(result, nodes);
  1639. }
  1640. });
  1641. });
  1642. }
  1643. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1644. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1645. const tenderSelect = TenderSelect({
  1646. type: 'stage',
  1647. afterLoad: function (result, select) {
  1648. const nodes = stageTree.loadPostStageData(result);
  1649. const posterity = stageTree.getPosterity(select);
  1650. for (const p of posterity) {
  1651. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1652. }
  1653. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1654. if (detail) {
  1655. detail.loadStageLedgerUpdateData(result, nodes);
  1656. } else {
  1657. stageIm.loadUpdateLedgerData(result, nodes);
  1658. }
  1659. if (result.sumLoadHis.errors.length > 0) {
  1660. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1661. sumLoadMiss.show();
  1662. } else {
  1663. sumLoadMiss.clearMissData();
  1664. }
  1665. // todo 优化,仅加载需要刷新的变更令
  1666. if (checkedChanges) checkedChanges.reloadChangeData();
  1667. }
  1668. });
  1669. const batchImport = BatchImportStageGcl({
  1670. stageTree,
  1671. afterLoad: function (result, select) {
  1672. const nodes = stageTree.loadPostStageData(result);
  1673. const posterity = stageTree.getPosterity(select);
  1674. for (const p of posterity) {
  1675. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1676. }
  1677. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1678. if (detail) {
  1679. detail.loadStageLedgerUpdateData(result, nodes);
  1680. } else {
  1681. stageIm.loadUpdateLedgerData(result, nodes);
  1682. }
  1683. if (checkedChanges) checkedChanges.reloadChangeData();
  1684. }
  1685. });
  1686. const spssTenderSelect = TenderSelectMulti({
  1687. title: '根据(其他标段)计量比例计量',
  1688. type: 'gather',
  1689. dataType: 'stage',
  1690. afterSelect: function(select) {
  1691. const data = { filter: 'info', tender: select };
  1692. postData(`/sp/${spid}/spss/load`, data, function(result) {
  1693. const postil = result.map(x => { return `${x.name}(${x.stage_filter}) ${x.info.contract_tp || 0}`}).join(';');
  1694. const gatherContractTp = ZhCalc.sum(result.map(x => { return x.info.contract_tp; }));
  1695. const gatherTp = ZhCalc.sum(result.map(x => { return x.info.total_price; }));
  1696. const node = SpreadJsObj.getSelectObject(slSheet);
  1697. const contract_tp = ZhCalc.mul(ZhCalc.div(gatherContractTp, gatherTp), node.total_price);
  1698. const contract_expr = result.length > 1
  1699. ? '(' + result.map(x => { return x.info.contract_tp; }).join('+') + ')/(' + result.map(x => { return x.info.total_price; }).join('+') + ')'
  1700. : result[0].info.contract_tp + '/' + result[0].info.total_price;
  1701. stageTreeSpreadObj.updateNodeData({ stage: { lid: node.id, contract_tp, contract_expr, postil } });
  1702. });
  1703. },
  1704. });
  1705. $.contextMenu({
  1706. selector: '#stage-ledger',
  1707. build: function ($trigger, e) {
  1708. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1709. stageTreeSpreadObj.loadRelaData();
  1710. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1711. },
  1712. items: {
  1713. 'remainCur': {
  1714. name: '填剩余量',
  1715. disabled: function (key, opt) {
  1716. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1717. return readOnly || !node || node.lock;
  1718. },
  1719. callback: function (key, opt) {
  1720. const sheet = spSpread.getActiveSheet();
  1721. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1722. const updateStage = [];
  1723. const posterity = stageTree.getPosterity(node);
  1724. posterity.unshift(node);
  1725. for (const p of posterity) {
  1726. if (p.children && p.children.length > 0) continue;
  1727. if (!p.b_code) continue;
  1728. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1729. if (posRange.length > 0) continue;
  1730. if (!p.is_tp) {
  1731. const qty = ZhCalc.sub(p.quantity, p.pre_contract_qty);
  1732. const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
  1733. if (differ) updateStage.push({ lid: p.id, contract_qty: qty, contract_expr: '' });
  1734. } else {
  1735. const tp = ZhCalc.sub(p.total_price, p.pre_contract_tp);
  1736. const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
  1737. if (differ) updateStage.push({ lid: p.id, contract_tp: tp });
  1738. }
  1739. }
  1740. if (updateStage.length === 0) {
  1741. toastr.warning('所选节点及子项已全部计量');
  1742. return;
  1743. }
  1744. if (updateStage.length > 0) {
  1745. if (updateStage.length > 1000) {
  1746. toastr.warning('提交的数据太大,仅提交1000条数据');
  1747. updateStage.length = 1000;
  1748. }
  1749. postData(window.location.pathname + '/update', {bills: { stage: updateStage }}, function (result) {
  1750. const nodes = stageTree.loadPostStageData(result);
  1751. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1752. if (detail) {
  1753. detail.loadStageLedgerUpdateData(result, nodes);
  1754. } else {
  1755. stageIm.loadUpdateLedgerData(result, nodes);
  1756. }
  1757. stageTreeSpreadObj.loadExprToInput(sheet);
  1758. });
  1759. }
  1760. }
  1761. },
  1762. 'remainCurPos': {
  1763. name: '填剩余量(计量单元)',
  1764. disabled: function (key, opt) {
  1765. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1766. return readOnly || !node || node.lock;
  1767. },
  1768. callback: function (key, opt) {
  1769. const sheet = spSpread.getActiveSheet();
  1770. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1771. const data = { updateType: 'batchUpdate', updateData: [] };
  1772. const posterity = stageTree.getPosterity(node);
  1773. posterity.unshift(node);
  1774. for (const p of posterity) {
  1775. if (p.children && p.children.length > 0) continue;
  1776. if (!p.b_code) continue;
  1777. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1778. if (posRange.length === 0) continue;
  1779. for (const pr of posRange) {
  1780. const qty = ZhCalc.sub(pr.quantity, pr.pre_contract_qty);
  1781. const differ = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1782. if (differ) data.updateData.push({ lid: pr.lid, pid: pr.id, contract_qty: qty, contract_expr: '' });
  1783. }
  1784. }
  1785. if (data.updateData.length === 0) {
  1786. toastr.warning('所选节点及子项已全部计量');
  1787. return;
  1788. }
  1789. if (data.updateData.length > 0) {
  1790. if (data.updateData.length > 1000) {
  1791. toastr.warning('提交的数据太大,仅提交1000条数据');
  1792. data.updateData.length = 1000;
  1793. }
  1794. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1795. if (result.pos) {
  1796. stagePos.updateDatas(result.pos.pos);
  1797. stagePos.loadCurStageData(result.pos.curStageData);
  1798. }
  1799. const nodes = stageTree.loadPostStageData(result.ledger);
  1800. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1801. stagePosSpreadObj.loadCurPosData();
  1802. if (detail) {
  1803. detail.loadStagePosUpdateData(result, nodes);
  1804. } else {
  1805. stageIm.loadUpdatePosData(result, nodes);
  1806. }
  1807. stageTreeSpreadObj.loadExprToInput(sheet);
  1808. });
  1809. }
  1810. }
  1811. },
  1812. 'remainXmjQty': {
  1813. name: '填项目节数量',
  1814. callback: function(key, opt) {
  1815. const sheet = spSpread.getActiveSheet();
  1816. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1817. const updateDgn = [];
  1818. const posterity = stageTree.getPosterity(node);
  1819. posterity.unshift(node);
  1820. for (const p of posterity) {
  1821. if (p.b_code) continue;
  1822. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1823. if (posRange.length > 0) continue;
  1824. if (p.dgn_qty1 !== p.deal_dgn_qty1 || p.dgn_qty2 !== p.deal_dgn_qty2) updateDgn.push({ id: p.id, deal_dgn_qty1: p.dgn_qty1, deal_dgn_qty2: p.dgn_qty2 });
  1825. }
  1826. if (updateDgn.length === 0) {
  1827. toastr.warning('所选项目节及子项的项目节数量已与台账相等');
  1828. return;
  1829. }
  1830. if (updateDgn.length > 1000) {
  1831. toastr.warning('提交的数据太大,仅提交1000条数据');
  1832. updateDgn.length = 1000;
  1833. }
  1834. postData(window.location.pathname + '/update', {bills: { dgn: updateDgn }}, function (result) {
  1835. const nodes = stageTree.loadPostStageData(result);
  1836. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1837. if (detail) {
  1838. detail.loadStageLedgerUpdateData(result, nodes);
  1839. } else {
  1840. stageIm.loadUpdateLedgerData(result, nodes);
  1841. }
  1842. stageTreeSpreadObj.loadExprToInput(sheet);
  1843. });
  1844. // postData(window.location.pathname + '/update', { dgn: 'all' }, function (result) {
  1845. // const nodes = stageTree.loadPostStageData(result);
  1846. // stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1847. // if (detail) {
  1848. // detail.loadStageLedgerUpdateData(result, nodes);
  1849. // } else {
  1850. // stageIm.loadUpdateLedgerData(result, nodes);
  1851. // }
  1852. // stageTreeSpreadObj.loadExprToInput(sheet);
  1853. // });
  1854. },
  1855. visible: function(key, opt) {
  1856. return !readOnly;
  1857. },
  1858. disabled: function (key, opt) {
  1859. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1860. return !node || !!node.b_code;
  1861. }
  1862. },
  1863. 'remainByExprAll': {
  1864. name: '计算本期合同计量',
  1865. icon: 'fa-forward',
  1866. callback: function(key, opt) {
  1867. const sheet = spSpread.getActiveSheet();
  1868. TreeExprCalc.setCalcType(TreeExprCalc.calcType.sortCache);
  1869. const calcExpr = stageTree.nodes.filter(x => {
  1870. if (x.children && x.children.length > 0) return false;
  1871. const posRange = stagePos.getLedgerPos(x.id);
  1872. if (posRange && posRange.length > 0) return false;
  1873. return !!x.calc_expr;
  1874. }).map(x => { return { id: x.id, expr: x.calc_expr, unit: x.unit, unit_price: x.unit_price, calcField: x.is_tp ? 'tp' : 'qty' }});
  1875. if (calcExpr.length === 0) {
  1876. toastr.warning('沒有可计算的公式');
  1877. return;
  1878. }
  1879. TreeExprCalc.calcAllExpr(calcExpr);
  1880. const updateData = calcExpr.map(x => {
  1881. const data = { lid: x.id, contract_expr: x.formula };
  1882. const field = x.calcField === 'qty' ? 'contract_qty' : 'contract_tp';
  1883. data[field] = x.value;
  1884. return data;
  1885. });
  1886. postData(window.location.pathname + '/update', {bills: { stage: updateData }}, function (result) {
  1887. const nodes = stageTree.loadPostStageData(result);
  1888. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1889. if (detail) {
  1890. detail.loadStageLedgerUpdateData(result, nodes);
  1891. } else {
  1892. stageIm.loadUpdateLedgerData(result, nodes);
  1893. }
  1894. stageTreeSpreadObj.loadExprToInput(sheet);
  1895. });
  1896. },
  1897. visible: function(key, opt) {
  1898. return !readOnly && contractExpr;
  1899. },
  1900. },
  1901. zjjlSpr: '----',
  1902. 'locateZjjl': {
  1903. name: '定位至中间计量',
  1904. icon: 'fa-sign-in',
  1905. callback: function (key, opt) {
  1906. if (!detail) {
  1907. detail = new Detail($('#detail-spread'));
  1908. }
  1909. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1910. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1911. if (leafUsedBills) {
  1912. if (!$('#zhongjian').hasClass('active')) {
  1913. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1914. $('a', '.side-menu').removeClass('active');
  1915. $('.tab-content .tab-select-show').removeClass('active');
  1916. tab.addClass('active');
  1917. tabPanel.addClass('active');
  1918. showSideTools(tab.hasClass('active'));
  1919. slSpread.refresh();
  1920. spSpread.refresh();
  1921. }
  1922. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1923. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1924. SpreadJsObj.locateData(detail.sheet, im);
  1925. detail.spread.refresh();
  1926. $('#zhongjian .sjs-bottom').height('400px');
  1927. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1928. detail.reLoadDetailData();
  1929. } else {
  1930. toastr.error('无可定位中间计量');
  1931. }
  1932. },
  1933. disabled: function (key, opt) {
  1934. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1935. return !node;
  1936. }
  1937. },
  1938. tagSpr: '----',
  1939. tag: {
  1940. name: '书签',
  1941. callback: function (key, opt, menu, e) {
  1942. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1943. addTag.do(node);
  1944. },
  1945. disabled: function (key, opt) {
  1946. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1947. return !node;
  1948. }
  1949. },
  1950. showSpr: '----',
  1951. showLast: {
  1952. name: '显示至最底层',
  1953. callback: function (key, opt, menu, e) {
  1954. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1955. setTimeout(() => {
  1956. showWaitingView();
  1957. stageTree.expandByCustom(x => {
  1958. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1959. });
  1960. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1961. closeWaitingView();
  1962. }, 100);
  1963. },
  1964. disabled: function (key, opt) {
  1965. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1966. return !node;
  1967. }
  1968. },
  1969. detail: {
  1970. name: '查看变更后数量明细',
  1971. callback: function(key, opt, menu, e) {
  1972. const curBills = SpreadJsObj.getSelectObject(slSheet);
  1973. $('#tz2d-hint').html(`当前清单:${curBills.b_code || ''} ${curBills.name || ''}`);
  1974. $('#tz2d-tz').html(`台账数量:${ curBills.quantity || 0}`);
  1975. $('#tz2d-qc').html(`变更数量:${ ZhCalc.sub(curBills.tz2_qty, curBills.quantity) || 0}`);
  1976. $('#tz2d-sum').html(`变更后数量:${ curBills.tz2_qty || 0}`);
  1977. const html = [];
  1978. html.push('<tr class="text-center"><th>变更令编号</th><th>变更令名称</th><th>计量单元</th><th>计价</th><th>批复数量</th></tr>');
  1979. if (!curBills.changeBills) curBills.changeBills = [];
  1980. for (const cb of curBills.changeBills) {
  1981. html.push(`<tr><td>${cb.code}</td><td>${cb.name}</td><td>${cb.pos}</td><td class="text-center">${ cb.is_valuation ? '√' : '' }</td><td class="text-right">${cb.qty}</td></tr>`);
  1982. }
  1983. $('#tz2d-list').html(html.join(''));
  1984. $('#tz2-detail').modal('show');
  1985. },
  1986. disabled: function(key, opt) {
  1987. const curBills = SpreadJsObj.getSelectObject(slSheet);
  1988. return !curBills || !curBills.b_code;
  1989. }
  1990. },
  1991. exportSpr: '----',
  1992. exportSelectNodeXlsx: {
  1993. name: '导出选中节点至Excel',
  1994. callback: function (key, opt, menu, e) {
  1995. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1996. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1997. },
  1998. disabled: function (key, opt) {
  1999. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2000. return !node;
  2001. }
  2002. },
  2003. exportContractExprXlsx: {
  2004. name: '导出本期合同计量公式',
  2005. callback: function(key, opt, menu, e) {
  2006. exportExcelSetting.cols.push({title: '本期合同计量计算式', colSpan: '1', rowSpan: '2', field: 'contract_expr_str', hAlign: 0, width: 140, formatter: '@'});
  2007. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + '本期合同计量公式.xlsx', null, false);
  2008. exportExcelSetting.cols.splice(exportExcelSetting.cols.length - 1, 1);
  2009. },
  2010. visible: function(key, opt) {
  2011. return contractExpr;
  2012. }
  2013. },
  2014. dealLoadSpr: '---',
  2015. exportDealData: {
  2016. name: '导出本期合同计量',
  2017. callback: function (key, opt, menu, e) {
  2018. window.open(window.location.pathname + '/cpd');
  2019. },
  2020. },
  2021. importDealData: {
  2022. name: '导入本期合同计量',
  2023. callback: function (key, opt, menu, e) {
  2024. BaseImportFile.show({
  2025. validList: ['.cpd'],
  2026. url: window.location.pathname + '/cpd/load',
  2027. afterImport: function() {
  2028. window.location.reload();
  2029. }
  2030. });
  2031. },
  2032. disabled: function(key, opt) {
  2033. return readOnly || stage.revising || stage.status !== auditConst.status.uncheck;
  2034. },
  2035. },
  2036. exportTestData: {
  2037. name: '导出测试数据',
  2038. callback: function (key, opt, menu, e) {
  2039. const data = stageTree.nodes.map(x => {
  2040. const parent = stageTree.getParent(x);
  2041. return {
  2042. id: x.id, parentId: parent ? parent.id : '-1', seq: x.order,
  2043. code: x.code || '', b_code: x.b_code || '', name: x.name || '', unit: x.unit || '', unit_price: x.unit_price || 0,
  2044. quantity: x.quantity || 0, total_price: x.total_price || 0,
  2045. is_tp: x.is_tp || 0,
  2046. contract_qty: x.contract_qty || 0, contract_tp: x.contract_tp || 0,
  2047. qc_qty: x.qc_qty || 0, qc_tp: x.qc_tp || 0,
  2048. gather_qty: x.gather_qty || 0, gather_tp: x.gather_tp || 0,
  2049. pre_contract_qty: x.pre_contract_qty || 0, pre_contract_tp: x.pre_contract_tp || 0,
  2050. pre_qc_qty: x.pre_qc_qty || 0, pre_qc_tp: x.pre_qc_tp || 0,
  2051. pre_gather_qty: x.pre_gather_qty || 0, pre_gather_tp: x.pre_gather_tp || 0,
  2052. end_contract_qty: x.end_contract_qty || 0, end_contract_tp: x.end_contract_tp || 0,
  2053. end_qc_qty: x.end_qc_qty || 0, end_qc_tp: x.end_qc_tp || 0,
  2054. end_gather_qty: x.end_gather_qty || 0, end_gather_tp: x.end_gather_tp || 0,
  2055. memo: x.memo || '',
  2056. gxby_status: x.gxby_status || 0, gxby_url: x.gxby_status || '',
  2057. dagl_status: x.gxby_status || 0, dagl_url: x.dagl_url || '',
  2058. wbs_url: x.wbs_url || '',
  2059. };
  2060. });
  2061. const blob = new Blob([JSON.stringify(data, '', '\t')], { type: 'application/text'});
  2062. saveAs(blob, 'test.json');
  2063. },
  2064. visible: function() {
  2065. return is_debug || false;
  2066. }
  2067. },
  2068. sumLoadSpr: '---',
  2069. importStageGcl: {
  2070. name: '导入(其他标段)工程量清单计量数据',
  2071. icon: 'fa-link',
  2072. disabled: function (key, opt) {
  2073. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2074. return readOnly || !node || !stageTree.isLeafXmj(node);
  2075. },
  2076. callback: function (key, opt) {
  2077. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  2078. }
  2079. },
  2080. batchImportStageGcl: {
  2081. name: '批量导入(其他标段)工程量清单计量数据',
  2082. icon: 'fa-link',
  2083. disabled: function (key, opt) {
  2084. return readOnly;
  2085. },
  2086. callback: function (key, opt){
  2087. batchImport.show();
  2088. }
  2089. },
  2090. percentSpr: '---',
  2091. percentCalc: {
  2092. name: '根据(其他标段)计量比例计量',
  2093. disabled: function(key, opt) {
  2094. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2095. const posRange = stagePos.getLedgerPos(node.id) || [];
  2096. return readOnly || !node || !node.is_tp || posRange.length > 0;
  2097. },
  2098. callback: function(key, opt) {
  2099. spssTenderSelect.showSelect();
  2100. }
  2101. },
  2102. shoufangdanSpr: '---',
  2103. shoufangdan: {
  2104. name: '生成收方单',
  2105. visible: function(key, opt) {
  2106. if (cur_uid === stage.user_id) return true;
  2107. },
  2108. disabled: function (key, opt) {
  2109. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2110. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  2111. },
  2112. callback: function (key, opt) {
  2113. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2114. $('#shoufang-lid').val(node.id);
  2115. $('#shoufang-pid').val('');
  2116. $('#shoufang-ledger').text('清单:' + node.b_code);
  2117. $('#shoufang-pos').text('').hide();
  2118. $('#addshoufang').modal('show');
  2119. }
  2120. },
  2121. lockedSpr: '----',
  2122. lockedHint: {
  2123. name: '检查审批状态',
  2124. visible: function (key, opt) {
  2125. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2126. return node.locked;
  2127. },
  2128. callback: function (key, opt) {
  2129. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2130. const lockedInfo = stageTree.getLockedInfo(node);
  2131. toastr.warning(`审批人 ${lockedInfo.map(x => { return x.name; }).join(',')} 审批通过,如需修改,请联系审批人重新审批`);
  2132. }
  2133. },
  2134. }
  2135. });
  2136. const stagePosSpreadObj = {
  2137. loadExprToInput(sheet) {
  2138. const sel = sheet.getSelections()[0];
  2139. if (!sel) return;
  2140. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  2141. if (col && col.type === 'Number') {
  2142. const data = SpreadJsObj.getSelectObject(sheet);
  2143. if (data) {
  2144. const exprInfo = getExprInfo(col.field);
  2145. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  2146. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2147. .attr('readOnly', readOnly || cell.locked());
  2148. $('#pos-expr').attr('data-row', sel.row);
  2149. } else {
  2150. $('#pos-expr').val('').attr('readOnly', true);
  2151. $('#pos-expr').removeAttr('data-row');
  2152. }
  2153. } else {
  2154. $('#pos-expr').val('').attr('readOnly', true);
  2155. $('#pos-expr').removeAttr('data-row');
  2156. }
  2157. },
  2158. /**
  2159. * 加载计量单元 根据当前台账选择节点
  2160. */
  2161. loadCurPosData: function () {
  2162. const sheet = slSpread.getActiveSheet();
  2163. const node = SpreadJsObj.getSelectObject(sheet);
  2164. if (node) {
  2165. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  2166. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  2167. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  2168. const posMeasure = $('#pos-measure')[0].checked;
  2169. const posUnMeasure = $('#pos-un-measure')[0].checked;
  2170. posData.forEach(x => {
  2171. x.visible = true;
  2172. if (posMeasure && x.visible) {
  2173. x.visible = !!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty;
  2174. }
  2175. if (posUnMeasure && x.visible) {
  2176. // 不考虑不计价
  2177. x.visible = !x.end_contract_qty && !x.end_qc_qty && !x.end_gather_qty; // && !x.qc_minus_qty;
  2178. }
  2179. });
  2180. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  2181. getNodeList(node.id);
  2182. } else {
  2183. spSpread.getActiveSheet().zh_setting.readOnly = true;
  2184. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  2185. }
  2186. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  2187. },
  2188. editEnded: function (e, info) {
  2189. if (info.sheet.zh_setting) {
  2190. // 未改变过,则直接跳过
  2191. const sortData = info.sheet.zh_data;
  2192. const posData = sortData ? sortData[info.row] : null;
  2193. const col = info.sheet.zh_setting.cols[info.col];
  2194. const orgText = posData ? posData[col.field] : null;
  2195. const newText = trimInvalidChar(info.editingText);
  2196. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  2197. return;
  2198. }
  2199. // 台账模式下,不可新增
  2200. if (checkTzMeasureType() && !posData) {
  2201. toastr.error('台账模式不可新增计量单元数据');
  2202. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2203. return ;
  2204. }
  2205. // 不同节点下,计量单元检查输入
  2206. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2207. const node = stagePosSpreadObj.stageTreeNode;
  2208. if (!node) {
  2209. toastr.warning('数据错误, 请刷新页面后再试');
  2210. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2211. return;
  2212. } else if (newText !== '' && node.children && node.children.length > 0) {
  2213. toastr.error('父节点不可插入计量单元');
  2214. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2215. return;
  2216. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  2217. toastr.error('项目节不可插入计量单元');
  2218. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2219. return;
  2220. }
  2221. // 生成提交数据
  2222. const data = {};
  2223. if (col.field === 'name') {
  2224. if ((!newText || newText === '') && posData) {
  2225. toastr.error('部位名称不可为空');
  2226. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2227. return;
  2228. } else if (!posData) {
  2229. if (newText !== '') {
  2230. data.updateType = 'add';
  2231. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2232. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2233. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2234. return;
  2235. }
  2236. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2237. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  2238. } else {
  2239. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2240. return;
  2241. }
  2242. } else {
  2243. data.updateType = 'update';
  2244. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  2245. }
  2246. } else if (!posData) {
  2247. toastr.warning('新增计量单元请先输入名称');
  2248. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  2249. data.updateType = 'update';
  2250. data.updateData = {pid: posData.id, lid: posData.lid};
  2251. data.updateData[col.field] = newText;
  2252. } else {
  2253. data.updateType = 'update';
  2254. data.updateData = {pid: posData.id, lid: posData.lid};
  2255. if (col.type === 'Number') {
  2256. const exprInfo = getExprInfo(col.field);
  2257. const num = _.toNumber(newText);
  2258. if (_.isFinite(num)) {
  2259. data.updateData[col.field] = num;
  2260. if (exprInfo) {
  2261. data.updateData[exprInfo.expr] = '';
  2262. }
  2263. } else {
  2264. try {
  2265. data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2266. if (exprInfo) {
  2267. data.updateData[exprInfo.expr] = newText;
  2268. }
  2269. } catch(err) {
  2270. toastr.error('输入的表达式非法');
  2271. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2272. return;
  2273. }
  2274. }
  2275. } else if (col.field.indexOf('_expr') > 0) {
  2276. const exprInfo = getExprInfo(col.field, true);
  2277. if (!exprInfo) return;
  2278. if (newText) {
  2279. try {
  2280. data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2281. data.updateData[exprInfo.expr] = newText;
  2282. } catch(err) {
  2283. toastr.error('输入的表达式非法');
  2284. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2285. return;
  2286. }
  2287. } else {
  2288. data.updateData[exprInfo.qty] = 0;
  2289. data.updateData[exprInfo.expr] = '';
  2290. }
  2291. } else {
  2292. data.updateData[col.field] = newText;
  2293. }
  2294. }
  2295. // 提交数据到服务器
  2296. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2297. if (result.pos) {
  2298. stagePos.updateDatas(result.pos.pos);
  2299. stagePos.loadCurStageData(result.pos.curStageData);
  2300. }
  2301. const refreshData = stageTree.loadPostStageData(result.ledger);
  2302. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2303. stagePosSpreadObj.loadCurPosData();
  2304. if (detail) {
  2305. detail.loadStagePosUpdateData(result, refreshData);
  2306. } else {
  2307. stageIm.loadUpdatePosData(result, refreshData);
  2308. }
  2309. }, function () {
  2310. stagePosSpreadObj.loadCurPosData();
  2311. });
  2312. }
  2313. },
  2314. editStarting: function (e, info) {
  2315. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2316. const sel = info.sheet.getSelections();
  2317. if (!sel || !sel[0]) return;
  2318. const col = info.sheet.zh_setting.cols[sel[0].col];
  2319. const node = SpreadJsObj.getSelectObject(info.sheet);
  2320. const exprInfo = getExprInfo(col.field);
  2321. if (exprInfo && node) {
  2322. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2323. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2324. }
  2325. }
  2326. switch (col.field) {
  2327. case 'contract_qty':
  2328. case 'contract_expr':
  2329. case 'qc_qty':
  2330. case 'qc_minus_qty':
  2331. info.cancel = node.settle_status === settleStatus.finish;
  2332. break;
  2333. }
  2334. },
  2335. clipboardPasting: function (e, info) {
  2336. if (info.sheet.zh_setting) {
  2337. const sortData = info.sheet.zh_data;
  2338. const range = info.cellRange;
  2339. const validField = ['contract_qty', 'contract_expr', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3', 'ex_stage_qty1'];
  2340. if (!checkTzMeasureType()) {
  2341. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  2342. }
  2343. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  2344. const col = info.sheet.zh_setting.cols[iCol];
  2345. if (validField.indexOf(col.field) === -1) {
  2346. if (checkTzMeasureType()) {
  2347. toastr.error('不可修改此数据');
  2348. info.cancel = true;
  2349. return;
  2350. } else {
  2351. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  2352. const pos = sortData(iRow);
  2353. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  2354. toastr.error('不可修改此数据');
  2355. info.cancel = true;
  2356. return;
  2357. }
  2358. }
  2359. }
  2360. }
  2361. }
  2362. }
  2363. },
  2364. clipboardPasted: function (e, info) {
  2365. const hint = {
  2366. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2367. };
  2368. if (info.sheet.zh_setting) {
  2369. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2370. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2371. }
  2372. const data = { updateType: '', updateData: [], };
  2373. const sortData = info.sheet.zh_data;
  2374. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2375. if (node.children && node.children.length > 0) return;
  2376. if (sortData && (info.cellRange.row >= sortData.length)) {
  2377. data.updateType = 'add';
  2378. if (info.cellRange.col !== 0) {
  2379. toastr.warning('新增计量单元请先输入名称');
  2380. stagePosSpreadObj.loadCurPosData();
  2381. return;
  2382. }
  2383. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2384. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2385. stagePosSpreadObj.loadCurPosData();
  2386. return;
  2387. }
  2388. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2389. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2390. const curRow = info.cellRange.row + iRow;
  2391. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  2392. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2393. const curCol = info.cellRange.col + iCol;
  2394. const colSetting = info.sheet.zh_setting.cols[curCol];
  2395. if (!colSetting) continue;
  2396. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2397. if (colSetting.type === 'Number') {
  2398. const exprInfo = getExprInfo(colSetting.field);
  2399. if (newValue) {
  2400. const num = _.toNumber(newValue);
  2401. if (num) {
  2402. newData[colSetting.field] = num;
  2403. if (exprInfo) {
  2404. newData[exprInfo.expr] = '';
  2405. }
  2406. } else {
  2407. try {
  2408. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2409. if (exprInfo) {
  2410. newData[exprInfo.expr] = newValue;
  2411. }
  2412. } catch(err) {
  2413. toastr.error('输入的表达式非法');
  2414. stagePosSpreadObj.loadCurPosData();
  2415. return;
  2416. }
  2417. }
  2418. } else {
  2419. newData[colSetting.field] = null;
  2420. if (exprInfo) newData[exprInfo.expr] = '';
  2421. }
  2422. } else if (colSetting.field.indexOf('_expr') > 0) {
  2423. try {
  2424. const exprInfo = getExprInfo(colSetting.field, true);
  2425. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2426. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2427. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2428. }
  2429. } catch (err) {
  2430. toastMessageUniq(hint.expr);
  2431. }
  2432. } else {
  2433. newData[colSetting.field] = newValue;
  2434. }
  2435. }
  2436. data.updateData.push(newData);
  2437. }
  2438. } else {
  2439. data.updateType = 'update';
  2440. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2441. const curRow = info.cellRange.row + iRow;
  2442. const curPos = sortData[curRow];
  2443. if (curPos) {
  2444. const newData = {pid: curPos.id, lid: curPos.lid};
  2445. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2446. const curCol = info.cellRange.col + iCol;
  2447. const colSetting = info.sheet.zh_setting.cols[curCol];
  2448. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2449. if (colSetting.type === 'Number') {
  2450. if (curPos.settle_status === settleStatus.finish) {
  2451. newData.error = 1;
  2452. continue;
  2453. }
  2454. const exprInfo = getExprInfo(colSetting.field);
  2455. if (!newValue) {
  2456. newData[colSetting.field] = newValue;
  2457. if (exprInfo) newData[exprInfo.expr] = '';
  2458. continue;
  2459. }
  2460. const num = _.toNumber(newValue);
  2461. if (num) {
  2462. newData[colSetting.field] = num;
  2463. if (exprInfo) newData[exprInfo.expr] = '';
  2464. } else {
  2465. try {
  2466. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2467. const exprInfo = getExprInfo(colSetting.field);
  2468. if (exprInfo) newData[exprInfo.expr] = newValue;
  2469. } catch(err) {
  2470. toastr.error('输入的表达式非法');
  2471. stagePosSpreadObj.loadCurPosData();
  2472. return;
  2473. }
  2474. }
  2475. } else if (colSetting.field.indexOf('_expr') > 0) {
  2476. try {
  2477. const exprInfo = getExprInfo(colSetting.field, true);
  2478. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2479. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2480. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2481. }
  2482. } catch (err) {
  2483. toastMessageUniq(hint.expr);
  2484. }
  2485. } else {
  2486. newData[colSetting.field] = newValue;
  2487. }
  2488. }
  2489. if (newData.error === undefined) data.updateData.push(newData);
  2490. }
  2491. }
  2492. }
  2493. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2494. if (result.pos) {
  2495. stagePos.updateDatas(result.pos.pos);
  2496. stagePos.loadCurStageData(result.pos.curStageData);
  2497. }
  2498. const nodes = stageTree.loadPostStageData(result.ledger);
  2499. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2500. stagePosSpreadObj.loadCurPosData();
  2501. if (detail) {
  2502. detail.loadStagePosUpdateData(result, nodes);
  2503. } else {
  2504. stageIm.loadUpdatePosData(result, nodes);
  2505. }
  2506. }, function () {
  2507. stagePosSpreadObj.loadCurPosData();
  2508. });
  2509. }
  2510. },
  2511. deletePress: function (sheet) {
  2512. if (sheet.zh_setting.readOnly) return;
  2513. if (sheet.zh_setting && sheet.zh_data) {
  2514. const sortData = sheet.zh_data;
  2515. if (!sortData || sortData.length === 0) { return; }
  2516. const sel = sheet.getSelections()[0];
  2517. const validCols = [];
  2518. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2519. const colSetting = sheet.zh_setting.cols[iCol];
  2520. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  2521. validCols.push(iCol);
  2522. }
  2523. }
  2524. if (validCols.length === 0) { return; }
  2525. const datas = [], posSelects = [];
  2526. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2527. const node = sortData[iRow];
  2528. if (node) {
  2529. const data = {pid: node.id, lid: node.lid};
  2530. for (const iCol of validCols) {
  2531. const colSetting = sheet.zh_setting.cols[iCol];
  2532. if (colSetting.field === 'name') {
  2533. toastr.error('部位名称不能为空');
  2534. return;
  2535. }
  2536. if (colSetting.Type === 'Number' && node.settle_status === settleStatus.finish) {
  2537. toastr.error('已结算节点不可计量');
  2538. return;
  2539. }
  2540. if (colSetting.field.indexOf('_expr') > 0) {
  2541. const exprInfo = getExprInfo(colSetting.field, true);
  2542. if (!exprInfo) continue;
  2543. data[exprInfo.expr] = '';
  2544. data[exprInfo.qty] = 0;
  2545. } else {
  2546. data[colSetting.field] = null;
  2547. const exprInfo = getExprInfo(colSetting.field);
  2548. if (exprInfo) {
  2549. data[exprInfo.expr] = '';
  2550. }
  2551. }
  2552. }
  2553. datas.push(data);
  2554. posSelects.push(node);
  2555. }
  2556. }
  2557. if (datas.length > 0) {
  2558. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  2559. if (result.pos) {
  2560. stagePos.updateDatas(result.pos.pos);
  2561. stagePos.loadCurStageData(result.pos.curStageData);
  2562. }
  2563. const nodes = stageTree.loadPostStageData(result.ledger);
  2564. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2565. if (detail) {
  2566. detail.loadStagePosUpdateData(result, nodes);
  2567. } else {
  2568. stageIm.loadUpdatePosData(result, nodes);
  2569. }
  2570. // todo 只加载改变项
  2571. stagePosSpreadObj.loadCurPosData();
  2572. });
  2573. }
  2574. }
  2575. },
  2576. deletePos: function (sheet) {
  2577. const sels = sheet.getSelections();
  2578. const sel = sels ? sels[0] : null;
  2579. if (sheet.zh_data && sel) {
  2580. const data = {updateType: 'delete', updateData: []};
  2581. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  2582. const posData = sheet.zh_data[sel.row + iRow];
  2583. if (posData) {
  2584. data.updateData.push(posData.id);
  2585. }
  2586. }
  2587. if (data.updateData.length > 0) {
  2588. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2589. stagePos.removeDatas(result.pos.pos);
  2590. const refreshData = stageTree.loadPostStageData(result.ledger);
  2591. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2592. stagePosSpreadObj.loadCurPosData();
  2593. if (detail) {
  2594. detail.loadStagePosUpdateData(result, refreshData);
  2595. } else {
  2596. stageIm.loadUpdatePosData(result, refreshData);
  2597. }
  2598. });
  2599. }
  2600. }
  2601. },
  2602. selectionChanged: function (e, info) {
  2603. stagePosSpreadObj.loadExprToInput(info.sheet);
  2604. },
  2605. addPegs: function (pegs) {
  2606. if (!pegs || pegs.length <= 0) return;
  2607. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2608. if (!node) return;
  2609. const sheet = spSpread.getActiveSheet();
  2610. const sortData = sheet.zh_data || [];
  2611. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2612. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2613. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2614. if (result.pos) {
  2615. stagePos.updateDatas(result.pos.pos);
  2616. }
  2617. stagePosSpreadObj.loadCurPosData();
  2618. });
  2619. }
  2620. };
  2621. $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
  2622. $('#pos-un-measure').click(stagePosSpreadObj.loadCurPosData);
  2623. // 加载上下窗口resizer
  2624. $.divResizer({
  2625. select: '#main-resize',
  2626. callback: function () {
  2627. slSpread.refresh();
  2628. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2629. $(".sp-wrap").height(bcontent-30);
  2630. spSpread.refresh();
  2631. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2632. }
  2633. });
  2634. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2635. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;reCalcChange' }, function (result) {
  2636. // 加载树结构
  2637. stageTree.loadDatas(result.ledgerData, result.locked);
  2638. if (stage.assist) {
  2639. stageTree.loadFilter(stage.assist.ass_ledger_id);
  2640. } else if (stage.relaAuditor && stage.relaAuditor.audit_ledger_id) {
  2641. stageTree.loadFilter(stage.relaAuditor.audit_ledger_id);
  2642. }
  2643. // 加载部位明细
  2644. stagePos.loadDatas(result.posData);
  2645. stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.reCalcChange);
  2646. checkShowLast(result.ledgerData.length);
  2647. treeCalc.calculateAll(stageTree);
  2648. for (const t of result.tags) {
  2649. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2650. }
  2651. billsTag.loadDatas(result.tags);
  2652. stagePos.calculateAll();
  2653. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2654. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2655. stagePosSpreadObj.loadCurPosData();
  2656. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2657. TreeExprCalc.init({
  2658. tree: stageTree,
  2659. decimal: tenderInfo.decimal,
  2660. precision: tenderInfo.precision,
  2661. calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
  2662. exprFieldsIndex: {
  2663. tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',
  2664. bqhtje: 'contract_tp',
  2665. },
  2666. exprCacheKey: ['bqhtje'],
  2667. });
  2668. // 加载中间计量
  2669. stageIm.init(tenderInfo, stage, imType, tenderInfo.decimal);
  2670. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.stageChange, result.import_change, result.detailAtt);
  2671. if (stage.assist) {
  2672. stageIm.loadFilter(stage.assist.ass_ledger_id);
  2673. } else if (stage.relaAuditor) {
  2674. stageIm.loadFilter(stage.relaAuditor.audit_ledger_id);
  2675. }
  2676. errorList.loadHisErrorData();
  2677. checkList.loadHisCheckData();
  2678. sumLoadMiss.loadHisMissData();
  2679. // 收方单赋值
  2680. ledgerData = result.ledgerData;
  2681. posData = result.posData;
  2682. makeShouFang();
  2683. }, null, true);
  2684. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2685. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2686. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2687. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2688. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2689. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2690. if (!readOnly) {
  2691. $('#pos-expr').bind('change onblur', function () {
  2692. if (this.readOnly) return;
  2693. const expr = $(this);
  2694. const posSheet = spSpread.getActiveSheet();
  2695. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2696. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2697. if (!select) return;
  2698. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2699. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2700. const data = {pid: select.id, lid: select.lid};
  2701. const exprInfo = getExprInfo(field);
  2702. if (newValue !== '') {
  2703. const num = _.toNumber(newValue);
  2704. if (num) {
  2705. data[field] = num;
  2706. if (exprInfo) data[exprInfo.expr] = '';
  2707. } else {
  2708. try {
  2709. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2710. if (exprInfo) data[exprInfo.expr] = newValue;
  2711. } catch (err) {
  2712. toastr.error('输入的表达式非法');
  2713. return;
  2714. }
  2715. }
  2716. } else {
  2717. data[field] = null;
  2718. if (exprInfo) data[exprInfo.expr] = '';
  2719. }
  2720. // 提交数据到服务器
  2721. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2722. if (result.pos) {
  2723. stagePos.updateDatas(result.pos.pos);
  2724. stagePos.loadCurStageData(result.pos.curStageData);
  2725. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2726. }
  2727. const refreshData = stageTree.loadPostStageData(result.ledger);
  2728. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2729. if (detail) {
  2730. detail.loadStagePosUpdateData(result, refreshData);
  2731. } else {
  2732. stageIm.loadUpdatePosData(result, refreshData);
  2733. }
  2734. });
  2735. });
  2736. }
  2737. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2738. $.contextMenu({
  2739. selector: '#stage-pos',
  2740. build: function ($trigger, e) {
  2741. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2742. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2743. },
  2744. items: {
  2745. 'del': {
  2746. name: '删除',
  2747. icon: 'fa-remove',
  2748. visible: function (key, opt) {
  2749. return !checkTzMeasureType();
  2750. },
  2751. disabled: function (key, opt) {
  2752. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2753. if (!node || node.lock) return true;
  2754. const sheet = spSpread.getActiveSheet();
  2755. if (sheet.zh_data && !readOnly) {
  2756. const selection = sheet.getSelections();
  2757. if (selection && selection[0]) {
  2758. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2759. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2760. const posData = sheet.zh_data[selection[0].row + iRow];
  2761. if (posData) {
  2762. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2763. valid = true;
  2764. break;
  2765. }
  2766. } else {
  2767. valid = true;
  2768. break;
  2769. }
  2770. }
  2771. return valid;
  2772. } else {
  2773. return true;
  2774. }
  2775. } else {
  2776. return true;
  2777. }
  2778. },
  2779. callback: function (key, opt) {
  2780. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2781. }
  2782. },
  2783. 'sort': {
  2784. name: '排序',
  2785. items: {
  2786. "addStageReverse": {
  2787. name: '按新增期倒序',
  2788. icon: 'fa-sort-amount-desc',
  2789. callback: function (key, opt) {
  2790. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2791. if (spSheet.zh_data) {
  2792. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2793. SpreadJsObj.reLoadSheetData(spSheet);
  2794. }
  2795. }
  2796. }
  2797. }
  2798. },
  2799. 'merge-peg': {
  2800. name: '合并起讫桩号',
  2801. visible: function (key, opt) {
  2802. return !checkTzMeasureType();
  2803. },
  2804. disabled: function (key, opt) {
  2805. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2806. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2807. },
  2808. callback: function (key, opt) {
  2809. mergePeg.show();
  2810. }
  2811. },
  2812. 'calcByRatio': {
  2813. name: '按比例计量',
  2814. visible: function (key, opt) {
  2815. const data = spSpread.getActiveSheet().zh_data;
  2816. return checkTzMeasureType() && data && data.length > 0;
  2817. },
  2818. disabled: function (key, opt) {
  2819. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2820. return node.lock;
  2821. },
  2822. callback: function (key, opt) {
  2823. $('#cbr-ratio').val('');
  2824. $('#apply2sibling')[0].checked = false;
  2825. $('#cbr-check-all')[0].checked = false;
  2826. const html = [];
  2827. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2828. html.push('<tr>');
  2829. html.push('<td>', i+1, '</td>');
  2830. html.push('<td>', p.name, '</td>');
  2831. html.push('<td>', p.quantity, '</td>');
  2832. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2833. html.push('</tr>');
  2834. }
  2835. $('#cbr-pos-list').html(html.join(''));
  2836. $('#calc-by-ratio').modal('show');
  2837. }
  2838. },
  2839. 'remainCur': {
  2840. name: '填剩余量(选中行)',
  2841. disabled: function (key, opt) {
  2842. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2843. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2844. return readOnly || node.lock || !curPos;
  2845. },
  2846. callback: function (key, opt) {
  2847. const sheet = spSpread.getActiveSheet();
  2848. const sels = sheet.getSelections();
  2849. if (!sels || !sels[0]) return;
  2850. const data = { updateType: 'update', updateData: [] };
  2851. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2852. const curRow = iRow + sels[0].row;
  2853. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2854. if (!curPos) continue;
  2855. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2856. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2857. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2858. }
  2859. if (data.updateData.length > 0) {
  2860. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2861. if (result.pos) {
  2862. stagePos.updateDatas(result.pos.pos);
  2863. stagePos.loadCurStageData(result.pos.curStageData);
  2864. }
  2865. const nodes = stageTree.loadPostStageData(result.ledger);
  2866. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2867. stagePosSpreadObj.loadCurPosData();
  2868. if (detail) {
  2869. detail.loadStagePosUpdateData(result, nodes);
  2870. } else {
  2871. stageIm.loadUpdatePosData(result, nodes);
  2872. }
  2873. });
  2874. }
  2875. },
  2876. visible: function(key, opt) {
  2877. return checkTzMeasureType();
  2878. },
  2879. },
  2880. 'remainAll': {
  2881. name: '填剩余量(全部行)',
  2882. disabled: function (key, opt) {
  2883. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2884. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2885. return readOnly || node.lock || !curPos;
  2886. },
  2887. callback: function (key, opt) {
  2888. const sheet = spSpread.getActiveSheet();
  2889. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2890. const data = { updateType: 'update', updateData: [] };
  2891. for (const curPos of sheet.zh_data) {
  2892. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2893. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2894. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2895. }
  2896. if (data.updateData.length > 0) {
  2897. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2898. if (result.pos) {
  2899. stagePos.updateDatas(result.pos.pos);
  2900. stagePos.loadCurStageData(result.pos.curStageData);
  2901. }
  2902. const nodes = stageTree.loadPostStageData(result.ledger);
  2903. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2904. stagePosSpreadObj.loadCurPosData();
  2905. if (detail) {
  2906. detail.loadStagePosUpdateData(result, nodes);
  2907. } else {
  2908. stageIm.loadUpdatePosData(result, nodes);
  2909. }
  2910. });
  2911. }
  2912. },
  2913. visible: function(key, opt) {
  2914. return checkTzMeasureType();
  2915. },
  2916. },
  2917. 'shoufangdan': {
  2918. name: '生成收方单',
  2919. visible: function(key, opt) {
  2920. if (cur_uid === stage.user_id) return true;
  2921. },
  2922. disabled: function (key, opt) {
  2923. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2924. if (!node || cur_uid !== stage.user_id) return true;
  2925. },
  2926. callback: function (key, opt) {
  2927. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2928. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2929. $('#shoufang-lid').val(node.lid);
  2930. $('#shoufang-pid').val(node.id);
  2931. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2932. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2933. $('#addshoufang').modal('show');
  2934. }
  2935. },
  2936. detail: {
  2937. name: '查看变更后数量明细',
  2938. callback: function(key, opt, menu, e) {
  2939. const curBills = SpreadJsObj.getSelectObject(slSheet);
  2940. const curPos = SpreadJsObj.getSelectObject(spSheet);
  2941. $('#tz2d-hint').html(`当前清单:${curBills.b_code || ''} ${curBills.name || ''} - [${curPos.name || ''}]`);
  2942. $('#tz2d-tz').html(`台账数量:${ curPos.quantity || 0}`);
  2943. $('#tz2d-qc').html(`变更数量:${ ZhCalc.sub(curPos.tz2_qty, curPos.quantity) || 0}`);
  2944. $('#tz2d-sum').html(`变更后数量:${ curPos.tz2_qty || 0}`);
  2945. const html = [];
  2946. html.push('<tr class="text-center"><th>变更令编号</th><th>变更令名称</th><th>计价</th><th>批复数量</th></tr>');
  2947. if (!curPos.changeBills) curPos.changeBills = [];
  2948. for (const cb of curPos.changeBills) {
  2949. html.push(`<tr><td>${cb.code}</td><td>${cb.name}</td><td class="text-center">${ cb.is_valuation ? '√' : '' }</td><td class="text-right">${cb.qty}</td></tr>`);
  2950. }
  2951. $('#tz2d-list').html(html.join(''));
  2952. $('#tz2-detail').modal('show');
  2953. },
  2954. disabled: function(key, opt) {
  2955. const curPos = SpreadJsObj.getSelectObject(spSheet);
  2956. return !curPos;
  2957. }
  2958. },
  2959. }
  2960. });
  2961. $.subMenu({
  2962. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2963. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2964. key: 'menu.1.0.0',
  2965. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2966. callback: function (info) {
  2967. if (info.mini) {
  2968. $('.panel-title').addClass('fluid');
  2969. $('#sub-menu').removeClass('panel-sidebar');
  2970. } else {
  2971. $('.panel-title').removeClass('fluid');
  2972. $('#sub-menu').addClass('panel-sidebar');
  2973. }
  2974. autoFlashHeight();
  2975. slSpread.refresh();
  2976. spSpread.refresh();
  2977. if (searchLedger) searchLedger.spread.refresh();
  2978. if (detail) detail.spread.refresh();
  2979. if (checkedChanges) checkedChanges.refresh();
  2980. if (errorList && errorList.spread) errorList.spread.refresh();
  2981. if (checkList) checkList.spread.refresh();
  2982. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2983. }
  2984. });
  2985. $('#row-view').on('show.bs.modal', function () {
  2986. const html = [], customDisplay = customColDisplay();
  2987. for (const cd of customDisplay) {
  2988. html.push('<tr>');
  2989. html.push('<td>', cd.title, '</td>');
  2990. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2991. html.push('</tr>');
  2992. }
  2993. $('#row-view-list').html(html.join(''));
  2994. });
  2995. $('#row-view-ok').click(function () {
  2996. const customDisplay = customColDisplay();
  2997. const cvl = $('#row-view-list').children();
  2998. for (const cv of cvl) {
  2999. const title = $(cv).children()[0].innerHTML;
  3000. const check = $('input', cv)[0].checked;
  3001. const cd = customDisplay.find(function (c) {
  3002. return c.title === title;
  3003. });
  3004. cd.visible = check;
  3005. }
  3006. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  3007. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  3008. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  3009. $('#row-view').modal('hide');
  3010. });
  3011. const posSearch = (function () {
  3012. let resultArr = [];
  3013. const search = function () {
  3014. resultArr = [];
  3015. const keyword = $('#pos-search-keyword').val();
  3016. const checkOver = $('#pos-over-search')[0].checked;
  3017. const checkEmpty = $('#pos-empty-search')[0].checked;
  3018. const sortData = spSpread.getActiveSheet().zh_data;
  3019. if (checkOver || checkEmpty) {
  3020. if (sortData) {
  3021. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  3022. const sd = sortData[i];
  3023. let match = false;
  3024. if (checkOver) {
  3025. if (sd.end_gather_qty) {
  3026. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  3027. }
  3028. }
  3029. if (checkEmpty) {
  3030. if (sd.quantity) {
  3031. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  3032. }
  3033. }
  3034. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  3035. if (match) {
  3036. resultArr.push({index: i, data: sd});
  3037. }
  3038. }
  3039. }
  3040. } else if (keyword && keyword !== '') {
  3041. if (sortData) {
  3042. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  3043. const sd = sortData[i];
  3044. if (sd.name && sd.name.indexOf(keyword) > -1) {
  3045. resultArr.push({index: i, data: sd});
  3046. }
  3047. }
  3048. }
  3049. }
  3050. $('#pos-search-result').html('结果:' + resultArr.length);
  3051. };
  3052. const searchAndLocate = function () {
  3053. search();
  3054. if (resultArr.length > 0) {
  3055. const sheet = spSpread.getActiveSheet();
  3056. const sel = sheet.getSelections()[0];
  3057. const curRow = sel ? sel.row : 0;
  3058. const pos = resultArr[0];
  3059. if (pos.index !== curRow) {
  3060. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  3061. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  3062. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  3063. }
  3064. }
  3065. };
  3066. const locateNext = function () {
  3067. if (resultArr.length > 0) {
  3068. const sheet = spSpread.getActiveSheet();
  3069. const sel = sheet.getSelections()[0];
  3070. const curRow = sel ? sel.row : 0;
  3071. let next = _.find(resultArr, function (d) {
  3072. return d.index > curRow;
  3073. });
  3074. if (!next) next = resultArr[0];
  3075. if (next.index !== curRow) {
  3076. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  3077. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  3078. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  3079. }
  3080. }
  3081. };
  3082. const locatePre = function () {
  3083. if (resultArr.length > 0) {
  3084. const sheet = spSpread.getActiveSheet();
  3085. const sel = sheet.getSelections()[0];
  3086. const curRow = sel ? sel.row : 0;
  3087. let next = _.findLast(resultArr, function (d) {
  3088. return d.index < curRow;
  3089. });
  3090. if (!next) next = resultArr[resultArr.length - 1];
  3091. if (next.index !== curRow) {
  3092. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  3093. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  3094. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  3095. }
  3096. }
  3097. };
  3098. return {search, searchAndLocate, locateNext, locatePre};
  3099. })();
  3100. $('#pos-search-keyword').bind('keydown', function(e){
  3101. if (e.keyCode == 13) posSearch.searchAndLocate();
  3102. });
  3103. $('#pos-empty-search').click(function () {
  3104. if (this.checked) {
  3105. $('[for=' + this.id +']').addClass('text-warning');
  3106. } else {
  3107. $('[for=' + this.id +']').removeClass('text-warning');
  3108. }
  3109. if (this.checked) {
  3110. if ($('#pos-over-search')[0].checked) {
  3111. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3112. } else {
  3113. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3114. }
  3115. } else {
  3116. if ($('#pos-over-search')[0].checked) {
  3117. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3118. } else {
  3119. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3120. }
  3121. }
  3122. posSearch.searchAndLocate();
  3123. });
  3124. $('#pos-over-search').click(function () {
  3125. if (this.checked) {
  3126. $('[for=' + this.id +']').addClass('text-danger');
  3127. } else {
  3128. $('[for=' + this.id +']').removeClass('text-danger');
  3129. }
  3130. if (this.checked) {
  3131. if ($('#pos-empty-search')[0].checked) {
  3132. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3133. } else {
  3134. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3135. }
  3136. } else {
  3137. if ($('#pos-empty-search')[0].checked) {
  3138. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3139. } else {
  3140. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3141. }
  3142. }
  3143. posSearch.searchAndLocate();
  3144. });
  3145. $('#pos-search-next').click(() => {posSearch.locateNext()});
  3146. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  3147. $.divResizer({
  3148. select: '#right-spr',
  3149. callback: function () {
  3150. autoFlashHeight();
  3151. slSpread.refresh();
  3152. spSpread.refresh();
  3153. if (searchLedger) {
  3154. searchLedger.spread.refresh();
  3155. }
  3156. if (detail) {
  3157. detail.spread.refresh();
  3158. }
  3159. if (checkedChanges) checkedChanges.refresh();
  3160. if (errorList && errorList.spread) errorList.spread.refresh();
  3161. if (checkList) checkList.spread.refresh();
  3162. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3163. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3164. }
  3165. });
  3166. // 中间计量加载上下窗口resizer
  3167. $.divResizer({
  3168. select: '#zhongjian-spr',
  3169. callback: function () {
  3170. if (detail) {
  3171. detail.spread.refresh();
  3172. }
  3173. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3174. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3175. }
  3176. });
  3177. // 附件加载上下窗口resizer
  3178. $.divResizer({
  3179. select: '#file-spr',
  3180. callback: function () {
  3181. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3182. }
  3183. });
  3184. // 变更令加载上下窗口resizer
  3185. $.divResizer({
  3186. select: '#change-spr',
  3187. callback: function () {
  3188. if (checkedChanges) checkedChanges.refresh();
  3189. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3190. }
  3191. });
  3192. class Detail {
  3193. constructor (obj) {
  3194. const self = this;
  3195. this.spreadSetting = {
  3196. cols: [
  3197. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3198. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3199. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3200. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  3201. {
  3202. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  3203. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  3204. },
  3205. {
  3206. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  3207. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  3208. return data.attachment ? data.attachment.length : 0;
  3209. }
  3210. },
  3211. ],
  3212. headRows: 1,
  3213. emptyRows: 0,
  3214. headRowHeight: [32],
  3215. headColWidth: [30],
  3216. defaultRowHeight: 21,
  3217. headerFont: '12px 微软雅黑',
  3218. font: '12px 微软雅黑',
  3219. readOnly: readOnly,
  3220. selectedBackColor: '#fffacd',
  3221. imageClick: function (data) {
  3222. self.makeAttTable(data);
  3223. $('#im-file').modal('show');
  3224. }
  3225. };
  3226. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  3227. this.sheet = this.spread.getActiveSheet();
  3228. this.spread.options.allowUserDragFill = true;
  3229. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  3230. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3231. this.detailObj = {
  3232. selectionChanged: function (e, info) {
  3233. self.reLoadDetailData();
  3234. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  3235. self.loadLocateInfo();
  3236. }
  3237. },
  3238. editEnded: function(e, info) {
  3239. if (info.sheet.zh_setting) {
  3240. const col = info.sheet.zh_setting.cols[info.col];
  3241. if (col.field !== 'doc_code') {
  3242. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3243. return;
  3244. }
  3245. const data = SpreadJsObj.getSelectObject(info.sheet);
  3246. if (data) {
  3247. const updateData = {lid: data.lid, pid: data.pid};
  3248. if (data.uuid) {
  3249. updateData.uuid = data.uuid;
  3250. } else {
  3251. updateData.code = data.code;
  3252. updateData.name = data.name;
  3253. updateData.unit = data.unit;
  3254. updateData.unit_price = data.unit_price;
  3255. updateData.pid = data.pid;
  3256. updateData.pos_name = data.pos_name;
  3257. updateData.im_type = data.im_type;
  3258. }
  3259. if (data.custom_define.indexOf('doc_code') === -1) {
  3260. updateData.custom_define = data.custom_define;
  3261. updateData.custom_define.push('doc_code');
  3262. updateData.custom_define = updateData.custom_define.join(',');
  3263. }
  3264. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  3265. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3266. stageIm.loadUpdateDetailData(result);
  3267. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3268. }, function () {
  3269. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3270. });
  3271. } else {
  3272. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3273. }
  3274. }
  3275. },
  3276. clipboardPasted: function (e, info) {
  3277. if (info.sheet.zh_setting && info.sheet.zh_data) {
  3278. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  3279. if (info.cellRange.colCount > 1) {
  3280. toastr.warning('请勿同时复制粘贴多列数据');
  3281. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3282. return;
  3283. }
  3284. if (col.field !== 'doc_code') {
  3285. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3286. return;
  3287. }
  3288. const datas = [];
  3289. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3290. const curRow = info.cellRange.row + iRow;
  3291. const data = info.sheet.zh_data[curRow];
  3292. if (data) {
  3293. const updateData = {lid: data.lid, pid: data.pid};
  3294. if (data.uuid) {
  3295. updateData.uuid = data.uuid;
  3296. } else {
  3297. updateData.code = data.code;
  3298. updateData.name = data.name;
  3299. updateData.unit = data.unit;
  3300. updateData.unit_price = data.unit_price;
  3301. updateData.pid = data.pid;
  3302. updateData.pos_name = data.pos_name;
  3303. updateData.im_type = data.im_type;
  3304. }
  3305. if (data.custom_define.indexOf('doc_code') === -1) {
  3306. updateData.custom_define = data.custom_define;
  3307. updateData.custom_define.push('doc_code');
  3308. updateData.custom_define = updateData.custom_define.join(',');
  3309. }
  3310. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  3311. datas.push(updateData);
  3312. }
  3313. }
  3314. if (datas.length > 0) {
  3315. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3316. stageIm.loadUpdateDetailData(result);
  3317. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3318. }, function () {
  3319. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3320. })
  3321. }
  3322. }
  3323. },
  3324. deletePress: function (sheet) {
  3325. if (sheet.zh_setting) {
  3326. const datas = [];
  3327. const sel = sheet.getSelections()[0];
  3328. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3329. const col = sheet.zh_setting.cols[iCol];
  3330. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3331. const data = sheet.zh_data[iRow];
  3332. if (col.field === 'doc_code') {
  3333. const updateData = {lid: data.lid};
  3334. if (data.uuid) {
  3335. updateData.uuid = data.uuid;
  3336. updateData.doc_code = '';
  3337. datas.push(updateData);
  3338. }
  3339. }
  3340. }
  3341. }
  3342. if (datas.length > 0) {
  3343. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3344. stageIm.loadUpdateDetailData(result);
  3345. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3346. }, function () {
  3347. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3348. });
  3349. }
  3350. }
  3351. },
  3352. dragFillBlock: function (e, info) {
  3353. info.cancel = true;
  3354. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  3355. const sel = info.sheet.getSelections()[0];
  3356. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  3357. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  3358. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  3359. if (text === '') return;
  3360. const regRst = /(\d+)$/g.exec(text), datas = [];
  3361. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  3362. const curRow = info.fillRange.row + iRow;
  3363. const data = info.sheet.zh_data[curRow];
  3364. if (data) {
  3365. const updateData = {lid: data.lid};
  3366. if (data.uuid) {
  3367. updateData.uuid = data.uuid;
  3368. } else {
  3369. updateData.code = data.code;
  3370. updateData.name = data.name;
  3371. updateData.unit = data.unit;
  3372. updateData.unit_price = data.unit_price;
  3373. updateData.pid = data.pid;
  3374. updateData.pos_name = data.pos_name;
  3375. updateData.im_type = data.im_type;
  3376. }
  3377. if (regRst) {
  3378. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  3379. } else {
  3380. updateData.doc_code = text.replace('\n', '');
  3381. }
  3382. if (data.custom_define.indexOf('doc_code') === -1) {
  3383. updateData.custom_define = data.custom_define;
  3384. updateData.custom_define.push('doc_code');
  3385. updateData.custom_define = updateData.custom_define.join(',');
  3386. }
  3387. datas.push(updateData);
  3388. }
  3389. }
  3390. if (datas.length > 0) {
  3391. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3392. stageIm.loadUpdateDetailData(result);
  3393. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3394. }, function () {
  3395. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3396. })
  3397. }
  3398. },
  3399. };
  3400. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  3401. if (!readOnly) {
  3402. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  3403. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  3404. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  3405. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  3406. }
  3407. this._initImTypeSetRela();
  3408. this._initModifyDetail();
  3409. this._initLocateRela();
  3410. this._initAttRela();
  3411. // 草图相关
  3412. this._initImageRela();
  3413. this.reBuildImData();
  3414. }
  3415. makeAttTable (data) {
  3416. let html = [];
  3417. if (data.attachment) {
  3418. for (const att of data.attachment) {
  3419. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked || deleteFilePermission))
  3420. ? '<a class="delete-att text-danger ml-1" href="javascript:void(0);" data-imid="'+ data.att_uuid +'" data-attid="'+ att.file_id +'" title="删除"><i class="fa fa-remove "></i></a>'
  3421. : '';
  3422. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  3423. const downloadHtml = '<a href="'+ window.location.pathname + '/im-file/download?im_id='+ data.att_uuid +'&file_id='+ att.file_id +'" title="下载"><i class="fa fa-download "></i></a>';
  3424. html.push(`<tr><td><input type="checkbox" name="sia-check" fid="${att.file_id}"></td><td style="width: 200px">` + att.filename + att.fileext + '</td><td>' + att.username + '</td><td>' + att.in_time + '</td>',
  3425. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  3426. }
  3427. }
  3428. $('#im-attList').html(html.join(''));
  3429. }
  3430. _initAttRela() {
  3431. // 上传附件
  3432. const self = this;
  3433. $('#upload-im-file').change(function () {
  3434. const files = this.files;
  3435. const sels = self.sheet.getSelections();
  3436. const select = SpreadJsObj.getSelectObject(self.sheet);
  3437. if (!select) return;
  3438. const formData = new FormData();
  3439. const baseInfo = {};
  3440. if (select.att_uuid) {
  3441. baseInfo.uuid = select.att_uuid;
  3442. } else {
  3443. baseInfo.im_type = select.im_type;
  3444. baseInfo.lid = select.lid;
  3445. baseInfo.pid = select.pid;
  3446. baseInfo.code = select.code;
  3447. baseInfo.name = select.name;
  3448. baseInfo.unit = select.unit;
  3449. baseInfo.unit_price = select.unit_price;
  3450. baseInfo.pos_name = select.pos_name;
  3451. }
  3452. formData.append('base', JSON.stringify(baseInfo));
  3453. for (const file of files) {
  3454. if (file === undefined) {
  3455. toast('未选择上传文件!', 'error');
  3456. return false;
  3457. }
  3458. const filesize = file.size;
  3459. if (filesize > 50 * 1024 * 1024) {
  3460. toast('存在上传文件大小过大!', 'error');
  3461. return false;
  3462. }
  3463. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3464. if (whiteList.indexOf(fileext) === -1) {
  3465. toast('只能上传指定格式的附件!', 'error');
  3466. return false;
  3467. }
  3468. formData.append('size', filesize);
  3469. formData.append('file[]', file);
  3470. }
  3471. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  3472. stageIm.loadUpdateDetailAtt(data);
  3473. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3474. self.makeAttTable(select);
  3475. $('#upload-im-file').val('');
  3476. });
  3477. });
  3478. // 删除附件
  3479. $('body').on('click', '.delete-att' ,function () {
  3480. const sels = self.sheet.getSelections();
  3481. const select = SpreadJsObj.getSelectObject(self.sheet);
  3482. if (!select) return;
  3483. const uuid = $(this).attr('data-imid');
  3484. const file_id = $(this).attr('data-attid');
  3485. const att = select.attachment.find(x => {
  3486. return x.file_id === file_id;
  3487. });
  3488. deleteAfterHint(function () {
  3489. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  3490. stageIm.loadUpdateDetailAtt(result);
  3491. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3492. self.makeAttTable(select);
  3493. });
  3494. }, `确认删除附件「${att.filename}」?`);
  3495. });
  3496. // 预览附件
  3497. $('body').on('click', '.preview-att', function () {
  3498. const uuid = $(this).attr('data-imid');
  3499. const file_id = $(this).attr('data-attid');
  3500. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  3501. const { filepath } = result;
  3502. $('#load-file').attr('href', filepath);
  3503. $('#load-file')[0].click();
  3504. });
  3505. });
  3506. $('#batch-download-im-file').click(function() {
  3507. const select = $('[name=sia-check]:checked');
  3508. if (select.length === 0) {
  3509. toastr.warning('请选择需要批量下载的文件');
  3510. return;
  3511. }
  3512. const files = [];
  3513. const curIm = SpreadJsObj.getSelectObject(self.sheet);
  3514. for (const s of select) {
  3515. const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
  3516. if (att) files.push(att);
  3517. }
  3518. if (files.length === 0) return;
  3519. AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
  3520. $(self).removeAttr('disabled');
  3521. if (fails.length === 0) {
  3522. toastr.success('下载成功');
  3523. } else {
  3524. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  3525. }
  3526. }, () => {
  3527. $(self).removeAttr('disabled');
  3528. toastr.error('批量下载失败');
  3529. });
  3530. });
  3531. }
  3532. _initImTypeSetRela() {
  3533. const self = this;
  3534. const gatherConfirmPopover = {
  3535. reBind: function (obj, eventName, fun) {
  3536. obj.unbind(eventName);
  3537. obj.bind(eventName, fun);
  3538. },
  3539. check: function (pos, hint, okCallback) {
  3540. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  3541. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  3542. this.reBind(cancelObj, 'click', function () {
  3543. confirmObj.hide();
  3544. });
  3545. this.reBind(okObj, 'click', function () {
  3546. okCallback();
  3547. confirmObj.hide();
  3548. });
  3549. hintObj.text(hint);
  3550. confirmObj.css("top", pos.y).css("left", pos.x).show();
  3551. }
  3552. };
  3553. this.gsTree = stageIm.getGsTree();
  3554. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3555. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3556. jlCol.title = '本期计量金额';
  3557. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3558. $('[name=type-title-contract]').text('本期合同计量金额');
  3559. $('[name=type-title-qc]').text('本期变更计量金额');
  3560. if ($('#show-qc-minus-jl').length > 0) {
  3561. $('#show-qc-minus-jl').parent().hide();
  3562. $('#qc-minus-jl').parent().hide();
  3563. }
  3564. } else {
  3565. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3566. jlCol.title = '本期计量数量';
  3567. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3568. $('[name=type-title-contract]').text('本期合同计量数量');
  3569. $('[name=type-title-qc]').text('本期变更计量数量');
  3570. if ($('#show-qc-minus-jl').length > 0) {
  3571. $('#show-qc-minus-jl').parent().show();
  3572. $('#qc-minus-jl').parent().show();
  3573. }
  3574. }
  3575. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3576. $('#show-jldy').parent().show();
  3577. $('#jldy').parent().show();
  3578. $('#show-xm-name').parent().hide();
  3579. $('#xm-name').parent().hide();
  3580. } else {
  3581. $('#show-jldy').parent().hide();
  3582. $('#jldy').parent().hide();
  3583. $('#show-xm-name').parent().show();
  3584. $('#xm-name').parent().show();
  3585. }
  3586. // 选择中间计量模式
  3587. $('div[name="im-type"]').click(function () {
  3588. function chooseType(obj) {
  3589. obj.style.cursor = 'default';
  3590. $(obj).children().addClass('text-primary');
  3591. $(obj).addClass('border-primary');
  3592. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3593. }
  3594. function validType(obj) {
  3595. obj.style.cursor = 'pointer';
  3596. $(obj).children().removeClass('text-primary');
  3597. $(obj).removeClass('border-primary');
  3598. $('i', obj).remove();
  3599. }
  3600. if (this.style.cursor === 'pointer') {
  3601. const typeArr = $('div[name="im-type"]');
  3602. for (const t of typeArr) {
  3603. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  3604. chooseType(t);
  3605. } else {
  3606. validType(t)
  3607. }
  3608. }
  3609. }
  3610. });
  3611. $('#choose').on('show.bs.modal', function () {
  3612. function chooseType(obj) {
  3613. obj.style.cursor = 'default';
  3614. $(obj).children().addClass('text-primary');
  3615. $('i', obj).remove();
  3616. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3617. }
  3618. function validType(obj) {
  3619. obj.style.cursor = 'pointer';
  3620. $(obj).children().removeClass('text-primary');
  3621. $('i', obj).remove();
  3622. }
  3623. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  3624. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  3625. const typeArr = $('div[name="im-type"]');
  3626. for (const t of typeArr) {
  3627. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  3628. chooseType(t);
  3629. } else {
  3630. validType(t)
  3631. }
  3632. }
  3633. });
  3634. // 提交 中间计量模式
  3635. $('#choose-ok').click(() => {
  3636. let startNum;
  3637. try {
  3638. startNum = parseInt($('#im-start-num').val());
  3639. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  3640. } catch (err) {
  3641. toastr.error("起始编号请输入正整数");
  3642. return;
  3643. }
  3644. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  3645. return it.style.cursor !== 'pointer';
  3646. });
  3647. const data = {
  3648. im_type: parseInt($(chooseType).attr('im-type')),
  3649. im_pre: $('#im-pre').val(),
  3650. im_start_num: startNum,
  3651. };
  3652. postData(window.location.pathname + '/detail/build', data, function (result) {
  3653. stage.im_type = data.im_type;
  3654. stage.im_pre = data.im_pre;
  3655. stage.im_start_num = data.im_start_num;
  3656. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3657. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3658. jlCol.title = '本期计量金额';
  3659. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3660. $('[name=type-title-contract]').text('本期合同计量金额');
  3661. $('[name=type-title-qc]').text('本期变更计量金额');
  3662. if ($('#show-qc-minus-jl').length > 0) {
  3663. $('#show-qc-minus-jl').parent().hide();
  3664. $('#qc-minus-jl').parent().hide();
  3665. }
  3666. } else {
  3667. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3668. jlCol.title = '本期计量数量';
  3669. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3670. $('[name=type-title-contract]').text('本期合同计量数量');
  3671. $('[name=type-title-qc]').text('本期变更计量数量');
  3672. if ($('#show-qc-minus-jl').length > 0) {
  3673. $('#show-qc-minus-jl').parent().show();
  3674. $('#qc-minus-jl').parent().show();
  3675. }
  3676. }
  3677. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3678. $('#show-jldy').parent().show();
  3679. $('#jldy').parent().show();
  3680. $('#show-xm-name').parent().hide();
  3681. $('#xm-name').parent().hide();
  3682. } else {
  3683. $('#show-jldy').parent().hide();
  3684. $('#jldy').parent().hide();
  3685. $('#show-xm-name').parent().show();
  3686. $('#xm-name').parent().show();
  3687. }
  3688. // 加载生成数据
  3689. self.reBuildImData();
  3690. $('#choose').modal('hide');
  3691. });
  3692. });
  3693. // 显示树结构信息
  3694. $('#choose2').on('shown.bs.modal', function () {
  3695. if (!self.gsSpread) {
  3696. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3697. const setting = {
  3698. cols: [
  3699. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3700. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3701. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3702. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3703. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3704. ],
  3705. headRows: 1,
  3706. emptyRows: 0,
  3707. headRowHeight: [32],
  3708. defaultRowHeight: 21,
  3709. headerFont: '12px 微软雅黑',
  3710. font: '12px 微软雅黑',
  3711. };
  3712. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3713. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3714. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3715. function checkParent(node) {
  3716. const parent = self.gsTree.getParent(node);
  3717. if (parent) {
  3718. return parent.check ? parent.check : checkParent(parent);
  3719. } else {
  3720. return false;
  3721. }
  3722. }
  3723. function checkChildren(node) {
  3724. for (const child of node.children) {
  3725. if (child.check) {
  3726. return true;
  3727. } else if (checkChildren(child)) {
  3728. return true;
  3729. }
  3730. }
  3731. return false;
  3732. }
  3733. if (!$('#im-gather-check')[0].checked) { return; }
  3734. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3735. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3736. if (sheet.isEditing()) {
  3737. sheet.endEdit(true);
  3738. }
  3739. }
  3740. if (info.sheet.zh_setting) {
  3741. const col = info.sheet.zh_setting.cols[info.col];
  3742. if (col.field !== 'check') {
  3743. return;
  3744. }
  3745. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3746. const node = sortData[info.row];
  3747. if (!node.check) {
  3748. if (checkParent(node)) {
  3749. const rect = info.sheet.getCellRect(info.row, info.col);
  3750. gatherConfirmPopover.check({
  3751. x: rect.x + rect.width / 2 + 25,
  3752. y: rect.y + rect.height / 2 + 3,
  3753. }, '父项已勾选,继续将取消父项勾选。', function () {
  3754. node.check = true;
  3755. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3756. const rows = [self.gsTree.nodes.indexOf(node)];
  3757. for (const p of parents) {
  3758. if (p.check) {
  3759. p.check = false;
  3760. rows.push(self.gsTree.nodes.indexOf(p));
  3761. }
  3762. }
  3763. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3764. });
  3765. } else if (checkChildren(node)) {
  3766. const rect = info.sheet.getCellRect(info.row, info.col);
  3767. gatherConfirmPopover.check({
  3768. x: rect.x + rect.width / 2 + 25,
  3769. y: rect.y + rect.height / 2 + 3,
  3770. }, '子项已勾选,继续将取消子项勾选。', function () {
  3771. node.check = true;
  3772. const posterity = self.gsTree.getPosterity(node);
  3773. const rows = [self.gsTree.nodes.indexOf(node)];
  3774. for (const p of posterity) {
  3775. if (p.check) {
  3776. rows.push(self.gsTree.nodes.indexOf(p));
  3777. p.check = false;
  3778. }
  3779. }
  3780. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3781. });
  3782. } else {
  3783. node.check = true;
  3784. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3785. }
  3786. } else {
  3787. node.check = false;
  3788. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3789. }
  3790. }
  3791. });
  3792. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3793. for (const node of self.gsTree.datas) {
  3794. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3795. }
  3796. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3797. self.gsTree.expandByLevel(4);
  3798. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3799. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3800. } else {
  3801. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3802. for (const node of self.gsTree.datas) {
  3803. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3804. }
  3805. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3806. }
  3807. });
  3808. // 提交 高级设置
  3809. $('#choose2-ok').click(() => {
  3810. if (!self.gsTree) { return; }
  3811. const nodes = [];
  3812. for (const node of self.gsTree.datas) {
  3813. if (node.check) {
  3814. nodes.push(node.id);
  3815. }
  3816. }
  3817. const data = {
  3818. im_gather: $('#im-gather-check')[0].checked,
  3819. im_gather_node: nodes.join(','),
  3820. };
  3821. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3822. stage.im_gather = data.im_gather;
  3823. stage.im_gather_node = data.im_gather_node;
  3824. $('#choose2').modal('hide');
  3825. });
  3826. });
  3827. }
  3828. _initLocateRela() {
  3829. const self = this;
  3830. $('#im-locate2bills').click(function () {
  3831. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3832. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3833. if (select && select.source) {
  3834. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3835. stagePosSpreadObj.loadCurPosData();
  3836. if (select.source[curIndex-1].pos_id) {
  3837. SpreadJsObj.locateDataBy(spSpread.getActiveSheet(), function(data){ return data.id === select.source[curIndex-1].pos_id});
  3838. }
  3839. }
  3840. });
  3841. $('#im-locate-pre').click(function () {
  3842. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3843. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3844. if (select && select.source) {
  3845. const targetIndex = Math.max(curIndex-1, 1);
  3846. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3847. stagePosSpreadObj.loadCurPosData();
  3848. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3849. }
  3850. });
  3851. $('#im-locate-next').click(function () {
  3852. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3853. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3854. if (select && select.source) {
  3855. const targetIndex = Math.min(curIndex+1, select.source.length);
  3856. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3857. stagePosSpreadObj.loadCurPosData();
  3858. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3859. }
  3860. });
  3861. }
  3862. _initModifyDetail() {
  3863. const self = this;
  3864. // 重置
  3865. $('#reset-detail-ok').click(function () {
  3866. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3867. if (!data.uuid) return;
  3868. const updateData = {
  3869. lid: data.lid, pid: data.pid,
  3870. uuid: data.uuid,
  3871. custom_define: [],
  3872. };
  3873. for (const f of data.custom_define) {
  3874. if (stageIm.resetFields.indexOf(f) >= 0) {
  3875. updateData[f] = null;
  3876. } else {
  3877. updateData.custom_define.push(f);
  3878. }
  3879. }
  3880. updateData.custom_define = updateData.custom_define.join(',');
  3881. $('#reset-detail-modal').modal('hide');
  3882. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3883. stageIm.loadUpdateDetailData(result);
  3884. self.reLoadDetailData();
  3885. });
  3886. });
  3887. // 编辑
  3888. $('#edit-detail').click(function () {
  3889. $(this).hide();
  3890. $('#save-detail').show();
  3891. $('#cancel-detail').show();
  3892. $('#detail-show').hide();
  3893. $('#detail-edit').show();
  3894. self.updateImageData = null;
  3895. });
  3896. // 保存
  3897. $('#save-detail').click(() => {
  3898. function check(field, obj, org, update) {
  3899. const newValue = obj.val();
  3900. if (!org[field]) {
  3901. if (newValue !== '') {
  3902. update[field] = newValue;
  3903. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3904. return true;
  3905. }
  3906. } else if (newValue !== org[field]){
  3907. update[field] = newValue;
  3908. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3909. return true;
  3910. }
  3911. return false;
  3912. }
  3913. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3914. const updateData = {lid: data.lid, pid: data.pid};
  3915. if (data.uuid) {
  3916. updateData.uuid = data.uuid;
  3917. updateData.custom_define = data.custom_define;
  3918. } else {
  3919. updateData.code = data.code;
  3920. updateData.name = data.name;
  3921. updateData.unit = data.unit;
  3922. updateData.unit_price = data.unit_price;
  3923. updateData.pid = data.pid;
  3924. updateData.pos_name = data.pos_name;
  3925. updateData.im_type = data.im_type;
  3926. updateData.custom_define = [];
  3927. }
  3928. let infoUpdate = false;
  3929. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3930. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3931. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3932. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3933. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3934. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3935. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3936. updateData.custom_define = updateData.custom_define.join(',');
  3937. if (infoUpdate) {
  3938. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3939. stageIm.loadUpdateDetailData(result);
  3940. self.reLoadDetailData();
  3941. if (!self.updateImageData) return;
  3942. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3943. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3944. stageIm.loadUpdateDetailData(result);
  3945. self.reLoadDetailData();
  3946. });
  3947. });
  3948. } else if (self.updateImageData) {
  3949. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3950. stageIm.loadUpdateDetailData(result);
  3951. self.reLoadDetailData();
  3952. });
  3953. } else {
  3954. self.reLoadDetailData();
  3955. }
  3956. });
  3957. // 取消
  3958. $('#cancel-detail').click(() => {
  3959. self.reLoadDetailData();
  3960. });
  3961. }
  3962. _initImageRela() {
  3963. const self = this;
  3964. $('#edit-detail').click(function () {
  3965. loadImageItem();
  3966. });
  3967. function setdraggrable(){
  3968. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3969. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3970. stop: function( event, ui ) {
  3971. }
  3972. });
  3973. }
  3974. function upload(formData) {
  3975. if (formData.length < 1) {
  3976. return;
  3977. }
  3978. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3979. const html = [];
  3980. html.push('<div class="img-item">');
  3981. html.push('<div class="img-bar">');
  3982. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3983. html.push('</div>');
  3984. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3985. html.push('</div>');
  3986. $('.img-view').append(html.join(''));
  3987. $('.img-bar').click(removeImageItem);
  3988. setdraggrable();
  3989. $('#upload-img-file').val('');
  3990. });
  3991. }
  3992. function dragFile(e) {
  3993. var file = null,
  3994. data = e.dataTransfer.types;
  3995. for (var i = 0; i < data.length; i += 1) {
  3996. if (data[i] === 'Files') {
  3997. file = e.dataTransfer.files; //获取文件
  3998. break;
  3999. }
  4000. }
  4001. if (file && file[0].type.indexOf('image') !== -1) {
  4002. var formData = new FormData();
  4003. formData.append('file', file[0]); //上传单个文件的添加方式
  4004. upload(formData); //upload 异步上传
  4005. }
  4006. }
  4007. // 移动图片
  4008. const moveImageItem = function (ev) {
  4009. const item = this;
  4010. const view = $('.img-view')[0];
  4011. let oEvent = ev;
  4012. // 浏览器有一些图片的默认事件,这里要阻止
  4013. oEvent.preventDefault();
  4014. let disX = oEvent.clientX - item.offsetLeft;
  4015. let disY = oEvent.clientY - item.offsetTop;
  4016. view.onmousemove = function (ev) {
  4017. oEvent = ev;
  4018. oEvent.preventDefault();
  4019. let x = oEvent.clientX -disX;
  4020. let y = oEvent.clientY -disY;
  4021. // 图形移动的边界判断
  4022. x = x <= 0 ? 0 : x;
  4023. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  4024. y = y <= 0 ? 0 : y;
  4025. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  4026. item.style.left = x + 'px';
  4027. item.style.top = y + 'px';
  4028. };
  4029. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  4030. view.onmouseleave = function () {
  4031. view.onmousemove = null;
  4032. view.onmouseup = null;
  4033. };
  4034. // 鼠标弹起后停止移动
  4035. view.onmouseup=function() {
  4036. view.onmousemove = null;
  4037. view.onmouseup = null;
  4038. };
  4039. };
  4040. const removeImageItem = function () {
  4041. $(this).parent().remove();
  4042. };
  4043. // 加载草图组成
  4044. const loadImageItem = function () {
  4045. self.updateImageData = null;
  4046. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  4047. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  4048. const html = [];
  4049. for (const item of items) {
  4050. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  4051. html.push('<div class="img-item" style="' + itemStyle + '">');
  4052. html.push('<div class="img-bar">');
  4053. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  4054. html.push('</div>');
  4055. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  4056. html.push('</div>');
  4057. }
  4058. $('.img-view').html(html.join(''));
  4059. $('.img-bar').click(removeImageItem);
  4060. setdraggrable();
  4061. };
  4062. // 上传图片
  4063. $('#upload-img').click(function () {
  4064. $('#upload-img-file').trigger('click');
  4065. });
  4066. // 拖拽上传
  4067. //拖拽上传文件
  4068. const dragbox = document.querySelector('#upload-img');
  4069. dragbox.addEventListener('dragover', function(e) {
  4070. e.preventDefault(); // 必须阻止默认事件
  4071. }, false);
  4072. dragbox.addEventListener('drop', function(e) {
  4073. e.preventDefault(); // 阻止默认事件
  4074. dragFile(e);
  4075. }, false);
  4076. //拖拽上传文件
  4077. const dragbox2 = document.querySelector('.img-view');
  4078. dragbox2.addEventListener('dragover', function(e) {
  4079. e.preventDefault(); // 必须阻止默认事件
  4080. }, false);
  4081. dragbox2.addEventListener('drop', function(e) {
  4082. e.preventDefault(); // 阻止默认事件
  4083. dragFile(e);
  4084. }, false);
  4085. // 粘贴上传
  4086. $(".img-view").on('paste', function(ev) {
  4087. let file = null;
  4088. const data = (event.clipboardData || window.clipboardData).items;
  4089. for (let i = 0; i < data.length; i += 1) {
  4090. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  4091. file = data[i].getAsFile(); //读取图片文件
  4092. break;
  4093. }
  4094. }
  4095. if (file) {
  4096. const formData = new FormData();
  4097. formData.append('file', file); //上传单个文件的添加方式
  4098. upload(formData); //异步上传文件
  4099. }
  4100. });
  4101. $('#upload-img-file').change(function () {
  4102. const file = this.files[0];
  4103. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  4104. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  4105. if (!imgStr.test(ext)) {
  4106. toastr.error('请上传正确的图片格式文件');
  4107. return
  4108. }
  4109. if ($(this).val()) {
  4110. const formData = new FormData();
  4111. formData.append('file', this.files[0]);
  4112. upload(formData);
  4113. }
  4114. });
  4115. // 保存草图修改结果
  4116. $('#edit-img-ok').click(function () {
  4117. // 记录上传的图片的信息
  4118. const items = $('.img-item');
  4119. const img_remark = $('#text-edit').val();
  4120. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  4121. // 生成上传数据
  4122. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  4123. if (data.uuid) {
  4124. updateData.uuid = data.uuid;
  4125. } else {
  4126. updateData.code = data.code;
  4127. updateData.name = data.name;
  4128. updateData.unit = data.unit;
  4129. updateData.unit_price = data.unit_price;
  4130. updateData.pid = data.pid;
  4131. updateData.pos_name = data.pos_name;
  4132. updateData.im_type = data.im_type;
  4133. }
  4134. if (items.length === 1) {
  4135. const itemInfo = [];
  4136. for (const item of items) {
  4137. const itemData = {
  4138. src: $('img', item).attr('src'),
  4139. left: item.style.left,
  4140. top: item.style.top,
  4141. width: item.style.width,
  4142. height: item.style.height,
  4143. };
  4144. itemInfo.push(itemData);
  4145. }
  4146. // 获取合并好的图片数据
  4147. const canvas = document.createElement('canvas');
  4148. const view = $('.img-view')[0];
  4149. const b = items[0];
  4150. const pos = $(b).position();
  4151. const img = $('img', b)[0];
  4152. canvas.height = Math.max(view.clientHeight, Math.ceil(pos.top + img.naturalHeight));
  4153. canvas.width = Math.max(view.clientWidth, Math.ceil(pos.left + img.naturalWidth));
  4154. const ctx = canvas.getContext('2d');
  4155. ctx.fillStyle = '#ffffff';
  4156. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4157. ctx.drawImage(img, pos.left, pos.top);
  4158. updateData.img = canvas.toDataURL('image/png');
  4159. updateData.imgInfo = itemInfo;
  4160. self.updateImageData = updateData;
  4161. $('#calc-img').attr('src', updateData.img);
  4162. $('#calc-remark').html(img_remark);
  4163. $('#view-calc-img').attr('src', updateData.img);
  4164. $('#show-calc-img').attr('src', updateData.img);
  4165. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4166. $('#view-calc-remark').text(img_remark);
  4167. $('#edit-img').modal('hide');
  4168. } else if (items.length > 0) {
  4169. const itemInfo = [];
  4170. for (const item of items) {
  4171. const itemData = {
  4172. src: $('img', item).attr('src'),
  4173. left: item.style.left,
  4174. top: item.style.top,
  4175. width: item.style.width,
  4176. height: item.style.height,
  4177. };
  4178. itemInfo.push(itemData);
  4179. }
  4180. // 获取合并好的图片数据
  4181. const canvas = document.createElement('canvas');
  4182. const view = $('.img-view')[0];
  4183. canvas.height = view.clientHeight;
  4184. canvas.width = view.clientWidth;
  4185. const ctx = canvas.getContext('2d');
  4186. ctx.fillStyle = '#ffffff';
  4187. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4188. for (const b of $('.img-item')) {
  4189. const pos = $(b).position();
  4190. const img = $('img', b)[0];
  4191. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  4192. }
  4193. updateData.img = canvas.toDataURL('image/png');
  4194. updateData.imgInfo = itemInfo;
  4195. self.updateImageData = updateData;
  4196. $('#calc-img').attr('src', updateData.img);
  4197. $('#calc-remark').html(img_remark);
  4198. $('#view-calc-img').attr('src', updateData.img);
  4199. $('#show-calc-img').attr('src', updateData.img);
  4200. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4201. $('#view-calc-remark').text(img_remark);
  4202. $('#edit-img').modal('hide');
  4203. // });
  4204. } else if (data.calc_img) {
  4205. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  4206. $('#show-calc-img').attr('src', '');
  4207. $('#show-calc-remark').html('');
  4208. $('#calc-img').attr('src', '');
  4209. $('#calc-remark').html(img_remark);
  4210. $('#view-calc-img').attr('src', '');
  4211. $('#view-calc-remark').val(img_remark);
  4212. $('#text-edit').val(img_remark);
  4213. $('#edit-img').modal('hide');
  4214. } else {
  4215. self.updateImageData = updateData;
  4216. $('#show-calc-img').attr('src', '');
  4217. $('#show-calc-remark').html('');
  4218. $('#calc-img').attr('src', '');
  4219. $('#calc-remark').html(img_remark);
  4220. $('#view-calc-img').attr('src', '');
  4221. $('#view-calc-remark').val(img_remark);
  4222. $('#text-edit').val(img_remark);
  4223. $('#edit-img').modal('hide');
  4224. }
  4225. });
  4226. }
  4227. reBuildImData() {
  4228. const imData = stageIm.buildImData();
  4229. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4230. this.reLoadDetailData();
  4231. this.loadLocateInfo();
  4232. }
  4233. loadStageLedgerUpdateData(data, nodes) {
  4234. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  4235. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4236. this.reLoadDetailData();
  4237. }
  4238. loadStagePosUpdateData(data, nodes) {
  4239. const imData = stageIm.loadUpdatePosData(data, nodes);
  4240. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4241. this.reLoadDetailData();
  4242. }
  4243. loadStageChangeUpdateData(data, nodes) {
  4244. const imData = stageIm.loadUpdateChangeData(data, nodes);
  4245. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4246. this.reLoadDetailData();
  4247. }
  4248. loadLocateInfo() {
  4249. const select = SpreadJsObj.getSelectObject(this.sheet);
  4250. if (select && select.source.length > 1) {
  4251. $('#im-locate2bills').next().show();
  4252. } else {
  4253. $('#im-locate2bills').next().hide();
  4254. }
  4255. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  4256. }
  4257. reLoadDetailData() {
  4258. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  4259. $('#reset-detail').hide();
  4260. if (data) {
  4261. for (const f of data.custom_define) {
  4262. if (stageIm.resetFields.indexOf(f) >= 0) {
  4263. $('#reset-detail').show();
  4264. break;
  4265. }
  4266. }
  4267. $('#edit-detail').show();
  4268. $('#modify-img').show();
  4269. } else {
  4270. $('#edit-detail').hide();
  4271. $('#modify-img').hide();
  4272. }
  4273. $('#save-detail').hide();
  4274. $('#cancel-detail').hide();
  4275. $('#detail-show').show();
  4276. $('#detail-edit').hide();
  4277. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  4278. $('#show-contract-jl').text(contractJl);
  4279. $('#contract-jl').val(contractJl);
  4280. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  4281. $('#show-qc-jl').text(qcJl);
  4282. $('#qc-jl').val(qcJl);
  4283. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  4284. $('#show-qc-minus-jl').text(qcMinusJl);
  4285. $('#qc-minus-jl').val(qcMinusJl);
  4286. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  4287. $('#show-bgl-code').text(bglCode);
  4288. $('#bgl-code').val(bglCode);
  4289. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  4290. $('#show-bgl-drawing-code').text(bglDrawingCode);
  4291. $('#bgl-drawing-code').val(bglDrawingCode);
  4292. const bwName = data && data.bw ? data.bw : '';
  4293. $('#show-bw-name').text(bwName);
  4294. $('#bw-name').val(bwName);
  4295. const position = data && data.position ? data.position : '';
  4296. $('#show-position').text(position);
  4297. $('#position').val(position);
  4298. const peg = data && data.peg ? data.peg : '';
  4299. $('#show-peg').text(peg);
  4300. $('#peg').val(peg);
  4301. const xmName = data && data.xm ? data.xm: '';
  4302. $('#show-xm-name').text(xmName);
  4303. $('#xm-name').val(xmName);
  4304. const jldy = data && data.jldy ? data.jldy: '';
  4305. $('#show-jldy').text(jldy);
  4306. $('#jldy').val(jldy);
  4307. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  4308. $('#show-drawing-code').text(drawingCode);
  4309. $('#drawing-code').val(drawingCode);
  4310. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  4311. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  4312. $('#calc-memo').val(calcMemo);
  4313. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  4314. $('#show-calc-img').attr('src', calcImgSrc);
  4315. $('#calc-img').attr('src', calcImgSrc);
  4316. $('#view-calc-img').attr('src', calcImgSrc);
  4317. const calcImgRemark = data && data.calc_img_remark || '';
  4318. $('#view-calc-remark').val(calcImgRemark);
  4319. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  4320. $('#calc-remark').html(calcImgRemark);
  4321. $("#view-calc-remark").attr('readonly', true);
  4322. // 处理 编辑 -> 添加草图中textarea多余的空格
  4323. $('#text-edit').val(calcImgRemark)
  4324. }
  4325. }
  4326. class CheckedChange {
  4327. constructor (setting) {
  4328. const self = this;
  4329. this.changeSpreadSetting = {
  4330. cols: [
  4331. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: function (x) { return x.t_name ? `所属标段:${x.t_name}` : ''; }},
  4332. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  4333. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4334. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  4335. ],
  4336. emptyRows: 0,
  4337. headRows: 1,
  4338. headRowHeight: [32],
  4339. headColWidth: [30],
  4340. defaultRowHeight: 21,
  4341. headerFont: '12px 微软雅黑',
  4342. font: '12px 微软雅黑',
  4343. readOnly: true,
  4344. getColor: function (sheet, data, row, col, defaultColor) {
  4345. if (data && data.is_import) {
  4346. return '#eee';
  4347. } else {
  4348. return defaultColor;
  4349. }
  4350. }
  4351. };
  4352. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  4353. this.changeSheet = this.changeSpread.getActiveSheet();
  4354. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  4355. const getTipText = function (data) {
  4356. if (!data) return '';
  4357. const tips = [];
  4358. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  4359. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  4360. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  4361. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  4362. return tips.join('-');
  4363. };
  4364. this.changeBillsSpreadSetting = {
  4365. cols: [
  4366. {title: '计价', colSpan: '1', rowSpan: '1', field: 'is_valuation', hAlign: 1, width: 30, cellType: 'checkbox'},
  4367. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  4368. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
  4369. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4370. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  4371. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  4372. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  4373. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  4374. ],
  4375. emptyRows: 0,
  4376. headRows: 1,
  4377. headRowHeight: [32],
  4378. defaultRowHeight: 21,
  4379. headerFont: '12px 微软雅黑',
  4380. font: '12px 微软雅黑',
  4381. readOnly: true
  4382. };
  4383. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  4384. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  4385. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  4386. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  4387. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4388. if (change) self.refreshChangeDetailData(change);
  4389. });
  4390. this.changes = null;
  4391. this.reloadChangeData();
  4392. setting.reloadObj.click(function() {
  4393. self.reloadChangeData();
  4394. });
  4395. $.contextMenu({
  4396. selector: '#' + setting.changeBillsObj.attr('id'),
  4397. build: function ($trigger, e) {
  4398. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  4399. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4400. },
  4401. items: {
  4402. 'locateZjjl': {
  4403. name: '定位至台账',
  4404. icon: 'fa-sign-in',
  4405. callback: function (key, opt) {
  4406. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4407. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4408. if (change.is_import) {
  4409. if (changeBills.pos && changeBills.pos.length > 0) {
  4410. const node = stageTree.getItems(changeBills.pos[0].ledger_id);
  4411. if (!node || node.filter) return;
  4412. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  4413. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4414. stagePosSpreadObj.loadCurPosData();
  4415. }
  4416. } else if (changeBills.gcl_id) {
  4417. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4418. if (!node || node.filter) return;
  4419. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  4420. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4421. stagePosSpreadObj.loadCurPosData();
  4422. const posData = spSpread.getActiveSheet().zh_data;
  4423. if (!posData || posData.length === 0) return;
  4424. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4425. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  4426. } else {
  4427. const cb = {
  4428. b_code: changeBills.code || '',
  4429. name: changeBills.name || '',
  4430. unit: changeBills.unit || '',
  4431. unit_price: changeBills.unit_price || 0,
  4432. };
  4433. for (const node of stageTree.nodes) {
  4434. if (node.children && node.children.length > 0) continue;
  4435. if (node.filter) continue;
  4436. const b = {
  4437. b_code: node.b_code || '',
  4438. name: node.name || '',
  4439. unit: node.unit || '',
  4440. unit_price: node.unit_price || 0,
  4441. };
  4442. if (_.isMatch(cb, b)) {
  4443. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  4444. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4445. stagePosSpreadObj.loadCurPosData();
  4446. return;
  4447. }
  4448. }
  4449. }
  4450. },
  4451. disabled: function (key, opt) {
  4452. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4453. return !changeBills;
  4454. }
  4455. },
  4456. 'autoUse': {
  4457. name: '调用',
  4458. icon: 'fa-play',
  4459. callback: function (key, opt) {
  4460. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4461. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4462. const billsPos = self.findBillsPos(curChange, changeBills);
  4463. if (!billsPos) {
  4464. toastr.warning('无可调用的清单或计量单元');
  4465. return;
  4466. }
  4467. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
  4468. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4469. if (result.pos) {
  4470. stagePos.loadCurStageData(result.pos.curStageData);
  4471. }
  4472. const nodes = stageTree.loadPostStageData(result.bills);
  4473. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4474. stagePosSpreadObj.loadCurPosData();
  4475. if (detail) {
  4476. detail.loadStageChangeUpdateData(result, nodes);
  4477. } else {
  4478. stageIm.loadUpdateChangeData(result, nodes)
  4479. }
  4480. });
  4481. },
  4482. disabled: function (key, opt) {
  4483. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4484. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4485. return !changeBills || curChange.is_import;
  4486. },
  4487. visible: function (key, opt) {
  4488. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4489. }
  4490. },
  4491. }
  4492. });
  4493. $.contextMenu({
  4494. selector: '#' + setting.changeObj.attr('id'),
  4495. build: function ($trigger, e) {
  4496. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  4497. const change = target.cellTypeHintInfo ? self.changes[target.cellTypeHitInfo.row] : null;
  4498. if (change) self.refreshChangeDetailData(change);
  4499. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4500. },
  4501. items: {
  4502. 'autoUseCur': {
  4503. name: '自动调用',
  4504. icon: 'fa-play',
  4505. callback: function (key, opt) {
  4506. checkAgainHint(function(){
  4507. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4508. const changeBills = self.changeBillsSheet.zh_data;
  4509. const data = { bills: [], autoType: 'bills' };
  4510. for (const cb of changeBills) {
  4511. const billsPos = self.findBillsPos(curChange, cb);
  4512. if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
  4513. }
  4514. if (data.bills.length === 0) {
  4515. toastr.warning('无可调用的清单或计量单元');
  4516. return;
  4517. }
  4518. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4519. if (result.pos) {
  4520. stagePos.loadCurStageData(result.pos.curStageData);
  4521. }
  4522. const nodes = stageTree.loadPostStageData(result.bills);
  4523. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4524. stagePosSpreadObj.loadCurPosData();
  4525. if (detail) {
  4526. detail.loadStageChangeUpdateData(result, nodes);
  4527. } else {
  4528. stageIm.loadUpdateChangeData(result, nodes)
  4529. }
  4530. });
  4531. }, ['自动调用后,已调用变更令无法批量取消,请谨慎操作。', '确定自动调用变更令?']);
  4532. },
  4533. disabled: function (key, opt) {
  4534. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4535. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4536. return !curChange || !changeBills || curChange.is_import;
  4537. },
  4538. visible: function (key, opt) {
  4539. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4540. }
  4541. },
  4542. 'autoUseAll': {
  4543. name: '自动调用(全部变更令)',
  4544. icon: 'fa-play',
  4545. callback: function (key, opt) {
  4546. checkAgainHint(function(){
  4547. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  4548. window.location.reload();
  4549. });
  4550. }, ['自动调用后,已调用变更令无法批量取消,请谨慎操作。', '确定自动调用变更令?']);
  4551. },
  4552. disabled: function (key, opt) {
  4553. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4554. return !curChange || curChange.is_import;
  4555. },
  4556. visible: function (key, opt) {
  4557. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4558. }
  4559. }
  4560. }
  4561. });
  4562. }
  4563. refreshChangeDetailData(data) {
  4564. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4565. if (change.cid === this.curChangeId) return;
  4566. this.curChangeId = change.cid;
  4567. const self = this;
  4568. if (change.detail) {
  4569. self.loadChangeDetailData();
  4570. } else {
  4571. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  4572. change.detail = result;
  4573. self.analyzeChange(change);
  4574. self.loadChangeDetailData();
  4575. });
  4576. }
  4577. }
  4578. loadChangeDetailData(data) {
  4579. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4580. if (change) {
  4581. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  4582. } else {
  4583. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  4584. }
  4585. }
  4586. refresh() {
  4587. this.changeSpread.refresh();
  4588. this.changeBillsSpread.refresh();
  4589. }
  4590. reloadChangeData() {
  4591. const self = this;
  4592. postData(window.location.pathname + '/change/data', null, function (result) {
  4593. self.changes = [];
  4594. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  4595. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  4596. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  4597. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  4598. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  4599. self.changeSheet.setSelection(0, 0, 1, 1);
  4600. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  4601. self.loadChangeDetailData();
  4602. });
  4603. }
  4604. _analyzeCommon(change) {
  4605. for (const b of change.bills) {
  4606. const eub = change.detail.endUsedBills.find(function (x) {
  4607. return x.cbid === b.id;
  4608. });
  4609. if (eub) b.used_qty = eub.qty;
  4610. b.qty = _.toNumber(b.samount);
  4611. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  4612. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4613. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  4614. b.cur_qty = 0;
  4615. for (const p of b.pos) {
  4616. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  4617. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  4618. }
  4619. }
  4620. }
  4621. _analyzeImport(change) {
  4622. for (const b of change.bills) {
  4623. const eub = change.detail.endUsedBills.find(function (x) {
  4624. return x.rela_cbid === b.id;
  4625. });
  4626. if (eub) b.used_qty = eub.rela_qty;
  4627. b.qty = _.toNumber(b.samount);
  4628. delete b.unit_price;
  4629. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4630. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  4631. b.cur_qty = 0;
  4632. for (const p of b.pos) {
  4633. p.qty = p.rela_qty;
  4634. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  4635. p.ledger_id = node.ledger_id;
  4636. p.f_qty = node.quantity;
  4637. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  4638. }
  4639. }
  4640. }
  4641. analyzeChange(change) {
  4642. change.bills = change.detail.bills;
  4643. if (change.is_import) {
  4644. this._analyzeImport(change);
  4645. } else {
  4646. this._analyzeCommon(change);
  4647. }
  4648. }
  4649. findBillsPos(change, changeBills) {
  4650. if (change.is_import) {
  4651. return null;
  4652. } else if (changeBills.gcl_id) {
  4653. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4654. if (node.filter) return null;
  4655. if (node.settle_status === settleStatus.finish) return null;
  4656. const posData = stagePos.getLedgerPos(node.id) || [];
  4657. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4658. if (changePos && changePos.settle_status) return null;
  4659. let defaultPos;
  4660. if (posData.length > 0) {
  4661. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4662. if (!defaultPos) return null;
  4663. } else {
  4664. defaultPos = { id: '-1' };
  4665. }
  4666. return { lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
  4667. } else {
  4668. const cb = {
  4669. b_code: changeBills.code || '',
  4670. name: changeBills.name || '',
  4671. unit: changeBills.unit || '',
  4672. unit_price: changeBills.unit_price || 0,
  4673. };
  4674. for (const node of stageTree.nodes) {
  4675. if (node.children && node.children.length > 0) continue;
  4676. if (node.filter) continue;
  4677. if (node.settle_status === settleStatus.finish) continue;
  4678. const b = {
  4679. b_code: node.b_code || '',
  4680. name: node.name || '',
  4681. unit: node.unit || '',
  4682. unit_price: node.unit_price || 0,
  4683. };
  4684. if (_.isMatch(cb, b)) {
  4685. posData = stagePos.getLedgerPos(node.id) || [];
  4686. let defaultPos;
  4687. if (posData.length > 0) {
  4688. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4689. if (!defaultPos) return null;
  4690. } else {
  4691. defaultPos = { id: '-1' };
  4692. }
  4693. return { lid: node.id, pid: defaultPos.id };
  4694. }
  4695. }
  4696. return null;
  4697. }
  4698. }
  4699. }
  4700. // 展开收起附件
  4701. $('a', '.right-nav').bind('click', function () {
  4702. //const main = $('#main-view'), tool = $('#tools-view');
  4703. const tab = $(this), tabPanel = $(tab.attr('content'));
  4704. if (!tab.hasClass('active')) {
  4705. $('a', '.side-menu').removeClass('active');
  4706. $('.tab-content .tab-select-show').removeClass('active');
  4707. tab.addClass('active');
  4708. tabPanel.addClass('active');
  4709. showSideTools(tab.hasClass('active'));
  4710. if (tab.attr('content') === '#search' && !searchLedger) {
  4711. searchLedger = $.ledgerSearch({
  4712. selector: '#search',
  4713. ledger: { billsTree: stageTree, pos: stagePos },
  4714. searchOver: true,
  4715. searchEmpty: true,
  4716. resultSpreadSetting: {
  4717. cols: [
  4718. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4719. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4720. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4721. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4722. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4723. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4724. {title: '完成率(%)', field: completePerField, hAlign: 2, width: 70},
  4725. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4726. ],
  4727. emptyRows: 0,
  4728. headRows: 1,
  4729. headRowHeight: [32],
  4730. headColWidth: [30],
  4731. defaultRowHeight: 21,
  4732. headerFont: '12px 微软雅黑',
  4733. font: '12px 微软雅黑',
  4734. selectedBackColor: '#fffacd',
  4735. readOnly: true,
  4736. },
  4737. locate: function(cur) {
  4738. if (!cur.lid) return;
  4739. SpreadJsObj.locateTreeNode(slSheet, cur.lid, true);
  4740. stageTreeSpreadObj.loadRelaData();
  4741. if (cur.pid && cur.pid !== -1) {
  4742. const pIndex = spSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4743. SpreadJsObj.locateRow(spSheet, pIndex);
  4744. }
  4745. },
  4746. customSearch: [
  4747. {
  4748. key: 'less', title: '漏计', valid: true,
  4749. check: function (node) {
  4750. if (node.quantity) {
  4751. return ZhCalc.sub(ZhCalc.sum([node.quantity, node.end_qc_qty, node.end_qc_minus_qty]), node.end_gather_qty) > 0;
  4752. } else if (node.total_price) {
  4753. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  4754. }
  4755. }
  4756. }, {
  4757. key: 'over', title: '超计', valid: true,
  4758. check: function (node) {
  4759. return checkUtils.billsOver(node, stagePos, tenderInfo.checkOverInfo);
  4760. }
  4761. }, {
  4762. key: 'empty', title: '漏计', valid: false,
  4763. check: function (node) {
  4764. if (node.quantity) {
  4765. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4766. } else if (node.total_price) {
  4767. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4768. }
  4769. }
  4770. }, {
  4771. key: 'estimate', title: '预计变更', valid: true,
  4772. check: function (node) {
  4773. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4774. if (posRange.length > 0) {
  4775. for (const p of posRange) {
  4776. if (!checkZero(p.estimate_qty)) return true;
  4777. }
  4778. return false;
  4779. } else {
  4780. return false;
  4781. }
  4782. }
  4783. }
  4784. ],
  4785. });
  4786. searchLedger.spread.refresh();
  4787. }
  4788. if (tab.attr('content') === '#fujian') {
  4789. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4790. node && getNodeList(node.id);
  4791. }
  4792. if (tab.attr('content') === '#zhongjian') {
  4793. if (!detail) {
  4794. detail = new Detail($('#detail-spread'));
  4795. detail.spread.refresh();
  4796. $('#zhongjian .sjs-bottom').height('400px');
  4797. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4798. } else {
  4799. detail.spread.refresh();
  4800. }
  4801. }
  4802. if (tab.attr('content') === '#checked-change') {
  4803. if (!checkedChanges) {
  4804. checkedChanges = new CheckedChange({
  4805. changeObj: $('#cc-spread'),
  4806. changeBillsObj: $('#ccb-spread'),
  4807. reloadObj: $('#refresh-cc'),
  4808. });
  4809. checkedChanges.refresh();
  4810. } else {
  4811. $('#ccb-spread').height('400px');
  4812. checkedChanges.refresh();
  4813. }
  4814. }
  4815. if (tab.attr('content') === '#error-list') {
  4816. errorList.spread.refresh();
  4817. }
  4818. if (tab.attr('content') === '#check-list') {
  4819. checkList.spread.refresh();
  4820. }
  4821. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4822. } else {
  4823. tab.removeClass('active');
  4824. tabPanel.removeClass('active');
  4825. showSideTools(tab.hasClass('active'));
  4826. }
  4827. autoFlashHeight();
  4828. slSpread.refresh();
  4829. spSpread.refresh();
  4830. });
  4831. // 切换附件里节点和所有附件
  4832. $('#fujian .nav-link').on('click', function () {
  4833. const tabPanel = $(this).attr('fujian-content');
  4834. if (tabPanel !== 'syfujian') {
  4835. $('#showPage').hide();
  4836. $('#bach-download').prop('type', 'curr');
  4837. } else {
  4838. $('#showPage').show();
  4839. $('#bach-download').prop('type', 'all')
  4840. }
  4841. $('#showAttachment').hide();
  4842. });
  4843. // 上传附件
  4844. $('#upload-file-btn').click(function () {
  4845. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4846. if (!node) return
  4847. const files = $('#upload-file')[0].files;
  4848. const formData = new FormData();
  4849. formData.append('lid', node.id);
  4850. for (const file of files) {
  4851. if (file === undefined) {
  4852. toastr.error('未选择上传文件!');
  4853. return false;
  4854. }
  4855. const filesize = file.size;
  4856. if (filesize > 50 * 1024 * 1024) {
  4857. toastr.error('存在上传文件大小过大!');
  4858. return false;
  4859. }
  4860. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4861. if (whiteList.indexOf(fileext) === -1) {
  4862. toastr.error('只能上传指定格式的附件!');
  4863. return false;
  4864. }
  4865. formData.append('size', filesize);
  4866. formData.append('file[]', file);
  4867. }
  4868. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4869. $('#upload').modal('hide');
  4870. // 插入到attData中
  4871. attData = data.concat(attData);
  4872. // 重新生成List
  4873. getAllList();
  4874. getNodeList(node.id);
  4875. }, function () {
  4876. toastr.error('附件上传失败');
  4877. });
  4878. $('#upload-file').val('');
  4879. });
  4880. // 获取附件信息
  4881. $('.list-table').on('click', '.att-file-name', function () {
  4882. const fid = $(this).attr('file-id');
  4883. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4884. return;
  4885. }
  4886. const att = attData.find(function (item) {
  4887. return item.id === parseInt(fid);
  4888. });
  4889. $('#edit-att').hide();
  4890. $('#show-att').show();
  4891. if (att !== undefined) {
  4892. // 进来先把编辑功能隐藏
  4893. $('#btn-att a').eq(3).hide()
  4894. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4895. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4896. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4897. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4898. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4899. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4900. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4901. $('#show-att tr').eq(3).children('td').text(att.remark);
  4902. // 附件uid等于当前用户id, 附件上传本人
  4903. if (parseInt(cur_uid) === att.uid) {
  4904. $('#btn-att').show();
  4905. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4906. if (showDel) $('#btn-att a').eq(3).show();
  4907. // $('#btn-att a').eq(3).show();
  4908. $('#btn-att a').eq(2).hide();
  4909. $('#btn-att a').eq(4).hide();
  4910. $('#btn-att a').eq(5).hide();
  4911. } else {
  4912. $('#btn-att').hide();
  4913. $('#btn-att a').eq(3).hide();
  4914. $('#btn-att a').eq(2).hide();
  4915. $('#btn-att a').eq(4).hide();
  4916. $('#btn-att a').eq(5).hide();
  4917. }
  4918. $('#showAttachment').attr('file-id', fid);
  4919. $('#showAttachment').show();
  4920. } else {
  4921. $('#showAttachment').hide();
  4922. $('#showAttachment').attr('file-id', '');
  4923. toastr.error('附件信息获取失败');
  4924. }
  4925. });
  4926. // $('body').on('click', '.alllist-table a', handleFileList);
  4927. $('body').on('click', '#btn-att a', function () {
  4928. const content = $(this).attr('content');
  4929. const fid = $('#showAttachment').attr('file-id');
  4930. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4931. if (content === 'edit') {
  4932. $('#btn-att a').eq(3).hide();
  4933. $('#btn-att a').eq(2).show();
  4934. $('#btn-att a').eq(4).show();
  4935. $('#btn-att a').eq(5).show();
  4936. $('#show-att').hide();
  4937. $('#edit-att').show();
  4938. const att = attData.find(function (item) {
  4939. return item.id === parseInt(fid);
  4940. });
  4941. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4942. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4943. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4944. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4945. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4946. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4947. } else if (content === 'cancel') {
  4948. $('#show-att').show();
  4949. $('#edit-att').hide();
  4950. $('#btn-att a').eq(3).show();
  4951. $('#btn-att a').eq(2).hide();
  4952. $('#btn-att a').eq(4).hide();
  4953. $('#btn-att a').eq(5).hide();
  4954. } else if (content === 'save') {
  4955. const formData = new FormData();
  4956. formData.append('id', fid);
  4957. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4958. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4959. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4960. const file = $('#change-att-btn')[0];
  4961. if (file.files[0] !== undefined) {
  4962. const filesize = file.files[0].size;
  4963. formData.append('size', filesize);
  4964. formData.append('file', file.files[0]);
  4965. }
  4966. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4967. // 替换到attData中
  4968. const att_index = attData.findIndex(function (item) {
  4969. return item.id === parseInt(fid);
  4970. });
  4971. attData.splice(att_index, 1, data);
  4972. // 重新生成List
  4973. getAllList(parseInt($('#currentPage').text()));
  4974. getNodeList(node.id);
  4975. $('#show-att').show();
  4976. $('#edit-att').hide();
  4977. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4978. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4979. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4980. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4981. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4982. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4983. $('#show-att tr').eq(4).children('td').text(data.remark);
  4984. $('#btn-att a').eq(3).show();
  4985. $('#btn-att a').eq(2).hide();
  4986. $('#btn-att a').eq(4).hide();
  4987. $('#btn-att a').eq(5).hide();
  4988. }, function () {
  4989. toastr.error('附件上传失败');
  4990. });
  4991. $('#change-att-btn').val('');
  4992. } else if (content === 'del') {
  4993. const data = {id: fid};
  4994. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4995. // 删除到attData中
  4996. const att_index = attData.findIndex(function (item) {
  4997. return item.id === parseInt(fid);
  4998. });
  4999. attData.splice(att_index, 1);
  5000. // 重新生成List
  5001. if ($('#alllist-table tr').length === 1) {
  5002. getAllList(parseInt($('#currentPage').text()) - 1);
  5003. } else {
  5004. getAllList(parseInt($('#currentPage').text()));
  5005. }
  5006. getNodeList(node.id);
  5007. $('#showAttachment').hide();
  5008. $('#showAttachment').attr('file-id', '');
  5009. });
  5010. } else if (content === 'view') {
  5011. const data = {id: fid};
  5012. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  5013. const { filepath } = result
  5014. $('#load-file').attr('href', filepath);
  5015. $('#load-file')[0].click();
  5016. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  5017. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  5018. });
  5019. } else if (content === 'location') {
  5020. const att = attData.find(item => item.id === parseInt(fid));
  5021. if (Object.keys(att).length) {
  5022. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  5023. stagePosSpreadObj.loadCurPosData();
  5024. }
  5025. }
  5026. });
  5027. // 替换附件
  5028. $('#change-att-btn').on('change', function () {
  5029. const file = $('#change-att-btn')[0].files[0];
  5030. const name = file.name;
  5031. const filename = name.substring(0, name.lastIndexOf("."));
  5032. const fileext = name.substr(name.indexOf("."));
  5033. const filesize = file.size;
  5034. if (filesize > 50 * 1024 * 1024) {
  5035. toastr.error('文件大小过大!');
  5036. $('#change-att-btn').val('');
  5037. return false;
  5038. }
  5039. if (whiteList.indexOf(fileext) === -1) {
  5040. toastr.error('只能上传指定格式的附件!');
  5041. $('#change-att-btn').val('');
  5042. return false;
  5043. }
  5044. $('#edit-att .form-group').eq(0).find('input').val(filename);
  5045. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  5046. });
  5047. // 切换页数
  5048. $('.page-select').on('click', function () {
  5049. const totalPageNum = parseInt($('#totalPage').text());
  5050. const lastPageNum = parseInt($('#currentPage').text());
  5051. const status = $(this).attr('content');
  5052. if (status === 'pre' && lastPageNum > 1) {
  5053. getAllList(lastPageNum-1);
  5054. $('#showAttachment').hide();
  5055. $('#syfujian .check-all-file').prop('checked', false)
  5056. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5057. getAllList(lastPageNum+1);
  5058. $('#showAttachment').hide();
  5059. $('#syfujian .check-all-file').prop('checked', false)
  5060. }
  5061. });
  5062. // 批量下载
  5063. $('#bach-download').click(function() {
  5064. const fileIds = [];
  5065. const type = $(this).attr('type');
  5066. let node = ''
  5067. if (type === 'curr') {
  5068. node = '#nodelist-table .check-file:checked'
  5069. } else {
  5070. node = '#alllist-table .check-file:checked'
  5071. }
  5072. $(node).each(function() {
  5073. const fileId = $(this).attr('file-id');
  5074. fileId && fileIds.push(fileId);
  5075. });
  5076. if (fileIds.length) {
  5077. if (fileIds.length > 20) {
  5078. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  5079. }
  5080. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  5081. $(this).attr('disabled', "true")
  5082. const btn = $(this);
  5083. const fileArr = [];
  5084. for (const id of fileIds) {
  5085. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  5086. fileArr.push({
  5087. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  5088. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  5089. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  5090. });
  5091. }
  5092. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  5093. try {
  5094. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  5095. } catch (e) {
  5096. btn.removeAttr('disabled');
  5097. toastr.clear();
  5098. toastr.error('批量下载失败');
  5099. }
  5100. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  5101. // toastr.clear()
  5102. // toastr.success('压缩文件成功')
  5103. // btn.removeAttr('disabled')
  5104. // const href = window.URL.createObjectURL(result)
  5105. // $('#zipDown').attr('href', href);
  5106. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  5107. // $("#zipDown")[0].click();
  5108. // }, () => {
  5109. // btn.removeAttr('disabled')
  5110. // toastr.clear()
  5111. // toastr.error('批量下载失败')
  5112. // });
  5113. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  5114. // $('#zipDown').attr('href', url);
  5115. // $("#zipDown")[0].click();
  5116. }
  5117. });
  5118. // 监听附件check是否选中
  5119. $('.list-table').on('click', '.check-file', function() {
  5120. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  5121. const childs = $(this).parents('.list-table').children().length;
  5122. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  5123. if (checkedList.length === childs) {
  5124. checkBox.prop("checked", true);
  5125. } else {
  5126. checkBox.prop("checked", false);
  5127. }
  5128. });
  5129. $('.check-all-file').click(function() {
  5130. const isCheck = $(this).is(':checked');
  5131. $(this).parents('table').find('.list-table').each(function() {
  5132. $(this).find('input:checkbox').prop("checked", isCheck);
  5133. })
  5134. });
  5135. // 显示层次
  5136. (function (select, sheet) {
  5137. $(select).click(function () {
  5138. if (!sheet.zh_tree) return;
  5139. const tag = $(this).attr('tag');
  5140. const tree = sheet.zh_tree;
  5141. setTimeout(() => {
  5142. showWaitingView();
  5143. switch (tag) {
  5144. case "1":
  5145. case "2":
  5146. case "3":
  5147. case "4":
  5148. case "5":
  5149. tree.expandByLevel(parseInt(tag));
  5150. SpreadJsObj.refreshTreeRowVisible(sheet);
  5151. break;
  5152. case "last":
  5153. tree.expandByCustom(() => { return true; });
  5154. SpreadJsObj.refreshTreeRowVisible(sheet);
  5155. break;
  5156. case "leafXmj":
  5157. tree.expandToLeafXmj();
  5158. SpreadJsObj.refreshTreeRowVisible(sheet);
  5159. break;
  5160. case "curMeasure":
  5161. tree.expandByCustom(function (node) {
  5162. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  5163. if (node[field]) {
  5164. return true;
  5165. }
  5166. }
  5167. return false;
  5168. });
  5169. SpreadJsObj.refreshTreeRowVisible(sheet);
  5170. break;
  5171. case "endMeasure":
  5172. tree.expandByCustom(function (node) {
  5173. for (const field of ['contract_tp', 'qc_tp', 'gather_tp', 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp']) {
  5174. if (node[field]) {
  5175. return true;
  5176. }
  5177. }
  5178. return false;
  5179. });
  5180. SpreadJsObj.refreshTreeRowVisible(sheet);
  5181. break;
  5182. }
  5183. closeWaitingView();
  5184. }, 100);
  5185. });
  5186. })('a[name=showLevel]', slSpread.getActiveSheet());
  5187. const stageCheckerSetting = {
  5188. ledgerTree: stageTree,
  5189. ledgerPos: stagePos,
  5190. checkList: checkList,
  5191. decimal: tenderInfo.decimal,
  5192. checkOption: checkOption,
  5193. };
  5194. if (!checkTzMeasureType()) {
  5195. stageCheckerSetting.checkOption.tp.fields.push(
  5196. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  5197. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  5198. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  5199. {qty: 'quantity', tp: 'total_price'},
  5200. );
  5201. }
  5202. $('#ledger-check2').click(() => {
  5203. ledgerCheck2(stageCheckerSetting).then(result => {
  5204. check2Viewing({
  5205. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  5206. randomWait: true,
  5207. prefix: 'check2-',
  5208. checks: result,
  5209. checkList: checkList,
  5210. });
  5211. });
  5212. });
  5213. const dataChecker = DataChecker({
  5214. checkUrl: window.location.pathname + '/check',
  5215. completeData: function (data) {
  5216. stagePos.updateDatas({pos: data.source.pos});
  5217. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  5218. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  5219. stagePosSpreadObj.loadCurPosData();
  5220. for (const e of data.error) {
  5221. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  5222. }
  5223. },
  5224. errorList: errorList,
  5225. });
  5226. $('[name=stage-start]').submit(function (e) {
  5227. if (checkAuditorFrom()) {
  5228. // 再检查多人协同确认情况
  5229. const list = stage.relaAssists.find(x => {return !x.confirm });
  5230. if(list) {
  5231. toastr.error('请检查多人协同确认情况再上报');
  5232. $('#hide-all').hide();
  5233. return false;
  5234. }
  5235. $(this).parent().parent().parent().modal('hide');
  5236. dataChecker.checkAndPost(this.action, {});
  5237. $('#hide-all').hide();
  5238. }
  5239. return false;
  5240. });
  5241. $('#audit-check0').submit(function (e) {
  5242. // 再检查多人协同确认情况
  5243. const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
  5244. if(list) {
  5245. toastr.error('请检查多人协同确认情况再审批通过');
  5246. $('#hide-all').hide();
  5247. return false;
  5248. }
  5249. const checkType = parseInt($('[name=checkType]').val());
  5250. const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
  5251. const data = {
  5252. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5253. coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
  5254. checkType,
  5255. };
  5256. $('#sp-done').modal('hide');
  5257. checkType && dataChecker.checkAndPost(this.action, data);
  5258. $('#hide-all').hide();
  5259. return false;
  5260. });
  5261. $('#audit-check1').submit(function (e) {
  5262. const checkType = parseInt($('[name=checkType]:checked').val());
  5263. const confirm = stage.relaAssists.filter(x => { return x.confirm });
  5264. const data = {
  5265. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5266. coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
  5267. checkType,
  5268. };
  5269. if ($('#warning-text').length) $('#warning-text').remove();
  5270. if (!checkType && !$('#warning-text').length) {
  5271. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5272. return false
  5273. }
  5274. $('#sp-back').modal('hide');
  5275. checkType && dataChecker.checkAndPost(this.action, data);
  5276. $('#hide-all').hide();
  5277. return false;
  5278. });
  5279. $('#exportExcel').click(function () {
  5280. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  5281. });
  5282. $('#cbr-check-all').click(function () {
  5283. if (this.checked) {
  5284. $('input', '#cbr-pos-list').attr('checked', 'checked');
  5285. } else {
  5286. $('input', '#cbr-pos-list').removeAttr('checked');
  5287. }
  5288. });
  5289. $('#cbr-ok').click(() => {
  5290. const ratio = parseInt($('#cbr-ratio').val());
  5291. if (!ratio) {
  5292. toastr.warning('请输入计量比例');
  5293. return;
  5294. } else if (ratio < 1) {
  5295. toastr.warning('计量比例不可小于1');
  5296. return;
  5297. } else if (ratio > 100) {
  5298. toastr.warning('计量比例不可大于100');
  5299. return;
  5300. }
  5301. const apply2sibling = $('#apply2sibling')[0].checked;
  5302. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  5303. if (posName.length === 0) {
  5304. toastr.warning('请勾选需要按计量比例的计量单元');
  5305. return;
  5306. }
  5307. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  5308. });
  5309. // 收方单生成
  5310. $('#setshoufang').click(function () {
  5311. const lid = $('#shoufang-lid').val();
  5312. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  5313. // 修改线上
  5314. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  5315. // 收方单tab打开并显示在最新
  5316. if (!$('#shoufang-tab').hasClass('active')) {
  5317. $('#shoufang-tab').click();
  5318. }
  5319. const data = makeOneShouFang(result);
  5320. data.filenum = 0;
  5321. sfData = _.concat(data, sfData);
  5322. getShouFangList();
  5323. });
  5324. });
  5325. $('body').on('click', '.del-shoufang', function () {
  5326. const id = $(this).attr('data-id');
  5327. $('#del-shoufang-id').val(id);
  5328. const name = $(this).parents('tr').children('td').eq(0).text();
  5329. const ledger_code = name.split(' / ')[0];
  5330. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  5331. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  5332. if (pos_name) {
  5333. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  5334. } else {
  5335. $('#del-shoufang-pos').text('').hide();
  5336. }
  5337. });
  5338. // 收方单删除
  5339. $('#delshoufang').click(function () {
  5340. const sfid = $('#del-shoufang-id').val();
  5341. // 修改线上
  5342. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  5343. // 删除到sfData中
  5344. const att_index = sfData.findIndex(function (item) {
  5345. return item.id === parseInt(sfid);
  5346. });
  5347. sfData.splice(att_index, 1);
  5348. // 重新生成List
  5349. if ($('#shoufang-table tr').length === 1) {
  5350. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  5351. } else {
  5352. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  5353. }
  5354. $('#shoufangdelete').modal('hide');
  5355. });
  5356. });
  5357. // 切换页数
  5358. $('.shoufang-page-select').on('click', function () {
  5359. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  5360. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  5361. const status = $(this).attr('content');
  5362. if (status === 'pre' && lastPageNum > 1) {
  5363. getShouFangList(lastPageNum-1);
  5364. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5365. getShouFangList(lastPageNum+1);
  5366. }
  5367. });
  5368. // 获取单个收方单附件列表
  5369. $('body').on('click', '.show-shoufang-att', function () {
  5370. const id = parseInt($(this).attr('data-id'));
  5371. let html = '';
  5372. $('#shoufang-flie-list').html(html);
  5373. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  5374. for (const att of result) {
  5375. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  5376. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  5377. `<a href="${att.filepath}" target="_blank"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a>` + makeViewHtml(att.viewpath) + makeDelHtml(att.id, att.extra_upload) +`</td></tr>`;
  5378. }
  5379. $('#shoufang-flie-list').html(html);
  5380. $('[data-toggle="tooltip"]').tooltip()
  5381. });
  5382. function makeViewHtml(viewpath) {
  5383. return viewpath ? `<a href="${viewpath}" target="_blank" class="ml-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a>` : '';
  5384. }
  5385. function makeDelHtml(fid, extra_upload) {
  5386. return sfAttDelPower &&
  5387. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5388. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  5389. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5390. }
  5391. });
  5392. function makeEditHtml(fid, filename, fileext, extra_upload) {
  5393. return sfAttDelPower &&
  5394. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5395. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  5396. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  5397. }
  5398. // 修改收方单附件文件名
  5399. $('body').on('click', '.edit-shoufang-att', function () {
  5400. $(this).children('i').tooltip('hide');
  5401. const fid = $(this).data('id');
  5402. const filename = $(this).data('filename');
  5403. const fileext = $(this).data('fileext');
  5404. const html = `<div class="input-group input-group-sm">
  5405. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  5406. <div class="input-group-append" id="button-${fid}">
  5407. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  5408. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  5409. </div>
  5410. </div>`;
  5411. $(this).parents('td').html(html);
  5412. });
  5413. // 确认修改文件名
  5414. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  5415. const validText = $.trim($(this).parents('td').find('input').val());
  5416. const orgValue = $.trim($(this).data('filename'));
  5417. const fileext = $(this).data('fileext');
  5418. const fid = $(this).data('fid');
  5419. if (!validText) {
  5420. toastr.error('文件名不能为空');
  5421. return;
  5422. }
  5423. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  5424. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  5425. toastr.error('文件名中不能包含.字符和空格');
  5426. return;
  5427. }
  5428. if(validText == orgValue) {
  5429. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  5430. $(this).parents('td').html(html);
  5431. return;
  5432. }
  5433. const data = {
  5434. id: fid,
  5435. filename: validText,
  5436. };
  5437. const _self = $(this);
  5438. postData('/wap/shoufang/editfile', data, function (result) {
  5439. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  5440. _self.parents('td').html(html);
  5441. });
  5442. });
  5443. // 取消修改文件名
  5444. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  5445. const fid = $(this).data('fid');
  5446. const filename = $(this).data('filename');
  5447. const fileext = $(this).data('fileext');
  5448. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  5449. $(this).parents('td').html(html);
  5450. });
  5451. // 删除收方单附件
  5452. $('body').on('click', '.del-shoufang-att', function () {
  5453. const id = $(this).data('id');
  5454. const _self = $(this);
  5455. const data = { id };
  5456. const sfid = $(this).data('sfid');
  5457. postData('/wap/shoufang/delfile', data, function (result) {
  5458. _self.parents('tr').remove();
  5459. // 附件个数更新
  5460. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  5461. const sfInfo = _.find(sfData, { id: sfid });
  5462. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  5463. });
  5464. });
  5465. // 定位到对应的清单或计量单元
  5466. $('body').on('click', '.show-shoufang-node', function () {
  5467. const id = parseInt($(this).attr('data-id'));
  5468. const sfInfo = _.find(sfData, { id });
  5469. if (sfInfo) {
  5470. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5471. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  5472. stagePosSpreadObj.loadCurPosData();
  5473. if (sfInfo.pid) {
  5474. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  5475. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  5476. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  5477. }
  5478. }
  5479. });
  5480. // 定位到对应的清单或计量单元
  5481. $('body').on('click', '.show-shoufang-report', function () {
  5482. const id = parseInt($(this).attr('data-id'));
  5483. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  5484. sessionStorage.qrCodePath = qrCodePath;
  5485. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  5486. sessionStorage.req_params = JSON.stringify(req_params);
  5487. sessionStorage.rpt_name = rpt_name;
  5488. window.open('/individualReport/A4');
  5489. });
  5490. $('#importExcel').click(() => {
  5491. importExcel.doImport({
  5492. template: {
  5493. hint: '计量台账',
  5494. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  5495. },
  5496. callback: function (sheet) {
  5497. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  5498. window.location.reload();
  5499. }, null);
  5500. }
  5501. });
  5502. });
  5503. const stageAssistRela = {
  5504. refreshAssConfirmBtn: function () {
  5505. if (stage.assist) {
  5506. const caption = stage.assist.user_id === stage.user_id
  5507. ? (stage.assist.confirm ? '撤销上报' : '确认上报')
  5508. : (stage.assist.confirm ? '重新审批' : '审批通过');
  5509. if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
  5510. } else {
  5511. $('#ass-confirm-btn').hide();
  5512. }
  5513. },
  5514. checkAssistPartUsed(assist) {
  5515. const ass_lid = assist.ass_ledger_id.split(',');
  5516. for (const lid of ass_lid) {
  5517. const node = stageTree.getItems(lid);
  5518. if (!node) continue;
  5519. if (checkUsed(stageTree, stagePos, node)) return true;
  5520. }
  5521. return false;
  5522. },
  5523. refreshAssistTable: function () {
  5524. const html = [];
  5525. for (const ra of stage.relaAssists) {
  5526. const used = this.checkAssistPartUsed(ra);
  5527. const hint = used
  5528. ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
  5529. : '<td>本期未计量</td>';
  5530. html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
  5531. }
  5532. return $('#assistList').html(html.join(''));
  5533. },
  5534. refreshAssists: function () {
  5535. if (stage.relaAssists.length > 0) {
  5536. $('#assistCount').html(stage.relaAssists.length || '').parent().show();
  5537. } else {
  5538. $('#assistCount').parent().hide();
  5539. }
  5540. },
  5541. refreshReadOnly(){
  5542. stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
  5543. SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
  5544. stagePosSpreadObj.loadCurPosData();
  5545. },
  5546. init: function() {
  5547. this.refreshAssConfirmBtn();
  5548. this.refreshReadOnly();
  5549. this.refreshAssists();
  5550. },
  5551. };
  5552. stageAssistRela.init();
  5553. $('#ass-confirm-btn').click(() => {
  5554. const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
  5555. postData(window.location.pathname + '/ass-confirm', data, function(result) {
  5556. window.location.reload();
  5557. // stage.assist = result;
  5558. // stageAssistRela.refreshAssConfirmBtn();
  5559. // stageAssistRela.refreshReadOnly();
  5560. });
  5561. });
  5562. $('#assists').on('show.bs.modal', function(){
  5563. postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
  5564. stage.relaAssists = result;
  5565. stageAssistRela.refreshAssistTable();
  5566. });
  5567. });
  5568. $('body').on('click', 'a[name=att-delete]', function() {
  5569. const fid = this.getAttribute('file-id');
  5570. if (!fid) return;
  5571. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  5572. const data = {id: fid};
  5573. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  5574. // 删除到attData中
  5575. const att_index = attData.findIndex(function (item) {
  5576. return item.id === parseInt(fid);
  5577. });
  5578. attData.splice(att_index, 1);
  5579. // 重新生成List
  5580. if ($('#alllist-table tr').length === 1) {
  5581. getAllList(parseInt($('#currentPage').text()) - 1);
  5582. } else {
  5583. getAllList(parseInt($('#currentPage').text()));
  5584. }
  5585. getNodeList(node.id);
  5586. $('#showAttachment').hide();
  5587. $('#showAttachment').attr('file-id', '');
  5588. });
  5589. });
  5590. });
  5591. function makeOneShouFang(sf) {
  5592. const lData = _.find(ledgerData, { id: sf.lid });
  5593. sf.name = lData.b_code;
  5594. if (sf.pid) {
  5595. const pData = _.find(posData, { id: sf.pid });
  5596. if (pData && pData.name) {
  5597. sf.name = lData.b_code + ' / ' + pData.name;
  5598. }
  5599. }
  5600. return sf;
  5601. }
  5602. function makeShouFang() {
  5603. for (const sf of sfData) {
  5604. makeOneShouFang(sf);
  5605. }
  5606. getShouFangList();
  5607. }
  5608. // 生成收方单列表
  5609. function getShouFangList(currPageNum = 1) {
  5610. // 每页最多几个附件
  5611. const pageCount = 20;
  5612. // 附件总数
  5613. const total = sfData.length;
  5614. // 总页数
  5615. const pageNum = Math.ceil(total/pageCount);
  5616. $('#shoufang-totalPage').text(pageNum);
  5617. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  5618. // 当前页附件内容
  5619. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  5620. let html = '';
  5621. for(const att of currPageAttData) {
  5622. html += '<tr><td>' + att.name + '</td>' +
  5623. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  5624. '<td width="100">' +
  5625. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-node mr-1" data-toggle="tooltip" data-placement="left" data-original-title="定位"><i class="fa fa-crosshairs"></i></a> ' +
  5626. '<a href="javascript:void(0);" data-id="'+ att.id +'" class="show-shoufang-report mr-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a> ' +
  5627. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  5628. makeDelHtml(att.id, att.extra_upload) +
  5629. '</td></tr>';
  5630. }
  5631. function makeDelHtml(id, extra_upload) {
  5632. return cur_uid === stage.user_id &&
  5633. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5634. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  5635. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5636. }
  5637. $('#shoufang-table').html(html);
  5638. $('[data-toggle="tooltip"]').tooltip();
  5639. }
  5640. function makeReportData(sfid) {
  5641. const sfInfo = _.find(sfData, { id: sfid });
  5642. const ledger_code = sfInfo.name.split(' / ')[0];
  5643. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  5644. const replace_key_params = {
  5645. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  5646. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  5647. 'KEY_合同段': tenderInfo.deal_info.dealName,
  5648. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  5649. 'KEY_编号': '',
  5650. 'KEY_设计工程数量': 0,
  5651. };
  5652. // if (sfInfo.pid) {
  5653. // const pData = _.find(posData, { id: sfInfo.pid });
  5654. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  5655. // } else {
  5656. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5657. // }
  5658. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  5659. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  5660. const req_params = {
  5661. rpt_tpl_id: window.location.host === '127.0.0.1:7002' || window.location.host === 'jlqa.smartcost.com.cn:7002' ? 1784 : (window.location.host === 'jluat.smartcost.com.cn' ? 315 : 2138), // 1784(qa的,外网是2138)
  5662. pageSize: 'A4',
  5663. project_id: tender.project_id,
  5664. tender_id: tender.id,
  5665. stage_id: stage.id,
  5666. sp_id: spid,
  5667. };
  5668. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  5669. const qrCodePath = sfInfo.qrcode;
  5670. return [qrCodePath, replace_key_params, req_params, rpt_name];
  5671. }