stage.js 275 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573
  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. const posUnMeasure = $('#pos-un-measure')[0].checked;
  1972. posData.forEach(x => {
  1973. x.visible = true;
  1974. if (posMeasure && x.visible) {
  1975. x.visible = !!x.contract_qty || !!x.qc_qty || !!x.qc_minus_qty;
  1976. }
  1977. if (posUnMeasure && x.visible) {
  1978. // 不考虑不计价
  1979. x.visible = !x.end_contract_qty && !x.end_qc_qty && !x.end_gather_qty; // && !x.qc_minus_qty;
  1980. }
  1981. });
  1982. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData, posReadOnly);
  1983. getNodeList(node.id);
  1984. } else {
  1985. spSpread.getActiveSheet().zh_setting.readOnly = true;
  1986. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', [], true);
  1987. }
  1988. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1989. },
  1990. editEnded: function (e, info) {
  1991. if (info.sheet.zh_setting) {
  1992. // 未改变过,则直接跳过
  1993. const sortData = info.sheet.zh_data;
  1994. const posData = sortData ? sortData[info.row] : null;
  1995. const col = info.sheet.zh_setting.cols[info.col];
  1996. const orgText = posData ? posData[col.field] : null;
  1997. const newText = trimInvalidChar(info.editingText);
  1998. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1999. return;
  2000. }
  2001. // 台账模式下,不可新增
  2002. if (checkTzMeasureType() && !posData) {
  2003. toastr.error('台账模式不可新增计量单元数据');
  2004. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2005. return ;
  2006. }
  2007. // 不同节点下,计量单元检查输入
  2008. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2009. const node = stagePosSpreadObj.stageTreeNode;
  2010. if (!node) {
  2011. toastr.warning('数据错误, 请刷新页面后再试');
  2012. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2013. return;
  2014. } else if (newText !== '' && node.children && node.children.length > 0) {
  2015. toastr.error('父节点不可插入计量单元');
  2016. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2017. return;
  2018. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  2019. toastr.error('项目节不可插入计量单元');
  2020. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2021. return;
  2022. }
  2023. // 生成提交数据
  2024. const data = {};
  2025. if (col.field === 'name') {
  2026. if ((!newText || newText === '') && posData) {
  2027. toastr.error('部位名称不可为空');
  2028. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2029. return;
  2030. } else if (!posData) {
  2031. if (newText !== '') {
  2032. data.updateType = 'add';
  2033. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2034. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2035. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2036. return;
  2037. }
  2038. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2039. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  2040. } else {
  2041. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2042. return;
  2043. }
  2044. } else {
  2045. data.updateType = 'update';
  2046. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  2047. }
  2048. } else if (!posData) {
  2049. toastr.warning('新增计量单元请先输入名称');
  2050. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  2051. data.updateType = 'update';
  2052. data.updateData = {pid: posData.id, lid: posData.lid};
  2053. data.updateData[col.field] = newText;
  2054. } else {
  2055. data.updateType = 'update';
  2056. data.updateData = {pid: posData.id, lid: posData.lid};
  2057. if (col.type === 'Number') {
  2058. const exprInfo = getExprInfo(col.field);
  2059. const num = _.toNumber(newText);
  2060. if (_.isFinite(num)) {
  2061. data.updateData[col.field] = num;
  2062. if (exprInfo) {
  2063. data.updateData[exprInfo.expr] = '';
  2064. }
  2065. } else {
  2066. try {
  2067. data.updateData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2068. if (exprInfo) {
  2069. data.updateData[exprInfo.expr] = newText;
  2070. }
  2071. } catch(err) {
  2072. toastr.error('输入的表达式非法');
  2073. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2074. return;
  2075. }
  2076. }
  2077. } else if (col.field.indexOf('_expr') > 0) {
  2078. const exprInfo = getExprInfo(col.field, true);
  2079. if (!exprInfo) return;
  2080. if (newText) {
  2081. try {
  2082. data.updateData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2083. data.updateData[exprInfo.expr] = newText;
  2084. } catch(err) {
  2085. toastr.error('输入的表达式非法');
  2086. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2087. return;
  2088. }
  2089. } else {
  2090. data.updateData[exprInfo.qty] = 0;
  2091. data.updateData[exprInfo.expr] = '';
  2092. }
  2093. } else {
  2094. data.updateData[col.field] = newText;
  2095. }
  2096. }
  2097. // 提交数据到服务器
  2098. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2099. if (result.pos) {
  2100. stagePos.updateDatas(result.pos.pos);
  2101. stagePos.loadCurStageData(result.pos.curStageData);
  2102. }
  2103. const refreshData = stageTree.loadPostStageData(result.ledger);
  2104. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2105. stagePosSpreadObj.loadCurPosData();
  2106. if (detail) {
  2107. detail.loadStagePosUpdateData(result, refreshData);
  2108. } else {
  2109. stageIm.loadUpdatePosData(result, refreshData);
  2110. }
  2111. }, function () {
  2112. stagePosSpreadObj.loadCurPosData();
  2113. });
  2114. }
  2115. },
  2116. editStarting: function (e, info) {
  2117. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2118. const sel = info.sheet.getSelections();
  2119. if (!sel || !sel[0]) return;
  2120. const col = info.sheet.zh_setting.cols[sel[0].col];
  2121. const node = SpreadJsObj.getSelectObject(info.sheet);
  2122. const exprInfo = getExprInfo(col.field);
  2123. if (exprInfo && node) {
  2124. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2125. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2126. }
  2127. }
  2128. switch (col.field) {
  2129. case 'contract_qty':
  2130. case 'contract_expr':
  2131. case 'qc_qty':
  2132. case 'qc_minus_qty':
  2133. info.cancel = node.settle_status === settleStatus.finish;
  2134. break;
  2135. }
  2136. },
  2137. clipboardPasting: function (e, info) {
  2138. if (info.sheet.zh_setting) {
  2139. const sortData = info.sheet.zh_data;
  2140. const range = info.cellRange;
  2141. const validField = ['contract_qty', 'contract_expr', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
  2142. if (!checkTzMeasureType()) {
  2143. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  2144. }
  2145. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  2146. const col = info.sheet.zh_setting.cols[iCol];
  2147. if (validField.indexOf(col.field) === -1) {
  2148. if (checkTzMeasureType()) {
  2149. toastr.error('不可修改此数据');
  2150. info.cancel = true;
  2151. return;
  2152. } else {
  2153. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  2154. const pos = sortData(iRow);
  2155. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  2156. toastr.error('不可修改此数据');
  2157. info.cancel = true;
  2158. return;
  2159. }
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. },
  2166. clipboardPasted: function (e, info) {
  2167. const hint = {
  2168. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  2169. };
  2170. if (info.sheet.zh_setting) {
  2171. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2172. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2173. }
  2174. const data = { updateType: '', updateData: [], };
  2175. const sortData = info.sheet.zh_data;
  2176. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2177. if (node.children && node.children.length > 0) return;
  2178. if (sortData && (info.cellRange.row >= sortData.length)) {
  2179. data.updateType = 'add';
  2180. if (info.cellRange.col !== 0) {
  2181. toastr.warning('新增计量单元请先输入名称');
  2182. stagePosSpreadObj.loadCurPosData();
  2183. return;
  2184. }
  2185. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  2186. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  2187. stagePosSpreadObj.loadCurPosData();
  2188. return;
  2189. }
  2190. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2191. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2192. const curRow = info.cellRange.row + iRow;
  2193. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  2194. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2195. const curCol = info.cellRange.col + iCol;
  2196. const colSetting = info.sheet.zh_setting.cols[curCol];
  2197. if (!colSetting) continue;
  2198. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2199. if (colSetting.type === 'Number') {
  2200. const exprInfo = getExprInfo(colSetting.field);
  2201. if (newValue) {
  2202. const num = _.toNumber(newValue);
  2203. if (num) {
  2204. newData[colSetting.field] = num;
  2205. if (exprInfo) {
  2206. newData[exprInfo.expr] = '';
  2207. }
  2208. } else {
  2209. try {
  2210. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2211. if (exprInfo) {
  2212. newData[exprInfo.expr] = newValue;
  2213. }
  2214. } catch(err) {
  2215. toastr.error('输入的表达式非法');
  2216. stagePosSpreadObj.loadCurPosData();
  2217. return;
  2218. }
  2219. }
  2220. } else {
  2221. newData[colSetting.field] = null;
  2222. if (exprInfo) newData[exprInfo.expr] = '';
  2223. }
  2224. } else if (colSetting.field.indexOf('_expr') > 0) {
  2225. try {
  2226. const exprInfo = getExprInfo(colSetting.field, true);
  2227. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2228. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2229. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2230. }
  2231. } catch (err) {
  2232. toastMessageUniq(hint.expr);
  2233. }
  2234. } else {
  2235. newData[colSetting.field] = newValue;
  2236. }
  2237. }
  2238. data.updateData.push(newData);
  2239. }
  2240. } else {
  2241. data.updateType = 'update';
  2242. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2243. const curRow = info.cellRange.row + iRow;
  2244. const curPos = sortData[curRow];
  2245. if (curPos) {
  2246. const newData = {pid: curPos.id, lid: curPos.lid};
  2247. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  2248. const curCol = info.cellRange.col + iCol;
  2249. const colSetting = info.sheet.zh_setting.cols[curCol];
  2250. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2251. if (colSetting.type === 'Number') {
  2252. if (curPos.settle_status === settleStatus.finish) {
  2253. newData.error = 1;
  2254. continue;
  2255. }
  2256. const exprInfo = getExprInfo(colSetting.field);
  2257. if (!newValue) {
  2258. newData[colSetting.field] = newValue;
  2259. if (exprInfo) newData[exprInfo.expr] = '';
  2260. continue;
  2261. }
  2262. const num = _.toNumber(newValue);
  2263. if (num) {
  2264. newData[colSetting.field] = num;
  2265. if (exprInfo) newData[exprInfo.expr] = '';
  2266. } else {
  2267. try {
  2268. newData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2269. const exprInfo = getExprInfo(colSetting.field);
  2270. if (exprInfo) newData[exprInfo.expr] = newValue;
  2271. } catch(err) {
  2272. toastr.error('输入的表达式非法');
  2273. stagePosSpreadObj.loadCurPosData();
  2274. return;
  2275. }
  2276. }
  2277. } else if (colSetting.field.indexOf('_expr') > 0) {
  2278. try {
  2279. const exprInfo = getExprInfo(colSetting.field, true);
  2280. newData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  2281. if (newData[exprInfo.expr] || newData[exprInfo.qty] === undefined) {
  2282. newData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newData[exprInfo.expr]));
  2283. }
  2284. } catch (err) {
  2285. toastMessageUniq(hint.expr);
  2286. }
  2287. } else {
  2288. newData[colSetting.field] = newValue;
  2289. }
  2290. }
  2291. if (newData.error === undefined) data.updateData.push(newData);
  2292. }
  2293. }
  2294. }
  2295. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2296. if (result.pos) {
  2297. stagePos.updateDatas(result.pos.pos);
  2298. stagePos.loadCurStageData(result.pos.curStageData);
  2299. }
  2300. const nodes = stageTree.loadPostStageData(result.ledger);
  2301. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2302. stagePosSpreadObj.loadCurPosData();
  2303. if (detail) {
  2304. detail.loadStagePosUpdateData(result, nodes);
  2305. } else {
  2306. stageIm.loadUpdatePosData(result, nodes);
  2307. }
  2308. }, function () {
  2309. stagePosSpreadObj.loadCurPosData();
  2310. });
  2311. }
  2312. },
  2313. deletePress: function (sheet) {
  2314. if (sheet.zh_setting.readOnly) return;
  2315. if (sheet.zh_setting && sheet.zh_data) {
  2316. const sortData = sheet.zh_data;
  2317. if (!sortData || sortData.length === 0) { return; }
  2318. const sel = sheet.getSelections()[0];
  2319. const validCols = [];
  2320. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2321. const colSetting = sheet.zh_setting.cols[iCol];
  2322. if (!colSetting.readOnly && colSetting.field !== 'qc_qty' && colSetting.field !== 'qc_minus_qty') {
  2323. validCols.push(iCol);
  2324. }
  2325. }
  2326. if (validCols.length === 0) { return; }
  2327. const datas = [], posSelects = [];
  2328. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2329. const node = sortData[iRow];
  2330. if (node) {
  2331. const data = {pid: node.id, lid: node.lid};
  2332. for (const iCol of validCols) {
  2333. const colSetting = sheet.zh_setting.cols[iCol];
  2334. if (colSetting.field === 'name') {
  2335. toastr.error('部位名称不能为空');
  2336. return;
  2337. }
  2338. if (colSetting.Type === 'Number' && node.settle_status === settleStatus.finish) {
  2339. toastr.error('已结算节点不可计量');
  2340. return;
  2341. }
  2342. if (colSetting.field.indexOf('_expr') > 0) {
  2343. const exprInfo = getExprInfo(colSetting.field, true);
  2344. if (!exprInfo) continue;
  2345. data[exprInfo.expr] = '';
  2346. data[exprInfo.qty] = 0;
  2347. } else {
  2348. data[colSetting.field] = null;
  2349. const exprInfo = getExprInfo(colSetting.field);
  2350. if (exprInfo) {
  2351. data[exprInfo.expr] = '';
  2352. }
  2353. }
  2354. }
  2355. datas.push(data);
  2356. posSelects.push(node);
  2357. }
  2358. }
  2359. if (datas.length > 0) {
  2360. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  2361. if (result.pos) {
  2362. stagePos.updateDatas(result.pos.pos);
  2363. stagePos.loadCurStageData(result.pos.curStageData);
  2364. }
  2365. const nodes = stageTree.loadPostStageData(result.ledger);
  2366. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2367. if (detail) {
  2368. detail.loadStagePosUpdateData(result, nodes);
  2369. } else {
  2370. stageIm.loadUpdatePosData(result, nodes);
  2371. }
  2372. // todo 只加载改变项
  2373. stagePosSpreadObj.loadCurPosData();
  2374. });
  2375. }
  2376. }
  2377. },
  2378. deletePos: function (sheet) {
  2379. const sels = sheet.getSelections();
  2380. const sel = sels ? sels[0] : null;
  2381. if (sheet.zh_data && sel) {
  2382. const data = {updateType: 'delete', updateData: []};
  2383. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  2384. const posData = sheet.zh_data[sel.row + iRow];
  2385. if (posData) {
  2386. data.updateData.push(posData.id);
  2387. }
  2388. }
  2389. if (data.updateData.length > 0) {
  2390. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2391. stagePos.removeDatas(result.pos.pos);
  2392. const refreshData = stageTree.loadPostStageData(result.ledger);
  2393. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2394. stagePosSpreadObj.loadCurPosData();
  2395. if (detail) {
  2396. detail.loadStagePosUpdateData(result, refreshData);
  2397. } else {
  2398. stageIm.loadUpdatePosData(result, refreshData);
  2399. }
  2400. });
  2401. }
  2402. }
  2403. },
  2404. selectionChanged: function (e, info) {
  2405. stagePosSpreadObj.loadExprToInput(info.sheet);
  2406. },
  2407. addPegs: function (pegs) {
  2408. if (!pegs || pegs.length <= 0) return;
  2409. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2410. if (!node) return;
  2411. const sheet = spSpread.getActiveSheet();
  2412. const sortData = sheet.zh_data || [];
  2413. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  2414. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  2415. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  2416. if (result.pos) {
  2417. stagePos.updateDatas(result.pos.pos);
  2418. }
  2419. stagePosSpreadObj.loadCurPosData();
  2420. });
  2421. }
  2422. };
  2423. $('#pos-measure').click(stagePosSpreadObj.loadCurPosData);
  2424. $('#pos-un-measure').click(stagePosSpreadObj.loadCurPosData);
  2425. // 加载上下窗口resizer
  2426. $.divResizer({
  2427. select: '#main-resize',
  2428. callback: function () {
  2429. slSpread.refresh();
  2430. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2431. $(".sp-wrap").height(bcontent-30);
  2432. spSpread.refresh();
  2433. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2434. }
  2435. });
  2436. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  2437. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;stageChange;import_change;tag' }, function (result) {
  2438. // 加载树结构
  2439. stageTree.loadDatas(result.ledgerData, result.locked);
  2440. if (stage.assist) {
  2441. stageTree.loadFilter(stage.assist.ass_ledger_id);
  2442. } else if (stage.relaAuditor && stage.relaAuditor.audit_ledger_id) {
  2443. stageTree.loadFilter(stage.relaAuditor.audit_ledger_id);
  2444. }
  2445. // 加载部位明细
  2446. stagePos.loadDatas(result.posData);
  2447. checkShowLast(result.ledgerData.length);
  2448. treeCalc.calculateAll(stageTree);
  2449. for (const t of result.tags) {
  2450. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  2451. }
  2452. billsTag.loadDatas(result.tags);
  2453. stagePos.calculateAll();
  2454. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  2455. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  2456. stagePosSpreadObj.loadCurPosData();
  2457. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  2458. TreeExprCalc.init({
  2459. tree: stageTree,
  2460. decimal: tenderInfo.decimal,
  2461. precision: tenderInfo.precision,
  2462. calcField: { qty: 'contract_qty', tp: 'contract_tp' }, calcType: TreeExprCalc.calcType.sortCache,
  2463. exprFieldsIndex: {
  2464. tzsl: 'quantity', tzje: 'total_price', qysl: 'deal_qty', qyje: 'deal_tp',
  2465. bqhtje: 'contract_tp',
  2466. },
  2467. exprCacheKey: ['bqhtje'],
  2468. });
  2469. // 加载中间计量
  2470. stageIm.init(tenderInfo, stage, imType, tenderInfo.decimal);
  2471. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.stageChange, result.import_change, result.detailAtt);
  2472. if (stage.assist) {
  2473. stageIm.loadFilter(stage.assist.ass_ledger_id);
  2474. } else if (stage.relaAuditor) {
  2475. stageIm.loadFilter(stage.relaAuditor.audit_ledger_id);
  2476. }
  2477. errorList.loadHisErrorData();
  2478. checkList.loadHisCheckData();
  2479. sumLoadMiss.loadHisMissData();
  2480. // 收方单赋值
  2481. ledgerData = result.ledgerData;
  2482. posData = result.posData;
  2483. makeShouFang();
  2484. }, null, true);
  2485. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2486. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2487. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2488. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2489. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2490. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2491. if (!readOnly) {
  2492. $('#pos-expr').bind('change onblur', function () {
  2493. if (this.readOnly) return;
  2494. const expr = $(this);
  2495. const posSheet = spSpread.getActiveSheet();
  2496. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2497. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2498. if (!select) return;
  2499. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2500. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2501. const data = {pid: select.id, lid: select.lid};
  2502. const exprInfo = getExprInfo(field);
  2503. if (newValue !== '') {
  2504. const num = _.toNumber(newValue);
  2505. if (num) {
  2506. data[field] = num;
  2507. if (exprInfo) data[exprInfo.expr] = '';
  2508. } else {
  2509. try {
  2510. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  2511. if (exprInfo) data[exprInfo.expr] = newValue;
  2512. } catch (err) {
  2513. toastr.error('输入的表达式非法');
  2514. return;
  2515. }
  2516. }
  2517. } else {
  2518. data[field] = null;
  2519. if (exprInfo) data[exprInfo.expr] = '';
  2520. }
  2521. // 提交数据到服务器
  2522. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2523. if (result.pos) {
  2524. stagePos.updateDatas(result.pos.pos);
  2525. stagePos.loadCurStageData(result.pos.curStageData);
  2526. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2527. }
  2528. const refreshData = stageTree.loadPostStageData(result.ledger);
  2529. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2530. if (detail) {
  2531. detail.loadStagePosUpdateData(result, refreshData);
  2532. } else {
  2533. stageIm.loadUpdatePosData(result, refreshData);
  2534. }
  2535. });
  2536. });
  2537. }
  2538. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2539. $.contextMenu({
  2540. selector: '#stage-pos',
  2541. build: function ($trigger, e) {
  2542. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2543. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2544. },
  2545. items: {
  2546. 'del': {
  2547. name: '删除',
  2548. icon: 'fa-remove',
  2549. visible: function (key, opt) {
  2550. return !checkTzMeasureType();
  2551. },
  2552. disabled: function (key, opt) {
  2553. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2554. if (!node || node.lock) return true;
  2555. const sheet = spSpread.getActiveSheet();
  2556. if (sheet.zh_data && !readOnly) {
  2557. const selection = sheet.getSelections();
  2558. if (selection && selection[0]) {
  2559. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2560. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2561. const posData = sheet.zh_data[selection[0].row + iRow];
  2562. if (posData) {
  2563. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2564. valid = true;
  2565. break;
  2566. }
  2567. } else {
  2568. valid = true;
  2569. break;
  2570. }
  2571. }
  2572. return valid;
  2573. } else {
  2574. return true;
  2575. }
  2576. } else {
  2577. return true;
  2578. }
  2579. },
  2580. callback: function (key, opt) {
  2581. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2582. }
  2583. },
  2584. 'sort': {
  2585. name: '排序',
  2586. items: {
  2587. "addStageReverse": {
  2588. name: '按新增期倒序',
  2589. icon: 'fa-sort-amount-desc',
  2590. callback: function (key, opt) {
  2591. stagePos.sort = [['add_stage_order', 'desc'], ['porder', 'asc']];
  2592. const spSheet = spSpread.getActiveSheet();
  2593. if (spSheet.zh_data) {
  2594. spSheet.zh_data.sort((x, y) => { return y.add_stage_order - x.add_stage_order || x.porder - y.porder; });
  2595. SpreadJsObj.reLoadSheetData(spSheet);
  2596. }
  2597. }
  2598. }
  2599. }
  2600. },
  2601. 'merge-peg': {
  2602. name: '合并起讫桩号',
  2603. visible: function (key, opt) {
  2604. return !checkTzMeasureType();
  2605. },
  2606. disabled: function (key, opt) {
  2607. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2608. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2609. },
  2610. callback: function (key, opt) {
  2611. mergePeg.show();
  2612. }
  2613. },
  2614. 'calcByRatio': {
  2615. name: '按比例计量',
  2616. visible: function (key, opt) {
  2617. const data = spSpread.getActiveSheet().zh_data;
  2618. return checkTzMeasureType() && data && data.length > 0;
  2619. },
  2620. disabled: function (key, opt) {
  2621. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2622. return node.lock;
  2623. },
  2624. callback: function (key, opt) {
  2625. $('#cbr-ratio').val('');
  2626. $('#apply2sibling')[0].checked = false;
  2627. $('#cbr-check-all')[0].checked = false;
  2628. const html = [];
  2629. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2630. html.push('<tr>');
  2631. html.push('<td>', i+1, '</td>');
  2632. html.push('<td>', p.name, '</td>');
  2633. html.push('<td>', p.quantity, '</td>');
  2634. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2635. html.push('</tr>');
  2636. }
  2637. $('#cbr-pos-list').html(html.join(''));
  2638. $('#calc-by-ratio').modal('show');
  2639. }
  2640. },
  2641. 'remainCur': {
  2642. name: '填剩余量(选中行)',
  2643. disabled: function (key, opt) {
  2644. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2645. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2646. return readOnly || node.lock || !curPos;
  2647. },
  2648. callback: function (key, opt) {
  2649. const sheet = spSpread.getActiveSheet();
  2650. const sels = sheet.getSelections();
  2651. if (!sels || !sels[0]) return;
  2652. const data = { updateType: 'update', updateData: [] };
  2653. for (let iRow = 0; iRow < sels[0].rowCount; iRow++) {
  2654. const curRow = iRow + sels[0].row;
  2655. const curPos = SpreadJsObj.getRowObject(sheet, curRow);
  2656. if (!curPos) continue;
  2657. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2658. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2659. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2660. }
  2661. if (data.updateData.length > 0) {
  2662. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2663. if (result.pos) {
  2664. stagePos.updateDatas(result.pos.pos);
  2665. stagePos.loadCurStageData(result.pos.curStageData);
  2666. }
  2667. const nodes = stageTree.loadPostStageData(result.ledger);
  2668. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2669. stagePosSpreadObj.loadCurPosData();
  2670. if (detail) {
  2671. detail.loadStagePosUpdateData(result, nodes);
  2672. } else {
  2673. stageIm.loadUpdatePosData(result, nodes);
  2674. }
  2675. });
  2676. }
  2677. },
  2678. visible: function(key, opt) {
  2679. return checkTzMeasureType();
  2680. },
  2681. },
  2682. 'remainAll': {
  2683. name: '填剩余量(全部行)',
  2684. disabled: function (key, opt) {
  2685. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2686. const curPos = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2687. return readOnly || node.lock || !curPos;
  2688. },
  2689. callback: function (key, opt) {
  2690. const sheet = spSpread.getActiveSheet();
  2691. if (!sheet.zh_data || sheet.zh_data.length === 0) return;
  2692. const data = { updateType: 'update', updateData: [] };
  2693. for (const curPos of sheet.zh_data) {
  2694. const qty = ZhCalc.sub(curPos.quantity, curPos.pre_contract_qty);
  2695. const differ = ZhCalc.sub(curPos.quantity, curPos.end_contract_qty);
  2696. if (differ) data.updateData.push({ pid: curPos.id, lid: curPos.lid, contract_qty: qty, contract_expr: '' });
  2697. }
  2698. if (data.updateData.length > 0) {
  2699. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  2700. if (result.pos) {
  2701. stagePos.updateDatas(result.pos.pos);
  2702. stagePos.loadCurStageData(result.pos.curStageData);
  2703. }
  2704. const nodes = stageTree.loadPostStageData(result.ledger);
  2705. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  2706. stagePosSpreadObj.loadCurPosData();
  2707. if (detail) {
  2708. detail.loadStagePosUpdateData(result, nodes);
  2709. } else {
  2710. stageIm.loadUpdatePosData(result, nodes);
  2711. }
  2712. });
  2713. }
  2714. },
  2715. visible: function(key, opt) {
  2716. return checkTzMeasureType();
  2717. },
  2718. },
  2719. 'shoufangdan': {
  2720. name: '生成收方单',
  2721. visible: function(key, opt) {
  2722. if (cur_uid === stage.user_id) return true;
  2723. },
  2724. disabled: function (key, opt) {
  2725. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2726. if (!node || cur_uid !== stage.user_id) return true;
  2727. },
  2728. callback: function (key, opt) {
  2729. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2730. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2731. $('#shoufang-lid').val(node.lid);
  2732. $('#shoufang-pid').val(node.id);
  2733. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2734. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2735. $('#addshoufang').modal('show');
  2736. }
  2737. }
  2738. }
  2739. });
  2740. $.subMenu({
  2741. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2742. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2743. key: 'menu.1.0.0',
  2744. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2745. callback: function (info) {
  2746. if (info.mini) {
  2747. $('.panel-title').addClass('fluid');
  2748. $('#sub-menu').removeClass('panel-sidebar');
  2749. } else {
  2750. $('.panel-title').removeClass('fluid');
  2751. $('#sub-menu').addClass('panel-sidebar');
  2752. }
  2753. autoFlashHeight();
  2754. slSpread.refresh();
  2755. spSpread.refresh();
  2756. if (searchLedger) searchLedger.spread.refresh();
  2757. if (detail) detail.spread.refresh();
  2758. if (checkedChanges) checkedChanges.refresh();
  2759. if (errorList && errorList.spread) errorList.spread.refresh();
  2760. if (checkList) checkList.spread.refresh();
  2761. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2762. }
  2763. });
  2764. $('#row-view').on('show.bs.modal', function () {
  2765. const html = [], customDisplay = customColDisplay();
  2766. for (const cd of customDisplay) {
  2767. html.push('<tr>');
  2768. html.push('<td>', cd.title, '</td>');
  2769. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2770. html.push('</tr>');
  2771. }
  2772. $('#row-view-list').html(html.join(''));
  2773. });
  2774. $('#row-view-ok').click(function () {
  2775. const customDisplay = customColDisplay();
  2776. const cvl = $('#row-view-list').children();
  2777. for (const cv of cvl) {
  2778. const title = $(cv).children()[0].innerHTML;
  2779. const check = $('input', cv)[0].checked;
  2780. const cd = customDisplay.find(function (c) {
  2781. return c.title === title;
  2782. });
  2783. cd.visible = check;
  2784. }
  2785. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2786. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2787. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2788. $('#row-view').modal('hide');
  2789. });
  2790. const posSearch = (function () {
  2791. let resultArr = [];
  2792. const search = function () {
  2793. resultArr = [];
  2794. const keyword = $('#pos-search-keyword').val();
  2795. const checkOver = $('#pos-over-search')[0].checked;
  2796. const checkEmpty = $('#pos-empty-search')[0].checked;
  2797. const sortData = spSpread.getActiveSheet().zh_data;
  2798. if (checkOver || checkEmpty) {
  2799. if (sortData) {
  2800. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2801. const sd = sortData[i];
  2802. let match = false;
  2803. if (checkOver) {
  2804. if (sd.end_gather_qty) {
  2805. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2806. }
  2807. }
  2808. if (checkEmpty) {
  2809. if (sd.quantity) {
  2810. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2811. }
  2812. }
  2813. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2814. if (match) {
  2815. resultArr.push({index: i, data: sd});
  2816. }
  2817. }
  2818. }
  2819. } else if (keyword && keyword !== '') {
  2820. if (sortData) {
  2821. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2822. const sd = sortData[i];
  2823. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2824. resultArr.push({index: i, data: sd});
  2825. }
  2826. }
  2827. }
  2828. }
  2829. $('#pos-search-result').html('结果:' + resultArr.length);
  2830. };
  2831. const searchAndLocate = function () {
  2832. search();
  2833. if (resultArr.length > 0) {
  2834. const sheet = spSpread.getActiveSheet();
  2835. const sel = sheet.getSelections()[0];
  2836. const curRow = sel ? sel.row : 0;
  2837. const pos = resultArr[0];
  2838. if (pos.index !== curRow) {
  2839. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2840. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2841. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2842. }
  2843. }
  2844. };
  2845. const locateNext = function () {
  2846. if (resultArr.length > 0) {
  2847. const sheet = spSpread.getActiveSheet();
  2848. const sel = sheet.getSelections()[0];
  2849. const curRow = sel ? sel.row : 0;
  2850. let next = _.find(resultArr, function (d) {
  2851. return d.index > curRow;
  2852. });
  2853. if (!next) next = resultArr[0];
  2854. if (next.index !== curRow) {
  2855. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2856. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2857. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2858. }
  2859. }
  2860. };
  2861. const locatePre = function () {
  2862. if (resultArr.length > 0) {
  2863. const sheet = spSpread.getActiveSheet();
  2864. const sel = sheet.getSelections()[0];
  2865. const curRow = sel ? sel.row : 0;
  2866. let next = _.findLast(resultArr, function (d) {
  2867. return d.index < curRow;
  2868. });
  2869. if (!next) next = resultArr[resultArr.length - 1];
  2870. if (next.index !== curRow) {
  2871. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2872. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2873. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2874. }
  2875. }
  2876. };
  2877. return {search, searchAndLocate, locateNext, locatePre};
  2878. })();
  2879. $('#pos-search-keyword').bind('keydown', function(e){
  2880. if (e.keyCode == 13) posSearch.searchAndLocate();
  2881. });
  2882. $('#pos-empty-search').click(function () {
  2883. if (this.checked) {
  2884. $('[for=' + this.id +']').addClass('text-warning');
  2885. } else {
  2886. $('[for=' + this.id +']').removeClass('text-warning');
  2887. }
  2888. if (this.checked) {
  2889. if ($('#pos-over-search')[0].checked) {
  2890. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2891. } else {
  2892. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2893. }
  2894. } else {
  2895. if ($('#pos-over-search')[0].checked) {
  2896. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2897. } else {
  2898. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2899. }
  2900. }
  2901. posSearch.searchAndLocate();
  2902. });
  2903. $('#pos-over-search').click(function () {
  2904. if (this.checked) {
  2905. $('[for=' + this.id +']').addClass('text-danger');
  2906. } else {
  2907. $('[for=' + this.id +']').removeClass('text-danger');
  2908. }
  2909. if (this.checked) {
  2910. if ($('#pos-empty-search')[0].checked) {
  2911. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2912. } else {
  2913. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2914. }
  2915. } else {
  2916. if ($('#pos-empty-search')[0].checked) {
  2917. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2918. } else {
  2919. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2920. }
  2921. }
  2922. posSearch.searchAndLocate();
  2923. });
  2924. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2925. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2926. $.divResizer({
  2927. select: '#right-spr',
  2928. callback: function () {
  2929. slSpread.refresh();
  2930. spSpread.refresh();
  2931. if (searchLedger) {
  2932. searchLedger.spread.refresh();
  2933. }
  2934. if (detail) {
  2935. detail.spread.refresh();
  2936. }
  2937. if (checkedChanges) checkedChanges.refresh();
  2938. if (errorList && errorList.spread) errorList.spread.refresh();
  2939. if (checkList) checkList.spread.refresh();
  2940. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2941. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2942. }
  2943. });
  2944. // 中间计量加载上下窗口resizer
  2945. $.divResizer({
  2946. select: '#zhongjian-spr',
  2947. callback: function () {
  2948. if (detail) {
  2949. detail.spread.refresh();
  2950. }
  2951. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2952. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2953. }
  2954. });
  2955. // 附件加载上下窗口resizer
  2956. $.divResizer({
  2957. select: '#file-spr',
  2958. callback: function () {
  2959. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2960. }
  2961. });
  2962. // 变更令加载上下窗口resizer
  2963. $.divResizer({
  2964. select: '#change-spr',
  2965. callback: function () {
  2966. if (checkedChanges) checkedChanges.refresh();
  2967. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2968. }
  2969. });
  2970. class Detail {
  2971. constructor (obj) {
  2972. const self = this;
  2973. this.spreadSetting = {
  2974. cols: [
  2975. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2976. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2977. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2978. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2979. {
  2980. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2981. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2982. },
  2983. {
  2984. title: '附件', colSpan: '1', rowSpan: '1', field: 'attachment', hAlign: 0, width: 60, readOnly: true, cellType: 'imageBtn',
  2985. normalImg: '#rela-file-icon', hoverImg: '#rela-file-hover', getValue: function (data) {
  2986. return data.attachment ? data.attachment.length : 0;
  2987. }
  2988. },
  2989. ],
  2990. headRows: 1,
  2991. emptyRows: 0,
  2992. headRowHeight: [32],
  2993. headColWidth: [30],
  2994. defaultRowHeight: 21,
  2995. headerFont: '12px 微软雅黑',
  2996. font: '12px 微软雅黑',
  2997. readOnly: readOnly,
  2998. selectedBackColor: '#fffacd',
  2999. imageClick: function (data) {
  3000. self.makeAttTable(data);
  3001. $('#im-file').modal('show');
  3002. }
  3003. };
  3004. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  3005. this.sheet = this.spread.getActiveSheet();
  3006. this.spread.options.allowUserDragFill = true;
  3007. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  3008. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3009. this.detailObj = {
  3010. selectionChanged: function (e, info) {
  3011. self.reLoadDetailData();
  3012. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  3013. self.loadLocateInfo();
  3014. }
  3015. },
  3016. editEnded: function(e, info) {
  3017. if (info.sheet.zh_setting) {
  3018. const col = info.sheet.zh_setting.cols[info.col];
  3019. if (col.field !== 'doc_code') {
  3020. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3021. return;
  3022. }
  3023. const data = SpreadJsObj.getSelectObject(info.sheet);
  3024. if (data) {
  3025. const updateData = {lid: data.lid, pid: data.pid};
  3026. if (data.uuid) {
  3027. updateData.uuid = data.uuid;
  3028. } else {
  3029. updateData.code = data.code;
  3030. updateData.name = data.name;
  3031. updateData.unit = data.unit;
  3032. updateData.unit_price = data.unit_price;
  3033. updateData.pid = data.pid;
  3034. updateData.pos_name = data.pos_name;
  3035. updateData.im_type = data.im_type;
  3036. }
  3037. if (data.custom_define.indexOf('doc_code') === -1) {
  3038. updateData.custom_define = data.custom_define;
  3039. updateData.custom_define.push('doc_code');
  3040. updateData.custom_define = updateData.custom_define.join(',');
  3041. }
  3042. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  3043. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3044. stageIm.loadUpdateDetailData(result);
  3045. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3046. }, function () {
  3047. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3048. });
  3049. } else {
  3050. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  3051. }
  3052. }
  3053. },
  3054. clipboardPasted: function (e, info) {
  3055. if (info.sheet.zh_setting && info.sheet.zh_data) {
  3056. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  3057. if (info.cellRange.colCount > 1) {
  3058. toastr.warning('请勿同时复制粘贴多列数据');
  3059. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3060. return;
  3061. }
  3062. if (col.field !== 'doc_code') {
  3063. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  3064. return;
  3065. }
  3066. const datas = [];
  3067. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3068. const curRow = info.cellRange.row + iRow;
  3069. const data = info.sheet.zh_data[curRow];
  3070. if (data) {
  3071. const updateData = {lid: data.lid, pid: data.pid};
  3072. if (data.uuid) {
  3073. updateData.uuid = data.uuid;
  3074. } else {
  3075. updateData.code = data.code;
  3076. updateData.name = data.name;
  3077. updateData.unit = data.unit;
  3078. updateData.unit_price = data.unit_price;
  3079. updateData.pid = data.pid;
  3080. updateData.pos_name = data.pos_name;
  3081. updateData.im_type = data.im_type;
  3082. }
  3083. if (data.custom_define.indexOf('doc_code') === -1) {
  3084. updateData.custom_define = data.custom_define;
  3085. updateData.custom_define.push('doc_code');
  3086. updateData.custom_define = updateData.custom_define.join(',');
  3087. }
  3088. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  3089. datas.push(updateData);
  3090. }
  3091. }
  3092. if (datas.length > 0) {
  3093. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3094. stageIm.loadUpdateDetailData(result);
  3095. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3096. }, function () {
  3097. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3098. })
  3099. }
  3100. }
  3101. },
  3102. deletePress: function (sheet) {
  3103. if (sheet.zh_setting) {
  3104. const datas = [];
  3105. const sel = sheet.getSelections()[0];
  3106. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  3107. const col = sheet.zh_setting.cols[iCol];
  3108. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  3109. const data = sheet.zh_data[iRow];
  3110. if (col.field === 'doc_code') {
  3111. const updateData = {lid: data.lid};
  3112. if (data.uuid) {
  3113. updateData.uuid = data.uuid;
  3114. updateData.doc_code = '';
  3115. datas.push(updateData);
  3116. }
  3117. }
  3118. }
  3119. }
  3120. if (datas.length > 0) {
  3121. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3122. stageIm.loadUpdateDetailData(result);
  3123. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3124. }, function () {
  3125. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  3126. });
  3127. }
  3128. }
  3129. },
  3130. dragFillBlock: function (e, info) {
  3131. info.cancel = true;
  3132. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  3133. const sel = info.sheet.getSelections()[0];
  3134. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  3135. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  3136. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  3137. if (text === '') return;
  3138. const regRst = /(\d+)$/g.exec(text), datas = [];
  3139. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  3140. const curRow = info.fillRange.row + iRow;
  3141. const data = info.sheet.zh_data[curRow];
  3142. if (data) {
  3143. const updateData = {lid: data.lid};
  3144. if (data.uuid) {
  3145. updateData.uuid = data.uuid;
  3146. } else {
  3147. updateData.code = data.code;
  3148. updateData.name = data.name;
  3149. updateData.unit = data.unit;
  3150. updateData.unit_price = data.unit_price;
  3151. updateData.pid = data.pid;
  3152. updateData.pos_name = data.pos_name;
  3153. updateData.im_type = data.im_type;
  3154. }
  3155. if (regRst) {
  3156. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  3157. } else {
  3158. updateData.doc_code = text.replace('\n', '');
  3159. }
  3160. if (data.custom_define.indexOf('doc_code') === -1) {
  3161. updateData.custom_define = data.custom_define;
  3162. updateData.custom_define.push('doc_code');
  3163. updateData.custom_define = updateData.custom_define.join(',');
  3164. }
  3165. datas.push(updateData);
  3166. }
  3167. }
  3168. if (datas.length > 0) {
  3169. postData(window.location.pathname + '/detail/save', datas, function (result) {
  3170. stageIm.loadUpdateDetailData(result);
  3171. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3172. }, function () {
  3173. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  3174. })
  3175. }
  3176. },
  3177. };
  3178. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  3179. if (!readOnly) {
  3180. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  3181. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  3182. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  3183. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  3184. }
  3185. this._initImTypeSetRela();
  3186. this._initModifyDetail();
  3187. this._initLocateRela();
  3188. this._initAttRela();
  3189. // 草图相关
  3190. this._initImageRela();
  3191. this.reBuildImData();
  3192. }
  3193. makeAttTable (data) {
  3194. let html = [];
  3195. if (data.attachment) {
  3196. for (const att of data.attachment) {
  3197. const delHtml = (parseInt(att.uid) === userID && (att.renew || stage.status !== auditConst.status.checked || deleteFilePermission))
  3198. ? '<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>'
  3199. : '';
  3200. const viewHtml = att.viewpath ? `<a class="ml-1" href="${att.viewpath}" target="_blank" title="预览"><i class="fa fa-eye"></i></a>` : '';
  3201. 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>';
  3202. 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>',
  3203. '<td>', downloadHtml, viewHtml, delHtml, '</td></tr>');
  3204. }
  3205. }
  3206. $('#im-attList').html(html.join(''));
  3207. }
  3208. _initAttRela() {
  3209. // 上传附件
  3210. const self = this;
  3211. $('#upload-im-file').change(function () {
  3212. const files = this.files;
  3213. const sels = self.sheet.getSelections();
  3214. const select = SpreadJsObj.getSelectObject(self.sheet);
  3215. if (!select) return;
  3216. const formData = new FormData();
  3217. const baseInfo = {};
  3218. if (select.att_uuid) {
  3219. baseInfo.uuid = select.att_uuid;
  3220. } else {
  3221. baseInfo.im_type = select.im_type;
  3222. baseInfo.lid = select.lid;
  3223. baseInfo.pid = select.pid;
  3224. baseInfo.code = select.code;
  3225. baseInfo.name = select.name;
  3226. baseInfo.unit = select.unit;
  3227. baseInfo.unit_price = select.unit_price;
  3228. baseInfo.pos_name = select.pos_name;
  3229. }
  3230. formData.append('base', JSON.stringify(baseInfo));
  3231. for (const file of files) {
  3232. if (file === undefined) {
  3233. toast('未选择上传文件!', 'error');
  3234. return false;
  3235. }
  3236. const filesize = file.size;
  3237. if (filesize > 30 * 1024 * 1024) {
  3238. toast('存在上传文件大小过大!', 'error');
  3239. return false;
  3240. }
  3241. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3242. if (whiteList.indexOf(fileext) === -1) {
  3243. toast('只能上传指定格式的附件!', 'error');
  3244. return false;
  3245. }
  3246. formData.append('size', filesize);
  3247. formData.append('file[]', file);
  3248. }
  3249. postDataWithFile(window.location.pathname + '/im-file/upload', formData, function (data) {
  3250. stageIm.loadUpdateDetailAtt(data);
  3251. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3252. self.makeAttTable(select);
  3253. $('#upload-im-file').val('');
  3254. });
  3255. });
  3256. // 删除附件
  3257. $('body').on('click', '.delete-att' ,function () {
  3258. const sels = self.sheet.getSelections();
  3259. const select = SpreadJsObj.getSelectObject(self.sheet);
  3260. if (!select) return;
  3261. const uuid = $(this).attr('data-imid');
  3262. const file_id = $(this).attr('data-attid');
  3263. const att = select.attachment.find(x => {
  3264. return x.file_id === file_id;
  3265. });
  3266. deleteAfterHint(function () {
  3267. postData(window.location.pathname + '/im-file/del', { uuid, file_id }, function (result) {
  3268. stageIm.loadUpdateDetailAtt(result);
  3269. SpreadJsObj.reLoadRowData(self.sheet, sels[0].row);
  3270. self.makeAttTable(select);
  3271. });
  3272. }, `确认删除附件「${att.filename}」?`);
  3273. });
  3274. // 预览附件
  3275. $('body').on('click', '.preview-att', function () {
  3276. const uuid = $(this).attr('data-imid');
  3277. const file_id = $(this).attr('data-attid');
  3278. postData(window.location.pathname + `/im-file/preview?uuid=${uuid}&file_id=${file_id}`, {}, function (result) {
  3279. const { filepath } = result;
  3280. $('#load-file').attr('href', filepath);
  3281. $('#load-file')[0].click();
  3282. });
  3283. });
  3284. $('#batch-download-im-file').click(function() {
  3285. const select = $('[name=sia-check]:checked');
  3286. if (select.length === 0) {
  3287. toastr.warning('请选择需要批量下载的文件');
  3288. return;
  3289. }
  3290. const files = [];
  3291. const curIm = SpreadJsObj.getSelectObject(self.sheet);
  3292. for (const s of select) {
  3293. const att = curIm.attachment.find(x => { return x.file_id === s.getAttribute('fid')});
  3294. if (att) files.push(att);
  3295. }
  3296. if (files.length === 0) return;
  3297. AliOss.zipFiles(files, `中间计量[${curIm.code}].zip`, (fails) => {
  3298. $(self).removeAttr('disabled');
  3299. if (fails.length === 0) {
  3300. toastr.success('下载成功');
  3301. } else {
  3302. toastr.warning(`下载成功(${fails.length}个文件下载失败)`);
  3303. }
  3304. }, () => {
  3305. $(self).removeAttr('disabled');
  3306. toastr.error('批量下载失败');
  3307. });
  3308. });
  3309. }
  3310. _initImTypeSetRela() {
  3311. const self = this;
  3312. const gatherConfirmPopover = {
  3313. reBind: function (obj, eventName, fun) {
  3314. obj.unbind(eventName);
  3315. obj.bind(eventName, fun);
  3316. },
  3317. check: function (pos, hint, okCallback) {
  3318. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  3319. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  3320. this.reBind(cancelObj, 'click', function () {
  3321. confirmObj.hide();
  3322. });
  3323. this.reBind(okObj, 'click', function () {
  3324. okCallback();
  3325. confirmObj.hide();
  3326. });
  3327. hintObj.text(hint);
  3328. confirmObj.css("top", pos.y).css("left", pos.x).show();
  3329. }
  3330. };
  3331. this.gsTree = stageIm.getGsTree();
  3332. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3333. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3334. jlCol.title = '本期计量金额';
  3335. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3336. $('[name=type-title-contract]').text('本期合同计量金额');
  3337. $('[name=type-title-qc]').text('本期变更计量金额');
  3338. if ($('#show-qc-minus-jl').length > 0) {
  3339. $('#show-qc-minus-jl').parent().hide();
  3340. $('#qc-minus-jl').parent().hide();
  3341. }
  3342. } else {
  3343. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3344. jlCol.title = '本期计量数量';
  3345. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3346. $('[name=type-title-contract]').text('本期合同计量数量');
  3347. $('[name=type-title-qc]').text('本期变更计量数量');
  3348. if ($('#show-qc-minus-jl').length > 0) {
  3349. $('#show-qc-minus-jl').parent().show();
  3350. $('#qc-minus-jl').parent().show();
  3351. }
  3352. }
  3353. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3354. $('#show-jldy').parent().show();
  3355. $('#jldy').parent().show();
  3356. $('#show-xm-name').parent().hide();
  3357. $('#xm-name').parent().hide();
  3358. } else {
  3359. $('#show-jldy').parent().hide();
  3360. $('#jldy').parent().hide();
  3361. $('#show-xm-name').parent().show();
  3362. $('#xm-name').parent().show();
  3363. }
  3364. // 选择中间计量模式
  3365. $('div[name="im-type"]').click(function () {
  3366. function chooseType(obj) {
  3367. obj.style.cursor = 'default';
  3368. $(obj).children().addClass('text-primary');
  3369. $(obj).addClass('border-primary');
  3370. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3371. }
  3372. function validType(obj) {
  3373. obj.style.cursor = 'pointer';
  3374. $(obj).children().removeClass('text-primary');
  3375. $(obj).removeClass('border-primary');
  3376. $('i', obj).remove();
  3377. }
  3378. if (this.style.cursor === 'pointer') {
  3379. const typeArr = $('div[name="im-type"]');
  3380. for (const t of typeArr) {
  3381. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  3382. chooseType(t);
  3383. } else {
  3384. validType(t)
  3385. }
  3386. }
  3387. }
  3388. });
  3389. $('#choose').on('show.bs.modal', function () {
  3390. function chooseType(obj) {
  3391. obj.style.cursor = 'default';
  3392. $(obj).children().addClass('text-primary');
  3393. $('i', obj).remove();
  3394. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  3395. }
  3396. function validType(obj) {
  3397. obj.style.cursor = 'pointer';
  3398. $(obj).children().removeClass('text-primary');
  3399. $('i', obj).remove();
  3400. }
  3401. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  3402. $('#im-start-num').val(stage.im_start_num ? stage.im_start_num : '');
  3403. const typeArr = $('div[name="im-type"]');
  3404. for (const t of typeArr) {
  3405. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  3406. chooseType(t);
  3407. } else {
  3408. validType(t)
  3409. }
  3410. }
  3411. });
  3412. // 提交 中间计量模式
  3413. $('#choose-ok').click(() => {
  3414. let startNum;
  3415. try {
  3416. startNum = parseInt($('#im-start-num').val());
  3417. if (!startNum || startNum <= 0) throw '起始编号请输入正整数';
  3418. } catch (err) {
  3419. toastr.error("起始编号请输入正整数");
  3420. return;
  3421. }
  3422. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  3423. return it.style.cursor !== 'pointer';
  3424. });
  3425. const data = {
  3426. im_type: parseInt($(chooseType).attr('im-type')),
  3427. im_pre: $('#im-pre').val(),
  3428. im_start_num: startNum,
  3429. };
  3430. postData(window.location.pathname + '/detail/build', data, function (result) {
  3431. stage.im_type = data.im_type;
  3432. stage.im_pre = data.im_pre;
  3433. stage.im_start_num = data.im_start_num;
  3434. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  3435. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3436. jlCol.title = '本期计量金额';
  3437. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3438. $('[name=type-title-contract]').text('本期合同计量金额');
  3439. $('[name=type-title-qc]').text('本期变更计量金额');
  3440. if ($('#show-qc-minus-jl').length > 0) {
  3441. $('#show-qc-minus-jl').parent().hide();
  3442. $('#qc-minus-jl').parent().hide();
  3443. }
  3444. } else {
  3445. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  3446. jlCol.title = '本期计量数量';
  3447. SpreadJsObj.reLoadSheetHeader(self.sheet);
  3448. $('[name=type-title-contract]').text('本期合同计量数量');
  3449. $('[name=type-title-qc]').text('本期变更计量数量');
  3450. if ($('#show-qc-minus-jl').length > 0) {
  3451. $('#show-qc-minus-jl').parent().show();
  3452. $('#qc-minus-jl').parent().show();
  3453. }
  3454. }
  3455. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  3456. $('#show-jldy').parent().show();
  3457. $('#jldy').parent().show();
  3458. $('#show-xm-name').parent().hide();
  3459. $('#xm-name').parent().hide();
  3460. } else {
  3461. $('#show-jldy').parent().hide();
  3462. $('#jldy').parent().hide();
  3463. $('#show-xm-name').parent().show();
  3464. $('#xm-name').parent().show();
  3465. }
  3466. // 加载生成数据
  3467. self.reBuildImData();
  3468. $('#choose').modal('hide');
  3469. });
  3470. });
  3471. // 显示树结构信息
  3472. $('#choose2').on('shown.bs.modal', function () {
  3473. if (!self.gsSpread) {
  3474. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  3475. const setting = {
  3476. cols: [
  3477. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  3478. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  3479. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  3480. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  3481. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  3482. ],
  3483. headRows: 1,
  3484. emptyRows: 0,
  3485. headRowHeight: [32],
  3486. defaultRowHeight: 21,
  3487. headerFont: '12px 微软雅黑',
  3488. font: '12px 微软雅黑',
  3489. };
  3490. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  3491. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  3492. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  3493. function checkParent(node) {
  3494. const parent = self.gsTree.getParent(node);
  3495. if (parent) {
  3496. return parent.check ? parent.check : checkParent(parent);
  3497. } else {
  3498. return false;
  3499. }
  3500. }
  3501. function checkChildren(node) {
  3502. for (const child of node.children) {
  3503. if (child.check) {
  3504. return true;
  3505. } else if (checkChildren(child)) {
  3506. return true;
  3507. }
  3508. }
  3509. return false;
  3510. }
  3511. if (!$('#im-gather-check')[0].checked) { return; }
  3512. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  3513. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  3514. if (sheet.isEditing()) {
  3515. sheet.endEdit(true);
  3516. }
  3517. }
  3518. if (info.sheet.zh_setting) {
  3519. const col = info.sheet.zh_setting.cols[info.col];
  3520. if (col.field !== 'check') {
  3521. return;
  3522. }
  3523. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  3524. const node = sortData[info.row];
  3525. if (!node.check) {
  3526. if (checkParent(node)) {
  3527. const rect = info.sheet.getCellRect(info.row, info.col);
  3528. gatherConfirmPopover.check({
  3529. x: rect.x + rect.width / 2 + 25,
  3530. y: rect.y + rect.height / 2 + 3,
  3531. }, '父项已勾选,继续将取消父项勾选。', function () {
  3532. node.check = true;
  3533. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  3534. const rows = [self.gsTree.nodes.indexOf(node)];
  3535. for (const p of parents) {
  3536. if (p.check) {
  3537. p.check = false;
  3538. rows.push(self.gsTree.nodes.indexOf(p));
  3539. }
  3540. }
  3541. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3542. });
  3543. } else if (checkChildren(node)) {
  3544. const rect = info.sheet.getCellRect(info.row, info.col);
  3545. gatherConfirmPopover.check({
  3546. x: rect.x + rect.width / 2 + 25,
  3547. y: rect.y + rect.height / 2 + 3,
  3548. }, '子项已勾选,继续将取消子项勾选。', function () {
  3549. node.check = true;
  3550. const posterity = self.gsTree.getPosterity(node);
  3551. const rows = [self.gsTree.nodes.indexOf(node)];
  3552. for (const p of posterity) {
  3553. if (p.check) {
  3554. rows.push(self.gsTree.nodes.indexOf(p));
  3555. p.check = false;
  3556. }
  3557. }
  3558. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  3559. });
  3560. } else {
  3561. node.check = true;
  3562. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3563. }
  3564. } else {
  3565. node.check = false;
  3566. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  3567. }
  3568. }
  3569. });
  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.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  3575. self.gsTree.expandByLevel(4);
  3576. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  3577. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  3578. } else {
  3579. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  3580. for (const node of self.gsTree.datas) {
  3581. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  3582. }
  3583. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  3584. }
  3585. });
  3586. // 提交 高级设置
  3587. $('#choose2-ok').click(() => {
  3588. if (!self.gsTree) { return; }
  3589. const nodes = [];
  3590. for (const node of self.gsTree.datas) {
  3591. if (node.check) {
  3592. nodes.push(node.id);
  3593. }
  3594. }
  3595. const data = {
  3596. im_gather: $('#im-gather-check')[0].checked,
  3597. im_gather_node: nodes.join(','),
  3598. };
  3599. postData(window.location.pathname + '/detail/adv', data, function (result) {
  3600. stage.im_gather = data.im_gather;
  3601. stage.im_gather_node = data.im_gather_node;
  3602. $('#choose2').modal('hide');
  3603. });
  3604. });
  3605. }
  3606. _initLocateRela() {
  3607. const self = this;
  3608. $('#im-locate2bills').click(function () {
  3609. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3610. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3611. if (select && select.source) {
  3612. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  3613. stagePosSpreadObj.loadCurPosData();
  3614. if (select.source[curIndex-1].pos_id) {
  3615. SpreadJsObj.locateDataBy(spSpread.getActiveSheet(), function(data){ return data.id === select.source[curIndex-1].pos_id});
  3616. }
  3617. }
  3618. });
  3619. $('#im-locate-pre').click(function () {
  3620. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3621. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3622. if (select && select.source) {
  3623. const targetIndex = Math.max(curIndex-1, 1);
  3624. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3625. stagePosSpreadObj.loadCurPosData();
  3626. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3627. }
  3628. });
  3629. $('#im-locate-next').click(function () {
  3630. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  3631. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3632. if (select && select.source) {
  3633. const targetIndex = Math.min(curIndex+1, select.source.length);
  3634. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  3635. stagePosSpreadObj.loadCurPosData();
  3636. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  3637. }
  3638. });
  3639. }
  3640. _initModifyDetail() {
  3641. const self = this;
  3642. // 重置
  3643. $('#reset-detail-ok').click(function () {
  3644. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3645. if (!data.uuid) return;
  3646. const updateData = {
  3647. lid: data.lid, pid: data.pid,
  3648. uuid: data.uuid,
  3649. custom_define: [],
  3650. };
  3651. for (const f of data.custom_define) {
  3652. if (stageIm.resetFields.indexOf(f) >= 0) {
  3653. updateData[f] = null;
  3654. } else {
  3655. updateData.custom_define.push(f);
  3656. }
  3657. }
  3658. updateData.custom_define = updateData.custom_define.join(',');
  3659. $('#reset-detail-modal').modal('hide');
  3660. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3661. stageIm.loadUpdateDetailData(result);
  3662. self.reLoadDetailData();
  3663. });
  3664. });
  3665. // 编辑
  3666. $('#edit-detail').click(function () {
  3667. $(this).hide();
  3668. $('#save-detail').show();
  3669. $('#cancel-detail').show();
  3670. $('#detail-show').hide();
  3671. $('#detail-edit').show();
  3672. self.updateImageData = null;
  3673. });
  3674. // 保存
  3675. $('#save-detail').click(() => {
  3676. function check(field, obj, org, update) {
  3677. const newValue = obj.val();
  3678. if (!org[field]) {
  3679. if (newValue !== '') {
  3680. update[field] = newValue;
  3681. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3682. return true;
  3683. }
  3684. } else if (newValue !== org[field]){
  3685. update[field] = newValue;
  3686. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  3687. return true;
  3688. }
  3689. return false;
  3690. }
  3691. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3692. const updateData = {lid: data.lid, pid: data.pid};
  3693. if (data.uuid) {
  3694. updateData.uuid = data.uuid;
  3695. updateData.custom_define = data.custom_define;
  3696. } else {
  3697. updateData.code = data.code;
  3698. updateData.name = data.name;
  3699. updateData.unit = data.unit;
  3700. updateData.unit_price = data.unit_price;
  3701. updateData.pid = data.pid;
  3702. updateData.pos_name = data.pos_name;
  3703. updateData.im_type = data.im_type;
  3704. updateData.custom_define = [];
  3705. }
  3706. let infoUpdate = false;
  3707. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  3708. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  3709. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  3710. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  3711. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  3712. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  3713. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  3714. updateData.custom_define = updateData.custom_define.join(',');
  3715. if (infoUpdate) {
  3716. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  3717. stageIm.loadUpdateDetailData(result);
  3718. self.reLoadDetailData();
  3719. if (!self.updateImageData) return;
  3720. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  3721. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3722. stageIm.loadUpdateDetailData(result);
  3723. self.reLoadDetailData();
  3724. });
  3725. });
  3726. } else if (self.updateImageData) {
  3727. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  3728. stageIm.loadUpdateDetailData(result);
  3729. self.reLoadDetailData();
  3730. });
  3731. } else {
  3732. self.reLoadDetailData();
  3733. }
  3734. });
  3735. // 取消
  3736. $('#cancel-detail').click(() => {
  3737. self.reLoadDetailData();
  3738. });
  3739. }
  3740. _initImageRela() {
  3741. const self = this;
  3742. $('#edit-detail').click(function () {
  3743. loadImageItem();
  3744. });
  3745. function setdraggrable(){
  3746. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3747. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3748. stop: function( event, ui ) {
  3749. }
  3750. });
  3751. }
  3752. function upload(formData) {
  3753. if (formData.length < 1) {
  3754. return;
  3755. }
  3756. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3757. const html = [];
  3758. html.push('<div class="img-item">');
  3759. html.push('<div class="img-bar">');
  3760. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3761. html.push('</div>');
  3762. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3763. html.push('</div>');
  3764. $('.img-view').append(html.join(''));
  3765. $('.img-bar').click(removeImageItem);
  3766. setdraggrable();
  3767. $('#upload-img-file').val('');
  3768. });
  3769. }
  3770. function dragFile(e) {
  3771. var file = null,
  3772. data = e.dataTransfer.types;
  3773. for (var i = 0; i < data.length; i += 1) {
  3774. if (data[i] === 'Files') {
  3775. file = e.dataTransfer.files; //获取文件
  3776. break;
  3777. }
  3778. }
  3779. if (file && file[0].type.indexOf('image') !== -1) {
  3780. var formData = new FormData();
  3781. formData.append('file', file[0]); //上传单个文件的添加方式
  3782. upload(formData); //upload 异步上传
  3783. }
  3784. }
  3785. // 移动图片
  3786. const moveImageItem = function (ev) {
  3787. const item = this;
  3788. const view = $('.img-view')[0];
  3789. let oEvent = ev;
  3790. // 浏览器有一些图片的默认事件,这里要阻止
  3791. oEvent.preventDefault();
  3792. let disX = oEvent.clientX - item.offsetLeft;
  3793. let disY = oEvent.clientY - item.offsetTop;
  3794. view.onmousemove = function (ev) {
  3795. oEvent = ev;
  3796. oEvent.preventDefault();
  3797. let x = oEvent.clientX -disX;
  3798. let y = oEvent.clientY -disY;
  3799. // 图形移动的边界判断
  3800. x = x <= 0 ? 0 : x;
  3801. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3802. y = y <= 0 ? 0 : y;
  3803. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3804. item.style.left = x + 'px';
  3805. item.style.top = y + 'px';
  3806. };
  3807. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3808. view.onmouseleave = function () {
  3809. view.onmousemove = null;
  3810. view.onmouseup = null;
  3811. };
  3812. // 鼠标弹起后停止移动
  3813. view.onmouseup=function() {
  3814. view.onmousemove = null;
  3815. view.onmouseup = null;
  3816. };
  3817. };
  3818. const removeImageItem = function () {
  3819. $(this).parent().remove();
  3820. };
  3821. // 加载草图组成
  3822. const loadImageItem = function () {
  3823. self.updateImageData = null;
  3824. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3825. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3826. const html = [];
  3827. for (const item of items) {
  3828. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3829. html.push('<div class="img-item" style="' + itemStyle + '">');
  3830. html.push('<div class="img-bar">');
  3831. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3832. html.push('</div>');
  3833. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3834. html.push('</div>');
  3835. }
  3836. $('.img-view').html(html.join(''));
  3837. $('.img-bar').click(removeImageItem);
  3838. setdraggrable();
  3839. };
  3840. // 上传图片
  3841. $('#upload-img').click(function () {
  3842. $('#upload-img-file').trigger('click');
  3843. });
  3844. // 拖拽上传
  3845. //拖拽上传文件
  3846. const dragbox = document.querySelector('#upload-img');
  3847. dragbox.addEventListener('dragover', function(e) {
  3848. e.preventDefault(); // 必须阻止默认事件
  3849. }, false);
  3850. dragbox.addEventListener('drop', function(e) {
  3851. e.preventDefault(); // 阻止默认事件
  3852. dragFile(e);
  3853. }, false);
  3854. //拖拽上传文件
  3855. const dragbox2 = document.querySelector('.img-view');
  3856. dragbox2.addEventListener('dragover', function(e) {
  3857. e.preventDefault(); // 必须阻止默认事件
  3858. }, false);
  3859. dragbox2.addEventListener('drop', function(e) {
  3860. e.preventDefault(); // 阻止默认事件
  3861. dragFile(e);
  3862. }, false);
  3863. // 粘贴上传
  3864. $(".img-view").on('paste', function(ev) {
  3865. let file = null;
  3866. const data = (event.clipboardData || window.clipboardData).items;
  3867. for (let i = 0; i < data.length; i += 1) {
  3868. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3869. file = data[i].getAsFile(); //读取图片文件
  3870. break;
  3871. }
  3872. }
  3873. if (file) {
  3874. const formData = new FormData();
  3875. formData.append('file', file); //上传单个文件的添加方式
  3876. upload(formData); //异步上传文件
  3877. }
  3878. });
  3879. $('#upload-img-file').change(function () {
  3880. const file = this.files[0];
  3881. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3882. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3883. if (!imgStr.test(ext)) {
  3884. toastr.error('请上传正确的图片格式文件');
  3885. return
  3886. }
  3887. if ($(this).val()) {
  3888. const formData = new FormData();
  3889. formData.append('file', this.files[0]);
  3890. upload(formData);
  3891. }
  3892. });
  3893. // 保存草图修改结果
  3894. $('#edit-img-ok').click(function () {
  3895. // 记录上传的图片的信息
  3896. const items = $('.img-item');
  3897. const img_remark = $('#text-edit').val();
  3898. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3899. // 生成上传数据
  3900. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3901. if (data.uuid) {
  3902. updateData.uuid = data.uuid;
  3903. } else {
  3904. updateData.code = data.code;
  3905. updateData.name = data.name;
  3906. updateData.unit = data.unit;
  3907. updateData.unit_price = data.unit_price;
  3908. updateData.pid = data.pid;
  3909. updateData.pos_name = data.pos_name;
  3910. updateData.im_type = data.im_type;
  3911. }
  3912. if (items.length > 0) {
  3913. const itemInfo = [];
  3914. for (const item of items) {
  3915. const itemData = {
  3916. src: $('img', item).attr('src'),
  3917. left: item.style.left,
  3918. top: item.style.top,
  3919. width: item.style.width,
  3920. height: item.style.height,
  3921. };
  3922. itemInfo.push(itemData);
  3923. }
  3924. // 获取合并好的图片数据
  3925. const canvas = document.createElement('canvas');
  3926. const view = $('.img-view')[0];
  3927. canvas.height = view.clientHeight;
  3928. canvas.width = view.clientWidth;
  3929. const ctx = canvas.getContext('2d');
  3930. ctx.fillStyle = '#ffffff';
  3931. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3932. for (const b of $('.img-item')) {
  3933. const pos = $(b).position();
  3934. const img = $('img', b)[0];
  3935. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3936. }
  3937. updateData.img = canvas.toDataURL('image/png');
  3938. updateData.imgInfo = itemInfo;
  3939. self.updateImageData = updateData;
  3940. $('#calc-img').attr('src', updateData.img);
  3941. $('#calc-remark').html(img_remark);
  3942. $('#view-calc-img').attr('src', updateData.img);
  3943. $('#show-calc-img').attr('src', updateData.img);
  3944. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3945. $('#view-calc-remark').text(img_remark);
  3946. $('#edit-img').modal('hide');
  3947. // });
  3948. } else if (data.calc_img) {
  3949. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3950. $('#show-calc-img').attr('src', '');
  3951. $('#show-calc-remark').html('');
  3952. $('#calc-img').attr('src', '');
  3953. $('#calc-remark').html(img_remark);
  3954. $('#view-calc-img').attr('src', '');
  3955. $('#view-calc-remark').val(img_remark);
  3956. $('#text-edit').val(img_remark);
  3957. $('#edit-img').modal('hide');
  3958. } else {
  3959. self.updateImageData = updateData;
  3960. $('#show-calc-img').attr('src', '');
  3961. $('#show-calc-remark').html('');
  3962. $('#calc-img').attr('src', '');
  3963. $('#calc-remark').html(img_remark);
  3964. $('#view-calc-img').attr('src', '');
  3965. $('#view-calc-remark').val(img_remark);
  3966. $('#text-edit').val(img_remark);
  3967. $('#edit-img').modal('hide');
  3968. }
  3969. });
  3970. }
  3971. reBuildImData() {
  3972. const imData = stageIm.buildImData();
  3973. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3974. this.reLoadDetailData();
  3975. this.loadLocateInfo();
  3976. }
  3977. loadStageLedgerUpdateData(data, nodes) {
  3978. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3979. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3980. this.reLoadDetailData();
  3981. }
  3982. loadStagePosUpdateData(data, nodes) {
  3983. const imData = stageIm.loadUpdatePosData(data, nodes);
  3984. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3985. this.reLoadDetailData();
  3986. }
  3987. loadStageChangeUpdateData(data, nodes) {
  3988. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3989. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3990. this.reLoadDetailData();
  3991. }
  3992. loadLocateInfo() {
  3993. const select = SpreadJsObj.getSelectObject(this.sheet);
  3994. if (select && select.source.length > 1) {
  3995. $('#im-locate2bills').next().show();
  3996. } else {
  3997. $('#im-locate2bills').next().hide();
  3998. }
  3999. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  4000. }
  4001. reLoadDetailData() {
  4002. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  4003. $('#reset-detail').hide();
  4004. if (data) {
  4005. for (const f of data.custom_define) {
  4006. if (stageIm.resetFields.indexOf(f) >= 0) {
  4007. $('#reset-detail').show();
  4008. break;
  4009. }
  4010. }
  4011. $('#edit-detail').show();
  4012. $('#modify-img').show();
  4013. } else {
  4014. $('#edit-detail').hide();
  4015. $('#modify-img').hide();
  4016. }
  4017. $('#save-detail').hide();
  4018. $('#cancel-detail').hide();
  4019. $('#detail-show').show();
  4020. $('#detail-edit').hide();
  4021. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  4022. $('#show-contract-jl').text(contractJl);
  4023. $('#contract-jl').val(contractJl);
  4024. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  4025. $('#show-qc-jl').text(qcJl);
  4026. $('#qc-jl').val(qcJl);
  4027. const qcMinusJl = data && data.qc_minus_jl ? data.qc_minus_jl : '';
  4028. $('#show-qc-minus-jl').text(qcMinusJl);
  4029. $('#qc-minus-jl').val(qcMinusJl);
  4030. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  4031. $('#show-bgl-code').text(bglCode);
  4032. $('#bgl-code').val(bglCode);
  4033. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  4034. $('#show-bgl-drawing-code').text(bglDrawingCode);
  4035. $('#bgl-drawing-code').val(bglDrawingCode);
  4036. const bwName = data && data.bw ? data.bw : '';
  4037. $('#show-bw-name').text(bwName);
  4038. $('#bw-name').val(bwName);
  4039. const position = data && data.position ? data.position : '';
  4040. $('#show-position').text(position);
  4041. $('#position').val(position);
  4042. const peg = data && data.peg ? data.peg : '';
  4043. $('#show-peg').text(peg);
  4044. $('#peg').val(peg);
  4045. const xmName = data && data.xm ? data.xm: '';
  4046. $('#show-xm-name').text(xmName);
  4047. $('#xm-name').val(xmName);
  4048. const jldy = data && data.jldy ? data.jldy: '';
  4049. $('#show-jldy').text(jldy);
  4050. $('#jldy').val(jldy);
  4051. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  4052. $('#show-drawing-code').text(drawingCode);
  4053. $('#drawing-code').val(drawingCode);
  4054. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  4055. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  4056. $('#calc-memo').val(calcMemo);
  4057. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  4058. $('#show-calc-img').attr('src', calcImgSrc);
  4059. $('#calc-img').attr('src', calcImgSrc);
  4060. $('#view-calc-img').attr('src', calcImgSrc);
  4061. const calcImgRemark = data && data.calc_img_remark || '';
  4062. $('#view-calc-remark').val(calcImgRemark);
  4063. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  4064. $('#calc-remark').html(calcImgRemark);
  4065. $("#view-calc-remark").attr('readonly', true);
  4066. // 处理 编辑 -> 添加草图中textarea多余的空格
  4067. $('#text-edit').val(calcImgRemark)
  4068. }
  4069. }
  4070. class CheckedChange {
  4071. constructor (setting) {
  4072. const self = this;
  4073. this.changeSpreadSetting = {
  4074. cols: [
  4075. {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}` : ''; }},
  4076. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  4077. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  4078. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  4079. ],
  4080. emptyRows: 0,
  4081. headRows: 1,
  4082. headRowHeight: [32],
  4083. headColWidth: [30],
  4084. defaultRowHeight: 21,
  4085. headerFont: '12px 微软雅黑',
  4086. font: '12px 微软雅黑',
  4087. readOnly: true,
  4088. getColor: function (sheet, data, row, col, defaultColor) {
  4089. if (data && data.is_import) {
  4090. return '#eee';
  4091. } else {
  4092. return defaultColor;
  4093. }
  4094. }
  4095. };
  4096. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  4097. this.changeSheet = this.changeSpread.getActiveSheet();
  4098. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  4099. const getTipText = function (data) {
  4100. if (!data) return '';
  4101. const tips = [];
  4102. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  4103. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  4104. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  4105. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  4106. return tips.join('-');
  4107. };
  4108. this.changeBillsSpreadSetting = {
  4109. cols: [
  4110. {title: '计价', colSpan: '1', rowSpan: '1', field: 'is_valuation', hAlign: 1, width: 30, cellType: 'checkbox'},
  4111. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  4112. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, cellType: 'delayTip', getTip: getTipText},
  4113. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4114. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  4115. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@'},
  4116. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@'},
  4117. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  4118. ],
  4119. emptyRows: 0,
  4120. headRows: 1,
  4121. headRowHeight: [32],
  4122. defaultRowHeight: 21,
  4123. headerFont: '12px 微软雅黑',
  4124. font: '12px 微软雅黑',
  4125. readOnly: true
  4126. };
  4127. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  4128. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  4129. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  4130. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  4131. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4132. if (change) self.refreshChangeDetailData(change);
  4133. });
  4134. this.changes = null;
  4135. this.reloadChangeData();
  4136. setting.reloadObj.click(function() {
  4137. self.reloadChangeData();
  4138. });
  4139. $.contextMenu({
  4140. selector: '#' + setting.changeBillsObj.attr('id'),
  4141. build: function ($trigger, e) {
  4142. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  4143. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4144. },
  4145. items: {
  4146. 'locateZjjl': {
  4147. name: '定位至台账',
  4148. icon: 'fa-sign-in',
  4149. callback: function (key, opt) {
  4150. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  4151. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4152. if (change.is_import) {
  4153. if (changeBills.pos && changeBills.pos.length > 0) {
  4154. const node = stageTree.getItems(changeBills.pos[0].ledger_id);
  4155. if (!node || node.filter) return;
  4156. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), changeBills.pos[0].ledger_id, true);
  4157. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4158. stagePosSpreadObj.loadCurPosData();
  4159. }
  4160. } else if (changeBills.gcl_id) {
  4161. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4162. if (!node || node.filter) return;
  4163. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id, true);
  4164. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4165. stagePosSpreadObj.loadCurPosData();
  4166. const posData = spSpread.getActiveSheet().zh_data;
  4167. if (!posData || posData.length === 0) return;
  4168. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4169. if (changePos) SpreadJsObj.locateData(spSpread.getActiveSheet(), changePos);
  4170. } else {
  4171. const cb = {
  4172. b_code: changeBills.code || '',
  4173. name: changeBills.name || '',
  4174. unit: changeBills.unit || '',
  4175. unit_price: changeBills.unit_price || 0,
  4176. };
  4177. for (const node of stageTree.nodes) {
  4178. if (node.children && node.children.length > 0) continue;
  4179. if (node.filter) continue;
  4180. const b = {
  4181. b_code: node.b_code || '',
  4182. name: node.name || '',
  4183. unit: node.unit || '',
  4184. unit_price: node.unit_price || 0,
  4185. };
  4186. if (_.isMatch(cb, b)) {
  4187. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  4188. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  4189. stagePosSpreadObj.loadCurPosData();
  4190. return;
  4191. }
  4192. }
  4193. }
  4194. },
  4195. disabled: function (key, opt) {
  4196. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4197. return !changeBills;
  4198. }
  4199. },
  4200. 'autoUse': {
  4201. name: '调用',
  4202. icon: 'fa-play',
  4203. callback: function (key, opt) {
  4204. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4205. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4206. const billsPos = self.findBillsPos(curChange, changeBills);
  4207. if (!billsPos) {
  4208. toastr.warning('无可调用的清单或计量单元');
  4209. return;
  4210. }
  4211. const data = { autoType: 'bills', bills: [{ ...billsPos, cid: changeBills.cid, cbid: changeBills.id }] };
  4212. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4213. if (result.pos) {
  4214. stagePos.loadCurStageData(result.pos.curStageData);
  4215. }
  4216. const nodes = stageTree.loadPostStageData(result.bills);
  4217. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4218. stagePosSpreadObj.loadCurPosData();
  4219. if (detail) {
  4220. detail.loadStageChangeUpdateData(result, nodes);
  4221. } else {
  4222. stageIm.loadUpdateChangeData(result, nodes)
  4223. }
  4224. });
  4225. },
  4226. disabled: function (key, opt) {
  4227. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4228. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4229. return !changeBills || curChange.is_import;
  4230. },
  4231. visible: function (key, opt) {
  4232. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4233. }
  4234. },
  4235. }
  4236. });
  4237. $.contextMenu({
  4238. selector: '#' + setting.changeObj.attr('id'),
  4239. build: function ($trigger, e) {
  4240. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeSpread);
  4241. const change = target.cellTypeHintInfo ? self.changes[target.cellTypeHitInfo.row] : null;
  4242. if (change) self.refreshChangeDetailData(change);
  4243. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4244. },
  4245. items: {
  4246. 'autoUseCur': {
  4247. name: '自动调用',
  4248. icon: 'fa-play',
  4249. callback: function (key, opt) {
  4250. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4251. const changeBills = self.changeBillsSheet.zh_data;
  4252. const data = { bills: [], autoType: 'bills' };
  4253. for (const cb of changeBills) {
  4254. const billsPos = self.findBillsPos(curChange, cb);
  4255. if (billsPos) data.bills.push({ ...billsPos, cid: cb.cid, cbid: cb.id })
  4256. }
  4257. if (data.bills.length === 0) {
  4258. toastr.warning('无可调用的清单或计量单元');
  4259. return;
  4260. }
  4261. postData(window.location.pathname + '/auto-use-change', data, function(result) {
  4262. if (result.pos) {
  4263. stagePos.loadCurStageData(result.pos.curStageData);
  4264. }
  4265. const nodes = stageTree.loadPostStageData(result.bills);
  4266. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  4267. stagePosSpreadObj.loadCurPosData();
  4268. if (detail) {
  4269. detail.loadStageChangeUpdateData(result, nodes);
  4270. } else {
  4271. stageIm.loadUpdateChangeData(result, nodes)
  4272. }
  4273. });
  4274. },
  4275. disabled: function (key, opt) {
  4276. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4277. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  4278. return !curChange || !changeBills || curChange.is_import;
  4279. },
  4280. visible: function (key, opt) {
  4281. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4282. }
  4283. },
  4284. 'autoUseAll': {
  4285. name: '自动调用(全部变更令)',
  4286. icon: 'fa-play',
  4287. callback: function (key, opt) {
  4288. postData(window.location.pathname + '/auto-use-change', { autoType: 'all' }, function(result) {
  4289. window.location.reload();
  4290. });
  4291. },
  4292. disabled: function (key, opt) {
  4293. const curChange = SpreadJsObj.getSelectObject(self.changeSheet);
  4294. return !curChange || curChange.is_import;
  4295. },
  4296. visible: function (key, opt) {
  4297. return stage.status === 1 && stage.isCheckFirst && !stage.assist;
  4298. }
  4299. }
  4300. }
  4301. });
  4302. }
  4303. refreshChangeDetailData(data) {
  4304. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4305. if (change.cid === this.curChangeId) return;
  4306. this.curChangeId = change.cid;
  4307. const self = this;
  4308. if (change.detail) {
  4309. self.loadChangeDetailData();
  4310. } else {
  4311. postData(window.location.pathname + '/change/detail', {cid: change.cid, is_import: change.is_import}, function (result) {
  4312. change.detail = result;
  4313. self.analyzeChange(change);
  4314. self.loadChangeDetailData();
  4315. });
  4316. }
  4317. }
  4318. loadChangeDetailData(data) {
  4319. const change = data || SpreadJsObj.getSelectObject(this.changeSheet);
  4320. if (change) {
  4321. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  4322. } else {
  4323. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  4324. }
  4325. }
  4326. refresh() {
  4327. this.changeSpread.refresh();
  4328. this.changeBillsSpread.refresh();
  4329. }
  4330. reloadChangeData() {
  4331. const self = this;
  4332. postData(window.location.pathname + '/change/data', null, function (result) {
  4333. self.changes = [];
  4334. result.changes.forEach(x => { x.is_import = 0; self.changes.push(x); });
  4335. result.import_changes.forEach(x => { x.is_import = 1; delete x.total_price; self.changes.push(x); });
  4336. if (result.changes.length > 0) self.analyzeChange(result.changes[0]);
  4337. if (result.import_changes.length > 0) self.analyzeChange(result.import_changes[0]);
  4338. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  4339. self.changeSheet.setSelection(0, 0, 1, 1);
  4340. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  4341. self.loadChangeDetailData();
  4342. });
  4343. }
  4344. _analyzeCommon(change) {
  4345. for (const b of change.bills) {
  4346. const eub = change.detail.endUsedBills.find(function (x) {
  4347. return x.cbid === b.id;
  4348. });
  4349. if (eub) b.used_qty = eub.qty;
  4350. b.qty = _.toNumber(b.samount);
  4351. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  4352. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4353. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  4354. b.cur_qty = 0;
  4355. for (const p of b.pos) {
  4356. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  4357. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  4358. }
  4359. }
  4360. }
  4361. _analyzeImport(change) {
  4362. for (const b of change.bills) {
  4363. const eub = change.detail.endUsedBills.find(function (x) {
  4364. return x.rela_cbid === b.id;
  4365. });
  4366. if (eub) b.used_qty = eub.rela_qty;
  4367. b.qty = _.toNumber(b.samount);
  4368. delete b.unit_price;
  4369. // b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  4370. b.pos = _.filter(change.detail.curUsedBills, { rela_cbid: b.id });
  4371. b.cur_qty = 0;
  4372. for (const p of b.pos) {
  4373. p.qty = p.rela_qty;
  4374. const node = stageTree.datas.find(x => { return x.id === p.lid; });
  4375. p.ledger_id = node.ledger_id;
  4376. p.f_qty = node.quantity;
  4377. b.cur_qty = ZhCalc.add(b.cur_qty, p.rela_qty);
  4378. }
  4379. }
  4380. }
  4381. analyzeChange(change) {
  4382. change.bills = change.detail.bills;
  4383. if (change.is_import) {
  4384. this._analyzeImport(change);
  4385. } else {
  4386. this._analyzeCommon(change);
  4387. }
  4388. }
  4389. findBillsPos(change, changeBills) {
  4390. if (change.is_import) {
  4391. return null;
  4392. } else if (changeBills.gcl_id) {
  4393. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  4394. if (node.filter) return null;
  4395. if (node.settle_status === settleStatus.finish) return null;
  4396. posData = stagePos.getLedgerPos(node.id) || [];
  4397. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  4398. if (changePos && changePos.settle_status) return null;
  4399. let defaultPos;
  4400. if (posData.length > 0) {
  4401. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4402. if (!defaultPos) return null;
  4403. } else {
  4404. defaultPos = { id: '-1' };
  4405. }
  4406. return { lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
  4407. } else {
  4408. const cb = {
  4409. b_code: changeBills.code || '',
  4410. name: changeBills.name || '',
  4411. unit: changeBills.unit || '',
  4412. unit_price: changeBills.unit_price || 0,
  4413. };
  4414. for (const node of stageTree.nodes) {
  4415. if (node.children && node.children.length > 0) continue;
  4416. if (node.filter) continue;
  4417. if (node.settle_status === settleStatus.finish) continue;
  4418. const b = {
  4419. b_code: node.b_code || '',
  4420. name: node.name || '',
  4421. unit: node.unit || '',
  4422. unit_price: node.unit_price || 0,
  4423. };
  4424. if (_.isMatch(cb, b)) {
  4425. posData = stagePos.getLedgerPos(node.id) || [];
  4426. let defaultPos;
  4427. if (posData.length > 0) {
  4428. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  4429. if (!defaultPos) return null;
  4430. } else {
  4431. defaultPos = { id: '-1' };
  4432. }
  4433. return { lid: node.id, pid: defaultPos.id };
  4434. }
  4435. }
  4436. return null;
  4437. }
  4438. }
  4439. }
  4440. // 展开收起附件
  4441. $('a', '.right-nav').bind('click', function () {
  4442. //const main = $('#main-view'), tool = $('#tools-view');
  4443. const tab = $(this), tabPanel = $(tab.attr('content'));
  4444. if (!tab.hasClass('active')) {
  4445. $('a', '.side-menu').removeClass('active');
  4446. $('.tab-content .tab-select-show').removeClass('active');
  4447. tab.addClass('active');
  4448. tabPanel.addClass('active');
  4449. showSideTools(tab.hasClass('active'));
  4450. if (tab.attr('content') === '#search' && !searchLedger) {
  4451. searchLedger = $.billsSearch({
  4452. selector: '#search',
  4453. searchSpread: slSpread,
  4454. searchOver: true,
  4455. searchEmpty: true,
  4456. resultSpreadSetting: {
  4457. cols: [
  4458. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4459. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4460. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4461. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4462. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4463. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4464. {title: '完成率(%)', field: completePerField, hAlign: 2, width: 70},
  4465. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4466. ],
  4467. emptyRows: 0,
  4468. headRows: 1,
  4469. headRowHeight: [32],
  4470. headColWidth: [30],
  4471. defaultRowHeight: 21,
  4472. headerFont: '12px 微软雅黑',
  4473. font: '12px 微软雅黑',
  4474. selectedBackColor: '#fffacd',
  4475. readOnly: true,
  4476. },
  4477. afterLocated: function () {
  4478. stagePosSpreadObj.loadCurPosData();
  4479. },
  4480. customSearch: [
  4481. {
  4482. key: 'less', title: '漏计', valid: true,
  4483. check: function (node) {
  4484. if (node.quantity) {
  4485. return ZhCalc.sub(ZhCalc.sum([node.quantity, node.end_qc_qty, node.end_qc_minus_qty]), node.end_gather_qty) > 0;
  4486. } else if (node.total_price) {
  4487. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  4488. }
  4489. }
  4490. }, {
  4491. key: 'over', title: '超计', valid: true,
  4492. check: function (node) {
  4493. return checkUtils.billsOver(node, stagePos, tenderInfo.checkOverInfo);
  4494. }
  4495. }, {
  4496. key: 'empty', title: '漏计', valid: false,
  4497. check: function (node) {
  4498. if (node.quantity) {
  4499. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  4500. } else if (node.total_price) {
  4501. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  4502. }
  4503. }
  4504. }, {
  4505. key: 'estimate', title: '预计变更', valid: true,
  4506. check: function (node) {
  4507. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  4508. if (posRange.length > 0) {
  4509. for (const p of posRange) {
  4510. if (!checkZero(p.estimate_qty)) return true;
  4511. }
  4512. return false;
  4513. } else {
  4514. return false;
  4515. }
  4516. }
  4517. }
  4518. ],
  4519. });
  4520. searchLedger.spread.refresh();
  4521. }
  4522. if (tab.attr('content') === '#fujian') {
  4523. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4524. node && getNodeList(node.id);
  4525. }
  4526. if (tab.attr('content') === '#zhongjian') {
  4527. if (!detail) {
  4528. detail = new Detail($('#detail-spread'));
  4529. detail.spread.refresh();
  4530. $('#zhongjian .sjs-bottom').height('400px');
  4531. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  4532. } else {
  4533. detail.spread.refresh();
  4534. }
  4535. }
  4536. if (tab.attr('content') === '#checked-change') {
  4537. if (!checkedChanges) {
  4538. checkedChanges = new CheckedChange({
  4539. changeObj: $('#cc-spread'),
  4540. changeBillsObj: $('#ccb-spread'),
  4541. reloadObj: $('#refresh-cc'),
  4542. });
  4543. checkedChanges.refresh();
  4544. } else {
  4545. $('#ccb-spread').height('400px');
  4546. checkedChanges.refresh();
  4547. }
  4548. }
  4549. if (tab.attr('content') === '#error-list') {
  4550. errorList.spread.refresh();
  4551. }
  4552. if (tab.attr('content') === '#check-list') {
  4553. checkList.spread.refresh();
  4554. }
  4555. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  4556. } else {
  4557. tab.removeClass('active');
  4558. tabPanel.removeClass('active');
  4559. showSideTools(tab.hasClass('active'));
  4560. }
  4561. slSpread.refresh();
  4562. spSpread.refresh();
  4563. });
  4564. // 切换附件里节点和所有附件
  4565. $('#fujian .nav-link').on('click', function () {
  4566. const tabPanel = $(this).attr('fujian-content');
  4567. if (tabPanel !== 'syfujian') {
  4568. $('#showPage').hide();
  4569. $('#bach-download').prop('type', 'curr');
  4570. } else {
  4571. $('#showPage').show();
  4572. $('#bach-download').prop('type', 'all')
  4573. }
  4574. $('#showAttachment').hide();
  4575. });
  4576. // 上传附件
  4577. $('#upload-file-btn').click(function () {
  4578. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4579. if (!node) return
  4580. const files = $('#upload-file')[0].files;
  4581. const formData = new FormData();
  4582. formData.append('lid', node.id);
  4583. for (const file of files) {
  4584. if (file === undefined) {
  4585. toastr.error('未选择上传文件!');
  4586. return false;
  4587. }
  4588. const filesize = file.size;
  4589. if (filesize > 30 * 1024 * 1024) {
  4590. toastr.error('存在上传文件大小过大!');
  4591. return false;
  4592. }
  4593. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  4594. if (whiteList.indexOf(fileext) === -1) {
  4595. toastr.error('只能上传指定格式的附件!');
  4596. return false;
  4597. }
  4598. formData.append('size', filesize);
  4599. formData.append('file[]', file);
  4600. }
  4601. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  4602. $('#upload').modal('hide');
  4603. // 插入到attData中
  4604. attData = data.concat(attData);
  4605. // 重新生成List
  4606. getAllList();
  4607. getNodeList(node.id);
  4608. }, function () {
  4609. toastr.error('附件上传失败');
  4610. });
  4611. $('#upload-file').val('');
  4612. });
  4613. // 获取附件信息
  4614. $('.list-table').on('click', '.att-file-name', function () {
  4615. const fid = $(this).attr('file-id');
  4616. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  4617. return;
  4618. }
  4619. const att = attData.find(function (item) {
  4620. return item.id === parseInt(fid);
  4621. });
  4622. $('#edit-att').hide();
  4623. $('#show-att').show();
  4624. if (att !== undefined) {
  4625. // 进来先把编辑功能隐藏
  4626. $('#btn-att a').eq(3).hide()
  4627. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  4628. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4629. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  4630. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  4631. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  4632. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  4633. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  4634. $('#show-att tr').eq(3).children('td').text(att.remark);
  4635. // 附件uid等于当前用户id, 附件上传本人
  4636. if (parseInt(cur_uid) === att.uid) {
  4637. $('#btn-att').show();
  4638. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  4639. if (showDel) $('#btn-att a').eq(3).show();
  4640. // $('#btn-att a').eq(3).show();
  4641. $('#btn-att a').eq(2).hide();
  4642. $('#btn-att a').eq(4).hide();
  4643. $('#btn-att a').eq(5).hide();
  4644. } else {
  4645. $('#btn-att').hide();
  4646. $('#btn-att a').eq(3).hide();
  4647. $('#btn-att a').eq(2).hide();
  4648. $('#btn-att a').eq(4).hide();
  4649. $('#btn-att a').eq(5).hide();
  4650. }
  4651. $('#showAttachment').attr('file-id', fid);
  4652. $('#showAttachment').show();
  4653. } else {
  4654. $('#showAttachment').hide();
  4655. $('#showAttachment').attr('file-id', '');
  4656. toastr.error('附件信息获取失败');
  4657. }
  4658. });
  4659. // $('body').on('click', '.alllist-table a', handleFileList);
  4660. $('body').on('click', '#btn-att a', function () {
  4661. const content = $(this).attr('content');
  4662. const fid = $('#showAttachment').attr('file-id');
  4663. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  4664. if (content === 'edit') {
  4665. $('#btn-att a').eq(3).hide();
  4666. $('#btn-att a').eq(2).show();
  4667. $('#btn-att a').eq(4).show();
  4668. $('#btn-att a').eq(5).show();
  4669. $('#show-att').hide();
  4670. $('#edit-att').show();
  4671. const att = attData.find(function (item) {
  4672. return item.id === parseInt(fid);
  4673. });
  4674. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  4675. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  4676. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  4677. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  4678. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  4679. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  4680. } else if (content === 'cancel') {
  4681. $('#show-att').show();
  4682. $('#edit-att').hide();
  4683. $('#btn-att a').eq(3).show();
  4684. $('#btn-att a').eq(2).hide();
  4685. $('#btn-att a').eq(4).hide();
  4686. $('#btn-att a').eq(5).hide();
  4687. } else if (content === 'save') {
  4688. const formData = new FormData();
  4689. formData.append('id', fid);
  4690. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  4691. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  4692. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  4693. const file = $('#change-att-btn')[0];
  4694. if (file.files[0] !== undefined) {
  4695. const filesize = file.files[0].size;
  4696. formData.append('size', filesize);
  4697. formData.append('file', file.files[0]);
  4698. }
  4699. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  4700. // 替换到attData中
  4701. const att_index = attData.findIndex(function (item) {
  4702. return item.id === parseInt(fid);
  4703. });
  4704. attData.splice(att_index, 1, data);
  4705. // 重新生成List
  4706. getAllList(parseInt($('#currentPage').text()));
  4707. getNodeList(node.id);
  4708. $('#show-att').show();
  4709. $('#edit-att').hide();
  4710. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  4711. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  4712. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  4713. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  4714. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  4715. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  4716. $('#show-att tr').eq(4).children('td').text(data.remark);
  4717. $('#btn-att a').eq(3).show();
  4718. $('#btn-att a').eq(2).hide();
  4719. $('#btn-att a').eq(4).hide();
  4720. $('#btn-att a').eq(5).hide();
  4721. }, function () {
  4722. toastr.error('附件上传失败');
  4723. });
  4724. $('#change-att-btn').val('');
  4725. } else if (content === 'del') {
  4726. const data = {id: fid};
  4727. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  4728. // 删除到attData中
  4729. const att_index = attData.findIndex(function (item) {
  4730. return item.id === parseInt(fid);
  4731. });
  4732. attData.splice(att_index, 1);
  4733. // 重新生成List
  4734. if ($('#alllist-table tr').length === 1) {
  4735. getAllList(parseInt($('#currentPage').text()) - 1);
  4736. } else {
  4737. getAllList(parseInt($('#currentPage').text()));
  4738. }
  4739. getNodeList(node.id);
  4740. $('#showAttachment').hide();
  4741. $('#showAttachment').attr('file-id', '');
  4742. });
  4743. } else if (content === 'view') {
  4744. const data = {id: fid};
  4745. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  4746. const { filepath } = result
  4747. $('#load-file').attr('href', filepath);
  4748. $('#load-file')[0].click();
  4749. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  4750. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  4751. });
  4752. } else if (content === 'location') {
  4753. const att = attData.find(item => item.id === parseInt(fid));
  4754. if (Object.keys(att).length) {
  4755. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  4756. stagePosSpreadObj.loadCurPosData();
  4757. }
  4758. }
  4759. });
  4760. // 替换附件
  4761. $('#change-att-btn').on('change', function () {
  4762. const file = $('#change-att-btn')[0].files[0];
  4763. const name = file.name;
  4764. const filename = name.substring(0, name.lastIndexOf("."));
  4765. const fileext = name.substr(name.indexOf("."));
  4766. const filesize = file.size;
  4767. if (filesize > 30 * 1024 * 1024) {
  4768. toastr.error('文件大小过大!');
  4769. $('#change-att-btn').val('');
  4770. return false;
  4771. }
  4772. if (whiteList.indexOf(fileext) === -1) {
  4773. toastr.error('只能上传指定格式的附件!');
  4774. $('#change-att-btn').val('');
  4775. return false;
  4776. }
  4777. $('#edit-att .form-group').eq(0).find('input').val(filename);
  4778. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  4779. });
  4780. // 切换页数
  4781. $('.page-select').on('click', function () {
  4782. const totalPageNum = parseInt($('#totalPage').text());
  4783. const lastPageNum = parseInt($('#currentPage').text());
  4784. const status = $(this).attr('content');
  4785. if (status === 'pre' && lastPageNum > 1) {
  4786. getAllList(lastPageNum-1);
  4787. $('#showAttachment').hide();
  4788. $('#syfujian .check-all-file').prop('checked', false)
  4789. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4790. getAllList(lastPageNum+1);
  4791. $('#showAttachment').hide();
  4792. $('#syfujian .check-all-file').prop('checked', false)
  4793. }
  4794. });
  4795. // 批量下载
  4796. $('#bach-download').click(function() {
  4797. const fileIds = [];
  4798. const type = $(this).attr('type');
  4799. let node = ''
  4800. if (type === 'curr') {
  4801. node = '#nodelist-table .check-file:checked'
  4802. } else {
  4803. node = '#alllist-table .check-file:checked'
  4804. }
  4805. $(node).each(function() {
  4806. const fileId = $(this).attr('file-id');
  4807. fileId && fileIds.push(fileId);
  4808. });
  4809. if (fileIds.length) {
  4810. if (fileIds.length > 20) {
  4811. return toastr.warning(`最大允许20个文件(当前${fileIds.length}个)`)
  4812. }
  4813. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  4814. $(this).attr('disabled', "true")
  4815. const btn = $(this);
  4816. const fileArr = [];
  4817. for (const id of fileIds) {
  4818. const fileInfo = _.find(currPageFileData, { id: parseInt(id) });
  4819. fileArr.push({
  4820. url: fileInfo.orginpath, //文件的oss存储路径 (必填)
  4821. name: fileInfo.filename, // 文件名 (可选, 不需要填扩展名)
  4822. foldPath: '' // (可选, 文件在压缩包中的存储路径)
  4823. });
  4824. }
  4825. const packageName = `${tender.name}-计量台账-第${stage.order}期-附件.zip`;
  4826. try {
  4827. zipOss.downloadFromAliOss(fileArr, packageName, btn);
  4828. } catch (e) {
  4829. btn.removeAttr('disabled');
  4830. toastr.clear();
  4831. toastr.error('批量下载失败');
  4832. }
  4833. // postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  4834. // toastr.clear()
  4835. // toastr.success('压缩文件成功')
  4836. // btn.removeAttr('disabled')
  4837. // const href = window.URL.createObjectURL(result)
  4838. // $('#zipDown').attr('href', href);
  4839. // $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  4840. // $("#zipDown")[0].click();
  4841. // }, () => {
  4842. // btn.removeAttr('disabled')
  4843. // toastr.clear()
  4844. // toastr.error('批量下载失败')
  4845. // });
  4846. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  4847. // $('#zipDown').attr('href', url);
  4848. // $("#zipDown")[0].click();
  4849. }
  4850. });
  4851. // 监听附件check是否选中
  4852. $('.list-table').on('click', '.check-file', function() {
  4853. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  4854. const childs = $(this).parents('.list-table').children().length;
  4855. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  4856. if (checkedList.length === childs) {
  4857. checkBox.prop("checked", true);
  4858. } else {
  4859. checkBox.prop("checked", false);
  4860. }
  4861. });
  4862. $('.check-all-file').click(function() {
  4863. const isCheck = $(this).is(':checked');
  4864. $(this).parents('table').find('.list-table').each(function() {
  4865. $(this).find('input:checkbox').prop("checked", isCheck);
  4866. })
  4867. });
  4868. // 显示层次
  4869. (function (select, sheet) {
  4870. $(select).click(function () {
  4871. if (!sheet.zh_tree) return;
  4872. const tag = $(this).attr('tag');
  4873. const tree = sheet.zh_tree;
  4874. setTimeout(() => {
  4875. showWaitingView();
  4876. switch (tag) {
  4877. case "1":
  4878. case "2":
  4879. case "3":
  4880. case "4":
  4881. case "5":
  4882. tree.expandByLevel(parseInt(tag));
  4883. SpreadJsObj.refreshTreeRowVisible(sheet);
  4884. break;
  4885. case "last":
  4886. tree.expandByCustom(() => { return true; });
  4887. SpreadJsObj.refreshTreeRowVisible(sheet);
  4888. break;
  4889. case "leafXmj":
  4890. tree.expandToLeafXmj();
  4891. SpreadJsObj.refreshTreeRowVisible(sheet);
  4892. break;
  4893. case "curMeasure":
  4894. tree.expandByCustom(function (node) {
  4895. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  4896. if (node[field]) {
  4897. return true;
  4898. }
  4899. }
  4900. return false;
  4901. });
  4902. SpreadJsObj.refreshTreeRowVisible(sheet);
  4903. break;
  4904. case "endMeasure":
  4905. tree.expandByCustom(function (node) {
  4906. 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']) {
  4907. if (node[field]) {
  4908. return true;
  4909. }
  4910. }
  4911. return false;
  4912. });
  4913. SpreadJsObj.refreshTreeRowVisible(sheet);
  4914. break;
  4915. }
  4916. closeWaitingView();
  4917. }, 100);
  4918. });
  4919. })('a[name=showLevel]', slSpread.getActiveSheet());
  4920. const stageCheckerSetting = {
  4921. ledgerTree: stageTree,
  4922. ledgerPos: stagePos,
  4923. checkList: checkList,
  4924. decimal: tenderInfo.decimal,
  4925. checkOption: checkOption,
  4926. };
  4927. if (!checkTzMeasureType()) {
  4928. stageCheckerSetting.checkOption.tp.fields.push(
  4929. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  4930. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  4931. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  4932. {qty: 'quantity', tp: 'total_price'},
  4933. );
  4934. }
  4935. $('#ledger-check2').click(() => {
  4936. ledgerCheck2(stageCheckerSetting).then(result => {
  4937. check2Viewing({
  4938. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  4939. randomWait: true,
  4940. prefix: 'check2-',
  4941. checks: result,
  4942. checkList: checkList,
  4943. });
  4944. });
  4945. });
  4946. const dataChecker = DataChecker({
  4947. checkUrl: window.location.pathname + '/check',
  4948. completeData: function (data) {
  4949. stagePos.updateDatas({pos: data.source.pos});
  4950. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4951. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4952. stagePosSpreadObj.loadCurPosData();
  4953. for (const e of data.error) {
  4954. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4955. }
  4956. },
  4957. errorList: errorList,
  4958. });
  4959. $('[name=stage-start]').submit(function (e) {
  4960. if (checkAuditorFrom()) {
  4961. // 再检查多人协同确认情况
  4962. const list = stage.relaAssists.find(x => {return !x.confirm });
  4963. if(list) {
  4964. toastr.error('请检查多人协同确认情况再上报');
  4965. $('#hide-all').hide();
  4966. return false;
  4967. }
  4968. $(this).parent().parent().parent().modal('hide');
  4969. dataChecker.checkAndPost(this.action, {});
  4970. $('#hide-all').hide();
  4971. }
  4972. return false;
  4973. });
  4974. $('#audit-check0').submit(function (e) {
  4975. // 再检查多人协同确认情况
  4976. const list = stage.relaAssists.find(x => {return !x.confirm && stageAssistRela.checkAssistPartUsed(x) });
  4977. if(list) {
  4978. toastr.error('请检查多人协同确认情况再审批通过');
  4979. $('#hide-all').hide();
  4980. return false;
  4981. }
  4982. const checkType = parseInt($('[name=checkType]').val());
  4983. const noUsed = stage.relaAssists.filter(x => {return !stageAssistRela.checkAssistPartUsed(x) });
  4984. const data = {
  4985. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4986. coop_noUsed: noUsed && noUsed.length > 0 ? noUsed.map(x => { return x.ass_ledger_id; }) : [],
  4987. checkType,
  4988. };
  4989. $('#sp-done').modal('hide');
  4990. checkType && dataChecker.checkAndPost(this.action, data);
  4991. $('#hide-all').hide();
  4992. return false;
  4993. });
  4994. $('#audit-check1').submit(function (e) {
  4995. const checkType = parseInt($('[name=checkType]:checked').val());
  4996. const confirm = stage.relaAssists.filter(x => { return x.confirm });
  4997. const data = {
  4998. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4999. coop_checked: confirm && confirm.length > 0 ? confirm.map(x => { return x.id; }) : [],
  5000. checkType,
  5001. };
  5002. if ($('#warning-text').length) $('#warning-text').remove();
  5003. if (!checkType && !$('#warning-text').length) {
  5004. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  5005. return false
  5006. }
  5007. $('#sp-back').modal('hide');
  5008. checkType && dataChecker.checkAndPost(this.action, data);
  5009. $('#hide-all').hide();
  5010. return false;
  5011. });
  5012. $('#exportExcel').click(function () {
  5013. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  5014. });
  5015. $('#cbr-check-all').click(function () {
  5016. if (this.checked) {
  5017. $('input', '#cbr-pos-list').attr('checked', 'checked');
  5018. } else {
  5019. $('input', '#cbr-pos-list').removeAttr('checked');
  5020. }
  5021. });
  5022. $('#cbr-ok').click(() => {
  5023. const ratio = parseInt($('#cbr-ratio').val());
  5024. if (!ratio) {
  5025. toastr.warning('请输入计量比例');
  5026. return;
  5027. } else if (ratio < 1) {
  5028. toastr.warning('计量比例不可小于1');
  5029. return;
  5030. } else if (ratio > 100) {
  5031. toastr.warning('计量比例不可大于100');
  5032. return;
  5033. }
  5034. const apply2sibling = $('#apply2sibling')[0].checked;
  5035. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  5036. if (posName.length === 0) {
  5037. toastr.warning('请勾选需要按计量比例的计量单元');
  5038. return;
  5039. }
  5040. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  5041. });
  5042. // 收方单生成
  5043. $('#setshoufang').click(function () {
  5044. const lid = $('#shoufang-lid').val();
  5045. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  5046. // 修改线上
  5047. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  5048. // 收方单tab打开并显示在最新
  5049. if (!$('#shoufang-tab').hasClass('active')) {
  5050. $('#shoufang-tab').click();
  5051. }
  5052. const data = makeOneShouFang(result);
  5053. data.filenum = 0;
  5054. sfData = _.concat(data, sfData);
  5055. getShouFangList();
  5056. });
  5057. });
  5058. $('body').on('click', '.del-shoufang', function () {
  5059. const id = $(this).attr('data-id');
  5060. $('#del-shoufang-id').val(id);
  5061. const name = $(this).parents('tr').children('td').eq(0).text();
  5062. const ledger_code = name.split(' / ')[0];
  5063. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  5064. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  5065. if (pos_name) {
  5066. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  5067. } else {
  5068. $('#del-shoufang-pos').text('').hide();
  5069. }
  5070. });
  5071. // 收方单删除
  5072. $('#delshoufang').click(function () {
  5073. const sfid = $('#del-shoufang-id').val();
  5074. // 修改线上
  5075. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  5076. // 删除到sfData中
  5077. const att_index = sfData.findIndex(function (item) {
  5078. return item.id === parseInt(sfid);
  5079. });
  5080. sfData.splice(att_index, 1);
  5081. // 重新生成List
  5082. if ($('#shoufang-table tr').length === 1) {
  5083. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  5084. } else {
  5085. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  5086. }
  5087. $('#shoufangdelete').modal('hide');
  5088. });
  5089. });
  5090. // 切换页数
  5091. $('.shoufang-page-select').on('click', function () {
  5092. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  5093. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  5094. const status = $(this).attr('content');
  5095. if (status === 'pre' && lastPageNum > 1) {
  5096. getShouFangList(lastPageNum-1);
  5097. } else if (status === 'next' && lastPageNum < totalPageNum) {
  5098. getShouFangList(lastPageNum+1);
  5099. }
  5100. });
  5101. // 获取单个收方单附件列表
  5102. $('body').on('click', '.show-shoufang-att', function () {
  5103. const id = parseInt($(this).attr('data-id'));
  5104. let html = '';
  5105. $('#shoufang-flie-list').html(html);
  5106. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  5107. for (const att of result) {
  5108. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  5109. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  5110. `<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>`;
  5111. }
  5112. $('#shoufang-flie-list').html(html);
  5113. $('[data-toggle="tooltip"]').tooltip()
  5114. });
  5115. function makeViewHtml(viewpath) {
  5116. 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>` : '';
  5117. }
  5118. function makeDelHtml(fid, extra_upload) {
  5119. return sfAttDelPower &&
  5120. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5121. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att pull-right text-danger mr-2">' +
  5122. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5123. }
  5124. });
  5125. function makeEditHtml(fid, filename, fileext, extra_upload) {
  5126. return sfAttDelPower &&
  5127. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5128. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  5129. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  5130. }
  5131. // 修改收方单附件文件名
  5132. $('body').on('click', '.edit-shoufang-att', function () {
  5133. $(this).children('i').tooltip('hide');
  5134. const fid = $(this).data('id');
  5135. const filename = $(this).data('filename');
  5136. const fileext = $(this).data('fileext');
  5137. const html = `<div class="input-group input-group-sm">
  5138. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  5139. <div class="input-group-append" id="button-${fid}">
  5140. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  5141. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  5142. </div>
  5143. </div>`;
  5144. $(this).parents('td').html(html);
  5145. });
  5146. // 确认修改文件名
  5147. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  5148. const validText = $.trim($(this).parents('td').find('input').val());
  5149. const orgValue = $.trim($(this).data('filename'));
  5150. const fileext = $(this).data('fileext');
  5151. const fid = $(this).data('fid');
  5152. if (!validText) {
  5153. toastr.error('文件名不能为空');
  5154. return;
  5155. }
  5156. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  5157. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  5158. toastr.error('文件名中不能包含.字符和空格');
  5159. return;
  5160. }
  5161. if(validText == orgValue) {
  5162. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  5163. $(this).parents('td').html(html);
  5164. return;
  5165. }
  5166. const data = {
  5167. id: fid,
  5168. filename: validText,
  5169. };
  5170. const _self = $(this);
  5171. postData('/wap/shoufang/editfile', data, function (result) {
  5172. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  5173. _self.parents('td').html(html);
  5174. });
  5175. });
  5176. // 取消修改文件名
  5177. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  5178. const fid = $(this).data('fid');
  5179. const filename = $(this).data('filename');
  5180. const fileext = $(this).data('fileext');
  5181. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  5182. $(this).parents('td').html(html);
  5183. });
  5184. // 删除收方单附件
  5185. $('body').on('click', '.del-shoufang-att', function () {
  5186. const id = $(this).data('id');
  5187. const _self = $(this);
  5188. const data = { id };
  5189. const sfid = $(this).data('sfid');
  5190. postData('/wap/shoufang/delfile', data, function (result) {
  5191. _self.parents('tr').remove();
  5192. // 附件个数更新
  5193. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  5194. const sfInfo = _.find(sfData, { id: sfid });
  5195. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  5196. });
  5197. });
  5198. // 定位到对应的清单或计量单元
  5199. $('body').on('click', '.show-shoufang-node', function () {
  5200. const id = parseInt($(this).attr('data-id'));
  5201. const sfInfo = _.find(sfData, { id });
  5202. if (sfInfo) {
  5203. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5204. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  5205. stagePosSpreadObj.loadCurPosData();
  5206. if (sfInfo.pid) {
  5207. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  5208. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  5209. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  5210. }
  5211. }
  5212. });
  5213. // 定位到对应的清单或计量单元
  5214. $('body').on('click', '.show-shoufang-report', function () {
  5215. const id = parseInt($(this).attr('data-id'));
  5216. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  5217. sessionStorage.qrCodePath = qrCodePath;
  5218. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  5219. sessionStorage.req_params = JSON.stringify(req_params);
  5220. sessionStorage.rpt_name = rpt_name;
  5221. window.open('/individualReport/A4');
  5222. });
  5223. $('#importExcel').click(() => {
  5224. importExcel.doImport({
  5225. template: {
  5226. hint: '计量台账',
  5227. url: 'https://jl-assets.oss-cn-shenzhen.aliyuncs.com/template/导入计量台账Excel格式.xlsx',
  5228. },
  5229. callback: function (sheet) {
  5230. postDataCompress(window.location.pathname + '/importStageSheet', {sheet}, function (result) {
  5231. window.location.reload();
  5232. }, null);
  5233. }
  5234. });
  5235. });
  5236. const stageAssistRela = {
  5237. refreshAssConfirmBtn: function () {
  5238. if (stage.assist) {
  5239. const caption = stage.assist.user_id === stage.user_id
  5240. ? (stage.assist.confirm ? '撤销上报' : '确认上报')
  5241. : (stage.assist.confirm ? '重新审批' : '审批通过');
  5242. if (!stage.readOnly || stage.assist.locked) $('#ass-confirm-btn').show().html(caption);
  5243. } else {
  5244. $('#ass-confirm-btn').hide();
  5245. }
  5246. },
  5247. checkAssistPartUsed(assist) {
  5248. const ass_lid = assist.ass_ledger_id.split(',');
  5249. for (const lid of ass_lid) {
  5250. const node = stageTree.getItems(lid);
  5251. if (!node) continue;
  5252. if (checkUsed(stageTree, stagePos, node)) return true;
  5253. }
  5254. return false;
  5255. },
  5256. refreshAssistTable: function () {
  5257. const html = [];
  5258. for (const ra of stage.relaAssists) {
  5259. const used = this.checkAssistPartUsed(ra);
  5260. const hint = used
  5261. ? (ra.confirm ? `<td class="text-success">${moment(ra.update_time).format('YYYY-MM-DD HH:mm')}</td>` : '<td class="text-warning">待确认</td>')
  5262. : '<td>本期未计量</td>';
  5263. html.push(`<tr><td>${ra.name}</td><td>${ra.company}</td>${hint}</tr>`);
  5264. }
  5265. return $('#assistList').html(html.join(''));
  5266. },
  5267. refreshAssists: function () {
  5268. if (stage.relaAssists.length > 0) {
  5269. $('#assistCount').html(stage.relaAssists.length || '').parent().show();
  5270. } else {
  5271. $('#assistCount').parent().hide();
  5272. }
  5273. },
  5274. refreshReadOnly(){
  5275. stageTreeSpreadObj.assistReadOnly = stage.readOnly || stage.revising || (!!stage.assist && !!stage.assist.confirm);
  5276. SpreadJsObj.refreshSheetReadOnly(slSpread.getActiveSheet());
  5277. stagePosSpreadObj.loadCurPosData();
  5278. },
  5279. init: function() {
  5280. this.refreshAssConfirmBtn();
  5281. this.refreshReadOnly();
  5282. this.refreshAssists();
  5283. },
  5284. };
  5285. stageAssistRela.init();
  5286. $('#ass-confirm-btn').click(() => {
  5287. const data = { user_id: stage.assist.user_id, ass_user_id: stage.assist.ass_user_id, confirm: !stage.assist.confirm, type: 'stage' };
  5288. postData(window.location.pathname + '/ass-confirm', data, function(result) {
  5289. window.location.reload();
  5290. // stage.assist = result;
  5291. // stageAssistRela.refreshAssConfirmBtn();
  5292. // stageAssistRela.refreshReadOnly();
  5293. });
  5294. });
  5295. $('#assists').on('show.bs.modal', function(){
  5296. postData(window.location.pathname + '/ass', { user_id: userID, type: 'stage' }, function (result) {
  5297. stage.relaAssists = result;
  5298. stageAssistRela.refreshAssistTable();
  5299. });
  5300. });
  5301. $('body').on('click', 'a[name=att-delete]', function() {
  5302. const fid = this.getAttribute('file-id');
  5303. if (!fid) return;
  5304. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  5305. const data = {id: fid};
  5306. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  5307. // 删除到attData中
  5308. const att_index = attData.findIndex(function (item) {
  5309. return item.id === parseInt(fid);
  5310. });
  5311. attData.splice(att_index, 1);
  5312. // 重新生成List
  5313. if ($('#alllist-table tr').length === 1) {
  5314. getAllList(parseInt($('#currentPage').text()) - 1);
  5315. } else {
  5316. getAllList(parseInt($('#currentPage').text()));
  5317. }
  5318. getNodeList(node.id);
  5319. $('#showAttachment').hide();
  5320. $('#showAttachment').attr('file-id', '');
  5321. });
  5322. });
  5323. });
  5324. function makeOneShouFang(sf) {
  5325. const lData = _.find(ledgerData, { id: sf.lid });
  5326. sf.name = lData.b_code;
  5327. if (sf.pid) {
  5328. const pData = _.find(posData, { id: sf.pid });
  5329. if (pData && pData.name) {
  5330. sf.name = lData.b_code + ' / ' + pData.name;
  5331. }
  5332. }
  5333. return sf;
  5334. }
  5335. function makeShouFang() {
  5336. for (const sf of sfData) {
  5337. makeOneShouFang(sf);
  5338. }
  5339. getShouFangList();
  5340. }
  5341. // 生成收方单列表
  5342. function getShouFangList(currPageNum = 1) {
  5343. // 每页最多几个附件
  5344. const pageCount = 20;
  5345. // 附件总数
  5346. const total = sfData.length;
  5347. // 总页数
  5348. const pageNum = Math.ceil(total/pageCount);
  5349. $('#shoufang-totalPage').text(pageNum);
  5350. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  5351. // 当前页附件内容
  5352. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  5353. let html = '';
  5354. for(const att of currPageAttData) {
  5355. html += '<tr><td>' + att.name + '</td>' +
  5356. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  5357. '<td width="100">' +
  5358. '<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> ' +
  5359. '<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> ' +
  5360. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  5361. makeDelHtml(att.id, att.extra_upload) +
  5362. '</td></tr>';
  5363. }
  5364. function makeDelHtml(id, extra_upload) {
  5365. return cur_uid === stage.user_id &&
  5366. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  5367. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  5368. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  5369. }
  5370. $('#shoufang-table').html(html);
  5371. $('[data-toggle="tooltip"]').tooltip();
  5372. }
  5373. function makeReportData(sfid) {
  5374. const sfInfo = _.find(sfData, { id: sfid });
  5375. const ledger_code = sfInfo.name.split(' / ')[0];
  5376. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  5377. const replace_key_params = {
  5378. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  5379. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  5380. 'KEY_合同段': tenderInfo.deal_info.dealName,
  5381. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  5382. 'KEY_编号': '',
  5383. 'KEY_设计工程数量': 0,
  5384. };
  5385. // if (sfInfo.pid) {
  5386. // const pData = _.find(posData, { id: sfInfo.pid });
  5387. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  5388. // } else {
  5389. const lData = _.find(ledgerData, { id: sfInfo.lid });
  5390. // }
  5391. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  5392. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  5393. const req_params = {
  5394. 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)
  5395. pageSize: 'A4',
  5396. project_id: tender.project_id,
  5397. tender_id: tender.id,
  5398. stage_id: stage.id,
  5399. };
  5400. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  5401. const qrCodePath = sfInfo.qrcode;
  5402. return [qrCodePath, replace_key_params, req_params, rpt_name];
  5403. }