stage.js 235 KB

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