stage.js 203 KB

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