stage.js 234 KB

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