stage.js 293 KB

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