stage.js 279 KB

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