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