stage.js 256 KB

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