change_revise.js 263 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304
  1. 'use strict';
  2. /**
  3. * 台账修订页面js
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const ckBillsSpread = '/tender/' + window.location.pathname.split('/')[2] + '/change/revise-billsSelect';
  10. const invalidFields = {
  11. parent: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'deal_qty', 'deal_tp', 'unit_price', 'ex_qty1', 'ex_tp1'],
  12. gcl: ['dgn_qty1', 'dgn_qty2'],
  13. posCode: ['b_code'],
  14. posCalc: ['sgfh_qty', 'sgfh_tp', 'sjcl_qty', 'sjcl_tp', 'qtcl_qty', 'qtcl_tp', 'ex_qty1', 'ex_tp1'],
  15. posXmj: ['code'],
  16. };
  17. function getExprInfo (field, converse = false) {
  18. const exprField = [
  19. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  20. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  21. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  22. ];
  23. return converse ? _.find(exprField, {expr: field}) : _.find(exprField, {qty: field});
  24. }
  25. function transExpr(expr) {
  26. return $.trim(expr).replace('\t', '').replace('=', '').replace(new RegExp('%', 'gm'), '/100');
  27. }
  28. const copyBlockTag = 'zh.calc.copyBlock';
  29. const dskCompilation = 'zh.calc.dskCompilation';
  30. const checkOption = {
  31. sibling: { enable: 1 },
  32. empty_code: { enable: 1 },
  33. calc: {
  34. enable: 1,
  35. fields: ['sgfh_qty', 'qtcl_qty', 'sjcl_qty', 'quantity'],
  36. },
  37. zero: { enable: 1 },
  38. zeroPos: { enable: 1 },
  39. tp: {
  40. enable: 1,
  41. fields: [
  42. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  43. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  44. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  45. {qty: 'quantity', tp: 'total_price'},
  46. {qty: 'deal_qty', tp: 'deal_tp'},
  47. ],
  48. },
  49. same_code: { enable: 1 },
  50. same_bills: { enable: 1 },
  51. };
  52. $(document).ready(() => {
  53. let stdXmj, stdGcl, searchLedger;
  54. autoFlashHeight();
  55. billsSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', });
  56. const billsIndex = _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'drawing_code' }) : (_.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) !== -1 ? _.findIndex(billsSpreadSetting.cols, { field: 'ex_tp1' }) + 1 : billsSpreadSetting.cols.length - 1);
  57. console.log(billsSpreadSetting.cols);
  58. billsSpreadSetting.cols.splice(billsIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
  59. billsSpreadSetting.cols.splice(billsIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  60. billsSpreadSetting.cols.splice(billsIndex + 2, 0, {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true},);
  61. if (!billsSpreadSetting.readOnly) {
  62. for (const col of billsSpreadSetting.cols) {
  63. if (!col.readOnly || col.readOnly === false)
  64. col.readOnly = 'readOnly.isChangeAdd';
  65. }
  66. }
  67. posSpreadSetting.cols.unshift({ title: '变更清单', colSpan: '1', rowSpan: '2', field: 'is_change', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isChangeList', getValue: 'getValue.isChange' });
  68. const posIndex = _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) !== -1 ? _.findIndex(posSpreadSetting.cols, { field: 'drawing_code' }) : posSpreadSetting.cols.length;
  69. posSpreadSetting.cols.splice(posIndex, 0, { title: '计价', colSpan: '1', rowSpan: '2', field: 'is_valuation', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isValuation', getValue: 'getValue.isValuation' });
  70. posSpreadSetting.cols.splice(posIndex + 1, 0, {title: '申请变更增(+)减(-)|数量', colSpan: '1|1', rowSpan: '|1', field: 'camount', hAlign: 2, width: 120, readOnly: 'readOnly.isSettle', getValue: 'getValue.camount'},);
  71. if (!posSpreadSetting.readOnly) {
  72. for (const col of posSpreadSetting.cols) {
  73. if (!col.readOnly || col.readOnly === false)
  74. col.readOnly = 'readOnly.isChangeAdd';
  75. }
  76. }
  77. const billsCol = {
  78. getValue: {
  79. isChange: function (data) {
  80. if (!data) return 0;
  81. if (!data.name) return 0;
  82. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  83. return cInfo ? 1 : 0;
  84. },
  85. isValuation: function (data) {
  86. if (!data) return 0;
  87. if (!data.name) return 0;
  88. const cList = _.filter(changeList, { gcl_id: data.id });
  89. if (cList.length === 0) return 0;
  90. return _.find(cList, { is_valuation: 0 }) ? 0 : 1;
  91. },
  92. camount: function (data) {
  93. const cInfo = _.find(changeList, {gcl_id: data.id, mx_id: ''});
  94. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(data.unit)) : ZhCalc.round(data.camount, findDecimal(data.unit));
  95. }
  96. },
  97. readOnly: {
  98. isChangeAdd: function (data) {
  99. return !readOnly && !data.formc;
  100. },
  101. isChangeList: function (data) {
  102. if (!data) return true;
  103. let edit = !readOnly && !(data.is_leaf && data.b_code);
  104. if (!edit && data.id) {
  105. const lPos = pos.getLedgerPos(data.id);
  106. if (lPos && lPos.length > 0) {
  107. edit = true;
  108. }
  109. }
  110. return edit;
  111. },
  112. isValuation: function (data) {
  113. if (!data) return true;
  114. return !readOnly && !(data && data.name && _.findIndex(changeList, { gcl_id: data.id, mx_id: '' }) !== -1);
  115. },
  116. isSettle: function (data) {
  117. if (!data) return true;
  118. return !readOnly && !(!billsCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  119. }
  120. }
  121. };
  122. const posCol = {
  123. getValue: {
  124. isChange: function (data) {
  125. if (!data) return 0;
  126. if (!data.name) return 0;
  127. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  128. return cInfo ? 1 : 0;
  129. },
  130. isValuation: function (data) {
  131. if (!data) return 0;
  132. if (!data.name) return 0;
  133. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  134. return cInfo ? cInfo.is_valuation : 0;
  135. },
  136. camount: function (data) {
  137. if (!data) return '';
  138. if (!data.name) return '';
  139. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  140. return cInfo ? ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)) : '';
  141. }
  142. },
  143. readOnly: {
  144. isChangeAdd: function (data) {
  145. return !readOnly && !data.formc && (!data.settle_status || (data.settle_status && data.settle_status === settleStatus.finish));
  146. },
  147. isChangeList: function (data) {
  148. if (!data) return true;
  149. // console.log(data.name);
  150. return !readOnly && !data.name;
  151. },
  152. isValuation: function (data) {
  153. if (!data) return true;
  154. return !readOnly && !posCol.getValue.isChange(data);
  155. },
  156. isSettle: function (data) {
  157. if (!data) return true;
  158. return !readOnly && !(!posCol.readOnly.isChangeList(data) && (!data.settle_status || (data.settle_status && data.settle_status !== settleStatus.finish)));
  159. }
  160. }
  161. };
  162. console.log(posSpreadSetting);
  163. // 判断是否是已结算清单
  164. function checkIsSettle(data) {
  165. const info = data.mx_id ? _.find(settlePos, { lid: data.gcl_id, pid: data.mx_id }) : _.find(settleBills, { lid: data.gcl_id });
  166. if (info && info.settle_status && info.settle_status === settleStatus.finish) {
  167. return true;
  168. }
  169. return false;
  170. }
  171. // 初始化spread
  172. const billsSpread = SpreadJsObj.createNewSpread($('#bills-spread')[0]);
  173. const billsSheet = billsSpread.getActiveSheet();
  174. billsSpreadSetting.rowHeader = [
  175. {
  176. rowHeaderType: 'circle',
  177. setting: {
  178. size: 5,
  179. indent: 16,
  180. getColor: function (index, data) {
  181. if (!data) return;
  182. if(!data.formc && !data.cid) return;
  183. return '#dc3545';
  184. }
  185. },
  186. },
  187. ];
  188. billsSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  189. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  190. return spreadColor.stage.settle;
  191. }
  192. if (data && data.is_change) {
  193. return '#c3e6cb';
  194. }
  195. return defaultColor;
  196. };
  197. billsSpreadSetting.localCache = {
  198. key: 'changes-ledger-spread',
  199. colWidth: true,
  200. };
  201. sjsSettingObj.setFxTreeStyle(billsSpreadSetting, sjsSettingObj.FxTreeStyle.jz);
  202. if (thousandth) sjsSettingObj.setTpThousandthFormat(billsSpreadSetting);
  203. sjsSettingObj.setNodeTypeCol(billsSpreadSetting.cols, [{field: 'node_type'}]);
  204. SpreadJsObj.initSpreadSettingEvents(billsSpreadSetting, billsCol);
  205. SpreadJsObj.initSheet(billsSheet, billsSpreadSetting);
  206. const posSpread = SpreadJsObj.createNewSpread($('#pos-spread')[0]);
  207. const posSheet = posSpread.getActiveSheet();
  208. posSpreadSetting.rowHeader = [
  209. {
  210. rowHeaderType: 'circle',
  211. setting: {
  212. size: 5,
  213. indent: 16,
  214. getColor: function (index, data) {
  215. if (!data) return;
  216. if(!data.formc) return;
  217. return '#dc3545';
  218. }
  219. },
  220. },
  221. ];
  222. posSpreadSetting.getColor = function (sheet, data, row, col, defaultColor) {
  223. if (data && data.settle_status && data.settle_status === settleStatus.finish) {
  224. return spreadColor.stage.settle;
  225. }
  226. return defaultColor;
  227. };
  228. posSpreadSetting.localCache = {
  229. key: 'changes-pos-spread',
  230. colWidth: true,
  231. };
  232. sjsSettingObj.setGridSelectStyle(posSpreadSetting);
  233. if (thousandth) sjsSettingObj.setTpThousandthFormat(posSpreadSetting);
  234. SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  235. SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  236. const posSearch = $.posSearch({selector: '#pos-search', searchSpread: posSpread});
  237. const errorList = $.cs_errorList({
  238. tabSelector: '#error-list-tab',
  239. selector: '#error-list',
  240. relaSpread: billsSpread,
  241. storeKey: 'change-revise-error-' + window.location.pathname.split('/')[2],
  242. afterLocated: function () {
  243. posSpreadObj.loadCurPosData();
  244. },
  245. afterShow: function () {
  246. billsSpread.refresh();
  247. if (posSpread) posSpread.refresh();
  248. },
  249. });
  250. const checkList = $.ledger_checkList({
  251. id: 'check-list',
  252. tabSelector: '#check-list-tab',
  253. selector: '#check-list',
  254. relaSpread: billsSpread,
  255. storeKey: 'change-revise-check-' + window.location.pathname.split('/')[2],
  256. checkType: getCheckType(checkOption),
  257. afterLocated: function () {
  258. posSpreadObj.loadCurPosData();
  259. },
  260. afterShow: function () {
  261. billsSpread.refresh();
  262. if (posSpread) posSpread.refresh();
  263. },
  264. });
  265. const sumLoadMiss = $.sumLoadMiss({
  266. tabSelector: '#sum-load-miss-tab',
  267. selector: '#sum-load-miss',
  268. relaSpread: billsSpread,
  269. storeKey: 'change-revise-slm-' + window.location.pathname.split('/')[2],
  270. id: 'revise-slm',
  271. afterLocated: function () {
  272. posSpreadObj.loadCurPosData();
  273. },
  274. afterShow: function () {
  275. billsSpread.refresh();
  276. if (posSpread) posSpread.refresh();
  277. },
  278. });
  279. // 初始化 节点树结构
  280. const treeSetting = {
  281. id: 'ledger_id',
  282. pid: 'ledger_pid',
  283. order: 'order',
  284. level: 'level',
  285. rootId: -1,
  286. keys: ['id', 'tender_id', 'ledger_id'],
  287. calcFields: ['sgfh_tp', 'sjcl_tp', 'qtcl_tp', 'total_price', 'ca_tp', 'ex_tp1'],
  288. autoExpand: 3,
  289. markExpandKey: 'change-bills-expand',
  290. markExpandSubKey: window.location.pathname.split('/')[2],
  291. };
  292. if (!isTz) {
  293. treeSetting.calcFields.push('deal_tp');
  294. }
  295. treeSetting.calcFun = function (node) {
  296. if (node && node.b_code) {
  297. const posData = pos.getLedgerPos(node.id) || [];
  298. let camount = ZhCalc.round(node.camount, findDecimal(node.unit)) || 0;
  299. if (posData.length > 0) {
  300. let sgfh_qty = 0;
  301. let sjcl_qty = 0;
  302. let qtcl_qty = 0;
  303. let ex_qty1 = 0;
  304. camount = 0;
  305. for (const np of posData) {
  306. sgfh_qty = ZhCalc.add(sgfh_qty, np.sgfh_qty);
  307. sjcl_qty = ZhCalc.add(sjcl_qty, np.sjcl_qty);
  308. qtcl_qty = ZhCalc.add(qtcl_qty, np.qtcl_qty);
  309. ex_qty1 = ZhCalc.add(ex_qty1, np.ex_qty1);
  310. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  311. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(node.unit))) : camount;
  312. }
  313. if (!_.isEqual(node.sgfh_qty, sgfh_qty) || !_.isEqual(node.sjcl_qty, sjcl_qty) || !_.isEqual(node.qtcl_qty, qtcl_qty)) {
  314. node.sgfh_qty = sgfh_qty;
  315. node.sjcl_qty = sjcl_qty;
  316. node.qtcl_qty = qtcl_qty;
  317. node.ex_qty1 = ex_qty1;
  318. node.quantity = ZhCalc.sum([node.sgfh_qty, node.sjcl_qty, node.qtcl_qty]);
  319. node.sgfh_tp = ZhCalc.mul(sgfh_qty, node.unit_price, decimal.tp) || 0;
  320. node.sjcl_tp = ZhCalc.mul(sjcl_qty, node.unit_price, decimal.tp) || 0;
  321. node.qtcl_tp = ZhCalc.mul(qtcl_qty, node.unit_price, decimal.tp) || 0;
  322. node.total_price = ZhCalc.mul(node.quantity, node.unit_price, decimal.tp) || 0;
  323. }
  324. if (!_.isEqual(node.ex_qty1, ex_qty1)) {
  325. node.ex_qty1 = ex_qty1;
  326. node.ex_tp1 = ZhCalc.mul(node.ex_qty1, node.unit_price, decimal.tp) || 0;
  327. }
  328. }
  329. node.camount = camount;
  330. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  331. }
  332. node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
  333. };
  334. const billsTree = createNewPathTree('revise', treeSetting);
  335. console.log(billsTree, treeSetting);
  336. // 初始化 计量单元
  337. const pos = new PosData({ id: 'id', ledgerId: 'lid' });
  338. // 清单 相关方法&绑定spreadjs事件
  339. const billsTreeSpreadObj = {
  340. loadExprToInput(sheet) {
  341. const sel = sheet.getSelections()[0];
  342. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  343. if (col && col.field === 'camount') {
  344. const data = SpreadJsObj.getSelectObject(sheet);
  345. if (data) {
  346. const cInfo = _.find(changeList, { gcl_id: data.id, mx_id: '' });
  347. if (!cInfo) {
  348. $('#bills-expr').val('').attr('readOnly', true);
  349. $('#bills-expr').removeAttr('data-row');
  350. } else {
  351. const value = cInfo.camount_expr ? cInfo.camount_expr : ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit));
  352. $('#bills-expr').val(value).attr('field', col.field).attr('org', ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit)))
  353. .attr('readOnly', billsCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  354. }
  355. } else {
  356. $('#bills-expr').val('').attr('readOnly', true);
  357. $('#bills-expr').removeAttr('data-row');
  358. }
  359. } else if (col && col.type === 'Number') {
  360. const data = SpreadJsObj.getSelectObject(sheet);
  361. if (data) {
  362. const exprInfo = getExprInfo(col.field);
  363. if (exprInfo) {
  364. $('#bills-expr').val(data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  365. .attr('field', col.field).attr('org', data[col.field]);
  366. } else {
  367. $('#bills-expr').val(data[col.field]).attr('field', col.field).attr('org', data[col.field]);
  368. }
  369. if (col.field.indexOf('dgn') >= 0) {
  370. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (_.isString(data.b_code) && data.b_code !== '') || !data.formc);
  371. } else if (col.field === 'unit_price') {
  372. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || (_.isBoolean(data.used) && data.used === true) || !data.formc);
  373. } else {
  374. const nodePos = pos.getLedgerPos(data.id);
  375. if (nodePos && nodePos.length > 0) {
  376. $('#bills-expr').val('').attr('readOnly', true);
  377. $('#bills-expr').removeAttr('data-row');
  378. } else {
  379. $('#bills-expr').attr('readOnly', readOnly || cell.locked() || (data.children && data.children.length > 0) || !data.formc);
  380. }
  381. }
  382. $('#bills-expr').attr('data-row', sel.row);
  383. } else {
  384. $('#bills-expr').val('').attr('readOnly', true);
  385. $('#bills-expr').removeAttr('data-row');
  386. }
  387. } else {
  388. $('#bills-expr').val('').attr('readOnly', true);
  389. $('#bills-expr').removeAttr('data-row');
  390. }
  391. },
  392. getDefaultSelectInfo: function (sheet) {
  393. const tree = sheet.zh_tree;
  394. if (!tree) return;
  395. const sel = sheet.getSelections()[0];
  396. const node = sheet.zh_tree.nodes[sel.row];
  397. if (!node) return;
  398. let count = 1;
  399. if (sel.rowCount > 1) {
  400. for (let r = 1; r < sel.rowCount; r++) {
  401. const rNode = sheet.zh_tree.nodes[sel.row + r];
  402. if (rNode.level > node.level) continue;
  403. if ((rNode.level < node.level) || (rNode.level === node.level && rNode.pid !== node.pid)) {
  404. toastr.warning('请选择同一节点下的节点,进行该操作');
  405. return;
  406. }
  407. count += 1;
  408. }
  409. }
  410. return [tree, node, count];
  411. },
  412. /**
  413. * 刷新顶部按钮是否可用
  414. * @param sheet
  415. * @param selections
  416. */
  417. refreshOperationValid: function (sheet, selection) {
  418. const setObjEnable = function (obj, enable) {
  419. if (enable) {
  420. obj.removeClass('disabled');
  421. } else {
  422. obj.addClass('disabled');
  423. }
  424. };
  425. const invalidAll = function () {
  426. setObjEnable($('a[name=base-opr][type=add]'), false);
  427. setObjEnable($('a[name=base-opr][type=delete]'), false);
  428. setObjEnable($('a[name=base-opr][type=up-move]'), false);
  429. setObjEnable($('a[name=base-opr][type=down-move]'), false);
  430. setObjEnable($('a[name=base-opr][type=up-level]'), false);
  431. setObjEnable($('a[name=base-opr][type=down-level]'), false);
  432. };
  433. const sel = selection ? selection[0] : sheet.getSelections()[0];
  434. const row = sel ? sel.row : -1;
  435. const tree = sheet.zh_tree;
  436. if (!tree) {
  437. invalidAll();
  438. return;
  439. }
  440. const first = sheet.zh_tree.nodes[row];
  441. if (!first) {
  442. invalidAll();
  443. return;
  444. }
  445. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  446. if (sel.rowCount > 1 && first) {
  447. for (let r = 1; r < sel.rowCount; r++) {
  448. const rNode = tree.nodes[sel.row + r];
  449. if (!rNode) {
  450. sameParent = false;
  451. break;
  452. }
  453. if (!rNode.formc) {
  454. sameParent = false;
  455. break;
  456. }
  457. nodeUsed = nodeUsed || rNode.used;
  458. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  459. if (rNode.level > first.level) continue;
  460. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  461. sameParent = false;
  462. break;
  463. }
  464. last = rNode;
  465. }
  466. }
  467. const preNode = tree.getPreSiblingNode(first);
  468. const siblings = tree.getChildren(tree.getParent(first));
  469. let upPower = true;
  470. for (let order = last.order; order < siblings.length - 1; order ++) {
  471. if (!siblings[order].formc) {
  472. upPower = false;
  473. break;
  474. }
  475. }
  476. const valid = !sheet.zh_setting.readOnly;
  477. setObjEnable($('a[name=base-opr][type=add]'), valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  478. setObjEnable($('a[name=base-opr][type=delete]'), valid && first && sameParent && first.level > 1 && !nodeUsed && first.formc && !settleFinish);
  479. setObjEnable($('a[name=base-opr][type=up-move]'), valid && first && sameParent && first.level > 1 && preNode && first.formc);
  480. setObjEnable($('a[name=base-opr][type=down-move]'), valid && first && sameParent && first.level > 1 && !tree.isLastSibling(last) && first.formc);
  481. const posRange = last ? pos.getLedgerPos(last.id) : [];
  482. setObjEnable($('a[name=base-opr][type=up-level]'), valid && first && sameParent && tree.getParent(first) && !nodeUsed
  483. && first.level > 2 && ((!posRange || posRange.length === 0) || last.settle_status !== settleStatus.finish || tree.isLastSibling(last)) && upPower && first.formc);
  484. const preNodePosRange = preNode ? pos.getLedgerPos(preNode.id) : [];
  485. setObjEnable($('a[name=base-opr][type=down-level]'), valid && first && sameParent
  486. && first.level > 1 && preNode && (preNode.children.length > 0 || (preNode.children.length === 0 && preNode.formc && (!preNodePosRange || preNodePosRange.length === 0))) && !preNode.used && first.formc && preNode.settle_status !== settleStatus.finish);
  487. setObjEnable($('#cut'), valid);
  488. setObjEnable($('#paste'), valid);
  489. },
  490. /**
  491. *
  492. * @param sheet
  493. * @param data
  494. */
  495. refreshTree: function (sheet, data) {
  496. SpreadJsObj.massOperationSheet(sheet, function () {
  497. const tree = sheet.zh_tree;
  498. // 处理删除
  499. if (data.delete) {
  500. data.delete.sort(function (a, b) {
  501. return b.deleteIndex - a.deleteIndex;
  502. });
  503. for (const d of data.delete) {
  504. sheet.deleteRows(d.deleteIndex, 1);
  505. }
  506. }
  507. // 处理新增
  508. if (data.create) {
  509. const newNodes = data.create;
  510. if (newNodes) {
  511. newNodes.sort(function (a, b) {
  512. return a.index - b.index;
  513. });
  514. for (const node of newNodes) {
  515. sheet.addRows(node.index, 1);
  516. SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);
  517. }
  518. }
  519. }
  520. // 处理更新
  521. if (data.update) {
  522. const rows = [];
  523. for (const u of data.update) {
  524. rows.push(tree.nodes.indexOf(u));
  525. }
  526. SpreadJsObj.reLoadRowsData(sheet, rows);
  527. }
  528. // 处理展开
  529. if (data.expand) {
  530. const expanded = [];
  531. for (const e of data.expand) {
  532. if (expanded.indexOf(e) === -1) {
  533. const posterity = tree.getPosterity(e);
  534. for (const p of posterity) {
  535. sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);
  536. expanded.push(p);
  537. }
  538. }
  539. }
  540. }
  541. });
  542. },
  543. selectionChanged: function (e, info) {
  544. if (info.newSelections) {
  545. if (!info.oldSelections || info.newSelections[0].row !== info.oldSelections[0].row || info.newSelections[0].rowCount !== info.oldSelections[0].rowCount) {
  546. billsTreeSpreadObj.refreshOperationValid(info.sheet);
  547. billsTreeSpreadObj.refreshPosData();
  548. }
  549. }
  550. billsTreeSpreadObj.loadExprToInput(info.sheet);
  551. },
  552. refreshPosData: function() {
  553. SpreadJsObj.resetTopAndSelect(posSheet);
  554. posSpreadObj.loadCurPosData();
  555. SpreadJsObj.saveTopAndSelect(billsSheet, ckBillsSpread);
  556. posSearch.search($('#pos-keyword').val());
  557. },
  558. /**
  559. * 新增节点
  560. * @param spread
  561. */
  562. baseOpr: function (sheet, type, addCount = 1) {
  563. const self = this;
  564. const [tree, node, count] = this.getDefaultSelectInfo(sheet);
  565. if (!tree || !node || !count) return;
  566. if (type === 'delete') {
  567. const parent = tree.getParent(node);
  568. const children = parent ? parent.children : tree.children;
  569. const index = children.indexOf(node);
  570. for (let i = 0; i < count; i++) {
  571. const child = children[i+index];
  572. if (tree.checkNodeUsed(child, pos)) {
  573. toastr.warning('选中的节点已计量,不可删除');
  574. return;
  575. }
  576. if (child.settle_status === settleStatus.finish) {
  577. toastr.warning('选中的节点已结算,不可删除');
  578. return;
  579. }
  580. }
  581. } else if (type === 'up-level') {
  582. const parent = tree.getParent(node);
  583. const children = parent ? parent.children : tree.children;
  584. const index = children.indexOf(node);
  585. const lastSelect = children[index + count - 1];
  586. if (tree.checkNodeUsed(lastSelect, pos) && (!lastSelect.children || lastSelect.children.length === 0) && (children.length > index + count)) {
  587. toastr.warning('选中的节点已计量,不可升级');
  588. return;
  589. }
  590. if (lastSelect.settle_status === settleStatus.finish && (children.length > index + count)) {
  591. toastr.warning('选中的节点已结算,不可升级');
  592. return;
  593. }
  594. // for (let i = index; i < children.length; i++) {
  595. // const child = children[index];
  596. // if (tree.checkNodeUsed(child, pos)) {
  597. // if (i >= index + count) {
  598. // toastr.warning('其后节点已计量,选中的节点不可升级');
  599. // } else {
  600. // toastr.warning('选中的节点已计量,不可升级');
  601. // }
  602. // return;
  603. // }
  604. // }
  605. } else if (type === 'down-level') {
  606. const parent = tree.getParent(node);
  607. const children = parent ? parent.children : tree.children;
  608. const index = children.indexOf(node);
  609. if (index > 0 && children[index-1].used) {
  610. toastr.warning('其前节点已计量,选中的节点不可降级');
  611. return;
  612. }
  613. if (index > 0 && children[index-1].settle_status === settleStatus.finish) {
  614. toastr.warning('其前节点已结算,选中的节点不可降级');
  615. return;
  616. }
  617. for (let i = index; i < count; i++) {
  618. const child = children[i+index];
  619. if (tree.checkNodeUsed(child, pos)) {
  620. toastr.warning('选中的节点已计量,不可降级');
  621. return;
  622. }
  623. if (tree.settle_status === settleStatus.finish) {
  624. toastr.warning('选中的节点已结算,不可降级');
  625. return;
  626. }
  627. }
  628. } else if (type === 'add') {
  629. if (node.settle_status === settleStatus.finish) {
  630. toastr.warning('选中的节点已结算,不可新增子项');
  631. return;
  632. }
  633. }
  634. if (type === 'delete') {
  635. deleteAfterHint(function () {
  636. postData(window.location.pathname + '/update', {
  637. postType: type,
  638. postData: {
  639. id: node.ledger_id,
  640. count: type === 'add' ? addCount : count,
  641. }
  642. }, function (result) {
  643. changeList = result.changeList;
  644. const refreshData = tree.loadPostData(result);
  645. self.refreshTree(sheet, refreshData);
  646. const sel = sheet.getSelections()[0];
  647. if (sel) {
  648. sheet.setSelection(sel.row, sel.col, 1, sel.colCount);
  649. billsTreeSpreadObj.refreshPosData();
  650. }
  651. self.refreshOperationValid(sheet);
  652. });
  653. });
  654. } else {
  655. postData(window.location.pathname + '/update', {
  656. postType: type,
  657. postData: {
  658. id: node.ledger_id,
  659. count: type === 'add' ? addCount : count,
  660. }
  661. }, function (result) {
  662. changeList = result.changeList;
  663. const refreshData = tree.loadPostData(result);
  664. self.refreshTree(sheet, refreshData);
  665. if (['up-move', 'down-move'].indexOf(type) > -1) {
  666. const sel = sheet.getSelections()[0];
  667. if (sel) {
  668. sheet.setSelection(tree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  669. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(node)]);
  670. }
  671. } else if (type === 'add') {
  672. const sel = sheet.getSelections()[0];
  673. if (sel) {
  674. sheet.setSelection(tree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  675. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(refreshData.create[0])]);
  676. billsTreeSpreadObj.refreshPosData();
  677. }
  678. }
  679. self.refreshOperationValid(sheet);
  680. });
  681. }
  682. },
  683. buttonClicked: function (e, info, v) {
  684. if (info.sheet.zh_setting) {
  685. const select = SpreadJsObj.getSelectObject(info.sheet);
  686. const col = info.sheet.zh_setting.cols[info.col];
  687. if (col.field === 'is_change') {
  688. if (billsCol.readOnly.isChangeList(select)) {
  689. return
  690. }
  691. if (info.sheet.isEditing()) {
  692. info.sheet.endEdit(true);
  693. }
  694. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  695. if (is_change) {
  696. makeGclGatherData();
  697. const gclInfo = _.find(gclGatherData, function (item) {
  698. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.id });
  699. });
  700. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  701. return item.gcl_id === select.id;
  702. });
  703. const oldCInfo = _.find(oldChangeList, { gcl_id: select.id, mx_id: '' });
  704. const data = {
  705. lid: gclInfo.leafXmjs[0].gcl_id || select.id,
  706. code: gclInfo.b_code,
  707. name: gclInfo.name || '',
  708. unit: gclInfo.unit || '',
  709. unit_price: gclInfo.unit_price,
  710. oamount: xmjInfo.quantity,
  711. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  712. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  713. xmj_code: xmjInfo.code || '',
  714. xmj_jldy: xmjInfo.jldy || '',
  715. xmj_dwgc: xmjInfo.dwgc || '',
  716. xmj_fbgc: xmjInfo.fbgc || '',
  717. xmj_fxgc: xmjInfo.fxgc || '',
  718. gcl_id: select.id,
  719. mx_id: '',
  720. };
  721. if (oldCInfo) {
  722. data.detail = oldCInfo.detail;
  723. data.camount = oldCInfo.camount;
  724. data.camount_expr = oldCInfo.camount_expr;
  725. data.spamount = oldCInfo.spamount;
  726. data.is_valuation = oldCInfo.is_valuation;
  727. data.delimit = oldCInfo.delimit;
  728. }
  729. // 更新至服务器
  730. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  731. changeList = result.changeList;
  732. select.is_change = 1;
  733. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  734. if (oldCInfo) {
  735. select.camount = data.camount;
  736. const refreshNode = billsTree.loadPostData({ update: [select] });
  737. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  738. }
  739. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  740. }, function () {
  741. info.sheet.setValue(info.row, info.col, 0);
  742. });
  743. } else {
  744. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.id }) !== -1) {
  745. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  746. info.sheet.setValue(info.row, info.col, 1);
  747. return
  748. }
  749. const cInfo = _.find(changeList, { gcl_id: select.id });
  750. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  751. toastr.warning('该清单计量单元已被使用,无法取消勾选');
  752. info.sheet.setValue(info.row, info.col, 1);
  753. return
  754. } else if (checkIsSettle(cInfo)) {
  755. toastr.warning('该清单计量单元已结算,无法取消勾选');
  756. info.sheet.setValue(info.row, info.col, 1);
  757. return
  758. } else {
  759. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  760. changeList = result.changeList;
  761. select.is_change = 0;
  762. select.is_valuation = 0;
  763. select.camount = null;
  764. const billsNode = select;
  765. billsTreeSpreadObj.reCalcCamount(billsNode);
  766. const loadResult = { update: [billsNode] };
  767. const refreshNode = billsTree.loadPostData(loadResult);
  768. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  769. // 重算申请数量金额
  770. // const refreshNode = billsTree.loadPostData(result);
  771. // billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  772. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  773. }, function () {
  774. info.sheet.setValue(info.row, info.col, 1);
  775. });
  776. }
  777. }
  778. } else if (col.field === 'is_valuation') {
  779. if (billsCol.readOnly.isChangeList(select)) {
  780. return;
  781. }
  782. if (!billsCol.getValue.isChange(select)) {
  783. toastr.warning('请先勾选变更清单才能勾选计价');
  784. info.sheet.setValue(info.row, info.col, 0);
  785. return;
  786. }
  787. if (info.sheet.isEditing()) {
  788. info.sheet.endEdit(true);
  789. }
  790. const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  791. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  792. toastr.warning('该变更清单已被调用,无法更改计价');
  793. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  794. return;
  795. }
  796. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  797. // select.is_valuation = is_valuation;
  798. cInfo.is_valuation = is_valuation;
  799. delete cInfo.waitingLoading;
  800. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  801. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  802. info.sheet.setValue(info.row, info.col, is_valuation);
  803. }, function () {
  804. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  805. cInfo.is_valuation = select.is_valuation;
  806. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  807. });
  808. }
  809. }
  810. },
  811. /**
  812. * 编辑单元格响应事件
  813. * @param {Object} e
  814. * @param {Object} info
  815. */
  816. editEnded: function (e, info) {
  817. if (info.sheet.zh_setting) {
  818. const col = info.sheet.zh_setting.cols[info.col];
  819. if (col.field === 'is_change' || col.field === 'is_valuation') {
  820. return;
  821. }
  822. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  823. const node = sortData[info.row];
  824. if (col.field === 'camount') {
  825. if (!node) {
  826. toastr.error('数据错误,请选择台账节点后再试');
  827. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  828. return;
  829. }
  830. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  831. if (!cInfo) {
  832. makeGclGatherData();
  833. const gclInfo = _.find(gclGatherData, function (item) {
  834. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  835. });
  836. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  837. return item.gcl_id === node.id;
  838. });
  839. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  840. const data = {
  841. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  842. code: gclInfo.b_code,
  843. name: gclInfo.name || '',
  844. unit: gclInfo.unit || '',
  845. unit_price: gclInfo.unit_price,
  846. oamount: xmjInfo.quantity,
  847. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  848. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  849. xmj_code: xmjInfo.code || '',
  850. xmj_jldy: xmjInfo.jldy || '',
  851. xmj_dwgc: xmjInfo.dwgc || '',
  852. xmj_fbgc: xmjInfo.fbgc || '',
  853. xmj_fxgc: xmjInfo.fxgc || '',
  854. gcl_id: node.id,
  855. mx_id: '',
  856. };
  857. if (oldCInfo) {
  858. data.detail = oldCInfo.detail;
  859. data.camount = oldCInfo.camount;
  860. data.camount_expr = oldCInfo.camount_expr;
  861. data.spamount = oldCInfo.spamount;
  862. data.is_valuation = oldCInfo.is_valuation;
  863. data.delimit = oldCInfo.delimit;
  864. }
  865. cInfo = data;
  866. // toastr.error('未勾选变更清单,无法编辑申请数量');
  867. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  868. // return;
  869. }
  870. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  871. const orgValue = validText && validText !== ''
  872. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  873. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  874. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  875. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  876. return;
  877. }
  878. const exprQuantity = {
  879. expr: '',
  880. quantity: 0,
  881. };
  882. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  883. if (!valid) {
  884. toastr.error(msg);
  885. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  886. return;
  887. }
  888. if (isNaN(exprQuantity.quantity)) {
  889. toastr.error('不能输入其它非数字类型字符');
  890. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  891. return;
  892. }
  893. validText = parseFloat(exprQuantity.quantity);
  894. if (cInfo.id) {
  895. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  896. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  897. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  898. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  899. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  900. return;
  901. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  902. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  903. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  904. return;
  905. }
  906. }
  907. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  908. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  909. cInfo.camount_expr = exprQuantity.expr;
  910. node[col.field] = cInfo[col.field];
  911. delete cInfo.waitingLoading;
  912. if (cInfo.id) {
  913. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  914. type: 'update',
  915. updateData: cInfo
  916. }, function (result) {
  917. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  918. const billsNode = node;
  919. billsTreeSpreadObj.reCalcCamount(billsNode);
  920. const loadResult = {update: [billsNode]};
  921. const refreshNode = billsTree.loadPostData(loadResult);
  922. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  923. }, function () {
  924. cInfo[col.field] = orgValue;
  925. cInfo.spamount = orgValue;
  926. node[col.field] = orgValue;
  927. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  928. });
  929. } else {
  930. // 更新至服务器
  931. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  932. changeList = result.changeList;
  933. node.is_change = 1;
  934. node.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  935. node.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  936. billsTreeSpreadObj.reCalcCamount(node);
  937. const refreshNode = billsTree.loadPostData({ update: [node] });
  938. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  939. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  940. }, function () {
  941. cInfo[col.field] = orgValue;
  942. cInfo.spamount = orgValue;
  943. node[col.field] = orgValue;
  944. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  945. });
  946. }
  947. return;
  948. }
  949. const data = {
  950. id: node.id,
  951. tender_id: node.tender_id,
  952. ledger_id: node.ledger_id
  953. };
  954. // 未改变值则不提交
  955. const orgValue = node[col.field];
  956. const newValue = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  957. if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
  958. return;
  959. }
  960. // 台账模式,检查计量单元相关
  961. if (isTz) {
  962. if (col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  963. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  964. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  965. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  966. if (!node.children || node.children.length ===0) {
  967. const lPos = pos.getLedgerPos(node.id);
  968. if (lPos && lPos.length > 0) {
  969. toastr.error('清单含有计量单元,不可修改施工图复核数量');
  970. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  971. return;
  972. }
  973. }
  974. }
  975. if (col.field === 'b_code' && (newValue === '' || !newValue)) {
  976. const lPos = pos.getLedgerPos(node.id);
  977. if (lPos && lPos.length > 0) {
  978. toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
  979. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  980. return;
  981. }
  982. }
  983. }
  984. // 获取更新数据
  985. const exprInfo = getExprInfo(col.field);
  986. if (info.editingText) {
  987. const text = newValue;
  988. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
  989. toastr.error('节点已计量,请勿删除编号');
  990. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  991. return;
  992. }
  993. if (col.type === 'Number') {
  994. const num = _.toNumber(text);
  995. if (_.isFinite(num)) {
  996. data[col.field] = num;
  997. if (exprInfo) {
  998. data[exprInfo.expr] = '';
  999. }
  1000. } else {
  1001. try {
  1002. data[col.field] = ZhCalc.mathCalcExpr(transExpr(text));
  1003. if (exprInfo) {
  1004. data[exprInfo.expr] = newValue;
  1005. }
  1006. } catch(err) {
  1007. toastr.error('输入的表达式非法');
  1008. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1009. return;
  1010. }
  1011. }
  1012. } else {
  1013. data[col.field] = text;
  1014. }
  1015. } else {
  1016. if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '') {
  1017. toastr.error('节点已计量,请勿删除编号');
  1018. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1019. return;
  1020. }
  1021. data[col.field] = null;
  1022. if (exprInfo) {
  1023. data[exprInfo.expr] = '';
  1024. }
  1025. }
  1026. if (col.field === 'b_code' && newValue) {
  1027. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1028. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1029. });
  1030. const ledgerOneData = _.find(ledgerData, { b_code: newValue });
  1031. if (ledgerOneData) {
  1032. data.name = ledgerOneData.name;
  1033. data.unit = ledgerOneData.unit;
  1034. data.unit_price = ledgerOneData.unit_price;
  1035. }
  1036. }
  1037. // 更新至服务器
  1038. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1039. changeList = result.changeList;
  1040. const refreshNode = billsTree.loadPostData(result);
  1041. for (const u of refreshNode.update) {
  1042. billsTreeSpreadObj.reCalcCamount(u);
  1043. }
  1044. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1045. billsTreeSpreadObj.refreshPosData();
  1046. });
  1047. }
  1048. },
  1049. clipboardPasting: function (e, info) {
  1050. const tree = info.sheet.zh_tree, setting = info.sheet.zh_setting;
  1051. info.cancel = true;
  1052. if (!setting || !tree) return;
  1053. // const range = info.cellRange;
  1054. // for (let iRow = range.row; iRow < range.row + range.rowCount; iRow++) {
  1055. // const node = tree.nodes[iRow];
  1056. // if (tree.checkNodeUsed(node, pos)) {
  1057. // toastr.warning('"' + node.code + node.b_code + ' ' + node.name +'"已计量,请勿修改');
  1058. // return;
  1059. // }
  1060. // }
  1061. const pasteData = info.pasteData.html
  1062. ? SpreadJsObj.analysisPasteHtml(info.pasteData.html)
  1063. : (info.pasteData.text === ''
  1064. ? SpreadJsObj.Clipboard.getAnalysisPasteText()
  1065. : SpreadJsObj.analysisPasteText(info.pasteData.text));
  1066. const hint = {
  1067. usedUp: {type: 'warning', msg: '节点已计量,不可修改单价'},
  1068. usedCode: {type: 'warning', msg: '节点已计量,编号不可修改为空值'},
  1069. invalidExpr: {type: 'warning', msg: '粘贴的表达式非法'},
  1070. posCode: {type: 'warning', msg: '清单含有计量单元,不可粘贴清单编号为空'},
  1071. posQty: {type: 'warning', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可粘贴'},
  1072. parent: {type: 'warning', msg: '含有子项的清单,不可粘贴数量、单价、金额'},
  1073. gcl: {type: 'warning', msg: '工程量清单,不可粘贴项目节数量'},
  1074. posXmj: {type: 'warning', msg: '清单含有计量单元,不可粘贴项目节编号'},
  1075. // sameParent: {type: 'warning', msg: '仅可粘贴同层节点'},
  1076. settle: {type: 'warning', msg: '已结算节点,不可修改数量、单价、金额'},
  1077. };
  1078. const datas = [], filterNodes = [], camountData = [], insertCamountData = [];
  1079. let pid, level, filterRow = 0;
  1080. makeGclGatherData();
  1081. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1082. const curRow = info.cellRange.row + iRow;
  1083. const node = tree.nodes[curRow];
  1084. if (!node) continue;
  1085. if (!pid) pid = node.ledger_pid;
  1086. if (!level) level = node.level;
  1087. // if (node.ledger_pid !== pid) {
  1088. // toastMessageUniq(hint.sameParent);
  1089. // filterRow+=1;
  1090. // continue;
  1091. // }
  1092. if (node.level < level) break;
  1093. let bPaste = false;
  1094. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1095. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1096. const curCol = info.cellRange.col + iCol;
  1097. const colSetting = info.sheet.zh_setting.cols[curCol];
  1098. const value = colSetting.wordWrap ? pasteData[iRow-filterRow][iCol] : trimInvalidChar(pasteData[iRow-filterRow][iCol]);
  1099. if (node.children && node.children.length > 0 && invalidFields.parent.indexOf(colSetting.field) >= 0) {
  1100. toastMessageUniq(hint.parent);
  1101. continue;
  1102. }
  1103. if (!_.isEmpty(node.b_code) && invalidFields.gcl.indexOf(colSetting.field) >= 0) {
  1104. toastMessageUniq(hint.gcl);
  1105. continue;
  1106. }
  1107. const lPos = pos.getLedgerPos(node.id);
  1108. if (lPos && lPos.length > 0) {
  1109. if (value === '' && colSetting.field === 'b_code') {
  1110. toastMessageUniq(hint.posCode);
  1111. continue;
  1112. }
  1113. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1114. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1115. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1116. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1117. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1118. if (isTz) {
  1119. toastMessageUniq(hint.posQty);
  1120. continue;
  1121. }
  1122. }
  1123. if (value !== '' && invalidFields.posXmj.indexOf(colSetting.field) >= 0) {
  1124. toastMessageUniq(hint.posXmj);
  1125. continue;
  1126. }
  1127. }
  1128. if (tree.checkNodeUsed(node, pos) && colSetting.field === 'unit_price') {
  1129. toastMessageUniq (hint.usedUp);
  1130. continue;
  1131. }
  1132. if (colSetting.type === 'Number' && node.settle_status === settleStatus.finish) {
  1133. toastMessageUniq(hint.settle);
  1134. continue;
  1135. }
  1136. if (colSetting.field === 'camount') {
  1137. bPaste = true;
  1138. let validText = value;
  1139. let cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1140. if (!cInfo) {
  1141. const gclInfo = _.find(gclGatherData, function (item) {
  1142. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: node.id });
  1143. });
  1144. const xmjInfo = gclInfo.leafXmjs.find(function (item) {
  1145. return item.gcl_id === node.id;
  1146. });
  1147. const oldCInfo = _.find(oldChangeList, { gcl_id: node.id, mx_id: '' });
  1148. const data = {
  1149. lid: gclInfo.leafXmjs[0].gcl_id || node.id,
  1150. code: gclInfo.b_code,
  1151. name: gclInfo.name || '',
  1152. unit: gclInfo.unit || '',
  1153. unit_price: gclInfo.unit_price,
  1154. oamount: xmjInfo.quantity,
  1155. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  1156. bwmx: xmjInfo.bwmx || xmjInfo.jldy,
  1157. xmj_code: xmjInfo.code || '',
  1158. xmj_jldy: xmjInfo.jldy || '',
  1159. xmj_dwgc: xmjInfo.dwgc || '',
  1160. xmj_fbgc: xmjInfo.fbgc || '',
  1161. xmj_fxgc: xmjInfo.fxgc || '',
  1162. gcl_id: node.id,
  1163. mx_id: '',
  1164. };
  1165. if (oldCInfo) {
  1166. data.detail = oldCInfo.detail;
  1167. data.camount = oldCInfo.camount;
  1168. data.camount_expr = oldCInfo.camount_expr;
  1169. data.spamount = oldCInfo.spamount;
  1170. data.is_valuation = oldCInfo.is_valuation;
  1171. data.delimit = oldCInfo.delimit;
  1172. }
  1173. cInfo = data;
  1174. // bPaste = false;
  1175. // continue;
  1176. }
  1177. const exprQuantity = {
  1178. expr: '',
  1179. quantity: 0,
  1180. };
  1181. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1182. if (!valid) {
  1183. toastMessageUniq(hint.invalidExpr);
  1184. bPaste = false;
  1185. continue;
  1186. }
  1187. if (isNaN(exprQuantity.quantity)) {
  1188. toastMessageUniq(hint.invalidExpr);
  1189. bPaste = false;
  1190. continue;
  1191. }
  1192. validText = parseFloat(exprQuantity.quantity);
  1193. if (cInfo.id) {
  1194. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1195. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  1196. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1197. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1198. bPaste = false;
  1199. continue;
  1200. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1201. toastr.error(curRow ? '台账第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1202. bPaste = false;
  1203. continue;
  1204. }
  1205. }
  1206. if (bPaste) {
  1207. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1208. filterNodes.push(node);
  1209. if (cInfo.id) {
  1210. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1211. } else {
  1212. cInfo.camount = node.camount;
  1213. cInfo.camount_expr = exprQuantity.expr;
  1214. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1215. insertCamountData.push(cInfo);
  1216. }
  1217. } else {
  1218. filterNodes.push(node);
  1219. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1220. }
  1221. continue;
  1222. }
  1223. if (colSetting.type === 'Number') {
  1224. const num = _.toNumber(value);
  1225. if (num) {
  1226. data[colSetting.field] = num;
  1227. } else {
  1228. try {
  1229. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1230. const exprInfo = getExprInfo(colSetting.field);
  1231. if (exprInfo) {
  1232. data[exprInfo.expr] = value;
  1233. }
  1234. bPaste = true;
  1235. } catch (err) {
  1236. toastMessageUniq(hint.invalidExpr);
  1237. continue;
  1238. }
  1239. }
  1240. } else {
  1241. if (node.used && (colSetting.field === 'code' || colSetting.field ==='b_code')
  1242. && data[colSetting.field] !== '' && value === '') {
  1243. toastMessageUniq(hint.usedCode);
  1244. continue;
  1245. }
  1246. data[colSetting.field] = value;
  1247. }
  1248. if (colSetting.field === 'b_code' && value) {
  1249. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1250. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1251. });
  1252. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1253. if (ledgerOneData) {
  1254. data.name = ledgerOneData.name;
  1255. data.unit = ledgerOneData.unit;
  1256. data.unit_price = ledgerOneData.unit_price;
  1257. }
  1258. }
  1259. bPaste = true;
  1260. }
  1261. if (bPaste) {
  1262. datas.push(data);
  1263. } else {
  1264. filterNodes.push(node);
  1265. }
  1266. }
  1267. if (camountData.length > 0 || insertCamountData.length > 0) {
  1268. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  1269. changeList = result;
  1270. // 给所有filterNodes 加上is_change=1
  1271. filterNodes.forEach(function (item) {
  1272. item.is_change = 1;
  1273. });
  1274. const loadResult = { update: filterNodes };
  1275. const refreshNode = billsTree.loadPostData(loadResult);
  1276. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1277. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1278. }, function () {
  1279. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1280. return;
  1281. });
  1282. return;
  1283. }
  1284. if (datas.length > 0) {
  1285. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1286. changeList = result.changeList;
  1287. const refreshNode = tree.loadPostData(result);
  1288. if (refreshNode.update) {
  1289. refreshNode.update = refreshNode.update.concat(filterNodes);
  1290. }
  1291. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1292. }, function () {
  1293. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1294. });
  1295. } else {
  1296. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1297. }
  1298. },
  1299. clipboardPasted: function (e, info) {
  1300. const hint = {
  1301. usedUp: {type: 'error', msg: '节点已计量,不可修改单价'},
  1302. usedCode: {type: 'error', msg: '节点已计量,编号不可修改为空值'},
  1303. invalidExpr: {type: 'error', msg: '粘贴的表达式非法'},
  1304. posCode: {type: 'error', msg: '清单含有计量单元,请先删除计量单元,再修改清单编号为空'},
  1305. posQty: {type: 'error', msg: '清单含有计量单元,数量金额根据计量单元汇总计算所得,不可修改'},
  1306. };
  1307. const tree = info.sheet.zh_tree;
  1308. if (!tree) { return; }
  1309. const sortData = info.sheet.zh_tree.nodes;
  1310. const datas = [], filterNodes = [], camountData = [];
  1311. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {
  1312. let bPaste = false;
  1313. const curRow = info.cellRange.row + iRow;
  1314. const node = sortData[curRow];
  1315. if (node) {
  1316. const data = info.sheet.zh_tree.getNodeKeyData(node);
  1317. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1318. const curCol = info.cellRange.col + iCol;
  1319. const colSetting = info.sheet.zh_setting.cols[curCol];
  1320. const value = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  1321. const lPos = pos.getLedgerPos(node.id);
  1322. if (lPos && lPos.length > 0) {
  1323. if (value === '' && colSetting.field === 'b_code') {
  1324. toastMessageUniq(hint.posCode);
  1325. continue;
  1326. }
  1327. if (colSetting.field === 'sgfh_qty' || colSetting.field === 'sgfh_tp' ||
  1328. colSetting.field === 'sjcl_qty' || colSetting.field === 'sjcl_tp' ||
  1329. colSetting.field === 'qtcl_qty' || colSetting.field === 'qtcl_tp' ||
  1330. colSetting.field === 'camount' || colSetting.field === 'ca_tp' ||
  1331. colSetting.field === 'ex_qty1' || colSetting.field === 'ex_tp1') {
  1332. toastMessageUniq(hint.posQty);
  1333. continue;
  1334. }
  1335. }
  1336. if (node.used && colSetting.field === 'unit_price') {
  1337. toastMessageUniq (hint.usedUp);
  1338. continue;
  1339. }
  1340. if (colSetting.field === 'camount') {
  1341. bPaste = true;
  1342. let validText = value;
  1343. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1344. if (!cInfo) {
  1345. bPaste = false;
  1346. continue;
  1347. }
  1348. const exprQuantity = {
  1349. expr: '',
  1350. quantity: 0,
  1351. };
  1352. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  1353. if (!valid) {
  1354. toastMessageUniq(hint.invalidExpr);
  1355. bPaste = false;
  1356. continue;
  1357. }
  1358. if (isNaN(exprQuantity.quantity)) {
  1359. toastMessageUniq(hint.invalidExpr);
  1360. bPaste = false;
  1361. continue;
  1362. }
  1363. validText = parseFloat(exprQuantity.quantity);
  1364. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1365. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1366. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1367. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1368. bPaste = false;
  1369. continue;
  1370. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1371. toastr.error(curRow ? '台账第' + (curRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1372. bPaste = false;
  1373. continue;
  1374. }
  1375. if (bPaste) {
  1376. node.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  1377. filterNodes.push(node);
  1378. camountData.push({id: cInfo.id, camount: node.camount, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  1379. } else {
  1380. filterNodes.push(node);
  1381. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1382. }
  1383. continue;
  1384. }
  1385. if (colSetting.type === 'Number') {
  1386. const num = _.toNumber(value);
  1387. if (num) {
  1388. data[colSetting.field] = num;
  1389. } else {
  1390. try {
  1391. data[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(value));
  1392. } catch (err) {
  1393. toastMessageUniq(hint.invalidExpr);
  1394. continue;
  1395. }
  1396. }
  1397. } else {
  1398. if (node.used && (colSetting.field === 'code' || colSetting.field === 'b_code')
  1399. && data[colSetting.field] !== '' && value === '') {
  1400. toastMessageUniq(hint.usedCode);
  1401. continue;
  1402. }
  1403. data[colSetting.field] = value;
  1404. }
  1405. if (colSetting.field === 'b_code' && value) {
  1406. const ledgerData = _.filter(billsTree.nodes, function (item) {
  1407. return item.b_code !== null && item.b_code !== '' && !item.formc;
  1408. });
  1409. const ledgerOneData = _.find(ledgerData, { b_code: value });
  1410. if (ledgerOneData) {
  1411. data.name = ledgerOneData.name;
  1412. data.unit = ledgerOneData.unit;
  1413. data.unit_price = ledgerOneData.unit_price;
  1414. }
  1415. }
  1416. bPaste = true;
  1417. }
  1418. if (bPaste) {
  1419. datas.push(data);
  1420. } else {
  1421. filterNodes.push(node);
  1422. }
  1423. }
  1424. }
  1425. if (camountData.length > 0) {
  1426. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountData }, function (result) {
  1427. changeList = result;
  1428. const loadResult = { update: filterNodes };
  1429. const refreshNode = billsTree.loadPostData(loadResult);
  1430. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1431. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1432. }, function () {
  1433. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1434. return;
  1435. });
  1436. return;
  1437. }
  1438. if (datas.length > 0) {
  1439. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1440. changeList = result.changeList;
  1441. const refreshNode = tree.loadPostData(result);
  1442. if (refreshNode.update) {
  1443. refreshNode.update = refreshNode.update.concat(filterNodes);
  1444. }
  1445. billsTreeSpreadObj.refreshTree(info.sheet, refreshNode);
  1446. }, function () {
  1447. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1448. });
  1449. } else {
  1450. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1451. }
  1452. },
  1453. deletePress: function (sheet) {
  1454. if (!sheet.zh_setting) return;
  1455. const sel = sheet.getSelections()[0], datas = [], camountDatas = [];
  1456. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1457. let bDel = false;
  1458. const node = sheet.zh_tree.nodes[iRow];
  1459. const data = sheet.zh_tree.getNodeKeyData(node);
  1460. const cData = {};
  1461. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1462. const col = sheet.zh_setting.cols[iCol];
  1463. const style = sheet.getStyle(iRow, iCol);
  1464. if (style.locked || (['dgn_qty1', 'dgn_qty2'].indexOf(col.field) >= 0 && node.b_code)) continue;
  1465. if (col.type === 'Number' && node.settle_status === settleStatus.finish) continue;
  1466. if (['dgn_qty1', 'dgn_qty2', 'camount'].indexOf(col.field) < 0 && sheet.zh_tree.checkNodeUsed(node, pos)) {
  1467. toastr.warning('"' + (node.code || '') + (node.b_code || '') + ' ' + node.name +'"已计量,请勿修改');
  1468. return;
  1469. }
  1470. if (col.field === 'camount') {
  1471. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1472. if (!cInfo) continue;
  1473. cData.id = cInfo.id;
  1474. cData.camount = null;
  1475. cData.camount_expr = '';
  1476. cData.spamount = null;
  1477. data.camount = null;
  1478. } else {
  1479. data[col.field] = null;
  1480. const exprInfo = getExprInfo(col.field);
  1481. if (exprInfo) {
  1482. data[exprInfo.expr] = '';
  1483. }
  1484. }
  1485. bDel = true;
  1486. }
  1487. if (bDel) {
  1488. datas.push(data);
  1489. if (cData.id) camountDatas.push(cData);
  1490. }
  1491. }
  1492. if (camountDatas.length > 0) {
  1493. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  1494. changeList = result;
  1495. for (const d of datas) {
  1496. billsTreeSpreadObj.reCalcCamount(d);
  1497. }
  1498. const loadResult = { update: datas };
  1499. const refreshNode = billsTree.loadPostData(loadResult);
  1500. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1501. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1502. });
  1503. return;
  1504. }
  1505. if (datas.length > 0) {
  1506. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1507. changeList = result.changeList;
  1508. const refreshNode = sheet.zh_tree.loadPostData(result);
  1509. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1510. billsTreeSpreadObj.loadExprToInput(sheet);
  1511. });
  1512. }
  1513. },
  1514. pasteBlock: function (spread, copyInfo) {
  1515. const self = this;
  1516. const sheet = spread.getActiveSheet();
  1517. const [tree, node] = this.getDefaultSelectInfo(spread.getActiveSheet());
  1518. if (node.settle_status === settleStatus.finish) {
  1519. toastr.warning('选中的节点已结算,不可粘贴整块');
  1520. return;
  1521. }
  1522. postData(window.location.pathname + '/update', {
  1523. postType: 'paste-block',
  1524. postData: {
  1525. id: tree.getNodeKey(node),
  1526. tid: copyInfo.tid,
  1527. block: copyInfo.block,
  1528. }
  1529. }, function (data) {
  1530. changeList = data.changeList;
  1531. pos.updateDatas(data.pos);
  1532. const result = tree.loadPostData(data.ledger);
  1533. self.refreshTree(sheet, result);
  1534. const sel = sheet.getSelections()[0];
  1535. if (sel) {
  1536. sheet.setSelection(tree.nodes.indexOf(result.create[0]), sel.col, sel.rowCount, sel.colCount);
  1537. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, tree.nodes.indexOf(result.create[0])]);
  1538. }
  1539. self.refreshOperationValid(sheet);
  1540. removeLocalCache(copyBlockTag);
  1541. }, null, true);
  1542. },
  1543. topRowChanged: function (e, info) {
  1544. SpreadJsObj.saveTopAndSelect(info.sheet, ckBillsSpread);
  1545. },
  1546. editStarting(e, info) {
  1547. if (!info.sheet.zh_setting || !info.sheet.zh_tree) return;
  1548. const col = info.sheet.zh_setting.cols[info.col];
  1549. const node = info.sheet.zh_tree.nodes[info.row];
  1550. if (!node) {
  1551. info.cancel = true;
  1552. return;
  1553. }
  1554. if (col.field === 'camount') {
  1555. const cInfo = _.find(changeList, { gcl_id: node.id, mx_id: '' });
  1556. if (!cInfo) {
  1557. if (billsCol.readOnly.isSettle(node)) {
  1558. toastr.error('清单数据未完善,无法编辑申请数量');
  1559. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1560. return
  1561. }
  1562. return;
  1563. }
  1564. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  1565. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  1566. }
  1567. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  1568. info.cancel = true;
  1569. }
  1570. } else {
  1571. const exprInfo = getExprInfo(col.field);
  1572. if (exprInfo) {
  1573. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1574. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1575. }
  1576. }
  1577. switch (col.field) {
  1578. case 'code':
  1579. const posRange = pos.getLedgerPos(node.id);
  1580. info.cancel = posRange && posRange.length > 0;
  1581. break;
  1582. case 'unit_price':
  1583. info.cancel = (node.children && node.children.length > 0) || node.used || node.settle_status === settleStatus.finish;
  1584. break;
  1585. case 'sgfh_qty':
  1586. case 'sgfh_tp':
  1587. case 'sjcl_qty':
  1588. case 'sjcl_tp':
  1589. case 'qtcl_qty':
  1590. case 'qtcl_tp':
  1591. case 'deal_qty':
  1592. case 'deal_tp':
  1593. case 'ex_qty1':
  1594. case 'ex_tp1':
  1595. info.cancel = (node.children && node.children.length > 0) || node.settle_status === settleStatus.finish;
  1596. break;
  1597. case 'dgn_qty1':
  1598. case 'dgn_qty2':
  1599. info.cancel = !_.isEmpty(node.b_code || node.settle_status === settleStatus.finish);
  1600. break;
  1601. }
  1602. }
  1603. },
  1604. cut: function (sheet, sel, callback) {
  1605. if (!sheet || !sel) return;
  1606. if (sel.colCount >= sheet.zh_setting.cols.length) {
  1607. toastr.warning('请勿选中整行剪切');
  1608. return;
  1609. }
  1610. const sortData = SpreadJsObj.getSortData(sheet), datas = [];
  1611. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1612. const node = sortData[iRow];
  1613. if (node) {
  1614. const data = sheet.zh_tree.getNodeKeyData(node);
  1615. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1616. const col = sheet.zh_setting.cols[iCol];
  1617. if (col.field === 'b_code' || col.field === 'sgfh_qty' || col.field === 'sgfh_tp' ||
  1618. col.field === 'sjcl_qty' || col.field === 'sjcl_tp' ||
  1619. col.field === 'qtcl_qty' || col.field === 'qtcl_tp' ||
  1620. col.field === 'ex_qty1' || col.field === 'ex_tp1') {
  1621. const lPos = pos.getLedgerPos(node.id);
  1622. if (lPos && lPos.length > 0) {
  1623. toastr.error('不可剪切');
  1624. return;
  1625. }
  1626. }
  1627. const style = sheet.getStyle(iRow, iCol);
  1628. if (style.locked) {
  1629. toastr.error('不可剪切');
  1630. return;
  1631. }
  1632. const colSetting = sheet.zh_setting.cols[iCol];
  1633. data[colSetting.field] = null;
  1634. const exprInfo = getExprInfo(colSetting.field);
  1635. if (exprInfo) {
  1636. data[exprInfo.expr] = '';
  1637. }
  1638. }
  1639. datas.push(data);
  1640. }
  1641. }
  1642. if (datas.length > 0) {
  1643. callback();
  1644. postData(window.location.pathname + '/update', {postType: 'update', postData: datas}, function (result) {
  1645. changeList = result.changeList;
  1646. const refreshNode = sheet.zh_tree.loadPostData(result);
  1647. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1648. });
  1649. }
  1650. },
  1651. sortCode: function (sheet) {
  1652. const tree = sheet.zh_tree;
  1653. if (!tree) return;
  1654. const select = SpreadJsObj.getSelectObject(sheet);
  1655. if (!select || !select.code || select.code === '') return;
  1656. const recursiveSortCode = function (data, parentCode, children) {
  1657. if (!children || children.length === 0) return;
  1658. for (const [i, child] of children.entries()) {
  1659. if (!child.b_code || child.b_code === '') {
  1660. const code = parentCode + '-' + (i + 1);
  1661. const cData = tree.getNodeKeyData(child);
  1662. cData.code = code;
  1663. data.push(cData);
  1664. if (!tree.isLeafXmj(child)) {
  1665. recursiveSortCode(data, code, child.children);
  1666. }
  1667. }
  1668. }
  1669. };
  1670. const data = [];
  1671. recursiveSortCode(data, select.code, select.children);
  1672. if (data.length > 0) {
  1673. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1674. changeList = result.changeList;
  1675. const refreshNode = tree.loadPostData(result);
  1676. billsTreeSpreadObj.refreshTree(sheet, refreshNode);
  1677. })
  1678. }
  1679. },
  1680. reCalcCamount: function (node) {
  1681. if (node && node.b_code) {
  1682. const posData = pos.getLedgerPos(node.id) || [];
  1683. let camount = node.camount || 0;
  1684. let is_valuation = node.is_valuation || 0;
  1685. if (posData.length > 0) {
  1686. camount = 0;
  1687. for (const np of posData) {
  1688. const cInfo = _.find(changeList, { gcl_id: np.lid, mx_id: np.id });
  1689. camount = cInfo ? ZhCalc.add(camount, ZhCalc.round(cInfo.camount, findDecimal(cInfo.unit))) : camount;
  1690. if (cInfo && cInfo.is_valuation) {
  1691. is_valuation = 1;
  1692. }
  1693. }
  1694. }
  1695. node.camount = camount;
  1696. node.ca_tp = ZhCalc.mul(camount, node.unit_price, decimal.tp) || 0;
  1697. node.is_valuation = is_valuation;
  1698. }
  1699. },
  1700. _checkExprValid(expr) {
  1701. if (!expr) return [true, null];
  1702. const param = [];
  1703. let num = '', base = '';
  1704. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1705. if (/^[\d\.%]+/.test(expr[i])) {
  1706. if (base !== '') {
  1707. param.push({type: 'base', value: base});
  1708. base = '';
  1709. }
  1710. num = num + expr[i];
  1711. } else if (expr[i] === '(') {
  1712. if (num !== '') {
  1713. param.push({type: 'num', value: num});
  1714. num = '';
  1715. }
  1716. if (base !== '') {
  1717. param.push({type: 'base', value: base});
  1718. base = '';
  1719. }
  1720. param.push({type: 'left', value: '('});
  1721. } else if (expr[i] === ')') {
  1722. if (num !== '') {
  1723. param.push({type: 'num', value: num});
  1724. num = '';
  1725. }
  1726. if (base !== '') {
  1727. param.push({type: 'base', value: base});
  1728. base = '';
  1729. }
  1730. param.push({type: 'right', value: ')'});
  1731. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1732. if (num !== '') {
  1733. param.push({type: 'num', value: num});
  1734. num = '';
  1735. }
  1736. if (base !== '') {
  1737. param.push({type: 'base', value: base});
  1738. base = '';
  1739. }
  1740. param.push({type: 'calc', value: expr[i]});
  1741. } else {
  1742. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1743. }
  1744. }
  1745. if (num !== '') {
  1746. param.push({type: 'num', value: num});
  1747. num = '';
  1748. }
  1749. if (base !== '') {
  1750. param.push({type: 'base', value: base});
  1751. base = '';
  1752. }
  1753. if (param.length === 0) return true;
  1754. if (param.length > 1) {
  1755. if (param[0].value === '-' && param[1].type === 'num') {
  1756. param[1].value = '-' + param[1].value;
  1757. param.shift();
  1758. }
  1759. }
  1760. const iLen = param.length;
  1761. let iLeftCount = 0, iRightCount = 0;
  1762. for (const [i, p] of param.entries()) {
  1763. if (p.type === 'calc') {
  1764. if (i === 0 || i === iLen - 1)
  1765. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1766. }
  1767. if (p.type === 'num') {
  1768. num = p.value.replace('%', '');
  1769. if (p.value.length - num.length > 1)
  1770. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1771. num = _.toNumber(num);
  1772. if (num === undefined || num === null || _.isNaN(num))
  1773. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1774. if (i > 0) {
  1775. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1776. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1777. } else if (param[i - 1].value === '/' && num === 0) {
  1778. return [false, '输入的表达式非法:请勿除0'];
  1779. }
  1780. }
  1781. }
  1782. if (p.type === 'base') {
  1783. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1784. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1785. }
  1786. if (p.type === 'left') {
  1787. iLeftCount += 1;
  1788. if (i !== 0 && param[i-1].type !== 'calc')
  1789. return [false, '输入的表达式非法:(前应有运算符'];
  1790. }
  1791. if (p.type === 'right') {
  1792. iRightCount += 1;
  1793. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1794. return [false, '输入的表达式非法:)后应有运算符'];
  1795. if (iRightCount > iLeftCount)
  1796. return [false, '输入的表达式非法:")"前无对应的"("'];
  1797. }
  1798. }
  1799. if (iLeftCount > iRightCount)
  1800. return [false, '输入的表达式非法:"("后无对应的")"'];
  1801. return [true, ''];
  1802. },
  1803. _checkExpr: function (text, data) {
  1804. if (text) {
  1805. const num = _.toNumber(text);
  1806. if (num) {
  1807. data.quantity = num;
  1808. data.expr = '';
  1809. } else {
  1810. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1811. const [valid, msg] = this._checkExprValid(expr);
  1812. if (!valid) return [valid, msg];
  1813. data.expr = expr;
  1814. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace(new RegExp('%', 'gm'), '/100'));
  1815. // const ce = new CalcEvalMin();
  1816. // data.quantity = ce.eval(expr);
  1817. // console.log(data.quantity);
  1818. }
  1819. } else {
  1820. data.quantity = 0;
  1821. data.expr = '';
  1822. }
  1823. return [true, ''];
  1824. },
  1825. };
  1826. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  1827. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1828. billsSpread.bind(spreadNS.Events.SelectionChanged, billsTreeSpreadObj.selectionChanged);
  1829. billsSpread.bind(spreadNS.Events.topRowChanged, billsTreeSpreadObj.topRowChanged);
  1830. if (!readOnly) {
  1831. // 增删上下移升降级
  1832. $('a[name="base-opr"]').click(function () {
  1833. billsTreeSpreadObj.baseOpr(billsSheet, this.getAttribute('type'));
  1834. });
  1835. $('a[name=cpc]').click(function () {
  1836. billsSpread.commandManager().execute({
  1837. cmd: this.getAttribute('type'),
  1838. sheetName: billsSheet.name()
  1839. });
  1840. });
  1841. $('#bills-expr').bind('change onblur', function () {
  1842. if (this.readOnly) return;
  1843. const expr = $(this);
  1844. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1845. const select = billsTree.getItemsByIndex(row);
  1846. if (!select) return;
  1847. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  1848. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1849. if (field === 'camount') {
  1850. const cInfo = _.find(changeList, { gcl_id: select.id, mx_id: '' });
  1851. if (!cInfo) {
  1852. toastr.error('未勾选变更清单,无法编辑申请数量');
  1853. return;
  1854. }
  1855. const exprQuantity = {
  1856. expr: '',
  1857. quantity: 0,
  1858. };
  1859. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  1860. if (!valid) {
  1861. toastr.error(msg);
  1862. return;
  1863. }
  1864. if (isNaN(exprQuantity.quantity)) {
  1865. toastr.error('不能输入其它非数字类型字符');
  1866. return;
  1867. }
  1868. const camount = parseFloat(exprQuantity.quantity);
  1869. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  1870. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  1871. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  1872. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  1873. return;
  1874. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  1875. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  1876. return;
  1877. }
  1878. cInfo.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1879. select.camount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1880. cInfo.spamount = ZhCalc.round(camount, findDecimal(select.unit)) || 0;
  1881. cInfo.camount_expr = exprQuantity.expr;
  1882. delete cInfo.waitingLoading;
  1883. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  1884. SpreadJsObj.reLoadRowData(billsSheet, row);
  1885. billsTreeSpreadObj.reCalcCamount(select);
  1886. const loadResult = { update: [select] };
  1887. const refreshNode = billsTree.loadPostData(loadResult);
  1888. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1889. billsTreeSpreadObj.loadExprToInput(billsSheet);
  1890. }, function () {
  1891. cInfo.camount = orgValue;
  1892. cInfo.spamount = orgValue;
  1893. select.camount = orgValue;
  1894. SpreadJsObj.reLoadRowData(billsSheet, row);
  1895. });
  1896. return;
  1897. }
  1898. const data = {
  1899. id: select.id,
  1900. tender_id: select.tender_id,
  1901. ledger_id: select.ledger_id
  1902. };
  1903. const exprInfo = getExprInfo(field);
  1904. if (newValue !== '') {
  1905. const num = _.toNumber(newValue);
  1906. if (num) {
  1907. data[field] = num;
  1908. if (exprInfo) {
  1909. data[exprInfo.expr] = '';
  1910. }
  1911. } else {
  1912. try {
  1913. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  1914. if (exprInfo) {
  1915. data[exprInfo.expr] = newValue;
  1916. }
  1917. } catch (err) {
  1918. toastr.error('输入的表达式非法');
  1919. return;
  1920. }
  1921. }
  1922. } else {
  1923. data[field] = null;
  1924. if (exprInfo) {
  1925. data[exprInfo.expr] = '';
  1926. }
  1927. }
  1928. // 更新至服务器
  1929. postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
  1930. changeList = result.changeList;
  1931. const refreshNode = billsTree.loadPostData(result);
  1932. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  1933. });
  1934. });
  1935. billsSpread.bind(spreadNS.Events.EditStarting, billsTreeSpreadObj.editStarting);
  1936. billsSpread.bind(spreadNS.Events.EditEnded, billsTreeSpreadObj.editEnded);
  1937. billsSpread.bind(spreadNS.Events.ButtonClicked, billsTreeSpreadObj.buttonClicked);
  1938. billsSpread.bind(spreadNS.Events.ClipboardPasting, billsTreeSpreadObj.clipboardPasting);
  1939. billsSpread.bind(spreadNS.Events.ClipboardChanging, function (e, info) {
  1940. const copyText = SpreadJsObj.getFilterCopyText(info.sheet);
  1941. SpreadJsObj.Clipboard.setCopyData(copyText);
  1942. });
  1943. SpreadJsObj.addDeleteBind(billsSpread, billsTreeSpreadObj.deletePress);
  1944. SpreadJsObj.addCutEvents(billsSpread, billsTreeSpreadObj.cut);
  1945. }
  1946. // 右键菜单
  1947. let batchInsertObj;
  1948. $.contextMenu.types.batchInsert = function (item, opt, root) {
  1949. const self = this;
  1950. if ($.isFunction(item.icon)) {
  1951. item._icon = item.icon.call(this, this, $t, key, item);
  1952. } else {
  1953. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  1954. // to enable font awesome
  1955. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  1956. } else {
  1957. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  1958. }
  1959. }
  1960. this.addClass(item._icon);
  1961. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="20" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  1962. .appendTo(this);
  1963. const $input = $obj.find('input');
  1964. const event = () => {
  1965. if (self.hasClass('context-menu-disabled')) return;
  1966. item.batchInsert($input[0], root);
  1967. };
  1968. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  1969. $input.click((e) => {e.stopPropagation();})
  1970. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  1971. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  1972. };
  1973. const billsContextMenuOptions = {
  1974. selector: '#bills-spread',
  1975. build: function ($trigger, e) {
  1976. const target = SpreadJsObj.safeRightClickSelection($trigger, e, billsSpread);
  1977. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1978. },
  1979. items: {}
  1980. };
  1981. if (!readOnly) {
  1982. billsContextMenuOptions.items.create = {
  1983. name: '新增',
  1984. icon: 'fa-sign-in',
  1985. callback: function (key, opt) {
  1986. billsTreeSpreadObj.baseOpr(billsSheet, 'add');
  1987. },
  1988. disabled: function (key, opt) {
  1989. const sheet = billsSheet;
  1990. const selection = sheet.getSelections();
  1991. const sel = selection ? selection[0] : sheet.getSelections()[0];
  1992. const row = sel ? sel.row : -1;
  1993. const tree = sheet.zh_tree;
  1994. if (!tree) return true;
  1995. const first = sheet.zh_tree.nodes[row];
  1996. const valid = !sheet.zh_setting.readOnly;
  1997. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  1998. }
  1999. };
  2000. billsContextMenuOptions.items.delete = {
  2001. name: '删除',
  2002. icon: 'fa-remove',
  2003. callback: function (key, opt) {
  2004. billsTreeSpreadObj.baseOpr(billsSheet, 'delete');
  2005. },
  2006. disabled: function (key, opt) {
  2007. const sheet = billsSheet;
  2008. const selection = sheet.getSelections();
  2009. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2010. const row = sel ? sel.row : -1;
  2011. const tree = sheet.zh_tree;
  2012. if (!tree) return true;
  2013. const first = sheet.zh_tree.nodes[row];
  2014. let last = first, sameParent = true, nodeUsed = first.used, settleFinish = first.settle_status === settleStatus.finish;
  2015. if (sel.rowCount > 1 && first) {
  2016. for (let r = 1; r < sel.rowCount; r++) {
  2017. const rNode = tree.nodes[sel.row + r];
  2018. if (!rNode) {
  2019. sameParent = false;
  2020. break;
  2021. }
  2022. if (!rNode.formc) {
  2023. return true;
  2024. }
  2025. nodeUsed = nodeUsed || rNode.used;
  2026. settleFinish = settleFinish || rNode.settle_status === settleStatus.finish;
  2027. if (rNode.level > first.level) continue;
  2028. if ((rNode.level < first.level) || (rNode.level === first.level && rNode.pid !== first.pid)) {
  2029. sameParent = false;
  2030. break;
  2031. }
  2032. last = rNode;
  2033. }
  2034. }
  2035. const valid = !sheet.zh_setting.readOnly;
  2036. return !(valid && first && sameParent && !(first.level === 1 && first.node_type) && !nodeUsed && first.formc && !settleFinish);
  2037. }
  2038. };
  2039. billsContextMenuOptions.items.sprBase = '----';
  2040. }
  2041. billsContextMenuOptions.items.copyBlock = {
  2042. name: '复制整块',
  2043. icon: 'fa-files-o',
  2044. callback: function (key, opt) {
  2045. const copyBlockList = [];
  2046. const sheet = billsSheet;
  2047. const sel = sheet.getSelections()[0];
  2048. let iRow = sel.row;
  2049. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2050. while (iRow < sel.row + sel.rowCount) {
  2051. const node = sheet.zh_tree.nodes[iRow];
  2052. if (node.ledger_pid !== pid) {
  2053. toastr.error('仅可同时选中同层节点');
  2054. return;
  2055. }
  2056. const posterity = sheet.zh_tree.getPosterity(node);
  2057. iRow += posterity.length + 1;
  2058. posterity.unshift(node);
  2059. copyBlockList.push(sheet.zh_tree.getDefaultData(posterity));
  2060. }
  2061. for (const cbl of copyBlockList) {
  2062. for (const b of cbl) {
  2063. const posRange = pos.getLedgerPos(b.id);
  2064. if (posRange && posRange.length > 0) b.pos = posRange;
  2065. }
  2066. }
  2067. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2068. },
  2069. visible: function (key, opt) {
  2070. const sheet = billsSheet;
  2071. const selection = sheet.getSelections();
  2072. const row = selection[0].row;
  2073. const select = billsTree.nodes[row];
  2074. return select;
  2075. },
  2076. disabled: function (key, opt) {
  2077. const sheet = billsSheet;
  2078. const selection = sheet.getSelections();
  2079. const row = selection[0].row;
  2080. const select = billsTree.nodes[row];
  2081. return select && select.level <= 1;
  2082. }
  2083. };
  2084. billsContextMenuOptions.items.copyBlockXmj = {
  2085. name: '复制整块(只复制项目节)',
  2086. icon: 'fa-files-o',
  2087. callback: function (key, opt) {
  2088. const copyBlockList = [];
  2089. const sheet = billsSheet;
  2090. const sel = sheet.getSelections()[0];
  2091. let iRow = sel.row;
  2092. const pid = sheet.zh_tree.nodes[iRow].ledger_pid;
  2093. while (iRow < sel.row + sel.rowCount) {
  2094. const node = sheet.zh_tree.nodes[iRow];
  2095. if (node.ledger_pid !== pid) {
  2096. toastr.error('仅可同时选中同层节点');
  2097. return;
  2098. }
  2099. const posterity = sheet.zh_tree.getPosterity(node);
  2100. iRow += posterity.length + 1;
  2101. const copyPosterity = posterity.filter(x => { return !x.b_code; });
  2102. copyPosterity.unshift(node);
  2103. const copyData = sheet.zh_tree.getDefaultData(copyPosterity);
  2104. for (const p of copyData) {
  2105. const children = copyData.filter(y => {return y.ledger_pid === p.ledger_id}) || [];
  2106. p.is_leaf = children.length === 0;
  2107. }
  2108. copyBlockList.push(copyData);
  2109. }
  2110. setLocalCache(copyBlockTag, JSON.stringify({ block: copyBlockList }));
  2111. },
  2112. visible: function (key, opt) {
  2113. const sheet = billsSheet;
  2114. const selection = sheet.getSelections();
  2115. const row = selection[0].row;
  2116. const select = billsTree.nodes[row];
  2117. return select;
  2118. },
  2119. disabled: function (key, opt) {
  2120. const sheet = billsSheet;
  2121. const selection = sheet.getSelections();
  2122. const row = selection[0].row;
  2123. const select = billsTree.nodes[row];
  2124. return select && select.level <= 1;
  2125. }
  2126. };
  2127. if (!readOnly) {
  2128. billsContextMenuOptions.items.pasteBlock = {
  2129. name: '粘贴整块',
  2130. icon: 'fa-clipboard',
  2131. disabled: function (key, opt) {
  2132. //const block = treeOperationObj.block || [];
  2133. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2134. return !(copyInfo && copyInfo.block && copyInfo.block.length > 0);
  2135. },
  2136. callback: function (key, opt) {
  2137. //const block = treeOperationObj.block || [];
  2138. const copyInfo = JSON.parse(getLocalCache(copyBlockTag));
  2139. if (copyInfo.block.length > 0) {
  2140. billsTreeSpreadObj.pasteBlock(billsSpread, copyInfo);
  2141. } else {
  2142. document.execCommand('paste');
  2143. }
  2144. },
  2145. visible: function (key, opt) {
  2146. return !readOnly;
  2147. }
  2148. };
  2149. billsContextMenuOptions.items.sprBlock = '----';
  2150. }
  2151. if (!readOnly) {
  2152. billsContextMenuOptions.items.batchInsert = {
  2153. name: '批量插入',
  2154. type: 'batchInsert',
  2155. value: '2',
  2156. icon: 'fa-sign-in',
  2157. batchInsert: function (obj, root) {
  2158. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  2159. obj.value = obj.max;
  2160. toastr.warning('批量插入不可多于' + obj.max);
  2161. } else if (_.toNumber(obj.value) < _.toNumber(obj.min)) {
  2162. obj.value = obj.min;
  2163. toastr.warning('批量插入不可少于' + obj.min);
  2164. } else {
  2165. billsTreeSpreadObj.baseOpr(billsSheet, 'add', parseInt(obj.value));
  2166. root.$menu.trigger('contextmenu:hide');
  2167. }
  2168. },
  2169. disabled: function (key, opt) {
  2170. const sheet = billsSheet;
  2171. const selection = sheet.getSelections();
  2172. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2173. const row = sel ? sel.row : -1;
  2174. const tree = sheet.zh_tree;
  2175. if (!tree) return true;
  2176. const first = sheet.zh_tree.nodes[row];
  2177. const valid = !sheet.zh_setting.readOnly;
  2178. return !(valid && first && first.level > 1 && first.settle_status !== settleStatus.finish);
  2179. }
  2180. };
  2181. billsContextMenuOptions.items.batchInsertBillsPos = {
  2182. name: '批量插入清单-计量单元',
  2183. icon: 'fa-sign-in',
  2184. visible: function (key, opt) {
  2185. return false;
  2186. },
  2187. disabled: function (key, opt) {
  2188. if (!isTz) return true;
  2189. const select = SpreadJsObj.getSelectObject(billsSheet);
  2190. if (select) {
  2191. if (select.code && select.code !== '') {
  2192. return !billsTree.isLeafXmj(select) || select.settle_status === settleStatus.finish;
  2193. } else {
  2194. const parent = billsTree.getParent(select);
  2195. return !(parent && billsTree.isLeafXmj(parent)) || !(parent && parent.settle_status === settleStatus.finish);
  2196. }
  2197. } else {
  2198. return false;
  2199. }
  2200. },
  2201. callback: function (key, opt) {
  2202. if (!batchInsertObj) {
  2203. batchInsertObj = new BatchInsertBillsPosObj($('#batch'));
  2204. } else {
  2205. batchInsertObj.initView();
  2206. }
  2207. $('#batch').modal('show');
  2208. }
  2209. };
  2210. }
  2211. billsContextMenuOptions.items.sprTag = '----';
  2212. billsContextMenuOptions.items.showLast = {
  2213. name: '显示至最底层',
  2214. callback: function (key, opt, menu, e) {
  2215. const node = SpreadJsObj.getSelectObject(billsSheet);
  2216. setTimeout(() => {
  2217. showWaitingView();
  2218. billsTree.expandByCustom(x => {
  2219. return x.expanded || (x.id === node.id) || (x.full_path.indexOf(node.ledger_id + '-') >= 0);
  2220. });
  2221. SpreadJsObj.refreshTreeRowVisible(billsSheet);
  2222. closeWaitingView();
  2223. }, 100);
  2224. },
  2225. };
  2226. $.contextMenu(billsContextMenuOptions);
  2227. // 计量单元 相关方法&绑定spreadjs事件
  2228. const posSpreadObj = {
  2229. refreshOperationValid: function (sheet, selection) {
  2230. const setObjEnable = function (obj, enable) {
  2231. if (enable) {
  2232. obj.removeClass('disabled');
  2233. } else {
  2234. obj.addClass('disabled');
  2235. }
  2236. };
  2237. const invalidAll = function () {
  2238. setObjEnable($('a[name=pos-opr][type=up-move]'), false);
  2239. setObjEnable($('a[name=pos-opr][type=down-move]'), false);
  2240. };
  2241. const sel = selection ? selection[0] : sheet.getSelections()[0];
  2242. const row = sel ? sel.row : -1;
  2243. const first = sheet.zh_data[row];
  2244. if (!first) {
  2245. invalidAll();
  2246. return;
  2247. }
  2248. let last = first;
  2249. if (sel.rowCount > 1 && first) {
  2250. for (let r = 1; r < sel.rowCount; r++) {
  2251. const rNode = sheet.zh_data[sel.row + r];
  2252. if (!rNode) break;
  2253. last = rNode;
  2254. }
  2255. }
  2256. const preNode = sheet.zh_data[row - 1];
  2257. const valid = !sheet.zh_setting.readOnly;
  2258. setObjEnable($('a[name=pos-opr][type=up-move]'), valid && first && preNode && first.formc);
  2259. setObjEnable($('a[name=pos-opr][type=down-move]'), valid && first && (sheet.zh_data.indexOf(last) < sheet.zh_data.length - 1) && first.formc);
  2260. },
  2261. loadExprToInput: function () {
  2262. const sel = posSheet.getSelections()[0];
  2263. if (!sel) return;
  2264. const col = posSheet.zh_setting.cols[sel.col];
  2265. const cell = posSheet.getCell(sel.col, sel.col);
  2266. if (col && col.field === 'camount') {
  2267. const data = SpreadJsObj.getSelectObject(posSheet);
  2268. if (data) {
  2269. const cInfo = _.find(changeList, { gcl_id: data.lid, mx_id: data.id });
  2270. if (!cInfo) {
  2271. $('#pos-expr').val('').attr('readOnly', true);
  2272. $('#pos-expr').removeAttr('data-row');
  2273. } else {
  2274. const value = cInfo.camount_expr ? cInfo.camount_expr : cInfo.camount;
  2275. $('#pos-expr').val(value).attr('field', col.field).attr('org', cInfo.camount)
  2276. .attr('readOnly', posCol.readOnly.isSettle(data)).attr('data-row', sel.row);
  2277. }
  2278. } else {
  2279. $('#pos-expr').val('').attr('readOnly', true);
  2280. $('#pos-expr').removeAttr('data-row');
  2281. }
  2282. } else if (col && col.type === 'Number') {
  2283. const data = SpreadJsObj.getSelectObject(posSheet);
  2284. if (data) {
  2285. const exprInfo = getExprInfo(col.field);
  2286. const value = exprInfo
  2287. ? (data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field])
  2288. : data[col.field];
  2289. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  2290. .attr('readOnly', readOnly || !data.formc || data.settle_status === settleStatus.finish).attr('data-row', sel.row);
  2291. } else {
  2292. $('#pos-expr').val('').attr('readOnly', true);
  2293. $('#pos-expr').removeAttr('data-row');
  2294. }
  2295. } else {
  2296. $('#pos-expr').val('').attr('readOnly', true);
  2297. $('#pos-expr').removeAttr('data-row');
  2298. }
  2299. },
  2300. /**
  2301. * 加载计量单元 根据当前台账选择节点
  2302. */
  2303. loadCurPosData: function () {
  2304. const node = SpreadJsObj.getSelectObject(billsSheet);
  2305. // SpreadJsObj.initSpreadSettingEvents(posSpreadSetting, posCol);
  2306. // SpreadJsObj.initSheet(posSheet, posSpreadSetting);
  2307. if (node) {
  2308. const posData = pos.getLedgerPos(node.id) || [];
  2309. console.log(posData);
  2310. SpreadJsObj.loadSheetData(posSheet, 'data', posData);
  2311. posSheet.zh_setting.readOnly = readOnly || (node.used && posData.length === 0) || (node.settle_status && node.settle_status === settleStatus.finish);
  2312. } else {
  2313. SpreadJsObj.loadSheetData(posSheet, 'data', []);
  2314. posSheet.zh_setting.readOnly = true;
  2315. }
  2316. SpreadJsObj.massOperationSheet(posSheet, function () {
  2317. if (posSheet.zh_setting) {
  2318. posSheet.zh_setting.cols.forEach(function (col, i) {
  2319. for (let iRow = 0; iRow < posSheet.getRowCount(); iRow++) {
  2320. if (i !== 0 && col.field !== 'camount' && col.field !== 'is_valuation') {
  2321. posSheet.getCell(iRow, i).locked((posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].formc) || posSheet.zh_setting.readOnly || false);
  2322. } else {
  2323. let lock = false;
  2324. if (!posSheet.zh_data[iRow]) {
  2325. lock = true;
  2326. }
  2327. if (col.field === 'camount' && posCol.readOnly.isSettle(posSheet.zh_data[iRow])) {
  2328. lock = true;
  2329. }
  2330. posSheet.getCell(iRow, i).locked(lock || (posSheet.zh_data[iRow] && !posSheet.zh_data[iRow].name) || posSheet.zh_setting.readOnly || false);
  2331. }
  2332. }
  2333. });
  2334. }
  2335. });
  2336. // SpreadJsObj.refreshSheetReadOnly(posSheet);
  2337. posSpreadObj.loadExprToInput();
  2338. posSpreadObj.refreshOperationValid(posSheet);
  2339. },
  2340. baseOpr: function (sheet, type) {
  2341. const data = {
  2342. postType: 'pos',
  2343. posPostType: type === 'delete' ? type : 'update',
  2344. postData: [],
  2345. };
  2346. const selection = sheet.getSelections();
  2347. const row = selection[0].row, count = selection[0].rowCount;
  2348. const first = sheet.zh_data[row];
  2349. if (type === 'delete') {
  2350. for (let iRow = 0; iRow < count; iRow++) {
  2351. const posData = sheet.zh_data[iRow + row];
  2352. if (posData) {
  2353. if (posData.used) {
  2354. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2355. return;
  2356. }
  2357. if (posData.settle_status) {
  2358. toastr.error('"' + posData.name + '"已结算,请勿删除');
  2359. return;
  2360. }
  2361. data.postData.push(sheet.zh_data[iRow + row].id);
  2362. }
  2363. }
  2364. } else if (type === 'up-move') {
  2365. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  2366. for (let iRow = 0; iRow < count; iRow++) {
  2367. const posData = sheet.zh_data[iRow + row];
  2368. if (posData) {
  2369. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row - 1].porder});
  2370. preUpdate.porder = posData.porder;
  2371. }
  2372. }
  2373. data.postData.push(preUpdate);
  2374. } else if (type === 'down-move') {
  2375. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  2376. for (let iRow = count - 1; iRow >= 0; iRow--) {
  2377. const posData = sheet.zh_data[iRow + row];
  2378. if (posData) {
  2379. data.postData.push({id: posData.id, lid: posData.lid, porder: sheet.zh_data[iRow + row + 1].porder});
  2380. nextUpdate.porder = posData.porder;
  2381. }
  2382. }
  2383. data.postData.push(nextUpdate);
  2384. } else if (type === 'add') {
  2385. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2386. if (billsNode.settle_status === settleStatus.finish) {
  2387. toastr.warning('清单已结算,不可新增计量单元');
  2388. return;
  2389. }
  2390. }
  2391. if (data.postData.length > 0) {
  2392. postData(window.location.pathname + '/update', data, function (result) {
  2393. changeList = result.changeList;
  2394. if (type === 'delete') {
  2395. pos.removeDatas(result.pos);
  2396. sheet.deleteRows(row, count);
  2397. const loadResult = billsTree.loadPostData(result.ledger);
  2398. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2399. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2400. posSpreadObj.refreshOperationValid(posSheet);
  2401. } else {
  2402. pos.updateDatas(result.pos);
  2403. const sel = selection[0];
  2404. if (sel) {
  2405. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  2406. SpreadJsObj.reloadRowsBackColor(sheet, [sel.row, sheet.zh_data.indexOf(first)]);
  2407. }
  2408. posSpreadObj.loadCurPosData();
  2409. }
  2410. });
  2411. }
  2412. },
  2413. editStarting: function (e, info) {
  2414. posSpreadObj.billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2415. const sel = info.sheet.getSelections();
  2416. if (!sel || !sel[0]) return;
  2417. const col = info.sheet.zh_setting.cols[sel[0].col];
  2418. const node = SpreadJsObj.getSelectObject(info.sheet);
  2419. const exprInfo = getExprInfo(col.field);
  2420. if (col.field === 'camount') {
  2421. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2422. if (!cInfo) {
  2423. if (posCol.readOnly.isSettle(node)) {
  2424. toastr.error('清单数据未完善,无法编辑申请数量');
  2425. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2426. return
  2427. }
  2428. return
  2429. }
  2430. if (cInfo.camount_expr && cInfo.camount_expr !== '') {
  2431. info.sheet.getCell(info.row, info.col).text(cInfo.camount_expr);
  2432. }
  2433. } else if (node && exprInfo) {
  2434. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  2435. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  2436. }
  2437. }
  2438. if (col.type === 'Number' && node.settle_status === settleStatus.finish) {
  2439. info.cancel = true;
  2440. }
  2441. },
  2442. buttonClicked: function (e, info) {
  2443. if (info.sheet.zh_setting) {
  2444. const select = SpreadJsObj.getSelectObject(info.sheet);
  2445. const col = info.sheet.zh_setting.cols[info.col];
  2446. if (col.field === 'is_change') {
  2447. if (posCol.readOnly.isChangeList(select)) {
  2448. info.sheet.setValue(info.row, info.col, !select || !select.is_change ? 0 : 1);
  2449. return
  2450. }
  2451. if (info.sheet.isEditing()) {
  2452. info.sheet.endEdit(true);
  2453. }
  2454. const is_change = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2455. // const valutaionCol = _.findIndex(info.sheet.zh_setting.cols, { field: 'is_valuation' });
  2456. if (is_change) {
  2457. makeGclGatherData();
  2458. const gclInfo = _.find(gclGatherData, function (item) {
  2459. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: select.lid, mx_id: select.id });
  2460. });
  2461. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: select.id });
  2462. const oldCInfo = _.find(oldChangeList, { gcl_id: select.lid, mx_id: select.id });
  2463. const data = {
  2464. lid: select.lid,
  2465. code: gclInfo.b_code,
  2466. name: gclInfo.name || '',
  2467. unit: gclInfo.unit || '',
  2468. unit_price: gclInfo.unit_price,
  2469. oamount: xmjInfo.quantity,
  2470. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2471. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2472. xmj_code: xmjInfo.code || '',
  2473. xmj_jldy: xmjInfo.jldy || '',
  2474. xmj_dwgc: xmjInfo.dwgc || '',
  2475. xmj_fbgc: xmjInfo.fbgc || '',
  2476. xmj_fxgc: xmjInfo.fxgc || '',
  2477. gcl_id: select.lid,
  2478. mx_id: select.id,
  2479. }
  2480. if (oldCInfo) {
  2481. data.detail = oldCInfo.detail;
  2482. data.camount = oldCInfo.camount;
  2483. data.camount_expr = oldCInfo.camount_expr;
  2484. data.spamount = oldCInfo.spamount;
  2485. data.is_valuation = oldCInfo.is_valuation;
  2486. data.delimit = oldCInfo.delimit;
  2487. }
  2488. // 更新至服务器
  2489. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [data]}, function (result) {
  2490. changeList = result.changeList;
  2491. select.is_change = 1;
  2492. select.is_valuation = data.is_valuation !== undefined ? data.is_valuation : 1;
  2493. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2494. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2495. if (_.findIndex(changeList, { gcl_id: select.lid }) !== -1) {
  2496. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2497. billsNode.is_change = 1;
  2498. billsTreeSpreadObj.reCalcCamount(billsNode);
  2499. const loadResult = { update: [billsNode] };
  2500. const refreshNode = billsTree.loadPostData(loadResult);
  2501. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2502. }
  2503. }, function () {
  2504. info.sheet.setValue(info.row, info.col, 0);
  2505. });
  2506. } else {
  2507. if (changeOrder && _.findIndex(oldChangeList, { gcl_id: select.lid, mx_id: select.id }) !== -1) {
  2508. toastr.warning('插入台账清单功能下无法从这移除已勾选清单');
  2509. info.sheet.setValue(info.row, info.col, 1);
  2510. return
  2511. }
  2512. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2513. if (_.find(changeUsedData, { cbid: cInfo.id })) {
  2514. toastr.warning('该计量单元已被使用,无法取消变更');
  2515. info.sheet.setValue(info.row, info.col, 1);
  2516. return
  2517. } else if (checkIsSettle(cInfo)) {
  2518. toastr.warning('该计量单元已结算,无法取消变更');
  2519. info.sheet.setValue(info.row, info.col, 1);
  2520. return
  2521. } else {
  2522. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'del-change-list', ids: [cInfo.id] }, function (result) {
  2523. changeList = result.changeList;
  2524. select.is_change = 0;
  2525. select.is_valuation = 0;
  2526. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2527. // info.sheet.setValue(info.row, valutaionCol, 0);
  2528. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2529. billsTreeSpreadObj.reCalcCamount(billsNode);
  2530. // 判断是否只剩一个,并同步去勾
  2531. if (_.findIndex(changeList, { gcl_id: select.lid }) === -1) {
  2532. billsNode.is_change = 0;
  2533. }
  2534. const loadResult = { update: [billsNode] };
  2535. const refreshNode = billsTree.loadPostData(loadResult);
  2536. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2537. }, function () {
  2538. info.sheet.setValue(info.row, info.col, 1);
  2539. });
  2540. }
  2541. }
  2542. } else if (col.field === 'is_valuation') {
  2543. if (!posCol.getValue.isChange(select)) {
  2544. toastr.warning('请先勾选变更清单才能勾选计价');
  2545. info.sheet.setValue(info.row, info.col, !select || !select.is_valuation ? 0 : 1);
  2546. return;
  2547. }
  2548. if (info.sheet.isEditing()) {
  2549. info.sheet.endEdit(true);
  2550. }
  2551. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  2552. if (_.findIndex(changeUsedData, { cbid: cInfo.id }) !== -1) {
  2553. toastr.warning('该变更清单已被调用,无法更改计价');
  2554. info.sheet.setValue(info.row, info.col, cInfo.is_valuation);
  2555. return;
  2556. }
  2557. const is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2558. // select.is_valuation = is_valuation;
  2559. cInfo.is_valuation = is_valuation;
  2560. delete cInfo.waitingLoading;
  2561. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  2562. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2563. info.sheet.setValue(info.row, info.col, is_valuation);
  2564. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2565. SpreadJsObj.reLoadRowData(billsSheet, billsTree.getNodeIndex(billsNode));
  2566. }, function () {
  2567. select.is_valuation = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  2568. cInfo.is_valuation = select.is_valuation;
  2569. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2570. });
  2571. }
  2572. }
  2573. },
  2574. /**
  2575. * 编辑单元格响应事件
  2576. * @param {Object} e
  2577. * @param {Object} info
  2578. */
  2579. editEnded: function (e, info) {
  2580. if (!info.sheet.zh_setting) {
  2581. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2582. return;
  2583. }
  2584. const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
  2585. const node = posSpreadObj.billsNode;
  2586. const col = info.sheet.zh_setting.cols[info.col];
  2587. if (col.field === 'is_change' || col.field === 'is_valuation') {
  2588. return;
  2589. }
  2590. if (col.field === 'camount') {
  2591. if (!node) {
  2592. toastr.error('数据错误,请选择台账节点后再试');
  2593. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2594. return;
  2595. }
  2596. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  2597. if (!cInfo) {
  2598. if (posCol.readOnly.isSettle(posData)) {
  2599. toastr.error('清单数据未完善,无法编辑申请数量');
  2600. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2601. return
  2602. }
  2603. makeGclGatherData();
  2604. const gclInfo = _.find(gclGatherData, function (item) {
  2605. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  2606. });
  2607. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  2608. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  2609. const data = {
  2610. lid: posData.lid,
  2611. code: gclInfo.b_code,
  2612. name: gclInfo.name || '',
  2613. unit: gclInfo.unit || '',
  2614. unit_price: gclInfo.unit_price,
  2615. oamount: xmjInfo.quantity,
  2616. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  2617. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  2618. xmj_code: xmjInfo.code || '',
  2619. xmj_jldy: xmjInfo.jldy || '',
  2620. xmj_dwgc: xmjInfo.dwgc || '',
  2621. xmj_fbgc: xmjInfo.fbgc || '',
  2622. xmj_fxgc: xmjInfo.fxgc || '',
  2623. gcl_id: posData.lid,
  2624. mx_id: posData.id,
  2625. }
  2626. if (oldCInfo) {
  2627. data.detail = oldCInfo.detail;
  2628. data.camount = oldCInfo.camount;
  2629. data.camount_expr = oldCInfo.camount_expr;
  2630. data.spamount = oldCInfo.spamount;
  2631. data.is_valuation = oldCInfo.is_valuation;
  2632. data.delimit = oldCInfo.delimit;
  2633. }
  2634. cInfo = data;
  2635. // toastr.error('未勾选变更清单,无法编辑申请数量');
  2636. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2637. // return;
  2638. }
  2639. let validText = info.editingText ? trimInvalidChar(info.editingText) : '';
  2640. const orgValue = validText && validText !== ''
  2641. ? (_.toNumber(validText) ? cInfo.camount : cInfo.camount_expr)
  2642. : (cInfo.camount_expr && cInfo.camount_expr !== '' ? cInfo.camount_expr : cInfo.camount);
  2643. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  2644. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2645. return;
  2646. }
  2647. const exprQuantity = {
  2648. expr: '',
  2649. quantity: 0,
  2650. };
  2651. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  2652. if (!valid) {
  2653. toastr.error(msg);
  2654. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2655. return;
  2656. }
  2657. if (isNaN(exprQuantity.quantity)) {
  2658. toastr.error('不能输入其它非数字类型字符');
  2659. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2660. return;
  2661. }
  2662. validText = parseFloat(exprQuantity.quantity);
  2663. if (cInfo.id) {
  2664. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  2665. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  2666. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  2667. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  2668. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2669. return;
  2670. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  2671. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  2672. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2673. return;
  2674. }
  2675. }
  2676. cInfo[col.field] = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2677. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  2678. cInfo.camount_expr = exprQuantity.expr;
  2679. delete cInfo.waitingLoading;
  2680. if (cInfo.id) {
  2681. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type: 'update', updateData: cInfo }, function (result) {
  2682. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2683. const billsNode = node;
  2684. billsTreeSpreadObj.reCalcCamount(billsNode);
  2685. const loadResult = {update: [billsNode]};
  2686. const refreshNode = billsTree.loadPostData(loadResult);
  2687. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2688. }, function () {
  2689. cInfo[col.field] = orgValue;
  2690. cInfo.spamount = orgValue;
  2691. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2692. });
  2693. } else {
  2694. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {type: 'add-change-list', postData: [cInfo]}, function (result) {
  2695. changeList = result.changeList;
  2696. posData.is_change = 1;
  2697. posData.is_valuation = cInfo.is_valuation !== undefined ? cInfo.is_valuation : 1;
  2698. posData.camount = cInfo.camount !== undefined ? cInfo.camount : null;
  2699. posData.ca_tp = cInfo.camount !== undefined ? ZhCalc.mul(cInfo.camount, cInfo.unit_price, decimal.tp) : null;
  2700. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2701. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2702. // info.sheet.setValue(info.row, valutaionCol, data.is_valuation !== undefined ? data.is_valuation : 1);
  2703. if (_.findIndex(changeList, { gcl_id: posData.lid }) !== -1) {
  2704. billsNode.is_change = 1;
  2705. }
  2706. billsTreeSpreadObj.reCalcCamount(billsNode);
  2707. const loadResult = { update: [billsNode] };
  2708. const refreshNode = billsTree.loadPostData(loadResult);
  2709. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2710. }, function () {
  2711. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2712. });
  2713. }
  2714. return;
  2715. }
  2716. const orgText = posData ? posData[col.field] : null;
  2717. const newText = col.wordWrap ? info.editingText : trimInvalidChar(info.editingText);
  2718. if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
  2719. if (!node) {
  2720. toastr.error('数据错误,请选择台账节点后再试');
  2721. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2722. return;
  2723. } else if (newText && newText !== '' && node.children && node.children.length > 0) {
  2724. toastr.error('父节点不可插入计量单元');
  2725. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2726. return;
  2727. } else if (newText && newText !== '' && (!node.b_code || node.b_code === '')) {
  2728. toastr.error('项目节不可插入计量单元');
  2729. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2730. return;
  2731. }
  2732. const data = {postType: 'pos'};
  2733. if (col.field === 'name') {
  2734. if (newText === '' && posData) {
  2735. toastr.error('部位名称不可为空', 'error');
  2736. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2737. return;
  2738. } else if (!posData) {
  2739. if (newText && newText !== '') {
  2740. data.posPostType = 'add';
  2741. const sortData = info.sheet.zh_data;
  2742. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  2743. data.postData = { name: newText, lid: node.id, porder: order};
  2744. if (node.settle_status === settleStatus.finish) {
  2745. toastr.error('已结算清单不可插入计量单元');
  2746. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2747. return;
  2748. }
  2749. } else {
  2750. return;
  2751. }
  2752. } else {
  2753. data.posPostType = 'update';
  2754. data.postData = {id: posData.id, name: newText};
  2755. if (col.type === 'Number' && posData.settle_status === settleStatus.finish) {
  2756. toastr.error('计量单元已结算,不可修改');
  2757. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2758. return;
  2759. }
  2760. }
  2761. } else if (!posData) {
  2762. toastr.warning('新增计量单元请先输入名称');
  2763. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2764. return;
  2765. } else {
  2766. data.posPostType = 'update';
  2767. data.postData = {id: posData.id};
  2768. if (col.type === 'Number') {
  2769. const exprInfo = getExprInfo(col.field);
  2770. const num = _.toNumber(newText);
  2771. if (_.isFinite(num)) {
  2772. data.postData[col.field] = num;
  2773. if (exprInfo) {
  2774. data.postData[exprInfo.expr] = '';
  2775. }
  2776. } else {
  2777. try {
  2778. data.postData[col.field] = ZhCalc.mathCalcExpr(transExpr(newText));
  2779. if (exprInfo) {
  2780. data.postData[exprInfo.expr] = newText;
  2781. }
  2782. } catch(err) {
  2783. toastr.error('输入的表达式非法');
  2784. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2785. return;
  2786. }
  2787. }
  2788. } else if (col.field.indexOf('_expr') > 0) {
  2789. const exprInfo = getExprInfo(col.field, true);
  2790. if (!exprInfo) return;
  2791. if (newText) {
  2792. try {
  2793. data.postData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(newText));
  2794. data.postData[exprInfo.expr] = newText;
  2795. } catch(err) {
  2796. toastr.error('输入的表达式非法');
  2797. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2798. return;
  2799. }
  2800. } else {
  2801. data.postData[exprInfo.qty] = 0;
  2802. data.postData[exprInfo.expr] = '';
  2803. }
  2804. } else {
  2805. data.postData[col.field] = newText;
  2806. }
  2807. }
  2808. postData(window.location.pathname + '/update', data, function (result) {
  2809. changeList = result.changeList;
  2810. const updateRst = pos.updateDatas(result.pos);
  2811. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  2812. if (updateRst.create.length > 0) {
  2813. posSpreadObj.loadCurPosData();
  2814. } else {
  2815. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2816. }
  2817. const loadResult = billsTree.loadPostData(result.ledger);
  2818. // 判断是否只剩一个,并同步去勾
  2819. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2820. // billsNode.is_change = ? 1 : 0;
  2821. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2822. billsNode.is_change = 1;
  2823. } else {
  2824. billsNode.is_change = 0;
  2825. billsNode.is_valuation = 0;
  2826. billsNode.camount = null;
  2827. billsNode.ca_tp = null;
  2828. }
  2829. if (loadResult.update) {
  2830. const r = _.find(loadResult.update, { id: billsNode.id });
  2831. r.is_change = billsNode.is_change;
  2832. } else {
  2833. loadResult.update = [billsNode];
  2834. }
  2835. const refreshNode = billsTree.loadPostData(loadResult);
  2836. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2837. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2838. }, function () {
  2839. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2840. });
  2841. },
  2842. /**
  2843. * 删除按钮响应事件
  2844. * @param sheet
  2845. */
  2846. deletePress: function (sheet) {
  2847. if (!sheet.zh_setting) return;
  2848. const sortData = sheet.zh_data;
  2849. const datas = [], posSelects = [], camountDatas = [];
  2850. const sel = sheet.getSelections()[0];
  2851. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2852. let bDel = false;
  2853. const node = sortData[iRow];
  2854. if (node) {
  2855. const data = {id: node.id};
  2856. const cData = {};
  2857. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2858. const colSetting = sheet.zh_setting.cols[iCol];
  2859. if (colSetting.field === 'name') {
  2860. toastr.error('部位名称不能为空');
  2861. return;
  2862. }
  2863. const style = sheet.getStyle(iRow, iCol);
  2864. if (!style.locked) {
  2865. const colSetting = sheet.zh_setting.cols[iCol];
  2866. if (colSetting.field === 'camount') {
  2867. const cInfo = _.find(changeList, { gcl_id: node.lid, mx_id: node.id });
  2868. if (!cInfo) continue;
  2869. cData.id = cInfo.id;
  2870. cData.camount = null;
  2871. cData.camount_expr = '';
  2872. cData.spamount = null;
  2873. } else if (colSetting.field.indexOf('_expr') > 0) {
  2874. const exprInfo = getExprInfo(colSetting.field, true);
  2875. if (!exprInfo) continue;
  2876. data[exprInfo.expr] = '';
  2877. data[exprInfo.qty] = 0;
  2878. } else {
  2879. data[colSetting.field] = null;
  2880. const exprInfo = getExprInfo(colSetting.field);
  2881. if (exprInfo) data[exprInfo.expr] = '';
  2882. }
  2883. bDel = true;
  2884. }
  2885. }
  2886. if (bDel) {
  2887. datas.push(data);
  2888. if (cData.id) camountDatas.push(cData);
  2889. posSelects.push(node);
  2890. }
  2891. }
  2892. }
  2893. if (camountDatas.length > 0) {
  2894. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', updateData: camountDatas }, function (result) {
  2895. changeList = result;
  2896. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2897. billsTreeSpreadObj.reCalcCamount(billsNode);
  2898. const loadResult = { update: [billsNode] };
  2899. const refreshNode = billsTree.loadPostData(loadResult);
  2900. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2901. posSpreadObj.loadCurPosData();
  2902. }, function () {
  2903. posSpreadObj.loadCurPosData();
  2904. });
  2905. return;
  2906. }
  2907. if (datas.length > 0) {
  2908. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: datas}, function (result) {
  2909. changeList = result.changeList;
  2910. pos.updateDatas(result.pos);
  2911. posSpreadObj.loadCurPosData();
  2912. const loadResult = billsTree.loadPostData(result.ledger);
  2913. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  2914. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2915. }, function () {
  2916. posSpreadObj.loadCurPosData();
  2917. });
  2918. }
  2919. },
  2920. /**
  2921. * 删除 计量单元
  2922. * @param sheet
  2923. */
  2924. deletePos: function (sheet) {
  2925. const selection = sheet.getSelections();
  2926. const data = {
  2927. postType: 'pos',
  2928. posPostType: 'delete',
  2929. postData: [],
  2930. };
  2931. const row = selection[0].row, count = selection[0].rowCount;
  2932. const sortData = sheet.zh_data;
  2933. for (let iRow = 0; iRow < count; iRow++) {
  2934. const posData = sortData[iRow + row];
  2935. if (posData) {
  2936. if (posData.used) {
  2937. toastr.error('"' + posData.name + '"已计量,请勿删除');
  2938. return;
  2939. }
  2940. if (posData.settle_status === settleStatus.finish) {
  2941. toastr.error(`"${posData.name}"已计量,请勿删除`);
  2942. return;
  2943. }
  2944. data.postData.push(sortData[iRow + row].id);
  2945. }
  2946. }
  2947. if (data.postData.length > 0) {
  2948. postData(window.location.pathname + '/update', data, function (result) {
  2949. changeList = result.changeList;
  2950. pos.removeDatas(result.pos);
  2951. sheet.deleteRows(row, count);
  2952. const loadResult = billsTree.loadPostData(result.ledger);
  2953. // 判断是否只剩一个,并同步去勾
  2954. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  2955. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  2956. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  2957. billsNode.is_change = 1;
  2958. } else {
  2959. billsNode.is_change = 0;
  2960. billsNode.is_valuation = 0;
  2961. billsNode.camount = null;
  2962. billsNode.ca_tp = null;
  2963. }
  2964. if (loadResult.update) {
  2965. const r = _.find(loadResult.update, { id: billsNode.id });
  2966. r.is_change = billsNode.is_change;
  2967. } else {
  2968. loadResult.update = [billsNode];
  2969. }
  2970. billsTreeSpreadObj.reCalcCamount(billsNode);
  2971. const refreshNode = billsTree.loadPostData(loadResult);
  2972. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  2973. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  2974. });
  2975. }
  2976. },
  2977. /**
  2978. * 粘贴单元格响应事件
  2979. * @param e
  2980. * @param info
  2981. */
  2982. clipboardPasted: function (e, info) {
  2983. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  2984. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  2985. }
  2986. const node = SpreadJsObj.getSelectObject(billsSheet);
  2987. if (node.code && (node.code !== '')) {
  2988. toastr.error('项目节不可含有节点明细');
  2989. posSpreadObj.loadCurPosData();
  2990. return;
  2991. }
  2992. if (node.children && (node.children.length > 0)) {
  2993. toastr.error('仅节点子项可以含有计量单元');
  2994. posSpreadObj.loadCurPosData();
  2995. return;
  2996. }
  2997. if (node.settle_status === settleStatus.finish) {
  2998. toastr.error('清单已结算,请勿修改计量单元数据');
  2999. posSpread.loadCurPosData();
  3000. return;
  3001. }
  3002. if (!info.sheet.zh_setting) {
  3003. posSpreadObj.loadCurPosData();
  3004. return;
  3005. }
  3006. const data = [];
  3007. const camountData = [], insertCamountData = [];
  3008. const sortData = info.sheet.zh_data || [];
  3009. const hint = {
  3010. expr: {type: 'warning', msg: '粘贴了表达式非法,已过滤'},
  3011. settle: {type: 'warning', msg: '计量单元已结算,不可修改台账数据,已过滤'},
  3012. };
  3013. if (sortData.length === 0 || info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  3014. const nameCol = info.sheet.zh_setting.cols.findIndex(x => { return x.field === 'name'; });
  3015. if (info.cellRange.col > nameCol || info.cellRange.col + info.cellRange.colCount < nameCol) {
  3016. toastr.warning('新增计量单元请先输入名称');
  3017. posSpreadObj.loadCurPosData();
  3018. return;
  3019. }
  3020. }
  3021. let bHint = false;
  3022. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3023. makeGclGatherData();
  3024. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3025. let bPaste = true;
  3026. const curRow = info.cellRange.row + iRow;
  3027. const posData = curRow >= sortData.length ? {lid: node.id, porder: lastOrder + curRow - sortData.length} : {id: sortData[curRow].id, lid: node.id};
  3028. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  3029. const curCol = info.cellRange.col + iCol;
  3030. const colSetting = info.sheet.zh_setting.cols[curCol];
  3031. if (!colSetting) continue;
  3032. posData[colSetting.field] = colSetting.wordWrap ? info.sheet.getText(curRow, curCol) : trimInvalidChar(info.sheet.getText(curRow, curCol));
  3033. if (posData.id && colSetting.type === 'Number' && sortData[curRow].settle_status === settleStatus.finish) {
  3034. bPaste = false;
  3035. toastMessageUniq(hint.settle);
  3036. continue;
  3037. }
  3038. if (colSetting.field === 'camount') {
  3039. bPaste = true;
  3040. let validText = posData[colSetting.field];
  3041. let cInfo = _.find(changeList, { gcl_id: posData.lid, mx_id: posData.id });
  3042. if (!cInfo) {
  3043. const gclInfo = _.find(gclGatherData, function (item) {
  3044. return item.leafXmjs && _.find(item.leafXmjs, {gcl_id: posData.lid, mx_id: posData.id });
  3045. });
  3046. const xmjInfo = _.find(gclInfo.leafXmjs, { mx_id: posData.id });
  3047. const oldCInfo = _.find(oldChangeList, { gcl_id: posData.lid, mx_id: posData.id });
  3048. const data = {
  3049. lid: posData.lid,
  3050. code: gclInfo.b_code,
  3051. name: gclInfo.name || '',
  3052. unit: gclInfo.unit || '',
  3053. unit_price: gclInfo.unit_price,
  3054. oamount: xmjInfo.quantity,
  3055. oamount2: oldCInfo ? oldCInfo.oamount2 : xmjInfo.quantity,
  3056. bwmx: xmjInfo.bwmx || xmjInfo.jldy || '',
  3057. xmj_code: xmjInfo.code || '',
  3058. xmj_jldy: xmjInfo.jldy || '',
  3059. xmj_dwgc: xmjInfo.dwgc || '',
  3060. xmj_fbgc: xmjInfo.fbgc || '',
  3061. xmj_fxgc: xmjInfo.fxgc || '',
  3062. gcl_id: posData.lid,
  3063. mx_id: posData.id,
  3064. }
  3065. if (oldCInfo) {
  3066. data.detail = oldCInfo.detail;
  3067. data.camount = oldCInfo.camount;
  3068. data.camount_expr = oldCInfo.camount_expr;
  3069. data.spamount = oldCInfo.spamount;
  3070. data.is_valuation = oldCInfo.is_valuation;
  3071. data.delimit = oldCInfo.delimit;
  3072. }
  3073. cInfo = data;
  3074. // bPaste = false;
  3075. // continue;
  3076. }
  3077. const exprQuantity = {
  3078. expr: '',
  3079. quantity: 0,
  3080. };
  3081. const [valid, msg] = billsTreeSpreadObj._checkExpr(validText, exprQuantity);
  3082. if (!valid) {
  3083. toastMessageUniq(hint.expr);
  3084. bPaste = false;
  3085. continue;
  3086. }
  3087. if (isNaN(exprQuantity.quantity)) {
  3088. toastMessageUniq(hint.expr);
  3089. bPaste = false;
  3090. continue;
  3091. }
  3092. validText = parseFloat(exprQuantity.quantity);
  3093. if (cInfo.id) {
  3094. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3095. const usedInfo = _.find(changeUsedData, {cbid: cInfo.id});
  3096. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3097. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须大于等于已调用值 ' + usedInfo.qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3098. bPaste = false;
  3099. continue;
  3100. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3101. toastr.error(curRow ? '计量单元第' + (curRow + 1) + '行变更数值必须小于等于已调用值 ' + usedInfo.qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3102. bPaste = false;
  3103. continue;
  3104. }
  3105. }
  3106. if (bPaste) {
  3107. if (cInfo.id) {
  3108. camountData.push({id: cInfo.id, camount: ZhCalc.round(validText, findDecimal(node.unit)) || 0, camount_expr: exprQuantity.expr, spamount: ZhCalc.round(validText, findDecimal(node.unit)) || 0 });
  3109. } else {
  3110. cInfo.camount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3111. cInfo.camount_expr = exprQuantity.expr;
  3112. cInfo.spamount = ZhCalc.round(validText, findDecimal(node.unit)) || 0;
  3113. insertCamountData.push(cInfo);
  3114. }
  3115. } else {
  3116. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  3117. }
  3118. continue;
  3119. }
  3120. if (colSetting.type === 'Number') {
  3121. const num = _.toNumber(posData[colSetting.field]);
  3122. if (num) {
  3123. posData[colSetting.field] = num;
  3124. } else {
  3125. try {
  3126. posData[colSetting.field] = ZhCalc.mathCalcExpr(transExpr(posData[colSetting.field]));
  3127. const exprInfo = getExprInfo(colSetting.field);
  3128. if (exprInfo) {
  3129. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3130. }
  3131. } catch (err) {
  3132. if (!bHint) {
  3133. toastr.warning('粘贴了非法表达式,已过滤');
  3134. bHint = true;
  3135. }
  3136. bPaste = false;
  3137. }
  3138. }
  3139. } else if (colSetting.field.indexOf('_expr') > 0) {
  3140. try {
  3141. const exprInfo = getExprInfo(colSetting.field, true);
  3142. posData[exprInfo.expr] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  3143. if (posData[exprInfo.expr] || !posData[exprInfo.qty]) {
  3144. posData[exprInfo.qty] = ZhCalc.mathCalcExpr(transExpr(posData[exprInfo.expr]));
  3145. }
  3146. bPaste = true;
  3147. } catch (err) {
  3148. toastMessageUniq(hint.expr);
  3149. }
  3150. } else {
  3151. bPaste = true;
  3152. }
  3153. }
  3154. if (bPaste) {
  3155. data.push(posData);
  3156. }
  3157. }
  3158. if (camountData.length > 0 || insertCamountData.length > 0) {
  3159. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'paste', insertData: insertCamountData, updateData: camountData }, function (result) {
  3160. changeList = result;
  3161. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3162. billsTreeSpreadObj.reCalcCamount(billsNode);
  3163. const loadResult = { update: [billsNode] };
  3164. const refreshNode = billsTree.loadPostData(loadResult);
  3165. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3166. posSpreadObj.loadCurPosData();
  3167. }, function () {
  3168. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3169. return;
  3170. });
  3171. return;
  3172. }
  3173. if (data.length === 0) {
  3174. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3175. return;
  3176. }
  3177. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: data}, function (result) {
  3178. changeList = result.changeList;
  3179. pos.updateDatas(result.pos);
  3180. posSpreadObj.loadCurPosData();
  3181. const loadResult = result.ledger;
  3182. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3183. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3184. // billsNode.is_change = _.findIndex(changeList, { gcl_id: billsNode.id }) > -1 ? 1 : 0;
  3185. if (_.findIndex(changeList, { gcl_id: billsNode.id }) > -1) {
  3186. billsNode.is_change = 1;
  3187. } else {
  3188. billsNode.is_change = 0;
  3189. billsNode.is_valuation = 0;
  3190. billsNode.camount = null;
  3191. billsNode.ca_tp = null;
  3192. }
  3193. if (loadResult.update) {
  3194. const r = _.find(loadResult.update, { id: billsNode.id });
  3195. r.is_change = billsNode.is_change;
  3196. } else {
  3197. loadResult.update = [billsNode];
  3198. }
  3199. billsTreeSpreadObj.reCalcCamount(billsNode);
  3200. const refreshNode = billsTree.loadPostData(loadResult);
  3201. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3202. posSpreadObj.loadCurPosData();
  3203. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3204. }, function () {
  3205. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  3206. });
  3207. },
  3208. selectionChanged: function (e, info) {
  3209. posSpreadObj.loadExprToInput();
  3210. posSpreadObj.refreshOperationValid(posSheet);
  3211. },
  3212. addPegs: function (pegs) {
  3213. if (!pegs || pegs.length <= 0) return;
  3214. const node = SpreadJsObj.getSelectObject(billsSheet);
  3215. if (!node) return;
  3216. const sheet = posSpread.getActiveSheet();
  3217. const sortData = sheet.zh_data || [];
  3218. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  3219. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  3220. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'paste', postData: pegs}, function (result) {
  3221. changeList = result.changeList;
  3222. pos.updateDatas(result.pos);
  3223. posSpreadObj.loadCurPosData();
  3224. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3225. });
  3226. }
  3227. };
  3228. posSpread.bind(spreadNS.Events.SelectionChanged, posSpreadObj.selectionChanged);
  3229. if (!readOnly) {
  3230. $('a[name="pos-opr"]').click(function () {
  3231. posSpreadObj.baseOpr(posSheet, this.getAttribute('type'));
  3232. });
  3233. $('#pos-expr').bind('change onblur', function () {
  3234. if (this.readOnly) return;
  3235. const expr = $(this);
  3236. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  3237. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  3238. if (!select) return;
  3239. const billsNode = SpreadJsObj.getSelectObject(billsSheet);
  3240. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
  3241. if (orgValue === newValue || (!orgValue && newValue == '')) return;
  3242. if (field === 'camount') {
  3243. const cInfo = _.find(changeList, { gcl_id: select.lid, mx_id: select.id });
  3244. if (!cInfo) {
  3245. toastr.error('未勾选变更清单,无法编辑申请数量');
  3246. return;
  3247. }
  3248. const exprQuantity = {
  3249. expr: '',
  3250. quantity: 0,
  3251. };
  3252. const [valid, msg] = billsTreeSpreadObj._checkExpr(newValue, exprQuantity);
  3253. if (!valid) {
  3254. toastr.error(msg);
  3255. return;
  3256. }
  3257. if (isNaN(exprQuantity.quantity)) {
  3258. toastr.error('不能输入其它非数字类型字符');
  3259. return;
  3260. }
  3261. const camount = parseFloat(exprQuantity.quantity);
  3262. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  3263. const usedInfo = _.find(changeUsedData, { cbid: cInfo.id });
  3264. if (usedInfo && usedInfo.qty >= 0 && validText < usedInfo.qty) {
  3265. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.qty);
  3266. return;
  3267. } else if (usedInfo && usedInfo.qty < 0 && validText > usedInfo.qty) {
  3268. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.qty);
  3269. return;
  3270. }
  3271. cInfo.camount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3272. cInfo.spamount = ZhCalc.round(camount, findDecimal(billsNode.unit)) || 0;
  3273. cInfo.camount_expr = exprQuantity.expr;
  3274. delete cInfo.waitingLoading;
  3275. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', { type:'update', updateData: cInfo }, function (result) {
  3276. SpreadJsObj.reLoadRowData(posSheet, row);
  3277. billsTreeSpreadObj.reCalcCamount(billsNode);
  3278. const loadResult = { update: [billsNode] };
  3279. const refreshNode = billsTree.loadPostData(loadResult);
  3280. billsTreeSpreadObj.refreshTree(billsSheet, refreshNode);
  3281. posSpreadObj.loadExprToInput(posSheet);
  3282. }, function () {
  3283. cInfo.camount = orgValue;
  3284. cInfo.spamount = orgValue;
  3285. SpreadJsObj.reLoadRowData(posSheet, row);
  3286. });
  3287. return;
  3288. }
  3289. const data = {id: select.id};
  3290. const exprInfo = getExprInfo(field);
  3291. if (newValue !== '') {
  3292. const num = _.toNumber(newValue);
  3293. if (num) {
  3294. data[field] = num;
  3295. if (exprInfo) data[exprInfo.expr] = '';
  3296. } else {
  3297. try {
  3298. data[field] = ZhCalc.mathCalcExpr(transExpr(newValue));
  3299. if (exprInfo) data[exprInfo.expr] = newValue;
  3300. } catch (err) {
  3301. toastr.error('输入的表达式非法');
  3302. return;
  3303. }
  3304. }
  3305. } else {
  3306. data[field] = null;
  3307. if (exprInfo) data[exprInfo.expr] = '';
  3308. }
  3309. // 更新至服务器
  3310. postData(window.location.pathname + '/update', {postType: 'pos', posPostType: 'update', postData: data}, function (result) {
  3311. changeList = result.changeList;
  3312. const updateRst = pos.updateDatas(result.pos);
  3313. // 刷新当前行, 不适用于新增(在非下一空白行新增)
  3314. SpreadJsObj.reLoadRowData(posSheet, row);
  3315. const loadResult = billsTree.loadPostData(result.ledger);
  3316. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  3317. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3318. });
  3319. });
  3320. posSpread.bind(spreadNS.Events.EditStarting, posSpreadObj.editStarting);
  3321. posSpread.bind(spreadNS.Events.EditEnded, posSpreadObj.editEnded);
  3322. posSpread.bind(spreadNS.Events.ButtonClicked, posSpreadObj.buttonClicked);
  3323. posSpread.bind(spreadNS.Events.ClipboardPasted, posSpreadObj.clipboardPasted);
  3324. SpreadJsObj.addDeleteBind(posSpread, posSpreadObj.deletePress);
  3325. $.contextMenu({
  3326. selector: '#pos-spread',
  3327. build: function ($trigger, e) {
  3328. const target = SpreadJsObj.safeRightClickSelection($trigger, e, posSpread);
  3329. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3330. },
  3331. items: {
  3332. 'delete': {
  3333. name: '删除',
  3334. icon: 'fa-remove',
  3335. disabled: function (key, opt) {
  3336. if (posSheet.zh_data) {
  3337. const selection = posSheet.getSelections();
  3338. const sel = selection ? selection[0] : sheet.getSelections()[0];
  3339. const row = sel ? sel.row : -1;
  3340. const rowCount = sel.rowCount;
  3341. let settleFinish = false;
  3342. for (let i = row; i < row + rowCount; i++) {
  3343. if (!posSheet.zh_data[i]) continue;
  3344. settleFinish = settleFinish || posSheet.zh_data[i].settle_status === settleStatus.finish;
  3345. }
  3346. return (posSheet.zh_data.length < selection[0].row + selection[0].rowCount) || (posSheet.zh_data[selection[0].row] && !posSheet.zh_data[selection[0].row].formc) || settleFinish;
  3347. } else {
  3348. return true;
  3349. }
  3350. },
  3351. callback: function (key, opt) {
  3352. posSpreadObj.deletePos(posSheet);
  3353. }
  3354. },
  3355. }
  3356. });
  3357. }
  3358. // 加载清单&计量单元数据
  3359. const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  3360. let gclGatherData;
  3361. postData(preUrl + '/defaultBills', { from: 'revise' }, function (result) {
  3362. for (const b of result.bills) {
  3363. if (!(b.is_leaf && b.b_code)) {
  3364. b.is_change = 0;
  3365. b.is_valutaion = 0;
  3366. } else {
  3367. const cInfo = _.find(changeList, { gcl_id: b.id });
  3368. b.is_change = cInfo ? 1 : 0;
  3369. b.is_valuation = cInfo ? cInfo.is_valuation : 0;
  3370. b.camount = cInfo ? cInfo.camount : 0;
  3371. }
  3372. }
  3373. billsTree.loadDatas(result.bills);
  3374. pos.loadDatas(result.pos);
  3375. treeCalc.calculateAll(billsTree);
  3376. SpreadJsObj.loadSheetData(billsSheet, SpreadJsObj.DataType.Tree, billsTree);
  3377. SpreadJsObj.loadTopAndSelect(billsSheet, ckBillsSpread);
  3378. checkShowLast(result.bills.length);
  3379. posSpreadObj.loadCurPosData();
  3380. SpreadJsObj.resetTopAndSelect(posSheet);
  3381. billsTreeSpreadObj.refreshOperationValid(billsSheet);
  3382. billsTreeSpreadObj.loadExprToInput(billsSheet);
  3383. checkList.loadHisCheckData();
  3384. console.log(billsTree);
  3385. }, null);
  3386. $.divResizer({
  3387. select: '#revise-resize',
  3388. callback: function () {
  3389. billsSpread.refresh();
  3390. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  3391. $(".sp-wrap").height(bcontent-30);
  3392. posSpread.refresh();
  3393. }
  3394. });
  3395. function makeGclGatherData() {
  3396. gclGatherModel.loadLedgerData(billsTree.datas);
  3397. gclGatherModel.loadPosData(pos.datas);
  3398. gclGatherData = gclGatherModel.gatherGclData();
  3399. gclGatherData = _.filter(gclGatherData, function (item) {
  3400. return item.leafXmjs && item.leafXmjs.length !== 0;
  3401. });
  3402. gclGatherData = gclGatherData.sort(sortByCode);
  3403. }
  3404. class DealBills {
  3405. constructor (selector, spreadSetting) {
  3406. const self = this;
  3407. this.loaded = false;
  3408. this.obj = $(selector)[0];
  3409. this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3410. this.spreadSetting = spreadSetting;
  3411. this.spread = SpreadJsObj.createNewSpread(this.obj);
  3412. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  3413. if (!readOnly) {
  3414. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3415. const dealSheet = info.sheet;
  3416. const mainSheet = billsSheet;
  3417. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3418. if (!dealBills) { return; }
  3419. const mainTree = mainSheet.zh_tree;
  3420. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3421. if (!mainNode || !mainTree) { return; }
  3422. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3423. toastr.warning('非最底层项目下,不应添加节点');
  3424. return;
  3425. }
  3426. if (mainNode.settle_status === settleStatus.finish) {
  3427. toastr.warning('已结算节点下,不应添加签约清单');
  3428. return;
  3429. }
  3430. postData(window.location.pathname + '/update', {
  3431. postType: 'add-deal',
  3432. postData: {
  3433. id: mainNode.ledger_id,
  3434. type: mainNode.code ? 'child' : 'next',
  3435. dealBills: {
  3436. b_code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3437. unit_price: dealBills.unit_price,
  3438. }
  3439. },
  3440. }, function (result) {
  3441. changeList = result.changeList;
  3442. const refreshData = mainTree.loadPostData(result);
  3443. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3444. const sel = mainSheet.getSelections()[0];
  3445. if (sel && refreshData.create[0]) {
  3446. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3447. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3448. }
  3449. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3450. billsSpread.focus();
  3451. posSpreadObj.loadCurPosData();
  3452. });
  3453. });
  3454. }
  3455. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3456. }
  3457. loadData (callback) {
  3458. if (this.loaded) {
  3459. if (callback) callback();
  3460. return;
  3461. }
  3462. const self = this;
  3463. postData(this.url+'/get-data', {}, function (data) {
  3464. self.data = data;
  3465. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
  3466. self.loaded = true;
  3467. if (callback) callback();
  3468. });
  3469. }
  3470. calculateData () {
  3471. if (this.data) {
  3472. for (const d of this.data) {
  3473. d.total_price = _.multiply(d.quantity, d.unit_price);
  3474. }
  3475. }
  3476. }
  3477. }
  3478. class BatchInsertBillsPosObj {
  3479. constructor (obj) {
  3480. const self = this;
  3481. this.obj = obj;
  3482. this.billsCount = 6;
  3483. this.posCount = 1000;
  3484. this.filter = getLocalCache('zh-calc-batch-filter');
  3485. if (!this.filter) {
  3486. this.filter = '1';
  3487. }
  3488. $('input[name=batch-filter]')[0].checked = this.filter && this.filter != '0';
  3489. // 初始化 清单编号窗口 参数
  3490. this.qdSpreadSetting = {
  3491. cols: [
  3492. {title: '编号', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  3493. {title: '名称', field: 'name', hAlign: 0, width: 120, formatter: '@'},
  3494. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3495. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3496. {title: '图册号', field: 'name', hAlign: 0, width: 60, formatter: '@'},
  3497. ],
  3498. emptyRows: this.billsCount,
  3499. headRows: 1,
  3500. headRowHeight: [32],
  3501. headerFont: '12px 微软雅黑',
  3502. font: '12px 微软雅黑',
  3503. };
  3504. this.qdSpread = SpreadJsObj.createNewSpread($('.batch-l-t', this.obj)[0]);
  3505. // 初始化 部位数量复核表 参数
  3506. this.posSpreadSetting = {
  3507. cols: [
  3508. {title: '名称', field: 'bw', hAlign: 0, width: 80, formatter: '@'},
  3509. {title: '图册号', field: 'drawingCode', hAlign: 0, formatter: '@', width: 60},
  3510. ],
  3511. emptyRows: this.posCount,
  3512. headRows: 1,
  3513. headRowHeight: [32],
  3514. headerFont: '12px 微软雅黑',
  3515. font: '12px 微软雅黑',
  3516. };
  3517. for (let iNum = 1; iNum <= this.billsCount; iNum++) {
  3518. this.posSpreadSetting.cols.push(
  3519. {title: '清单' + iNum, field: 'bills' + iNum, hAlign: 2, width: 50}
  3520. )
  3521. }
  3522. this.posSpread = SpreadJsObj.createNewSpread($('.batch-l-b', this.obj)[0]);
  3523. // 初始化 签约节点 参数
  3524. this.dealSpreadSetting = {
  3525. cols: [
  3526. {title: '清单编号', field: 'code', width: 80, hAlign: 0, formatter: '@', readOnly: true},
  3527. {title: '名称', field: 'name', width: 230, hAlign: 0, formatter: '@', readOnly: true},
  3528. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3529. {title: '单价', field: 'unit_price', hAlign: 2, width: 60, readOnly: true},
  3530. ],
  3531. emptyRows: 0,
  3532. headRows: 1,
  3533. headRowHeight: [32],
  3534. headerFont: '12px 微软雅黑',
  3535. font: '12px 微软雅黑',
  3536. };
  3537. this.dealSpread = SpreadJsObj.createNewSpread($('.batch-r', this.obj)[0]);
  3538. // 初始化 清单编号、部位数量复核表 表格
  3539. this.initView();
  3540. SpreadJsObj.initSheet(this.dealSpread.getActiveSheet(), this.dealSpreadSetting);
  3541. SpreadJsObj.refreshColumnAlign(this.dealSpread.getActiveSheet());
  3542. // 拉取签约节点数据
  3543. dealBills.loadData(() => {
  3544. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3545. });
  3546. // 双击签约节点,自动添加到清单编号窗口
  3547. this.dealSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (e, info) {
  3548. const deal = info.sheet.zh_data[info.row];
  3549. const qdSheet = self.qdSpread.getActiveSheet(), posSheet = self.posSpread.getActiveSheet();
  3550. const sel = qdSheet.getSelections()[0];
  3551. qdSheet.getCell(sel.row, 0).value(deal.code);
  3552. qdSheet.getCell(sel.row, 1).value(deal.name);
  3553. qdSheet.getCell(sel.row, 2).value(deal.unit);
  3554. qdSheet.getCell(sel.row, 3).value(deal.unit_price);
  3555. if (sel.row + 1 === qdSheet.getRowCount()) {
  3556. const count = sel.row + 2;
  3557. qdSheet.setRowCount(count);
  3558. qdSheet.getCell(sel.row + 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + count);
  3559. const colCount = posSheet.getColumnCount() + 1;
  3560. posSheet.setColumnCount(colCount);
  3561. posSheet.getCell(0, colCount - 1, GC.Spread.Sheets.SheetArea.colHeader).text('清单' + count);
  3562. }
  3563. qdSheet.setSelection(sel.row + 1, sel.col, 1, 1);
  3564. qdSheet.getParent().focus();
  3565. });
  3566. this.qdSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3567. const billsCount = info.sheet.getRowCount(), posSheet = self.posSpread.getActiveSheet();
  3568. const count = posSheet.getColumnCount() - 2;
  3569. if (billsCount > count) {
  3570. posSheet.setColumnCount(billsCount + 2);
  3571. for (let i = count + 1; i <= billsCount; i++) {
  3572. info.sheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3573. posSheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3574. }
  3575. }
  3576. if (info.cellRange.col === 0 && info.cellRange.colCount === 1) {
  3577. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3578. if (dealBills && dealBills.length > 0) {
  3579. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  3580. const curRow = iRow + info.cellRange.row;
  3581. const bills = _.find(dealBills, {code: info.sheet.getText(curRow, 0)});
  3582. if (bills) {
  3583. info.sheet.getCell(curRow, 1).value(bills.name);
  3584. info.sheet.getCell(curRow, 2).value(bills.unit);
  3585. info.sheet.getCell(curRow, 3).value(bills.unit_price);
  3586. }
  3587. }
  3588. }
  3589. }
  3590. });
  3591. this.posSpread.bind(spreadNS.Events.ClipboardPasted, function (e, info) {
  3592. const billsCount = info.sheet.getColumnCount() - 2, qdSheet = self.qdSpread.getActiveSheet();
  3593. const count = qdSheet.getRowCount();
  3594. if (billsCount > count) {
  3595. qdSheet.setRowCount(billsCount);
  3596. for (let i = count + 1; i <= billsCount; i++) {
  3597. qdSheet.getCell(i - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + i);
  3598. info.sheet.getCell(0, i + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + i);
  3599. }
  3600. }
  3601. });
  3602. this.qdSpread.bind(spreadNS.Events.EditEnded, function (e, info) {
  3603. if (info.col === 0) {
  3604. const dealBills = self.dealSpread.getActiveSheet().zh_data;
  3605. if (dealBills && dealBills.length > 0) {
  3606. const bills = _.find(dealBills, {code: info.editingText});
  3607. if (bills) {
  3608. info.sheet.getCell(info.row, 1).value(bills.name);
  3609. info.sheet.getCell(info.row, 2).value(bills.unit);
  3610. info.sheet.getCell(info.row, 3).value(bills.unit_price);
  3611. }
  3612. }
  3613. }
  3614. });
  3615. this.obj.bind('shown.bs.modal', function () {
  3616. self.qdSpread.refresh();
  3617. self.posSpread.refresh();
  3618. self.dealSpread.refresh();
  3619. });
  3620. $('#batch-ok').click(function () {
  3621. const selection = billsSheet.getSelections();
  3622. const sel = selection[0];
  3623. const row = selection[0].row;
  3624. const select = billsTree.nodes[row];
  3625. if (select) {
  3626. const insertData = {};
  3627. insertData.batchType = (select.code && select.code !== '') ? 'child' : 'next';
  3628. insertData.id = select[billsTree.setting.id];
  3629. insertData.batchData = self.getBatchData();
  3630. if (insertData.batchData.length > 0) {
  3631. postData(window.location.pathname + '/update', {
  3632. postType: 'batch-insert',
  3633. postData: insertData
  3634. }, function (data) {
  3635. changeList = result.changeList;
  3636. pos.updateDatas(data.pos);
  3637. const result = billsTree.loadPostData(data.ledger);
  3638. billsTreeSpreadObj.refreshTree(billsSheet, result);
  3639. billsSheet.setSelection(result.create[0].index, sel.col, sel.rowCount, sel.colCount);
  3640. SpreadJsObj.reloadRowsBackColor(billsSheet, [sel.row, result.create[0].index]);
  3641. billsTreeSpreadObj.refreshOperationValid(billsSheet, selection);
  3642. posSpreadObj.loadCurPosData();
  3643. self.obj.modal('hide');
  3644. }, null, true);
  3645. } else {
  3646. self.obj.modal('hide');
  3647. }
  3648. }
  3649. });
  3650. $('input[name=batch-filter]').change(function () {
  3651. setLocalCache('zh-calc-batch-filter', this.checked ? 1 : 0);
  3652. });
  3653. $.contextMenu({
  3654. selector: '.batch-l-t',
  3655. build: function ($trigger, e) {
  3656. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.qdSpread);
  3657. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3658. },
  3659. items: {
  3660. 'create': {
  3661. name: '新增行',
  3662. icon: 'fa-sign-in',
  3663. callback: function (key, opt) {
  3664. const qdSheet = self.qdSpread.getActiveSheet();
  3665. const posSheet = self.posSpread.getActiveSheet();
  3666. qdSheet.addRows(qdSheet.getRowCount(), 1);
  3667. const index = qdSheet.getRowCount();
  3668. qdSheet.getCell(qdSheet.getRowCount() - 1, 0, spreadNS.SheetArea.rowHeader).text('清单' + index);
  3669. posSheet.addColumns(posSheet.getColumnCount(), 1);
  3670. posSheet.getCell(0, index + 2 - 1, spreadNS.SheetArea.colHeader).text('清单' + index);
  3671. },
  3672. },
  3673. 'delete': {
  3674. name: '删除行',
  3675. icon: 'fa-remove',
  3676. callback: function (key, opt) {
  3677. const qdSheet = self.qdSpread.getActiveSheet();
  3678. const posSheet = self.posSpread.getActiveSheet();
  3679. const sel = qdSheet.getSelections()[0];
  3680. qdSheet.deleteRows(sel.row, sel.rowCount);
  3681. posSheet.deleteColumns(sel.row + 2, sel.rowCount);
  3682. for (let iRow = 0, iLen = qdSheet.getRowCount(); iRow < iLen; iRow++) {
  3683. qdSheet.getCell(iRow, 0, spreadNS.SheetArea.rowHeader).text('清单' + (iRow+1));
  3684. }
  3685. for (let iCol = 0, iLen = posSheet.getColumnCount() - 2; iCol < iLen; iCol++) {
  3686. posSheet.getCell(0, iCol + 2, spreadNS.SheetArea.colHeader).text('清单' + (iCol+1));
  3687. }
  3688. qdSheet.setSelection(sel.row, sel.col, 1, 1);
  3689. },
  3690. },
  3691. }
  3692. });
  3693. }
  3694. // 初始化左侧表格
  3695. initView () {
  3696. // 初始化 清单编号
  3697. const qdSheet = this.qdSpread.getActiveSheet();
  3698. SpreadJsObj.initSheet(qdSheet, this.qdSpreadSetting);
  3699. SpreadJsObj.refreshColumnAlign(qdSheet);
  3700. // 清理原有数据
  3701. SpreadJsObj.beginMassOperation(qdSheet);
  3702. qdSheet.clear(0, 0, qdSheet.getRowCount(), qdSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3703. for (let iRow = 1; iRow <= this.billsCount; iRow++) {
  3704. qdSheet.getCell(iRow - 1, 0, GC.Spread.Sheets.SheetArea.rowHeader).text('清单' + iRow);
  3705. }
  3706. qdSheet.setSelection(0, 0, 1 ,1);
  3707. SpreadJsObj.endMassOperation(qdSheet);
  3708. // 初始化 部位数量复核表
  3709. const posSheet = this.posSpread.getActiveSheet();
  3710. SpreadJsObj.initSheet(posSheet, this.posSpreadSetting);
  3711. SpreadJsObj.refreshColumnAlign(posSheet);
  3712. // 清理原有数据
  3713. SpreadJsObj.beginMassOperation(posSheet);
  3714. posSheet.setColumnWidth(0, 45, GC.Spread.Sheets.SheetArea.rowHeader);
  3715. posSheet.clear(0, 0, posSheet.getRowCount(), posSheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
  3716. posSheet.setSelection(0, 0, 1 ,1);
  3717. SpreadJsObj.endMassOperation(posSheet);
  3718. // 检查签约节点数据,以工具栏数据为准
  3719. if (dealBills) {
  3720. SpreadJsObj.loadSheetData(this.dealSpread.getActiveSheet(), 'data', dealBills.data);
  3721. }
  3722. this.dealSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  3723. }
  3724. // 获取界面数据
  3725. getBatchData () {
  3726. const result = [];
  3727. const qdSheet = this.qdSpread.getActiveSheet(), posSheet = this.posSpread.getActiveSheet();
  3728. for (let iRow = 0; iRow < qdSheet.getRowCount(); iRow++) {
  3729. if (qdSheet.getText(iRow, 0) === '') { continue; }
  3730. const qd = {
  3731. b_code: qdSheet.getText(iRow, 0),
  3732. name: qdSheet.getText(iRow, 1),
  3733. unit: qdSheet.getText(iRow, 2),
  3734. price: _.toNumber(qdSheet.getText(iRow, 3)),
  3735. pos: [],
  3736. };
  3737. for (let iPosRow = 0; iPosRow < posSheet.getRowCount(); iPosRow++) {
  3738. const value = _.toNumber(posSheet.getText(iPosRow, iRow + 2));
  3739. if (value !== 0 && !isNaN(value)) {
  3740. qd.pos.push({
  3741. name: posSheet.getText(iPosRow, 0),
  3742. drawing_code: posSheet.getText(iPosRow, 1),
  3743. quantity: value, porder: qd.pos.length + 1,
  3744. });
  3745. }
  3746. }
  3747. if (!$('input[name=batch-filter]')[0].checked || qd.pos.length > 0) result.push(qd);
  3748. }
  3749. return result;
  3750. }
  3751. }
  3752. const dealBills = new DealBills('#deal-bills-spread', {
  3753. cols: [
  3754. {title: '清单编号', field: 'code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  3755. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  3756. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  3757. {title: '单价', field: 'unit_price', hAlign: 2, width: 50, readOnly: true},
  3758. {title: '数量', field: 'quantity', hAlign: 2, width: 50, readOnly: true},
  3759. {title: '金额', field: 'total_price', hAlign: 2, width: 50, readOnly: true},
  3760. ],
  3761. emptyRows: 0,
  3762. headRows: 1,
  3763. headRowHeight: [32],
  3764. headColWidth: [30],
  3765. defaultRowHeight: 21,
  3766. headerFont: '12px 微软雅黑',
  3767. font: '12px 微软雅黑',
  3768. selectedBackColor: '#fffacd',
  3769. });
  3770. class Jlzf {
  3771. constructor (selector, spreadSetting) {
  3772. const self = this;
  3773. this.loaded = false;
  3774. this.obj = $(selector);
  3775. const relaSelect = {
  3776. showLevel: `cb-${spreadSetting.stdType}-sl`,
  3777. searchText: `cb-${spreadSetting.stdType}-st`,
  3778. searchResult: `cb-${spreadSetting.stdType}-sr`,
  3779. searchPre: `cb-${spreadSetting.stdType}-sp`,
  3780. searchNext: `cb-${spreadSetting.stdType}-sn`,
  3781. searchClose: `cb-${spreadSetting.stdType}-sc`,
  3782. };
  3783. this.obj.html(
  3784. '<div class="sjs-bar d-flex">\n' +
  3785. ' <div class="ml-1">\n' +
  3786. ' <div class="px-2 border-primary border-1 d-flex">\n' +
  3787. ' <div class="d-inline-block">\n' +
  3788. ' <div class="input-group input-group-sm mr-1">' +
  3789. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  3790. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  3791. ' <div class="input-group-append" >\n' +
  3792. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  3793. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  3794. ' </div>\n' +
  3795. ' </div>\n' +
  3796. ' </div>\n' +
  3797. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  3798. ' </div>\n' +
  3799. ' </div>' +
  3800. '</div>\n' +
  3801. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  3802. );
  3803. autoFlashHeight();
  3804. const sh = `.cb-${spreadSetting.stdType}-sh`;
  3805. function getObjHeight(select) {
  3806. return select.length > 0 ? select.height() : 0;
  3807. }
  3808. const cHeader = getObjHeight($(".c-header"));
  3809. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  3810. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  3811. this.spreadSetting = spreadSetting;
  3812. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  3813. const searchSheet = this.spread.getActiveSheet();
  3814. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  3815. if (!readOnly) {
  3816. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  3817. const dealSheet = info.sheet;
  3818. const mainSheet = billsSheet;
  3819. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  3820. if (!dealBills) { return; }
  3821. const mainTree = mainSheet.zh_tree;
  3822. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  3823. if (!mainNode || !mainTree) { return; }
  3824. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  3825. toastr.warning('非最底层项目下,不应添加节点');
  3826. return;
  3827. }
  3828. if (mainNode.settle_status === settleStatus.finish) {
  3829. toastr.warning('已结算节点下,不应添加签约清单');
  3830. return;
  3831. }
  3832. postData(window.location.pathname + '/update', {
  3833. postType: 'add-deal',
  3834. postData: {
  3835. id: mainNode.ledger_id,
  3836. type: mainNode.code ? 'child' : 'next',
  3837. dealBills: {
  3838. b_code: dealBills.b_code, code: dealBills.code, name: dealBills.name, unit: dealBills.unit,
  3839. unit_price: dealBills.unit_price,
  3840. }
  3841. },
  3842. }, function (result) {
  3843. changeList = result.changeList;
  3844. const refreshData = mainTree.loadPostData(result);
  3845. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  3846. const sel = mainSheet.getSelections()[0];
  3847. if (sel && refreshData.create[0]) {
  3848. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  3849. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  3850. }
  3851. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  3852. billsSpread.focus();
  3853. posSpreadObj.loadCurPosData();
  3854. });
  3855. });
  3856. }
  3857. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  3858. const searchObj = {
  3859. result: [],
  3860. cur: 0,
  3861. searchStdNode: function() {
  3862. const keyword = $(`#${relaSelect.searchText}`).val();
  3863. const sortData = SpreadJsObj.getSortData(searchSheet);
  3864. searchObj.result = keyword ? sortData.filter(x => {
  3865. return (x.code && x.code.indexOf(keyword) >= 0) || (x.b_code && x.b_code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  3866. }) : [];
  3867. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  3868. searchObj.cur = 0;
  3869. if (searchObj.result.length > 0) {
  3870. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  3871. }
  3872. },
  3873. searchPre: function () {
  3874. if (searchObj.result.length === 0) return;
  3875. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  3876. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  3877. },
  3878. searchNext: function () {
  3879. if (searchObj.result.length === 0) return;
  3880. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  3881. SpreadJsObj.locateData(searchSheet, searchObj.result[searchObj.cur]);
  3882. },
  3883. clear: function () {
  3884. $(`#${relaSelect.searchText}`).val('');
  3885. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  3886. searchObj.result = [];
  3887. searchObj.cur = 0;
  3888. }
  3889. };
  3890. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  3891. $(`#${relaSelect.searchPre}`).click(function (e) {
  3892. searchObj.searchPre();
  3893. e.stopPropagation();
  3894. });
  3895. $(`#${relaSelect.searchNext}`).click(function (e) {
  3896. searchObj.searchNext();
  3897. e.stopPropagation();
  3898. });
  3899. $(`#${relaSelect.searchClose}`).click(function (e) {
  3900. searchObj.clear();
  3901. e.stopPropagation();
  3902. });
  3903. };
  3904. loadData (callback) {
  3905. // if (this.loaded) {
  3906. // if (callback) callback();
  3907. // return;
  3908. // }
  3909. const self = this;
  3910. const datas = billsTree.nodes.filter(node => node.is_leaf === 1 && !node.code && node.ccid !== undefined && node.ccid !== '');
  3911. const showDatas = [];
  3912. for (const d of datas) {
  3913. if (_.findIndex(showDatas, { b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price }) === -1) {
  3914. showDatas.push({ code: d.code, b_code: d.b_code ? d.b_code : '', name: d.name, unit: d.unit, unit_price: d.unit_price });
  3915. }
  3916. }
  3917. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', _.uniqWith(showDatas, _.isEqual).sort(sortByCode));
  3918. // self.loaded = true;
  3919. if (callback) callback();
  3920. }
  3921. }
  3922. const jlzfBills = new Jlzf('#jlzf-spread', {
  3923. cols: [
  3924. // {title: '项目节编号', field: 'code', hAlign: 0, width: 85, formatter: '@'},
  3925. {title: '清单编号', field: 'b_code', hAlign: 0, width: 100, formatter: '@'},
  3926. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  3927. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  3928. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3929. ],
  3930. emptyRows: 0,
  3931. headRows: 1,
  3932. headRowHeight: [32],
  3933. headColWidth: [30],
  3934. defaultRowHeight: 21,
  3935. headerFont: '12px 微软雅黑',
  3936. font: '12px 微软雅黑',
  3937. selectedBackColor: '#fffacd',
  3938. readOnly: true,
  3939. stdType: 'jlzf',
  3940. });
  3941. class Dsk {
  3942. constructor (selector, spreadSetting) {
  3943. const self = this;
  3944. this.loaded = false;
  3945. this.obj = $(selector);
  3946. const dskProjectHtml = spreadSetting.libs.map(l => {
  3947. return `<option value="${l.pid}" ${spreadSetting.select_lib === l.pid ? 'selected' : ''}>${l.name}</option>`;
  3948. });
  3949. const relaSelect = {
  3950. showLevel: `cb-${spreadSetting.stdType}-sl`,
  3951. searchText: `cb-${spreadSetting.stdType}-st`,
  3952. searchResult: `cb-${spreadSetting.stdType}-sr`,
  3953. searchPre: `cb-${spreadSetting.stdType}-sp`,
  3954. searchNext: `cb-${spreadSetting.stdType}-sn`,
  3955. searchClose: `cb-${spreadSetting.stdType}-sc`,
  3956. };
  3957. this.obj.html(
  3958. '<div class="sjs-bar d-flex">\n' +
  3959. ' <div class="dropdown mr-1">\n' +
  3960. ' <button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  3961. ' <i class="fa fa-list-ol"></i> 显示层级\n' +
  3962. ' </button>\n' +
  3963. ' <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">\n' +
  3964. ` <a class="dropdown-item" href="javascript: void(0);" tag="1" name="${relaSelect.showLevel}">第一层</a>\n` +
  3965. ` <a class="dropdown-item" href="javascript: void(0);" tag="2" name="${relaSelect.showLevel}">第二层</a>\n` +
  3966. ` <a class="dropdown-item" href="javascript: void(0);" tag="3" name="${relaSelect.showLevel}">第三层</a>\n` +
  3967. ` <a class="dropdown-item" href="javascript: void(0);" tag="4" name="${relaSelect.showLevel}">第四层</a>\n` +
  3968. ` <a class="dropdown-item" href="javascript: void(0);" tag="5" name="${relaSelect.showLevel}">第五层</a>\n` +
  3969. ` <a class="dropdown-item" href="javascript: void(0);" tag="last" name="${relaSelect.showLevel}">最底层</a>\n` +
  3970. ' </div>\n' +
  3971. ' </div>' +
  3972. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project">${dskProjectHtml.join('')}</select></div>\n` +
  3973. ` <div class="input-group input-group-sm pr-1"><select class="form-control form-control-sm col-auto" id="change-dsk-project-tree"></select></div>\n` +
  3974. ' <div class="ml-1">\n' +
  3975. ' <div class="dropdown">\n' +
  3976. ' <button class="btn btn-sm btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  3977. ' <i class="fa fa-search"></i>\n' +
  3978. ' </button>\n' +
  3979. ' <div class="dropdown-menu dropdown-menu-right">\n' +
  3980. ' <div class="px-2 border-primary border-1 d-flex" style="width: 300px">\n' +
  3981. ' <div class="d-inline-block">\n' +
  3982. ' <div class="input-group input-group-sm mr-1">' +
  3983. ` <input type="text" class="form-control" placeholder="输入编号/名称查找" id="${relaSelect.searchText}">\n` +
  3984. ` <div class="input-group-append" ><span class="input-group-text" id="${relaSelect.searchResult}">结果:0</span></div>\n` +
  3985. ' <div class="input-group-append" >\n' +
  3986. ` <button class="btn btn-outline-secondary" type="button" title="上一个" id="${relaSelect.searchPre}"><i class="fa fa-angle-double-left"></i></button>\n` +
  3987. ` <button class="btn btn-outline-secondary" type="button" title="下一个" id="${relaSelect.searchNext}"><i class="fa fa-angle-double-right"></i></button>\n` +
  3988. ' </div>\n' +
  3989. ' </div>\n' +
  3990. ' </div>\n' +
  3991. ` <div class="d-inline-block"><button class="btn btn-light text-danger btn-sm ml-1" type="button" id="${relaSelect.searchClose}"><i class="fa fa-remove"></i></button></div>\n` +
  3992. ' </div>\n' +
  3993. ' </div>\n' +
  3994. ' </div>\n' +
  3995. ' </div>' +
  3996. '</div>\n' +
  3997. `<div id="cb-${spreadSetting.stdType}-spread" class="cb-${spreadSetting.stdType}-sh"></div>\n`
  3998. );
  3999. autoFlashHeight();
  4000. const sh = `.cb-${spreadSetting.stdType}-sh`;
  4001. function getObjHeight(select) {
  4002. return select.length > 0 ? select.height() : 0;
  4003. }
  4004. const cHeader = getObjHeight($(".c-header"));
  4005. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55-30);
  4006. // this.url = '/tender/' + window.location.pathname.split('/')[2] + '/deal';
  4007. this.spreadSetting = spreadSetting;
  4008. this.spread = SpreadJsObj.createNewSpread($(`#cb-${spreadSetting.stdType}-spread`)[0]);
  4009. const searchSheet = this.spread.getActiveSheet();
  4010. SpreadJsObj.initSheet(searchSheet, this.spreadSetting);
  4011. (function (select, sheet) {
  4012. $(select).click(function () {
  4013. if (!sheet.zh_tree) return;
  4014. const tag = $(this).attr('tag');
  4015. const tree = sheet.zh_tree;
  4016. setTimeout(() => {
  4017. switch (tag) {
  4018. case "1":
  4019. case "2":
  4020. case "3":
  4021. case "4":
  4022. case "5":
  4023. tree.expandByLevel(parseInt(tag));
  4024. SpreadJsObj.refreshTreeRowVisible(sheet);
  4025. break;
  4026. case "last":
  4027. tree.expandByCustom(() => { return true; });
  4028. SpreadJsObj.refreshTreeRowVisible(sheet);
  4029. break;
  4030. }
  4031. }, 100);
  4032. });
  4033. })(`a[name=${relaSelect.showLevel}]`, searchSheet);
  4034. if (!readOnly) {
  4035. this.spread.bind(spreadNS.Events.CellDoubleClick, function (e, info) {
  4036. const dealSheet = info.sheet;
  4037. const mainSheet = billsSheet;
  4038. const dealBills = SpreadJsObj.getSelectObject(dealSheet);
  4039. if (!dealBills) { return; }
  4040. const mainTree = mainSheet.zh_tree;
  4041. const mainNode = SpreadJsObj.getSelectObject(mainSheet);
  4042. if (!mainNode || !mainTree) { return; }
  4043. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4044. toastr.warning('非最底层项目下,不应添加节点');
  4045. return;
  4046. }
  4047. if (mainNode.settle_status === settleStatus.finish) {
  4048. toastr.warning('已结算节点下,不应添加签约清单');
  4049. return;
  4050. }
  4051. const is_bill = dealBills.kind === 4;
  4052. // 判断dealBills.code以-开头,是则向上判断是否需要拼接code名称
  4053. function makeCode(dealBills) {
  4054. const originalCode = dealBills.code;
  4055. if (!originalCode || originalCode.charAt(0) !== '-') {
  4056. return originalCode;
  4057. }
  4058. const parents = dealSheet.zh_tree.getAllParents(dealBills);
  4059. if (!parents || parents.length === 0) {
  4060. return originalCode;
  4061. }
  4062. const kind4Parents = _.filter(parents, { kind: 4 });
  4063. if (!kind4Parents || kind4Parents.length === 0) {
  4064. return originalCode;
  4065. }
  4066. const firstParentCode = kind4Parents[0].code;
  4067. if (firstParentCode.charAt(0) === '-') {
  4068. return originalCode;
  4069. }
  4070. const codeParts = [];
  4071. for (const parent of kind4Parents.reverse()) {
  4072. codeParts.push(parent.code);
  4073. if (parent.code.charAt(0) !== '-') {
  4074. break;
  4075. }
  4076. }
  4077. if (codeParts.length > 0) {
  4078. return codeParts.reverse().join('') + originalCode;
  4079. }
  4080. return originalCode;
  4081. }
  4082. const oneBills = {
  4083. b_code: is_bill ? makeCode(dealBills) : null, code: !is_bill ? dealBills.code : null, name: dealBills.name, unit: dealBills.unit,
  4084. unit_price: is_bill ? dealBills.unitPrice : null, quantity: null, total_price: null,
  4085. sgfh_qty: null, sgfh_tp: null,
  4086. };
  4087. postData(window.location.pathname + '/update', {
  4088. postType: 'add-deal',
  4089. postData: {
  4090. id: mainNode.ledger_id,
  4091. type: mainNode.code ? 'child' : 'next',
  4092. dealBills: oneBills,
  4093. },
  4094. }, function (result) {
  4095. changeList = result.changeList;
  4096. const refreshData = mainTree.loadPostData(result);
  4097. billsTreeSpreadObj.refreshTree(mainSheet, refreshData);
  4098. const sel = mainSheet.getSelections()[0];
  4099. if (sel && refreshData.create[0]) {
  4100. mainSheet.setSelection(mainTree.nodes.indexOf(refreshData.create[0]), sel.col, sel.rowCount, sel.colCount);
  4101. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(refreshData.create[0])]);
  4102. }
  4103. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4104. billsSpread.focus();
  4105. posSpreadObj.loadCurPosData();
  4106. });
  4107. });
  4108. }
  4109. SpreadJsObj.forbiddenSpreadContextMenu(selector, this.spread);
  4110. const searchObj = {
  4111. result: [],
  4112. cur: 0,
  4113. searchStdNode: function() {
  4114. const keyword = $(`#${relaSelect.searchText}`).val();
  4115. searchObj.result = keyword ? dskProjectBills2Tree.tenderTree.nodes.filter(x => {
  4116. return (x.code && x.code.indexOf(keyword) >= 0) || (x.name && x.name.indexOf(keyword) >= 0);
  4117. }) : [];
  4118. // searchObj.result = [];
  4119. // for (const x of pathTree.nodes) {
  4120. // if (x.code.indexOf(keyword) >= 0 || x.b_code.indexOf(keyword) >= 0 || x.name.indexOf(keyword) >= 0) {
  4121. // searchObj.result.push(x);
  4122. // }
  4123. // }
  4124. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${searchObj.result.length}`;
  4125. searchObj.cur = 0;
  4126. if (searchObj.result.length > 0) {
  4127. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]));
  4128. }
  4129. },
  4130. searchPre: function () {
  4131. if (searchObj.result.length === 0) return;
  4132. searchObj.cur = searchObj.cur === 0 ? searchObj.result.length - 1 : this.cur - 1;
  4133. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4134. },
  4135. searchNext: function () {
  4136. if (searchObj.result.length === 0) return;
  4137. searchObj.cur = searchObj.cur === searchObj.result.length - 1 ? 0 : searchObj.cur + 1;
  4138. SpreadJsObj.locateTreeNode(searchSheet, dskProjectBills2Tree.tenderTree.getNodeKey(searchObj.result[searchObj.cur]), true);
  4139. },
  4140. clear: function () {
  4141. $(`#${relaSelect.searchText}`).val('');
  4142. $(`#${relaSelect.searchResult}`)[0].innerText = `结果:${0}`;
  4143. searchObj.result = [];
  4144. searchObj.cur = 0;
  4145. }
  4146. };
  4147. $(`#${relaSelect.searchText}`).change(searchObj.searchStdNode);
  4148. $(`#${relaSelect.searchPre}`).click(function (e) {
  4149. searchObj.searchPre();
  4150. e.stopPropagation();
  4151. });
  4152. $(`#${relaSelect.searchNext}`).click(function (e) {
  4153. searchObj.searchNext();
  4154. e.stopPropagation();
  4155. });
  4156. $(`#${relaSelect.searchClose}`).click(function (e) {
  4157. searchObj.clear();
  4158. e.stopPropagation();
  4159. });
  4160. };
  4161. loadData (callback) {
  4162. if (this.loaded) {
  4163. if (callback) callback();
  4164. return;
  4165. }
  4166. const self = this;
  4167. if (dskAccountData && dskAccountData.select_project) {
  4168. self.loaded = true;
  4169. changeDskProject(dskAccountData.select_project);
  4170. } else {
  4171. SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', []);
  4172. self.loaded = true;
  4173. }
  4174. if (callback) callback();
  4175. }
  4176. }
  4177. $('body').on('change', '#change-dsk-project', function () {
  4178. const pid = $(this).val();
  4179. changeDskProject(pid);
  4180. });
  4181. $('body').on('change', '#change-dsk-project-tree', function () {
  4182. const treeId = $(this).val();
  4183. const projectInfo = _.find(dskProjects, { pid: dskAccountData.select_project });
  4184. changeDskProjectTree(projectInfo, treeId);
  4185. });
  4186. function setDskProjectTreeSelect(trees) {
  4187. let html = '';
  4188. for (const tree of trees) {
  4189. html += `<option value="${tree.ID}" ${tree.ID === dskAccountData.select_tree ? 'selected' : ''}>${tree.name}</option>`;
  4190. }
  4191. $('#change-dsk-project-tree').html(html);
  4192. }
  4193. function changeDskProject(pid) {
  4194. const projectInfo = _.find(dskProjects, { pid });
  4195. if (!projectInfo) {
  4196. dskAccountData.select_project = null;
  4197. dskAccountData.select_tree = null;
  4198. const tree = dskProjectBills2Tree.convert([]);
  4199. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4200. return;
  4201. }
  4202. postData('/profile/dsk/api', { type: 'project_tree', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, projectId: projectInfo.pid }, function (datas) {
  4203. const trees = _.filter(datas, x => x.type === 4);
  4204. dskAccountData.select_project = projectInfo.pid;
  4205. setDskProjectTreeSelect(trees);
  4206. changeDskProjectTree(projectInfo, trees.length > 0 ? trees[0].ID : null);
  4207. });
  4208. }
  4209. function changeDskProjectTree(projectInfo, treeId) {
  4210. dskAccountData.select_tree = treeId;
  4211. if (!treeId) {
  4212. const tree = dskProjectBills2Tree.convert([]);
  4213. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4214. return;
  4215. }
  4216. postData('/profile/dsk/api', { type: 'project_bills', tid: window.location.pathname.split('/')[2], compilationId: projectInfo.compilationId, treeId }, function (result) {
  4217. const tree = dskProjectBills2Tree.convert(result);
  4218. console.log(tree);
  4219. SpreadJsObj.loadSheetData(dskBills.spread.getActiveSheet(), SpreadJsObj.DataType.Tree, tree);
  4220. });
  4221. }
  4222. const dskBills = new Dsk('#dsk-spread', {
  4223. cols: [
  4224. {title: '编号', field: 'code', hAlign: 0, width: 150, formatter: '@', cellType: 'tree'},
  4225. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@'},
  4226. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@'},
  4227. {title: '单价', field: 'unitPrice', hAlign: 2, width: 80, formatter: '@'},
  4228. {title: '数量', field: 'quantity', hAlign: 2, width: 80, formatter: '@'},
  4229. ],
  4230. emptyRows: 0,
  4231. headRows: 1,
  4232. headRowHeight: [32],
  4233. headColWidth: [30],
  4234. defaultRowHeight: 21,
  4235. headerFont: '12px 微软雅黑',
  4236. font: '12px 微软雅黑',
  4237. selectedBackColor: '#fffacd',
  4238. readOnly: true,
  4239. stdType: 'dsk',
  4240. libs: dskProjects,
  4241. select_lib: dskAccountData.select_project ? dskAccountData.select_project : null,
  4242. });
  4243. const dskProjectBills2Tree = (function () {
  4244. const treeSetting = {
  4245. id: 'dpb_id',
  4246. pid: 'dpb_pid',
  4247. order: 'seq',
  4248. level: 'level',
  4249. rootId: '-1',
  4250. fullPath: 'full_path',
  4251. };
  4252. const tenderTree = createNewPathTree('gather', treeSetting);
  4253. function setChildrenNode(node, dxs, files, tenders) {
  4254. const dxchildren = _.filter(dxs, { parentID: node.bid });
  4255. const children = _.filter(files, { parentID: node.bid });
  4256. const tenderChildren = _.filter(tenders, { parentID: node.bid });
  4257. const checkChildren = _.orderBy([...dxchildren, ...children, ...tenderChildren], ['seq', 'asc']);
  4258. for (const t of checkChildren) {
  4259. const child = {
  4260. bid: t.ID,
  4261. parentID: t.parentID,
  4262. name: t.name,
  4263. kind: t.kind,
  4264. code: t.code,
  4265. quantity: t.quantity,
  4266. quantity2: t.quantity2,
  4267. unit: t.unit,
  4268. unitPrice: t.unitPrice,
  4269. totalPrice: t.totalPrice,
  4270. formulaCode: t.formulaCode,
  4271. flag: t.flag,
  4272. remark: t.remark,
  4273. };
  4274. tenderTree.addNode(child, node);
  4275. setChildrenNode(child, dxs, files, tenders);
  4276. }
  4277. }
  4278. function convert (projects) {
  4279. tenderTree.clearDatas();
  4280. // 区分文件夹及项目
  4281. const topLevel = _.orderBy(_.filter(projects, { parentID: '-1' }), ['seq', 'asc']);
  4282. const dxs = _.filter(projects, { kind: 1 });
  4283. const files = _.filter(projects, { kind: 4 });
  4284. const tenders = _.filter(projects, { kind: 8 });
  4285. for (const t of topLevel) {
  4286. const node = {
  4287. bid: t.ID,
  4288. parentID: t.parentID,
  4289. name: t.name,
  4290. kind: t.kind,
  4291. code: t.code,
  4292. quantity: t.quantity,
  4293. quantity2: t.quantity2,
  4294. unit: t.unit,
  4295. unitPrice: t.unitPrice,
  4296. totalPrice: t.totalPrice,
  4297. formulaCode: t.formulaCode,
  4298. flag: t.flag,
  4299. remark: t.remark,
  4300. };
  4301. tenderTree.addNode(node, null);
  4302. setChildrenNode(node, dxs, files, tenders);
  4303. }
  4304. tenderTree.sortTreeNode(true);
  4305. return tenderTree;
  4306. }
  4307. return { tenderTree, convert }
  4308. })();
  4309. $.divResizer({
  4310. select: '#revise-right-spr',
  4311. callback: function () {
  4312. billsSpread.refresh();
  4313. if (posSpread) posSpread.refresh();
  4314. if (stdXmj) stdXmj.spread.refresh();
  4315. if (stdGcl) stdGcl.spread.refresh();
  4316. if (dealBills) dealBills.spread.refresh();
  4317. if (searchLedger) searchLedger.spread.refresh();
  4318. if (errorList) errorList.spread.refresh();
  4319. if (checkList) checkList.spread.refresh();
  4320. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4321. if (jlzfBills) jlzfBills.spread.refresh();
  4322. if (dskBills) dskBills.spread.refresh();
  4323. }
  4324. });
  4325. $.subMenu({
  4326. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  4327. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  4328. key: 'menu.1.0.0',
  4329. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  4330. callback: function (info) {
  4331. if (info.mini) {
  4332. $('.panel-title').addClass('fluid');
  4333. $('#sub-menu').removeClass('panel-sidebar');
  4334. } else {
  4335. $('.panel-title').removeClass('fluid');
  4336. $('#sub-menu').addClass('panel-sidebar');
  4337. }
  4338. autoFlashHeight();
  4339. billsSpread.refresh();
  4340. if (posSpread) posSpread.refresh();
  4341. if (stdXmj) stdXmj.spread.refresh();
  4342. if (stdGcl) stdGcl.spread.refresh();
  4343. if (dealBills) dealBills.spread.refresh();
  4344. if (searchLedger) searchLedger.spread.refresh();
  4345. if (errorList) errorList.spread.refresh();
  4346. if (checkList) checkList.spread.refresh();
  4347. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  4348. if (jlzfBills) jlzfBills.spread.refresh();
  4349. if (dskBills) dskBills.spread.refresh();
  4350. }
  4351. });
  4352. // showSideTools(true);
  4353. billsSpread.refresh();
  4354. if (posSpread) posSpread.refresh();
  4355. const stdLibCellDoubleClick = function (updateData, stdNode, stdTree) {
  4356. const mainSheet = billsSheet;
  4357. if (!stdTree || !mainSheet.zh_tree) { return; }
  4358. const mainTree = mainSheet.zh_tree;
  4359. const sel = mainSheet.getSelections()[0];
  4360. const mainNode = mainTree.nodes[sel.row];
  4361. if (!stdNode) return;
  4362. if (updateData.postData.stdType === 'gcl') {
  4363. if (mainNode.code && mainNode.code !== '' && !mainTree.isLeafXmj(mainNode)) {
  4364. toastr.warning('非最底层项目下,不应添加节点');
  4365. return;
  4366. }
  4367. if (mainNode.settle_status === settleStatus.finish) {
  4368. toastr.warning('已结算节点下,不可添加工程量清单');
  4369. return;
  4370. }
  4371. } else {
  4372. const stdNodes = stdTree.getAllParents(stdNode);
  4373. for (const node of stdNodes) {
  4374. const parent = mainTree.datas.find(x => { return x.code === node.code && x.name === node.name; });
  4375. if (parent && parent.settle_status === settleStatus.finish) {
  4376. toastr.warning('项目节父项已结算,不可添加节点');
  4377. return;
  4378. }
  4379. }
  4380. }
  4381. postData(window.location.pathname + '/update', {
  4382. postType: 'add-std',
  4383. postData: {
  4384. id: mainTree.getNodeKey(mainNode),
  4385. tender_id: mainNode.tender_id,
  4386. stdType: updateData.postData.stdType,
  4387. stdLibId: stdNode.list_id,
  4388. stdNode: stdTree.getNodeKey(stdNode)
  4389. }
  4390. }, function (result) {
  4391. changeList = result.changeList;
  4392. const refreshNode = mainTree.loadPostData(result);
  4393. billsTreeSpreadObj.refreshTree(mainSheet, refreshNode);
  4394. if (sel) {
  4395. if (refreshNode.create && refreshNode.create.length > 0) {
  4396. mainSheet.setSelection(refreshNode.create[refreshNode.create.length - 1].index, sel.col, sel.rowCount, sel.colCount);
  4397. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, refreshNode.create[refreshNode.create.length - 1].index]);
  4398. } else {
  4399. const node = _.find(mainTree.nodes, {code: stdNode.code, name: stdNode.name});
  4400. if (node) {
  4401. mainSheet.setSelection(mainTree.nodes.indexOf(node), sel.col, sel.rowCount, sel.colCount);
  4402. SpreadJsObj.reloadRowsBackColor(mainSheet, [sel.row, mainTree.nodes.indexOf(node)]);
  4403. }
  4404. }
  4405. }
  4406. billsTreeSpreadObj.refreshOperationValid(mainSheet);
  4407. billsSpread.focus();
  4408. posSpreadObj.loadCurPosData();
  4409. });
  4410. };
  4411. const stdXmjSetting = {
  4412. selector: '#std-xmj',
  4413. stdType: 'xmj',
  4414. libs: stdChapters,
  4415. treeSetting: {
  4416. id: 'chapter_id',
  4417. pid: 'pid',
  4418. order: 'order',
  4419. level: 'level',
  4420. rootId: -1,
  4421. keys: ['id', 'list_id', 'chapter_id'],
  4422. },
  4423. spreadSetting: {
  4424. cols: [
  4425. {title: '项目节编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4426. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4427. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4428. ],
  4429. treeCol: 0,
  4430. emptyRows: 0,
  4431. headRows: 1,
  4432. headRowHeight: [32],
  4433. defaultRowHeight: 21,
  4434. headerFont: '12px 微软雅黑',
  4435. font: '12px 微软雅黑',
  4436. headColWidth: [30],
  4437. selectedBackColor: '#fffacd',
  4438. },
  4439. cellDoubleClick: stdLibCellDoubleClick,
  4440. page: 'revise',
  4441. tid: window.location.pathname.split('/')[2],
  4442. };
  4443. const stdGclSetting = {
  4444. selector: '#std-gcl',
  4445. stdType: 'gcl',
  4446. libs: stdBills,
  4447. treeSetting: {
  4448. id: 'bill_id',
  4449. pid: 'pid',
  4450. order: 'order',
  4451. level: 'level',
  4452. rootId: -1,
  4453. keys: ['id', 'list_id', 'bill_id']
  4454. },
  4455. spreadSetting: {
  4456. cols: [
  4457. {title: '清单编号', field: 'b_code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  4458. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  4459. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true}
  4460. ],
  4461. treeCol: 0,
  4462. emptyRows: 0,
  4463. headRows: 1,
  4464. headRowHeight: [32],
  4465. defaultRowHeight: 21,
  4466. headerFont: '12px 微软雅黑',
  4467. font: '12px 微软雅黑',
  4468. headColWidth: [30],
  4469. selectedBackColor: '#fffacd',
  4470. },
  4471. cellDoubleClick: stdLibCellDoubleClick,
  4472. page: 'revise',
  4473. tid: window.location.pathname.split('/')[2],
  4474. };
  4475. // 展开收起标准节点
  4476. $('a', '#side-menu').bind('click', function (e) {
  4477. e.preventDefault();
  4478. const tab = $(this), tabPanel = $(tab.attr('content'));
  4479. // 展开工具栏、切换标签
  4480. if (!tab.hasClass('active')) {
  4481. const close = $('.active', '#side-menu').length === 0;
  4482. $('a', '#side-menu').removeClass('active');
  4483. tab.addClass('active');
  4484. $('.tab-content .tab-pane').removeClass('active');
  4485. tabPanel.addClass('active');
  4486. showSideTools(tab.hasClass('active'));
  4487. if (tab.attr('content') === '#std-xmj') {
  4488. if (!stdXmj) {
  4489. stdXmj = $.stdLib(stdXmjSetting);
  4490. }
  4491. stdXmj.spread.refresh();
  4492. } else if (tab.attr('content') === '#std-gcl') {
  4493. if (!stdGcl) {
  4494. stdGcl = $.stdLib(stdGclSetting);
  4495. }
  4496. stdGcl.spread.refresh();
  4497. } else if (tab.attr('content') === '#deal-bills') {
  4498. dealBills.loadData();
  4499. dealBills.spread.refresh();
  4500. } else if (tab.attr('content') === '#search') {
  4501. if (!searchLedger) {
  4502. searchLedger = $.ledgerSearch({
  4503. selector: '#search',
  4504. ledger: { billsTree: billsTree, pos: pos },
  4505. searchOver: true,
  4506. searchEmpty: true,
  4507. resultSpreadSetting: {
  4508. cols: [
  4509. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  4510. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  4511. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  4512. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  4513. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  4514. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  4515. {title: '部位', field: 'bw', hAlign: 2, width: 90},
  4516. ],
  4517. emptyRows: 0,
  4518. headRows: 1,
  4519. headRowHeight: [32],
  4520. headColWidth: [30],
  4521. defaultRowHeight: 21,
  4522. headerFont: '12px 微软雅黑',
  4523. font: '12px 微软雅黑',
  4524. selectedBackColor: '#fffacd',
  4525. readOnly: true,
  4526. },
  4527. locate: function(cur) {
  4528. if (!cur.lid) return;
  4529. SpreadJsObj.locateTreeNode(billsSheet, cur.lid, true);
  4530. posSpreadObj.loadCurPosData();
  4531. if (cur.pid && cur.pid !== -1) {
  4532. const pIndex = posSheet.zh_data.findIndex(x => { return x.id === cur.pid; });
  4533. SpreadJsObj.locateRow(posSheet, pIndex);
  4534. }
  4535. },
  4536. customSearch: [
  4537. {
  4538. key: 'revise', title: '新增部位', valid: true, parent: true,
  4539. check: function (node) {
  4540. if (node.formc || node.cid) {
  4541. return true;
  4542. } else {
  4543. return false;
  4544. }
  4545. }
  4546. }
  4547. ],
  4548. });
  4549. }
  4550. searchLedger.spread.refresh();
  4551. } else if (tab.attr('content') === '#error-list') {
  4552. errorList.spread.refresh();
  4553. } else if (tab.attr('content') === '#check-list') {
  4554. checkList.spread.refresh();
  4555. } else if (tab.attr('content') === '#sum-load-miss') {
  4556. sumLoadMiss.spread.refresh();
  4557. } else if (tab.attr('content') === '#dsk-list') {
  4558. const dskActiveTab = $('#dsk-tab a[class*="active"]').attr('href');
  4559. $(dskActiveTab).addClass('active');
  4560. if (dskActiveTab === '#jlzf-spread') {
  4561. $('#get-dsk-btn').hide();
  4562. $('#get-dsk-bills-btn').hide();
  4563. jlzfBills.loadData();
  4564. jlzfBills.spread.refresh();
  4565. } else if (dskActiveTab === '#dsk-spread') {
  4566. $('#get-dsk-btn').show();
  4567. $('#get-dsk-bills-btn').show();
  4568. dskBills.loadData();
  4569. dskBills.spread.refresh();
  4570. }
  4571. }
  4572. }
  4573. else {// 收起工具栏
  4574. tab.removeClass('active');
  4575. tabPanel.removeClass('active');
  4576. showSideTools(tab.hasClass('active'));
  4577. }
  4578. billsSpread.refresh();
  4579. if (posSpread) posSpread.refresh();
  4580. });
  4581. // 新增清单切换tab
  4582. $('#dsk-tab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  4583. e.preventDefault();
  4584. const dskActiveTab = $(this).attr('href');
  4585. if (dskActiveTab === '#jlzf-spread') {
  4586. $('#get-dsk-btn').hide();
  4587. $('#get-dsk-bills-btn').hide();
  4588. jlzfBills.loadData();
  4589. jlzfBills.spread.refresh();
  4590. } else if (dskActiveTab === '#dsk-spread') {
  4591. $('#get-dsk-btn').show();
  4592. $('#get-dsk-bills-btn').show();
  4593. dskBills.loadData();
  4594. dskBills.spread.refresh();
  4595. }
  4596. });
  4597. // 显示层次
  4598. (function (select, sheet) {
  4599. $(select).click(function () {
  4600. if (!sheet.zh_tree) return;
  4601. const tag = $(this).attr('tag');
  4602. const tree = sheet.zh_tree;
  4603. setTimeout(() => {
  4604. showWaitingView();
  4605. switch (tag) {
  4606. case "1":
  4607. case "2":
  4608. case "3":
  4609. case "4":
  4610. case "5":
  4611. tree.expandByLevel(parseInt(tag));
  4612. SpreadJsObj.refreshTreeRowVisible(sheet);
  4613. break;
  4614. case "last":
  4615. tree.expandByCustom(() => { return true; });
  4616. SpreadJsObj.refreshTreeRowVisible(sheet);
  4617. break;
  4618. case "leafXmj":
  4619. tree.expandToLeafXmj();
  4620. SpreadJsObj.refreshTreeRowVisible(sheet);
  4621. break;
  4622. }
  4623. closeWaitingView();
  4624. }, 100);
  4625. });
  4626. })('a[name=showLevel]', billsSheet);
  4627. const dataChecker = DataChecker({
  4628. checkUrl: window.location.pathname + '/check',
  4629. completeData: function (data) {
  4630. pos.updateDatas({update: data.source.pos});
  4631. const loadResult = billsTree.loadPostData({update: data.source.bills});
  4632. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  4633. posSpreadObj.loadCurPosData();
  4634. for (const e of data.error) {
  4635. e.serialNo = billsTree.getNodeIndex(billsTree.getItems(e.ledger_id)) + 1;
  4636. }
  4637. },
  4638. errorList: errorList,
  4639. });
  4640. $('#ledger-check2').click(() => {
  4641. ledgerCheck2({
  4642. ledgerTree: billsTree,
  4643. ledgerPos: pos,
  4644. checkList: checkList,
  4645. decimal: decimal,
  4646. checkOption: checkOption,
  4647. }).then(result => {
  4648. check2Viewing({
  4649. extra: ZhCalc.div(billsTree.datas.length + pos.datas.length, 10000, 0),
  4650. randomWait: true,
  4651. prefix: 'check2-',
  4652. checks: result,
  4653. checkList: checkList,
  4654. });
  4655. });
  4656. });
  4657. if (isYb) {
  4658. let compilationList = [];
  4659. $('#get-dsk-btn').click(function () {
  4660. // 判断是否已绑定dsk用户
  4661. postData('/profile/dsk/api', {type: 'hadbind'}, function (result) {
  4662. if (result === 1) {
  4663. $('#error-dsk .modal-body').find('h5').eq(0).show();
  4664. $('#error-dsk .modal-body').find('h5').eq(1).hide();
  4665. $('#error-dsk').modal('show');
  4666. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定手机');
  4667. } else if (result === 2) {
  4668. $('#error-dsk .modal-body').find('h5').eq(1).show();
  4669. $('#error-dsk .modal-body').find('h5').eq(0).hide();
  4670. $('#error-dsk').modal('show');
  4671. $('#error-dsk .modal-footer').find('a').eq(0).text('绑定账号');
  4672. } else {
  4673. postData('/profile/dsk/api', {
  4674. type: 'compilation',
  4675. getProject: 1,
  4676. compilationId: getLocalCache(dskCompilation)
  4677. }, function (result) {
  4678. let html = '';
  4679. for (const data of result.compilation) {
  4680. if (data.ID !== '5c66649650da2d000d8d37ba' && data.ID !== '5b52b027fd3bb0000b257cf8') {
  4681. html += `<option value="${data.ID}" ${result.select_compilation === data.ID ? 'selected' : ''}>${data.name}</option>`;
  4682. }
  4683. }
  4684. dskAccountData = result.dskAccountData;
  4685. compilationList = result.compilation;
  4686. console.log(compilationList);
  4687. $('#dsk-compilation-list').html(html);
  4688. $('#add-dsk').modal('show');
  4689. setLocalCache(dskCompilation, result.select_compilation);
  4690. makeDskProjectSjsHtml(result.project);
  4691. });
  4692. }
  4693. })
  4694. });
  4695. $('#get-dsk-bills-btn').click(function () {
  4696. const projectInfo = _.find(dskProjects, {pid: dskAccountData.select_project ? dskAccountData.select_project : null});
  4697. changeDskProjectTree(projectInfo, dskAccountData.select_tree ? dskAccountData.select_tree : null);
  4698. });
  4699. $('body').on('change', '#dsk-compilation-list', function () {
  4700. const compilationId = $(this).val();
  4701. setLocalCache(dskCompilation, compilationId);
  4702. dskProjectSpreadObj.refreshSourceTree();
  4703. });
  4704. $('.hide-dsk-modal').click(function () {
  4705. $('#error-dsk').modal('hide');
  4706. });
  4707. let dp = false;
  4708. let gsObj = {
  4709. setting: null,
  4710. gsSheet: null,
  4711. grSheet: null,
  4712. tenderSourceTree: null,
  4713. grArray: dskProjects ? dskProjects : [],
  4714. orgSelect: null,
  4715. };
  4716. function makeDskProjectSjsHtml(datas) {
  4717. if (!dp) {
  4718. initDskProjectTree();
  4719. dp = true;
  4720. }
  4721. gsObj.tenderSourceTree = dskProject2Tree.convert(datas);
  4722. SpreadJsObj.loadSheetData(gsObj.gsSheet, SpreadJsObj.DataType.Tree, gsObj.tenderSourceTree);
  4723. SpreadJsObj.loadSheetData(gsObj.grSheet, SpreadJsObj.DataType.Data, gsObj.grArray);
  4724. if (datas.length === 0) {
  4725. $('#show-project-0').show();
  4726. } else {
  4727. $('#show-project-0').hide();
  4728. }
  4729. }
  4730. const dskProjectSpreadObj = {
  4731. _addTender: function (tender) {
  4732. const gr = gsObj.grArray.find(function (x) {
  4733. return x.pid === tender.pid;
  4734. });
  4735. const c_id = getLocalCache(dskCompilation);
  4736. const t = {
  4737. pid: tender.pid,
  4738. name: tender.name,
  4739. compilationId: c_id,
  4740. compilationName: _.find(compilationList, {ID: c_id}).name
  4741. };
  4742. if (!gr) gsObj.grArray.push(t);
  4743. return t;
  4744. },
  4745. _removeTender: function (tender) {
  4746. const gri = gsObj.grArray.findIndex(function (x, i, arr) {
  4747. return x.pid === tender.pid;
  4748. });
  4749. if (gri >= 0) gsObj.grArray.splice(gri, 1);
  4750. },
  4751. reloadResultData: function () {
  4752. SpreadJsObj.reLoadSheetData(gsObj.grSheet);
  4753. },
  4754. refreshSourceTree: function () {
  4755. const c_id = getLocalCache(dskCompilation);
  4756. if (c_id) {
  4757. postData('/profile/dsk/api', {type: 'project', compilationId: c_id}, function (result) {
  4758. makeDskProjectSjsHtml(result);
  4759. });
  4760. }
  4761. },
  4762. gsButtonClicked: function (e, info) {
  4763. if (!info.sheet.zh_setting) return;
  4764. const col = info.sheet.zh_setting.cols[info.col];
  4765. if (col.field !== 'selected') return;
  4766. const node = SpreadJsObj.getSelectObject(info.sheet);
  4767. node.selected = !node.selected;
  4768. if (node.children && node.children.length > 0) {
  4769. const posterity = gsObj.tenderSourceTree.getPosterity(node);
  4770. for (const p of posterity) {
  4771. p.selected = node.selected;
  4772. if ((!p.children || p.children.length === 0) && p.type === 2) {
  4773. if (p.selected) {
  4774. dskProjectSpreadObj._addTender(p);
  4775. } else {
  4776. dskProjectSpreadObj._removeTender(p);
  4777. }
  4778. }
  4779. }
  4780. SpreadJsObj.reLoadRowData(info.sheet, info.row, posterity.length + 1);
  4781. } else if (node.type === 2) {
  4782. if (node.selected) {
  4783. dskProjectSpreadObj._addTender(node);
  4784. } else {
  4785. dskProjectSpreadObj._removeTender(node);
  4786. }
  4787. SpreadJsObj.reLoadRowData(info.sheet, info.row, 1);
  4788. }
  4789. dskProjectSpreadObj.reloadResultData();
  4790. },
  4791. deleteGr: function () {
  4792. if (gsObj.grArray.length === 0) return;
  4793. if (gsObj.grSheet.getSelections().length === 0) return;
  4794. const selections = gsObj.grSheet.getSelections();
  4795. const sel = selections ? selections[0] : gsObj.grSheet.getSelections()[0];
  4796. const row = sel && sel.row !== undefined ? sel.row : -1;
  4797. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  4798. return false;
  4799. }
  4800. const delList = [];
  4801. for (let r = 0; r < sel.rowCount; r++) {
  4802. const select = gsObj.grArray[row + r];
  4803. delList.push(select);
  4804. }
  4805. _.pullAll(gsObj.grArray, delList);
  4806. dskProjectSpreadObj.reloadResultData();
  4807. dskProjectSpreadObj.refreshSourceTree();
  4808. },
  4809. };
  4810. const initDskProjectTree = function () {
  4811. const gsSpread = SpreadJsObj.createNewSpread($('#dsk-project-source-spread')[0]);
  4812. gsObj.gsSheet = gsSpread.getActiveSheet();
  4813. const gsSpreadSetting = {
  4814. cols: [
  4815. {
  4816. title: '选择',
  4817. field: 'selected',
  4818. hAlign: 1,
  4819. width: 40,
  4820. formatter: '@',
  4821. cellType: 'checkbox',
  4822. readOnly: true,
  4823. },
  4824. {
  4825. title: '名称',
  4826. field: 'name',
  4827. hAlign: 0,
  4828. width: 400,
  4829. formatter: '@',
  4830. readOnly: true,
  4831. folderCell: true,
  4832. cellType: 'tree'
  4833. },
  4834. ],
  4835. emptyRows: 0,
  4836. headRows: 1,
  4837. headRowHeight: [32],
  4838. defaultRowHeight: 21,
  4839. headerFont: '12px 微软雅黑',
  4840. font: '12px 微软雅黑',
  4841. headColWidth: [0],
  4842. selectedBackColor: '#fffacd',
  4843. };
  4844. SpreadJsObj.initSheet(gsObj.gsSheet, gsSpreadSetting);
  4845. gsSpread.bind(spreadNS.Events.ButtonClicked, dskProjectSpreadObj.gsButtonClicked);
  4846. const grSpread = SpreadJsObj.createNewSpread($('#dsk-project-result-spread')[0]);
  4847. gsObj.grSheet = grSpread.getActiveSheet();
  4848. const grSpreadSetting = {
  4849. cols: [
  4850. {
  4851. title: '名称',
  4852. colSpan: '1',
  4853. rowSpan: '1',
  4854. field: 'name',
  4855. hAlign: 0,
  4856. width: 250,
  4857. formatter: '@',
  4858. readOnly: true,
  4859. cellType: 'ellipsisAutoTip',
  4860. scrollHeightClass: '.modal-height-500'
  4861. },
  4862. {
  4863. title: '所属编办',
  4864. colSpan: '1',
  4865. rowSpan: '1',
  4866. field: 'compilationName',
  4867. hAlign: 0,
  4868. width: 150,
  4869. formatter: '@',
  4870. readOnly: true
  4871. },
  4872. ],
  4873. emptyRows: 0,
  4874. headRows: 1,
  4875. headRowHeight: [32],
  4876. defaultRowHeight: 21,
  4877. headerFont: '12px 微软雅黑',
  4878. font: '12px 微软雅黑',
  4879. headColWidth: []
  4880. };
  4881. SpreadJsObj.initSheet(gsObj.grSheet, grSpreadSetting);
  4882. // 右键删除已选项目
  4883. const gsContextMenuOptions = {
  4884. selector: '#dsk-project-result-spread',
  4885. build: function ($trigger, e) {
  4886. const target = SpreadJsObj.safeRightClickSelection($trigger, e, grSpread);
  4887. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  4888. },
  4889. items: {
  4890. delete: {
  4891. name: '删除',
  4892. icon: 'fa-remove',
  4893. callback: function (key, opt) {
  4894. dskProjectSpreadObj.deleteGr();
  4895. },
  4896. disabled: function (key, opt) {
  4897. const selection = gsObj.grSheet.getSelections();
  4898. const sel = selection ? selection[0] : gsObj.grSheet.getSelections()[0];
  4899. const row = sel && sel.row !== undefined ? sel.row : -1;
  4900. if (row === -1 || sel.row + sel.rowCount > gsObj.grArray.length) {
  4901. return true;
  4902. }
  4903. return false;
  4904. }
  4905. },
  4906. }
  4907. };
  4908. $.contextMenu(gsContextMenuOptions);
  4909. $('#add-dsk').bind('shown.bs.modal', function () {
  4910. if (gsSpread) gsSpread.refresh();
  4911. if (grSpread) grSpread.refresh();
  4912. });
  4913. };
  4914. const dskProject2Tree = (function () {
  4915. const treeSetting = {
  4916. id: 'tmt_id',
  4917. pid: 'tmt_pid',
  4918. order: 'seq',
  4919. level: 'level',
  4920. rootId: '-1',
  4921. fullPath: 'full_path',
  4922. };
  4923. const tenderTree = createNewPathTree('gather', treeSetting);
  4924. function setChildrenNode(node, files, tenders) {
  4925. const children = _.filter(files, {parentID: node.pid});
  4926. const tenderChildren = _.filter(tenders, {parentID: node.pid});
  4927. const checkChildren = _.orderBy([...children, ...tenderChildren], ['seq', 'asc']);
  4928. for (const c of checkChildren) {
  4929. // if (c.type === 1 && _.filter(files, { parentID: c.ID }).length === 0 && _.filter(tenders, { parentID: c.ID }).length === 0) {
  4930. // // 判断文件夹下有无东西,没有就不插入
  4931. // continue;
  4932. // }
  4933. const child = {
  4934. pid: c.ID,
  4935. parentID: c.parentID,
  4936. name: c.name,
  4937. type: c.type,
  4938. selected: _.findIndex(gsObj.grArray, {pid: c.ID}) >= 0
  4939. };
  4940. tenderTree.addNode(child, node);
  4941. if (c.type === 1) setChildrenNode(child, files, tenders);
  4942. }
  4943. }
  4944. function convert(projects) {
  4945. tenderTree.clearDatas();
  4946. const result = filterFolders(projects);
  4947. const topLevel = _.orderBy(_.filter(result, {parentID: '-1'}), ['seq', 'asc']);
  4948. const files = _.filter(result, {type: 1});
  4949. const tenders = _.filter(result, {type: 2});
  4950. for (const t of topLevel) {
  4951. const node = {
  4952. pid: t.ID,
  4953. parentID: t.parentID,
  4954. name: t.name,
  4955. type: t.type,
  4956. selected: t.type === 2 ? _.findIndex(gsObj.grArray, {pid: t.ID}) >= 0 : false,
  4957. };
  4958. tenderTree.addNode(node, null);
  4959. if (t.type === 1) setChildrenNode(node, files, tenders);
  4960. }
  4961. tenderTree.sortTreeNode(true);
  4962. return tenderTree;
  4963. }
  4964. return {tenderTree, convert}
  4965. })();
  4966. function filterFolders(data) {
  4967. // 构建ID到节点的映射
  4968. const idMap = data.reduce((map, node) => {
  4969. map[node.ID] = node;
  4970. return map;
  4971. }, {});
  4972. // 建立父子关系映射
  4973. const parentMap = data.reduce((map, node) => {
  4974. if (node.parentID !== '-1') {
  4975. if (!map[node.parentID]) {
  4976. map[node.parentID] = [];
  4977. }
  4978. map[node.parentID].push(node.ID);
  4979. }
  4980. return map;
  4981. }, {});
  4982. // 检查节点及其子节点是否包含清单(type=1)
  4983. const hasChecklist = (id) => {
  4984. const node = idMap[id];
  4985. if (node.type === 2) {
  4986. return true;
  4987. }
  4988. if (!parentMap[id]) {
  4989. return false;
  4990. }
  4991. return parentMap[id].some(childID => hasChecklist(childID));
  4992. };
  4993. // 过滤节点
  4994. const filteredIDs = new Set();
  4995. data.forEach(node => {
  4996. if (node.type === 2 || hasChecklist(node.ID)) {
  4997. let currentID = node.ID;
  4998. while (currentID !== '-1') {
  4999. filteredIDs.add(currentID);
  5000. currentID = idMap[currentID].parentID;
  5001. }
  5002. }
  5003. });
  5004. // 返回过滤后的数据
  5005. return data.filter(node => filteredIDs.has(node.ID));
  5006. }
  5007. $('#set-dsk-project').click(function () {
  5008. postData('/profile/dsk/api', {
  5009. type: 'save_projects',
  5010. tid: window.location.pathname.split('/')[2],
  5011. project_list: gsObj.grArray
  5012. }, function (result) {
  5013. // dskAccountData.select_project = result;
  5014. dskProjects = gsObj.grArray;
  5015. if (!dskAccountData.select_project || dskAccountData.select_project !== result) {
  5016. dskAccountData.select_project = result;
  5017. changeDskProject(result);
  5018. dskBills.spread.refresh();
  5019. }
  5020. setDskProjectSelect(gsObj.grArray);
  5021. $('#add-dsk').modal('hide');
  5022. });
  5023. });
  5024. $('#add-dsk').on('hide.bs.modal', function () {
  5025. $('#autoTip').hide();
  5026. });
  5027. function setDskProjectSelect(projects) {
  5028. let html = '';
  5029. for (const project of projects) {
  5030. html += `<option value="${project.pid}" ${project.pid === dskAccountData.select_project ? 'selected' : ''}>${project.name}</option>`;
  5031. }
  5032. $('#change-dsk-project').html(html);
  5033. }
  5034. // 选中所有新增部位/清单
  5035. $('#add-all-revise').click(function() {
  5036. const this_cid = window.location.pathname.split('/')[4];
  5037. makeGclGatherData();
  5038. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5039. type: 'get-revise-list',
  5040. }, function (result) {
  5041. const addDatas = [];
  5042. for (const ggd in gclGatherData) {
  5043. gclGatherData[ggd].code = gclGatherData[ggd].b_code;
  5044. let hadcid = 0;
  5045. for (const xmj of gclGatherData[ggd].leafXmjs) {
  5046. const changeLedger = _.find(result.changeLedgerList, {id: xmj.gcl_id});
  5047. const changePos = _.find(result.changePosList, {id: xmj.mx_id, lid: xmj.gcl_id});
  5048. if (changeLedger || changePos) {
  5049. xmj.cid = 1;
  5050. xmj.ccid = changePos ? changePos.ccid : changeLedger ? changeLedger.ccid : 0;
  5051. hadcid = 1;
  5052. }
  5053. }
  5054. if (hadcid !== 0) gclGatherData[ggd].cid = 1;
  5055. }
  5056. for (const gclInfo of _.filter(gclGatherData, {cid: 1})) {
  5057. const leafXmjs = _.filter(gclInfo.leafXmjs, {ccid: this_cid});
  5058. if (leafXmjs.length > 0) {
  5059. gclInfo.is_change = 1;
  5060. for (const xmj of leafXmjs) {
  5061. if (_.findIndex(changeList, function (item) {
  5062. return item.gcl_id === xmj.gcl_id && item.mx_id === (xmj.mx_id || '');
  5063. }) === -1) {
  5064. addDatas.push({
  5065. lid: xmj.gcl_id,
  5066. code: gclInfo.code,
  5067. name: gclInfo.name || '',
  5068. unit: gclInfo.unit || '',
  5069. unit_price: gclInfo.unit_price,
  5070. oamount: xmj.quantity,
  5071. oamount2: xmj.quantity,
  5072. bwmx: xmj.bwmx || xmj.jldy || '',
  5073. xmj_code: xmj.code || '',
  5074. xmj_jldy: xmj.jldy || '',
  5075. xmj_dwgc: xmj.dwgc || '',
  5076. xmj_fbgc: xmj.fbgc || '',
  5077. xmj_fxgc: xmj.fxgc || '',
  5078. gcl_id: xmj.gcl_id,
  5079. mx_id: xmj.mx_id || '',
  5080. });
  5081. }
  5082. }
  5083. }
  5084. }
  5085. console.log(addDatas);
  5086. if (addDatas.length > 0) {
  5087. // 更新至服务器
  5088. postData('/tender/' + window.location.pathname.split('/')[2] + '/change/' + window.location.pathname.split('/')[4] + '/information/save', {
  5089. type: 'add-change-list',
  5090. postData: addDatas,
  5091. }, function (result) {
  5092. toastr.success('已新增当前变更令新增的所有部位/清单');
  5093. changeList = result.changeList;
  5094. const sortData = SpreadJsObj.getSortData(billsSheet);
  5095. const billsNodes = _.filter(sortData, function (item) {
  5096. return _.findIndex(addDatas, {gcl_id: item.id}) !== -1;
  5097. });
  5098. for (const billsNode of billsNodes) {
  5099. billsNode.is_change = 1;
  5100. }
  5101. const loadResult = { update: billsNodes };
  5102. billsTreeSpreadObj.refreshTree(billsSheet, loadResult);
  5103. posSpreadObj.loadCurPosData();
  5104. });
  5105. } else {
  5106. toastr.warning('未存在当前变更令新增的部位/清单');
  5107. }
  5108. });
  5109. });
  5110. }
  5111. });
  5112. function findDecimal(unit) {
  5113. let value = precision.other.value;
  5114. const changeUnits = precision;
  5115. for (const d in changeUnits) {
  5116. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  5117. value = changeUnits[d].value;
  5118. break;
  5119. }
  5120. }
  5121. return value;
  5122. }
  5123. // 编号排序,多重判断
  5124. function sortByCode(a, b, code = 'b_code') {
  5125. let code1 = a[code].split('-');
  5126. let code2 = b[code].split('-');
  5127. let code1length = code1.length;
  5128. let code2length = code2.length;
  5129. for (let i = 0; i < code1length; i ++) {
  5130. if (i+1 <= code2length) {
  5131. if (code1[i] != code2[i]) {
  5132. if (/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  5133. return parseInt(code1[i]) - parseInt(code2[i]);
  5134. } else if (!/^\d+$/.test(code1[i]) && /^\d+$/.test(code2[i])) {
  5135. return 1;
  5136. } else if (/^\d+$/.test(code1[i]) && !/^\d+$/.test(code2[i])) {
  5137. return -1;
  5138. } else {
  5139. const str1length = code1[i].length;
  5140. const str2length = code2[i].length;
  5141. for (let j = 0; j < str1length; j++) {
  5142. if (j+1 <= str2length) {
  5143. if (code1[i].charAt(j) != code2[i].charAt(j)) {
  5144. return code1[i].charAt(j).charCodeAt() - code2[i].charAt(j).charCodeAt();
  5145. } else if (j+1 == str1length && code1[i].charAt(j) == code2[i].charAt(j)) {
  5146. if (str1length == str2length) {
  5147. return 0;
  5148. } else {
  5149. return str1length - str2length;
  5150. }
  5151. }
  5152. } else {
  5153. if (j+1 >= str1length) {
  5154. return 1;
  5155. } else {
  5156. return -1;
  5157. }
  5158. }
  5159. }
  5160. }
  5161. } else if (i+1 == code1length && code1[i] == code2[i]) {
  5162. if (code1length == code2length) {
  5163. return 0;
  5164. } else {
  5165. return code1length - code2length;
  5166. }
  5167. }
  5168. } else {
  5169. if (i+1 >= code1length) {
  5170. return 1;
  5171. } else {
  5172. return -1;
  5173. }
  5174. }
  5175. }
  5176. }