stage.js 245 KB

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