stage.js 274 KB

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