stage.js 201 KB

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