stage.js 275 KB

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