stage.js 235 KB

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