stage.js 234 KB

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