stage.js 230 KB

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