stage.js 250 KB

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