stage.js 257 KB

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