stage.js 268 KB

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