stage.js 287 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786
  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. node.tz_qc_qty = ZhCalc.add(node.tz_qc_qty, changeBills.checked_amount);
  1551. if (tenderInfo.calc_type === 'up') {
  1552. node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.checked_price);
  1553. } else {
  1554. node.tz_qc_tp = ZhCalc.add(node.tz_qc_tp, changeBills.tp);
  1555. }
  1556. const posData = pos.getLedgerPos(node.id);
  1557. if (posData && posData.length > 0) {
  1558. for (const p of changeBills.pos) {
  1559. const changePos = p.bwmx ? posData.find(x => { return x.name === p.bwmx; }) : posData[0];
  1560. if (changePos) changePos.tz_qc_qty = ZhCalc.add(changePos.tz_qc_qty, p.checked_amount);
  1561. }
  1562. }
  1563. }
  1564. }
  1565. }
  1566. };
  1567. slSpread.bind(spreadNS.Events.EditEnded, stageTreeSpreadObj.editEnded);
  1568. slSpread.bind(spreadNS.Events.SelectionChanged, stageTreeSpreadObj.selectionChanged);
  1569. slSpread.bind(spreadNS.Events.ClipboardPasting, stageTreeSpreadObj.clipboardPasting);
  1570. slSpread.bind(spreadNS.Events.ClipboardPasted, stageTreeSpreadObj.clipboardPasted);
  1571. slSpread.bind(spreadNS.Events.TopRowChanged, stageTreeSpreadObj.topRowChanged);
  1572. slSpread.bind(spreadNS.Events.EditStarting, stageTreeSpreadObj.editStarting);
  1573. slSpread.bind(spreadNS.Events.ButtonClicked, stageTreeSpreadObj.buttonClicked);
  1574. SpreadJsObj.addCutEvents(slSpread, stageTreeSpreadObj.cut);
  1575. SpreadJsObj.addDeleteBind(slSpread, stageTreeSpreadObj.deletePress);
  1576. if (!readOnly) {
  1577. $('#bills-expr').bind('change onblur', function () {
  1578. if (this.readOnly) return;
  1579. const expr = $(this);
  1580. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1581. const select = stageTree.getItemsByIndex(row);
  1582. if (!select) return;
  1583. const field = expr.attr('field'), orgValue = expr.attr('org'), updateData = {};
  1584. let newValue = expr.val();
  1585. const num = _.toNumber(newValue);
  1586. if (_.isFinite(num)) {
  1587. newValue = num;
  1588. } else {
  1589. try {
  1590. newValue = ZhCalc.mathCalcExpr(transExpr(newValue));
  1591. } catch(err) {
  1592. toastr.error('输入的表达式非法');
  1593. return;
  1594. }
  1595. }
  1596. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1597. if (field.indexOf('_dgn_') > 0) {
  1598. updateData.dgn = {
  1599. id: select.id
  1600. };
  1601. updateData.dgn[field] = newValue;
  1602. } else {
  1603. updateData.stage = {
  1604. lid: select.id
  1605. };
  1606. updateData.stage[field] = newValue;
  1607. const exprInfo = getExprInfo(field);
  1608. if (exprInfo) {
  1609. updateData.stage[exprInfo.expr] = expr.val();
  1610. }
  1611. }
  1612. // 更新至服务器
  1613. postData(window.location.pathname + '/update', {bills: updateData}, function (result) {
  1614. const nodes = stageTree.loadPostStageData(result);
  1615. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1616. if (detail) {
  1617. detail.loadStageLedgerUpdateData(result, nodes);
  1618. } else {
  1619. stageIm.loadUpdateLedgerData(result, nodes);
  1620. }
  1621. });
  1622. });
  1623. }
  1624. stageTreeSpreadObj.loadExprToInput(slSpread.getActiveSheet());
  1625. const addTag = newTag({ledgerSheet: slSpread.getActiveSheet(), billsTag});
  1626. const tenderSelect = TenderSelect({
  1627. type: 'stage',
  1628. afterLoad: function (result, select) {
  1629. const nodes = stageTree.loadPostStageData(result);
  1630. const posterity = stageTree.getPosterity(select);
  1631. for (const p of posterity) {
  1632. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1633. }
  1634. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1635. if (detail) {
  1636. detail.loadStageLedgerUpdateData(result, nodes);
  1637. } else {
  1638. stageIm.loadUpdateLedgerData(result, nodes);
  1639. }
  1640. if (result.sumLoadHis.errors.length > 0) {
  1641. sumLoadMiss.loadMissData(result.sumLoadHis.errors);
  1642. sumLoadMiss.show();
  1643. } else {
  1644. sumLoadMiss.clearMissData();
  1645. }
  1646. // todo 优化,仅加载需要刷新的变更令
  1647. if (checkedChanges) checkedChanges.reloadChangeData();
  1648. }
  1649. });
  1650. const batchImport = BatchImportStageGcl({
  1651. stageTree,
  1652. afterLoad: function (result, select) {
  1653. const nodes = stageTree.loadPostStageData(result);
  1654. const posterity = stageTree.getPosterity(select);
  1655. for (const p of posterity) {
  1656. p.is_import = !!result.import_change.data.find(x => { return x.lid === p.id });
  1657. }
  1658. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1659. if (detail) {
  1660. detail.loadStageLedgerUpdateData(result, nodes);
  1661. } else {
  1662. stageIm.loadUpdateLedgerData(result, nodes);
  1663. }
  1664. if (checkedChanges) checkedChanges.reloadChangeData();
  1665. }
  1666. });
  1667. const spssTenderSelect = TenderSelectMulti({
  1668. title: '根据(其他标段)计量比例计量',
  1669. type: 'gather',
  1670. dataType: 'stage',
  1671. afterSelect: function(select) {
  1672. const data = { filter: 'info', tender: select };
  1673. postData(`/sp/${spid}/spss/load`, data, function(result) {
  1674. const postil = result.map(x => { return `${x.name}(${x.stage_filter}) ${x.info.contract_tp || 0}`}).join(';');
  1675. const gatherContractTp = ZhCalc.sum(result.map(x => { return x.info.contract_tp; }));
  1676. const gatherTp = ZhCalc.sum(result.map(x => { return x.info.total_price; }));
  1677. const node = SpreadJsObj.getSelectObject(slSheet);
  1678. const contract_tp = ZhCalc.mul(ZhCalc.div(gatherContractTp, gatherTp), node.total_price);
  1679. const contract_expr = result.length > 1
  1680. ? '(' + result.map(x => { return x.info.contract_tp; }).join('+') + ')/(' + result.map(x => { return x.info.total_price; }).join('+') + ')'
  1681. : result[0].info.contract_tp + '/' + result[0].info.total_price;
  1682. stageTreeSpreadObj.updateNodeData({ stage: { lid: node.id, contract_tp, contract_expr, postil } });
  1683. });
  1684. },
  1685. });
  1686. $.contextMenu({
  1687. selector: '#stage-ledger',
  1688. build: function ($trigger, e) {
  1689. const target = SpreadJsObj.safeRightClickSelection($trigger, e, slSpread);
  1690. stageTreeSpreadObj.loadRelaData();
  1691. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1692. },
  1693. items: {
  1694. 'remainCur': {
  1695. name: '填剩余量',
  1696. disabled: function (key, opt) {
  1697. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1698. return readOnly || !node || node.lock;
  1699. },
  1700. callback: function (key, opt) {
  1701. const sheet = spSpread.getActiveSheet();
  1702. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1703. const updateStage = [];
  1704. const posterity = stageTree.getPosterity(node);
  1705. posterity.unshift(node);
  1706. for (const p of posterity) {
  1707. if (p.children && p.children.length > 0) continue;
  1708. if (!p.b_code) continue;
  1709. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1710. if (posRange.length > 0) continue;
  1711. if (!p.is_tp) {
  1712. const qty = ZhCalc.sub(p.quantity, p.pre_contract_qty);
  1713. const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
  1714. if (differ) updateStage.push({ lid: p.id, contract_qty: qty, contract_expr: '' });
  1715. } else {
  1716. const tp = ZhCalc.sub(p.total_price, p.pre_contract_tp);
  1717. const differ = ZhCalc.sub(p.quantity, p.end_contract_qty);
  1718. if (differ) updateStage.push({ lid: p.id, contract_tp: tp });
  1719. }
  1720. }
  1721. if (updateStage.length === 0) {
  1722. toastr.warning('所选节点及子项已全部计量');
  1723. return;
  1724. }
  1725. if (updateStage.length > 0) {
  1726. if (updateStage.length > 1000) {
  1727. toastr.warning('提交的数据太大,仅提交1000条数据');
  1728. updateStage.length = 1000;
  1729. }
  1730. postData(window.location.pathname + '/update', {bills: { stage: updateStage }}, function (result) {
  1731. const nodes = stageTree.loadPostStageData(result);
  1732. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1733. if (detail) {
  1734. detail.loadStageLedgerUpdateData(result, nodes);
  1735. } else {
  1736. stageIm.loadUpdateLedgerData(result, nodes);
  1737. }
  1738. stageTreeSpreadObj.loadExprToInput(sheet);
  1739. });
  1740. }
  1741. }
  1742. },
  1743. 'remainCurPos': {
  1744. name: '填剩余量(计量单元)',
  1745. disabled: function (key, opt) {
  1746. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1747. return readOnly || !node || node.lock;
  1748. },
  1749. callback: function (key, opt) {
  1750. const sheet = spSpread.getActiveSheet();
  1751. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1752. const data = { updateType: 'batchUpdate', updateData: [] };
  1753. const posterity = stageTree.getPosterity(node);
  1754. posterity.unshift(node);
  1755. for (const p of posterity) {
  1756. if (p.children && p.children.length > 0) continue;
  1757. if (!p.b_code) continue;
  1758. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1759. if (posRange.length === 0) continue;
  1760. for (const pr of posRange) {
  1761. const qty = ZhCalc.sub(pr.quantity, pr.pre_contract_qty);
  1762. const differ = ZhCalc.sub(pr.quantity, pr.end_contract_qty);
  1763. if (differ) data.updateData.push({ lid: pr.lid, pid: pr.id, contract_qty: qty, contract_expr: '' });
  1764. }
  1765. }
  1766. if (data.updateData.length === 0) {
  1767. toastr.warning('所选节点及子项已全部计量');
  1768. return;
  1769. }
  1770. if (data.updateData.length > 0) {
  1771. if (data.updateData.length > 1000) {
  1772. toastr.warning('提交的数据太大,仅提交1000条数据');
  1773. data.updateData.length = 1000;
  1774. }
  1775. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1776. if (result.pos) {
  1777. stagePos.updateDatas(result.pos.pos);
  1778. stagePos.loadCurStageData(result.pos.curStageData);
  1779. }
  1780. const nodes = stageTree.loadPostStageData(result.ledger);
  1781. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1782. stagePosSpreadObj.loadCurPosData();
  1783. if (detail) {
  1784. detail.loadStagePosUpdateData(result, nodes);
  1785. } else {
  1786. stageIm.loadUpdatePosData(result, nodes);
  1787. }
  1788. stageTreeSpreadObj.loadExprToInput(sheet);
  1789. });
  1790. }
  1791. }
  1792. },
  1793. 'remainXmjQty': {
  1794. name: '填项目节数量',
  1795. callback: function(key, opt) {
  1796. const sheet = spSpread.getActiveSheet();
  1797. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1798. const updateDgn = [];
  1799. const posterity = stageTree.getPosterity(node);
  1800. posterity.unshift(node);
  1801. for (const p of posterity) {
  1802. if (p.b_code) continue;
  1803. const posRange = stagePos.ledgerPos[itemsPre + p.id] || [];
  1804. if (posRange.length > 0) continue;
  1805. 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 });
  1806. }
  1807. if (updateDgn.length === 0) {
  1808. toastr.warning('所选项目节及子项的项目节数量已与台账相等');
  1809. return;
  1810. }
  1811. if (updateDgn.length > 1000) {
  1812. toastr.warning('提交的数据太大,仅提交1000条数据');
  1813. updateDgn.length = 1000;
  1814. }
  1815. postData(window.location.pathname + '/update', {bills: { dgn: updateDgn }}, function (result) {
  1816. const nodes = stageTree.loadPostStageData(result);
  1817. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1818. if (detail) {
  1819. detail.loadStageLedgerUpdateData(result, nodes);
  1820. } else {
  1821. stageIm.loadUpdateLedgerData(result, nodes);
  1822. }
  1823. stageTreeSpreadObj.loadExprToInput(sheet);
  1824. });
  1825. // postData(window.location.pathname + '/update', { dgn: 'all' }, function (result) {
  1826. // const nodes = stageTree.loadPostStageData(result);
  1827. // stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1828. // if (detail) {
  1829. // detail.loadStageLedgerUpdateData(result, nodes);
  1830. // } else {
  1831. // stageIm.loadUpdateLedgerData(result, nodes);
  1832. // }
  1833. // stageTreeSpreadObj.loadExprToInput(sheet);
  1834. // });
  1835. },
  1836. visible: function(key, opt) {
  1837. return !readOnly;
  1838. },
  1839. disabled: function (key, opt) {
  1840. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1841. return !node || !!node.b_code;
  1842. }
  1843. },
  1844. 'remainByExprAll': {
  1845. name: '计算本期合同计量',
  1846. icon: 'fa-forward',
  1847. callback: function(key, opt) {
  1848. const sheet = spSpread.getActiveSheet();
  1849. TreeExprCalc.setCalcType(TreeExprCalc.calcType.sortCache);
  1850. const calcExpr = stageTree.nodes.filter(x => {
  1851. if (x.children && x.children.length > 0) return false;
  1852. const posRange = stagePos.getLedgerPos(x.id);
  1853. if (posRange && posRange.length > 0) return false;
  1854. return !!x.calc_expr;
  1855. }).map(x => { return { id: x.id, expr: x.calc_expr, unit: x.unit, unit_price: x.unit_price, calcField: x.is_tp ? 'tp' : 'qty' }});
  1856. if (calcExpr.length === 0) {
  1857. toastr.warning('沒有可计算的公式');
  1858. return;
  1859. }
  1860. TreeExprCalc.calcAllExpr(calcExpr);
  1861. const updateData = calcExpr.map(x => {
  1862. const data = { lid: x.id, contract_expr: x.formula };
  1863. const field = x.calcField === 'qty' ? 'contract_qty' : 'contract_tp';
  1864. data[field] = x.value;
  1865. return data;
  1866. });
  1867. postData(window.location.pathname + '/update', {bills: { stage: updateData }}, function (result) {
  1868. const nodes = stageTree.loadPostStageData(result);
  1869. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1870. if (detail) {
  1871. detail.loadStageLedgerUpdateData(result, nodes);
  1872. } else {
  1873. stageIm.loadUpdateLedgerData(result, nodes);
  1874. }
  1875. stageTreeSpreadObj.loadExprToInput(sheet);
  1876. });
  1877. },
  1878. visible: function(key, opt) {
  1879. return !readOnly && contractExpr;
  1880. },
  1881. },
  1882. zjjlSpr: '----',
  1883. 'locateZjjl': {
  1884. name: '定位至中间计量',
  1885. icon: 'fa-sign-in',
  1886. callback: function (key, opt) {
  1887. if (!detail) {
  1888. detail = new Detail($('#detail-spread'));
  1889. }
  1890. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1891. const [leafUsedBills, usedPos] = stageIm.getFirstUsed(node);
  1892. if (leafUsedBills) {
  1893. if (!$('#zhongjian').hasClass('active')) {
  1894. const tab = $('#zhongjiantab'), tabPanel = $(tab.attr('content'));
  1895. $('a', '.side-menu').removeClass('active');
  1896. $('.tab-content .tab-select-show').removeClass('active');
  1897. tab.addClass('active');
  1898. tabPanel.addClass('active');
  1899. showSideTools(tab.hasClass('active'));
  1900. slSpread.refresh();
  1901. spSpread.refresh();
  1902. }
  1903. const relaXmj = stageIm.getRelaXmj(leafUsedBills);
  1904. const im = stageIm.getRelaImData(relaXmj, leafUsedBills, usedPos);
  1905. SpreadJsObj.locateData(detail.sheet, im);
  1906. detail.spread.refresh();
  1907. $('#zhongjian .sjs-bottom').height('400px');
  1908. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  1909. detail.reLoadDetailData();
  1910. } else {
  1911. toastr.error('无可定位中间计量');
  1912. }
  1913. },
  1914. disabled: function (key, opt) {
  1915. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1916. return !node;
  1917. }
  1918. },
  1919. tagSpr: '----',
  1920. tag: {
  1921. name: '书签',
  1922. callback: function (key, opt, menu, e) {
  1923. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1924. addTag.do(node);
  1925. },
  1926. disabled: function (key, opt) {
  1927. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1928. return !node;
  1929. }
  1930. },
  1931. showSpr: '----',
  1932. showLast: {
  1933. name: '显示至最底层',
  1934. callback: function (key, opt, menu, e) {
  1935. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1936. setTimeout(() => {
  1937. showWaitingView();
  1938. stageTree.expandByCustom(x => {
  1939. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  1940. });
  1941. SpreadJsObj.refreshTreeRowVisible(slSpread.getActiveSheet());
  1942. closeWaitingView();
  1943. }, 100);
  1944. },
  1945. disabled: function (key, opt) {
  1946. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1947. return !node;
  1948. }
  1949. },
  1950. exportSpr: '----',
  1951. exportSelectNodeXlsx: {
  1952. name: '导出选中节点至Excel',
  1953. callback: function (key, opt, menu, e) {
  1954. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1955. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + `计量台账(${node.name || ''}).xlsx`, [node]);
  1956. },
  1957. disabled: function (key, opt) {
  1958. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1959. return !node;
  1960. }
  1961. },
  1962. exportContractExprXlsx: {
  1963. name: '导出本期合同计量公式',
  1964. callback: function(key, opt, menu, e) {
  1965. exportExcelSetting.cols.push({title: '本期合同计量计算式', colSpan: '1', rowSpan: '2', field: 'contract_expr_str', hAlign: 0, width: 140, formatter: '@'});
  1966. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + '本期合同计量公式.xlsx', null, false);
  1967. exportExcelSetting.cols.splice(exportExcelSetting.cols.length - 1, 1);
  1968. },
  1969. visible: function(key, opt) {
  1970. return contractExpr;
  1971. }
  1972. },
  1973. dealLoadSpr: '---',
  1974. exportDealData: {
  1975. name: '导出本期合同计量',
  1976. callback: function (key, opt, menu, e) {
  1977. window.open(window.location.pathname + '/cpd');
  1978. },
  1979. },
  1980. importDealData: {
  1981. name: '导入本期合同计量',
  1982. callback: function (key, opt, menu, e) {
  1983. BaseImportFile.show({
  1984. validList: ['.cpd'],
  1985. url: window.location.pathname + '/cpd/load',
  1986. afterImport: function() {
  1987. window.location.reload();
  1988. }
  1989. });
  1990. },
  1991. disabled: function(key, opt) {
  1992. return readOnly || stage.revising || stage.status !== auditConst.status.uncheck;
  1993. },
  1994. },
  1995. exportTestData: {
  1996. name: '导出测试数据',
  1997. callback: function (key, opt, menu, e) {
  1998. const data = stageTree.nodes.map(x => {
  1999. const parent = stageTree.getParent(x);
  2000. return {
  2001. id: x.id, parentId: parent ? parent.id : '-1', seq: x.order,
  2002. code: x.code || '', b_code: x.b_code || '', name: x.name || '', unit: x.unit || '', unit_price: x.unit_price || 0,
  2003. quantity: x.quantity || 0, total_price: x.total_price || 0,
  2004. is_tp: x.is_tp || 0,
  2005. contract_qty: x.contract_qty || 0, contract_tp: x.contract_tp || 0,
  2006. qc_qty: x.qc_qty || 0, qc_tp: x.qc_tp || 0,
  2007. gather_qty: x.gather_qty || 0, gather_tp: x.gather_tp || 0,
  2008. pre_contract_qty: x.pre_contract_qty || 0, pre_contract_tp: x.pre_contract_tp || 0,
  2009. pre_qc_qty: x.pre_qc_qty || 0, pre_qc_tp: x.pre_qc_tp || 0,
  2010. pre_gather_qty: x.pre_gather_qty || 0, pre_gather_tp: x.pre_gather_tp || 0,
  2011. end_contract_qty: x.end_contract_qty || 0, end_contract_tp: x.end_contract_tp || 0,
  2012. end_qc_qty: x.end_qc_qty || 0, end_qc_tp: x.end_qc_tp || 0,
  2013. end_gather_qty: x.end_gather_qty || 0, end_gather_tp: x.end_gather_tp || 0,
  2014. memo: x.memo || '',
  2015. gxby_status: x.gxby_status || 0, gxby_url: x.gxby_status || '',
  2016. dagl_status: x.gxby_status || 0, dagl_url: x.dagl_url || '',
  2017. wbs_url: x.wbs_url || '',
  2018. };
  2019. });
  2020. const blob = new Blob([JSON.stringify(data, '', '\t')], { type: 'application/text'});
  2021. saveAs(blob, 'test.json');
  2022. },
  2023. visible: function() {
  2024. return is_debug || false;
  2025. }
  2026. },
  2027. sumLoadSpr: '---',
  2028. importStageGcl: {
  2029. name: '导入(其他标段)工程量清单计量数据',
  2030. icon: 'fa-link',
  2031. disabled: function (key, opt) {
  2032. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2033. return readOnly || !node || !stageTree.isLeafXmj(node);
  2034. },
  2035. callback: function (key, opt) {
  2036. tenderSelect.showSelect(SpreadJsObj.getSelectObject(slSpread.getActiveSheet()));
  2037. }
  2038. },
  2039. batchImportStageGcl: {
  2040. name: '批量导入(其他标段)工程量清单计量数据',
  2041. icon: 'fa-link',
  2042. disabled: function (key, opt) {
  2043. return readOnly;
  2044. },
  2045. callback: function (key, opt){
  2046. batchImport.show();
  2047. }
  2048. },
  2049. percentSpr: '---',
  2050. percentCalc: {
  2051. name: '根据(其他标段)计量比例计量',
  2052. disabled: function(key, opt) {
  2053. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2054. const posRange = stagePos.getLedgerPos(node.id) || [];
  2055. return readOnly || !node || !node.is_tp || posRange.length > 0;
  2056. },
  2057. callback: function(key, opt) {
  2058. spssTenderSelect.showSelect();
  2059. }
  2060. },
  2061. shoufangdanSpr: '---',
  2062. shoufangdan: {
  2063. name: '生成收方单',
  2064. visible: function(key, opt) {
  2065. if (cur_uid === stage.user_id) return true;
  2066. },
  2067. disabled: function (key, opt) {
  2068. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2069. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  2070. },
  2071. callback: function (key, opt) {
  2072. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2073. $('#shoufang-lid').val(node.id);
  2074. $('#shoufang-pid').val('');
  2075. $('#shoufang-ledger').text('清单:' + node.b_code);
  2076. $('#shoufang-pos').text('').hide();
  2077. $('#addshoufang').modal('show');
  2078. }
  2079. },
  2080. lockedSpr: '----',
  2081. lockedHint: {
  2082. name: '检查审批状态',
  2083. visible: function (key, opt) {
  2084. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2085. return node.locked;
  2086. },
  2087. callback: function (key, opt) {
  2088. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2089. const lockedInfo = stageTree.getLockedInfo(node);
  2090. toastr.warning(`审批人 ${lockedInfo.map(x => { return x.name; }).join(',')} 审批通过,如需修改,请联系审批人重新审批`);
  2091. }
  2092. },
  2093. }
  2094. });
  2095. const stagePosSpreadObj = {
  2096. loadExprToInput(sheet) {
  2097. const sel = sheet.getSelections()[0];
  2098. if (!sel) return;
  2099. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  2100. if (col && col.type === 'Number') {
  2101. const data = SpreadJsObj.getSelectObject(sheet);
  2102. if (data) {
  2103. const exprInfo = getExprInfo(col.field);
  2104. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  2105. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2106. .attr('readOnly', readOnly || cell.locked());
  2107. $('#pos-expr').attr('data-row', sel.row);
  2108. } else {
  2109. $('#pos-expr').val('').attr('readOnly', true);
  2110. $('#pos-expr').removeAttr('data-row');
  2111. }
  2112. } else {
  2113. $('#pos-expr').val('').attr('readOnly', true);
  2114. $('#pos-expr').removeAttr('data-row');
  2115. }
  2116. },
  2117. /**
  2118. * 加载计量单元 根据当前台账选择节点
  2119. */
  2120. loadCurPosData: function () {
  2121. const sheet = slSpread.getActiveSheet();
  2122. const node = SpreadJsObj.getSelectObject(sheet);
  2123. if (node) {
  2124. const posReadOnly = node.lock || (node.children && node.children.length > 0) || !node.b_code;
  2125. spSpread.getActiveSheet().zh_setting.readOnly = posReadOnly;
  2126. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  2127. const posMeasure = $('#pos-measure')[0].checked;
  2128. const posUnMeasure = $('#pos-un-measure')[0].checked;
  2129. posData.forEach(x => {
  2130. x.visible = true;
  2131. if (posMeasure && x.visible) {
  2132. x.visible = !!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty;
  2133. }
  2134. if (posUnMeasure && x.visible) {
  2135. // 不考虑不计价
  2136. x.visible = !x.end_contract_qty && !x.end_qc_qty && !x.end_gather_qty; // && !x.qc_minus_qty;
  2137. }
  2138. });
  2139. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  2140. getNodeList(node.id);
  2141. } else {
  2142. spSpread.getActiveSheet().zh_setting.readOnly = true;
  2143. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  2144. }
  2145. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  2146. },
  2147. editEnded: function (e, info) {
  2148. if (info.sheet.zh_setting) {
  2149. // 未改变过,则直接跳过
  2150. const sortData = info.sheet.zh_data;
  2151. const posData = sortData ? sortData[info.row] : null;
  2152. const col = info.sheet.zh_setting.cols[info.col];
  2153. const orgText = posData ? posData[col.field] : null;
  2154. const newText = trimInvalidChar(info.editingText);
  2155. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  2156. return;
  2157. }
  2158. // 台账模式下,不可新增
  2159. if (checkTzMeasureType() && !posData) {
  2160. toastr.error('台账模式不可新增计量单元数据');
  2161. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2162. return ;
  2163. }
  2164. // 不同节点下,计量单元检查输入
  2165. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2166. const node = stagePosSpreadObj.stageTreeNode;
  2167. if (!node) {
  2168. toastr.warning('数据错误, 请刷新页面后再试');
  2169. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2170. return;
  2171. } else if (newText !== '' && node.children && node.children.length > 0) {
  2172. toastr.error('父节点不可插入计量单元');
  2173. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2174. return;
  2175. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  2176. toastr.error('项目节不可插入计量单元');
  2177. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2178. return;
  2179. }
  2180. // 生成提交数据
  2181. const data = {};
  2182. if (col.field === 'name') {
  2183. if ((!newText || newText === '') && posData) {
  2184. toastr.error('部位名称不可为空');
  2185. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2186. return;
  2187. } else if (!posData) {
  2188. if (newText !== '') {
  2189. data.updateType = 'add';
  2190. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2191. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2192. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2193. return;
  2194. }
  2195. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2196. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  2197. } else {
  2198. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2199. return;
  2200. }
  2201. } else {
  2202. data.updateType = 'update';
  2203. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  2204. }
  2205. } else if (!posData) {
  2206. toastr.warning('新增计量单元请先输入名称');
  2207. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  2208. data.updateType = 'update';
  2209. data.updateData = {pid: posData.id, lid: posData.lid};
  2210. data.updateData[col.field] = newText;
  2211. } else {
  2212. data.updateType = 'update';
  2213. data.updateData = {pid: posData.id, lid: posData.lid};
  2214. if (col.type === 'Number') {
  2215. const exprInfo = getExprInfo(col.field);
  2216. const num = _.toNumber(newText);
  2217. if (_.isFinite(num)) {
  2218. data.updateData[col.field] = num;
  2219. if (exprInfo) {
  2220. data.updateData[exprInfo.expr] = '';
  2221. }
  2222. } else {
  2223. try {
  2224. data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2225. if (exprInfo) {
  2226. data.updateData[exprInfo.expr] = newText;
  2227. }
  2228. } catch(err) {
  2229. toastr.error('输入的表达式非法');
  2230. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2231. return;
  2232. }
  2233. }
  2234. } else if (col.field.indexOf('_expr') > 0) {
  2235. const exprInfo = getExprInfo(col.field, true);
  2236. if (!exprInfo) return;
  2237. if (newText) {
  2238. try {
  2239. data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2240. data.updateData[exprInfo.expr] = newText;
  2241. } catch(err) {
  2242. toastr.error('输入的表达式非法');
  2243. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2244. return;
  2245. }
  2246. } else {
  2247. data.updateData[exprInfo.qty] = 0;
  2248. data.updateData[exprInfo.expr] = '';
  2249. }
  2250. } else {
  2251. data.updateData[col.field] = newText;
  2252. }
  2253. }
  2254. // 提交数据到服务器
  2255. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2256. if (result.pos) {
  2257. stagePos.updateDatas(result.pos.pos);
  2258. stagePos.loadCurStageData(result.pos.curStageData);
  2259. }
  2260. const refreshData = stageTree.loadPostStageData(result.ledger);
  2261. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2262. stagePosSpreadObj.loadCurPosData();
  2263. if (detail) {
  2264. detail.loadStagePosUpdateData(result, refreshData);
  2265. } else {
  2266. stageIm.loadUpdatePosData(result, refreshData);
  2267. }
  2268. }, function () {
  2269. stagePosSpreadObj.loadCurPosData();
  2270. });
  2271. }
  2272. },
  2273. editStarting: function (e, info) {
  2274. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2275. const sel = info.sheet.getSelections();
  2276. if (!sel || !sel[0]) return;
  2277. const col = info.sheet.zh_setting.cols[sel[0].col];
  2278. const node = SpreadJsObj.getSelectObject(info.sheet);
  2279. const exprInfo = getExprInfo(col.field);
  2280. if (exprInfo && node) {
  2281. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2282. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2283. }
  2284. }
  2285. switch (col.field) {
  2286. case 'contract_qty':
  2287. case 'contract_expr':
  2288. case 'qc_qty':
  2289. case 'qc_minus_qty':
  2290. info.cancel = node.settle_status === settleStatus.finish;
  2291. break;
  2292. }
  2293. },
  2294. clipboardPasting: function (e, info) {
  2295. if (info.sheet.zh_setting) {
  2296. const sortData = info.sheet.zh_data;
  2297. const range = info.cellRange;
  2298. const validField = ['contract_qty', 'contract_expr', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3', 'ex_stage_qty1'];
  2299. if (!checkTzMeasureType()) {
  2300. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  2301. }
  2302. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  2303. const col = info.sheet.zh_setting.cols[iCol];
  2304. if (validField.indexOf(col.field) === -1) {
  2305. if (checkTzMeasureType()) {
  2306. toastr.error('不可修改此数据');
  2307. info.cancel = true;
  2308. return;
  2309. } else {
  2310. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  2311. const pos = sortData(iRow);
  2312. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  2313. toastr.error('不可修改此数据');
  2314. info.cancel = true;
  2315. return;
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. }
  2322. },
  2323. clipboardPasted: function (e, info) {
  2324. const hint = {
  2325. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2326. };
  2327. if (info.sheet.zh_setting) {
  2328. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2329. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2330. }
  2331. const data = { updateType: '', updateData: [], };
  2332. const sortData = info.sheet.zh_data;
  2333. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2334. if (node.children && node.children.length > 0) return;
  2335. if (sortData && (info.cellRange.row >= sortData.length)) {
  2336. data.updateType = 'add';
  2337. if (info.cellRange.col !== 0) {
  2338. toastr.warning('新增计量单元请先输入名称');
  2339. stagePosSpreadObj.loadCurPosData();
  2340. return;
  2341. }
  2342. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2343. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2344. stagePosSpreadObj.loadCurPosData();
  2345. return;
  2346. }
  2347. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2348. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2349. const curRow = info.cellRange.row + iRow;
  2350. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  2351. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2352. const curCol = info.cellRange.col + iCol;
  2353. const colSetting = info.sheet.zh_setting.cols[curCol];
  2354. if (!colSetting) continue;
  2355. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2356. if (colSetting.type === 'Number') {
  2357. const exprInfo = getExprInfo(colSetting.field);
  2358. if (newValue) {
  2359. const num = _.toNumber(newValue);
  2360. if (num) {
  2361. newData[colSetting.field] = num;
  2362. if (exprInfo) {
  2363. newData[exprInfo.expr] = '';
  2364. }
  2365. } else {
  2366. try {
  2367. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2368. if (exprInfo) {
  2369. newData[exprInfo.expr] = newValue;
  2370. }
  2371. } catch(err) {
  2372. toastr.error('输入的表达式非法');
  2373. stagePosSpreadObj.loadCurPosData();
  2374. return;
  2375. }
  2376. }
  2377. } else {
  2378. newData[colSetting.field] = null;
  2379. if (exprInfo) newData[exprInfo.expr] = '';
  2380. }
  2381. } else if (colSetting.field.indexOf('_expr') > 0) {
  2382. try {
  2383. const exprInfo = getExprInfo(colSetting.field, true);
  2384. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2385. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2386. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2387. }
  2388. } catch (err) {
  2389. toastMessageUniq(hint.expr);
  2390. }
  2391. } else {
  2392. newData[colSetting.field] = newValue;
  2393. }
  2394. }
  2395. data.updateData.push(newData);
  2396. }
  2397. } else {
  2398. data.updateType = 'update';
  2399. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2400. const curRow = info.cellRange.row + iRow;
  2401. const curPos = sortData[curRow];
  2402. if (curPos) {
  2403. const newData = {pid: curPos.id, lid: curPos.lid};
  2404. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2405. const curCol = info.cellRange.col + iCol;
  2406. const colSetting = info.sheet.zh_setting.cols[curCol];
  2407. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2408. if (colSetting.type === 'Number') {
  2409. if (curPos.settle_status === settleStatus.finish) {
  2410. newData.error = 1;
  2411. continue;
  2412. }
  2413. const exprInfo = getExprInfo(colSetting.field);
  2414. if (!newValue) {
  2415. newData[colSetting.field] = newValue;
  2416. if (exprInfo) newData[exprInfo.expr] = '';
  2417. continue;
  2418. }
  2419. const num = _.toNumber(newValue);
  2420. if (num) {
  2421. newData[colSetting.field] = num;
  2422. if (exprInfo) newData[exprInfo.expr] = '';
  2423. } else {
  2424. try {
  2425. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2426. const exprInfo = getExprInfo(colSetting.field);
  2427. if (exprInfo) newData[exprInfo.expr] = newValue;
  2428. } catch(err) {
  2429. toastr.error('输入的表达式非法');
  2430. stagePosSpreadObj.loadCurPosData();
  2431. return;
  2432. }
  2433. }
  2434. } else if (colSetting.field.indexOf('_expr') > 0) {
  2435. try {
  2436. const exprInfo = getExprInfo(colSetting.field, true);
  2437. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2438. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2439. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2440. }
  2441. } catch (err) {
  2442. toastMessageUniq(hint.expr);
  2443. }
  2444. } else {
  2445. newData[colSetting.field] = newValue;
  2446. }
  2447. }
  2448. if (newData.error === undefined) data.updateData.push(newData);
  2449. }
  2450. }
  2451. }
  2452. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2453. if (result.pos) {
  2454. stagePos.updateDatas(result.pos.pos);
  2455. stagePos.loadCurStageData(result.pos.curStageData);
  2456. }
  2457. const nodes = stageTree.loadPostStageData(result.ledger);
  2458. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2459. stagePosSpreadObj.loadCurPosData();
  2460. if (detail) {
  2461. detail.loadStagePosUpdateData(result, nodes);
  2462. } else {
  2463. stageIm.loadUpdatePosData(result, nodes);
  2464. }
  2465. }, function () {
  2466. stagePosSpreadObj.loadCurPosData();
  2467. });
  2468. }
  2469. },
  2470. deletePress: function (sheet) {
  2471. if (sheet.zh_setting.readOnly) return;
  2472. if (sheet.zh_setting && sheet.zh_data) {
  2473. const sortData = sheet.zh_data;
  2474. if (!sortData || sortData.length === 0) { return; }
  2475. const sel = sheet.getSelections()[0];
  2476. const validCols = [];
  2477. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2478. const colSetting = sheet.zh_setting.cols[iCol];
  2479. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  2480. validCols.push(iCol);
  2481. }
  2482. }
  2483. if (validCols.length === 0) { return; }
  2484. const datas = [], posSelects = [];
  2485. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2486. const node = sortData[iRow];
  2487. if (node) {
  2488. const data = {pid: node.id, lid: node.lid};
  2489. for (const iCol of validCols) {
  2490. const colSetting = sheet.zh_setting.cols[iCol];
  2491. if (colSetting.field === 'name') {
  2492. toastr.error('部位名称不能为空');
  2493. return;
  2494. }
  2495. if (colSetting.Type === 'Number' && node.settle_status === settleStatus.finish) {
  2496. toastr.error('已结算节点不可计量');
  2497. return;
  2498. }
  2499. if (colSetting.field.indexOf('_expr') > 0) {
  2500. const exprInfo = getExprInfo(colSetting.field, true);
  2501. if (!exprInfo) continue;
  2502. data[exprInfo.expr] = '';
  2503. data[exprInfo.qty] = 0;
  2504. } else {
  2505. data[colSetting.field] = null;
  2506. const exprInfo = getExprInfo(colSetting.field);
  2507. if (exprInfo) {
  2508. data[exprInfo.expr] = '';
  2509. }
  2510. }
  2511. }
  2512. datas.push(data);
  2513. posSelects.push(node);
  2514. }
  2515. }
  2516. if (datas.length > 0) {
  2517. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  2518. if (result.pos) {
  2519. stagePos.updateDatas(result.pos.pos);
  2520. stagePos.loadCurStageData(result.pos.curStageData);
  2521. }
  2522. const nodes = stageTree.loadPostStageData(result.ledger);
  2523. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2524. if (detail) {
  2525. detail.loadStagePosUpdateData(result, nodes);
  2526. } else {
  2527. stageIm.loadUpdatePosData(result, nodes);
  2528. }
  2529. // todo 只加载改变项
  2530. stagePosSpreadObj.loadCurPosData();
  2531. });
  2532. }
  2533. }
  2534. },
  2535. deletePos: function (sheet) {
  2536. const sels = sheet.getSelections();
  2537. const sel = sels ? sels[0] : null;
  2538. if (sheet.zh_data && sel) {
  2539. const data = {updateType: 'delete', updateData: []};
  2540. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  2541. const posData = sheet.zh_data[sel.row + iRow];
  2542. if (posData) {
  2543. data.updateData.push(posData.id);
  2544. }
  2545. }
  2546. if (data.updateData.length > 0) {
  2547. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2548. stagePos.removeDatas(result.pos.pos);
  2549. const refreshData = stageTree.loadPostStageData(result.ledger);
  2550. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2551. stagePosSpreadObj.loadCurPosData();
  2552. if (detail) {
  2553. detail.loadStagePosUpdateData(result, refreshData);
  2554. } else {
  2555. stageIm.loadUpdatePosData(result, refreshData);
  2556. }
  2557. });
  2558. }
  2559. }
  2560. },
  2561. selectionChanged: function (e, info) {
  2562. stagePosSpreadObj.loadExprToInput(info.sheet);
  2563. },
  2564. addPegs: function (pegs) {
  2565. if (!pegs || pegs.length <= 0) return;
  2566. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2567. if (!node) return;
  2568. const sheet = spSpread.getActiveSheet();
  2569. const sortData = sheet.zh_data || [];
  2570. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2571. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2572. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2573. if (result.pos) {
  2574. stagePos.updateDatas(result.pos.pos);
  2575. }
  2576. stagePosSpreadObj.loadCurPosData();
  2577. });
  2578. }
  2579. };
  2580. $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
  2581. $('#pos-un-measure').click(stagePosSpreadObj.loadCurPosData);
  2582. // 加载上下窗口resizer
  2583. $.divResizer({
  2584. select: '#main-resize',
  2585. callback: function () {
  2586. slSpread.refresh();
  2587. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2588. $(".sp-wrap").height(bcontent-30);
  2589. spSpread.refresh();
  2590. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2591. }
  2592. });
  2593. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2594. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag;reCalcChange' }, function (result) {
  2595. // 加载树结构
  2596. stageTree.loadDatas(result.ledgerData, result.locked);
  2597. if (stage.assist) {
  2598. stageTree.loadFilter(stage.assist.ass_ledger_id);
  2599. } else if (stage.relaAuditor && stage.relaAuditor.audit_ledger_id) {
  2600. stageTree.loadFilter(stage.relaAuditor.audit_ledger_id);
  2601. }
  2602. // 加载部位明细
  2603. stagePos.loadDatas(result.posData);
  2604. stageTreeSpreadObj.loadChangeData(stageTree, stagePos, result.reCalcChange);
  2605. checkShowLast(result.ledgerData.length);
  2606. treeCalc.calculateAll(stageTree);
  2607. for (const t of result.tags) {
  2608. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2609. }
  2610. billsTag.loadDatas(result.tags);
  2611. stagePos.calculateAll();
  2612. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2613. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2614. stagePosSpreadObj.loadCurPosData();
  2615. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2616. TreeExprCalc.init({
  2617. tree: stageTree,
  2618. decimal: tenderInfo.decimal,
  2619. precision: tenderInfo.precision,
  2620. calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
  2621. exprFieldsIndex: {
  2622. tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',
  2623. bqhtje: 'contract_tp',
  2624. },
  2625. exprCacheKey: ['bqhtje'],
  2626. });
  2627. // 加载中间计量
  2628. stageIm.init(tenderInfo, stage, imType, tenderInfo.decimal);
  2629. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.stageChange, result.import_change, result.detailAtt);
  2630. if (stage.assist) {
  2631. stageIm.loadFilter(stage.assist.ass_ledger_id);
  2632. } else if (stage.relaAuditor) {
  2633. stageIm.loadFilter(stage.relaAuditor.audit_ledger_id);
  2634. }
  2635. errorList.loadHisErrorData();
  2636. checkList.loadHisCheckData();
  2637. sumLoadMiss.loadHisMissData();
  2638. // 收方单赋值
  2639. ledgerData = result.ledgerData;
  2640. posData = result.posData;
  2641. makeShouFang();
  2642. }, null, true);
  2643. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2644. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2645. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2646. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2647. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2648. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2649. if (!readOnly) {
  2650. $('#pos-expr').bind('change onblur', function () {
  2651. if (this.readOnly) return;
  2652. const expr = $(this);
  2653. const posSheet = spSpread.getActiveSheet();
  2654. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2655. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2656. if (!select) return;
  2657. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2658. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2659. const data = {pid: select.id, lid: select.lid};
  2660. const exprInfo = getExprInfo(field);
  2661. if (newValue !== '') {
  2662. const num = _.toNumber(newValue);
  2663. if (num) {
  2664. data[field] = num;
  2665. if (exprInfo) data[exprInfo.expr] = '';
  2666. } else {
  2667. try {
  2668. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2669. if (exprInfo) data[exprInfo.expr] = newValue;
  2670. } catch (err) {
  2671. toastr.error('输入的表达式非法');
  2672. return;
  2673. }
  2674. }
  2675. } else {
  2676. data[field] = null;
  2677. if (exprInfo) data[exprInfo.expr] = '';
  2678. }
  2679. // 提交数据到服务器
  2680. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2681. if (result.pos) {
  2682. stagePos.updateDatas(result.pos.pos);
  2683. stagePos.loadCurStageData(result.pos.curStageData);
  2684. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2685. }
  2686. const refreshData = stageTree.loadPostStageData(result.ledger);
  2687. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2688. if (detail) {
  2689. detail.loadStagePosUpdateData(result, refreshData);
  2690. } else {
  2691. stageIm.loadUpdatePosData(result, refreshData);
  2692. }
  2693. });
  2694. });
  2695. }
  2696. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2697. $.contextMenu({
  2698. selector: '#stage-pos',
  2699. build: function ($trigger, e) {
  2700. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2701. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2702. },
  2703. items: {
  2704. 'del': {
  2705. name: '删除',
  2706. icon: 'fa-remove',
  2707. visible: function (key, opt) {
  2708. return !checkTzMeasureType();
  2709. },
  2710. disabled: function (key, opt) {
  2711. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2712. if (!node || node.lock) return true;
  2713. const sheet = spSpread.getActiveSheet();
  2714. if (sheet.zh_data && !readOnly) {
  2715. const selection = sheet.getSelections();
  2716. if (selection && selection[0]) {
  2717. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2718. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2719. const posData = sheet.zh_data[selection[0].row + iRow];
  2720. if (posData) {
  2721. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2722. valid = true;
  2723. break;
  2724. }
  2725. } else {
  2726. valid = true;
  2727. break;
  2728. }
  2729. }
  2730. return valid;
  2731. } else {
  2732. return true;
  2733. }
  2734. } else {
  2735. return true;
  2736. }
  2737. },
  2738. callback: function (key, opt) {
  2739. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2740. }
  2741. },
  2742. 'sort': {
  2743. name: '排序',
  2744. items: {
  2745. "addStageReverse": {
  2746. name: '按新增期倒序',
  2747. icon: 'fa-sort-amount-desc',
  2748. callback: function (key, opt) {
  2749. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2750. const spSheet = spSpread.getActiveSheet();
  2751. if (spSheet.zh_data) {
  2752. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2753. SpreadJsObj.reLoadSheetData(spSheet);
  2754. }
  2755. }
  2756. }
  2757. }
  2758. },
  2759. 'merge-peg': {
  2760. name: '合并起讫桩号',
  2761. visible: function (key, opt) {
  2762. return !checkTzMeasureType();
  2763. },
  2764. disabled: function (key, opt) {
  2765. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2766. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2767. },
  2768. callback: function (key, opt) {
  2769. mergePeg.show();
  2770. }
  2771. },
  2772. 'calcByRatio': {
  2773. name: '按比例计量',
  2774. visible: function (key, opt) {
  2775. const data = spSpread.getActiveSheet().zh_data;
  2776. return checkTzMeasureType() && data && data.length > 0;
  2777. },
  2778. disabled: function (key, opt) {
  2779. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2780. return node.lock;
  2781. },
  2782. callback: function (key, opt) {
  2783. $('#cbr-ratio').val('');
  2784. $('#apply2sibling')[0].checked = false;
  2785. $('#cbr-check-all')[0].checked = false;
  2786. const html = [];
  2787. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2788. html.push('<tr>');
  2789. html.push('<td>', i+1, '</td>');
  2790. html.push('<td>', p.name, '</td>');
  2791. html.push('<td>', p.quantity, '</td>');
  2792. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2793. html.push('</tr>');
  2794. }
  2795. $('#cbr-pos-list').html(html.join(''));
  2796. $('#calc-by-ratio').modal('show');
  2797. }
  2798. },
  2799. 'remainCur': {
  2800. name: '填剩余量(选中行)',
  2801. disabled: function (key, opt) {
  2802. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2803. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2804. return readOnly || node.lock || !curPos;
  2805. },
  2806. callback: function (key, opt) {
  2807. const sheet = spSpread.getActiveSheet();
  2808. const sels = sheet.getSelections();
  2809. if (!sels || !sels[0]) return;
  2810. const data = { updateType: 'update', updateData: [] };
  2811. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2812. const curRow = iRow + sels[0].row;
  2813. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2814. if (!curPos) continue;
  2815. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2816. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2817. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2818. }
  2819. if (data.updateData.length > 0) {
  2820. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2821. if (result.pos) {
  2822. stagePos.updateDatas(result.pos.pos);
  2823. stagePos.loadCurStageData(result.pos.curStageData);
  2824. }
  2825. const nodes = stageTree.loadPostStageData(result.ledger);
  2826. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2827. stagePosSpreadObj.loadCurPosData();
  2828. if (detail) {
  2829. detail.loadStagePosUpdateData(result, nodes);
  2830. } else {
  2831. stageIm.loadUpdatePosData(result, nodes);
  2832. }
  2833. });
  2834. }
  2835. },
  2836. visible: function(key, opt) {
  2837. return checkTzMeasureType();
  2838. },
  2839. },
  2840. 'remainAll': {
  2841. name: '填剩余量(全部行)',
  2842. disabled: function (key, opt) {
  2843. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2844. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2845. return readOnly || node.lock || !curPos;
  2846. },
  2847. callback: function (key, opt) {
  2848. const sheet = spSpread.getActiveSheet();
  2849. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2850. const data = { updateType: 'update', updateData: [] };
  2851. for (const curPos of sheet.zh_data) {
  2852. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2853. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2854. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2855. }
  2856. if (data.updateData.length > 0) {
  2857. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2858. if (result.pos) {
  2859. stagePos.updateDatas(result.pos.pos);
  2860. stagePos.loadCurStageData(result.pos.curStageData);
  2861. }
  2862. const nodes = stageTree.loadPostStageData(result.ledger);
  2863. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2864. stagePosSpreadObj.loadCurPosData();
  2865. if (detail) {
  2866. detail.loadStagePosUpdateData(result, nodes);
  2867. } else {
  2868. stageIm.loadUpdatePosData(result, nodes);
  2869. }
  2870. });
  2871. }
  2872. },
  2873. visible: function(key, opt) {
  2874. return checkTzMeasureType();
  2875. },
  2876. },
  2877. 'shoufangdan': {
  2878. name: '生成收方单',
  2879. visible: function(key, opt) {
  2880. if (cur_uid === stage.user_id) return true;
  2881. },
  2882. disabled: function (key, opt) {
  2883. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2884. if (!node || cur_uid !== stage.user_id) return true;
  2885. },
  2886. callback: function (key, opt) {
  2887. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2888. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2889. $('#shoufang-lid').val(node.lid);
  2890. $('#shoufang-pid').val(node.id);
  2891. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2892. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2893. $('#addshoufang').modal('show');
  2894. }
  2895. }
  2896. }
  2897. });
  2898. $.subMenu({
  2899. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2900. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2901. key: 'menu.1.0.0',
  2902. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2903. callback: function (info) {
  2904. if (info.mini) {
  2905. $('.panel-title').addClass('fluid');
  2906. $('#sub-menu').removeClass('panel-sidebar');
  2907. } else {
  2908. $('.panel-title').removeClass('fluid');
  2909. $('#sub-menu').addClass('panel-sidebar');
  2910. }
  2911. autoFlashHeight();
  2912. slSpread.refresh();
  2913. spSpread.refresh();
  2914. if (searchLedger) searchLedger.spread.refresh();
  2915. if (detail) detail.spread.refresh();
  2916. if (checkedChanges) checkedChanges.refresh();
  2917. if (errorList && errorList.spread) errorList.spread.refresh();
  2918. if (checkList) checkList.spread.refresh();
  2919. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2920. }
  2921. });
  2922. $('#row-view').on('show.bs.modal', function () {
  2923. const html = [], customDisplay = customColDisplay();
  2924. for (const cd of customDisplay) {
  2925. html.push('<tr>');
  2926. html.push('<td>', cd.title, '</td>');
  2927. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2928. html.push('</tr>');
  2929. }
  2930. $('#row-view-list').html(html.join(''));
  2931. });
  2932. $('#row-view-ok').click(function () {
  2933. const customDisplay = customColDisplay();
  2934. const cvl = $('#row-view-list').children();
  2935. for (const cv of cvl) {
  2936. const title = $(cv).children()[0].innerHTML;
  2937. const check = $('input', cv)[0].checked;
  2938. const cd = customDisplay.find(function (c) {
  2939. return c.title === title;
  2940. });
  2941. cd.visible = check;
  2942. }
  2943. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2944. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2945. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2946. $('#row-view').modal('hide');
  2947. });
  2948. const posSearch = (function () {
  2949. let resultArr = [];
  2950. const search = function () {
  2951. resultArr = [];
  2952. const keyword = $('#pos-search-keyword').val();
  2953. const checkOver = $('#pos-over-search')[0].checked;
  2954. const checkEmpty = $('#pos-empty-search')[0].checked;
  2955. const sortData = spSpread.getActiveSheet().zh_data;
  2956. if (checkOver || checkEmpty) {
  2957. if (sortData) {
  2958. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2959. const sd = sortData[i];
  2960. let match = false;
  2961. if (checkOver) {
  2962. if (sd.end_gather_qty) {
  2963. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2964. }
  2965. }
  2966. if (checkEmpty) {
  2967. if (sd.quantity) {
  2968. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2969. }
  2970. }
  2971. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2972. if (match) {
  2973. resultArr.push({index: i, data: sd});
  2974. }
  2975. }
  2976. }
  2977. } else if (keyword && keyword !== '') {
  2978. if (sortData) {
  2979. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2980. const sd = sortData[i];
  2981. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2982. resultArr.push({index: i, data: sd});
  2983. }
  2984. }
  2985. }
  2986. }
  2987. $('#pos-search-result').html('结果:' + resultArr.length);
  2988. };
  2989. const searchAndLocate = function () {
  2990. search();
  2991. if (resultArr.length > 0) {
  2992. const sheet = spSpread.getActiveSheet();
  2993. const sel = sheet.getSelections()[0];
  2994. const curRow = sel ? sel.row : 0;
  2995. const pos = resultArr[0];
  2996. if (pos.index !== curRow) {
  2997. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2998. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2999. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  3000. }
  3001. }
  3002. };
  3003. const locateNext = function () {
  3004. if (resultArr.length > 0) {
  3005. const sheet = spSpread.getActiveSheet();
  3006. const sel = sheet.getSelections()[0];
  3007. const curRow = sel ? sel.row : 0;
  3008. let next = _.find(resultArr, function (d) {
  3009. return d.index > curRow;
  3010. });
  3011. if (!next) next = resultArr[0];
  3012. if (next.index !== curRow) {
  3013. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  3014. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  3015. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  3016. }
  3017. }
  3018. };
  3019. const locatePre = function () {
  3020. if (resultArr.length > 0) {
  3021. const sheet = spSpread.getActiveSheet();
  3022. const sel = sheet.getSelections()[0];
  3023. const curRow = sel ? sel.row : 0;
  3024. let next = _.findLast(resultArr, function (d) {
  3025. return d.index < curRow;
  3026. });
  3027. if (!next) next = resultArr[resultArr.length - 1];
  3028. if (next.index !== curRow) {
  3029. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  3030. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  3031. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  3032. }
  3033. }
  3034. };
  3035. return {search, searchAndLocate, locateNext, locatePre};
  3036. })();
  3037. $('#pos-search-keyword').bind('keydown', function(e){
  3038. if (e.keyCode == 13) posSearch.searchAndLocate();
  3039. });
  3040. $('#pos-empty-search').click(function () {
  3041. if (this.checked) {
  3042. $('[for=' + this.id +']').addClass('text-warning');
  3043. } else {
  3044. $('[for=' + this.id +']').removeClass('text-warning');
  3045. }
  3046. if (this.checked) {
  3047. if ($('#pos-over-search')[0].checked) {
  3048. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3049. } else {
  3050. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3051. }
  3052. } else {
  3053. if ($('#pos-over-search')[0].checked) {
  3054. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3055. } else {
  3056. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3057. }
  3058. }
  3059. posSearch.searchAndLocate();
  3060. });
  3061. $('#pos-over-search').click(function () {
  3062. if (this.checked) {
  3063. $('[for=' + this.id +']').addClass('text-danger');
  3064. } else {
  3065. $('[for=' + this.id +']').removeClass('text-danger');
  3066. }
  3067. if (this.checked) {
  3068. if ($('#pos-empty-search')[0].checked) {
  3069. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3070. } else {
  3071. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  3072. }
  3073. } else {
  3074. if ($('#pos-empty-search')[0].checked) {
  3075. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  3076. } else {
  3077. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  3078. }
  3079. }
  3080. posSearch.searchAndLocate();
  3081. });
  3082. $('#pos-search-next').click(() => {posSearch.locateNext()});
  3083. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  3084. $.divResizer({
  3085. select: '#right-spr',
  3086. callback: function () {
  3087. autoFlashHeight();
  3088. slSpread.refresh();
  3089. spSpread.refresh();
  3090. if (searchLedger) {
  3091. searchLedger.spread.refresh();
  3092. }
  3093. if (detail) {
  3094. detail.spread.refresh();
  3095. }
  3096. if (checkedChanges) checkedChanges.refresh();
  3097. if (errorList && errorList.spread) errorList.spread.refresh();
  3098. if (checkList) checkList.spread.refresh();
  3099. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  3100. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3101. }
  3102. });
  3103. // 中间计量加载上下窗口resizer
  3104. $.divResizer({
  3105. select: '#zhongjian-spr',
  3106. callback: function () {
  3107. if (detail) {
  3108. detail.spread.refresh();
  3109. }
  3110. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3111. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3112. }
  3113. });
  3114. // 附件加载上下窗口resizer
  3115. $.divResizer({
  3116. select: '#file-spr',
  3117. callback: function () {
  3118. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3119. }
  3120. });
  3121. // 变更令加载上下窗口resizer
  3122. $.divResizer({
  3123. select: '#change-spr',
  3124. callback: function () {
  3125. if (checkedChanges) checkedChanges.refresh();
  3126. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  3127. }
  3128. });
  3129. class Detail {
  3130. constructor (obj) {
  3131. const self = this;
  3132. this.spreadSetting = {
  3133. cols: [
  3134. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3135. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3136. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3137. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  3138. {
  3139. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  3140. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  3141. },
  3142. {
  3143. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  3144. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  3145. return data.attachment ? data.attachment.length : 0;
  3146. }
  3147. },
  3148. ],
  3149. headRows: 1,
  3150. emptyRows: 0,
  3151. headRowHeight: [32],
  3152. headColWidth: [30],
  3153. defaultRowHeight: 21,
  3154. headerFont: '12px 微软雅黑',
  3155. font: '12px 微软雅黑',
  3156. readOnly: readOnly,
  3157. selectedBackColor: '#fffacd',
  3158. imageClick: function (data) {
  3159. self.makeAttTable(data);
  3160. $('#im-file').modal('show');
  3161. }
  3162. };
  3163. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  3164. this.sheet = this.spread.getActiveSheet();
  3165. this.spread.options.allowUserDragFill = true;
  3166. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  3167. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3168. this.detailObj = {
  3169. selectionChanged: function (e, info) {
  3170. self.reLoadDetailData();
  3171. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  3172. self.loadLocateInfo();
  3173. }
  3174. },
  3175. editEnded: function(e, info) {
  3176. if (info.sheet.zh_setting) {
  3177. const col = info.sheet.zh_setting.cols[info.col];
  3178. if (col.field !== 'doc_code') {
  3179. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3180. return;
  3181. }
  3182. const data = SpreadJsObj.getSelectObject(info.sheet);
  3183. if (data) {
  3184. const updateData = {lid: data.lid, pid: data.pid};
  3185. if (data.uuid) {
  3186. updateData.uuid = data.uuid;
  3187. } else {
  3188. updateData.code = data.code;
  3189. updateData.name = data.name;
  3190. updateData.unit = data.unit;
  3191. updateData.unit_price = data.unit_price;
  3192. updateData.pid = data.pid;
  3193. updateData.pos_name = data.pos_name;
  3194. updateData.im_type = data.im_type;
  3195. }
  3196. if (data.custom_define.indexOf('doc_code') === -1) {
  3197. updateData.custom_define = data.custom_define;
  3198. updateData.custom_define.push('doc_code');
  3199. updateData.custom_define = updateData.custom_define.join(',');
  3200. }
  3201. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  3202. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3203. stageIm.loadUpdateDetailData(result);
  3204. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3205. }, function () {
  3206. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3207. });
  3208. } else {
  3209. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3210. }
  3211. }
  3212. },
  3213. clipboardPasted: function (e, info) {
  3214. if (info.sheet.zh_setting && info.sheet.zh_data) {
  3215. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  3216. if (info.cellRange.colCount > 1) {
  3217. toastr.warning('请勿同时复制粘贴多列数据');
  3218. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3219. return;
  3220. }
  3221. if (col.field !== 'doc_code') {
  3222. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3223. return;
  3224. }
  3225. const datas = [];
  3226. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3227. const curRow = info.cellRange.row + iRow;
  3228. const data = info.sheet.zh_data[curRow];
  3229. if (data) {
  3230. const updateData = {lid: data.lid, pid: data.pid};
  3231. if (data.uuid) {
  3232. updateData.uuid = data.uuid;
  3233. } else {
  3234. updateData.code = data.code;
  3235. updateData.name = data.name;
  3236. updateData.unit = data.unit;
  3237. updateData.unit_price = data.unit_price;
  3238. updateData.pid = data.pid;
  3239. updateData.pos_name = data.pos_name;
  3240. updateData.im_type = data.im_type;
  3241. }
  3242. if (data.custom_define.indexOf('doc_code') === -1) {
  3243. updateData.custom_define = data.custom_define;
  3244. updateData.custom_define.push('doc_code');
  3245. updateData.custom_define = updateData.custom_define.join(',');
  3246. }
  3247. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  3248. datas.push(updateData);
  3249. }
  3250. }
  3251. if (datas.length > 0) {
  3252. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3253. stageIm.loadUpdateDetailData(result);
  3254. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3255. }, function () {
  3256. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3257. })
  3258. }
  3259. }
  3260. },
  3261. deletePress: function (sheet) {
  3262. if (sheet.zh_setting) {
  3263. const datas = [];
  3264. const sel = sheet.getSelections()[0];
  3265. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3266. const col = sheet.zh_setting.cols[iCol];
  3267. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3268. const data = sheet.zh_data[iRow];
  3269. if (col.field === 'doc_code') {
  3270. const updateData = {lid: data.lid};
  3271. if (data.uuid) {
  3272. updateData.uuid = data.uuid;
  3273. updateData.doc_code = '';
  3274. datas.push(updateData);
  3275. }
  3276. }
  3277. }
  3278. }
  3279. if (datas.length > 0) {
  3280. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3281. stageIm.loadUpdateDetailData(result);
  3282. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3283. }, function () {
  3284. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3285. });
  3286. }
  3287. }
  3288. },
  3289. dragFillBlock: function (e, info) {
  3290. info.cancel = true;
  3291. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  3292. const sel = info.sheet.getSelections()[0];
  3293. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  3294. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  3295. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  3296. if (text === '') return;
  3297. const regRst = /(\d+)$/g.exec(text), datas = [];
  3298. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  3299. const curRow = info.fillRange.row + iRow;
  3300. const data = info.sheet.zh_data[curRow];
  3301. if (data) {
  3302. const updateData = {lid: data.lid};
  3303. if (data.uuid) {
  3304. updateData.uuid = data.uuid;
  3305. } else {
  3306. updateData.code = data.code;
  3307. updateData.name = data.name;
  3308. updateData.unit = data.unit;
  3309. updateData.unit_price = data.unit_price;
  3310. updateData.pid = data.pid;
  3311. updateData.pos_name = data.pos_name;
  3312. updateData.im_type = data.im_type;
  3313. }
  3314. if (regRst) {
  3315. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  3316. } else {
  3317. updateData.doc_code = text.replace('\n', '');
  3318. }
  3319. if (data.custom_define.indexOf('doc_code') === -1) {
  3320. updateData.custom_define = data.custom_define;
  3321. updateData.custom_define.push('doc_code');
  3322. updateData.custom_define = updateData.custom_define.join(',');
  3323. }
  3324. datas.push(updateData);
  3325. }
  3326. }
  3327. if (datas.length > 0) {
  3328. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3329. stageIm.loadUpdateDetailData(result);
  3330. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3331. }, function () {
  3332. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3333. })
  3334. }
  3335. },
  3336. };
  3337. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  3338. if (!readOnly) {
  3339. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  3340. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  3341. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  3342. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  3343. }
  3344. this._initImTypeSetRela();
  3345. this._initModifyDetail();
  3346. this._initLocateRela();
  3347. this._initAttRela();
  3348. // 草图相关
  3349. this._initImageRela();
  3350. this.reBuildImData();
  3351. }
  3352. makeAttTable (data) {
  3353. let html = [];
  3354. if (data.attachment) {
  3355. for (const att of data.attachment) {
  3356. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked || deleteFilePermission))
  3357. ? '<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>'
  3358. : '';
  3359. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  3360. 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>';
  3361. 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>',
  3362. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  3363. }
  3364. }
  3365. $('#im-attList').html(html.join(''));
  3366. }
  3367. _initAttRela() {
  3368. // 上传附件
  3369. const self = this;
  3370. $('#upload-im-file').change(function () {
  3371. const files = this.files;
  3372. const sels = self.sheet.getSelections();
  3373. const select = SpreadJsObj.getSelectObject(self.sheet);
  3374. if (!select) return;
  3375. const formData = new FormData();
  3376. const baseInfo = {};
  3377. if (select.att_uuid) {
  3378. baseInfo.uuid = select.att_uuid;
  3379. } else {
  3380. baseInfo.im_type = select.im_type;
  3381. baseInfo.lid = select.lid;
  3382. baseInfo.pid = select.pid;
  3383. baseInfo.code = select.code;
  3384. baseInfo.name = select.name;
  3385. baseInfo.unit = select.unit;
  3386. baseInfo.unit_price = select.unit_price;
  3387. baseInfo.pos_name = select.pos_name;
  3388. }
  3389. formData.append('base', JSON.stringify(baseInfo));
  3390. for (const file of files) {
  3391. if (file === undefined) {
  3392. toast('未选择上传文件!', 'error');
  3393. return false;
  3394. }
  3395. const filesize = file.size;
  3396. if (filesize > 50 * 1024 * 1024) {
  3397. toast('存在上传文件大小过大!', 'error');
  3398. return false;
  3399. }
  3400. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3401. if (whiteList.indexOf(fileext) === -1) {
  3402. toast('只能上传指定格式的附件!', 'error');
  3403. return false;
  3404. }
  3405. formData.append('size', filesize);
  3406. formData.append('file[]', file);
  3407. }
  3408. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  3409. stageIm.loadUpdateDetailAtt(data);
  3410. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3411. self.makeAttTable(select);
  3412. $('#upload-im-file').val('');
  3413. });
  3414. });
  3415. // 删除附件
  3416. $('body').on('click', '.delete-att' ,function () {
  3417. const sels = self.sheet.getSelections();
  3418. const select = SpreadJsObj.getSelectObject(self.sheet);
  3419. if (!select) return;
  3420. const uuid = $(this).attr('data-imid');
  3421. const file_id = $(this).attr('data-attid');
  3422. const att = select.attachment.find(x => {
  3423. return x.file_id === file_id;
  3424. });
  3425. deleteAfterHint(function () {
  3426. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  3427. stageIm.loadUpdateDetailAtt(result);
  3428. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3429. self.makeAttTable(select);
  3430. });
  3431. }, `确认删除附件「${att.filename}」?`);
  3432. });
  3433. // 预览附件
  3434. $('body').on('click', '.preview-att', function () {
  3435. const uuid = $(this).attr('data-imid');
  3436. const file_id = $(this).attr('data-attid');
  3437. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  3438. const { filepath } = result;
  3439. $('#load-file').attr('href', filepath);
  3440. $('#load-file')[0].click();
  3441. });
  3442. });
  3443. $('#batch-download-im-file').click(function() {
  3444. const select = $('[name=sia-check]:checked');
  3445. if (select.length === 0) {
  3446. toastr.warning('请选择需要批量下载的文件');
  3447. return;
  3448. }
  3449. const files = [];
  3450. const curIm = SpreadJsObj.getSelectObject(self.sheet);
  3451. for (const s of select) {
  3452. const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
  3453. if (att) files.push(att);
  3454. }
  3455. if (files.length === 0) return;
  3456. AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
  3457. $(self).removeAttr('disabled');
  3458. if (fails.length === 0) {
  3459. toastr.success('下载成功');
  3460. } else {
  3461. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  3462. }
  3463. }, () => {
  3464. $(self).removeAttr('disabled');
  3465. toastr.error('批量下载失败');
  3466. });
  3467. });
  3468. }
  3469. _initImTypeSetRela() {
  3470. const self = this;
  3471. const gatherConfirmPopover = {
  3472. reBind: function (obj, eventName, fun) {
  3473. obj.unbind(eventName);
  3474. obj.bind(eventName, fun);
  3475. },
  3476. check: function (pos, hint, okCallback) {
  3477. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  3478. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  3479. this.reBind(cancelObj, 'click', function () {
  3480. confirmObj.hide();
  3481. });
  3482. this.reBind(okObj, 'click', function () {
  3483. okCallback();
  3484. confirmObj.hide();
  3485. });
  3486. hintObj.text(hint);
  3487. confirmObj.css("top", pos.y).css("left", pos.x).show();
  3488. }
  3489. };
  3490. this.gsTree = stageIm.getGsTree();
  3491. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3492. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3493. jlCol.title = '本期计量金额';
  3494. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3495. $('[name=type-title-contract]').text('本期合同计量金额');
  3496. $('[name=type-title-qc]').text('本期变更计量金额');
  3497. if ($('#show-qc-minus-jl').length > 0) {
  3498. $('#show-qc-minus-jl').parent().hide();
  3499. $('#qc-minus-jl').parent().hide();
  3500. }
  3501. } else {
  3502. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3503. jlCol.title = '本期计量数量';
  3504. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3505. $('[name=type-title-contract]').text('本期合同计量数量');
  3506. $('[name=type-title-qc]').text('本期变更计量数量');
  3507. if ($('#show-qc-minus-jl').length > 0) {
  3508. $('#show-qc-minus-jl').parent().show();
  3509. $('#qc-minus-jl').parent().show();
  3510. }
  3511. }
  3512. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3513. $('#show-jldy').parent().show();
  3514. $('#jldy').parent().show();
  3515. $('#show-xm-name').parent().hide();
  3516. $('#xm-name').parent().hide();
  3517. } else {
  3518. $('#show-jldy').parent().hide();
  3519. $('#jldy').parent().hide();
  3520. $('#show-xm-name').parent().show();
  3521. $('#xm-name').parent().show();
  3522. }
  3523. // 选择中间计量模式
  3524. $('div[name="im-type"]').click(function () {
  3525. function chooseType(obj) {
  3526. obj.style.cursor = 'default';
  3527. $(obj).children().addClass('text-primary');
  3528. $(obj).addClass('border-primary');
  3529. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3530. }
  3531. function validType(obj) {
  3532. obj.style.cursor = 'pointer';
  3533. $(obj).children().removeClass('text-primary');
  3534. $(obj).removeClass('border-primary');
  3535. $('i', obj).remove();
  3536. }
  3537. if (this.style.cursor === 'pointer') {
  3538. const typeArr = $('div[name="im-type"]');
  3539. for (const t of typeArr) {
  3540. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  3541. chooseType(t);
  3542. } else {
  3543. validType(t)
  3544. }
  3545. }
  3546. }
  3547. });
  3548. $('#choose').on('show.bs.modal', function () {
  3549. function chooseType(obj) {
  3550. obj.style.cursor = 'default';
  3551. $(obj).children().addClass('text-primary');
  3552. $('i', obj).remove();
  3553. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3554. }
  3555. function validType(obj) {
  3556. obj.style.cursor = 'pointer';
  3557. $(obj).children().removeClass('text-primary');
  3558. $('i', obj).remove();
  3559. }
  3560. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  3561. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  3562. const typeArr = $('div[name="im-type"]');
  3563. for (const t of typeArr) {
  3564. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  3565. chooseType(t);
  3566. } else {
  3567. validType(t)
  3568. }
  3569. }
  3570. });
  3571. // 提交 中间计量模式
  3572. $('#choose-ok').click(() => {
  3573. let startNum;
  3574. try {
  3575. startNum = parseInt($('#im-start-num').val());
  3576. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  3577. } catch (err) {
  3578. toastr.error("起始编号请输入正整数");
  3579. return;
  3580. }
  3581. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  3582. return it.style.cursor !== 'pointer';
  3583. });
  3584. const data = {
  3585. im_type: parseInt($(chooseType).attr('im-type')),
  3586. im_pre: $('#im-pre').val(),
  3587. im_start_num: startNum,
  3588. };
  3589. postData(window.location.pathname + '/detail/build', data, function (result) {
  3590. stage.im_type = data.im_type;
  3591. stage.im_pre = data.im_pre;
  3592. stage.im_start_num = data.im_start_num;
  3593. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3594. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3595. jlCol.title = '本期计量金额';
  3596. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3597. $('[name=type-title-contract]').text('本期合同计量金额');
  3598. $('[name=type-title-qc]').text('本期变更计量金额');
  3599. if ($('#show-qc-minus-jl').length > 0) {
  3600. $('#show-qc-minus-jl').parent().hide();
  3601. $('#qc-minus-jl').parent().hide();
  3602. }
  3603. } else {
  3604. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3605. jlCol.title = '本期计量数量';
  3606. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3607. $('[name=type-title-contract]').text('本期合同计量数量');
  3608. $('[name=type-title-qc]').text('本期变更计量数量');
  3609. if ($('#show-qc-minus-jl').length > 0) {
  3610. $('#show-qc-minus-jl').parent().show();
  3611. $('#qc-minus-jl').parent().show();
  3612. }
  3613. }
  3614. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3615. $('#show-jldy').parent().show();
  3616. $('#jldy').parent().show();
  3617. $('#show-xm-name').parent().hide();
  3618. $('#xm-name').parent().hide();
  3619. } else {
  3620. $('#show-jldy').parent().hide();
  3621. $('#jldy').parent().hide();
  3622. $('#show-xm-name').parent().show();
  3623. $('#xm-name').parent().show();
  3624. }
  3625. // 加载生成数据
  3626. self.reBuildImData();
  3627. $('#choose').modal('hide');
  3628. });
  3629. });
  3630. // 显示树结构信息
  3631. $('#choose2').on('shown.bs.modal', function () {
  3632. if (!self.gsSpread) {
  3633. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3634. const setting = {
  3635. cols: [
  3636. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3637. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3638. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3639. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3640. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3641. ],
  3642. headRows: 1,
  3643. emptyRows: 0,
  3644. headRowHeight: [32],
  3645. defaultRowHeight: 21,
  3646. headerFont: '12px 微软雅黑',
  3647. font: '12px 微软雅黑',
  3648. };
  3649. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3650. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3651. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3652. function checkParent(node) {
  3653. const parent = self.gsTree.getParent(node);
  3654. if (parent) {
  3655. return parent.check ? parent.check : checkParent(parent);
  3656. } else {
  3657. return false;
  3658. }
  3659. }
  3660. function checkChildren(node) {
  3661. for (const child of node.children) {
  3662. if (child.check) {
  3663. return true;
  3664. } else if (checkChildren(child)) {
  3665. return true;
  3666. }
  3667. }
  3668. return false;
  3669. }
  3670. if (!$('#im-gather-check')[0].checked) { return; }
  3671. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3672. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3673. if (sheet.isEditing()) {
  3674. sheet.endEdit(true);
  3675. }
  3676. }
  3677. if (info.sheet.zh_setting) {
  3678. const col = info.sheet.zh_setting.cols[info.col];
  3679. if (col.field !== 'check') {
  3680. return;
  3681. }
  3682. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3683. const node = sortData[info.row];
  3684. if (!node.check) {
  3685. if (checkParent(node)) {
  3686. const rect = info.sheet.getCellRect(info.row, info.col);
  3687. gatherConfirmPopover.check({
  3688. x: rect.x + rect.width / 2 + 25,
  3689. y: rect.y + rect.height / 2 + 3,
  3690. }, '父项已勾选,继续将取消父项勾选。', function () {
  3691. node.check = true;
  3692. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3693. const rows = [self.gsTree.nodes.indexOf(node)];
  3694. for (const p of parents) {
  3695. if (p.check) {
  3696. p.check = false;
  3697. rows.push(self.gsTree.nodes.indexOf(p));
  3698. }
  3699. }
  3700. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3701. });
  3702. } else if (checkChildren(node)) {
  3703. const rect = info.sheet.getCellRect(info.row, info.col);
  3704. gatherConfirmPopover.check({
  3705. x: rect.x + rect.width / 2 + 25,
  3706. y: rect.y + rect.height / 2 + 3,
  3707. }, '子项已勾选,继续将取消子项勾选。', function () {
  3708. node.check = true;
  3709. const posterity = self.gsTree.getPosterity(node);
  3710. const rows = [self.gsTree.nodes.indexOf(node)];
  3711. for (const p of posterity) {
  3712. if (p.check) {
  3713. rows.push(self.gsTree.nodes.indexOf(p));
  3714. p.check = false;
  3715. }
  3716. }
  3717. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3718. });
  3719. } else {
  3720. node.check = true;
  3721. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3722. }
  3723. } else {
  3724. node.check = false;
  3725. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3726. }
  3727. }
  3728. });
  3729. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3730. for (const node of self.gsTree.datas) {
  3731. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3732. }
  3733. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3734. self.gsTree.expandByLevel(4);
  3735. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3736. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3737. } else {
  3738. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3739. for (const node of self.gsTree.datas) {
  3740. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3741. }
  3742. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3743. }
  3744. });
  3745. // 提交 高级设置
  3746. $('#choose2-ok').click(() => {
  3747. if (!self.gsTree) { return; }
  3748. const nodes = [];
  3749. for (const node of self.gsTree.datas) {
  3750. if (node.check) {
  3751. nodes.push(node.id);
  3752. }
  3753. }
  3754. const data = {
  3755. im_gather: $('#im-gather-check')[0].checked,
  3756. im_gather_node: nodes.join(','),
  3757. };
  3758. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3759. stage.im_gather = data.im_gather;
  3760. stage.im_gather_node = data.im_gather_node;
  3761. $('#choose2').modal('hide');
  3762. });
  3763. });
  3764. }
  3765. _initLocateRela() {
  3766. const self = this;
  3767. $('#im-locate2bills').click(function () {
  3768. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3769. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3770. if (select && select.source) {
  3771. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3772. stagePosSpreadObj.loadCurPosData();
  3773. if (select.source[curIndex-1].pos_id) {
  3774. SpreadJsObj.locateDataBy(spSpread.getActiveSheet(), function(data){ return data.id === select.source[curIndex-1].pos_id});
  3775. }
  3776. }
  3777. });
  3778. $('#im-locate-pre').click(function () {
  3779. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3780. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3781. if (select && select.source) {
  3782. const targetIndex = Math.max(curIndex-1, 1);
  3783. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3784. stagePosSpreadObj.loadCurPosData();
  3785. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3786. }
  3787. });
  3788. $('#im-locate-next').click(function () {
  3789. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3790. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3791. if (select && select.source) {
  3792. const targetIndex = Math.min(curIndex+1, select.source.length);
  3793. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3794. stagePosSpreadObj.loadCurPosData();
  3795. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3796. }
  3797. });
  3798. }
  3799. _initModifyDetail() {
  3800. const self = this;
  3801. // 重置
  3802. $('#reset-detail-ok').click(function () {
  3803. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3804. if (!data.uuid) return;
  3805. const updateData = {
  3806. lid: data.lid, pid: data.pid,
  3807. uuid: data.uuid,
  3808. custom_define: [],
  3809. };
  3810. for (const f of data.custom_define) {
  3811. if (stageIm.resetFields.indexOf(f) >= 0) {
  3812. updateData[f] = null;
  3813. } else {
  3814. updateData.custom_define.push(f);
  3815. }
  3816. }
  3817. updateData.custom_define = updateData.custom_define.join(',');
  3818. $('#reset-detail-modal').modal('hide');
  3819. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3820. stageIm.loadUpdateDetailData(result);
  3821. self.reLoadDetailData();
  3822. });
  3823. });
  3824. // 编辑
  3825. $('#edit-detail').click(function () {
  3826. $(this).hide();
  3827. $('#save-detail').show();
  3828. $('#cancel-detail').show();
  3829. $('#detail-show').hide();
  3830. $('#detail-edit').show();
  3831. self.updateImageData = null;
  3832. });
  3833. // 保存
  3834. $('#save-detail').click(() => {
  3835. function check(field, obj, org, update) {
  3836. const newValue = obj.val();
  3837. if (!org[field]) {
  3838. if (newValue !== '') {
  3839. update[field] = newValue;
  3840. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3841. return true;
  3842. }
  3843. } else if (newValue !== org[field]){
  3844. update[field] = newValue;
  3845. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3846. return true;
  3847. }
  3848. return false;
  3849. }
  3850. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3851. const updateData = {lid: data.lid, pid: data.pid};
  3852. if (data.uuid) {
  3853. updateData.uuid = data.uuid;
  3854. updateData.custom_define = data.custom_define;
  3855. } else {
  3856. updateData.code = data.code;
  3857. updateData.name = data.name;
  3858. updateData.unit = data.unit;
  3859. updateData.unit_price = data.unit_price;
  3860. updateData.pid = data.pid;
  3861. updateData.pos_name = data.pos_name;
  3862. updateData.im_type = data.im_type;
  3863. updateData.custom_define = [];
  3864. }
  3865. let infoUpdate = false;
  3866. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3867. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3868. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3869. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3870. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3871. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3872. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3873. updateData.custom_define = updateData.custom_define.join(',');
  3874. if (infoUpdate) {
  3875. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3876. stageIm.loadUpdateDetailData(result);
  3877. self.reLoadDetailData();
  3878. if (!self.updateImageData) return;
  3879. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3880. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3881. stageIm.loadUpdateDetailData(result);
  3882. self.reLoadDetailData();
  3883. });
  3884. });
  3885. } else if (self.updateImageData) {
  3886. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3887. stageIm.loadUpdateDetailData(result);
  3888. self.reLoadDetailData();
  3889. });
  3890. } else {
  3891. self.reLoadDetailData();
  3892. }
  3893. });
  3894. // 取消
  3895. $('#cancel-detail').click(() => {
  3896. self.reLoadDetailData();
  3897. });
  3898. }
  3899. _initImageRela() {
  3900. const self = this;
  3901. $('#edit-detail').click(function () {
  3902. loadImageItem();
  3903. });
  3904. function setdraggrable(){
  3905. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3906. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3907. stop: function( event, ui ) {
  3908. }
  3909. });
  3910. }
  3911. function upload(formData) {
  3912. if (formData.length < 1) {
  3913. return;
  3914. }
  3915. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3916. const html = [];
  3917. html.push('<div class="img-item">');
  3918. html.push('<div class="img-bar">');
  3919. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3920. html.push('</div>');
  3921. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3922. html.push('</div>');
  3923. $('.img-view').append(html.join(''));
  3924. $('.img-bar').click(removeImageItem);
  3925. setdraggrable();
  3926. $('#upload-img-file').val('');
  3927. });
  3928. }
  3929. function dragFile(e) {
  3930. var file = null,
  3931. data = e.dataTransfer.types;
  3932. for (var i = 0; i < data.length; i += 1) {
  3933. if (data[i] === 'Files') {
  3934. file = e.dataTransfer.files; //获取文件
  3935. break;
  3936. }
  3937. }
  3938. if (file && file[0].type.indexOf('image') !== -1) {
  3939. var formData = new FormData();
  3940. formData.append('file', file[0]); //上传单个文件的添加方式
  3941. upload(formData); //upload 异步上传
  3942. }
  3943. }
  3944. // 移动图片
  3945. const moveImageItem = function (ev) {
  3946. const item = this;
  3947. const view = $('.img-view')[0];
  3948. let oEvent = ev;
  3949. // 浏览器有一些图片的默认事件,这里要阻止
  3950. oEvent.preventDefault();
  3951. let disX = oEvent.clientX - item.offsetLeft;
  3952. let disY = oEvent.clientY - item.offsetTop;
  3953. view.onmousemove = function (ev) {
  3954. oEvent = ev;
  3955. oEvent.preventDefault();
  3956. let x = oEvent.clientX -disX;
  3957. let y = oEvent.clientY -disY;
  3958. // 图形移动的边界判断
  3959. x = x <= 0 ? 0 : x;
  3960. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3961. y = y <= 0 ? 0 : y;
  3962. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3963. item.style.left = x + 'px';
  3964. item.style.top = y + 'px';
  3965. };
  3966. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3967. view.onmouseleave = function () {
  3968. view.onmousemove = null;
  3969. view.onmouseup = null;
  3970. };
  3971. // 鼠标弹起后停止移动
  3972. view.onmouseup=function() {
  3973. view.onmousemove = null;
  3974. view.onmouseup = null;
  3975. };
  3976. };
  3977. const removeImageItem = function () {
  3978. $(this).parent().remove();
  3979. };
  3980. // 加载草图组成
  3981. const loadImageItem = function () {
  3982. self.updateImageData = null;
  3983. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3984. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3985. const html = [];
  3986. for (const item of items) {
  3987. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3988. html.push('<div class="img-item" style="' + itemStyle + '">');
  3989. html.push('<div class="img-bar">');
  3990. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3991. html.push('</div>');
  3992. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3993. html.push('</div>');
  3994. }
  3995. $('.img-view').html(html.join(''));
  3996. $('.img-bar').click(removeImageItem);
  3997. setdraggrable();
  3998. };
  3999. // 上传图片
  4000. $('#upload-img').click(function () {
  4001. $('#upload-img-file').trigger('click');
  4002. });
  4003. // 拖拽上传
  4004. //拖拽上传文件
  4005. const dragbox = document.querySelector('#upload-img');
  4006. dragbox.addEventListener('dragover', function(e) {
  4007. e.preventDefault(); // 必须阻止默认事件
  4008. }, false);
  4009. dragbox.addEventListener('drop', function(e) {
  4010. e.preventDefault(); // 阻止默认事件
  4011. dragFile(e);
  4012. }, false);
  4013. //拖拽上传文件
  4014. const dragbox2 = document.querySelector('.img-view');
  4015. dragbox2.addEventListener('dragover', function(e) {
  4016. e.preventDefault(); // 必须阻止默认事件
  4017. }, false);
  4018. dragbox2.addEventListener('drop', function(e) {
  4019. e.preventDefault(); // 阻止默认事件
  4020. dragFile(e);
  4021. }, false);
  4022. // 粘贴上传
  4023. $(".img-view").on('paste', function(ev) {
  4024. let file = null;
  4025. const data = (event.clipboardData || window.clipboardData).items;
  4026. for (let i = 0; i < data.length; i += 1) {
  4027. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  4028. file = data[i].getAsFile(); //读取图片文件
  4029. break;
  4030. }
  4031. }
  4032. if (file) {
  4033. const formData = new FormData();
  4034. formData.append('file', file); //上传单个文件的添加方式
  4035. upload(formData); //异步上传文件
  4036. }
  4037. });
  4038. $('#upload-img-file').change(function () {
  4039. const file = this.files[0];
  4040. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  4041. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  4042. if (!imgStr.test(ext)) {
  4043. toastr.error('请上传正确的图片格式文件');
  4044. return
  4045. }
  4046. if ($(this).val()) {
  4047. const formData = new FormData();
  4048. formData.append('file', this.files[0]);
  4049. upload(formData);
  4050. }
  4051. });
  4052. // 保存草图修改结果
  4053. $('#edit-img-ok').click(function () {
  4054. // 记录上传的图片的信息
  4055. const items = $('.img-item');
  4056. const img_remark = $('#text-edit').val();
  4057. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  4058. // 生成上传数据
  4059. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  4060. if (data.uuid) {
  4061. updateData.uuid = data.uuid;
  4062. } else {
  4063. updateData.code = data.code;
  4064. updateData.name = data.name;
  4065. updateData.unit = data.unit;
  4066. updateData.unit_price = data.unit_price;
  4067. updateData.pid = data.pid;
  4068. updateData.pos_name = data.pos_name;
  4069. updateData.im_type = data.im_type;
  4070. }
  4071. if (items.length === 1) {
  4072. const itemInfo = [];
  4073. for (const item of items) {
  4074. const itemData = {
  4075. src: $('img', item).attr('src'),
  4076. left: item.style.left,
  4077. top: item.style.top,
  4078. width: item.style.width,
  4079. height: item.style.height,
  4080. };
  4081. itemInfo.push(itemData);
  4082. }
  4083. // 获取合并好的图片数据
  4084. const canvas = document.createElement('canvas');
  4085. const view = $('.img-view')[0];
  4086. const b = items[0];
  4087. const pos = $(b).position();
  4088. const img = $('img', b)[0];
  4089. canvas.height = Math.max(view.clientHeight, Math.ceil(pos.top + img.naturalHeight));
  4090. canvas.width = Math.max(view.clientWidth, Math.ceil(pos.left + img.naturalWidth));
  4091. const ctx = canvas.getContext('2d');
  4092. ctx.fillStyle = '#ffffff';
  4093. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4094. ctx.drawImage(img, pos.left, pos.top);
  4095. updateData.img = canvas.toDataURL('image/png');
  4096. updateData.imgInfo = itemInfo;
  4097. self.updateImageData = updateData;
  4098. $('#calc-img').attr('src', updateData.img);
  4099. $('#calc-remark').html(img_remark);
  4100. $('#view-calc-img').attr('src', updateData.img);
  4101. $('#show-calc-img').attr('src', updateData.img);
  4102. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4103. $('#view-calc-remark').text(img_remark);
  4104. $('#edit-img').modal('hide');
  4105. } else if (items.length > 0) {
  4106. const itemInfo = [];
  4107. for (const item of items) {
  4108. const itemData = {
  4109. src: $('img', item).attr('src'),
  4110. left: item.style.left,
  4111. top: item.style.top,
  4112. width: item.style.width,
  4113. height: item.style.height,
  4114. };
  4115. itemInfo.push(itemData);
  4116. }
  4117. // 获取合并好的图片数据
  4118. const canvas = document.createElement('canvas');
  4119. const view = $('.img-view')[0];
  4120. canvas.height = view.clientHeight;
  4121. canvas.width = view.clientWidth;
  4122. const ctx = canvas.getContext('2d');
  4123. ctx.fillStyle = '#ffffff';
  4124. ctx.fillRect(0, 0, canvas.width, canvas.height);
  4125. for (const b of $('.img-item')) {
  4126. const pos = $(b).position();
  4127. const img = $('img', b)[0];
  4128. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  4129. }
  4130. updateData.img = canvas.toDataURL('image/png');
  4131. updateData.imgInfo = itemInfo;
  4132. self.updateImageData = updateData;
  4133. $('#calc-img').attr('src', updateData.img);
  4134. $('#calc-remark').html(img_remark);
  4135. $('#view-calc-img').attr('src', updateData.img);
  4136. $('#show-calc-img').attr('src', updateData.img);
  4137. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  4138. $('#view-calc-remark').text(img_remark);
  4139. $('#edit-img').modal('hide');
  4140. // });
  4141. } else if (data.calc_img) {
  4142. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  4143. $('#show-calc-img').attr('src', '');
  4144. $('#show-calc-remark').html('');
  4145. $('#calc-img').attr('src', '');
  4146. $('#calc-remark').html(img_remark);
  4147. $('#view-calc-img').attr('src', '');
  4148. $('#view-calc-remark').val(img_remark);
  4149. $('#text-edit').val(img_remark);
  4150. $('#edit-img').modal('hide');
  4151. } else {
  4152. self.updateImageData = updateData;
  4153. $('#show-calc-img').attr('src', '');
  4154. $('#show-calc-remark').html('');
  4155. $('#calc-img').attr('src', '');
  4156. $('#calc-remark').html(img_remark);
  4157. $('#view-calc-img').attr('src', '');
  4158. $('#view-calc-remark').val(img_remark);
  4159. $('#text-edit').val(img_remark);
  4160. $('#edit-img').modal('hide');
  4161. }
  4162. });
  4163. }
  4164. reBuildImData() {
  4165. const imData = stageIm.buildImData();
  4166. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4167. this.reLoadDetailData();
  4168. this.loadLocateInfo();
  4169. }
  4170. loadStageLedgerUpdateData(data, nodes) {
  4171. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  4172. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4173. this.reLoadDetailData();
  4174. }
  4175. loadStagePosUpdateData(data, nodes) {
  4176. const imData = stageIm.loadUpdatePosData(data, nodes);
  4177. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4178. this.reLoadDetailData();
  4179. }
  4180. loadStageChangeUpdateData(data, nodes) {
  4181. const imData = stageIm.loadUpdateChangeData(data, nodes);
  4182. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  4183. this.reLoadDetailData();
  4184. }
  4185. loadLocateInfo() {
  4186. const select = SpreadJsObj.getSelectObject(this.sheet);
  4187. if (select && select.source.length > 1) {
  4188. $('#im-locate2bills').next().show();
  4189. } else {
  4190. $('#im-locate2bills').next().hide();
  4191. }
  4192. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  4193. }
  4194. reLoadDetailData() {
  4195. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  4196. $('#reset-detail').hide();
  4197. if (data) {
  4198. for (const f of data.custom_define) {
  4199. if (stageIm.resetFields.indexOf(f) >= 0) {
  4200. $('#reset-detail').show();
  4201. break;
  4202. }
  4203. }
  4204. $('#edit-detail').show();
  4205. $('#modify-img').show();
  4206. } else {
  4207. $('#edit-detail').hide();
  4208. $('#modify-img').hide();
  4209. }
  4210. $('#save-detail').hide();
  4211. $('#cancel-detail').hide();
  4212. $('#detail-show').show();
  4213. $('#detail-edit').hide();
  4214. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  4215. $('#show-contract-jl').text(contractJl);
  4216. $('#contract-jl').val(contractJl);
  4217. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  4218. $('#show-qc-jl').text(qcJl);
  4219. $('#qc-jl').val(qcJl);
  4220. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  4221. $('#show-qc-minus-jl').text(qcMinusJl);
  4222. $('#qc-minus-jl').val(qcMinusJl);
  4223. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  4224. $('#show-bgl-code').text(bglCode);
  4225. $('#bgl-code').val(bglCode);
  4226. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  4227. $('#show-bgl-drawing-code').text(bglDrawingCode);
  4228. $('#bgl-drawing-code').val(bglDrawingCode);
  4229. const bwName = data && data.bw ? data.bw : '';
  4230. $('#show-bw-name').text(bwName);
  4231. $('#bw-name').val(bwName);
  4232. const position = data && data.position ? data.position : '';
  4233. $('#show-position').text(position);
  4234. $('#position').val(position);
  4235. const peg = data && data.peg ? data.peg : '';
  4236. $('#show-peg').text(peg);
  4237. $('#peg').val(peg);
  4238. const xmName = data && data.xm ? data.xm: '';
  4239. $('#show-xm-name').text(xmName);
  4240. $('#xm-name').val(xmName);
  4241. const jldy = data && data.jldy ? data.jldy: '';
  4242. $('#show-jldy').text(jldy);
  4243. $('#jldy').val(jldy);
  4244. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  4245. $('#show-drawing-code').text(drawingCode);
  4246. $('#drawing-code').val(drawingCode);
  4247. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  4248. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  4249. $('#calc-memo').val(calcMemo);
  4250. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  4251. $('#show-calc-img').attr('src', calcImgSrc);
  4252. $('#calc-img').attr('src', calcImgSrc);
  4253. $('#view-calc-img').attr('src', calcImgSrc);
  4254. const calcImgRemark = data && data.calc_img_remark || '';
  4255. $('#view-calc-remark').val(calcImgRemark);
  4256. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  4257. $('#calc-remark').html(calcImgRemark);
  4258. $("#view-calc-remark").attr('readonly', true);
  4259. // 处理 编辑 -> 添加草图中textarea多余的空格
  4260. $('#text-edit').val(calcImgRemark)
  4261. }
  4262. }
  4263. class CheckedChange {
  4264. constructor (setting) {
  4265. const self = this;
  4266. this.changeSpreadSetting = {
  4267. cols: [
  4268. {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}` : ''; }},
  4269. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  4270. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4271. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  4272. ],
  4273. emptyRows: 0,
  4274. headRows: 1,
  4275. headRowHeight: [32],
  4276. headColWidth: [30],
  4277. defaultRowHeight: 21,
  4278. headerFont: '12px 微软雅黑',
  4279. font: '12px 微软雅黑',
  4280. readOnly: true,
  4281. getColor: function (sheet, data, row, col, defaultColor) {
  4282. if (data && data.is_import) {
  4283. return '#eee';
  4284. } else {
  4285. return defaultColor;
  4286. }
  4287. }
  4288. };
  4289. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  4290. this.changeSheet = this.changeSpread.getActiveSheet();
  4291. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  4292. const getTipText = function (data) {
  4293. if (!data) return '';
  4294. const tips = [];
  4295. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  4296. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  4297. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  4298. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  4299. return tips.join('-');
  4300. };
  4301. this.changeBillsSpreadSetting = {
  4302. cols: [
  4303. {title: '计价', colSpan: '1', rowSpan: '1', field: 'is_valuation', hAlign: 1, width: 30, cellType: 'checkbox'},
  4304. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  4305. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
  4306. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4307. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  4308. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  4309. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  4310. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  4311. ],
  4312. emptyRows: 0,
  4313. headRows: 1,
  4314. headRowHeight: [32],
  4315. defaultRowHeight: 21,
  4316. headerFont: '12px 微软雅黑',
  4317. font: '12px 微软雅黑',
  4318. readOnly: true
  4319. };
  4320. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  4321. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  4322. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  4323. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  4324. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4325. if (change) self.refreshChangeDetailData(change);
  4326. });
  4327. this.changes = null;
  4328. this.reloadChangeData();
  4329. setting.reloadObj.click(function() {
  4330. self.reloadChangeData();
  4331. });
  4332. $.contextMenu({
  4333. selector: '#' + setting.changeBillsObj.attr('id'),
  4334. build: function ($trigger, e) {
  4335. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  4336. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4337. },
  4338. items: {
  4339. 'locateZjjl': {
  4340. name: '定位至台账',
  4341. icon: 'fa-sign-in',
  4342. callback: function (key, opt) {
  4343. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4344. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4345. if (change.is_import) {
  4346. if (changeBills.pos && changeBills.pos.length > 0) {
  4347. const node = stageTree.getItems(changeBills.pos[0].ledger_id);
  4348. if (!node || node.filter) return;
  4349. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  4350. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4351. stagePosSpreadObj.loadCurPosData();
  4352. }
  4353. } else if (changeBills.gcl_id) {
  4354. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4355. if (!node || node.filter) return;
  4356. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  4357. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4358. stagePosSpreadObj.loadCurPosData();
  4359. const posData = spSpread.getActiveSheet().zh_data;
  4360. if (!posData || posData.length === 0) return;
  4361. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4362. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  4363. } else {
  4364. const cb = {
  4365. b_code: changeBills.code || '',
  4366. name: changeBills.name || '',
  4367. unit: changeBills.unit || '',
  4368. unit_price: changeBills.unit_price || 0,
  4369. };
  4370. for (const node of stageTree.nodes) {
  4371. if (node.children && node.children.length > 0) continue;
  4372. if (node.filter) continue;
  4373. const b = {
  4374. b_code: node.b_code || '',
  4375. name: node.name || '',
  4376. unit: node.unit || '',
  4377. unit_price: node.unit_price || 0,
  4378. };
  4379. if (_.isMatch(cb, b)) {
  4380. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  4381. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4382. stagePosSpreadObj.loadCurPosData();
  4383. return;
  4384. }
  4385. }
  4386. }
  4387. },
  4388. disabled: function (key, opt) {
  4389. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4390. return !changeBills;
  4391. }
  4392. },
  4393. 'autoUse': {
  4394. name: '调用',
  4395. icon: 'fa-play',
  4396. callback: function (key, opt) {
  4397. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4398. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4399. const billsPos = self.findBillsPos(curChange, changeBills);
  4400. if (!billsPos) {
  4401. toastr.warning('无可调用的清单或计量单元');
  4402. return;
  4403. }
  4404. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
  4405. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4406. if (result.pos) {
  4407. stagePos.loadCurStageData(result.pos.curStageData);
  4408. }
  4409. const nodes = stageTree.loadPostStageData(result.bills);
  4410. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4411. stagePosSpreadObj.loadCurPosData();
  4412. if (detail) {
  4413. detail.loadStageChangeUpdateData(result, nodes);
  4414. } else {
  4415. stageIm.loadUpdateChangeData(result, nodes)
  4416. }
  4417. });
  4418. },
  4419. disabled: function (key, opt) {
  4420. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4421. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4422. return !changeBills || curChange.is_import;
  4423. },
  4424. visible: function (key, opt) {
  4425. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4426. }
  4427. },
  4428. }
  4429. });
  4430. $.contextMenu({
  4431. selector: '#' + setting.changeObj.attr('id'),
  4432. build: function ($trigger, e) {
  4433. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  4434. const change = target.cellTypeHintInfo ? self.changes[target.cellTypeHitInfo.row] : null;
  4435. if (change) self.refreshChangeDetailData(change);
  4436. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4437. },
  4438. items: {
  4439. 'autoUseCur': {
  4440. name: '自动调用',
  4441. icon: 'fa-play',
  4442. callback: function (key, opt) {
  4443. checkAgainHint(function(){
  4444. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4445. const changeBills = self.changeBillsSheet.zh_data;
  4446. const data = { bills: [], autoType: 'bills' };
  4447. for (const cb of changeBills) {
  4448. const billsPos = self.findBillsPos(curChange, cb);
  4449. if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
  4450. }
  4451. if (data.bills.length === 0) {
  4452. toastr.warning('无可调用的清单或计量单元');
  4453. return;
  4454. }
  4455. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4456. if (result.pos) {
  4457. stagePos.loadCurStageData(result.pos.curStageData);
  4458. }
  4459. const nodes = stageTree.loadPostStageData(result.bills);
  4460. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4461. stagePosSpreadObj.loadCurPosData();
  4462. if (detail) {
  4463. detail.loadStageChangeUpdateData(result, nodes);
  4464. } else {
  4465. stageIm.loadUpdateChangeData(result, nodes)
  4466. }
  4467. });
  4468. }, ['自动调用后,已调用变更令无法批量取消,请谨慎操作。', '确定自动调用变更令?']);
  4469. },
  4470. disabled: function (key, opt) {
  4471. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4472. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4473. return !curChange || !changeBills || curChange.is_import;
  4474. },
  4475. visible: function (key, opt) {
  4476. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4477. }
  4478. },
  4479. 'autoUseAll': {
  4480. name: '自动调用(全部变更令)',
  4481. icon: 'fa-play',
  4482. callback: function (key, opt) {
  4483. checkAgainHint(function(){
  4484. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  4485. window.location.reload();
  4486. });
  4487. }, ['自动调用后,已调用变更令无法批量取消,请谨慎操作。', '确定自动调用变更令?']);
  4488. },
  4489. disabled: function (key, opt) {
  4490. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4491. return !curChange || curChange.is_import;
  4492. },
  4493. visible: function (key, opt) {
  4494. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4495. }
  4496. }
  4497. }
  4498. });
  4499. }
  4500. refreshChangeDetailData(data) {
  4501. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4502. if (change.cid === this.curChangeId) return;
  4503. this.curChangeId = change.cid;
  4504. const self = this;
  4505. if (change.detail) {
  4506. self.loadChangeDetailData();
  4507. } else {
  4508. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  4509. change.detail = result;
  4510. self.analyzeChange(change);
  4511. self.loadChangeDetailData();
  4512. });
  4513. }
  4514. }
  4515. loadChangeDetailData(data) {
  4516. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4517. if (change) {
  4518. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  4519. } else {
  4520. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  4521. }
  4522. }
  4523. refresh() {
  4524. this.changeSpread.refresh();
  4525. this.changeBillsSpread.refresh();
  4526. }
  4527. reloadChangeData() {
  4528. const self = this;
  4529. postData(window.location.pathname + '/change/data', null, function (result) {
  4530. self.changes = [];
  4531. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  4532. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  4533. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  4534. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  4535. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  4536. self.changeSheet.setSelection(0, 0, 1, 1);
  4537. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  4538. self.loadChangeDetailData();
  4539. });
  4540. }
  4541. _analyzeCommon(change) {
  4542. for (const b of change.bills) {
  4543. const eub = change.detail.endUsedBills.find(function (x) {
  4544. return x.cbid === b.id;
  4545. });
  4546. if (eub) b.used_qty = eub.qty;
  4547. b.qty = _.toNumber(b.samount);
  4548. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  4549. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4550. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  4551. b.cur_qty = 0;
  4552. for (const p of b.pos) {
  4553. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  4554. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  4555. }
  4556. }
  4557. }
  4558. _analyzeImport(change) {
  4559. for (const b of change.bills) {
  4560. const eub = change.detail.endUsedBills.find(function (x) {
  4561. return x.rela_cbid === b.id;
  4562. });
  4563. if (eub) b.used_qty = eub.rela_qty;
  4564. b.qty = _.toNumber(b.samount);
  4565. delete b.unit_price;
  4566. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4567. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  4568. b.cur_qty = 0;
  4569. for (const p of b.pos) {
  4570. p.qty = p.rela_qty;
  4571. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  4572. p.ledger_id = node.ledger_id;
  4573. p.f_qty = node.quantity;
  4574. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  4575. }
  4576. }
  4577. }
  4578. analyzeChange(change) {
  4579. change.bills = change.detail.bills;
  4580. if (change.is_import) {
  4581. this._analyzeImport(change);
  4582. } else {
  4583. this._analyzeCommon(change);
  4584. }
  4585. }
  4586. findBillsPos(change, changeBills) {
  4587. if (change.is_import) {
  4588. return null;
  4589. } else if (changeBills.gcl_id) {
  4590. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4591. if (node.filter) return null;
  4592. if (node.settle_status === settleStatus.finish) return null;
  4593. const posData = stagePos.getLedgerPos(node.id) || [];
  4594. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4595. if (changePos && changePos.settle_status) return null;
  4596. let defaultPos;
  4597. if (posData.length > 0) {
  4598. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4599. if (!defaultPos) return null;
  4600. } else {
  4601. defaultPos = { id: '-1' };
  4602. }
  4603. return { lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
  4604. } else {
  4605. const cb = {
  4606. b_code: changeBills.code || '',
  4607. name: changeBills.name || '',
  4608. unit: changeBills.unit || '',
  4609. unit_price: changeBills.unit_price || 0,
  4610. };
  4611. for (const node of stageTree.nodes) {
  4612. if (node.children && node.children.length > 0) continue;
  4613. if (node.filter) continue;
  4614. if (node.settle_status === settleStatus.finish) continue;
  4615. const b = {
  4616. b_code: node.b_code || '',
  4617. name: node.name || '',
  4618. unit: node.unit || '',
  4619. unit_price: node.unit_price || 0,
  4620. };
  4621. if (_.isMatch(cb, b)) {
  4622. posData = stagePos.getLedgerPos(node.id) || [];
  4623. let defaultPos;
  4624. if (posData.length > 0) {
  4625. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4626. if (!defaultPos) return null;
  4627. } else {
  4628. defaultPos = { id: '-1' };
  4629. }
  4630. return { lid: node.id, pid: defaultPos.id };
  4631. }
  4632. }
  4633. return null;
  4634. }
  4635. }
  4636. }
  4637. // 展开收起附件
  4638. $('a', '.right-nav').bind('click', function () {
  4639. //const main = $('#main-view'), tool = $('#tools-view');
  4640. const tab = $(this), tabPanel = $(tab.attr('content'));
  4641. if (!tab.hasClass('active')) {
  4642. $('a', '.side-menu').removeClass('active');
  4643. $('.tab-content .tab-select-show').removeClass('active');
  4644. tab.addClass('active');
  4645. tabPanel.addClass('active');
  4646. showSideTools(tab.hasClass('active'));
  4647. if (tab.attr('content') === '#search' && !searchLedger) {
  4648. searchLedger = $.ledgerSearch({
  4649. selector: '#search',
  4650. ledger: { billsTree: stageTree, pos: stagePos },
  4651. searchOver: true,
  4652. searchEmpty: true,
  4653. resultSpreadSetting: {
  4654. cols: [
  4655. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4656. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4657. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4658. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4659. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4660. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4661. {title: '完成率(%)', field: completePerField, hAlign: 2, width: 70},
  4662. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4663. ],
  4664. emptyRows: 0,
  4665. headRows: 1,
  4666. headRowHeight: [32],
  4667. headColWidth: [30],
  4668. defaultRowHeight: 21,
  4669. headerFont: '12px 微软雅黑',
  4670. font: '12px 微软雅黑',
  4671. selectedBackColor: '#fffacd',
  4672. readOnly: true,
  4673. },
  4674. locate: function(cur) {
  4675. if (!cur.lid) return;
  4676. SpreadJsObj.locateTreeNode(slSheet, cur.lid, true);
  4677. stageTreeSpreadObj.loadRelaData();
  4678. if (cur.pid && cur.pid !== -1) {
  4679. const pIndex = spSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4680. SpreadJsObj.locateRow(spSheet, pIndex);
  4681. }
  4682. },
  4683. customSearch: [
  4684. {
  4685. key: 'less', title: '漏计', valid: true,
  4686. check: function (node) {
  4687. if (node.quantity) {
  4688. return ZhCalc.sub(ZhCalc.sum([node.quantity, node.end_qc_qty, node.end_qc_minus_qty]), node.end_gather_qty) > 0;
  4689. } else if (node.total_price) {
  4690. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  4691. }
  4692. }
  4693. }, {
  4694. key: 'over', title: '超计', valid: true,
  4695. check: function (node) {
  4696. return checkUtils.billsOver(node, stagePos, tenderInfo.checkOverInfo);
  4697. }
  4698. }, {
  4699. key: 'empty', title: '漏计', valid: false,
  4700. check: function (node) {
  4701. if (node.quantity) {
  4702. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4703. } else if (node.total_price) {
  4704. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4705. }
  4706. }
  4707. }, {
  4708. key: 'estimate', title: '预计变更', valid: true,
  4709. check: function (node) {
  4710. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4711. if (posRange.length > 0) {
  4712. for (const p of posRange) {
  4713. if (!checkZero(p.estimate_qty)) return true;
  4714. }
  4715. return false;
  4716. } else {
  4717. return false;
  4718. }
  4719. }
  4720. }
  4721. ],
  4722. });
  4723. searchLedger.spread.refresh();
  4724. }
  4725. if (tab.attr('content') === '#fujian') {
  4726. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4727. node && getNodeList(node.id);
  4728. }
  4729. if (tab.attr('content') === '#zhongjian') {
  4730. if (!detail) {
  4731. detail = new Detail($('#detail-spread'));
  4732. detail.spread.refresh();
  4733. $('#zhongjian .sjs-bottom').height('400px');
  4734. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4735. } else {
  4736. detail.spread.refresh();
  4737. }
  4738. }
  4739. if (tab.attr('content') === '#checked-change') {
  4740. if (!checkedChanges) {
  4741. checkedChanges = new CheckedChange({
  4742. changeObj: $('#cc-spread'),
  4743. changeBillsObj: $('#ccb-spread'),
  4744. reloadObj: $('#refresh-cc'),
  4745. });
  4746. checkedChanges.refresh();
  4747. } else {
  4748. $('#ccb-spread').height('400px');
  4749. checkedChanges.refresh();
  4750. }
  4751. }
  4752. if (tab.attr('content') === '#error-list') {
  4753. errorList.spread.refresh();
  4754. }
  4755. if (tab.attr('content') === '#check-list') {
  4756. checkList.spread.refresh();
  4757. }
  4758. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4759. } else {
  4760. tab.removeClass('active');
  4761. tabPanel.removeClass('active');
  4762. showSideTools(tab.hasClass('active'));
  4763. }
  4764. autoFlashHeight();
  4765. slSpread.refresh();
  4766. spSpread.refresh();
  4767. });
  4768. // 切换附件里节点和所有附件
  4769. $('#fujian .nav-link').on('click', function () {
  4770. const tabPanel = $(this).attr('fujian-content');
  4771. if (tabPanel !== 'syfujian') {
  4772. $('#showPage').hide();
  4773. $('#bach-download').prop('type', 'curr');
  4774. } else {
  4775. $('#showPage').show();
  4776. $('#bach-download').prop('type', 'all')
  4777. }
  4778. $('#showAttachment').hide();
  4779. });
  4780. // 上传附件
  4781. $('#upload-file-btn').click(function () {
  4782. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4783. if (!node) return
  4784. const files = $('#upload-file')[0].files;
  4785. const formData = new FormData();
  4786. formData.append('lid', node.id);
  4787. for (const file of files) {
  4788. if (file === undefined) {
  4789. toastr.error('未选择上传文件!');
  4790. return false;
  4791. }
  4792. const filesize = file.size;
  4793. if (filesize > 50 * 1024 * 1024) {
  4794. toastr.error('存在上传文件大小过大!');
  4795. return false;
  4796. }
  4797. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4798. if (whiteList.indexOf(fileext) === -1) {
  4799. toastr.error('只能上传指定格式的附件!');
  4800. return false;
  4801. }
  4802. formData.append('size', filesize);
  4803. formData.append('file[]', file);
  4804. }
  4805. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4806. $('#upload').modal('hide');
  4807. // 插入到attData中
  4808. attData = data.concat(attData);
  4809. // 重新生成List
  4810. getAllList();
  4811. getNodeList(node.id);
  4812. }, function () {
  4813. toastr.error('附件上传失败');
  4814. });
  4815. $('#upload-file').val('');
  4816. });
  4817. // 获取附件信息
  4818. $('.list-table').on('click', '.att-file-name', function () {
  4819. const fid = $(this).attr('file-id');
  4820. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4821. return;
  4822. }
  4823. const att = attData.find(function (item) {
  4824. return item.id === parseInt(fid);
  4825. });
  4826. $('#edit-att').hide();
  4827. $('#show-att').show();
  4828. if (att !== undefined) {
  4829. // 进来先把编辑功能隐藏
  4830. $('#btn-att a').eq(3).hide()
  4831. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4832. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4833. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4834. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4835. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4836. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4837. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4838. $('#show-att tr').eq(3).children('td').text(att.remark);
  4839. // 附件uid等于当前用户id, 附件上传本人
  4840. if (parseInt(cur_uid) === att.uid) {
  4841. $('#btn-att').show();
  4842. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4843. if (showDel) $('#btn-att a').eq(3).show();
  4844. // $('#btn-att a').eq(3).show();
  4845. $('#btn-att a').eq(2).hide();
  4846. $('#btn-att a').eq(4).hide();
  4847. $('#btn-att a').eq(5).hide();
  4848. } else {
  4849. $('#btn-att').hide();
  4850. $('#btn-att a').eq(3).hide();
  4851. $('#btn-att a').eq(2).hide();
  4852. $('#btn-att a').eq(4).hide();
  4853. $('#btn-att a').eq(5).hide();
  4854. }
  4855. $('#showAttachment').attr('file-id', fid);
  4856. $('#showAttachment').show();
  4857. } else {
  4858. $('#showAttachment').hide();
  4859. $('#showAttachment').attr('file-id', '');
  4860. toastr.error('附件信息获取失败');
  4861. }
  4862. });
  4863. // $('body').on('click', '.alllist-table a', handleFileList);
  4864. $('body').on('click', '#btn-att a', function () {
  4865. const content = $(this).attr('content');
  4866. const fid = $('#showAttachment').attr('file-id');
  4867. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4868. if (content === 'edit') {
  4869. $('#btn-att a').eq(3).hide();
  4870. $('#btn-att a').eq(2).show();
  4871. $('#btn-att a').eq(4).show();
  4872. $('#btn-att a').eq(5).show();
  4873. $('#show-att').hide();
  4874. $('#edit-att').show();
  4875. const att = attData.find(function (item) {
  4876. return item.id === parseInt(fid);
  4877. });
  4878. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4879. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4880. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4881. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4882. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4883. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4884. } else if (content === 'cancel') {
  4885. $('#show-att').show();
  4886. $('#edit-att').hide();
  4887. $('#btn-att a').eq(3).show();
  4888. $('#btn-att a').eq(2).hide();
  4889. $('#btn-att a').eq(4).hide();
  4890. $('#btn-att a').eq(5).hide();
  4891. } else if (content === 'save') {
  4892. const formData = new FormData();
  4893. formData.append('id', fid);
  4894. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4895. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4896. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4897. const file = $('#change-att-btn')[0];
  4898. if (file.files[0] !== undefined) {
  4899. const filesize = file.files[0].size;
  4900. formData.append('size', filesize);
  4901. formData.append('file', file.files[0]);
  4902. }
  4903. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4904. // 替换到attData中
  4905. const att_index = attData.findIndex(function (item) {
  4906. return item.id === parseInt(fid);
  4907. });
  4908. attData.splice(att_index, 1, data);
  4909. // 重新生成List
  4910. getAllList(parseInt($('#currentPage').text()));
  4911. getNodeList(node.id);
  4912. $('#show-att').show();
  4913. $('#edit-att').hide();
  4914. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4915. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4916. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4917. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4918. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4919. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4920. $('#show-att tr').eq(4).children('td').text(data.remark);
  4921. $('#btn-att a').eq(3).show();
  4922. $('#btn-att a').eq(2).hide();
  4923. $('#btn-att a').eq(4).hide();
  4924. $('#btn-att a').eq(5).hide();
  4925. }, function () {
  4926. toastr.error('附件上传失败');
  4927. });
  4928. $('#change-att-btn').val('');
  4929. } else if (content === 'del') {
  4930. const data = {id: fid};
  4931. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4932. // 删除到attData中
  4933. const att_index = attData.findIndex(function (item) {
  4934. return item.id === parseInt(fid);
  4935. });
  4936. attData.splice(att_index, 1);
  4937. // 重新生成List
  4938. if ($('#alllist-table tr').length === 1) {
  4939. getAllList(parseInt($('#currentPage').text()) - 1);
  4940. } else {
  4941. getAllList(parseInt($('#currentPage').text()));
  4942. }
  4943. getNodeList(node.id);
  4944. $('#showAttachment').hide();
  4945. $('#showAttachment').attr('file-id', '');
  4946. });
  4947. } else if (content === 'view') {
  4948. const data = {id: fid};
  4949. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4950. const { filepath } = result
  4951. $('#load-file').attr('href', filepath);
  4952. $('#load-file')[0].click();
  4953. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4954. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4955. });
  4956. } else if (content === 'location') {
  4957. const att = attData.find(item => item.id === parseInt(fid));
  4958. if (Object.keys(att).length) {
  4959. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4960. stagePosSpreadObj.loadCurPosData();
  4961. }
  4962. }
  4963. });
  4964. // 替换附件
  4965. $('#change-att-btn').on('change', function () {
  4966. const file = $('#change-att-btn')[0].files[0];
  4967. const name = file.name;
  4968. const filename = name.substring(0, name.lastIndexOf("."));
  4969. const fileext = name.substr(name.indexOf("."));
  4970. const filesize = file.size;
  4971. if (filesize > 50 * 1024 * 1024) {
  4972. toastr.error('文件大小过大!');
  4973. $('#change-att-btn').val('');
  4974. return false;
  4975. }
  4976. if (whiteList.indexOf(fileext) === -1) {
  4977. toastr.error('只能上传指定格式的附件!');
  4978. $('#change-att-btn').val('');
  4979. return false;
  4980. }
  4981. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4982. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4983. });
  4984. // 切换页数
  4985. $('.page-select').on('click', function () {
  4986. const totalPageNum = parseInt($('#totalPage').text());
  4987. const lastPageNum = parseInt($('#currentPage').text());
  4988. const status = $(this).attr('content');
  4989. if (status === 'pre' && lastPageNum > 1) {
  4990. getAllList(lastPageNum-1);
  4991. $('#showAttachment').hide();
  4992. $('#syfujian .check-all-file').prop('checked', false)
  4993. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4994. getAllList(lastPageNum+1);
  4995. $('#showAttachment').hide();
  4996. $('#syfujian .check-all-file').prop('checked', false)
  4997. }
  4998. });
  4999. // 批量下载
  5000. $('#bach-download').click(function() {
  5001. const fileIds = [];
  5002. const type = $(this).attr('type');
  5003. let node = ''
  5004. if (type === 'curr') {
  5005. node = '#nodelist-table .check-file:checked'
  5006. } else {
  5007. node = '#alllist-table .check-file:checked'
  5008. }
  5009. $(node).each(function() {
  5010. const fileId = $(this).attr('file-id');
  5011. fileId && fileIds.push(fileId);
  5012. });
  5013. if (fileIds.length) {
  5014. if (fileIds.length > 20) {
  5015. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  5016. }
  5017. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  5018. $(this).attr('disabled', "true")
  5019. const btn = $(this);
  5020. const fileArr = [];
  5021. for (const id of fileIds) {
  5022. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  5023. fileArr.push({
  5024. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  5025. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  5026. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  5027. });
  5028. }
  5029. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  5030. try {
  5031. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  5032. } catch (e) {
  5033. btn.removeAttr('disabled');
  5034. toastr.clear();
  5035. toastr.error('批量下载失败');
  5036. }
  5037. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  5038. // toastr.clear()
  5039. // toastr.success('压缩文件成功')
  5040. // btn.removeAttr('disabled')
  5041. // const href = window.URL.createObjectURL(result)
  5042. // $('#zipDown').attr('href', href);
  5043. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  5044. // $("#zipDown")[0].click();
  5045. // }, () => {
  5046. // btn.removeAttr('disabled')
  5047. // toastr.clear()
  5048. // toastr.error('批量下载失败')
  5049. // });
  5050. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  5051. // $('#zipDown').attr('href', url);
  5052. // $("#zipDown")[0].click();
  5053. }
  5054. });
  5055. // 监听附件check是否选中
  5056. $('.list-table').on('click', '.check-file', function() {
  5057. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  5058. const childs = $(this).parents('.list-table').children().length;
  5059. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  5060. if (checkedList.length === childs) {
  5061. checkBox.prop("checked", true);
  5062. } else {
  5063. checkBox.prop("checked", false);
  5064. }
  5065. });
  5066. $('.check-all-file').click(function() {
  5067. const isCheck = $(this).is(':checked');
  5068. $(this).parents('table').find('.list-table').each(function() {
  5069. $(this).find('input:checkbox').prop("checked", isCheck);
  5070. })
  5071. });
  5072. // 显示层次
  5073. (function (select, sheet) {
  5074. $(select).click(function () {
  5075. if (!sheet.zh_tree) return;
  5076. const tag = $(this).attr('tag');
  5077. const tree = sheet.zh_tree;
  5078. setTimeout(() => {
  5079. showWaitingView();
  5080. switch (tag) {
  5081. case "1":
  5082. case "2":
  5083. case "3":
  5084. case "4":
  5085. case "5":
  5086. tree.expandByLevel(parseInt(tag));
  5087. SpreadJsObj.refreshTreeRowVisible(sheet);
  5088. break;
  5089. case "last":
  5090. tree.expandByCustom(() => { return true; });
  5091. SpreadJsObj.refreshTreeRowVisible(sheet);
  5092. break;
  5093. case "leafXmj":
  5094. tree.expandToLeafXmj();
  5095. SpreadJsObj.refreshTreeRowVisible(sheet);
  5096. break;
  5097. case "curMeasure":
  5098. tree.expandByCustom(function (node) {
  5099. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  5100. if (node[field]) {
  5101. return true;
  5102. }
  5103. }
  5104. return false;
  5105. });
  5106. SpreadJsObj.refreshTreeRowVisible(sheet);
  5107. break;
  5108. case "endMeasure":
  5109. tree.expandByCustom(function (node) {
  5110. 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']) {
  5111. if (node[field]) {
  5112. return true;
  5113. }
  5114. }
  5115. return false;
  5116. });
  5117. SpreadJsObj.refreshTreeRowVisible(sheet);
  5118. break;
  5119. }
  5120. closeWaitingView();
  5121. }, 100);
  5122. });
  5123. })('a[name=showLevel]', slSpread.getActiveSheet());
  5124. const stageCheckerSetting = {
  5125. ledgerTree: stageTree,
  5126. ledgerPos: stagePos,
  5127. checkList: checkList,
  5128. decimal: tenderInfo.decimal,
  5129. checkOption: checkOption,
  5130. };
  5131. if (!checkTzMeasureType()) {
  5132. stageCheckerSetting.checkOption.tp.fields.push(
  5133. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  5134. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  5135. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  5136. {qty: 'quantity', tp: 'total_price'},
  5137. );
  5138. }
  5139. $('#ledger-check2').click(() => {
  5140. ledgerCheck2(stageCheckerSetting).then(result => {
  5141. check2Viewing({
  5142. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  5143. randomWait: true,
  5144. prefix: 'check2-',
  5145. checks: result,
  5146. checkList: checkList,
  5147. });
  5148. });
  5149. });
  5150. const dataChecker = DataChecker({
  5151. checkUrl: window.location.pathname + '/check',
  5152. completeData: function (data) {
  5153. stagePos.updateDatas({pos: data.source.pos});
  5154. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  5155. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  5156. stagePosSpreadObj.loadCurPosData();
  5157. for (const e of data.error) {
  5158. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  5159. }
  5160. },
  5161. errorList: errorList,
  5162. });
  5163. $('[name=stage-start]').submit(function (e) {
  5164. if (checkAuditorFrom()) {
  5165. // 再检查多人协同确认情况
  5166. const list = stage.relaAssists.find(x => {return !x.confirm });
  5167. if(list) {
  5168. toastr.error('请检查多人协同确认情况再上报');
  5169. $('#hide-all').hide();
  5170. return false;
  5171. }
  5172. $(this).parent().parent().parent().modal('hide');
  5173. dataChecker.checkAndPost(this.action, {});
  5174. $('#hide-all').hide();
  5175. }
  5176. return false;
  5177. });
  5178. $('#audit-check0').submit(function (e) {
  5179. // 再检查多人协同确认情况
  5180. const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
  5181. if(list) {
  5182. toastr.error('请检查多人协同确认情况再审批通过');
  5183. $('#hide-all').hide();
  5184. return false;
  5185. }
  5186. const checkType = parseInt($('[name=checkType]').val());
  5187. const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
  5188. const data = {
  5189. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5190. coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
  5191. checkType,
  5192. };
  5193. $('#sp-done').modal('hide');
  5194. checkType && dataChecker.checkAndPost(this.action, data);
  5195. $('#hide-all').hide();
  5196. return false;
  5197. });
  5198. $('#audit-check1').submit(function (e) {
  5199. const checkType = parseInt($('[name=checkType]:checked').val());
  5200. const confirm = stage.relaAssists.filter(x => { return x.confirm });
  5201. const data = {
  5202. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  5203. coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
  5204. checkType,
  5205. };
  5206. if ($('#warning-text').length) $('#warning-text').remove();
  5207. if (!checkType && !$('#warning-text').length) {
  5208. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5209. return false
  5210. }
  5211. $('#sp-back').modal('hide');
  5212. checkType && dataChecker.checkAndPost(this.action, data);
  5213. $('#hide-all').hide();
  5214. return false;
  5215. });
  5216. $('#exportExcel').click(function () {
  5217. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  5218. });
  5219. $('#cbr-check-all').click(function () {
  5220. if (this.checked) {
  5221. $('input', '#cbr-pos-list').attr('checked', 'checked');
  5222. } else {
  5223. $('input', '#cbr-pos-list').removeAttr('checked');
  5224. }
  5225. });
  5226. $('#cbr-ok').click(() => {
  5227. const ratio = parseInt($('#cbr-ratio').val());
  5228. if (!ratio) {
  5229. toastr.warning('请输入计量比例');
  5230. return;
  5231. } else if (ratio < 1) {
  5232. toastr.warning('计量比例不可小于1');
  5233. return;
  5234. } else if (ratio > 100) {
  5235. toastr.warning('计量比例不可大于100');
  5236. return;
  5237. }
  5238. const apply2sibling = $('#apply2sibling')[0].checked;
  5239. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  5240. if (posName.length === 0) {
  5241. toastr.warning('请勾选需要按计量比例的计量单元');
  5242. return;
  5243. }
  5244. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  5245. });
  5246. // 收方单生成
  5247. $('#setshoufang').click(function () {
  5248. const lid = $('#shoufang-lid').val();
  5249. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  5250. // 修改线上
  5251. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  5252. // 收方单tab打开并显示在最新
  5253. if (!$('#shoufang-tab').hasClass('active')) {
  5254. $('#shoufang-tab').click();
  5255. }
  5256. const data = makeOneShouFang(result);
  5257. data.filenum = 0;
  5258. sfData = _.concat(data, sfData);
  5259. getShouFangList();
  5260. });
  5261. });
  5262. $('body').on('click', '.del-shoufang', function () {
  5263. const id = $(this).attr('data-id');
  5264. $('#del-shoufang-id').val(id);
  5265. const name = $(this).parents('tr').children('td').eq(0).text();
  5266. const ledger_code = name.split(' / ')[0];
  5267. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  5268. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  5269. if (pos_name) {
  5270. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  5271. } else {
  5272. $('#del-shoufang-pos').text('').hide();
  5273. }
  5274. });
  5275. // 收方单删除
  5276. $('#delshoufang').click(function () {
  5277. const sfid = $('#del-shoufang-id').val();
  5278. // 修改线上
  5279. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  5280. // 删除到sfData中
  5281. const att_index = sfData.findIndex(function (item) {
  5282. return item.id === parseInt(sfid);
  5283. });
  5284. sfData.splice(att_index, 1);
  5285. // 重新生成List
  5286. if ($('#shoufang-table tr').length === 1) {
  5287. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  5288. } else {
  5289. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  5290. }
  5291. $('#shoufangdelete').modal('hide');
  5292. });
  5293. });
  5294. // 切换页数
  5295. $('.shoufang-page-select').on('click', function () {
  5296. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  5297. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  5298. const status = $(this).attr('content');
  5299. if (status === 'pre' && lastPageNum > 1) {
  5300. getShouFangList(lastPageNum-1);
  5301. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5302. getShouFangList(lastPageNum+1);
  5303. }
  5304. });
  5305. // 获取单个收方单附件列表
  5306. $('body').on('click', '.show-shoufang-att', function () {
  5307. const id = parseInt($(this).attr('data-id'));
  5308. let html = '';
  5309. $('#shoufang-flie-list').html(html);
  5310. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  5311. for (const att of result) {
  5312. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  5313. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  5314. `<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>`;
  5315. }
  5316. $('#shoufang-flie-list').html(html);
  5317. $('[data-toggle="tooltip"]').tooltip()
  5318. });
  5319. function makeViewHtml(viewpath) {
  5320. 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>` : '';
  5321. }
  5322. function makeDelHtml(fid, extra_upload) {
  5323. return sfAttDelPower &&
  5324. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5325. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  5326. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5327. }
  5328. });
  5329. function makeEditHtml(fid, filename, fileext, extra_upload) {
  5330. return sfAttDelPower &&
  5331. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5332. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  5333. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  5334. }
  5335. // 修改收方单附件文件名
  5336. $('body').on('click', '.edit-shoufang-att', function () {
  5337. $(this).children('i').tooltip('hide');
  5338. const fid = $(this).data('id');
  5339. const filename = $(this).data('filename');
  5340. const fileext = $(this).data('fileext');
  5341. const html = `<div class="input-group input-group-sm">
  5342. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  5343. <div class="input-group-append" id="button-${fid}">
  5344. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  5345. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  5346. </div>
  5347. </div>`;
  5348. $(this).parents('td').html(html);
  5349. });
  5350. // 确认修改文件名
  5351. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  5352. const validText = $.trim($(this).parents('td').find('input').val());
  5353. const orgValue = $.trim($(this).data('filename'));
  5354. const fileext = $(this).data('fileext');
  5355. const fid = $(this).data('fid');
  5356. if (!validText) {
  5357. toastr.error('文件名不能为空');
  5358. return;
  5359. }
  5360. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  5361. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  5362. toastr.error('文件名中不能包含.字符和空格');
  5363. return;
  5364. }
  5365. if(validText == orgValue) {
  5366. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  5367. $(this).parents('td').html(html);
  5368. return;
  5369. }
  5370. const data = {
  5371. id: fid,
  5372. filename: validText,
  5373. };
  5374. const _self = $(this);
  5375. postData('/wap/shoufang/editfile', data, function (result) {
  5376. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  5377. _self.parents('td').html(html);
  5378. });
  5379. });
  5380. // 取消修改文件名
  5381. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  5382. const fid = $(this).data('fid');
  5383. const filename = $(this).data('filename');
  5384. const fileext = $(this).data('fileext');
  5385. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  5386. $(this).parents('td').html(html);
  5387. });
  5388. // 删除收方单附件
  5389. $('body').on('click', '.del-shoufang-att', function () {
  5390. const id = $(this).data('id');
  5391. const _self = $(this);
  5392. const data = { id };
  5393. const sfid = $(this).data('sfid');
  5394. postData('/wap/shoufang/delfile', data, function (result) {
  5395. _self.parents('tr').remove();
  5396. // 附件个数更新
  5397. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  5398. const sfInfo = _.find(sfData, { id: sfid });
  5399. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  5400. });
  5401. });
  5402. // 定位到对应的清单或计量单元
  5403. $('body').on('click', '.show-shoufang-node', function () {
  5404. const id = parseInt($(this).attr('data-id'));
  5405. const sfInfo = _.find(sfData, { id });
  5406. if (sfInfo) {
  5407. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5408. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  5409. stagePosSpreadObj.loadCurPosData();
  5410. if (sfInfo.pid) {
  5411. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  5412. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  5413. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  5414. }
  5415. }
  5416. });
  5417. // 定位到对应的清单或计量单元
  5418. $('body').on('click', '.show-shoufang-report', function () {
  5419. const id = parseInt($(this).attr('data-id'));
  5420. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  5421. sessionStorage.qrCodePath = qrCodePath;
  5422. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  5423. sessionStorage.req_params = JSON.stringify(req_params);
  5424. sessionStorage.rpt_name = rpt_name;
  5425. window.open('/individualReport/A4');
  5426. });
  5427. $('#importExcel').click(() => {
  5428. importExcel.doImport({
  5429. template: {
  5430. hint: '计量台账',
  5431. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  5432. },
  5433. callback: function (sheet) {
  5434. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  5435. window.location.reload();
  5436. }, null);
  5437. }
  5438. });
  5439. });
  5440. const stageAssistRela = {
  5441. refreshAssConfirmBtn: function () {
  5442. if (stage.assist) {
  5443. const caption = stage.assist.user_id === stage.user_id
  5444. ? (stage.assist.confirm ? '撤销上报' : '确认上报')
  5445. : (stage.assist.confirm ? '重新审批' : '审批通过');
  5446. if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
  5447. } else {
  5448. $('#ass-confirm-btn').hide();
  5449. }
  5450. },
  5451. checkAssistPartUsed(assist) {
  5452. const ass_lid = assist.ass_ledger_id.split(',');
  5453. for (const lid of ass_lid) {
  5454. const node = stageTree.getItems(lid);
  5455. if (!node) continue;
  5456. if (checkUsed(stageTree, stagePos, node)) return true;
  5457. }
  5458. return false;
  5459. },
  5460. refreshAssistTable: function () {
  5461. const html = [];
  5462. for (const ra of stage.relaAssists) {
  5463. const used = this.checkAssistPartUsed(ra);
  5464. const hint = used
  5465. ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
  5466. : '<td>本期未计量</td>';
  5467. html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
  5468. }
  5469. return $('#assistList').html(html.join(''));
  5470. },
  5471. refreshAssists: function () {
  5472. if (stage.relaAssists.length > 0) {
  5473. $('#assistCount').html(stage.relaAssists.length || '').parent().show();
  5474. } else {
  5475. $('#assistCount').parent().hide();
  5476. }
  5477. },
  5478. refreshReadOnly(){
  5479. stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
  5480. SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
  5481. stagePosSpreadObj.loadCurPosData();
  5482. },
  5483. init: function() {
  5484. this.refreshAssConfirmBtn();
  5485. this.refreshReadOnly();
  5486. this.refreshAssists();
  5487. },
  5488. };
  5489. stageAssistRela.init();
  5490. $('#ass-confirm-btn').click(() => {
  5491. const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
  5492. postData(window.location.pathname + '/ass-confirm', data, function(result) {
  5493. window.location.reload();
  5494. // stage.assist = result;
  5495. // stageAssistRela.refreshAssConfirmBtn();
  5496. // stageAssistRela.refreshReadOnly();
  5497. });
  5498. });
  5499. $('#assists').on('show.bs.modal', function(){
  5500. postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
  5501. stage.relaAssists = result;
  5502. stageAssistRela.refreshAssistTable();
  5503. });
  5504. });
  5505. $('body').on('click', 'a[name=att-delete]', function() {
  5506. const fid = this.getAttribute('file-id');
  5507. if (!fid) return;
  5508. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  5509. const data = {id: fid};
  5510. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  5511. // 删除到attData中
  5512. const att_index = attData.findIndex(function (item) {
  5513. return item.id === parseInt(fid);
  5514. });
  5515. attData.splice(att_index, 1);
  5516. // 重新生成List
  5517. if ($('#alllist-table tr').length === 1) {
  5518. getAllList(parseInt($('#currentPage').text()) - 1);
  5519. } else {
  5520. getAllList(parseInt($('#currentPage').text()));
  5521. }
  5522. getNodeList(node.id);
  5523. $('#showAttachment').hide();
  5524. $('#showAttachment').attr('file-id', '');
  5525. });
  5526. });
  5527. });
  5528. function makeOneShouFang(sf) {
  5529. const lData = _.find(ledgerData, { id: sf.lid });
  5530. sf.name = lData.b_code;
  5531. if (sf.pid) {
  5532. const pData = _.find(posData, { id: sf.pid });
  5533. if (pData && pData.name) {
  5534. sf.name = lData.b_code + ' / ' + pData.name;
  5535. }
  5536. }
  5537. return sf;
  5538. }
  5539. function makeShouFang() {
  5540. for (const sf of sfData) {
  5541. makeOneShouFang(sf);
  5542. }
  5543. getShouFangList();
  5544. }
  5545. // 生成收方单列表
  5546. function getShouFangList(currPageNum = 1) {
  5547. // 每页最多几个附件
  5548. const pageCount = 20;
  5549. // 附件总数
  5550. const total = sfData.length;
  5551. // 总页数
  5552. const pageNum = Math.ceil(total/pageCount);
  5553. $('#shoufang-totalPage').text(pageNum);
  5554. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  5555. // 当前页附件内容
  5556. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  5557. let html = '';
  5558. for(const att of currPageAttData) {
  5559. html += '<tr><td>' + att.name + '</td>' +
  5560. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  5561. '<td width="100">' +
  5562. '<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> ' +
  5563. '<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> ' +
  5564. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  5565. makeDelHtml(att.id, att.extra_upload) +
  5566. '</td></tr>';
  5567. }
  5568. function makeDelHtml(id, extra_upload) {
  5569. return cur_uid === stage.user_id &&
  5570. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5571. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  5572. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5573. }
  5574. $('#shoufang-table').html(html);
  5575. $('[data-toggle="tooltip"]').tooltip();
  5576. }
  5577. function makeReportData(sfid) {
  5578. const sfInfo = _.find(sfData, { id: sfid });
  5579. const ledger_code = sfInfo.name.split(' / ')[0];
  5580. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  5581. const replace_key_params = {
  5582. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  5583. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  5584. 'KEY_合同段': tenderInfo.deal_info.dealName,
  5585. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  5586. 'KEY_编号': '',
  5587. 'KEY_设计工程数量': 0,
  5588. };
  5589. // if (sfInfo.pid) {
  5590. // const pData = _.find(posData, { id: sfInfo.pid });
  5591. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  5592. // } else {
  5593. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5594. // }
  5595. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  5596. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  5597. const req_params = {
  5598. 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)
  5599. pageSize: 'A4',
  5600. project_id: tender.project_id,
  5601. tender_id: tender.id,
  5602. stage_id: stage.id,
  5603. sp_id: spid,
  5604. };
  5605. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  5606. const qrCodePath = sfInfo.qrcode;
  5607. return [qrCodePath, replace_key_params, req_params, rpt_name];
  5608. }