stage.js 244 KB

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