stage.js 246 KB

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