stage.js 215 KB

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