stage.js 263 KB

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