stage.js 244 KB

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