stage.js 282 KB

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