stage.js 269 KB

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