stage.js 287 KB

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