stage.js 229 KB

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