stage.js 232 KB

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