stage.js 262 KB

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