stage.js 264 KB

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