stage.js 248 KB

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