stage.js 219 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557
  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. visible: function(key, opt) {
  1530. if (cur_uid === stage.user_id) return true;
  1531. },
  1532. disabled: function (key, opt) {
  1533. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1534. if (!node || !node.b_code || !node.is_leaf || cur_uid !== stage.user_id) return true;
  1535. },
  1536. callback: function (key, opt) {
  1537. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1538. $('#shoufang-lid').val(node.id);
  1539. $('#shoufang-pid').val('');
  1540. $('#shoufang-ledger').text('清单:' + node.b_code);
  1541. $('#shoufang-pos').text('').hide();
  1542. $('#addshoufang').modal('show');
  1543. }
  1544. }
  1545. }
  1546. });
  1547. const stagePosSpreadObj = {
  1548. loadExprToInput(sheet) {
  1549. const sel = sheet.getSelections()[0];
  1550. if (!sel) return;
  1551. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1552. if (col && col.type === 'Number') {
  1553. const data = SpreadJsObj.getSelectObject(sheet);
  1554. if (data) {
  1555. const exprInfo = getExprInfo(col.field);
  1556. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1557. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1558. .attr('readOnly', readOnly || cell.locked());
  1559. $('#pos-expr').attr('data-row', sel.row);
  1560. } else {
  1561. $('#pos-expr').val('').attr('readOnly', true);
  1562. $('#pos-expr').removeAttr('data-row');
  1563. }
  1564. } else {
  1565. $('#pos-expr').val('').attr('readOnly', true);
  1566. $('#pos-expr').removeAttr('data-row');
  1567. }
  1568. },
  1569. /**
  1570. * 加载计量单元 根据当前台账选择节点
  1571. */
  1572. loadCurPosData: function () {
  1573. const sheet = slSpread.getActiveSheet();
  1574. const node = SpreadJsObj.getSelectObject(sheet);
  1575. if (node) {
  1576. spSpread.getActiveSheet().zh_setting.readOnly = node.lock;
  1577. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1578. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1579. getNodeList(node.id);
  1580. // 如果是附件是当前节点,隐藏
  1581. // if ($('#dqjiedian').hasClass('active')) {
  1582. // $('#showAttachment').hide();
  1583. // }
  1584. } else {
  1585. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1586. }
  1587. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1588. },
  1589. editEnded: function (e, info) {
  1590. if (info.sheet.zh_setting) {
  1591. // 未改变过,则直接跳过
  1592. const sortData = info.sheet.zh_data;
  1593. const posData = sortData ? sortData[info.row] : null;
  1594. const col = info.sheet.zh_setting.cols[info.col];
  1595. const orgText = posData ? posData[col.field] : null;
  1596. const newText = trimInvalidChar(info.editingText);
  1597. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1598. return;
  1599. }
  1600. // 台账模式下,不可新增
  1601. if (checkTzMeasureType() && !posData) {
  1602. toastr.error('台账模式不可新增计量单元数据');
  1603. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1604. return ;
  1605. }
  1606. // 不同节点下,计量单元检查输入
  1607. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1608. const node = stagePosSpreadObj.stageTreeNode;
  1609. if (!node) {
  1610. toastr.warning('数据错误, 请刷新页面后再试');
  1611. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1612. return;
  1613. } else if (newText !== '' && node.children && node.children > 0) {
  1614. toastr.error('父节点不可插入计量单元');
  1615. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1616. return;
  1617. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1618. toastr.error('项目节不可插入计量单元');
  1619. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1620. return;
  1621. }
  1622. // 生成提交数据
  1623. const data = {};
  1624. if (col.field === 'name') {
  1625. if ((!newText || newText === '') && posData) {
  1626. toastr.error('部位名称不可为空');
  1627. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1628. return;
  1629. } else if (!posData) {
  1630. if (newText !== '') {
  1631. data.updateType = 'add';
  1632. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1633. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1634. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1635. return;
  1636. }
  1637. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1638. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1639. } else {
  1640. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1641. return;
  1642. }
  1643. } else {
  1644. data.updateType = 'update';
  1645. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1646. }
  1647. } else if (!posData) {
  1648. toastr.warning('新增计量单元请先输入名称');
  1649. } else if (['ex_memo1', 'ex_memo2', 'ex_memo3'].indexOf(col.field) >= 0) {
  1650. data.updateType = 'update';
  1651. data.updateData = {pid: posData.id, lid: posData.lid};
  1652. data.updateData[col.field] = newText;
  1653. } else {
  1654. data.updateType = 'update';
  1655. data.updateData = {pid: posData.id, lid: posData.lid};
  1656. if (col.type === 'Number') {
  1657. const exprInfo = getExprInfo(col.field);
  1658. const num = _.toNumber(newText);
  1659. if (_.isFinite(num)) {
  1660. data.updateData[col.field] = num;
  1661. if (exprInfo) {
  1662. data.updateData[exprInfo.expr] = '';
  1663. }
  1664. } else {
  1665. try {
  1666. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1667. if (exprInfo) {
  1668. data.updateData[exprInfo.expr] = newText;
  1669. }
  1670. } catch(err) {
  1671. toastr.error('输入的表达式非法');
  1672. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1673. return;
  1674. }
  1675. }
  1676. } else {
  1677. data.updateData[col.field] = newText;
  1678. }
  1679. }
  1680. // 提交数据到服务器
  1681. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1682. if (result.pos) {
  1683. stagePos.updateDatas(result.pos.pos);
  1684. stagePos.loadCurStageData(result.pos.curStageData);
  1685. }
  1686. const refreshData = stageTree.loadPostStageData(result.ledger);
  1687. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1688. stagePosSpreadObj.loadCurPosData();
  1689. if (detail) {
  1690. detail.loadStagePosUpdateData(result, refreshData);
  1691. } else {
  1692. stageIm.loadUpdatePosData(result, refreshData);
  1693. }
  1694. }, function () {
  1695. stagePosSpreadObj.loadCurPosData();
  1696. });
  1697. }
  1698. },
  1699. editStarting: function (e, info) {
  1700. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1701. const sel = info.sheet.getSelections();
  1702. if (!sel || !sel[0]) return;
  1703. const col = info.sheet.zh_setting.cols[sel[0].col];
  1704. const node = SpreadJsObj.getSelectObject(info.sheet);
  1705. const exprInfo = getExprInfo(col.field);
  1706. if (exprInfo) {
  1707. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1708. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1709. }
  1710. }
  1711. },
  1712. clipboardPasting: function (e, info) {
  1713. if (info.sheet.zh_setting) {
  1714. const sortData = info.sheet.zh_data;
  1715. const range = info.cellRange;
  1716. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty', 'ex_memo1', 'ex_memo2', 'ex_memo3'];
  1717. if (!checkTzMeasureType()) {
  1718. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1719. }
  1720. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1721. const col = info.sheet.zh_setting.cols[iCol];
  1722. if (validField.indexOf(col.field) === -1) {
  1723. if (checkTzMeasureType()) {
  1724. toastr.error('不可修改此数据');
  1725. info.cancel = true;
  1726. return;
  1727. } else {
  1728. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1729. const pos = sortData(iRow);
  1730. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1731. toastr.error('不可修改此数据');
  1732. info.cancel = true;
  1733. return;
  1734. }
  1735. }
  1736. }
  1737. }
  1738. }
  1739. }
  1740. },
  1741. clipboardPasted: function (e, info) {
  1742. if (info.sheet.zh_setting) {
  1743. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1744. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1745. }
  1746. const data = { updateType: '', updateData: [], };
  1747. const sortData = info.sheet.zh_data;
  1748. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1749. if (sortData && (info.cellRange.row >= sortData.length)) {
  1750. data.updateType = 'add';
  1751. if (info.cellRange.col !== 0) {
  1752. toastr.warning('新增计量单元请先输入名称');
  1753. stagePosSpreadObj.loadCurPosData();
  1754. return;
  1755. }
  1756. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1757. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1758. stagePosSpreadObj.loadCurPosData();
  1759. return;
  1760. }
  1761. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1762. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1763. const curRow = info.cellRange.row + iRow;
  1764. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1765. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1766. const curCol = info.cellRange.col + iCol;
  1767. const colSetting = info.sheet.zh_setting.cols[curCol];
  1768. if (!colSetting) continue;
  1769. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1770. if (colSetting.type === 'Number') {
  1771. const exprInfo = getExprInfo(colSetting.field);
  1772. if (newValue) {
  1773. const num = _.toNumber(newValue);
  1774. if (num) {
  1775. newData[colSetting.field] = num;
  1776. if (exprInfo) {
  1777. newData[exprInfo.expr] = '';
  1778. }
  1779. } else {
  1780. try {
  1781. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1782. if (exprInfo) {
  1783. newData[exprInfo.expr] = newValue;
  1784. }
  1785. } catch(err) {
  1786. toastr.error('输入的表达式非法');
  1787. stagePosSpreadObj.loadCurPosData();
  1788. return;
  1789. }
  1790. }
  1791. } else {
  1792. newData[colSetting.field] = null;
  1793. if (exprInfo) newData[exprInfo.expr] = '';
  1794. }
  1795. } else {
  1796. newData[colSetting.field] = newValue;
  1797. }
  1798. }
  1799. data.updateData.push(newData);
  1800. }
  1801. } else {
  1802. data.updateType = 'update';
  1803. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1804. const curRow = info.cellRange.row + iRow;
  1805. const curPos = sortData[curRow];
  1806. if (curPos) {
  1807. const newData = {pid: curPos.id, lid: curPos.lid};
  1808. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1809. const curCol = info.cellRange.col + iCol;
  1810. const colSetting = info.sheet.zh_setting.cols[curCol];
  1811. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1812. if (colSetting.type === 'Number') {
  1813. const exprInfo = getExprInfo(colSetting.field);
  1814. if (!newValue) {
  1815. newData[colSetting.field] = newValue;
  1816. if (exprInfo) newData[exprInfo.expr] = '';
  1817. continue;
  1818. }
  1819. const num = _.toNumber(newValue);
  1820. if (num) {
  1821. newData[colSetting.field] = num;
  1822. if (exprInfo) newData[exprInfo.expr] = '';
  1823. } else {
  1824. try {
  1825. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1826. const exprInfo = getExprInfo(colSetting.field);
  1827. if (exprInfo) newData[exprInfo.expr] = newValue;
  1828. } catch(err) {
  1829. toastr.error('输入的表达式非法');
  1830. stagePosSpreadObj.loadCurPosData();
  1831. return;
  1832. }
  1833. }
  1834. } else {
  1835. newData[colSetting.field] = newValue;
  1836. }
  1837. }
  1838. data.updateData.push(newData);
  1839. }
  1840. }
  1841. }
  1842. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1843. if (result.pos) {
  1844. stagePos.updateDatas(result.pos.pos);
  1845. stagePos.loadCurStageData(result.pos.curStageData);
  1846. }
  1847. const nodes = stageTree.loadPostStageData(result.ledger);
  1848. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1849. stagePosSpreadObj.loadCurPosData();
  1850. if (detail) {
  1851. detail.loadStagePosUpdateData(result, nodes);
  1852. } else {
  1853. stageIm.loadUpdatePosData(result, nodes);
  1854. }
  1855. }, function () {
  1856. stagePosSpreadObj.loadCurPosData();
  1857. });
  1858. }
  1859. },
  1860. deletePress: function (sheet) {
  1861. if (sheet.zh_setting.readOnly) return;
  1862. if (sheet.zh_setting && sheet.zh_data) {
  1863. const sortData = sheet.zh_data;
  1864. if (!sortData || sortData.length === 0) { return; }
  1865. const sel = sheet.getSelections()[0];
  1866. const validCols = [];
  1867. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1868. const colSetting = sheet.zh_setting.cols[iCol];
  1869. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1870. validCols.push(iCol);
  1871. }
  1872. }
  1873. if (validCols.length === 0) { return; }
  1874. const datas = [], posSelects = [];
  1875. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1876. const node = sortData[iRow];
  1877. if (node) {
  1878. const data = {pid: node.id, lid: node.lid};
  1879. for (const iCol of validCols) {
  1880. const colSetting = sheet.zh_setting.cols[iCol];
  1881. if (colSetting.field === 'name') {
  1882. toastr.error('部位名称不能为空');
  1883. return;
  1884. }
  1885. data[colSetting.field] = null;
  1886. const exprInfo = getExprInfo(colSetting.field);
  1887. if (exprInfo) {
  1888. data[exprInfo.expr] = '';
  1889. }
  1890. }
  1891. datas.push(data);
  1892. posSelects.push(node);
  1893. }
  1894. }
  1895. if (datas.length > 0) {
  1896. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1897. if (result.pos) {
  1898. stagePos.updateDatas(result.pos.pos);
  1899. stagePos.loadCurStageData(result.pos.curStageData);
  1900. }
  1901. const nodes = stageTree.loadPostStageData(result.ledger);
  1902. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1903. if (detail) {
  1904. detail.loadStagePosUpdateData(result, nodes);
  1905. } else {
  1906. stageIm.loadUpdatePosData(result, nodes);
  1907. }
  1908. // todo 只加载改变项
  1909. stagePosSpreadObj.loadCurPosData();
  1910. });
  1911. }
  1912. }
  1913. },
  1914. deletePos: function (sheet) {
  1915. const sels = sheet.getSelections();
  1916. const sel = sels ? sels[0] : null;
  1917. if (sheet.zh_data && sel) {
  1918. const data = {updateType: 'delete', updateData: []};
  1919. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1920. const posData = sheet.zh_data[sel.row + iRow];
  1921. if (posData) {
  1922. data.updateData.push(posData.id);
  1923. }
  1924. }
  1925. if (data.updateData.length > 0) {
  1926. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1927. stagePos.removeDatas(result.pos.pos);
  1928. const refreshData = stageTree.loadPostStageData(result.ledger);
  1929. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1930. stagePosSpreadObj.loadCurPosData();
  1931. if (detail) {
  1932. detail.loadStagePosUpdateData(result, refreshData);
  1933. } else {
  1934. stageIm.loadUpdatePosData(result, refreshData);
  1935. }
  1936. });
  1937. }
  1938. }
  1939. },
  1940. selectionChanged: function (e, info) {
  1941. stagePosSpreadObj.loadExprToInput(info.sheet);
  1942. },
  1943. addPegs: function (pegs) {
  1944. if (!pegs || pegs.length <= 0) return;
  1945. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1946. if (!node) return;
  1947. const sheet = spSpread.getActiveSheet();
  1948. const sortData = sheet.zh_data || [];
  1949. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1950. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1951. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1952. if (result.pos) {
  1953. stagePos.updateDatas(result.pos.pos);
  1954. }
  1955. stagePosSpreadObj.loadCurPosData();
  1956. });
  1957. }
  1958. };
  1959. // 加载上下窗口resizer
  1960. $.divResizer({
  1961. select: '#main-resize',
  1962. callback: function () {
  1963. slSpread.refresh();
  1964. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1965. $(".sp-wrap").height(bcontent-30);
  1966. spSpread.refresh();
  1967. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1968. }
  1969. });
  1970. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1971. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;cooperation' }, function (result) {
  1972. // 加载树结构
  1973. stageTree.loadDatas(result.ledgerData);
  1974. // stageTree.loadCurStageData(curStageData);
  1975. // stageTree.loadPreStageData(preStageData);
  1976. checkShowLast(result.ledgerData.length);
  1977. treeCalc.calculateAll(stageTree);
  1978. // 加载解锁相关
  1979. if (result.cooperation) {
  1980. stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2], result.cooperationConfirm);
  1981. $('#cooperationCount').html(stageTree.pwd.length || '');
  1982. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  1983. setCooperationSelectHtml();
  1984. reloadCooperationHtml();
  1985. }
  1986. for (const t of result.tags) {
  1987. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  1988. }
  1989. billsTag.loadDatas(result.tags);
  1990. // 加载部位明细
  1991. stagePos.loadDatas(result.posData);
  1992. stagePos.calculateAll();
  1993. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1994. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1995. stagePosSpreadObj.loadCurPosData();
  1996. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1997. // 加载中间计量
  1998. stageIm.init(stage, imType, tenderInfo.decimal);
  1999. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  2000. errorList.loadHisErrorData();
  2001. checkList.loadHisCheckData();
  2002. sumLoadMiss.loadHisMissData();
  2003. // 收方单赋值
  2004. ledgerData = result.ledgerData;
  2005. posData = result.posData;
  2006. makeShouFang();
  2007. }, null, true);
  2008. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  2009. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  2010. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  2011. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  2012. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  2013. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  2014. if (!readOnly) {
  2015. $('#pos-expr').bind('change onblur', function () {
  2016. if (this.readOnly) return;
  2017. const expr = $(this);
  2018. const posSheet = spSpread.getActiveSheet();
  2019. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  2020. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  2021. if (!select) return;
  2022. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  2023. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  2024. const data = {pid: select.id, lid: select.lid};
  2025. const exprInfo = getExprInfo(field);
  2026. if (newValue !== '') {
  2027. const num = _.toNumber(newValue);
  2028. if (num) {
  2029. data[field] = num;
  2030. if (exprInfo) data[exprInfo.expr] = '';
  2031. } else {
  2032. try {
  2033. data[field] = math.evaluate(transExpr(newValue));
  2034. if (exprInfo) data[exprInfo.expr] = newValue;
  2035. } catch (err) {
  2036. toastr.error('输入的表达式非法');
  2037. return;
  2038. }
  2039. }
  2040. } else {
  2041. data[field] = null;
  2042. if (exprInfo) data[exprInfo.expr] = '';
  2043. }
  2044. // 提交数据到服务器
  2045. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  2046. if (result.pos) {
  2047. stagePos.updateDatas(result.pos.pos);
  2048. stagePos.loadCurStageData(result.pos.curStageData);
  2049. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  2050. }
  2051. const refreshData = stageTree.loadPostStageData(result.ledger);
  2052. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  2053. if (detail) {
  2054. detail.loadStagePosUpdateData(result, refreshData);
  2055. } else {
  2056. stageIm.loadUpdatePosData(result, refreshData);
  2057. }
  2058. });
  2059. });
  2060. }
  2061. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  2062. $.contextMenu({
  2063. selector: '#stage-pos',
  2064. build: function ($trigger, e) {
  2065. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  2066. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  2067. },
  2068. items: {
  2069. 'del': {
  2070. name: '删除',
  2071. icon: 'fa-remove',
  2072. visible: function (key, opt) {
  2073. return !checkTzMeasureType();
  2074. },
  2075. disabled: function (key, opt) {
  2076. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2077. if (!node || node.lock) return true;
  2078. const sheet = spSpread.getActiveSheet();
  2079. if (sheet.zh_data && !readOnly) {
  2080. const selection = sheet.getSelections();
  2081. if (selection && selection[0]) {
  2082. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2083. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2084. const posData = sheet.zh_data[selection[0].row + iRow];
  2085. if (posData) {
  2086. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2087. valid = true;
  2088. break;
  2089. }
  2090. } else {
  2091. valid = true;
  2092. break;
  2093. }
  2094. }
  2095. return valid;
  2096. } else {
  2097. return true;
  2098. }
  2099. } else {
  2100. return true;
  2101. }
  2102. },
  2103. callback: function (key, opt) {
  2104. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2105. }
  2106. },
  2107. 'merge-peg': {
  2108. name: '合并起讫桩号',
  2109. visible: function (key, opt) {
  2110. return !checkTzMeasureType();
  2111. },
  2112. disabled: function (key, opt) {
  2113. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2114. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2115. },
  2116. callback: function (key, opt) {
  2117. mergePeg.show();
  2118. }
  2119. },
  2120. 'calcByRatio': {
  2121. name: '按比例计量',
  2122. visible: function (key, opt) {
  2123. const data = spSpread.getActiveSheet().zh_data;
  2124. return data && data.length > 0;
  2125. },
  2126. disabled: function (key, opt) {
  2127. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2128. return node.lock;
  2129. },
  2130. callback: function (key, opt) {
  2131. $('#cbr-ratio').val('');
  2132. $('#apply2sibling')[0].checked = false;
  2133. $('#cbr-check-all')[0].checked = false;
  2134. const html = [];
  2135. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2136. html.push('<tr>');
  2137. html.push('<td>', i+1, '</td>');
  2138. html.push('<td>', p.name, '</td>');
  2139. html.push('<td>', p.quantity, '</td>');
  2140. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2141. html.push('</tr>');
  2142. }
  2143. $('#cbr-pos-list').html(html.join(''));
  2144. $('#calc-by-ratio').modal('show');
  2145. }
  2146. },
  2147. 'shoufangdan': {
  2148. name: '生成收方单',
  2149. visible: function(key, opt) {
  2150. if (cur_uid === stage.user_id) return true;
  2151. },
  2152. disabled: function (key, opt) {
  2153. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2154. if (!node || cur_uid !== stage.user_id) return true;
  2155. },
  2156. callback: function (key, opt) {
  2157. const node = SpreadJsObj.getSelectObject(spSpread.getActiveSheet());
  2158. const ledgerNode = _.find(ledgerData, { id: node.lid });
  2159. $('#shoufang-lid').val(node.lid);
  2160. $('#shoufang-pid').val(node.id);
  2161. $('#shoufang-ledger').text('清单:' + ledgerNode.b_code);
  2162. $('#shoufang-pos').text('计量单元:' + node.name).show();
  2163. $('#addshoufang').modal('show');
  2164. }
  2165. }
  2166. }
  2167. });
  2168. $.subMenu({
  2169. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2170. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2171. key: 'menu.1.0.0',
  2172. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2173. callback: function (info) {
  2174. if (info.mini) {
  2175. $('.panel-title').addClass('fluid');
  2176. $('#sub-menu').removeClass('panel-sidebar');
  2177. } else {
  2178. $('.panel-title').removeClass('fluid');
  2179. $('#sub-menu').addClass('panel-sidebar');
  2180. }
  2181. autoFlashHeight();
  2182. slSpread.refresh();
  2183. spSpread.refresh();
  2184. if (searchLedger) searchLedger.spread.refresh();
  2185. if (detail) detail.spread.refresh();
  2186. if (checkedChanges) checkedChanges.refresh();
  2187. if (errorList && errorList.spread) errorList.spread.refresh();
  2188. if (checkList) checkList.spread.refresh();
  2189. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2190. }
  2191. });
  2192. $('#row-view').on('show.bs.modal', function () {
  2193. const html = [], customDisplay = customColDisplay();
  2194. for (const cd of customDisplay) {
  2195. html.push('<tr>');
  2196. html.push('<td>', cd.title, '</td>');
  2197. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2198. html.push('</tr>');
  2199. }
  2200. $('#row-view-list').html(html.join(''));
  2201. });
  2202. $('#row-view-ok').click(function () {
  2203. const customDisplay = customColDisplay();
  2204. const cvl = $('#row-view-list').children();
  2205. for (const cv of cvl) {
  2206. const title = $(cv).children()[0].innerHTML;
  2207. const check = $('input', cv)[0].checked;
  2208. const cd = customDisplay.find(function (c) {
  2209. return c.title === title;
  2210. });
  2211. cd.visible = check;
  2212. }
  2213. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2214. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2215. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2216. $('#row-view').modal('hide');
  2217. });
  2218. const posSearch = (function () {
  2219. let resultArr = [];
  2220. const search = function () {
  2221. resultArr = [];
  2222. const keyword = $('#pos-search-keyword').val();
  2223. const checkOver = $('#pos-over-search')[0].checked;
  2224. const checkEmpty = $('#pos-empty-search')[0].checked;
  2225. const sortData = spSpread.getActiveSheet().zh_data;
  2226. if (checkOver || checkEmpty) {
  2227. if (sortData) {
  2228. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2229. const sd = sortData[i];
  2230. let match = false;
  2231. if (checkOver) {
  2232. if (sd.end_gather_qty) {
  2233. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2234. }
  2235. }
  2236. if (checkEmpty) {
  2237. if (sd.quantity) {
  2238. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2239. }
  2240. }
  2241. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2242. if (match) {
  2243. resultArr.push({index: i, data: sd});
  2244. }
  2245. }
  2246. }
  2247. } else if (keyword && keyword !== '') {
  2248. if (sortData) {
  2249. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2250. const sd = sortData[i];
  2251. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2252. resultArr.push({index: i, data: sd});
  2253. }
  2254. }
  2255. }
  2256. }
  2257. $('#pos-search-result').html('结果:' + resultArr.length);
  2258. };
  2259. const searchAndLocate = function () {
  2260. search();
  2261. if (resultArr.length > 0) {
  2262. const sheet = spSpread.getActiveSheet();
  2263. const sel = sheet.getSelections()[0];
  2264. const curRow = sel ? sel.row : 0;
  2265. const pos = resultArr[0];
  2266. if (pos.index !== curRow) {
  2267. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2268. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2269. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2270. }
  2271. }
  2272. };
  2273. const locateNext = function () {
  2274. if (resultArr.length > 0) {
  2275. const sheet = spSpread.getActiveSheet();
  2276. const sel = sheet.getSelections()[0];
  2277. const curRow = sel ? sel.row : 0;
  2278. let next = _.find(resultArr, function (d) {
  2279. return d.index > curRow;
  2280. });
  2281. if (!next) next = resultArr[0];
  2282. if (next.index !== curRow) {
  2283. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2284. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2285. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2286. }
  2287. }
  2288. };
  2289. const locatePre = function () {
  2290. if (resultArr.length > 0) {
  2291. const sheet = spSpread.getActiveSheet();
  2292. const sel = sheet.getSelections()[0];
  2293. const curRow = sel ? sel.row : 0;
  2294. let next = _.findLast(resultArr, function (d) {
  2295. return d.index < curRow;
  2296. });
  2297. if (!next) next = resultArr[resultArr.length - 1];
  2298. if (next.index !== curRow) {
  2299. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2300. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2301. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2302. }
  2303. }
  2304. };
  2305. return {search, searchAndLocate, locateNext, locatePre};
  2306. })();
  2307. $('#pos-search-keyword').bind('keydown', function(e){
  2308. if (e.keyCode == 13) posSearch.searchAndLocate();
  2309. });
  2310. $('#pos-empty-search').click(function () {
  2311. if (this.checked) {
  2312. $('[for=' + this.id +']').addClass('text-warning');
  2313. } else {
  2314. $('[for=' + this.id +']').removeClass('text-warning');
  2315. }
  2316. if (this.checked) {
  2317. if ($('#pos-over-search')[0].checked) {
  2318. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2319. } else {
  2320. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2321. }
  2322. } else {
  2323. if ($('#pos-over-search')[0].checked) {
  2324. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2325. } else {
  2326. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2327. }
  2328. }
  2329. posSearch.searchAndLocate();
  2330. });
  2331. $('#pos-over-search').click(function () {
  2332. if (this.checked) {
  2333. $('[for=' + this.id +']').addClass('text-danger');
  2334. } else {
  2335. $('[for=' + this.id +']').removeClass('text-danger');
  2336. }
  2337. if (this.checked) {
  2338. if ($('#pos-empty-search')[0].checked) {
  2339. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2340. } else {
  2341. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2342. }
  2343. } else {
  2344. if ($('#pos-empty-search')[0].checked) {
  2345. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2346. } else {
  2347. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2348. }
  2349. }
  2350. posSearch.searchAndLocate();
  2351. });
  2352. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2353. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2354. $.divResizer({
  2355. select: '#right-spr',
  2356. callback: function () {
  2357. slSpread.refresh();
  2358. spSpread.refresh();
  2359. if (searchLedger) {
  2360. searchLedger.spread.refresh();
  2361. }
  2362. if (detail) {
  2363. detail.spread.refresh();
  2364. }
  2365. if (checkedChanges) checkedChanges.refresh();
  2366. if (errorList && errorList.spread) errorList.spread.refresh();
  2367. if (checkList) checkList.spread.refresh();
  2368. if (sumLoadMiss) sumLoadMiss.spread.refresh();
  2369. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2370. }
  2371. });
  2372. // 中间计量加载上下窗口resizer
  2373. $.divResizer({
  2374. select: '#zhongjian-spr',
  2375. callback: function () {
  2376. if (detail) {
  2377. detail.spread.refresh();
  2378. }
  2379. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2380. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2381. }
  2382. });
  2383. // 附件加载上下窗口resizer
  2384. $.divResizer({
  2385. select: '#file-spr',
  2386. callback: function () {
  2387. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2388. }
  2389. });
  2390. // 变更令加载上下窗口resizer
  2391. $.divResizer({
  2392. select: '#change-spr',
  2393. callback: function () {
  2394. if (checkedChanges) checkedChanges.refresh();
  2395. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2396. }
  2397. });
  2398. class Detail {
  2399. constructor (obj) {
  2400. const self = this;
  2401. this.spreadSetting = {
  2402. cols: [
  2403. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2404. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2405. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2406. {
  2407. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2408. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2409. },
  2410. ],
  2411. headRows: 1,
  2412. emptyRows: 0,
  2413. headRowHeight: [32],
  2414. headColWidth: [30],
  2415. defaultRowHeight: 21,
  2416. headerFont: '12px 微软雅黑',
  2417. font: '12px 微软雅黑',
  2418. readOnly: readOnly,
  2419. selectedBackColor: '#fffacd',
  2420. };
  2421. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2422. this.sheet = this.spread.getActiveSheet();
  2423. this.spread.options.allowUserDragFill = true;
  2424. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2425. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2426. this.detailObj = {
  2427. selectionChanged: function (e, info) {
  2428. self.reLoadDetailData();
  2429. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2430. self.loadLocateInfo();
  2431. }
  2432. },
  2433. editEnded: function(e, info) {
  2434. if (info.sheet.zh_setting) {
  2435. const col = info.sheet.zh_setting.cols[info.col];
  2436. if (col.field !== 'doc_code') {
  2437. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2438. return;
  2439. }
  2440. const data = SpreadJsObj.getSelectObject(info.sheet);
  2441. if (data) {
  2442. const updateData = {lid: data.lid, pid: data.pid};
  2443. if (data.uuid) {
  2444. updateData.uuid = data.uuid;
  2445. } else {
  2446. updateData.code = data.code;
  2447. updateData.name = data.name;
  2448. updateData.unit = data.unit;
  2449. updateData.unit_price = data.unit_price;
  2450. updateData.pid = data.pid;
  2451. updateData.pos_name = data.pos_name;
  2452. updateData.im_type = data.im_type;
  2453. }
  2454. if (data.custom_define.indexOf('doc_code') === -1) {
  2455. updateData.custom_define = data.custom_define;
  2456. updateData.custom_define.push('doc_code');
  2457. updateData.custom_define = updateData.custom_define.join(',');
  2458. }
  2459. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2460. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2461. stageIm.loadUpdateDetailData(result);
  2462. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2463. }, function () {
  2464. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2465. });
  2466. } else {
  2467. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2468. }
  2469. }
  2470. },
  2471. clipboardPasted: function (e, info) {
  2472. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2473. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2474. if (info.cellRange.colCount > 1) {
  2475. toastr.warning('请勿同时复制粘贴多列数据');
  2476. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2477. return;
  2478. }
  2479. if (col.field !== 'doc_code') {
  2480. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2481. return;
  2482. }
  2483. const datas = [];
  2484. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2485. const curRow = info.cellRange.row + iRow;
  2486. const data = info.sheet.zh_data[curRow];
  2487. if (data) {
  2488. const updateData = {lid: data.lid, pid: data.pid};
  2489. if (data.uuid) {
  2490. updateData.uuid = data.uuid;
  2491. } else {
  2492. updateData.code = data.code;
  2493. updateData.name = data.name;
  2494. updateData.unit = data.unit;
  2495. updateData.unit_price = data.unit_price;
  2496. updateData.pid = data.pid;
  2497. updateData.pos_name = data.pos_name;
  2498. updateData.im_type = data.im_type;
  2499. }
  2500. if (data.custom_define.indexOf('doc_code') === -1) {
  2501. updateData.custom_define = data.custom_define;
  2502. updateData.custom_define.push('doc_code');
  2503. updateData.custom_define = updateData.custom_define.join(',');
  2504. }
  2505. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2506. datas.push(updateData);
  2507. }
  2508. }
  2509. if (datas.length > 0) {
  2510. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2511. stageIm.loadUpdateDetailData(result);
  2512. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2513. }, function () {
  2514. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2515. })
  2516. }
  2517. }
  2518. },
  2519. deletePress: function (sheet) {
  2520. if (sheet.zh_setting) {
  2521. const datas = [];
  2522. const sel = sheet.getSelections()[0];
  2523. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2524. const col = sheet.zh_setting.cols[iCol];
  2525. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2526. const data = sheet.zh_data[iRow];
  2527. if (col.field === 'doc_code') {
  2528. const updateData = {lid: data.lid};
  2529. if (data.uuid) {
  2530. updateData.uuid = data.uuid;
  2531. updateData.doc_code = '';
  2532. datas.push(updateData);
  2533. }
  2534. }
  2535. }
  2536. }
  2537. if (datas.length > 0) {
  2538. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2539. stageIm.loadUpdateDetailData(result);
  2540. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2541. }, function () {
  2542. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2543. });
  2544. }
  2545. }
  2546. },
  2547. dragFillBlock: function (e, info) {
  2548. info.cancel = true;
  2549. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2550. const sel = info.sheet.getSelections()[0];
  2551. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2552. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2553. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2554. if (text === '') return;
  2555. const regRst = /(\d+)$/g.exec(text), datas = [];
  2556. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2557. const curRow = info.fillRange.row + iRow;
  2558. const data = info.sheet.zh_data[curRow];
  2559. if (data) {
  2560. const updateData = {lid: data.lid};
  2561. if (data.uuid) {
  2562. updateData.uuid = data.uuid;
  2563. } else {
  2564. updateData.code = data.code;
  2565. updateData.name = data.name;
  2566. updateData.unit = data.unit;
  2567. updateData.unit_price = data.unit_price;
  2568. updateData.pid = data.pid;
  2569. updateData.pos_name = data.pos_name;
  2570. updateData.im_type = data.im_type;
  2571. }
  2572. if (regRst) {
  2573. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2574. } else {
  2575. updateData.doc_code = text.replace('\n', '');
  2576. }
  2577. if (data.custom_define.indexOf('doc_code') === -1) {
  2578. updateData.custom_define = data.custom_define;
  2579. updateData.custom_define.push('doc_code');
  2580. updateData.custom_define = updateData.custom_define.join(',');
  2581. }
  2582. datas.push(updateData);
  2583. }
  2584. }
  2585. if (datas.length > 0) {
  2586. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2587. stageIm.loadUpdateDetailData(result);
  2588. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2589. }, function () {
  2590. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2591. })
  2592. }
  2593. },
  2594. };
  2595. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2596. if (!readOnly) {
  2597. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2598. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2599. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2600. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2601. }
  2602. this._initImTypeSetRela();
  2603. this._initModifyDetail();
  2604. this._initLocateRela();
  2605. // 草图相关
  2606. this._initImageRela();
  2607. this.reBuildImData();
  2608. }
  2609. _initImTypeSetRela() {
  2610. const self = this;
  2611. const gatherConfirmPopover = {
  2612. reBind: function (obj, eventName, fun) {
  2613. obj.unbind(eventName);
  2614. obj.bind(eventName, fun);
  2615. },
  2616. check: function (pos, hint, okCallback) {
  2617. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2618. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2619. this.reBind(cancelObj, 'click', function () {
  2620. confirmObj.hide();
  2621. });
  2622. this.reBind(okObj, 'click', function () {
  2623. okCallback();
  2624. confirmObj.hide();
  2625. });
  2626. hintObj.text(hint);
  2627. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2628. }
  2629. };
  2630. this.gsTree = stageIm.getGsTree();
  2631. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  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. } else {
  2638. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2639. jlCol.title = '本期计量数量';
  2640. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2641. $('#type-title-contract').text('本期合同计量数量');
  2642. $('#type-title-qc').text('本期变更计量数量');
  2643. }
  2644. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2645. $('#show-jldy').parent().show();
  2646. $('#jldy').parent().show();
  2647. $('#show-xm-name').parent().hide();
  2648. $('#xm-name').parent().hide();
  2649. } else {
  2650. $('#show-jldy').parent().hide();
  2651. $('#jldy').parent().hide();
  2652. $('#show-xm-name').parent().show();
  2653. $('#xm-name').parent().show();
  2654. }
  2655. // 选择中间计量模式
  2656. $('div[name="im-type"]').click(function () {
  2657. function chooseType(obj) {
  2658. obj.style.cursor = 'default';
  2659. $(obj).children().addClass('text-primary');
  2660. $(obj).addClass('border-primary');
  2661. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2662. }
  2663. function validType(obj) {
  2664. obj.style.cursor = 'pointer';
  2665. $(obj).children().removeClass('text-primary');
  2666. $(obj).removeClass('border-primary');
  2667. $('i', obj).remove();
  2668. }
  2669. if (this.style.cursor === 'pointer') {
  2670. const typeArr = $('div[name="im-type"]');
  2671. for (const t of typeArr) {
  2672. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2673. chooseType(t);
  2674. } else {
  2675. validType(t)
  2676. }
  2677. }
  2678. }
  2679. });
  2680. $('#choose').on('show.bs.modal', function () {
  2681. function chooseType(obj) {
  2682. obj.style.cursor = 'default';
  2683. $(obj).children().addClass('text-primary');
  2684. $('i', obj).remove();
  2685. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2686. }
  2687. function validType(obj) {
  2688. obj.style.cursor = 'pointer';
  2689. $(obj).children().removeClass('text-primary');
  2690. $('i', obj).remove();
  2691. }
  2692. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2693. const typeArr = $('div[name="im-type"]');
  2694. for (const t of typeArr) {
  2695. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2696. chooseType(t);
  2697. } else {
  2698. validType(t)
  2699. }
  2700. }
  2701. });
  2702. // 提交 中间计量模式
  2703. $('#choose-ok').click(() => {
  2704. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2705. return it.style.cursor !== 'pointer';
  2706. });
  2707. const data = {
  2708. im_type: parseInt($(chooseType).attr('im-type')),
  2709. im_pre: $('#im-pre').val(),
  2710. };
  2711. postData(window.location.pathname + '/detail/build', data, function (result) {
  2712. stage.im_type = data.im_type;
  2713. stage.im_pre = data.im_pre;
  2714. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  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. } else {
  2721. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2722. jlCol.title = '本期计量数量';
  2723. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2724. $('#type-title-contract').text('本期合同计量数量');
  2725. $('#type-title-qc').text('本期变更计量数量');
  2726. }
  2727. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2728. $('#show-jldy').parent().show();
  2729. $('#jldy').parent().show();
  2730. $('#show-xm-name').parent().hide();
  2731. $('#xm-name').parent().hide();
  2732. } else {
  2733. $('#show-jldy').parent().hide();
  2734. $('#jldy').parent().hide();
  2735. $('#show-xm-name').parent().show();
  2736. $('#xm-name').parent().show();
  2737. }
  2738. // 加载生成数据
  2739. self.reBuildImData();
  2740. $('#choose').modal('hide');
  2741. });
  2742. });
  2743. // 显示树结构信息
  2744. $('#choose2').on('shown.bs.modal', function () {
  2745. if (!self.gsSpread) {
  2746. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2747. const setting = {
  2748. cols: [
  2749. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2750. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2751. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2752. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2753. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2754. ],
  2755. headRows: 1,
  2756. emptyRows: 0,
  2757. headRowHeight: [32],
  2758. defaultRowHeight: 21,
  2759. headerFont: '12px 微软雅黑',
  2760. font: '12px 微软雅黑',
  2761. };
  2762. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2763. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2764. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2765. function checkParent(node) {
  2766. const parent = self.gsTree.getParent(node);
  2767. if (parent) {
  2768. return parent.check ? parent.check : checkParent(parent);
  2769. } else {
  2770. return false;
  2771. }
  2772. }
  2773. function checkChildren(node) {
  2774. for (const child of node.children) {
  2775. if (child.check) {
  2776. return true;
  2777. } else if (checkChildren(child)) {
  2778. return true;
  2779. }
  2780. }
  2781. return false;
  2782. }
  2783. if (!$('#im-gather-check')[0].checked) { return; }
  2784. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2785. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2786. if (sheet.isEditing()) {
  2787. sheet.endEdit(true);
  2788. }
  2789. }
  2790. if (info.sheet.zh_setting) {
  2791. const col = info.sheet.zh_setting.cols[info.col];
  2792. if (col.field !== 'check') {
  2793. return;
  2794. }
  2795. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2796. const node = sortData[info.row];
  2797. if (!node.check) {
  2798. if (checkParent(node)) {
  2799. const rect = info.sheet.getCellRect(info.row, info.col);
  2800. gatherConfirmPopover.check({
  2801. x: rect.x + rect.width / 2 + 25,
  2802. y: rect.y + rect.height / 2 + 3,
  2803. }, '父项已勾选,继续将取消父项勾选。', function () {
  2804. node.check = true;
  2805. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2806. const rows = [self.gsTree.nodes.indexOf(node)];
  2807. for (const p of parents) {
  2808. if (p.check) {
  2809. p.check = false;
  2810. rows.push(self.gsTree.nodes.indexOf(p));
  2811. }
  2812. }
  2813. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2814. });
  2815. } else if (checkChildren(node)) {
  2816. const rect = info.sheet.getCellRect(info.row, info.col);
  2817. gatherConfirmPopover.check({
  2818. x: rect.x + rect.width / 2 + 25,
  2819. y: rect.y + rect.height / 2 + 3,
  2820. }, '子项已勾选,继续将取消子项勾选。', function () {
  2821. node.check = true;
  2822. const posterity = self.gsTree.getPosterity(node);
  2823. const rows = [self.gsTree.nodes.indexOf(node)];
  2824. for (const p of posterity) {
  2825. if (p.check) {
  2826. rows.push(self.gsTree.nodes.indexOf(p));
  2827. p.check = false;
  2828. }
  2829. }
  2830. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2831. });
  2832. } else {
  2833. node.check = true;
  2834. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2835. }
  2836. } else {
  2837. node.check = false;
  2838. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2839. }
  2840. }
  2841. });
  2842. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2843. for (const node of self.gsTree.datas) {
  2844. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2845. }
  2846. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2847. self.gsTree.expandByLevel(4);
  2848. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2849. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2850. } else {
  2851. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2852. for (const node of self.gsTree.datas) {
  2853. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2854. }
  2855. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2856. }
  2857. });
  2858. // 提交 高级设置
  2859. $('#choose2-ok').click(() => {
  2860. if (!self.gsTree) { return; }
  2861. const nodes = [];
  2862. for (const node of self.gsTree.datas) {
  2863. if (node.check) {
  2864. nodes.push(node.id);
  2865. }
  2866. }
  2867. const data = {
  2868. im_gather: $('#im-gather-check')[0].checked,
  2869. im_gather_node: nodes.join(','),
  2870. };
  2871. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2872. stage.im_gather = data.im_gather;
  2873. stage.im_gather_node = data.im_gather_node;
  2874. $('#choose2').modal('hide');
  2875. });
  2876. });
  2877. }
  2878. _initLocateRela() {
  2879. const self = this;
  2880. $('#im-locate2bills').click(function () {
  2881. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2882. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2883. if (select && select.source) {
  2884. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2885. stagePosSpreadObj.loadCurPosData();
  2886. }
  2887. });
  2888. $('#im-locate-pre').click(function () {
  2889. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2890. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2891. if (select && select.source) {
  2892. const targetIndex = Math.max(curIndex-1, 1);
  2893. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2894. stagePosSpreadObj.loadCurPosData();
  2895. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2896. }
  2897. });
  2898. $('#im-locate-next').click(function () {
  2899. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2900. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2901. if (select && select.source) {
  2902. const targetIndex = Math.min(curIndex+1, select.source.length);
  2903. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2904. stagePosSpreadObj.loadCurPosData();
  2905. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2906. }
  2907. });
  2908. }
  2909. _initModifyDetail() {
  2910. const self = this;
  2911. // 重置
  2912. $('#reset-detail-ok').click(function () {
  2913. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2914. if (!data.uuid) return;
  2915. const updateData = {
  2916. lid: data.lid, pid: data.pid,
  2917. uuid: data.uuid,
  2918. custom_define: [],
  2919. };
  2920. for (const f of data.custom_define) {
  2921. if (stageIm.resetFields.indexOf(f) >= 0) {
  2922. updateData[f] = null;
  2923. } else {
  2924. updateData.custom_define.push(f);
  2925. }
  2926. }
  2927. updateData.custom_define = updateData.custom_define.join(',');
  2928. $('#reset-detail-modal').modal('hide');
  2929. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2930. stageIm.loadUpdateDetailData(result);
  2931. self.reLoadDetailData();
  2932. });
  2933. });
  2934. // 编辑
  2935. $('#edit-detail').click(function () {
  2936. $(this).hide();
  2937. $('#save-detail').show();
  2938. $('#cancel-detail').show();
  2939. $('#detail-show').hide();
  2940. $('#detail-edit').show();
  2941. self.updateImageData = null;
  2942. });
  2943. // 保存
  2944. $('#save-detail').click(() => {
  2945. function check(field, obj, org, update) {
  2946. const newValue = obj.val();
  2947. if (!org[field]) {
  2948. if (newValue !== '') {
  2949. update[field] = newValue;
  2950. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2951. return true;
  2952. }
  2953. } else if (newValue !== org[field]){
  2954. update[field] = newValue;
  2955. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2956. return true;
  2957. }
  2958. return false;
  2959. }
  2960. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2961. const updateData = {lid: data.lid, pid: data.pid};
  2962. if (data.uuid) {
  2963. updateData.uuid = data.uuid;
  2964. updateData.custom_define = data.custom_define;
  2965. } else {
  2966. updateData.code = data.code;
  2967. updateData.name = data.name;
  2968. updateData.unit = data.unit;
  2969. updateData.unit_price = data.unit_price;
  2970. updateData.pid = data.pid;
  2971. updateData.pos_name = data.pos_name;
  2972. updateData.im_type = data.im_type;
  2973. updateData.custom_define = [];
  2974. }
  2975. let infoUpdate = false;
  2976. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  2977. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  2978. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  2979. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  2980. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  2981. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  2982. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  2983. updateData.custom_define = updateData.custom_define.join(',');
  2984. if (infoUpdate) {
  2985. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2986. stageIm.loadUpdateDetailData(result);
  2987. self.reLoadDetailData();
  2988. if (!self.updateImageData) return;
  2989. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  2990. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2991. stageIm.loadUpdateDetailData(result);
  2992. self.reLoadDetailData();
  2993. });
  2994. });
  2995. } else if (self.updateImageData) {
  2996. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2997. stageIm.loadUpdateDetailData(result);
  2998. self.reLoadDetailData();
  2999. });
  3000. } else {
  3001. self.reLoadDetailData();
  3002. }
  3003. });
  3004. // 取消
  3005. $('#cancel-detail').click(() => {
  3006. self.reLoadDetailData();
  3007. });
  3008. }
  3009. _initImageRela() {
  3010. const self = this;
  3011. $('#edit-detail').click(function () {
  3012. loadImageItem();
  3013. });
  3014. function setdraggrable(){
  3015. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  3016. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  3017. stop: function( event, ui ) {
  3018. }
  3019. });
  3020. }
  3021. function upload(formData) {
  3022. if (formData.length < 1) {
  3023. return;
  3024. }
  3025. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  3026. const html = [];
  3027. html.push('<div class="img-item">');
  3028. html.push('<div class="img-bar">');
  3029. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3030. html.push('</div>');
  3031. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  3032. html.push('</div>');
  3033. $('.img-view').append(html.join(''));
  3034. $('.img-bar').click(removeImageItem);
  3035. setdraggrable();
  3036. $('#upload-img-file').val('');
  3037. });
  3038. }
  3039. function dragFile(e) {
  3040. var file = null,
  3041. data = e.dataTransfer.types;
  3042. for (var i = 0; i < data.length; i += 1) {
  3043. if (data[i] === 'Files') {
  3044. file = e.dataTransfer.files; //获取文件
  3045. break;
  3046. }
  3047. }
  3048. if (file && file[0].type.indexOf('image') !== -1) {
  3049. var formData = new FormData();
  3050. formData.append('file', file[0]); //上传单个文件的添加方式
  3051. upload(formData); //upload 异步上传
  3052. }
  3053. }
  3054. // 移动图片
  3055. const moveImageItem = function (ev) {
  3056. const item = this;
  3057. const view = $('.img-view')[0];
  3058. let oEvent = ev;
  3059. // 浏览器有一些图片的默认事件,这里要阻止
  3060. oEvent.preventDefault();
  3061. let disX = oEvent.clientX - item.offsetLeft;
  3062. let disY = oEvent.clientY - item.offsetTop;
  3063. view.onmousemove = function (ev) {
  3064. oEvent = ev;
  3065. oEvent.preventDefault();
  3066. let x = oEvent.clientX -disX;
  3067. let y = oEvent.clientY -disY;
  3068. // 图形移动的边界判断
  3069. x = x <= 0 ? 0 : x;
  3070. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  3071. y = y <= 0 ? 0 : y;
  3072. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  3073. item.style.left = x + 'px';
  3074. item.style.top = y + 'px';
  3075. };
  3076. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  3077. view.onmouseleave = function () {
  3078. view.onmousemove = null;
  3079. view.onmouseup = null;
  3080. };
  3081. // 鼠标弹起后停止移动
  3082. view.onmouseup=function() {
  3083. view.onmousemove = null;
  3084. view.onmouseup = null;
  3085. };
  3086. };
  3087. const removeImageItem = function () {
  3088. $(this).parent().remove();
  3089. };
  3090. // 加载草图组成
  3091. const loadImageItem = function () {
  3092. self.updateImageData = null;
  3093. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3094. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3095. const html = [];
  3096. for (const item of items) {
  3097. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3098. html.push('<div class="img-item" style="' + itemStyle + '">');
  3099. html.push('<div class="img-bar">');
  3100. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3101. html.push('</div>');
  3102. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3103. html.push('</div>');
  3104. }
  3105. $('.img-view').html(html.join(''));
  3106. $('.img-bar').click(removeImageItem);
  3107. setdraggrable();
  3108. };
  3109. // 上传图片
  3110. $('#upload-img').click(function () {
  3111. $('#upload-img-file').trigger('click');
  3112. });
  3113. // 拖拽上传
  3114. //拖拽上传文件
  3115. const dragbox = document.querySelector('#upload-img');
  3116. dragbox.addEventListener('dragover', function(e) {
  3117. e.preventDefault(); // 必须阻止默认事件
  3118. }, false);
  3119. dragbox.addEventListener('drop', function(e) {
  3120. e.preventDefault(); // 阻止默认事件
  3121. dragFile(e);
  3122. }, false);
  3123. //拖拽上传文件
  3124. const dragbox2 = document.querySelector('.img-view');
  3125. dragbox2.addEventListener('dragover', function(e) {
  3126. e.preventDefault(); // 必须阻止默认事件
  3127. }, false);
  3128. dragbox2.addEventListener('drop', function(e) {
  3129. e.preventDefault(); // 阻止默认事件
  3130. dragFile(e);
  3131. }, false);
  3132. // 粘贴上传
  3133. $(".img-view").on('paste', function(ev) {
  3134. let file = null;
  3135. const data = (event.clipboardData || window.clipboardData).items;
  3136. for (let i = 0; i < data.length; i += 1) {
  3137. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3138. file = data[i].getAsFile(); //读取图片文件
  3139. break;
  3140. }
  3141. }
  3142. if (file) {
  3143. const formData = new FormData();
  3144. formData.append('file', file); //上传单个文件的添加方式
  3145. upload(formData); //异步上传文件
  3146. }
  3147. });
  3148. $('#upload-img-file').change(function () {
  3149. const file = this.files[0];
  3150. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3151. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3152. if (!imgStr.test(ext)) {
  3153. toastr.error('请上传正确的图片格式文件');
  3154. return
  3155. }
  3156. if ($(this).val()) {
  3157. const formData = new FormData();
  3158. formData.append('file', this.files[0]);
  3159. upload(formData);
  3160. }
  3161. });
  3162. // 保存草图修改结果
  3163. $('#edit-img-ok').click(function () {
  3164. // 记录上传的图片的信息
  3165. const items = $('.img-item');
  3166. const img_remark = $('#text-edit').val();
  3167. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3168. // 生成上传数据
  3169. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid, calc_img_remark: img_remark};
  3170. if (data.uuid) {
  3171. updateData.uuid = data.uuid;
  3172. } else {
  3173. updateData.code = data.code;
  3174. updateData.name = data.name;
  3175. updateData.unit = data.unit;
  3176. updateData.unit_price = data.unit_price;
  3177. updateData.pid = data.pid;
  3178. updateData.pos_name = data.pos_name;
  3179. updateData.im_type = data.im_type;
  3180. }
  3181. if (items.length > 0) {
  3182. const itemInfo = [];
  3183. for (const item of items) {
  3184. const itemData = {
  3185. src: $('img', item).attr('src'),
  3186. left: item.style.left,
  3187. top: item.style.top,
  3188. width: item.style.width,
  3189. height: item.style.height,
  3190. };
  3191. itemInfo.push(itemData);
  3192. }
  3193. // 获取合并好的图片数据
  3194. const canvas = document.createElement('canvas');
  3195. const view = $('.img-view')[0];
  3196. canvas.height = view.clientHeight;
  3197. canvas.width = view.clientWidth;
  3198. const ctx = canvas.getContext('2d');
  3199. ctx.fillStyle = '#ffffff';
  3200. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3201. for (const b of $('.img-item')) {
  3202. const pos = $(b).position();
  3203. const img = $('img', b)[0];
  3204. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3205. }
  3206. updateData.img = canvas.toDataURL('image/png');
  3207. updateData.imgInfo = itemInfo;
  3208. self.updateImageData = updateData;
  3209. $('#calc-img').attr('src', updateData.img);
  3210. $('#calc-remark').html(img_remark);
  3211. $('#view-calc-img').attr('src', updateData.img);
  3212. $('#show-calc-img').attr('src', updateData.img);
  3213. $('#show-calc-remark').html((img_remark ? '<td colspan="2">'+ img_remark +'</td>' : ''));
  3214. $('#view-calc-remark').text(img_remark);
  3215. $('#edit-img').modal('hide');
  3216. // updateImageData = updateData;
  3217. // $('#edit-img').modal('hide');
  3218. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  3219. // stageIm.loadUpdateDetailData(result);
  3220. // data.calc_img = result.calc_img;
  3221. // data.calc_img_org = result.calc_img_org;
  3222. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3223. // $('#show-calc-img').attr('src', calcImgSrc);
  3224. // $('#calc-img').attr('src', calcImgSrc);
  3225. // $('#view-calc-img').attr('src', calcImgSrc);
  3226. // $('#edit-img').modal('hide');
  3227. // });
  3228. } else if (data.calc_img) {
  3229. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid, calc_img_remark: img_remark};
  3230. $('#show-calc-img').attr('src', '');
  3231. $('#show-calc-remark').html('');
  3232. $('#calc-img').attr('src', '');
  3233. $('#calc-remark').html('');
  3234. $('#view-calc-img').attr('src', '');
  3235. $('#view-calc-remark').val('');
  3236. $('#text-edit').val('');
  3237. $('#edit-img').modal('hide');
  3238. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  3239. // stageIm.loadUpdateDetailData(result);
  3240. // data.calc_img = result.calc_img;
  3241. // data.calc_img_org = result.calc_img_org;
  3242. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3243. // $('#show-calc-img').attr('src', calcImgSrc);
  3244. // $('#calc-img').attr('src', calcImgSrc);
  3245. // $('#view-calc-img').attr('src', calcImgSrc);
  3246. // $('#edit-img').modal('hide');
  3247. // });
  3248. } else {
  3249. self.updateImageData = updateData;
  3250. $('#show-calc-img').attr('src', '');
  3251. $('#show-calc-remark').html('');
  3252. $('#calc-img').attr('src', '');
  3253. $('#calc-remark').html('');
  3254. $('#view-calc-img').attr('src', '');
  3255. $('#view-calc-remark').val('');
  3256. $('#text-edit').val('');
  3257. $('#edit-img').modal('hide');
  3258. }
  3259. });
  3260. }
  3261. reBuildImData() {
  3262. const imData = stageIm.buildImData();
  3263. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3264. this.reLoadDetailData();
  3265. this.loadLocateInfo();
  3266. }
  3267. loadStageLedgerUpdateData(data, nodes) {
  3268. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3269. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3270. this.reLoadDetailData();
  3271. }
  3272. loadStagePosUpdateData(data, nodes) {
  3273. const imData = stageIm.loadUpdatePosData(data, nodes);
  3274. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3275. this.reLoadDetailData();
  3276. }
  3277. loadStageChangeUpdateData(data, nodes) {
  3278. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3279. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3280. this.reLoadDetailData();
  3281. }
  3282. loadLocateInfo() {
  3283. const select = SpreadJsObj.getSelectObject(this.sheet);
  3284. if (select && select.source.length > 1) {
  3285. $('#im-locate2bills').next().show();
  3286. } else {
  3287. $('#im-locate2bills').next().hide();
  3288. }
  3289. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3290. }
  3291. reLoadDetailData() {
  3292. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3293. $('#reset-detail').hide();
  3294. if (data) {
  3295. for (const f of data.custom_define) {
  3296. if (stageIm.resetFields.indexOf(f) >= 0) {
  3297. $('#reset-detail').show();
  3298. break;
  3299. }
  3300. }
  3301. $('#edit-detail').show();
  3302. $('#modify-img').show();
  3303. } else {
  3304. $('#edit-detail').hide();
  3305. $('#modify-img').hide();
  3306. }
  3307. $('#save-detail').hide();
  3308. $('#cancel-detail').hide();
  3309. $('#detail-show').show();
  3310. $('#detail-edit').hide();
  3311. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3312. $('#show-contract-jl').text(contractJl);
  3313. $('#contract-jl').val(contractJl);
  3314. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3315. $('#show-qc-jl').text(qcJl);
  3316. $('#qc-jl').val(qcJl);
  3317. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3318. $('#show-bgl-code').text(bglCode);
  3319. $('#bgl-code').val(bglCode);
  3320. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3321. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3322. $('#bgl-drawing-code').val(bglDrawingCode);
  3323. const bwName = data && data.bw ? data.bw : '';
  3324. $('#show-bw-name').text(bwName);
  3325. $('#bw-name').val(bwName);
  3326. const position = data && data.position ? data.position : '';
  3327. $('#show-position').text(position);
  3328. $('#position').val(position);
  3329. const peg = data && data.peg ? data.peg : '';
  3330. $('#show-peg').text(peg);
  3331. $('#peg').val(peg);
  3332. const xmName = data && data.xm ? data.xm: '';
  3333. $('#show-xm-name').text(xmName);
  3334. $('#xm-name').val(xmName);
  3335. const jldy = data && data.jldy ? data.jldy: '';
  3336. $('#show-jldy').text(jldy);
  3337. $('#jldy').val(jldy);
  3338. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3339. $('#show-drawing-code').text(drawingCode);
  3340. $('#drawing-code').val(drawingCode);
  3341. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3342. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3343. $('#calc-memo').val(calcMemo);
  3344. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3345. $('#show-calc-img').attr('src', calcImgSrc);
  3346. $('#calc-img').attr('src', calcImgSrc);
  3347. $('#view-calc-img').attr('src', calcImgSrc);
  3348. const calcImgRemark = data && data.calc_img_remark || '';
  3349. $('#view-calc-remark').val(calcImgRemark);
  3350. $('#show-calc-remark').html((calcImgRemark ? '<td colspan="2">'+ calcImgRemark +'</td>' : ''));
  3351. $('#calc-remark').html(calcImgRemark);
  3352. $("#view-calc-remark").attr('readonly', true);
  3353. // 处理 编辑 -> 添加草图中textarea多余的空格
  3354. $('#text-edit').val(calcImgRemark)
  3355. }
  3356. }
  3357. class CheckedChange {
  3358. constructor (setting) {
  3359. const self = this;
  3360. this.changeSpreadSetting = {
  3361. cols: [
  3362. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  3363. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3364. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3365. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3366. ],
  3367. emptyRows: 0,
  3368. headRows: 1,
  3369. headRowHeight: [32],
  3370. headColWidth: [30],
  3371. defaultRowHeight: 21,
  3372. headerFont: '12px 微软雅黑',
  3373. font: '12px 微软雅黑',
  3374. readOnly: true,
  3375. };
  3376. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3377. this.changeSheet = this.changeSpread.getActiveSheet();
  3378. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3379. const getTipText = function (data) {
  3380. if (!data) return '';
  3381. const tips = [];
  3382. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3383. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3384. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3385. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3386. return tips.join('-');
  3387. };
  3388. this.changeBillsSpreadSetting = {
  3389. cols: [
  3390. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', cellType: 'tip', getTip: getTipText},
  3391. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'tip', getTip: getTipText},
  3392. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'tip', getTip: getTipText},
  3393. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', cellType: 'tip', getTip: getTipText},
  3394. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3395. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3396. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: getTipText},
  3397. ],
  3398. emptyRows: 0,
  3399. headRows: 1,
  3400. headRowHeight: [32],
  3401. defaultRowHeight: 21,
  3402. headerFont: '12px 微软雅黑',
  3403. font: '12px 微软雅黑',
  3404. readOnly: true
  3405. };
  3406. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3407. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3408. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3409. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3410. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3411. if (change.cid === self.curChangeId) { return; }
  3412. self.curChangeId = change.cid;
  3413. if (change.detail) {
  3414. self.loadChangeDetailData();
  3415. } else {
  3416. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  3417. change.detail = result;
  3418. self.analyzeChange(change);
  3419. self.loadChangeDetailData();
  3420. });
  3421. }
  3422. });
  3423. this.changes = null;
  3424. this.reloadChangeData();
  3425. setting.reloadObj.click(function() {
  3426. self.reloadChangeData();
  3427. });
  3428. $.contextMenu({
  3429. selector: '#' + setting.changeBillsObj.attr('id'),
  3430. build: function ($trigger, e) {
  3431. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3432. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3433. },
  3434. items: {
  3435. 'locateZjjl': {
  3436. name: '定位至台账',
  3437. icon: 'fa-sign-in',
  3438. callback: function (key, opt) {
  3439. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3440. if (changeBills.gcl_id) {
  3441. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3442. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3443. stagePosSpreadObj.loadCurPosData();
  3444. } else {
  3445. const cb = {
  3446. b_code: changeBills.code || '',
  3447. name: changeBills.name || '',
  3448. unit: changeBills.unit || '',
  3449. unit_price: changeBills.unit_price || 0,
  3450. };
  3451. for (const node of stageTree.nodes) {
  3452. if (node.children && node.children.length > 0) continue;
  3453. const b = {
  3454. b_code: node.b_code || '',
  3455. name: node.name || '',
  3456. unit: node.unit || '',
  3457. unit_price: node.unit_price || 0,
  3458. };
  3459. if (_.isMatch(cb, b)) {
  3460. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3461. stagePosSpreadObj.loadCurPosData();
  3462. return;
  3463. }
  3464. }
  3465. }
  3466. },
  3467. disabled: function (key, opt) {
  3468. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3469. return !changeBills;
  3470. }
  3471. },
  3472. }
  3473. });
  3474. }
  3475. loadChangeDetailData() {
  3476. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  3477. if (change) {
  3478. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3479. } else {
  3480. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3481. }
  3482. }
  3483. refresh() {
  3484. this.changeSpread.refresh();
  3485. this.changeBillsSpread.refresh();
  3486. }
  3487. reloadChangeData() {
  3488. const self = this;
  3489. postData(window.location.pathname + '/change/data', null, function (result) {
  3490. self.changes = result.changes;
  3491. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3492. self.changeSheet.setSelection(0, 0, 1, 1);
  3493. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  3494. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3495. self.loadChangeDetailData();
  3496. });
  3497. }
  3498. analyzeChange(change) {
  3499. change.bills = change.detail.bills;
  3500. for (const b of change.bills) {
  3501. const aub = change.detail.addUsedBills.find(function (x) {
  3502. return x.id === b.id;
  3503. });
  3504. if (aub) {
  3505. b.used_qty = aub.used_qty;
  3506. }
  3507. b.qty = _.toNumber(b.samount);
  3508. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3509. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3510. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3511. b.cur_qty = 0;
  3512. for (const p of b.pos) {
  3513. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3514. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3515. }
  3516. }
  3517. }
  3518. }
  3519. // 展开收起附件
  3520. $('a', '.right-nav').bind('click', function () {
  3521. //const main = $('#main-view'), tool = $('#tools-view');
  3522. const tab = $(this), tabPanel = $(tab.attr('content'));
  3523. if (!tab.hasClass('active')) {
  3524. $('a', '.side-menu').removeClass('active');
  3525. $('.tab-content .tab-select-show').removeClass('active');
  3526. tab.addClass('active');
  3527. tabPanel.addClass('active');
  3528. showSideTools(tab.hasClass('active'));
  3529. if (tab.attr('content') === '#search' && !searchLedger) {
  3530. searchLedger = $.billsSearch({
  3531. selector: '#search',
  3532. searchSpread: slSpread,
  3533. searchRangeStr: '项目节编号/名称',
  3534. searchOver: true,
  3535. searchEmpty: true,
  3536. resultSpreadSetting: {
  3537. cols: [
  3538. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3539. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3540. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3541. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3542. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3543. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3544. {title: '完成率(%)', field: 'end_gather_percent', hAlign: 2, width: 70},
  3545. ],
  3546. emptyRows: 0,
  3547. headRows: 1,
  3548. headRowHeight: [32],
  3549. headColWidth: [30],
  3550. defaultRowHeight: 21,
  3551. headerFont: '12px 微软雅黑',
  3552. font: '12px 微软雅黑',
  3553. selectedBackColor: '#fffacd',
  3554. },
  3555. afterLocated: function () {
  3556. stagePosSpreadObj.loadCurPosData();
  3557. },
  3558. customSearch: [
  3559. {
  3560. key: 'less', title: '漏计', valid: true,
  3561. check: function (node) {
  3562. if (node.quantity) {
  3563. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3564. } else if (node.total_price) {
  3565. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3566. }
  3567. }
  3568. }, {
  3569. key: 'over', title: '超计', valid: true,
  3570. check: function (node) {
  3571. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3572. }
  3573. }, {
  3574. key: 'empty', title: '漏计', valid: false,
  3575. check: function (node) {
  3576. if (node.quantity) {
  3577. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3578. } else if (node.total_price) {
  3579. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3580. }
  3581. }
  3582. }, {
  3583. key: 'estimate', title: '预计变更', valid: true,
  3584. check: function (node) {
  3585. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3586. if (posRange.length > 0) {
  3587. for (const p of posRange) {
  3588. if (!checkZero(p.estimate_qty)) return true;
  3589. }
  3590. return false;
  3591. } else {
  3592. return false;
  3593. }
  3594. }
  3595. }
  3596. ],
  3597. });
  3598. searchLedger.spread.refresh();
  3599. }
  3600. if (tab.attr('content') === '#fujian') {
  3601. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3602. node && getNodeList(node.id);
  3603. }
  3604. if (tab.attr('content') === '#zhongjian') {
  3605. if (!detail) {
  3606. detail = new Detail($('#detail-spread'));
  3607. detail.spread.refresh();
  3608. $('#zhongjian .sjs-bottom').height('400px');
  3609. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3610. } else {
  3611. detail.spread.refresh();
  3612. }
  3613. }
  3614. if (tab.attr('content') === '#checked-change') {
  3615. if (!checkedChanges) {
  3616. checkedChanges = new CheckedChange({
  3617. changeObj: $('#cc-spread'),
  3618. changeBillsObj: $('#ccb-spread'),
  3619. reloadObj: $('#refresh-cc'),
  3620. });
  3621. checkedChanges.refresh();
  3622. } else {
  3623. $('#ccb-spread').height('400px');
  3624. checkedChanges.refresh();
  3625. }
  3626. }
  3627. if (tab.attr('content') === '#error-list') {
  3628. errorList.spread.refresh();
  3629. }
  3630. if (tab.attr('content') === '#check-list') {
  3631. checkList.spread.refresh();
  3632. }
  3633. if (tab.attr('content') === '#sum-load-miss') sumLoadMiss.spread.refresh();
  3634. } else {
  3635. tab.removeClass('active');
  3636. tabPanel.removeClass('active');
  3637. showSideTools(tab.hasClass('active'));
  3638. }
  3639. slSpread.refresh();
  3640. spSpread.refresh();
  3641. });
  3642. // 切换附件里节点和所有附件
  3643. $('#fujian .nav-link').on('click', function () {
  3644. const tabPanel = $(this).attr('fujian-content');
  3645. if (tabPanel !== 'syfujian') {
  3646. $('#showPage').hide();
  3647. $('#bach-download').prop('type', 'curr');
  3648. } else {
  3649. $('#showPage').show();
  3650. $('#bach-download').prop('type', 'all')
  3651. }
  3652. $('#showAttachment').hide();
  3653. });
  3654. // 上传附件
  3655. $('#upload-file-btn').click(function () {
  3656. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3657. // return toastr.error('当前操作没有权限!');
  3658. // }
  3659. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3660. if (!node) return
  3661. const files = $('#upload-file')[0].files;
  3662. const formData = new FormData();
  3663. formData.append('lid', node.id);
  3664. for (const file of files) {
  3665. if (file === undefined) {
  3666. toastr.error('未选择上传文件!');
  3667. return false;
  3668. }
  3669. const filesize = file.size;
  3670. if (filesize > 30 * 1024 * 1024) {
  3671. toastr.error('存在上传文件大小过大!');
  3672. return false;
  3673. }
  3674. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3675. if (whiteList.indexOf(fileext) === -1) {
  3676. toastr.error('只能上传指定格式的附件!');
  3677. return false;
  3678. }
  3679. formData.append('size', filesize);
  3680. formData.append('file[]', file);
  3681. }
  3682. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3683. $('#upload').modal('hide');
  3684. // 插入到attData中
  3685. attData = data.concat(attData);
  3686. // 重新生成List
  3687. getAllList();
  3688. getNodeList(node.id);
  3689. }, function () {
  3690. toastr.error('附件上传失败');
  3691. });
  3692. $('#upload-file').val('');
  3693. });
  3694. // 获取附件信息
  3695. $('.list-table').on('click', '.att-file-name', function () {
  3696. const fid = $(this).attr('file-id');
  3697. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3698. return;
  3699. }
  3700. const att = attData.find(function (item) {
  3701. return item.id === parseInt(fid);
  3702. });
  3703. $('#edit-att').hide();
  3704. $('#show-att').show();
  3705. if (att !== undefined) {
  3706. // 进来先把编辑功能隐藏
  3707. $('#btn-att a').eq(3).hide()
  3708. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3709. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3710. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3711. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3712. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3713. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3714. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3715. $('#show-att tr').eq(3).children('td').text(att.remark);
  3716. // 附件uid等于当前用户id, 附件上传本人
  3717. if (parseInt(cur_uid) === att.uid) {
  3718. $('#btn-att').show();
  3719. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3720. // if (!curAuditor) {
  3721. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3722. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3723. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3724. // } else {
  3725. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3726. // }
  3727. if (showDel) $('#btn-att a').eq(3).show();
  3728. // $('#btn-att a').eq(3).show();
  3729. $('#btn-att a').eq(2).hide();
  3730. $('#btn-att a').eq(4).hide();
  3731. $('#btn-att a').eq(5).hide();
  3732. } else {
  3733. $('#btn-att').hide();
  3734. $('#btn-att a').eq(3).hide();
  3735. $('#btn-att a').eq(2).hide();
  3736. $('#btn-att a').eq(4).hide();
  3737. $('#btn-att a').eq(5).hide();
  3738. }
  3739. $('#showAttachment').attr('file-id', fid);
  3740. $('#showAttachment').show();
  3741. } else {
  3742. $('#showAttachment').hide();
  3743. $('#showAttachment').attr('file-id', '');
  3744. toastr.error('附件信息获取失败');
  3745. }
  3746. });
  3747. // $('body').on('click', '.alllist-table a', handleFileList);
  3748. $('body').on('click', '#btn-att a', function () {
  3749. const content = $(this).attr('content');
  3750. const fid = $('#showAttachment').attr('file-id');
  3751. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3752. if (content === 'edit') {
  3753. $('#btn-att a').eq(3).hide();
  3754. $('#btn-att a').eq(2).show();
  3755. $('#btn-att a').eq(4).show();
  3756. $('#btn-att a').eq(5).show();
  3757. $('#show-att').hide();
  3758. $('#edit-att').show();
  3759. const att = attData.find(function (item) {
  3760. return item.id === parseInt(fid);
  3761. });
  3762. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3763. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3764. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3765. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3766. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3767. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3768. } else if (content === 'cancel') {
  3769. $('#show-att').show();
  3770. $('#edit-att').hide();
  3771. $('#btn-att a').eq(3).show();
  3772. $('#btn-att a').eq(2).hide();
  3773. $('#btn-att a').eq(4).hide();
  3774. $('#btn-att a').eq(5).hide();
  3775. } else if (content === 'save') {
  3776. const formData = new FormData();
  3777. formData.append('id', fid);
  3778. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3779. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3780. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3781. const file = $('#change-att-btn')[0];
  3782. if (file.files[0] !== undefined) {
  3783. const filesize = file.files[0].size;
  3784. formData.append('size', filesize);
  3785. formData.append('file', file.files[0]);
  3786. }
  3787. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3788. // 替换到attData中
  3789. const att_index = attData.findIndex(function (item) {
  3790. return item.id === parseInt(fid);
  3791. });
  3792. attData.splice(att_index, 1, data);
  3793. // 重新生成List
  3794. getAllList(parseInt($('#currentPage').text()));
  3795. getNodeList(node.id);
  3796. $('#show-att').show();
  3797. $('#edit-att').hide();
  3798. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3799. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3800. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3801. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3802. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3803. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3804. $('#show-att tr').eq(4).children('td').text(data.remark);
  3805. $('#btn-att a').eq(3).show();
  3806. $('#btn-att a').eq(2).hide();
  3807. $('#btn-att a').eq(4).hide();
  3808. $('#btn-att a').eq(5).hide();
  3809. }, function () {
  3810. toastr.error('附件上传失败');
  3811. });
  3812. $('#change-att-btn').val('');
  3813. } else if (content === 'del') {
  3814. const data = {id: fid};
  3815. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3816. // 删除到attData中
  3817. const att_index = attData.findIndex(function (item) {
  3818. return item.id === parseInt(fid);
  3819. });
  3820. attData.splice(att_index, 1);
  3821. // 重新生成List
  3822. if ($('#alllist-table tr').length === 1) {
  3823. getAllList(parseInt($('#currentPage').text()) - 1);
  3824. } else {
  3825. getAllList(parseInt($('#currentPage').text()));
  3826. }
  3827. getNodeList(node.id);
  3828. $('#showAttachment').hide();
  3829. $('#showAttachment').attr('file-id', '');
  3830. });
  3831. } else if (content === 'view') {
  3832. const data = {id: fid};
  3833. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3834. const { filepath } = result
  3835. $('#load-file').attr('href', filepath);
  3836. $('#load-file')[0].click();
  3837. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3838. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3839. });
  3840. } else if (content === 'location') {
  3841. const att = attData.find(item => item.id === parseInt(fid));
  3842. if (Object.keys(att).length) {
  3843. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3844. stagePosSpreadObj.loadCurPosData();
  3845. }
  3846. }
  3847. });
  3848. // 替换附件
  3849. $('#change-att-btn').on('change', function () {
  3850. const file = $('#change-att-btn')[0].files[0];
  3851. const name = file.name;
  3852. const filename = name.substring(0, name.lastIndexOf("."));
  3853. const fileext = name.substr(name.indexOf("."));
  3854. const filesize = file.size;
  3855. if (filesize > 10 * 1024 * 1024) {
  3856. toastr.error('文件大小过大!');
  3857. $('#change-att-btn').val('');
  3858. return false;
  3859. }
  3860. if (whiteList.indexOf(fileext) === -1) {
  3861. toastr.error('只能上传指定格式的附件!');
  3862. $('#change-att-btn').val('');
  3863. return false;
  3864. }
  3865. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3866. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3867. });
  3868. // 切换页数
  3869. $('.page-select').on('click', function () {
  3870. const totalPageNum = parseInt($('#totalPage').text());
  3871. const lastPageNum = parseInt($('#currentPage').text());
  3872. const status = $(this).attr('content');
  3873. if (status === 'pre' && lastPageNum > 1) {
  3874. getAllList(lastPageNum-1);
  3875. $('#showAttachment').hide();
  3876. $('#syfujian .check-all-file').prop('checked', false)
  3877. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3878. getAllList(lastPageNum+1);
  3879. $('#showAttachment').hide();
  3880. $('#syfujian .check-all-file').prop('checked', false)
  3881. }
  3882. });
  3883. // 批量下载
  3884. $('#bach-download').click(function() {
  3885. const fileIds = [];
  3886. const type = $(this).attr('type');
  3887. let node = ''
  3888. if (type === 'curr') {
  3889. node = '#nodelist-table .check-file:checked'
  3890. } else {
  3891. node = '#alllist-table .check-file:checked'
  3892. }
  3893. $(node).each(function() {
  3894. const fileId = $(this).attr('file-id');
  3895. fileId && fileIds.push(fileId);
  3896. });
  3897. if (fileIds.length) {
  3898. if (fileIds.length > 10) {
  3899. return toastr.warning(`最大允许10个文件(当前${fileIds.length}个)`)
  3900. }
  3901. toastr.success('正在进行压缩文件...', '', { timeOut: 0, extendedTimeOut: 0})
  3902. $(this).attr('disabled', "true")
  3903. const btn = $(this)
  3904. postCompressFile(`/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file`, {fileIds}, function(result) {
  3905. toastr.clear()
  3906. toastr.success('压缩文件成功')
  3907. btn.removeAttr('disabled')
  3908. const href = window.URL.createObjectURL(result)
  3909. $('#zipDown').attr('href', href);
  3910. $('#zipDown').attr('download', `${tender.name}-计量台账-第${stage.order}期-附件.zip`);
  3911. $("#zipDown")[0].click();
  3912. }, () => {
  3913. btn.removeAttr('disabled')
  3914. toastr.clear()
  3915. toastr.error('批量下载失败')
  3916. });
  3917. // const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  3918. // $('#zipDown').attr('href', url);
  3919. // $("#zipDown")[0].click();
  3920. }
  3921. });
  3922. // 监听附件check是否选中
  3923. $('.list-table').on('click', '.check-file', function() {
  3924. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3925. const childs = $(this).parents('.list-table').children().length;
  3926. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3927. if (checkedList.length === childs) {
  3928. checkBox.prop("checked", true);
  3929. } else {
  3930. checkBox.prop("checked", false);
  3931. }
  3932. });
  3933. $('.check-all-file').click(function() {
  3934. const isCheck = $(this).is(':checked');
  3935. $(this).parents('table').find('.list-table').each(function() {
  3936. $(this).find('input:checkbox').prop("checked", isCheck);
  3937. })
  3938. });
  3939. // 显示层次
  3940. (function (select, sheet) {
  3941. $(select).click(function () {
  3942. if (!sheet.zh_tree) return;
  3943. const tag = $(this).attr('tag');
  3944. const tree = sheet.zh_tree;
  3945. setTimeout(() => {
  3946. showWaitingView();
  3947. switch (tag) {
  3948. case "1":
  3949. case "2":
  3950. case "3":
  3951. case "4":
  3952. case "5":
  3953. tree.expandByLevel(parseInt(tag));
  3954. SpreadJsObj.refreshTreeRowVisible(sheet);
  3955. break;
  3956. case "last":
  3957. tree.expandByCustom(() => { return true; });
  3958. SpreadJsObj.refreshTreeRowVisible(sheet);
  3959. break;
  3960. case "leafXmj":
  3961. tree.expandToLeafXmj();
  3962. SpreadJsObj.refreshTreeRowVisible(sheet);
  3963. break;
  3964. case "curMeasure":
  3965. tree.expandByCustom(function (node) {
  3966. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3967. if (node[field]) {
  3968. return true;
  3969. }
  3970. }
  3971. return false;
  3972. });
  3973. SpreadJsObj.refreshTreeRowVisible(sheet);
  3974. break;
  3975. }
  3976. closeWaitingView();
  3977. }, 100);
  3978. });
  3979. })('a[name=showLevel]', slSpread.getActiveSheet());
  3980. const stageCheckerSetting = {
  3981. ledgerTree: stageTree,
  3982. ledgerPos: stagePos,
  3983. checkList: checkList,
  3984. decimal: tenderInfo.decimal,
  3985. checkOption: checkOption,
  3986. };
  3987. if (!checkTzMeasureType()) {
  3988. stageCheckerSetting.checkOption.calc.fields.push('sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity');
  3989. stageCheckerSetting.checkOption.tp.fields.push(
  3990. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  3991. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  3992. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  3993. {qty: 'quantity', tp: 'total_price'},
  3994. );
  3995. }
  3996. $('#ledger-check2').click(() => {
  3997. const result = ledgerCheck2(stageCheckerSetting);
  3998. check2Viewing({
  3999. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  4000. randomWait: true,
  4001. prefix: 'check2-',
  4002. checks: result,
  4003. checkList: checkList,
  4004. })
  4005. });
  4006. const dataChecker = DataChecker({
  4007. checkUrl: window.location.pathname + '/check',
  4008. completeData: function (data) {
  4009. stagePos.updateDatas({pos: data.source.pos});
  4010. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  4011. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  4012. stagePosSpreadObj.loadCurPosData();
  4013. for (const e of data.error) {
  4014. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  4015. }
  4016. },
  4017. errorList: errorList,
  4018. });
  4019. $('[name=stage-start]').submit(function (e) {
  4020. if (checkAuditorFrom()) {
  4021. // 再检查多人协同确认情况
  4022. const list = stageTree.pwd.find(x => {return !x.confirm });
  4023. if(list) {
  4024. toastr.error('请检查多人协同确认情况再上报');
  4025. $('#hide-all').hide();
  4026. return false;
  4027. }
  4028. $(this).parent().parent().parent().modal('hide');
  4029. dataChecker.checkAndPost(this.action, {});
  4030. $('#hide-all').hide();
  4031. }
  4032. return false;
  4033. });
  4034. $('#audit-check0').submit(function (e) {
  4035. // 再检查多人协同确认情况
  4036. const list = stageTree.pwd.find(x => {return !x.confirm });
  4037. if(list) {
  4038. toastr.error('请检查多人协同确认情况再审批通过');
  4039. $('#hide-all').hide();
  4040. return false;
  4041. }
  4042. const checkType = parseInt($('[name=checkType]').val());
  4043. const data = {
  4044. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4045. checkType,
  4046. };
  4047. $('#sp-done').modal('hide');
  4048. checkType && dataChecker.checkAndPost(this.action, data);
  4049. $('#hide-all').hide();
  4050. return false;
  4051. });
  4052. $('#audit-check1').submit(function (e) {
  4053. const checkType = parseInt($('[name=checkType]:checked').val());
  4054. const data = {
  4055. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  4056. checkType,
  4057. };
  4058. if ($('#warning-text').length) $('#warning-text').remove()
  4059. if (!checkType && !$('#warning-text').length) {
  4060. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  4061. return false
  4062. }
  4063. $('#sp-back').modal('hide');
  4064. checkType && dataChecker.checkAndPost(this.action, data);
  4065. $('#hide-all').hide();
  4066. return false;
  4067. });
  4068. $('#exportExcel').click(function () {
  4069. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  4070. });
  4071. $('#cbr-check-all').click(function () {
  4072. if (this.checked) {
  4073. $('input', '#cbr-pos-list').attr('checked', 'checked');
  4074. } else {
  4075. $('input', '#cbr-pos-list').removeAttr('checked');
  4076. }
  4077. });
  4078. $('#cbr-ok').click(() => {
  4079. const ratio = parseInt($('#cbr-ratio').val());
  4080. if (!ratio) {
  4081. toastr.warning('请输入计量比例');
  4082. return;
  4083. } else if (ratio < 1) {
  4084. toastr.warning('计量比例不可小于1');
  4085. return;
  4086. } else if (ratio > 100) {
  4087. toastr.warning('计量比例不可大于100');
  4088. return;
  4089. }
  4090. const apply2sibling = $('#apply2sibling')[0].checked;
  4091. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  4092. if (posName.length === 0) {
  4093. toastr.warning('请勾选需要按计量比例的计量单元');
  4094. return;
  4095. }
  4096. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  4097. });
  4098. $('body').on('click', '[name=ledger-unlock]', function() {
  4099. $('#cooperation').modal('hide');
  4100. const lid = this.getAttribute('lid');
  4101. if (!lid) return;
  4102. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4103. if (!p) return;
  4104. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  4105. $('#unlock-pwd').val('').removeClass('is-invalid');
  4106. $('.invalid-feedback', '#unlock').hide();
  4107. $('.alert-warning', '#unlock').hide();
  4108. $('#unlock-ok').attr('lid', lid);
  4109. $('#unlock').modal('show');
  4110. });
  4111. $('#unlock-ok').click(function () {
  4112. const lid = this.getAttribute('lid');
  4113. if (!lid) return;
  4114. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4115. if (!p) return;
  4116. if (p.pwd === $('#unlock-pwd').val()) {
  4117. const refresh = stageTree.lockNode(p, false);
  4118. // 修改线上
  4119. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  4120. stagePosSpreadObj.loadCurPosData();
  4121. $('#unlock').modal('hide');
  4122. reloadCooperationHtml();
  4123. } else {
  4124. $('#unlock-pwd').addClass('is-invalid');
  4125. $('.invalid-feedback', '#unlock').show();
  4126. $('.alert-warning', '#unlock').show();
  4127. }
  4128. });
  4129. $('#cooperationSelect').change(function () {
  4130. reloadCooperationHtml();
  4131. });
  4132. // 确认
  4133. $('body').on('click', '[name=ledger-confirm]', function() {
  4134. const lid = this.getAttribute('lid');
  4135. if (!lid) return;
  4136. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4137. if (!p) return;
  4138. // 修改线上
  4139. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4140. p.confirm = true;
  4141. p.confirm_time = new Date();
  4142. stageTree.confirmList = result.cooperationConfirm;
  4143. reloadCooperationHtml();
  4144. });
  4145. });
  4146. // 确认
  4147. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4148. const lid = this.getAttribute('lid');
  4149. if (!lid) return;
  4150. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4151. if (!p) return;
  4152. // 修改线上
  4153. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4154. p.confirm = false;
  4155. p.confirm_time = null;
  4156. stageTree.confirmList = result.cooperationConfirm;
  4157. reloadCooperationHtml();
  4158. });
  4159. });
  4160. // 收方单生成
  4161. $('#setshoufang').click(function () {
  4162. const lid = $('#shoufang-lid').val();
  4163. const pid = $('#shoufang-pid').val() !== '' ? $('#shoufang-pid').val() : null;
  4164. // 修改线上
  4165. postData(window.location.pathname + '/save/shoufang', { type: 'add', postData: { lid, pid } }, function (result) {
  4166. // 收方单tab打开并显示在最新
  4167. if (!$('#shoufang-tab').hasClass('active')) {
  4168. $('#shoufang-tab').click();
  4169. }
  4170. const data = makeOneShouFang(result);
  4171. data.filenum = 0;
  4172. sfData = _.concat(data, sfData);
  4173. getShouFangList();
  4174. });
  4175. });
  4176. $('body').on('click', '.del-shoufang', function () {
  4177. const id = $(this).attr('data-id');
  4178. $('#del-shoufang-id').val(id);
  4179. const name = $(this).parents('tr').children('td').eq(0).text();
  4180. const ledger_code = name.split(' / ')[0];
  4181. const pos_name = name.split(' / ')[1] ? name.split(' / ')[1] : '';
  4182. $('#del-shoufang-ledger').text('清单:' + ledger_code);
  4183. if (pos_name) {
  4184. $('#del-shoufang-pos').text('计量单元:' + pos_name).show();
  4185. } else {
  4186. $('#del-shoufang-pos').text('').hide();
  4187. }
  4188. });
  4189. // 收方单删除
  4190. $('#delshoufang').click(function () {
  4191. const sfid = $('#del-shoufang-id').val();
  4192. // 修改线上
  4193. postData(window.location.pathname + '/save/shoufang', { type: 'del', postData: { sfid } }, function (result) {
  4194. // 删除到sfData中
  4195. const att_index = sfData.findIndex(function (item) {
  4196. return item.id === parseInt(sfid);
  4197. });
  4198. sfData.splice(att_index, 1);
  4199. // 重新生成List
  4200. if ($('#shoufang-table tr').length === 1) {
  4201. getShouFangList(parseInt($('#shoufang-currentPage').text()) - 1);
  4202. } else {
  4203. getShouFangList(parseInt($('#shoufang-currentPage').text()));
  4204. }
  4205. $('#shoufangdelete').modal('hide');
  4206. });
  4207. });
  4208. // 切换页数
  4209. $('.shoufang-page-select').on('click', function () {
  4210. const totalPageNum = parseInt($('#shoufang-totalPage').text());
  4211. const lastPageNum = parseInt($('#shoufang-currentPage').text());
  4212. const status = $(this).attr('content');
  4213. if (status === 'pre' && lastPageNum > 1) {
  4214. getShouFangList(lastPageNum-1);
  4215. } else if (status === 'next' && lastPageNum < totalPageNum) {
  4216. getShouFangList(lastPageNum+1);
  4217. }
  4218. });
  4219. // 获取单个收方单附件列表
  4220. $('body').on('click', '.show-shoufang-att', function () {
  4221. const id = parseInt($(this).attr('data-id'));
  4222. let html = '';
  4223. $('#shoufang-flie-list').html(html);
  4224. postData(window.location.pathname + '/shoufang/file', { sfid: id }, function (result) {
  4225. for (const att of result) {
  4226. html += `<tr><td>${att.filename}${att.fileext} ` + makeEditHtml(att.id, att.filename, att.fileext, att.extra_upload) +
  4227. `<td>${moment(att.in_time).format('YYYY-MM-DD HH:mm')}</td><td>` +
  4228. `<a href="${att.filepath}" target="_blank"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a>` + makeViewHtml(att.viewpath) + makeDelHtml(att.id, att.extra_upload) +`</td></tr>`;
  4229. }
  4230. $('#shoufang-flie-list').html(html);
  4231. $('[data-toggle="tooltip"]').tooltip()
  4232. });
  4233. function makeViewHtml(viewpath) {
  4234. return viewpath ? `<a href="${viewpath}" target="_blank" class="ml-1"><i data-toggle="tooltip" data-placement="left" data-original-title="预览" class="fa fa-eye"></i></a>` : '';
  4235. }
  4236. function makeDelHtml(fid, extra_upload) {
  4237. return sfAttDelPower &&
  4238. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4239. '<a href="javascript:void(0)" data-sfid="'+ id +'" data-id="'+ fid +'" title="删除" class="del-shoufang-att text-danger ml-3">' +
  4240. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4241. }
  4242. });
  4243. function makeEditHtml(fid, filename, fileext, extra_upload) {
  4244. return sfAttDelPower &&
  4245. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4246. '<a href="javascript:void(0)" data-filename="' + filename + '" data-fileext="'+ fileext +'" data-id="'+ fid +'" class="edit-shoufang-att ml-1">' +
  4247. '<i data-toggle="tooltip" data-placement="left" data-original-title="修改文件名" class="fa fa-pencil"></i></a></td>' : ''
  4248. }
  4249. // 修改收方单附件文件名
  4250. $('body').on('click', '.edit-shoufang-att', function () {
  4251. $(this).children('i').tooltip('hide');
  4252. const fid = $(this).data('id');
  4253. const filename = $(this).data('filename');
  4254. const fileext = $(this).data('fileext');
  4255. const html = `<div class="input-group input-group-sm">
  4256. <input type="text" class="form-control" value="${filename}" placeholder="输入文件名" aria-describedby="button-${fid}" style="width:50px">
  4257. <div class="input-group-append" id="button-${fid}">
  4258. <button class="btn btn-outline-primary shoufang-att-confirm-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">确认</button>
  4259. <button class="btn btn-outline-secondary shoufang-att-cancel-btn" data-filename="${filename}" data-fileext="${fileext}" data-fid="${fid}" type="button">取消</button>
  4260. </div>
  4261. </div>`;
  4262. $(this).parents('td').html(html);
  4263. });
  4264. // 确认修改文件名
  4265. $('body').on('click', '.shoufang-att-confirm-btn', function () {
  4266. const validText = $.trim($(this).parents('td').find('input').val());
  4267. const orgValue = $.trim($(this).data('filename'));
  4268. const fileext = $(this).data('fileext');
  4269. const fid = $(this).data('fid');
  4270. if (!validText) {
  4271. toastr.error('文件名不能为空');
  4272. return;
  4273. }
  4274. // const reg = /^[0-9a-zA-Z\-_\u4e00-\u9fa5]+$/;
  4275. if(validText.indexOf('.') !== -1 || validText.indexOf(' ') !== -1) {
  4276. toastr.error('文件名中不能包含.字符和空格');
  4277. return;
  4278. }
  4279. if(validText == orgValue) {
  4280. const html = `${orgValue}${fileext} ` + makeEditHtml(fid, orgValue, fileext, 1);
  4281. $(this).parents('td').html(html);
  4282. return;
  4283. }
  4284. const data = {
  4285. id: fid,
  4286. filename: validText,
  4287. };
  4288. const _self = $(this);
  4289. postData('/wap/shoufang/editfile', data, function (result) {
  4290. const html = `${validText}${fileext} ` + makeEditHtml(fid, validText, fileext, 1);
  4291. _self.parents('td').html(html);
  4292. });
  4293. });
  4294. // 取消修改文件名
  4295. $('body').on('click', '.shoufang-att-cancel-btn', function () {
  4296. const fid = $(this).data('fid');
  4297. const filename = $(this).data('filename');
  4298. const fileext = $(this).data('fileext');
  4299. const html = `${filename}${fileext} ` + makeEditHtml(fid, filename, fileext, 1);
  4300. $(this).parents('td').html(html);
  4301. });
  4302. // 删除收方单附件
  4303. $('body').on('click', '.del-shoufang-att', function () {
  4304. const id = $(this).data('id');
  4305. const _self = $(this);
  4306. const data = { id };
  4307. const sfid = $(this).data('sfid');
  4308. postData('/wap/shoufang/delfile', data, function (result) {
  4309. _self.parents('tr').remove();
  4310. // 附件个数更新
  4311. $('#shoufang-table').find('.show-shoufang-att[data-id="'+ sfid +'"]').text($('#shoufang-flie-list tr').length);
  4312. const sfInfo = _.find(sfData, { id: sfid });
  4313. sfInfo.filenum = $('#shoufang-flie-list tr').length;
  4314. });
  4315. });
  4316. // 定位到对应的清单或计量单元
  4317. $('body').on('click', '.show-shoufang-node', function () {
  4318. const id = parseInt($(this).attr('data-id'));
  4319. const sfInfo = _.find(sfData, { id });
  4320. if (sfInfo) {
  4321. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4322. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), lData.ledger_id, true);
  4323. stagePosSpreadObj.loadCurPosData();
  4324. if (sfInfo.pid) {
  4325. const posData = _.find(spSpread.getActiveSheet().zh_data, { id: sfInfo.pid });
  4326. SpreadJsObj.locateData(spSpread.getActiveSheet(), posData);
  4327. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  4328. }
  4329. }
  4330. });
  4331. // 定位到对应的清单或计量单元
  4332. $('body').on('click', '.show-shoufang-report', function () {
  4333. const id = parseInt($(this).attr('data-id'));
  4334. const [qrCodePath, replace_key_params, req_params, rpt_name] = makeReportData(id);
  4335. sessionStorage.qrCodePath = qrCodePath;
  4336. sessionStorage.replace_key_params = JSON.stringify(replace_key_params);
  4337. sessionStorage.req_params = JSON.stringify(req_params);
  4338. sessionStorage.rpt_name = rpt_name;
  4339. window.open('/individualReport/A4');
  4340. });
  4341. });
  4342. function makeOneShouFang(sf) {
  4343. const lData = _.find(ledgerData, { id: sf.lid });
  4344. sf.name = lData.b_code;
  4345. if (sf.pid) {
  4346. const pData = _.find(posData, { id: sf.pid });
  4347. sf.name = lData.b_code + ' / ' + pData.name;
  4348. }
  4349. return sf;
  4350. }
  4351. function makeShouFang() {
  4352. for (const sf of sfData) {
  4353. makeOneShouFang(sf);
  4354. }
  4355. getShouFangList();
  4356. }
  4357. // 生成收方单列表
  4358. function getShouFangList(currPageNum = 1) {
  4359. // 每页最多几个附件
  4360. const pageCount = 20;
  4361. // 附件总数
  4362. const total = sfData.length;
  4363. // 总页数
  4364. const pageNum = Math.ceil(total/pageCount);
  4365. $('#shoufang-totalPage').text(pageNum);
  4366. $('#shoufang-currentPage').text(total === 0 ? 0 : currPageNum);
  4367. // 当前页附件内容
  4368. const currPageAttData = sfData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  4369. let html = '';
  4370. for(const att of currPageAttData) {
  4371. html += '<tr><td>' + att.name + '</td>' +
  4372. '<td width="40"><a href="#shoufangfile" class="show-shoufang-att" data-id="'+ att.id +'" data-toggle="modal" data-target="#shoufangfile">'+ att.filenum +'</a></td>' +
  4373. '<td width="100">' +
  4374. '<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> ' +
  4375. '<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> ' +
  4376. // '<a href="javascript:void(0);"><i data-toggle="tooltip" data-placement="left" data-original-title="下载" class="fa fa-download"></i></a> ' +
  4377. makeDelHtml(att.id, att.extra_upload) +
  4378. '</td></tr>';
  4379. }
  4380. function makeDelHtml(id, extra_upload) {
  4381. return cur_uid === stage.user_id &&
  4382. (stage.status !== auditConst.status.checked || (stage.status === auditConst.status.checked && extra_upload)) ?
  4383. '<a href="javascript:void(0);" data-id="'+ id +'" data-toggle="modal" data-target="#shoufangdelete" class="ml-3 text-danger del-shoufang">' +
  4384. '<i data-toggle="tooltip" data-placement="left" data-original-title="删除" class="fa fa-remove"></i></a>' : '';
  4385. }
  4386. $('#shoufang-table').html(html);
  4387. $('[data-toggle="tooltip"]').tooltip();
  4388. }
  4389. function makeReportData(sfid) {
  4390. const sfInfo = _.find(sfData, { id: sfid });
  4391. const ledger_code = sfInfo.name.split(' / ')[0];
  4392. const pos_name = sfInfo.name.split(' / ')[1] ? sfInfo.name.split(' / ')[1] : '';
  4393. const replace_key_params = {
  4394. 'KEY_标段名称': tenderInfo.deal_info.buildName,
  4395. 'KEY_总承包单位': tenderInfo.construction_unit.contract1.company,
  4396. 'KEY_合同段': tenderInfo.deal_info.dealName,
  4397. 'KEY_监理单位': tenderInfo.construction_unit.supervision1.company,
  4398. 'KEY_编号': '',
  4399. 'KEY_设计工程数量': 0,
  4400. };
  4401. // if (sfInfo.pid) {
  4402. // const pData = _.find(posData, { id: sfInfo.pid });
  4403. // replace_key_params['KEY_设计工程数量'] = pData.quantity;
  4404. // } else {
  4405. const lData = _.find(ledgerData, { id: sfInfo.lid });
  4406. // }
  4407. replace_key_params['KEY_子目号及子目名称'] = ledger_code + ' ' + lData.name;
  4408. replace_key_params['KEY_桩号及工程部位'] = pos_name;
  4409. const req_params = {
  4410. rpt_tpl_id: window.location.host === '127.0.0.1:7002' || window.location.host === 'jlqa.smartcost.com.cn:7002' ? 1784 : (window.location.host === 'jluat.smartcost.com.cn' ? 315 : 2138), // 1784(qa的,外网是2138)
  4411. pageSize: 'A4',
  4412. project_id: tender.project_id,
  4413. tender_id: tender.id,
  4414. stage_id: stage.id,
  4415. };
  4416. const rpt_name = tender.name + '-第' + stage.order + '期-' + ledger_code + (pos_name ? '/' + pos_name : '-' + lData.name);
  4417. const qrCodePath = sfInfo.qrcode;
  4418. return [qrCodePath, replace_key_params, req_params, rpt_name];
  4419. }