stage.js 256 KB

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