change_revise.js 245 KB

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