stage.js 261 KB

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