stage.js 287 KB

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