stage.js 265 KB

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