change_revise.js 247 KB

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