stage.js 268 KB

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