stage.js 279 KB

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