stage.js 235 KB

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