stage.js 276 KB

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