stage.js 236 KB

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