stage.js 247 KB

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