stage.js 258 KB

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