stage.js 243 KB

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