stage.js 233 KB

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