stage.js 276 KB

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