stage.js 292 KB

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