stage.js 284 KB

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