stage.js 201 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176
  1. 'use strict';
  2. /**
  3. * 期计量 - 本期计量台账页面 js
  4. *
  5. * @author Mai
  6. * @date 2018/12/7
  7. * @version
  8. */
  9. const ckBillsSpread = window.location.pathname + '-billsSelect';
  10. function checkTzMeasureType () {
  11. return tender.measure_type === measureType.tz.value;
  12. }
  13. function transExpr(expr) {
  14. return $.trim(expr).replace('\t', '').replace('=', '').replace('%', '/100');
  15. }
  16. function getExprInfo (field) {
  17. const exprField = [
  18. {qty: 'sgfh_qty', expr: 'sgfh_expr'},
  19. {qty: 'sjcl_qty', expr: 'sjcl_expr'},
  20. {qty: 'qtcl_qty', expr: 'qtcl_expr'},
  21. {qty: 'contract_qty', expr: 'contract_expr'},
  22. ];
  23. return _.find(exprField, {qty: field});
  24. }
  25. /**
  26. * 从cookie中读取缓存的列显示设置,没有则取默认
  27. * @returns {*[]}
  28. */
  29. function customColDisplay () {
  30. const defaultSetting = [
  31. { title: '本期计量合同', fields: ['contract_qty', 'contract_tp'], visible: true },
  32. { title: '本期数量变更', fields: ['qc_qty', 'qc_tp', 'qc_bgl'], visible: true },
  33. { title: '本期完成计量', fields: ['gather_qty', 'gather_tp'], visible: true },
  34. { title: '截止本期计量合同', fields: ['end_contract_qty', 'end_contract_tp'], visible: true },
  35. { title: '截止本期数量变更', fields: ['end_qc_qty', 'end_qc_tp', 'end_qc_bgl'], visible: true },
  36. { title: '截止本期完成计量', fields: ['end_gather_qty', 'end_gather_tp', 'end_gather_percent'], visible: true },
  37. { title: '本期批注', fields: ['postil'], visible: true },
  38. { title: '图册号', fields: ['drawing_code'], visible: true },
  39. { title: '备注', fields: ['memo'], visible: true },
  40. { title: '总额计量', fields: ['is_tp'], visible: true},
  41. ];
  42. if (!checkTzMeasureType()) {
  43. defaultSetting.unshift({ title: '签约合同', fields: ['deal_qty', 'deal_tp'], visible: true }, { title: '台账', fields: ['quantity', 'total_price'], visible: true});
  44. }
  45. const settingStr = Cookies.get(ckColSetting);
  46. if (settingStr) {
  47. const customSetting = JSON.parse(settingStr);
  48. for (const ds of defaultSetting) {
  49. const cs = customSetting.find(x => {return x.title === ds.title});
  50. if (cs) ds.visible = cs.visible;
  51. }
  52. }
  53. return defaultSetting;
  54. }
  55. /**
  56. * 根据列显示设置,调整setting中的列是否显示
  57. * @param setting
  58. * @param customDisplay
  59. */
  60. function customizeStageTreeSetting(setting, customDisplay) {
  61. for (const cd of customDisplay) {
  62. for (const c of setting.cols) {
  63. if (cd.fields.indexOf(c.field) !== -1) {
  64. c.visible = cd.visible;
  65. }
  66. }
  67. }
  68. }
  69. /**
  70. * 初始化 树结构 列事件
  71. * @param setting
  72. */
  73. function initTreeColSettingEvents(setting) {
  74. const Events = {
  75. readOnly: {
  76. measureData: function (node) {
  77. return node.children && node.children.length > 0;
  78. },
  79. },
  80. };
  81. const getEvent = function (eventName) {
  82. const names = eventName.split('.');
  83. let event = Events;
  84. for (let name of names) {
  85. if (event[name]) {
  86. event = event[name];
  87. } else {
  88. return null;
  89. }
  90. }
  91. if (event && Object.prototype.toString.apply(event) !== "[object Function]") {
  92. return null;
  93. } else {
  94. return event;
  95. }
  96. };
  97. for (const col of setting.cols) {
  98. if (col.readOnly && Object.prototype.toString.apply(col.readOnly) === "[object String]") {
  99. col.readOnly = getEvent(col.readOnly);
  100. }
  101. }
  102. }
  103. // 生成所有附件列表
  104. function getAllList(currPageNum = 1) {
  105. // 每页最多几个附件
  106. const pageCount = 15;
  107. // 附件总数
  108. const total = attData.length;
  109. // 总页数
  110. const pageNum = Math.ceil(total/pageCount);
  111. $('#totalPage').text(pageNum);
  112. $('#currentPage').text(total === 0 ? 0 : currPageNum);
  113. // 当前页附件内容
  114. const currPageAttData = attData.slice((currPageNum-1)*pageCount, currPageNum*pageCount);
  115. let html = '';
  116. // '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id
  117. for(const att of currPageAttData) {
  118. html += `<tr>
  119. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  120. <td>
  121. <div class="d-flex">
  122. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  123. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  124. </div>
  125. </td><td>${att.username}</td></tr>`
  126. }
  127. $('#alllist-table').html(html);
  128. $('#alllist-table').on('click', 'tr', function() {
  129. $('#alllist-table tr').removeClass('bg-light')
  130. $(this).addClass('bg-light')
  131. })
  132. }
  133. // 生成当前节点列表
  134. function getNodeList(node) {
  135. let html = '';
  136. for(const att of attData) {
  137. if (node === att.lid) {
  138. // html += '<tr><td><a href="javascript:void(0)" file-id="'+ att.id +'">'+ att.filename + att.fileext +'</a></td><td>'+ att.username +'</td></tr>';
  139. html += `<tr>
  140. <td width="25"><input type="checkbox" class="check-file" file-id=${att.id}></td>
  141. <td>
  142. <div class="d-flex">
  143. <a href="javascript:void(0)" class="pl-0 col-11 att-file-name" file-id=${att.id}>${att.filename}${att.fileext}</a>
  144. <a href="/tender/${tender.id}/measure/stage/${stage.order}/download/file/${att.id}" class="col-1 pl-0 att-file-btn"><i class="fa fa-download"></i></a>
  145. </div>
  146. </td><td>${att.username}</td></tr>`
  147. }
  148. }
  149. $('#nodelist-table').html(html);
  150. $('#nodelist-table').on('click', 'tr', function() {
  151. $('#nodelist-table tr').removeClass('bg-light')
  152. $(this).addClass('bg-light')
  153. })
  154. }
  155. function getGxbyText(data) {
  156. const def = thirdParty.gxby.find(function (x) {
  157. return x.value === data.gxby_status;
  158. });
  159. return def ? def.name : '';
  160. }
  161. function getDaglText(data) {
  162. const def = thirdParty.dagl.find(function (x) {
  163. return x.value === data.dagl_status;
  164. });
  165. return def ? def.name : '';
  166. }
  167. function getHintMsg () {
  168. return {
  169. invalidExpr: {type: 'warning', msg: '粘贴了非法表达式,已过滤'},
  170. disableChange: {type: 'error', msg: '不可修改此数据'},
  171. }
  172. }
  173. $(document).ready(() => {
  174. const exportExcelSetting = {
  175. cols: [
  176. {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', cellType: 'tree'},
  177. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 70, formatter: '@'},
  178. {title: '计量单元', colSpan: '1', rowSpan: '2', field: 'pos_code', hAlign: 0, width: 70, formatter: '@'},
  179. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  180. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', cellType: 'unit'},
  181. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number'},
  182. {title: '台账|数量', colSpan: '2|1', rowSpan: '1|1', field: 'quantity', hAlign: 2, width: 60, type: 'Number'},
  183. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 60, type: 'Number'},
  184. {title: '本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  185. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'contract_tp', hAlign: 2, width: 60, type: 'Number'},
  186. {title: '本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'},
  187. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'qc_tp', hAlign: 2, width: 60, type: 'Number'},
  188. {title: '本期完成计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  189. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'gather_tp', hAlign: 2, width: 60, type: 'Number'},
  190. {title: '截止本期合同计量|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_contract_qty', hAlign: 2, width: 60, type: 'Number'},
  191. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_contract_tp', hAlign: 2, width: 60, type: 'Number'},
  192. {title: '截止本期数量变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'end_qc_qty', hAlign: 2, width: 60, type: 'Number'},
  193. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_qc_tp', hAlign: 2, width: 60, type: 'Number'},
  194. {title: '截止本期完成计量|数量', colSpan: '3|1', rowSpan: '1|1', field: 'end_gather_qty', hAlign: 2, width: 60, type: 'Number'},
  195. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'end_gather_tp', hAlign: 2, width: 60, type: 'Number'},
  196. {title: '|完成率(%)', colSpan: '|1', rowSpan: '|1', field: 'end_gather_percent', hAlign: 2, width: 80, type: 'Number'},
  197. {title: '合同|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'deal_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  198. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'deal_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  199. {title: '变更|项目节数量1', colSpan: '2|1', rowSpan: '1|1', field: 'c_dgn_qty1', hAlign: 2, width: 60, type: 'Number'},
  200. {title: '|项目节数量2', colSpan: '|1', rowSpan: '|1', field: 'c_dgn_qty2', hAlign: 2, width: 60, type: 'Number'},
  201. {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'final_dgn_price', hAlign: 2, width: 60, type: 'Number'},
  202. {title: '本期批注', colSpan: '1', rowSpan: '2', field: 'postil', hAlign: 0, width: 100, formatter: '@', cellType: 'autoTip'},
  203. {title: '图(册)号', colSpan: '1', rowSpan: '2', field: 'drawing_code', hAlign: 0, width: 80, formatter: '@'},
  204. {title: '备注', colSpan: '1', rowSpan: '2', field: 'memo', hAlign: 0, width: 100, formatter: '@', cellType: 'ellipsisAutoTip'},
  205. ],
  206. headRows: 2,
  207. headRowHeight: [25, 25],
  208. defaultRowHeight: 21,
  209. headerFont: 'bold 10px 微软雅黑',
  210. font: '10px 微软雅黑'
  211. };
  212. let detail, searchLedger, checkedChanges;
  213. const checkOption = {
  214. sibling: { enable: 0 },
  215. empty_code: { enable: 0 },
  216. calc: {
  217. enable: 1,
  218. fields: ['contract_qty', 'qc_qty'],
  219. },
  220. zero: { enable: 0 },
  221. tp: {
  222. enable: 1,
  223. fields: [
  224. {qty: 'contract_qty', tp: 'contract_tp'},
  225. {qty: 'qc_qty', tp: 'qc_tp'},
  226. ],
  227. filter: function (node) {
  228. return node.is_tp;
  229. }
  230. },
  231. over: {
  232. enable: 1, isTz: checkTzMeasureType(),
  233. },
  234. limit3f: {
  235. enable: 1, checkType: [],
  236. }
  237. };
  238. if (tender.s2b_gxby_check) checkOption.limit3f.checkType.push('gxby');
  239. if (tender.s2b_dagl_check) checkOption.limit3f.checkType.push('dagl');
  240. // 界面布局
  241. autoFlashHeight();
  242. // 初始化 台账树结构 数据结构
  243. removeLocalCache('bills-fold');
  244. const stageTreeSetting = {
  245. id: 'ledger_id',
  246. pid: 'ledger_pid',
  247. order: 'order',
  248. level: 'level',
  249. rootId: -1,
  250. keys: ['id', 'tender_id', 'ledger_id'],
  251. stageId: 'id',
  252. autoExpand: 3,
  253. // markFoldKey: 'bills-fold',
  254. // markFoldSubKey: window.location.pathname.split('/')[2],
  255. markExpandKey: 'stage-bills-expand',
  256. markExpandSubKey: window.location.pathname.split('/')[2],
  257. };
  258. // 台账树结构计算相关设置
  259. stageTreeSetting.updateFields = ['contract_qty', 'contract_tp', 'qc_qty', 'qc_tp', 'postil', 'used', 'contract_expr'];
  260. stageTreeSetting.calcFields = ['deal_tp', 'total_price', 'contract_tp', 'qc_tp', 'gather_tp',
  261. 'pre_contract_tp', 'pre_qc_tp', 'pre_gather_tp', 'end_contract_tp', 'end_qc_tp', 'end_gather_tp', 'end_correct_tp'];
  262. stageTreeSetting.calcFun = function (node) {
  263. if (!node.children || node.children.length === 0) {
  264. node.pre_gather_qty = ZhCalc.add(node.pre_contract_qty, node.pre_qc_qty);
  265. node.gather_qty = ZhCalc.add(node.contract_qty, node.qc_qty);
  266. node.end_contract_qty = ZhCalc.add(node.pre_contract_qty, node.contract_qty);
  267. node.end_qc_qty = ZhCalc.add(node.pre_qc_qty, node.qc_qty);
  268. node.end_gather_qty = ZhCalc.add(node.pre_gather_qty, node.gather_qty);
  269. }
  270. node.pre_gather_tp = ZhCalc.add(node.pre_contract_tp, node.pre_qc_tp);
  271. node.gather_tp = ZhCalc.add(node.contract_tp, node.qc_tp);
  272. node.end_contract_tp = ZhCalc.add(node.pre_contract_tp, node.contract_tp);
  273. node.end_qc_tp = ZhCalc.add(node.pre_qc_tp, node.qc_tp);
  274. node.end_gather_tp = ZhCalc.add(node.pre_gather_tp, node.gather_tp);
  275. node.end_final_tp = ZhCalc.add(node.end_qc_tp, node.total_price);
  276. if (!node.children || node.children.length === 0) {
  277. if (node.end_contract_qty) {
  278. node.end_correct_tp = ZhCalc.add(node.end_qc_tp, ZhCalc.mul(node.end_contract_qty, node.unit_price, tenderInfo.decimal.tp));
  279. } else {
  280. node.end_correct_tp = node.end_gather_tp;
  281. }
  282. }
  283. node.end_gather_percent = ZhCalc.mul(ZhCalc.div(node.end_gather_tp, node.end_final_tp), 100, 2);
  284. node.end_correct_percent = ZhCalc.mul(ZhCalc.div(node.end_correct_tp, node.end_final_tp), 100, 2);
  285. node.final_dgn_price = ZhCalc.round(ZhCalc.div(node.end_gather_tp, ZhCalc.add(node.deal_dgn_qty1, node.c_dgn_qty1)), tenderInfo.decimal.up);
  286. };
  287. const stageTree = createNewPathTree('stage', stageTreeSetting);
  288. // 初始化 计量单元 数据结构
  289. const stagePosSetting = {
  290. id: 'id', ledgerId: 'lid',
  291. updateFields: ['contract_qty', 'qc_qty', 'postil', 'contract_expr'],
  292. };
  293. stagePosSetting.calcFun = function (pos) {
  294. pos.pre_gather_qty = ZhCalc.add(pos.pre_contract_qty, pos.pre_qc_qty);
  295. pos.gather_qty = ZhCalc.add(pos.contract_qty, pos.qc_qty);
  296. pos.end_contract_qty = ZhCalc.add(pos.pre_contract_qty, pos.contract_qty);
  297. pos.end_qc_qty = ZhCalc.add(pos.pre_qc_qty, pos.qc_qty);
  298. pos.end_gather_qty = ZhCalc.add(pos.pre_gather_qty, pos.gather_qty);
  299. pos.sum = ZhCalc.add(pos.end_qc_qty, pos.quantity);
  300. pos.end_gather_percent = ZhCalc.mul(ZhCalc.div(pos.end_gather_qty, pos.sum), 100, 2);
  301. pos.estimate_qty = !checkZero(pos.real_qty)
  302. ? ZhCalc.sub(ZhCalc.sub(pos.real_qty, pos.quantity), pos.end_qc_qty)
  303. : null;
  304. };
  305. const stagePos = new StagePosData(stagePosSetting);
  306. const setCooperationSelectHtml = function () {
  307. const selectHtml = [];
  308. selectHtml.push('<option>全部</option>');
  309. const cooName = _.uniqWith(_.map(stageTree.pwd, 'company'));
  310. for (const i of cooName) {
  311. selectHtml.push('<option>', i, '</option>');
  312. }
  313. $('#cooperationSelect').html(selectHtml.join(''));
  314. };
  315. const reloadCooperationHtml = function () {
  316. const html = [];
  317. const select = $('#cooperationSelect').val();
  318. const list = select !== '全部' ? _.filter(stageTree.pwd, { company: select }) : stageTree.pwd;
  319. for (const p of list) {
  320. if (!p.node) continue;
  321. if (p.confirm) {
  322. html.push(`<tr class="text-success">`);
  323. } else {
  324. html.push(`<tr>`);
  325. }
  326. html.push(`<td>${p.node.code}</td>`, `<td>${p.node.name}</td>`);
  327. if(coopwd) {
  328. html.push('<td>', p.check ? `已解锁:${p.pwd}` : `<a name="ledger-unlock" lid="${p.ledger_id}" href="javascript: void(0);">解锁</a>`, '</td>');
  329. }
  330. html.push('<td>', p.company, '</td>');
  331. if (p.check && p.confirm) {
  332. html.push('<td>', moment(p.confirm_time).format('YYYY-MM-DD HH:mm') + ' ' + (coopwd ? `<a name="ledger-unconfirm" href="javascript: void(0);" lid="${p.ledger_id}">重新审批</a>` : ''), '</td>');
  333. } else if (!p.check && p.confirm) {
  334. html.push('<td>', moment(p.confirm_time).format('YYYY-MM-DD HH:mm'), '</td>');
  335. } else if (p.check && !p.confirm && coopwd) {
  336. html.push('<td>', `<a name="ledger-confirm" href="javascript: void(0);" lid="${p.ledger_id}" class="btn btn-sm btn-success">确认</a>`, '</td>');
  337. } else {
  338. html.push('<td>', '</td>');
  339. }
  340. // html.push('<td>', p.check ? (p.confirm ? (moment(p.confirm_time).format('YYYY-MM-DD HH:mm') + ' ' + (coopwd ? `<a name="ledger-unconfirm" href="javascript: void(0);" lid="${p.ledger_id}">重新审批</a>` : '')) : `<a name="ledger-confirm" href="javascript: void(0);" lid="${p.ledger_id}" class="btn btn-sm btn-success">确认</a>`) : '' ,'</td>');
  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. }
  1476. });
  1477. const stagePosSpreadObj = {
  1478. loadExprToInput(sheet) {
  1479. const sel = sheet.getSelections()[0];
  1480. if (!sel) return;
  1481. const col = sheet.zh_setting.cols[sel.col], cell = sheet.getCell(sel.row, sel.col);
  1482. if (col && col.type === 'Number') {
  1483. const data = SpreadJsObj.getSelectObject(sheet);
  1484. if (data) {
  1485. const exprInfo = getExprInfo(col.field);
  1486. const value = exprInfo && data[exprInfo.expr] ? data[exprInfo.expr] : data[col.field];
  1487. $('#pos-expr').val(value).attr('field', col.field).attr('org', data[col.field])
  1488. .attr('readOnly', readOnly || cell.locked());
  1489. $('#pos-expr').attr('data-row', sel.row);
  1490. } else {
  1491. $('#pos-expr').val('').attr('readOnly', true);
  1492. $('#pos-expr').removeAttr('data-row');
  1493. }
  1494. } else {
  1495. $('#pos-expr').val('').attr('readOnly', true);
  1496. $('#pos-expr').removeAttr('data-row');
  1497. }
  1498. },
  1499. /**
  1500. * 加载计量单元 根据当前台账选择节点
  1501. */
  1502. loadCurPosData: function () {
  1503. const sheet = slSpread.getActiveSheet();
  1504. const node = SpreadJsObj.getSelectObject(sheet);
  1505. if (node) {
  1506. spSpread.getActiveSheet().zh_setting.readOnly = node.lock;
  1507. const posData = stagePos.ledgerPos[itemsPre + node.id] || [];
  1508. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', posData);
  1509. getNodeList(node.id);
  1510. // 如果是附件是当前节点,隐藏
  1511. // if ($('#dqjiedian').hasClass('active')) {
  1512. // $('#showAttachment').hide();
  1513. // }
  1514. } else {
  1515. SpreadJsObj.loadSheetData(spSpread.getActiveSheet(), 'data', []);
  1516. }
  1517. stagePosSpreadObj.loadExprToInput(spSpread.getActiveSheet());
  1518. },
  1519. editEnded: function (e, info) {
  1520. if (info.sheet.zh_setting) {
  1521. // 未改变过,则直接跳过
  1522. const sortData = info.sheet.zh_data;
  1523. const posData = sortData ? sortData[info.row] : null;
  1524. const col = info.sheet.zh_setting.cols[info.col];
  1525. const orgText = posData ? posData[col.field] : null;
  1526. const newText = trimInvalidChar(info.editingText);
  1527. if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
  1528. return;
  1529. }
  1530. // 台账模式下,不可新增
  1531. if (checkTzMeasureType() && !posData) {
  1532. toastr.error('台账模式不可新增计量单元数据');
  1533. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1534. return ;
  1535. }
  1536. // 不同节点下,计量单元检查输入
  1537. //const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1538. const node = stagePosSpreadObj.stageTreeNode;
  1539. if (!node) {
  1540. toastr.warning('数据错误, 请刷新页面后再试');
  1541. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1542. return;
  1543. } else if (newText !== '' && node.children && node.children > 0) {
  1544. toastr.error('父节点不可插入计量单元');
  1545. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1546. return;
  1547. } else if (newText !== '' && !node.b_code || node.b_code === '') {
  1548. toastr.error('项目节不可插入计量单元');
  1549. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1550. return;
  1551. }
  1552. // 生成提交数据
  1553. const data = {};
  1554. if (col.field === 'name') {
  1555. if ((!newText || newText === '') && posData) {
  1556. toastr.error('部位名称不可为空');
  1557. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1558. return;
  1559. } else if (!posData) {
  1560. if (newText !== '') {
  1561. data.updateType = 'add';
  1562. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1563. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1564. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1565. return;
  1566. }
  1567. const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
  1568. data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
  1569. } else {
  1570. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1571. return;
  1572. }
  1573. } else {
  1574. data.updateType = 'update';
  1575. data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
  1576. }
  1577. } else if (!posData) {
  1578. toastr.warning('新增计量单元请先输入名称');
  1579. } else {
  1580. data.updateType = 'update';
  1581. data.updateData = {pid: posData.id, lid: posData.lid};
  1582. if (col.type === 'Number') {
  1583. const exprInfo = getExprInfo(col.field);
  1584. const num = _.toNumber(newText);
  1585. if (_.isFinite(num)) {
  1586. data.updateData[col.field] = num;
  1587. if (exprInfo) {
  1588. data.updateData[exprInfo.expr] = '';
  1589. }
  1590. } else {
  1591. try {
  1592. data.updateData[col.field] = math.evaluate(transExpr(newText));
  1593. if (exprInfo) {
  1594. data.updateData[exprInfo.expr] = newText;
  1595. }
  1596. } catch(err) {
  1597. toastr.error('输入的表达式非法');
  1598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1599. return;
  1600. }
  1601. }
  1602. } else {
  1603. data.updateData[col.field] = newText;
  1604. }
  1605. }
  1606. // 提交数据到服务器
  1607. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1608. if (result.pos) {
  1609. stagePos.updateDatas(result.pos.pos);
  1610. stagePos.loadCurStageData(result.pos.curStageData);
  1611. }
  1612. const refreshData = stageTree.loadPostStageData(result.ledger);
  1613. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1614. stagePosSpreadObj.loadCurPosData();
  1615. if (detail) {
  1616. detail.loadStagePosUpdateData(result, refreshData);
  1617. } else {
  1618. stageIm.loadUpdatePosData(result, refreshData);
  1619. }
  1620. }, function () {
  1621. stagePosSpreadObj.loadCurPosData();
  1622. });
  1623. }
  1624. },
  1625. editStarting: function (e, info) {
  1626. stagePosSpreadObj.stageTreeNode = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1627. const sel = info.sheet.getSelections();
  1628. if (!sel || !sel[0]) return;
  1629. const col = info.sheet.zh_setting.cols[sel[0].col];
  1630. const node = SpreadJsObj.getSelectObject(info.sheet);
  1631. const exprInfo = getExprInfo(col.field);
  1632. if (exprInfo) {
  1633. if (node[exprInfo.expr] && node[exprInfo.expr] !== '') {
  1634. info.sheet.getCell(info.row, info.col).text(node[exprInfo.expr]);
  1635. }
  1636. }
  1637. },
  1638. clipboardPasting: function (e, info) {
  1639. if (info.sheet.zh_setting) {
  1640. const sortData = info.sheet.zh_data;
  1641. const range = info.cellRange;
  1642. const validField = ['contract_qty', 'qc_qty', 'postil', 'real_qty'];
  1643. if (!checkTzMeasureType()) {
  1644. validField.push('name', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'position', 'drawing_code');
  1645. }
  1646. for (let iCol = range.col; iCol < range.col + range.colCount; iCol++) {
  1647. const col = info.sheet.zh_setting.cols[iCol];
  1648. if (validField.indexOf(col.field) === -1) {
  1649. if (checkTzMeasureType()) {
  1650. toastr.error('不可修改此数据');
  1651. info.cancel = true;
  1652. return;
  1653. } else {
  1654. for (let iRow = range.row; iRow < range.row + range.rowCount; iRow) {
  1655. const pos = sortData(iRow);
  1656. if (pos.add_stage !== stage.id || pos.add_times !== stage.times) {
  1657. toastr.error('不可修改此数据');
  1658. info.cancel = true;
  1659. return;
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. },
  1667. clipboardPasted: function (e, info) {
  1668. if (info.sheet.zh_setting) {
  1669. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  1670. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  1671. }
  1672. const data = { updateType: '', updateData: [], };
  1673. const sortData = info.sheet.zh_data;
  1674. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1675. if (sortData && (info.cellRange.row >= sortData.length)) {
  1676. data.updateType = 'add';
  1677. if (info.cellRange.col !== 0) {
  1678. toastr.warning('新增计量单元请先输入名称');
  1679. stagePosSpreadObj.loadCurPosData();
  1680. return;
  1681. }
  1682. if ((node.pre_used === 1 || !checkZero(node.gather_qty) || !checkZero(node.gather_tp)) && sortData.length === 0) {
  1683. toastr.error('无计量单元的清单,计量后,不可新增计量单元');
  1684. stagePosSpreadObj.loadCurPosData();
  1685. return;
  1686. }
  1687. const lastOrder = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1688. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1689. const curRow = info.cellRange.row + iRow;
  1690. const newData = {lid: node.id, porder: lastOrder + curRow - sortData.length};
  1691. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1692. const curCol = info.cellRange.col + iCol;
  1693. const colSetting = info.sheet.zh_setting.cols[curCol];
  1694. if (!colSetting) continue;
  1695. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1696. if (colSetting.type === 'Number') {
  1697. const exprInfo = getExprInfo(colSetting.field);
  1698. if (newValue) {
  1699. const num = _.toNumber(newValue);
  1700. if (num) {
  1701. newData[colSetting.field] = num;
  1702. if (exprInfo) {
  1703. newData[exprInfo.expr] = '';
  1704. }
  1705. } else {
  1706. try {
  1707. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1708. if (exprInfo) {
  1709. newData[exprInfo.expr] = newValue;
  1710. }
  1711. } catch(err) {
  1712. toastr.error('输入的表达式非法');
  1713. stagePosSpreadObj.loadCurPosData();
  1714. return;
  1715. }
  1716. }
  1717. } else {
  1718. newData[colSetting.field] = null;
  1719. if (exprInfo) newData[exprInfo.expr] = '';
  1720. }
  1721. } else {
  1722. newData[colSetting.field] = newValue;
  1723. }
  1724. }
  1725. data.updateData.push(newData);
  1726. }
  1727. } else {
  1728. data.updateType = 'update';
  1729. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  1730. const curRow = info.cellRange.row + iRow;
  1731. const curPos = sortData[curRow];
  1732. if (curPos) {
  1733. const newData = {pid: curPos.id, lid: curPos.lid};
  1734. for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
  1735. const curCol = info.cellRange.col + iCol;
  1736. const colSetting = info.sheet.zh_setting.cols[curCol];
  1737. const newValue = trimInvalidChar(info.sheet.getText(curRow, curCol));
  1738. if (colSetting.type === 'Number') {
  1739. const exprInfo = getExprInfo(colSetting.field);
  1740. if (!newValue) {
  1741. newData[colSetting.field] = newValue;
  1742. if (exprInfo) newData[exprInfo.expr] = '';
  1743. continue;
  1744. }
  1745. const num = _.toNumber(newValue);
  1746. if (num) {
  1747. newData[colSetting.field] = num;
  1748. if (exprInfo) newData[exprInfo.expr] = '';
  1749. } else {
  1750. try {
  1751. newData[colSetting.field] = math.evaluate(transExpr(newValue));
  1752. const exprInfo = getExprInfo(colSetting.field);
  1753. if (exprInfo) newData[exprInfo.expr] = newValue;
  1754. } catch(err) {
  1755. toastr.error('输入的表达式非法');
  1756. stagePosSpreadObj.loadCurPosData();
  1757. return;
  1758. }
  1759. }
  1760. } else {
  1761. newData[colSetting.field] = newValue;
  1762. }
  1763. }
  1764. data.updateData.push(newData);
  1765. }
  1766. }
  1767. }
  1768. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1769. if (result.pos) {
  1770. stagePos.updateDatas(result.pos.pos);
  1771. stagePos.loadCurStageData(result.pos.curStageData);
  1772. }
  1773. const nodes = stageTree.loadPostStageData(result.ledger);
  1774. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1775. stagePosSpreadObj.loadCurPosData();
  1776. if (detail) {
  1777. detail.loadStagePosUpdateData(result, nodes);
  1778. } else {
  1779. stageIm.loadUpdatePosData(result, nodes);
  1780. }
  1781. }, function () {
  1782. stagePosSpreadObj.loadCurPosData();
  1783. });
  1784. }
  1785. },
  1786. deletePress: function (sheet) {
  1787. if (sheet.zh_setting.readOnly) return;
  1788. if (sheet.zh_setting && sheet.zh_data) {
  1789. const sortData = sheet.zh_data;
  1790. if (!sortData || sortData.length === 0) { return; }
  1791. const sel = sheet.getSelections()[0];
  1792. const validCols = [];
  1793. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  1794. const colSetting = sheet.zh_setting.cols[iCol];
  1795. if (!colSetting.readOnly && colSetting.field !== 'qc_qty') {
  1796. validCols.push(iCol);
  1797. }
  1798. }
  1799. if (validCols.length === 0) { return; }
  1800. const datas = [], posSelects = [];
  1801. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  1802. const node = sortData[iRow];
  1803. if (node) {
  1804. const data = {pid: node.id, lid: node.lid};
  1805. for (const iCol of validCols) {
  1806. const colSetting = sheet.zh_setting.cols[iCol];
  1807. if (colSetting.field === 'name') {
  1808. toastr.error('部位名称不能为空');
  1809. return;
  1810. }
  1811. data[colSetting.field] = null;
  1812. const exprInfo = getExprInfo(colSetting.field);
  1813. if (exprInfo) {
  1814. data[exprInfo.expr] = '';
  1815. }
  1816. }
  1817. datas.push(data);
  1818. posSelects.push(node);
  1819. }
  1820. }
  1821. if (datas.length > 0) {
  1822. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: datas} }, function (result) {
  1823. if (result.pos) {
  1824. stagePos.updateDatas(result.pos.pos);
  1825. stagePos.loadCurStageData(result.pos.curStageData);
  1826. }
  1827. const nodes = stageTree.loadPostStageData(result.ledger);
  1828. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), nodes);
  1829. if (detail) {
  1830. detail.loadStagePosUpdateData(result, nodes);
  1831. } else {
  1832. stageIm.loadUpdatePosData(result, nodes);
  1833. }
  1834. // todo 只加载改变项
  1835. stagePosSpreadObj.loadCurPosData();
  1836. });
  1837. }
  1838. }
  1839. },
  1840. deletePos: function (sheet) {
  1841. const sels = sheet.getSelections();
  1842. const sel = sels ? sels[0] : null;
  1843. if (sheet.zh_data && sel) {
  1844. const data = {updateType: 'delete', updateData: []};
  1845. for (let iRow = 0; iRow < sel.rowCount; iRow++) {
  1846. const posData = sheet.zh_data[sel.row + iRow];
  1847. if (posData) {
  1848. data.updateData.push(posData.id);
  1849. }
  1850. }
  1851. if (data.updateData.length > 0) {
  1852. postData(window.location.pathname + '/update', {pos: data}, function (result) {
  1853. stagePos.removeDatas(result.pos.pos);
  1854. const refreshData = stageTree.loadPostStageData(result.ledger);
  1855. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1856. stagePosSpreadObj.loadCurPosData();
  1857. if (detail) {
  1858. detail.loadStagePosUpdateData(result, refreshData);
  1859. } else {
  1860. stageIm.loadUpdatePosData(result, refreshData);
  1861. }
  1862. });
  1863. }
  1864. }
  1865. },
  1866. selectionChanged: function (e, info) {
  1867. stagePosSpreadObj.loadExprToInput(info.sheet);
  1868. },
  1869. addPegs: function (pegs) {
  1870. if (!pegs || pegs.length <= 0) return;
  1871. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1872. if (!node) return;
  1873. const sheet = spSpread.getActiveSheet();
  1874. const sortData = sheet.zh_data || [];
  1875. let order = sortData.length > 0 ? sortData[sortData.length - 1].porder + 1 : 1;
  1876. pegs.forEach(function (p) {p.porder = ++order; p.lid = node.id});
  1877. postData(window.location.pathname + '/update', {pos: {updateType: 'add', updateData: pegs} }, function (result) {
  1878. if (result.pos) {
  1879. stagePos.updateDatas(result.pos.pos);
  1880. }
  1881. stagePosSpreadObj.loadCurPosData();
  1882. });
  1883. }
  1884. };
  1885. // 加载上下窗口resizer
  1886. $.divResizer({
  1887. select: '#main-resize',
  1888. callback: function () {
  1889. slSpread.refresh();
  1890. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1891. $(".sp-wrap").height(bcontent-30);
  1892. spSpread.refresh();
  1893. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  1894. }
  1895. });
  1896. // 加载计量单元数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  1897. postData(window.location.pathname + '/load', { filter: 'ledger;pos;detail;change;tag;cooperation' }, function (result) {
  1898. // 加载树结构
  1899. stageTree.loadDatas(result.ledgerData);
  1900. // stageTree.loadCurStageData(curStageData);
  1901. // stageTree.loadPreStageData(preStageData);
  1902. checkShowLast(result.ledgerData.length);
  1903. treeCalc.calculateAll(stageTree);
  1904. // 加载解锁相关
  1905. if (result.cooperation) {
  1906. stageTree.loadPwd(result.cooperation, 'bills-p-' + userID + '-' + window.location.pathname.split('/')[2], result.cooperationConfirm);
  1907. // stageTree.loadOnlinePwd(result.cooperation, result.cooperationPwd, result.cooperationConfirm);
  1908. $('#cooperationCount').html(stageTree.pwd.length || '');
  1909. if (stageTree.pwd.length > 0) $('#cooperationCount').parent().show();
  1910. setCooperationSelectHtml();
  1911. reloadCooperationHtml();
  1912. }
  1913. for (const t of result.tags) {
  1914. t.node = stageTree.datas.find(x => {return x.id === t.lid});
  1915. }
  1916. billsTag.loadDatas(result.tags);
  1917. // 加载部位明细
  1918. stagePos.loadDatas(result.posData);
  1919. stagePos.calculateAll();
  1920. SpreadJsObj.loadSheetData(slSpread.getActiveSheet(), 'tree', stageTree);
  1921. SpreadJsObj.loadTopAndSelect(slSpread.getActiveSheet(), ckBillsSpread);
  1922. stagePosSpreadObj.loadCurPosData();
  1923. SpreadJsObj.resetTopAndSelect(spSpread.getActiveSheet());
  1924. // 加载中间计量
  1925. stageIm.init(stage, imType, tenderInfo.decimal);
  1926. stageIm.loadData(result.ledgerData, result.posData, result.detailData, result.changeData);
  1927. errorList.loadHisErrorData();
  1928. checkList.loadHisCheckData();
  1929. }, null, true);
  1930. spSpread.bind(spreadNS.Events.EditEnded, stagePosSpreadObj.editEnded);
  1931. spSpread.bind(spreadNS.Events.ClipboardPasting, stagePosSpreadObj.clipboardPasting);
  1932. spSpread.bind(spreadNS.Events.ClipboardPasted, stagePosSpreadObj.clipboardPasted);
  1933. spSpread.bind(spreadNS.Events.EditStarting, stagePosSpreadObj.editStarting);
  1934. spSpread.bind(spreadNS.Events.SelectionChanged, stagePosSpreadObj.selectionChanged);
  1935. SpreadJsObj.addDeleteBind(spSpread, stagePosSpreadObj.deletePress);
  1936. if (!readOnly) {
  1937. $('#pos-expr').bind('change onblur', function () {
  1938. if (this.readOnly) return;
  1939. const expr = $(this);
  1940. const posSheet = spSpread.getActiveSheet();
  1941. const row = expr.attr('data-row') ? _.toInteger(expr.attr('data-row')) : -1;
  1942. const select = posSheet.zh_data ? posSheet.zh_data[row] : null;
  1943. if (!select) return;
  1944. const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
  1945. if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
  1946. const data = {pid: select.id, lid: select.lid};
  1947. const exprInfo = getExprInfo(field);
  1948. if (newValue !== '') {
  1949. const num = _.toNumber(newValue);
  1950. if (num) {
  1951. data[field] = num;
  1952. if (exprInfo) data[exprInfo.expr] = '';
  1953. } else {
  1954. try {
  1955. data[field] = math.evaluate(transExpr(newValue));
  1956. if (exprInfo) data[exprInfo.expr] = newValue;
  1957. } catch (err) {
  1958. toastr.error('输入的表达式非法');
  1959. return;
  1960. }
  1961. }
  1962. } else {
  1963. data[field] = null;
  1964. if (exprInfo) data[exprInfo.expr] = '';
  1965. }
  1966. // 提交数据到服务器
  1967. postData(window.location.pathname + '/update', {pos: {updateType: 'update', updateData: data}}, function (result) {
  1968. if (result.pos) {
  1969. stagePos.updateDatas(result.pos.pos);
  1970. stagePos.loadCurStageData(result.pos.curStageData);
  1971. SpreadJsObj.reLoadRowData(posSheet, _.toNumber(row));
  1972. }
  1973. const refreshData = stageTree.loadPostStageData(result.ledger);
  1974. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  1975. if (detail) {
  1976. detail.loadStagePosUpdateData(result, refreshData);
  1977. } else {
  1978. stageIm.loadUpdatePosData(result, refreshData);
  1979. }
  1980. });
  1981. });
  1982. }
  1983. const mergePeg = NewMergePeg({ callback: stagePosSpreadObj.addPegs});
  1984. $.contextMenu({
  1985. selector: '#stage-pos',
  1986. build: function ($trigger, e) {
  1987. const target = SpreadJsObj.safeRightClickSelection($trigger, e, spSpread);
  1988. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  1989. },
  1990. items: {
  1991. 'del': {
  1992. name: '删除',
  1993. icon: 'fa-remove',
  1994. visible: function (key, opt) {
  1995. return !checkTzMeasureType();
  1996. },
  1997. disabled: function (key, opt) {
  1998. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  1999. if (!node || node.lock) return true;
  2000. const sheet = spSpread.getActiveSheet();
  2001. if (sheet.zh_data && !readOnly) {
  2002. const selection = sheet.getSelections();
  2003. if (selection && selection[0]) {
  2004. let valid = sheet.zh_data.length < selection[0].row + selection[0].rowCount;
  2005. for (let iRow = 0; iRow < selection[0].rowCount; iRow++) {
  2006. const posData = sheet.zh_data[selection[0].row + iRow];
  2007. if (posData) {
  2008. if (posData.add_stage_order < stage.order || ZhCalc.isNonZero(posData.gather_qty) || ZhCalc.isNonZero(posData.end_gather_qty)) {
  2009. valid = true;
  2010. break;
  2011. }
  2012. } else {
  2013. valid = true;
  2014. break;
  2015. }
  2016. }
  2017. return valid;
  2018. } else {
  2019. return true;
  2020. }
  2021. } else {
  2022. return true;
  2023. }
  2024. },
  2025. callback: function (key, opt) {
  2026. stagePosSpreadObj.deletePos(spSpread.getActiveSheet());
  2027. }
  2028. },
  2029. 'merge-peg': {
  2030. name: '合并起讫桩号',
  2031. visible: function (key, opt) {
  2032. return !checkTzMeasureType();
  2033. },
  2034. disabled: function (key, opt) {
  2035. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2036. return _.isNil(node) || _.isNil(node.b_code) || node.b_code === '' || node.lock;
  2037. },
  2038. callback: function (key, opt) {
  2039. mergePeg.show();
  2040. }
  2041. },
  2042. 'calcByRatio': {
  2043. name: '按比例计量',
  2044. visible: function (key, opt) {
  2045. const data = spSpread.getActiveSheet().zh_data;
  2046. return data && data.length > 0;
  2047. },
  2048. disabled: function (key, opt) {
  2049. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  2050. return node.lock;
  2051. },
  2052. callback: function (key, opt) {
  2053. $('#cbr-ratio').val('');
  2054. $('#apply2sibling')[0].checked = false;
  2055. $('#cbr-check-all')[0].checked = false;
  2056. const html = [];
  2057. for (const [i, p] of spSpread.getActiveSheet().zh_data.entries()) {
  2058. html.push('<tr>');
  2059. html.push('<td>', i+1, '</td>');
  2060. html.push('<td>', p.name, '</td>');
  2061. html.push('<td>', p.quantity, '</td>');
  2062. html.push('<td><input type="checkbox" pos-name="' + p.name + '"></td></td>');
  2063. html.push('</tr>');
  2064. }
  2065. $('#cbr-pos-list').html(html.join(''));
  2066. $('#calc-by-ratio').modal('show');
  2067. }
  2068. }
  2069. }
  2070. });
  2071. $.subMenu({
  2072. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2073. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2074. key: 'menu.1.0.0',
  2075. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2076. callback: function (info) {
  2077. if (info.mini) {
  2078. $('.panel-title').addClass('fluid');
  2079. $('#sub-menu').removeClass('panel-sidebar');
  2080. } else {
  2081. $('.panel-title').removeClass('fluid');
  2082. $('#sub-menu').addClass('panel-sidebar');
  2083. }
  2084. autoFlashHeight();
  2085. slSpread.refresh();
  2086. spSpread.refresh();
  2087. if (searchLedger) {
  2088. searchLedger.spread.refresh();
  2089. }
  2090. if (detail) {
  2091. detail.spread.refresh();
  2092. }
  2093. if (checkedChanges) checkedChanges.refresh();
  2094. if (errorList && errorList.spread) {
  2095. errorList.spread.refresh();
  2096. }
  2097. if (checkList) {
  2098. checkList.spread.refresh();
  2099. }
  2100. }
  2101. });
  2102. $('#row-view').on('show.bs.modal', function () {
  2103. const html = [], customDisplay = customColDisplay();
  2104. for (const cd of customDisplay) {
  2105. html.push('<tr>');
  2106. html.push('<td>', cd.title, '</td>');
  2107. html.push('<td>', '<input type="checkbox"' + (cd.visible ? ' checked=""' : '') + '>', '</td>');
  2108. html.push('</tr>');
  2109. }
  2110. $('#row-view-list').html(html.join(''));
  2111. });
  2112. $('#row-view-ok').click(function () {
  2113. const customDisplay = customColDisplay();
  2114. const cvl = $('#row-view-list').children();
  2115. for (const cv of cvl) {
  2116. const title = $(cv).children()[0].innerHTML;
  2117. const check = $('input', cv)[0].checked;
  2118. const cd = customDisplay.find(function (c) {
  2119. return c.title === title;
  2120. });
  2121. cd.visible = check;
  2122. }
  2123. customizeStageTreeSetting(ledgerSpreadSetting, customDisplay);
  2124. SpreadJsObj.refreshColumnVisible(slSpread.getActiveSheet());
  2125. Cookies.set(ckColSetting, JSON.stringify(customDisplay), 30*24*60*60*1000);
  2126. $('#row-view').modal('hide');
  2127. });
  2128. const posSearch = (function () {
  2129. let resultArr = [];
  2130. const search = function () {
  2131. resultArr = [];
  2132. const keyword = $('#pos-search-keyword').val();
  2133. const checkOver = $('#pos-over-search')[0].checked;
  2134. const checkEmpty = $('#pos-empty-search')[0].checked;
  2135. const sortData = spSpread.getActiveSheet().zh_data;
  2136. if (checkOver || checkEmpty) {
  2137. if (sortData) {
  2138. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2139. const sd = sortData[i];
  2140. let match = false;
  2141. if (checkOver) {
  2142. if (sd.end_gather_qty) {
  2143. if (!sd.quantity || Math.abs(sd.end_gather_qty) > Math.abs(ZhCalc.add(sd.quantity, sd.end_qc_qty))) match = true;
  2144. }
  2145. }
  2146. if (checkEmpty) {
  2147. if (sd.quantity) {
  2148. if (!sd.end_gather_qty || ZhCalc.sub(ZhCalc.add(sd.quantity, sd.end_qc_qty), sd.end_gather_qty) > 0) match = true;
  2149. }
  2150. }
  2151. if (keyword && keyword !== '' && sd.name && sd.name.indexOf(keyword) === -1) match = false;
  2152. if (match) {
  2153. resultArr.push({index: i, data: sd});
  2154. }
  2155. }
  2156. }
  2157. } else if (keyword && keyword !== '') {
  2158. if (sortData) {
  2159. for (let i = 0, iLength = sortData.length; i < iLength; i++) {
  2160. const sd = sortData[i];
  2161. if (sd.name && sd.name.indexOf(keyword) > -1) {
  2162. resultArr.push({index: i, data: sd});
  2163. }
  2164. }
  2165. }
  2166. }
  2167. $('#pos-search-result').html('结果:' + resultArr.length);
  2168. };
  2169. const searchAndLocate = function () {
  2170. search();
  2171. if (resultArr.length > 0) {
  2172. const sheet = spSpread.getActiveSheet();
  2173. const sel = sheet.getSelections()[0];
  2174. const curRow = sel ? sel.row : 0;
  2175. const pos = resultArr[0];
  2176. if (pos.index !== curRow) {
  2177. sheet.setSelection(pos.index, sel ? sel.col : 0, 1, 1);
  2178. sheet.showRow(pos.index, spreadNS.VerticalPosition.center);
  2179. SpreadJsObj.reloadRowsBackColor(sheet, [pos.index, curRow]);
  2180. }
  2181. }
  2182. };
  2183. const locateNext = function () {
  2184. if (resultArr.length > 0) {
  2185. const sheet = spSpread.getActiveSheet();
  2186. const sel = sheet.getSelections()[0];
  2187. const curRow = sel ? sel.row : 0;
  2188. let next = _.find(resultArr, function (d) {
  2189. return d.index > curRow;
  2190. });
  2191. if (!next) next = resultArr[0];
  2192. if (next.index !== curRow) {
  2193. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2194. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2195. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2196. }
  2197. }
  2198. };
  2199. const locatePre = function () {
  2200. if (resultArr.length > 0) {
  2201. const sheet = spSpread.getActiveSheet();
  2202. const sel = sheet.getSelections()[0];
  2203. const curRow = sel ? sel.row : 0;
  2204. let next = _.findLast(resultArr, function (d) {
  2205. return d.index < curRow;
  2206. });
  2207. if (!next) next = resultArr[resultArr.length - 1];
  2208. if (next.index !== curRow) {
  2209. sheet.setSelection(next.index, sel ? sel.col : 0, 1, 1);
  2210. sheet.showRow(next.index, spreadNS.VerticalPosition.center);
  2211. SpreadJsObj.reloadRowsBackColor(sheet, [next.index, curRow]);
  2212. }
  2213. }
  2214. };
  2215. return {search, searchAndLocate, locateNext, locatePre};
  2216. })();
  2217. $('#pos-search-keyword').bind('keydown', function(e){
  2218. if (e.keyCode == 13) posSearch.searchAndLocate();
  2219. });
  2220. $('#pos-empty-search').click(function () {
  2221. if (this.checked) {
  2222. $('[for=' + this.id +']').addClass('text-warning');
  2223. } else {
  2224. $('[for=' + this.id +']').removeClass('text-warning');
  2225. }
  2226. if (this.checked) {
  2227. if ($('#pos-over-search')[0].checked) {
  2228. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2229. } else {
  2230. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2231. }
  2232. } else {
  2233. if ($('#pos-over-search')[0].checked) {
  2234. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2235. } else {
  2236. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2237. }
  2238. }
  2239. posSearch.searchAndLocate();
  2240. });
  2241. $('#pos-over-search').click(function () {
  2242. if (this.checked) {
  2243. $('[for=' + this.id +']').addClass('text-danger');
  2244. } else {
  2245. $('[for=' + this.id +']').removeClass('text-danger');
  2246. }
  2247. if (this.checked) {
  2248. if ($('#pos-empty-search')[0].checked) {
  2249. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2250. } else {
  2251. $('#pos-search-keyword').attr('placeholder', '超计中按名称查询');
  2252. }
  2253. } else {
  2254. if ($('#pos-empty-search')[0].checked) {
  2255. $('#pos-search-keyword').attr('placeholder', '漏计中按名称查询');
  2256. } else {
  2257. $('#pos-search-keyword').attr('placeholder', '按名称查询');
  2258. }
  2259. }
  2260. posSearch.searchAndLocate();
  2261. });
  2262. $('#pos-search-next').click(() => {posSearch.locateNext()});
  2263. $('#pos-search-pre').click(() => {posSearch.locatePre()});
  2264. $.divResizer({
  2265. select: '#right-spr',
  2266. callback: function () {
  2267. slSpread.refresh();
  2268. spSpread.refresh();
  2269. if (searchLedger) {
  2270. searchLedger.spread.refresh();
  2271. }
  2272. if (detail) {
  2273. detail.spread.refresh();
  2274. }
  2275. if (checkedChanges) checkedChanges.refresh();
  2276. if (errorList && errorList.spread) {
  2277. errorList.spread.refresh();
  2278. }
  2279. if (checkList) {
  2280. checkList.spread.refresh();
  2281. }
  2282. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2283. }
  2284. });
  2285. // 中间计量加载上下窗口resizer
  2286. $.divResizer({
  2287. select: '#zhongjian-spr',
  2288. callback: function () {
  2289. if (detail) {
  2290. detail.spread.refresh();
  2291. }
  2292. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  2293. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2294. }
  2295. });
  2296. // 附件加载上下窗口resizer
  2297. $.divResizer({
  2298. select: '#file-spr',
  2299. callback: function () {
  2300. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2301. }
  2302. });
  2303. // 变更令加载上下窗口resizer
  2304. $.divResizer({
  2305. select: '#change-spr',
  2306. callback: function () {
  2307. if (checkedChanges) checkedChanges.refresh();
  2308. window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
  2309. }
  2310. });
  2311. class Detail {
  2312. constructor (obj) {
  2313. const self = this;
  2314. this.spreadSetting = {
  2315. cols: [
  2316. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2317. {title: '中间计量表号', colSpan: '1', rowSpan: '1', field: 'im_code', hAlign: 0, width: 85, formatter: '@', readOnly: true},
  2318. {title: '交工证书/凭证号', colSpan: '1', rowSpan: '1', field: 'doc_code', hAlign: 0, width: 110, formatter: '@'},
  2319. {
  2320. title: stage.im_type === imType.tz.value ? '本期计量金额' : '本期计量数量',
  2321. colSpan: '1', rowSpan: '1', field: 'jl', hAlign: 2, width: 85, formatter: '@', readOnly: true
  2322. },
  2323. ],
  2324. headRows: 1,
  2325. emptyRows: 0,
  2326. headRowHeight: [32],
  2327. headColWidth: [30],
  2328. defaultRowHeight: 21,
  2329. headerFont: '12px 微软雅黑',
  2330. font: '12px 微软雅黑',
  2331. readOnly: readOnly,
  2332. selectedBackColor: '#fffacd',
  2333. };
  2334. this.spread = SpreadJsObj.createNewSpread(obj[0]);
  2335. this.sheet = this.spread.getActiveSheet();
  2336. this.spread.options.allowUserDragFill = true;
  2337. this.spread.options.defaultDragFillType = spreadNS.Fill.AutoFillType.fillSeries;
  2338. SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
  2339. this.detailObj = {
  2340. selectionChanged: function (e, info) {
  2341. self.reLoadDetailData();
  2342. if (!info.oldSelections || !info.oldSelections[0] || info.oldSelections[0].row !== info.newSelections[0].row) {
  2343. self.loadLocateInfo();
  2344. }
  2345. },
  2346. editEnded: function(e, info) {
  2347. if (info.sheet.zh_setting) {
  2348. const col = info.sheet.zh_setting.cols[info.col];
  2349. if (col.field !== 'doc_code') {
  2350. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2351. return;
  2352. }
  2353. const data = SpreadJsObj.getSelectObject(info.sheet);
  2354. if (data) {
  2355. const updateData = {lid: data.lid, pid: data.pid};
  2356. if (data.uuid) {
  2357. updateData.uuid = data.uuid;
  2358. } else {
  2359. updateData.code = data.code;
  2360. updateData.name = data.name;
  2361. updateData.unit = data.unit;
  2362. updateData.unit_price = data.unit_price;
  2363. updateData.pid = data.pid;
  2364. updateData.pos_name = data.pos_name;
  2365. }
  2366. if (data.custom_define.indexOf('doc_code') === -1) {
  2367. updateData.custom_define = data.custom_define;
  2368. updateData.custom_define.push('doc_code');
  2369. updateData.custom_define = updateData.custom_define.join(',');
  2370. }
  2371. updateData.doc_code = info.editingText === null ? '' : info.editingText;
  2372. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2373. stageIm.loadUpdateDetailData(result);
  2374. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2375. }, function () {
  2376. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2377. });
  2378. } else {
  2379. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  2380. }
  2381. }
  2382. },
  2383. clipboardPasted: function (e, info) {
  2384. if (info.sheet.zh_setting && info.sheet.zh_data) {
  2385. const col = info.sheet.zh_setting.cols[info.cellRange.col];
  2386. if (info.cellRange.colCount > 1) {
  2387. toastr.warning('请勿同时复制粘贴多列数据');
  2388. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2389. return;
  2390. }
  2391. if (col.field !== 'doc_code') {
  2392. SpreadJsObj.reLoadSheetData(paySpread.getActiveSheet());
  2393. return;
  2394. }
  2395. const datas = [];
  2396. for (let iRow = 0; iRow < info.cellRange.rowCount; iRow++) {
  2397. const curRow = info.cellRange.row + iRow;
  2398. const data = info.sheet.zh_data[curRow];
  2399. if (data) {
  2400. const updateData = {lid: data.lid, pid: data.pid};
  2401. if (data.uuid) {
  2402. updateData.uuid = data.uuid;
  2403. } else {
  2404. updateData.code = data.code;
  2405. updateData.name = data.name;
  2406. updateData.unit = data.unit;
  2407. updateData.unit_price = data.unit_price;
  2408. updateData.pid = data.pid;
  2409. updateData.pos_name = data.pos_name;
  2410. }
  2411. if (data.custom_define.indexOf('doc_code') === -1) {
  2412. updateData.custom_define = data.custom_define;
  2413. updateData.custom_define.push('doc_code');
  2414. updateData.custom_define = updateData.custom_define.join(',');
  2415. }
  2416. updateData.doc_code = info.sheet.getText(curRow, info.cellRange.col).replace('\n', '');
  2417. datas.push(updateData);
  2418. }
  2419. }
  2420. if (datas.length > 0) {
  2421. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2422. stageIm.loadUpdateDetailData(result);
  2423. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2424. }, function () {
  2425. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  2426. })
  2427. }
  2428. }
  2429. },
  2430. deletePress: function (sheet) {
  2431. if (sheet.zh_setting) {
  2432. const datas = [];
  2433. const sel = sheet.getSelections()[0];
  2434. for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {
  2435. const col = sheet.zh_setting.cols[iCol];
  2436. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  2437. const data = sheet.zh_data[iRow];
  2438. if (col.field === 'doc_code') {
  2439. const updateData = {lid: data.lid};
  2440. if (data.uuid) {
  2441. updateData.uuid = data.uuid;
  2442. updateData.doc_code = '';
  2443. datas.push(updateData);
  2444. }
  2445. }
  2446. }
  2447. }
  2448. if (datas.length > 0) {
  2449. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2450. stageIm.loadUpdateDetailData(result);
  2451. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2452. }, function () {
  2453. SpreadJsObj.reLoadRowData(sheet, sel.row, sel.rowCount);
  2454. });
  2455. }
  2456. }
  2457. },
  2458. dragFillBlock: function (e, info) {
  2459. info.cancel = true;
  2460. if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
  2461. const sel = info.sheet.getSelections()[0];
  2462. const col = info.sheet.zh_setting.cols[info.fillRange.col];
  2463. if (info.fillRange.colCount > 1 || !sel || col.field !== 'doc_code') return;
  2464. const text = info.sheet.getText(sel.row + sel.rowCount - 1, sel.col);
  2465. if (text === '') return;
  2466. const regRst = /(\d+)$/g.exec(text), datas = [];
  2467. for (let iRow = 0; iRow < info.fillRange.rowCount; iRow++) {
  2468. const curRow = info.fillRange.row + iRow;
  2469. const data = info.sheet.zh_data[curRow];
  2470. if (data) {
  2471. const updateData = {lid: data.lid};
  2472. if (data.uuid) {
  2473. updateData.uuid = data.uuid;
  2474. } else {
  2475. updateData.code = data.code;
  2476. updateData.name = data.name;
  2477. updateData.unit = data.unit;
  2478. updateData.unit_price = data.unit_price;
  2479. updateData.pid = data.pid;
  2480. updateData.pos_name = data.pos_name;
  2481. }
  2482. if (regRst) {
  2483. updateData.doc_code = text.substr(0, regRst.index) + (parseInt(regRst[0]) + iRow + 1);
  2484. } else {
  2485. updateData.doc_code = text.replace('\n', '');
  2486. }
  2487. if (data.custom_define.indexOf('doc_code') === -1) {
  2488. updateData.custom_define = data.custom_define;
  2489. updateData.custom_define.push('doc_code');
  2490. updateData.custom_define = updateData.custom_define.join(',');
  2491. }
  2492. datas.push(updateData);
  2493. }
  2494. }
  2495. if (datas.length > 0) {
  2496. postData(window.location.pathname + '/detail/save', datas, function (result) {
  2497. stageIm.loadUpdateDetailData(result);
  2498. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2499. }, function () {
  2500. SpreadJsObj.reLoadRowData(info.sheet, info.fillRange.row, info.fillRange.rowCount);
  2501. })
  2502. }
  2503. },
  2504. };
  2505. this.spread.bind(spreadNS.Events.SelectionChanged, this.detailObj.selectionChanged);
  2506. if (!readOnly) {
  2507. this.spread.bind(spreadNS.Events.EditEnded, this.detailObj.editEnded);
  2508. this.spread.bind(spreadNS.Events.ClipboardPasted, this.detailObj.clipboardPasted);
  2509. this.spread.bind(spreadNS.Events.DragFillBlock, this.detailObj.dragFillBlock);
  2510. SpreadJsObj.addDeleteBind(this.spread, this.detailObj.deletePress);
  2511. }
  2512. this._initImTypeSetRela();
  2513. this._initModifyDetail();
  2514. this._initLocateRela();
  2515. // 草图相关
  2516. this._initImageRela();
  2517. this.reBuildImData();
  2518. }
  2519. _initImTypeSetRela() {
  2520. const self = this;
  2521. const gatherConfirmPopover = {
  2522. reBind: function (obj, eventName, fun) {
  2523. obj.unbind(eventName);
  2524. obj.bind(eventName, fun);
  2525. },
  2526. check: function (pos, hint, okCallback) {
  2527. const confirmObj = $('#gather-confirm'), hintObj = $('#gather-confirm-hint');
  2528. const okObj = $('#gather-confirm-ok'), cancelObj = $('#gather-confirm-cancel');
  2529. this.reBind(cancelObj, 'click', function () {
  2530. confirmObj.hide();
  2531. });
  2532. this.reBind(okObj, 'click', function () {
  2533. okCallback();
  2534. confirmObj.hide();
  2535. });
  2536. hintObj.text(hint);
  2537. confirmObj.css("top", pos.y).css("left", pos.x).show();
  2538. }
  2539. };
  2540. this.gsTree = stageIm.getGsTree();
  2541. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2542. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2543. jlCol.title = '本期计量金额';
  2544. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2545. $('#type-title-contract').text('本期合同计量金额');
  2546. $('#type-title-qc').text('本期变更计量金额');
  2547. } else {
  2548. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2549. jlCol.title = '本期计量数量';
  2550. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2551. $('#type-title-contract').text('本期合同计量数量');
  2552. $('#type-title-qc').text('本期变更计量数量');
  2553. }
  2554. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2555. $('#show-jldy').parent().show();
  2556. $('#jldy').parent().show();
  2557. $('#show-xm-name').parent().hide();
  2558. $('#xm-name').parent().hide();
  2559. } else {
  2560. $('#show-jldy').parent().hide();
  2561. $('#jldy').parent().hide();
  2562. $('#show-xm-name').parent().show();
  2563. $('#xm-name').parent().show();
  2564. }
  2565. // 选择中间计量模式
  2566. $('div[name="im-type"]').click(function () {
  2567. function chooseType(obj) {
  2568. obj.style.cursor = 'default';
  2569. $(obj).children().addClass('text-primary');
  2570. $(obj).addClass('border-primary');
  2571. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2572. }
  2573. function validType(obj) {
  2574. obj.style.cursor = 'pointer';
  2575. $(obj).children().removeClass('text-primary');
  2576. $(obj).removeClass('border-primary');
  2577. $('i', obj).remove();
  2578. }
  2579. if (this.style.cursor === 'pointer') {
  2580. const typeArr = $('div[name="im-type"]');
  2581. for (const t of typeArr) {
  2582. if ($(t).attr('im-type') === $(this).attr('im-type')) {
  2583. chooseType(t);
  2584. } else {
  2585. validType(t)
  2586. }
  2587. }
  2588. }
  2589. });
  2590. $('#choose').on('show.bs.modal', function () {
  2591. function chooseType(obj) {
  2592. obj.style.cursor = 'default';
  2593. $(obj).children().addClass('text-primary');
  2594. $('i', obj).remove();
  2595. $('h5', obj).prepend('<i class="fa fa-check pull-right"></i>');
  2596. }
  2597. function validType(obj) {
  2598. obj.style.cursor = 'pointer';
  2599. $(obj).children().removeClass('text-primary');
  2600. $('i', obj).remove();
  2601. }
  2602. $('#im-pre').val(stage.im_pre ? stage.im_pre : '');
  2603. const typeArr = $('div[name="im-type"]');
  2604. for (const t of typeArr) {
  2605. if (parseInt($(t).attr('im-type')) === stage.im_type) {
  2606. chooseType(t);
  2607. } else {
  2608. validType(t)
  2609. }
  2610. }
  2611. });
  2612. // 提交 中间计量模式
  2613. $('#choose-ok').click(() => {
  2614. const chooseType = _.find($('div[name="im-type"]', '#im-type'), function (it) {
  2615. return it.style.cursor !== 'pointer';
  2616. });
  2617. const data = {
  2618. im_type: parseInt($(chooseType).attr('im-type')),
  2619. im_pre: $('#im-pre').val(),
  2620. };
  2621. postData(window.location.pathname + '/detail/build', data, function (result) {
  2622. stage.im_type = data.im_type;
  2623. stage.im_pre = data.im_pre;
  2624. if (stage.im_type === imType.tz.value || stage.im_type === imType.bb.value) {
  2625. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2626. jlCol.title = '本期计量金额';
  2627. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2628. $('#type-title-contract').text('本期合同计量金额');
  2629. $('#type-title-qc').text('本期变更计量金额');
  2630. } else {
  2631. const jlCol = self.spreadSetting.cols.find(function (x) {return x.field === 'jl'});
  2632. jlCol.title = '本期计量数量';
  2633. SpreadJsObj.reLoadSheetHeader(self.sheet);
  2634. $('#type-title-contract').text('本期合同计量数量');
  2635. $('#type-title-qc').text('本期变更计量数量');
  2636. }
  2637. if (stage.im_type === imType.bb.value || stage.im_type === imType.bw.value) {
  2638. $('#show-jldy').parent().show();
  2639. $('#jldy').parent().show();
  2640. $('#show-xm-name').parent().hide();
  2641. $('#xm-name').parent().hide();
  2642. } else {
  2643. $('#show-jldy').parent().hide();
  2644. $('#jldy').parent().hide();
  2645. $('#show-xm-name').parent().show();
  2646. $('#xm-name').parent().show();
  2647. }
  2648. // 加载生成数据
  2649. self.reBuildImData();
  2650. $('#choose').modal('hide');
  2651. });
  2652. });
  2653. // 显示树结构信息
  2654. $('#choose2').on('shown.bs.modal', function () {
  2655. if (!self.gsSpread) {
  2656. self.gsSpread = SpreadJsObj.createNewSpread($('#im-gather-spread')[0]);
  2657. const setting = {
  2658. cols: [
  2659. {title: '计量\n汇总', colSpan: '1', rowSpan: '1', field: 'check', hAlign: 1, width: 50, formatter: '@', readOnly: true, cellType: 'checkbox'},
  2660. {title: '项目节编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: true, cellType: 'tree'},
  2661. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'b_code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  2662. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 230, formatter: '@', readOnly: true},
  2663. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  2664. ],
  2665. headRows: 1,
  2666. emptyRows: 0,
  2667. headRowHeight: [32],
  2668. defaultRowHeight: 21,
  2669. headerFont: '12px 微软雅黑',
  2670. font: '12px 微软雅黑',
  2671. };
  2672. sjsSettingObj.setFxTreeStyle(setting, sjsSettingObj.FxTreeStyle.jz);
  2673. SpreadJsObj.initSheet(self.gsSpread.getActiveSheet(), setting);
  2674. self.gsSpread.bind(spreadNS.Events.ButtonClicked, function (e, info) {
  2675. function checkParent(node) {
  2676. const parent = self.gsTree.getParent(node);
  2677. if (parent) {
  2678. return parent.check ? parent.check : checkParent(parent);
  2679. } else {
  2680. return false;
  2681. }
  2682. }
  2683. function checkChildren(node) {
  2684. for (const child of node.children) {
  2685. if (child.check) {
  2686. return true;
  2687. } else if (checkChildren(child)) {
  2688. return true;
  2689. }
  2690. }
  2691. return false;
  2692. }
  2693. if (!$('#im-gather-check')[0].checked) { return; }
  2694. const sheet = info.sheet, cellType = sheet.getCellType(info.row, info.col);
  2695. if (cellType instanceof spreadNS.CellTypes.CheckBox) {
  2696. if (sheet.isEditing()) {
  2697. sheet.endEdit(true);
  2698. }
  2699. }
  2700. if (info.sheet.zh_setting) {
  2701. const col = info.sheet.zh_setting.cols[info.col];
  2702. if (col.field !== 'check') {
  2703. return;
  2704. }
  2705. const sortData = info.sheet.zh_dataType === 'tree' ? info.sheet.zh_tree.nodes : info.sheet.zh_data;
  2706. const node = sortData[info.row];
  2707. if (!node.check) {
  2708. if (checkParent(node)) {
  2709. const rect = info.sheet.getCellRect(info.row, info.col);
  2710. gatherConfirmPopover.check({
  2711. x: rect.x + rect.width / 2 + 25,
  2712. y: rect.y + rect.height / 2 + 3,
  2713. }, '父项已勾选,继续将取消父项勾选。', function () {
  2714. node.check = true;
  2715. const parents = self.gsTree.getFullPathNodes(self.gsTree.getParent(node).full_path);
  2716. const rows = [self.gsTree.nodes.indexOf(node)];
  2717. for (const p of parents) {
  2718. if (p.check) {
  2719. p.check = false;
  2720. rows.push(self.gsTree.nodes.indexOf(p));
  2721. }
  2722. }
  2723. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2724. });
  2725. } else if (checkChildren(node)) {
  2726. const rect = info.sheet.getCellRect(info.row, info.col);
  2727. gatherConfirmPopover.check({
  2728. x: rect.x + rect.width / 2 + 25,
  2729. y: rect.y + rect.height / 2 + 3,
  2730. }, '子项已勾选,继续将取消子项勾选。', function () {
  2731. node.check = true;
  2732. const posterity = self.gsTree.getPosterity(node);
  2733. const rows = [self.gsTree.nodes.indexOf(node)];
  2734. for (const p of posterity) {
  2735. if (p.check) {
  2736. rows.push(self.gsTree.nodes.indexOf(p));
  2737. p.check = false;
  2738. }
  2739. }
  2740. SpreadJsObj.reLoadRowsData(info.sheet, rows);
  2741. });
  2742. } else {
  2743. node.check = true;
  2744. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2745. }
  2746. } else {
  2747. node.check = false;
  2748. SpreadJsObj.reLoadRowsData(info.sheet, [self.gsTree.nodes.indexOf(node)]);
  2749. }
  2750. }
  2751. });
  2752. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2753. for (const node of self.gsTree.datas) {
  2754. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2755. }
  2756. SpreadJsObj.loadSheetData(self.gsSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, self.gsTree);
  2757. self.gsTree.expandByLevel(4);
  2758. SpreadJsObj.refreshTreeRowVisible(self.gsSpread.getActiveSheet());
  2759. SpreadJsObj.resetFieldReadOnly(self.gsSpread.getActiveSheet, 'check', !$('#im-gather-check')[0].checked);
  2760. } else {
  2761. const gatherNodes = stage.im_gather_node ? _.map(stage.im_gather_node.split(',')) : [];
  2762. for (const node of self.gsTree.datas) {
  2763. node.check = gatherNodes.indexOf(node.id + '') !== -1;
  2764. }
  2765. SpreadJsObj.reLoadColsData(self.gsSpread.getActiveSheet(), [0]);
  2766. }
  2767. });
  2768. // 提交 高级设置
  2769. $('#choose2-ok').click(() => {
  2770. if (!self.gsTree) { return; }
  2771. const nodes = [];
  2772. for (const node of self.gsTree.datas) {
  2773. if (node.check) {
  2774. nodes.push(node.id);
  2775. }
  2776. }
  2777. const data = {
  2778. im_gather: $('#im-gather-check')[0].checked,
  2779. im_gather_node: nodes.join(','),
  2780. };
  2781. postData(window.location.pathname + '/detail/adv', data, function (result) {
  2782. stage.im_gather = data.im_gather;
  2783. stage.im_gather_node = data.im_gather_node;
  2784. $('#choose2').modal('hide');
  2785. });
  2786. });
  2787. }
  2788. _initLocateRela() {
  2789. const self = this;
  2790. $('#im-locate2bills').click(function () {
  2791. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2792. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2793. if (select && select.source) {
  2794. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[curIndex-1].id, true);
  2795. stagePosSpreadObj.loadCurPosData();
  2796. }
  2797. });
  2798. $('#im-locate-pre').click(function () {
  2799. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2800. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2801. if (select && select.source) {
  2802. const targetIndex = math.max(curIndex-1, 1);
  2803. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2804. stagePosSpreadObj.loadCurPosData();
  2805. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2806. }
  2807. });
  2808. $('#im-locate-next').click(function () {
  2809. const curIndex = parseInt($('#im-locate-info')[0].innerText.split('/')[0]);
  2810. const select = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2811. if (select && select.source) {
  2812. const targetIndex = math.min(curIndex+1, select.source.length);
  2813. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), select.source[targetIndex-1].id, true);
  2814. stagePosSpreadObj.loadCurPosData();
  2815. $('#im-locate-info')[0].innerText = targetIndex + '/' + select.source.length;
  2816. }
  2817. });
  2818. }
  2819. _initModifyDetail() {
  2820. const self = this;
  2821. // 重置
  2822. $('#reset-detail-ok').click(function () {
  2823. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2824. if (!data.uuid) return;
  2825. const updateData = {
  2826. lid: data.lid, pid: data.pid,
  2827. uuid: data.uuid,
  2828. custom_define: [],
  2829. };
  2830. for (const f of data.custom_define) {
  2831. if (stageIm.resetFields.indexOf(f) >= 0) {
  2832. updateData[f] = null;
  2833. } else {
  2834. updateData.custom_define.push(f);
  2835. }
  2836. }
  2837. updateData.custom_define = updateData.custom_define.join(',');
  2838. $('#reset-detail-modal').modal('hide');
  2839. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2840. stageIm.loadUpdateDetailData(result);
  2841. self.reLoadDetailData();
  2842. });
  2843. });
  2844. // 编辑
  2845. $('#edit-detail').click(function () {
  2846. $(this).hide();
  2847. $('#save-detail').show();
  2848. $('#cancel-detail').show();
  2849. $('#detail-show').hide();
  2850. $('#detail-edit').show();
  2851. self.updateImageData = null;
  2852. });
  2853. // 保存
  2854. $('#save-detail').click(() => {
  2855. function check(field, obj, org, update) {
  2856. const newValue = obj.val();
  2857. if (!org[field]) {
  2858. if (newValue !== '') {
  2859. update[field] = newValue;
  2860. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2861. return true;
  2862. }
  2863. } else if (newValue !== org[field]){
  2864. update[field] = newValue;
  2865. if (data.custom_define.indexOf(field) === -1) update.custom_define.push(field);
  2866. return true;
  2867. }
  2868. return false;
  2869. }
  2870. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  2871. const updateData = {lid: data.lid, pid: data.pid};
  2872. if (data.uuid) {
  2873. updateData.uuid = data.uuid;
  2874. updateData.custom_define = data.custom_define;
  2875. } else {
  2876. updateData.code = data.code;
  2877. updateData.name = data.name;
  2878. updateData.unit = data.unit;
  2879. updateData.unit_price = data.unit_price;
  2880. updateData.pid = data.pid;
  2881. updateData.pos_name = data.pos_name;
  2882. updateData.custom_define = [];
  2883. }
  2884. let infoUpdate = false;
  2885. infoUpdate = check('bw', $('#bw-name'), data, updateData) || infoUpdate;
  2886. infoUpdate = check('peg', $('#peg'), data, updateData) || infoUpdate;
  2887. infoUpdate = check('xm', $('#xm-name'), data, updateData) || infoUpdate;
  2888. infoUpdate = check('position', $('#position'), data, updateData) || infoUpdate;
  2889. infoUpdate = check('jldy', $('#jldy'), data, updateData) || infoUpdate;
  2890. infoUpdate = check('drawing_code', $('#drawing-code'), data, updateData) || infoUpdate;
  2891. infoUpdate = check('calc_memo', $('#calc-memo'), data, updateData) || infoUpdate;
  2892. updateData.custom_define = updateData.custom_define.join(',');
  2893. if (infoUpdate) {
  2894. postData(window.location.pathname + '/detail/save', updateData, function (result) {
  2895. stageIm.loadUpdateDetailData(result);
  2896. self.reLoadDetailData();
  2897. if (!self.updateImageData) return;
  2898. if (!self.updateImageData.uuid) self.updateImageData.uuid = result.uuid;
  2899. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2900. stageIm.loadUpdateDetailData(result);
  2901. self.reLoadDetailData();
  2902. });
  2903. });
  2904. } else if (self.updateImageData) {
  2905. postData(window.location.pathname + '/detail/merge-img', self.updateImageData, function (result) {
  2906. stageIm.loadUpdateDetailData(result);
  2907. self.reLoadDetailData();
  2908. });
  2909. } else {
  2910. self.reLoadDetailData();
  2911. }
  2912. });
  2913. // 取消
  2914. $('#cancel-detail').click(() => {
  2915. self.reLoadDetailData();
  2916. });
  2917. }
  2918. _initImageRela() {
  2919. const self = this;
  2920. $('#edit-detail').click(function () {
  2921. loadImageItem();
  2922. });
  2923. function setdraggrable(){
  2924. $( ".img-item" ).draggable({ containment: "parent" },{stop: function( event, ui ) {
  2925. }}).resizable({ containment: "parent" },{ handles: 'n, e, s, w, ne, se, sw, nw' },{ maxWidth: parseFloat($('#imgwidth').val())},{maxHeight: parseFloat($('#imgheight').val())},{
  2926. stop: function( event, ui ) {
  2927. }
  2928. });
  2929. }
  2930. function upload(formData) {
  2931. if (formData.length < 1) {
  2932. return;
  2933. }
  2934. postDataWithFile(window.location.pathname + '/detail/add-img', formData, function (result) {
  2935. const html = [];
  2936. html.push('<div class="img-item">');
  2937. html.push('<div class="img-bar">');
  2938. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  2939. html.push('</div>');
  2940. html.push('<div class="focus" style="width:100%; height:100%"><img src="', '/' + result, '" id="draggable" style="width:100%; height:100%"></div>');
  2941. html.push('</div>');
  2942. $('.img-view').append(html.join(''));
  2943. $('.img-bar').click(removeImageItem);
  2944. setdraggrable();
  2945. $('#upload-img-file').val('');
  2946. });
  2947. }
  2948. function dragFile(e) {
  2949. var file = null,
  2950. data = e.dataTransfer.types;
  2951. for (var i = 0; i < data.length; i += 1) {
  2952. if (data[i] === 'Files') {
  2953. file = e.dataTransfer.files; //获取文件
  2954. break;
  2955. }
  2956. }
  2957. if (file && file[0].type.indexOf('image') !== -1) {
  2958. var formData = new FormData();
  2959. formData.append('file', file[0]); //上传单个文件的添加方式
  2960. upload(formData); //upload 异步上传
  2961. }
  2962. }
  2963. // 移动图片
  2964. const moveImageItem = function (ev) {
  2965. const item = this;
  2966. const view = $('.img-view')[0];
  2967. let oEvent = ev;
  2968. // 浏览器有一些图片的默认事件,这里要阻止
  2969. oEvent.preventDefault();
  2970. let disX = oEvent.clientX - item.offsetLeft;
  2971. let disY = oEvent.clientY - item.offsetTop;
  2972. view.onmousemove = function (ev) {
  2973. oEvent = ev;
  2974. oEvent.preventDefault();
  2975. let x = oEvent.clientX -disX;
  2976. let y = oEvent.clientY -disY;
  2977. // 图形移动的边界判断
  2978. x = x <= 0 ? 0 : x;
  2979. x = x >= view.offsetWidth - item.offsetWidth ? view.offsetWidth - item.offsetWidth : x;
  2980. y = y <= 0 ? 0 : y;
  2981. y = y >= view.offsetHeight - item.offsetHeight ? view.offsetHeight - item.offsetHeight : y;
  2982. item.style.left = x + 'px';
  2983. item.style.top = y + 'px';
  2984. };
  2985. // 图形移出父盒子取消移动事件,防止移动过快触发鼠标移出事件,导致鼠标弹起事件失效
  2986. view.onmouseleave = function () {
  2987. view.onmousemove = null;
  2988. view.onmouseup = null;
  2989. };
  2990. // 鼠标弹起后停止移动
  2991. view.onmouseup=function() {
  2992. view.onmousemove = null;
  2993. view.onmouseup = null;
  2994. };
  2995. };
  2996. const removeImageItem = function () {
  2997. $(this).parent().remove();
  2998. };
  2999. // 加载草图组成
  3000. const loadImageItem = function () {
  3001. self.updateImageData = null;
  3002. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3003. const items = data.calc_img_org ? JSON.parse(data.calc_img_org) : [];
  3004. const html = [];
  3005. for (const item of items) {
  3006. const itemStyle = 'top:' + item.top + ';' + 'left:' + item.left + ';' + 'width:' + item.width + ';' + 'height:' + item.height + ';';
  3007. html.push('<div class="img-item" style="' + itemStyle + '">');
  3008. html.push('<div class="img-bar">');
  3009. html.push('<a href="javascript: void(0);" class="text-danger" title="删除"><i class="fa fa-remove" style="font-size: 24px"></i></a>');
  3010. html.push('</div>');
  3011. html.push('<div class="focus" style="width:100%; height:100%"><img src="', item.src, '" id="draggable" style="width:100%; height:100%"></div>');
  3012. html.push('</div>');
  3013. }
  3014. $('.img-view').html(html.join(''));
  3015. $('.img-bar').click(removeImageItem);
  3016. setdraggrable();
  3017. };
  3018. // 上传图片
  3019. $('#upload-img').click(function () {
  3020. $('#upload-img-file').trigger('click');
  3021. });
  3022. // 拖拽上传
  3023. //拖拽上传文件
  3024. const dragbox = document.querySelector('#upload-img');
  3025. dragbox.addEventListener('dragover', function(e) {
  3026. e.preventDefault(); // 必须阻止默认事件
  3027. }, false);
  3028. dragbox.addEventListener('drop', function(e) {
  3029. e.preventDefault(); // 阻止默认事件
  3030. dragFile(e);
  3031. }, false);
  3032. //拖拽上传文件
  3033. const dragbox2 = document.querySelector('.img-view');
  3034. dragbox2.addEventListener('dragover', function(e) {
  3035. e.preventDefault(); // 必须阻止默认事件
  3036. }, false);
  3037. dragbox2.addEventListener('drop', function(e) {
  3038. e.preventDefault(); // 阻止默认事件
  3039. dragFile(e);
  3040. }, false);
  3041. // 粘贴上传
  3042. $(".img-view").on('paste', function(ev) {
  3043. let file = null;
  3044. const data = (event.clipboardData || window.clipboardData).items;
  3045. for (let i = 0; i < data.length; i += 1) {
  3046. if ((data[i].kind == 'file') && (data[i].type.match('^image/'))) {
  3047. file = data[i].getAsFile(); //读取图片文件
  3048. break;
  3049. }
  3050. }
  3051. if (file) {
  3052. const formData = new FormData();
  3053. formData.append('file', file); //上传单个文件的添加方式
  3054. upload(formData); //异步上传文件
  3055. }
  3056. });
  3057. $('#upload-img-file').change(function () {
  3058. const file = this.files[0];
  3059. const ext = file.name.toLowerCase().split('.').splice(-1)[0];
  3060. const imgStr = /(jpg|jpeg|png|bmp|BMP|JPG|PNG|JPEG)$/;
  3061. if (!imgStr.test(ext)) {
  3062. toastr.error('请上传正确的图片格式文件');
  3063. return
  3064. }
  3065. if ($(this).val()) {
  3066. const formData = new FormData();
  3067. formData.append('file', this.files[0]);
  3068. upload(formData);
  3069. }
  3070. });
  3071. // 保存草图修改结果
  3072. $('#edit-img-ok').click(function () {
  3073. // 记录上传的图片的信息
  3074. const items = $('.img-item');
  3075. const img_remark = $('#text-edit').val();
  3076. const data = SpreadJsObj.getSelectObject(self.spread.getActiveSheet());
  3077. if (items.length > 0) {
  3078. const itemInfo = [];
  3079. for (const item of items) {
  3080. const itemData = {
  3081. src: $('img', item).attr('src'),
  3082. left: item.style.left,
  3083. top: item.style.top,
  3084. width: item.style.width,
  3085. height: item.style.height,
  3086. };
  3087. itemInfo.push(itemData);
  3088. }
  3089. // 获取合并好的图片数据
  3090. const canvas = document.createElement('canvas');
  3091. const view = $('.img-view')[0];
  3092. canvas.height = view.clientHeight;
  3093. canvas.width = view.clientWidth;
  3094. const ctx = canvas.getContext('2d');
  3095. ctx.fillStyle = '#ffffff';
  3096. ctx.fillRect(0, 0, canvas.width, canvas.height);
  3097. for (const b of $('.img-item')) {
  3098. const pos = $(b).position();
  3099. const img = $('img', b)[0];
  3100. ctx.drawImage(img, pos.left, pos.top, img.width, img.height);
  3101. }
  3102. // 生成上传数据
  3103. const updateData = {updateType: 'update', lid: data.lid, pid: data.pid};
  3104. if (data.uuid) {
  3105. updateData.uuid = data.uuid;
  3106. } else {
  3107. updateData.code = data.code;
  3108. updateData.name = data.name;
  3109. updateData.unit = data.unit;
  3110. updateData.unit_price = data.unit_price;
  3111. updateData.pid = data.pid;
  3112. updateData.pos_name = data.pos_name;
  3113. }
  3114. updateData.img = canvas.toDataURL('image/png');
  3115. updateData.imgInfo = itemInfo;
  3116. updateData.calc_img_remark = img_remark;
  3117. self.updateImageData = updateData;
  3118. $('#calc-img').attr('src', updateData.img);
  3119. $('#view-calc-img').attr('src', updateData.img);
  3120. $('#show-calc-img').attr('src', updateData.img);
  3121. $('#view-calc-remark').text(img_remark);
  3122. $('#edit-img').modal('hide');
  3123. // updateImageData = updateData;
  3124. // $('#edit-img').modal('hide');
  3125. // postData(window.location.pathname + '/detail/merge-img', updateData, function (result) {
  3126. // stageIm.loadUpdateDetailData(result);
  3127. // data.calc_img = result.calc_img;
  3128. // data.calc_img_org = result.calc_img_org;
  3129. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3130. // $('#show-calc-img').attr('src', calcImgSrc);
  3131. // $('#calc-img').attr('src', calcImgSrc);
  3132. // $('#view-calc-img').attr('src', calcImgSrc);
  3133. // $('#edit-img').modal('hide');
  3134. // });
  3135. } else if (data.calc_img) {
  3136. self.updateImageData = {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid};
  3137. $('#show-calc-img').attr('src', '');
  3138. $('#calc-img').attr('src', '');
  3139. $('#view-calc-img').attr('src', '');
  3140. $('#view-calc-remark').val('');
  3141. $('#text-edit').val('');
  3142. $('#edit-img').modal('hide');
  3143. // postData(window.location.pathname + '/detail/merge-img', {updateType: 'clear', lid: data.lid, pid: data.pid, uuid: data.uuid}, function (result) {
  3144. // stageIm.loadUpdateDetailData(result);
  3145. // data.calc_img = result.calc_img;
  3146. // data.calc_img_org = result.calc_img_org;
  3147. // const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3148. // $('#show-calc-img').attr('src', calcImgSrc);
  3149. // $('#calc-img').attr('src', calcImgSrc);
  3150. // $('#view-calc-img').attr('src', calcImgSrc);
  3151. // $('#edit-img').modal('hide');
  3152. // });
  3153. } else {
  3154. self.updateImageData = null;
  3155. $('#show-calc-img').attr('src', '');
  3156. $('#calc-img').attr('src', '');
  3157. $('#view-calc-img').attr('src', '');
  3158. $('#view-calc-remark').val('');
  3159. $('#text-edit').val('');
  3160. $('#edit-img').modal('hide');
  3161. }
  3162. });
  3163. }
  3164. reBuildImData() {
  3165. const imData = stageIm.buildImData();
  3166. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3167. this.reLoadDetailData();
  3168. this.loadLocateInfo();
  3169. }
  3170. loadStageLedgerUpdateData(data, nodes) {
  3171. const imData = stageIm.loadUpdateLedgerData(data, nodes);
  3172. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3173. this.reLoadDetailData();
  3174. }
  3175. loadStagePosUpdateData(data, nodes) {
  3176. const imData = stageIm.loadUpdatePosData(data, nodes);
  3177. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3178. this.reLoadDetailData();
  3179. }
  3180. loadStageChangeUpdateData(data, nodes) {
  3181. const imData = stageIm.loadUpdateChangeData(data, nodes);
  3182. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, imData);
  3183. this.reLoadDetailData();
  3184. }
  3185. loadLocateInfo() {
  3186. const select = SpreadJsObj.getSelectObject(this.sheet);
  3187. if (select && select.source.length > 1) {
  3188. $('#im-locate2bills').next().show();
  3189. } else {
  3190. $('#im-locate2bills').next().hide();
  3191. }
  3192. $('#im-locate-info')[0].innerText = '1/' + (select ? select.source.length : '0');
  3193. }
  3194. reLoadDetailData() {
  3195. const data = SpreadJsObj.getSelectObject(this.spread.getActiveSheet());
  3196. $('#reset-detail').hide();
  3197. if (data) {
  3198. for (const f of data.custom_define) {
  3199. if (stageIm.resetFields.indexOf(f) >= 0) {
  3200. $('#reset-detail').show();
  3201. break;
  3202. }
  3203. }
  3204. $('#edit-detail').show();
  3205. $('#modify-img').show();
  3206. } else {
  3207. $('#edit-detail').hide();
  3208. $('#modify-img').hide();
  3209. }
  3210. $('#save-detail').hide();
  3211. $('#cancel-detail').hide();
  3212. $('#detail-show').show();
  3213. $('#detail-edit').hide();
  3214. const contractJl = data && data.contract_jl ? data.contract_jl : '';
  3215. $('#show-contract-jl').text(contractJl);
  3216. $('#contract-jl').val(contractJl);
  3217. const qcJl = data && data.qc_jl ? data.qc_jl : '';
  3218. $('#show-qc-jl').text(qcJl);
  3219. $('#qc-jl').val(qcJl);
  3220. const bglCode = data && data.bgl_code ? data.bgl_code : '';
  3221. $('#show-bgl-code').text(bglCode);
  3222. $('#bgl-code').val(bglCode);
  3223. const bglDrawingCode = data && data.bgl_drawing_code ? data.bgl_drawing_code : '';
  3224. $('#show-bgl-drawing-code').text(bglDrawingCode);
  3225. $('#bgl-drawing-code').val(bglDrawingCode);
  3226. const bwName = data && data.bw ? data.bw : '';
  3227. $('#show-bw-name').text(bwName);
  3228. $('#bw-name').val(bwName);
  3229. const position = data && data.position ? data.position : '';
  3230. $('#show-position').text(position);
  3231. $('#position').val(position);
  3232. const peg = data && data.peg ? data.peg : '';
  3233. $('#show-peg').text(peg);
  3234. $('#peg').val(peg);
  3235. const xmName = data && data.xm ? data.xm: '';
  3236. $('#show-xm-name').text(xmName);
  3237. $('#xm-name').val(xmName);
  3238. const jldy = data && data.jldy ? data.jldy: '';
  3239. $('#show-jldy').text(jldy);
  3240. $('#jldy').val(jldy);
  3241. const drawingCode = data && data.drawing_code ? data.drawing_code: '';
  3242. $('#show-drawing-code').text(drawingCode);
  3243. $('#drawing-code').val(drawingCode);
  3244. const calcMemo = data && data.calc_memo ? data.calc_memo: '';
  3245. $('#show-calc-memo').html(calcMemo.replace(/\n/g, '<br/>'));
  3246. $('#calc-memo').val(calcMemo);
  3247. const calcImgSrc = data && data.calc_img ? '/' + data.calc_img : '';
  3248. $('#show-calc-img').attr('src', calcImgSrc);
  3249. $('#calc-img').attr('src', calcImgSrc);
  3250. $('#view-calc-img').attr('src', calcImgSrc);
  3251. const calcImgRemark = data && data.calc_img_remark || '';
  3252. $('#view-calc-remark').val(calcImgRemark);
  3253. $("#view-calc-remark").attr('readonly', true);
  3254. // 处理 编辑 -> 添加草图中textarea多余的空格
  3255. $('#text-edit').val(calcImgRemark)
  3256. }
  3257. }
  3258. class CheckedChange {
  3259. constructor (setting) {
  3260. const self = this;
  3261. this.changeSpreadSetting = {
  3262. cols: [
  3263. {title: '变更令号', colSpan: '1', rowSpan: '1', field: 'p_code', hAlign: 0, width: 100, formatter: '@'},
  3264. {title: '变更名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 180, formatter: '@'},
  3265. {title: '金额', colSpan: '1', rowSpan: '1', field: 'total_price', hAlign: 2, width: 80, type: 'Number'},
  3266. {title: '批复文号', colSpan: '1', rowSpan: '1', field: 'w_code', hAlign: 0, width: 100, formatter: '@'},
  3267. ],
  3268. emptyRows: 0,
  3269. headRows: 1,
  3270. headRowHeight: [32],
  3271. headColWidth: [30],
  3272. defaultRowHeight: 21,
  3273. headerFont: '12px 微软雅黑',
  3274. font: '12px 微软雅黑',
  3275. readOnly: true,
  3276. };
  3277. this.changeSpread = SpreadJsObj.createNewSpread(setting.changeObj[0]);
  3278. this.changeSheet = this.changeSpread.getActiveSheet();
  3279. SpreadJsObj.initSheet(this.changeSheet, this.changeSpreadSetting);
  3280. const getTipText = function (data) {
  3281. if (!data) return '';
  3282. const tips = [];
  3283. if (data.xmj_dwgc) tips.push(data.xmj_dwgc);
  3284. if (data.xmj_fbgc) tips.push(data.xmj_fbgc);
  3285. if (data.xmj_fxgc) tips.push(data.xmj_fxgc);
  3286. if (data.xmj_jldy) tips.push(data.xmj_jldy);
  3287. return tips.join('-');
  3288. };
  3289. this.changeBillsSpreadSetting = {
  3290. cols: [
  3291. {title: '清单编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 80, formatter: '@', cellType: 'tip', getTip: getTipText},
  3292. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 150, type: 'Number', cellType: 'tip', getTip: getTipText},
  3293. {title: '单位', colSpan: '1', rowSpan: '1', field: 'unit', hAlign: 1, width: 50, formatter: '@', cellType: 'tip', getTip: getTipText},
  3294. {title: '单价', colSpan: '1', rowSpan: '1', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', cellType: 'tip', getTip: getTipText},
  3295. {title: '数量', colSpan: '1', rowSpan: '1', field: 'qty', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3296. {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 60, formatter: '@', cellType: 'tip', getTip: getTipText},
  3297. {title: '变更部位', colSpan: '1', rowSpan: '1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@', cellType: 'tip', getTip: getTipText},
  3298. ],
  3299. emptyRows: 0,
  3300. headRows: 1,
  3301. headRowHeight: [32],
  3302. defaultRowHeight: 21,
  3303. headerFont: '12px 微软雅黑',
  3304. font: '12px 微软雅黑',
  3305. readOnly: true
  3306. };
  3307. this.changeBillsSpread = SpreadJsObj.createNewSpread(setting.changeBillsObj[0]);
  3308. this.changeBillsSheet = this.changeBillsSpread.getActiveSheet();
  3309. SpreadJsObj.initSheet(this.changeBillsSheet, this.changeBillsSpreadSetting);
  3310. this.changeSheet.bind(spreadNS.Events.SelectionChanged, function (e, info) {
  3311. const change = SpreadJsObj.getSelectObject(self.changeSheet);
  3312. if (change.cid === self.curChangeId) { return; }
  3313. self.curChangeId = change.cid;
  3314. if (change.detail) {
  3315. self.loadChangeDetailData();
  3316. } else {
  3317. postData(window.location.pathname + '/change/detail', {cid: change.cid}, function (result) {
  3318. change.detail = result;
  3319. self.analyzeChange(change);
  3320. self.loadChangeDetailData();
  3321. });
  3322. }
  3323. });
  3324. this.changes = null;
  3325. this.reloadChangeData();
  3326. setting.reloadObj.click(function() {
  3327. self.reloadChangeData();
  3328. });
  3329. $.contextMenu({
  3330. selector: '#' + setting.changeBillsObj.attr('id'),
  3331. build: function ($trigger, e) {
  3332. const target = SpreadJsObj.safeRightClickSelection($trigger, e, self.changeBillsSpread);
  3333. return target.hitTestType === spreadNS.SheetArea.viewport || target.hitTestType === spreadNS.SheetArea.rowHeader;
  3334. },
  3335. items: {
  3336. 'locateZjjl': {
  3337. name: '定位至台账',
  3338. icon: 'fa-sign-in',
  3339. callback: function (key, opt) {
  3340. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3341. if (changeBills.gcl_id) {
  3342. const node = stageTree.nodes.find(x => {return x.id === changeBills.gcl_id});
  3343. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3344. stagePosSpreadObj.loadCurPosData();
  3345. } else {
  3346. const cb = {
  3347. b_code: changeBills.code || '',
  3348. name: changeBills.name || '',
  3349. unit: changeBills.unit || '',
  3350. unit_price: changeBills.unit_price || 0,
  3351. };
  3352. for (const node of stageTree.nodes) {
  3353. if (node.children && node.children.length > 0) continue;
  3354. const b = {
  3355. b_code: node.b_code || '',
  3356. name: node.name || '',
  3357. unit: node.unit || '',
  3358. unit_price: node.unit_price || 0,
  3359. };
  3360. if (_.isMatch(cb, b)) {
  3361. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), node.ledger_id);
  3362. stagePosSpreadObj.loadCurPosData();
  3363. return;
  3364. }
  3365. }
  3366. }
  3367. },
  3368. disabled: function (key, opt) {
  3369. const changeBills = SpreadJsObj.getSelectObject(self.changeBillsSheet);
  3370. return !changeBills;
  3371. }
  3372. },
  3373. }
  3374. });
  3375. }
  3376. loadChangeDetailData() {
  3377. const change = SpreadJsObj.getSelectObject(this.changeSheet);
  3378. if (change) {
  3379. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, change.bills);
  3380. } else {
  3381. SpreadJsObj.loadSheetData(this.changeBillsSheet, SpreadJsObj.DataType.Data, []);
  3382. }
  3383. }
  3384. refresh() {
  3385. this.changeSpread.refresh();
  3386. this.changeBillsSpread.refresh();
  3387. }
  3388. reloadChangeData() {
  3389. const self = this;
  3390. postData(window.location.pathname + '/change/data', null, function (result) {
  3391. self.changes = result.changes;
  3392. SpreadJsObj.loadSheetData(self.changeSheet, SpreadJsObj.DataType.Data, self.changes);
  3393. self.changeSheet.setSelection(0, 0, 1, 1);
  3394. if (self.changes.length > 0) self.analyzeChange(result.changes[0]);
  3395. self.curChangeId = self.changes.length > 0 ? self.changes[0].id : null;
  3396. self.loadChangeDetailData();
  3397. });
  3398. }
  3399. analyzeChange(change) {
  3400. change.bills = change.detail.bills;
  3401. for (const b of change.bills) {
  3402. const aub = change.detail.addUsedBills.find(function (x) {
  3403. return x.id === b.id;
  3404. });
  3405. if (aub) {
  3406. b.used_qty = aub.used_qty;
  3407. }
  3408. b.qty = _.toNumber(b.samount);
  3409. b.valid_qty = ZhCalc.sub(b.qty, b.used_qty);
  3410. b.tp = ZhCalc.round(ZhCalc.mul(b.qty, b.unit_price), tenderInfo.decimal.tp);
  3411. b.pos = _.filter(change.detail.curUsedBills, {cbid: b.id});
  3412. b.cur_qty = 0;
  3413. for (const p of b.pos) {
  3414. p.f_qty = p.p_qty ? p.p_qty : p.l_qty;
  3415. b.cur_qty = ZhCalc.add(b.cur_qty, p.qty);
  3416. }
  3417. }
  3418. }
  3419. }
  3420. // 展开收起附件
  3421. $('a', '.right-nav').bind('click', function () {
  3422. //const main = $('#main-view'), tool = $('#tools-view');
  3423. const tab = $(this), tabPanel = $(tab.attr('content'));
  3424. if (!tab.hasClass('active')) {
  3425. $('a', '.side-menu').removeClass('active');
  3426. $('.tab-content .tab-select-show').removeClass('active');
  3427. tab.addClass('active');
  3428. tabPanel.addClass('active');
  3429. showSideTools(tab.hasClass('active'));
  3430. if (tab.attr('content') === '#search' && !searchLedger) {
  3431. searchLedger = $.billsSearch({
  3432. selector: '#search',
  3433. searchSpread: slSpread,
  3434. searchRangeStr: '项目节编号/名称',
  3435. searchOver: true,
  3436. searchEmpty: true,
  3437. resultSpreadSetting: {
  3438. cols: [
  3439. {title: '项目节编号', field: 'code', hAlign: 0, width: 90, formatter: '@'},
  3440. {title: '清单编号', field: 'b_code', hAlign: 0, width: 80, formatter: '@'},
  3441. {title: '名称', field: 'name', width: 150, hAlign: 0, formatter: '@'},
  3442. {title: '单位', field: 'unit', width: 50, hAlign: 1, formatter: '@'},
  3443. {title: '单价', field: 'unit_price', hAlign: 2, width: 50},
  3444. {title: '数量', field: 'quantity', hAlign: 2, width: 50},
  3445. {title: '完成率(%)', field: 'complete_percent', hAlign: 2, width: 70},
  3446. ],
  3447. emptyRows: 0,
  3448. headRows: 1,
  3449. headRowHeight: [32],
  3450. headColWidth: [30],
  3451. defaultRowHeight: 21,
  3452. headerFont: '12px 微软雅黑',
  3453. font: '12px 微软雅黑',
  3454. selectedBackColor: '#fffacd',
  3455. },
  3456. afterLocated: function () {
  3457. stagePosSpreadObj.loadCurPosData();
  3458. },
  3459. customSearch: [
  3460. {
  3461. key: 'less', title: '漏计', valid: true,
  3462. check: function (node) {
  3463. if (node.quantity) {
  3464. return ZhCalc.sub(ZhCalc.add(node.quantity, node.end_qc_qty), node.end_gather_qty) > 0;
  3465. } else if (node.total_price) {
  3466. return ZhCalc.sub(ZhCalc.add(node.total_price, node.end_qc_tp), node.end_gather_tp) > 0;
  3467. }
  3468. }
  3469. }, {
  3470. key: 'over', title: '超计', valid: true,
  3471. check: function (node) {
  3472. return checkUtils.billsOver(node, checkTzMeasureType(), stagePos);
  3473. }
  3474. }, {
  3475. key: 'empty', title: '漏计', valid: false,
  3476. check: function (node) {
  3477. if (node.quantity) {
  3478. return !node.end_gather_qty || checkZero(node.end_gather_qty);
  3479. } else if (node.total_price) {
  3480. return !node.end_gather_tp || checkZero(node.end_gather_tp);
  3481. }
  3482. }
  3483. }, {
  3484. key: 'estimate', title: '预计变更', valid: true,
  3485. check: function (node) {
  3486. const posRange = stagePos.ledgerPos[itemsPre + node.id] || [];
  3487. if (posRange.length > 0) {
  3488. for (const p of posRange) {
  3489. if (!checkZero(p.estimate_qty)) return true;
  3490. }
  3491. return false;
  3492. } else {
  3493. return false;
  3494. }
  3495. }
  3496. }
  3497. ],
  3498. });
  3499. searchLedger.spread.refresh();
  3500. }
  3501. if (tab.attr('content') === '#fujian') {
  3502. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3503. getNodeList(node.id);
  3504. }
  3505. if (tab.attr('content') === '#zhongjian') {
  3506. if (!detail) {
  3507. detail = new Detail($('#detail-spread'));
  3508. detail.spread.refresh();
  3509. $('#zhongjian .sjs-bottom').height('400px');
  3510. $('.zhongjian-msg').height($('#zhongjian .sjs-bottom').height());
  3511. } else {
  3512. detail.spread.refresh();
  3513. }
  3514. }
  3515. if (tab.attr('content') === '#checked-change') {
  3516. if (!checkedChanges) {
  3517. checkedChanges = new CheckedChange({
  3518. changeObj: $('#cc-spread'),
  3519. changeBillsObj: $('#ccb-spread'),
  3520. reloadObj: $('#refresh-cc'),
  3521. });
  3522. checkedChanges.refresh();
  3523. } else {
  3524. $('#ccb-spread').height('400px');
  3525. checkedChanges.refresh();
  3526. }
  3527. }
  3528. if (tab.attr('content') === '#error-list') {
  3529. errorList.spread.refresh();
  3530. }
  3531. if (tab.attr('content') === '#check-list') {
  3532. checkList.spread.refresh();
  3533. }
  3534. } else {
  3535. tab.removeClass('active');
  3536. tabPanel.removeClass('active');
  3537. showSideTools(tab.hasClass('active'));
  3538. }
  3539. slSpread.refresh();
  3540. spSpread.refresh();
  3541. });
  3542. // 切换附件里节点和所有附件
  3543. $('#fujian .nav-link').on('click', function () {
  3544. const tabPanel = $(this).attr('fujian-content');
  3545. if (tabPanel !== 'syfujian') {
  3546. $('#showPage').hide();
  3547. $('#bach-download').prop('type', 'curr');
  3548. } else {
  3549. $('#showPage').show();
  3550. $('#bach-download').prop('type', 'all')
  3551. }
  3552. $('#showAttachment').hide();
  3553. });
  3554. // 上传附件
  3555. $('#upload-file-btn').click(function () {
  3556. // if (curAuditor && curAuditor.aid !== cur_uid) {
  3557. // return toastr.error('当前操作没有权限!');
  3558. // }
  3559. const files = $('#upload-file')[0].files;
  3560. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3561. const formData = new FormData();
  3562. formData.append('lid', node.id);
  3563. for (const file of files) {
  3564. if (file === undefined) {
  3565. toastr.error('未选择上传文件!');
  3566. return false;
  3567. }
  3568. const filesize = file.size;
  3569. if (filesize > 30 * 1024 * 1024) {
  3570. toastr.error('存在上传文件大小过大!');
  3571. return false;
  3572. }
  3573. const fileext = '.' + file.name.toLowerCase().split('.').splice(-1)[0];
  3574. if (whiteList.indexOf(fileext) === -1) {
  3575. toastr.error('只能上传指定格式的附件!');
  3576. return false;
  3577. }
  3578. formData.append('size', filesize);
  3579. formData.append('file[]', file);
  3580. }
  3581. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/upload/file', formData, function (data) {
  3582. $('#upload').modal('hide');
  3583. // 插入到attData中
  3584. attData = data.concat(attData);
  3585. // 重新生成List
  3586. getAllList();
  3587. getNodeList(node.id);
  3588. }, function () {
  3589. toastr.error('附件上传失败');
  3590. });
  3591. $('#upload-file').val('');
  3592. });
  3593. // 获取附件信息
  3594. $('.list-table').on('click', '.att-file-name', function () {
  3595. const fid = $(this).attr('file-id');
  3596. if ($('#showAttachment').attr('file-id') === fid && !$('#showAttachment').is(":hidden")) {
  3597. return;
  3598. }
  3599. const att = attData.find(function (item) {
  3600. return item.id === parseInt(fid);
  3601. });
  3602. $('#edit-att').hide();
  3603. $('#show-att').show();
  3604. if (att !== undefined) {
  3605. // 进来先把编辑功能隐藏
  3606. $('#btn-att a').eq(3).hide()
  3607. $('#show-att tr').eq(0).children('td').text(att.filename + att.fileext);
  3608. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3609. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + att.lname));
  3610. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + att.id);
  3611. // $('#show-att tr').eq(2).find('a').attr('href', att.filepath);
  3612. $('#show-att tr').eq(2).children('td').eq(0).text(att.username);
  3613. $('#show-att tr').eq(2).children('td').eq(1).text(att.in_time);
  3614. $('#show-att tr').eq(3).children('td').text(att.remark);
  3615. // 附件uid等于当前用户id, 附件上传本人
  3616. if (parseInt(cur_uid) === att.uid) {
  3617. $('#btn-att').show();
  3618. const showDel = stage.status === auditConst.status.checked ? Boolean(att.extra_upload) : true;
  3619. // if (!curAuditor) {
  3620. // stage.status === auditConst.status.checked && parseInt(att.re_upload) && (showDel = true)
  3621. // stage.status === auditConst.status.uncheck && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3622. // stage.status === auditConst.status.checkNo && parseInt(cur_uid) === stage.user_id && (showDel = true)
  3623. // } else {
  3624. // curAuditor.aid === parseInt(cur_uid) && (showDel = true)
  3625. // }
  3626. if (showDel) $('#btn-att a').eq(3).show();
  3627. // $('#btn-att a').eq(3).show();
  3628. $('#btn-att a').eq(2).hide();
  3629. $('#btn-att a').eq(4).hide();
  3630. $('#btn-att a').eq(5).hide();
  3631. } else {
  3632. $('#btn-att').hide();
  3633. $('#btn-att a').eq(3).hide();
  3634. $('#btn-att a').eq(2).hide();
  3635. $('#btn-att a').eq(4).hide();
  3636. $('#btn-att a').eq(5).hide();
  3637. }
  3638. $('#showAttachment').attr('file-id', fid);
  3639. $('#showAttachment').show();
  3640. } else {
  3641. $('#showAttachment').hide();
  3642. $('#showAttachment').attr('file-id', '');
  3643. toastr.error('附件信息获取失败');
  3644. }
  3645. });
  3646. // $('body').on('click', '.alllist-table a', handleFileList);
  3647. $('body').on('click', '#btn-att a', function () {
  3648. const content = $(this).attr('content');
  3649. const fid = $('#showAttachment').attr('file-id');
  3650. const node = SpreadJsObj.getSelectObject(slSpread.getActiveSheet());
  3651. if (content === 'edit') {
  3652. $('#btn-att a').eq(3).hide();
  3653. $('#btn-att a').eq(2).show();
  3654. $('#btn-att a').eq(4).show();
  3655. $('#btn-att a').eq(5).show();
  3656. $('#show-att').hide();
  3657. $('#edit-att').show();
  3658. const att = attData.find(function (item) {
  3659. return item.id === parseInt(fid);
  3660. });
  3661. $('#edit-att .form-group').eq(0).find('input').val(att.filename);
  3662. $('#edit-att .form-group').eq(0).find('span').eq(1).text(att.fileext);
  3663. const name = att.code !== null && att.code !== '' ? att.code : (att.b_code !== null ? att.b_code : '');
  3664. $('#edit-att .form-group').eq(1).find('input').val($.trim(name + ' ' + att.lname));
  3665. $('#edit-att .form-group').eq(2).find('input').val(att.in_time);
  3666. $('#edit-att .form-group').eq(3).find('input').val(att.remark);
  3667. } else if (content === 'cancel') {
  3668. $('#show-att').show();
  3669. $('#edit-att').hide();
  3670. $('#btn-att a').eq(3).show();
  3671. $('#btn-att a').eq(2).hide();
  3672. $('#btn-att a').eq(4).hide();
  3673. $('#btn-att a').eq(5).hide();
  3674. } else if (content === 'save') {
  3675. const formData = new FormData();
  3676. formData.append('id', fid);
  3677. formData.append('filename', $('#edit-att .form-group').eq(0).find('input').val());
  3678. formData.append('fileext', $('#edit-att .form-group').eq(0).find('span').eq(1).text());
  3679. formData.append('remark', $('#edit-att .form-group').eq(3).find('input').val());
  3680. const file = $('#change-att-btn')[0];
  3681. if (file.files[0] !== undefined) {
  3682. const filesize = file.files[0].size;
  3683. formData.append('size', filesize);
  3684. formData.append('file', file.files[0]);
  3685. }
  3686. postDataWithFile('/tender/' + tender.id + '/measure/stage/' + stage.order + '/save/file', formData, function (data) {
  3687. // 替换到attData中
  3688. const att_index = attData.findIndex(function (item) {
  3689. return item.id === parseInt(fid);
  3690. });
  3691. attData.splice(att_index, 1, data);
  3692. // 重新生成List
  3693. getAllList(parseInt($('#currentPage').text()));
  3694. getNodeList(node.id);
  3695. $('#show-att').show();
  3696. $('#edit-att').hide();
  3697. $('#show-att tr').eq(0).children('td').text(data.filename + data.fileext);
  3698. const name = data.code !== null && data.code !== '' ? data.code : (data.b_code !== null ? data.b_code : '');
  3699. $('#show-att tr').eq(1).children('td').text($.trim(name + ' ' + data.lname));
  3700. // $('#show-att tr').eq(2).find('a').attr('href', '/tender/' + tender.id + '/measure/stage/' + stage.order + '/download/file/' + data.id);
  3701. $('#show-att tr').eq(3).children('td').eq(0).text(data.username);
  3702. $('#show-att tr').eq(3).children('td').eq(1).text(data.in_time);
  3703. $('#show-att tr').eq(4).children('td').text(data.remark);
  3704. $('#btn-att a').eq(3).show();
  3705. $('#btn-att a').eq(2).hide();
  3706. $('#btn-att a').eq(4).hide();
  3707. $('#btn-att a').eq(5).hide();
  3708. }, function () {
  3709. toastr.error('附件上传失败');
  3710. });
  3711. $('#change-att-btn').val('');
  3712. } else if (content === 'del') {
  3713. const data = {id: fid};
  3714. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/delete/file', data, function (result) {
  3715. // 删除到attData中
  3716. const att_index = attData.findIndex(function (item) {
  3717. return item.id === parseInt(fid);
  3718. });
  3719. attData.splice(att_index, 1);
  3720. // 重新生成List
  3721. if ($('#alllist-table tr').length === 1) {
  3722. getAllList(parseInt($('#currentPage').text()) - 1);
  3723. } else {
  3724. getAllList(parseInt($('#currentPage').text()));
  3725. }
  3726. getNodeList(node.id);
  3727. $('#showAttachment').hide();
  3728. $('#showAttachment').attr('file-id', '');
  3729. });
  3730. } else if (content === 'view') {
  3731. const data = {id: fid};
  3732. postData('/tender/' + tender.id + '/measure/stage/' + stage.order + '/check/file', data, function (result) {
  3733. const { filepath } = result
  3734. $('#load-file').attr('href', filepath);
  3735. $('#load-file')[0].click();
  3736. // $('#show-att tr').eq(2).find('a').attr('href', filepath)
  3737. // $('#show-att tr').eq(2).find('a').children('span').eq(0).trigger('click')
  3738. });
  3739. } else if (content === 'location') {
  3740. const att = attData.find(item => item.id === parseInt(fid));
  3741. if (Object.keys(att).length) {
  3742. SpreadJsObj.locateTreeNode(slSpread.getActiveSheet(), att.ledger_id, true);
  3743. stagePosSpreadObj.loadCurPosData();
  3744. }
  3745. }
  3746. });
  3747. // 替换附件
  3748. $('#change-att-btn').on('change', function () {
  3749. const file = $('#change-att-btn')[0].files[0];
  3750. const name = file.name;
  3751. const filename = name.substring(0, name.lastIndexOf("."));
  3752. const fileext = name.substr(name.indexOf("."));
  3753. const filesize = file.size;
  3754. if (filesize > 10 * 1024 * 1024) {
  3755. toastr.error('文件大小过大!');
  3756. $('#change-att-btn').val('');
  3757. return false;
  3758. }
  3759. if (whiteList.indexOf(fileext) === -1) {
  3760. toastr.error('只能上传指定格式的附件!');
  3761. $('#change-att-btn').val('');
  3762. return false;
  3763. }
  3764. $('#edit-att .form-group').eq(0).find('input').val(filename);
  3765. $('#edit-att .form-group').eq(0).find('span').eq(1).text(fileext);
  3766. });
  3767. // 切换页数
  3768. $('.page-select').on('click', function () {
  3769. const totalPageNum = parseInt($('#totalPage').text());
  3770. const lastPageNum = parseInt($('#currentPage').text());
  3771. const status = $(this).attr('content');
  3772. if (status === 'pre' && lastPageNum > 1) {
  3773. getAllList(lastPageNum-1);
  3774. $('#showAttachment').hide();
  3775. $('#syfujian .check-all-file').prop('checked', false)
  3776. } else if (status === 'next' && lastPageNum < totalPageNum) {
  3777. getAllList(lastPageNum+1);
  3778. $('#showAttachment').hide();
  3779. $('#syfujian .check-all-file').prop('checked', false)
  3780. }
  3781. });
  3782. // 批量下载
  3783. $('#bach-download').click(function() {
  3784. const fileIds = [];
  3785. const type = $(this).prop('type');
  3786. let node = ''
  3787. if (type === 'curr') {
  3788. node = '#nodelist-table .check-file:checked'
  3789. } else {
  3790. node = '#alllist-table .check-file:checked'
  3791. }
  3792. $(node).each(function() {
  3793. const fileId = $(this).attr('file-id');
  3794. fileId && fileIds.push(fileId);
  3795. });
  3796. if (fileIds.length) {
  3797. const url = `/tender/${tender.id}/measure/stage/${stage.order}/download/compresse-file?fileIds=${JSON.stringify(fileIds)}`;
  3798. $('#zipDown').attr('href', url);
  3799. $("#zipDown")[0].click();
  3800. }
  3801. });
  3802. // 监听附件check是否选中
  3803. $('.list-table').on('click', '.check-file', function() {
  3804. const checkedList = $(this).parents('.list-table').children().find('input:checked');
  3805. const childs = $(this).parents('.list-table').children().length;
  3806. const checkBox = $(this).parents('.list-table').parent().find('.check-all-file');
  3807. if (checkedList.length === childs) {
  3808. checkBox.prop("checked", true);
  3809. } else {
  3810. checkBox.prop("checked", false);
  3811. }
  3812. });
  3813. $('.check-all-file').click(function() {
  3814. const isCheck = $(this).is(':checked');
  3815. $(this).parents('table').find('.list-table').each(function() {
  3816. $(this).find('input:checkbox').prop("checked", isCheck);
  3817. })
  3818. });
  3819. // 显示层次
  3820. (function (select, sheet) {
  3821. $(select).click(function () {
  3822. if (!sheet.zh_tree) return;
  3823. const tag = $(this).attr('tag');
  3824. const tree = sheet.zh_tree;
  3825. setTimeout(() => {
  3826. showWaitingView();
  3827. switch (tag) {
  3828. case "1":
  3829. case "2":
  3830. case "3":
  3831. case "4":
  3832. case "5":
  3833. tree.expandByLevel(parseInt(tag));
  3834. SpreadJsObj.refreshTreeRowVisible(sheet);
  3835. break;
  3836. case "last":
  3837. tree.expandByCustom(() => { return true; });
  3838. SpreadJsObj.refreshTreeRowVisible(sheet);
  3839. break;
  3840. case "leafXmj":
  3841. tree.expandToLeafXmj();
  3842. SpreadJsObj.refreshTreeRowVisible(sheet);
  3843. break;
  3844. case "curMeasure":
  3845. tree.expandByCustom(function (node) {
  3846. for (const field of ['contract_tp', 'qc_tp', 'gather_tp']) {
  3847. if (node[field]) {
  3848. return true;
  3849. }
  3850. }
  3851. return false;
  3852. });
  3853. SpreadJsObj.refreshTreeRowVisible(sheet);
  3854. break;
  3855. }
  3856. closeWaitingView();
  3857. }, 100);
  3858. });
  3859. })('a[name=showLevel]', slSpread.getActiveSheet());
  3860. const stageCheckerSetting = {
  3861. ledgerTree: stageTree,
  3862. ledgerPos: stagePos,
  3863. checkList: checkList,
  3864. decimal: tenderInfo.decimal,
  3865. checkOption: checkOption,
  3866. };
  3867. if (!checkTzMeasureType()) {
  3868. stageCheckerSetting.checkOption.calc.fields.push('sgfh_qty', 'sjcl_qty', 'qtcl_qty', 'quantity');
  3869. stageCheckerSetting.checkOption.tp.fields.push(
  3870. {qty: 'sgfh_qty', tp: 'sgfh_tp'},
  3871. {qty: 'sjcl_qty', tp: 'sjcl_tp'},
  3872. {qty: 'qtcl_qty', tp: 'qtcl_tp'},
  3873. {qty: 'quantity', tp: 'total_price'},
  3874. );
  3875. }
  3876. $('#ledger-check2').click(() => {
  3877. const result = ledgerCheck2(stageCheckerSetting);
  3878. check2Viewing({
  3879. extra: ZhCalc.div(stageTree.datas.length + stagePos.datas.length, 10000, 0),
  3880. randomWait: true,
  3881. prefix: 'check2-',
  3882. checks: result,
  3883. checkList: checkList,
  3884. })
  3885. });
  3886. const dataChecker = DataChecker({
  3887. checkUrl: window.location.pathname + '/check',
  3888. completeData: function (data) {
  3889. stagePos.updateDatas({pos: data.source.pos});
  3890. const refreshData = stageTree.loadPostStageData({bills: data.source.bills});
  3891. stageTreeSpreadObj.refreshTreeNodes(slSpread.getActiveSheet(), refreshData);
  3892. stagePosSpreadObj.loadCurPosData();
  3893. for (const e of data.error) {
  3894. e.serialNo = stageTree.getNodeIndex(stageTree.getItems(e.ledger_id)) + 1;
  3895. }
  3896. },
  3897. errorList: errorList,
  3898. });
  3899. $('[name=stage-start]').submit(function (e) {
  3900. if (checkAuditorFrom()) {
  3901. // 再检查多人协同确认情况
  3902. const list = stageTree.pwd.find(x => {return !x.confirm });
  3903. if(list) {
  3904. toastr.error('请检查多人协同确认情况再上报');
  3905. $('#hide-all').hide();
  3906. return false;
  3907. }
  3908. $(this).parent().parent().parent().modal('hide');
  3909. dataChecker.checkAndPost(this.action, {});
  3910. $('#hide-all').hide();
  3911. }
  3912. return false;
  3913. });
  3914. $('#audit-check0').submit(function (e) {
  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. const checkType = parseInt($('[name=checkType]').val());
  3923. const data = {
  3924. opinion: $(`${'#sp-done'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3925. checkType,
  3926. };
  3927. $('#sp-done').modal('hide');
  3928. checkType && dataChecker.checkAndPost(this.action, data);
  3929. $('#hide-all').hide();
  3930. return false;
  3931. });
  3932. $('#audit-check1').submit(function (e) {
  3933. const checkType = parseInt($('[name=checkType]:checked').val());
  3934. const data = {
  3935. opinion: $(`${'#sp-back'}`).find('[name=opinion]').val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '),
  3936. checkType,
  3937. };
  3938. if ($('#warning-text').length) $('#warning-text').remove()
  3939. if (!checkType && !$('#warning-text').length) {
  3940. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  3941. return false
  3942. }
  3943. $('#sp-back').modal('hide');
  3944. checkType && dataChecker.checkAndPost(this.action, data);
  3945. $('#hide-all').hide();
  3946. return false;
  3947. });
  3948. $('#exportExcel').click(function () {
  3949. stageTreeSpreadObj.exportExcel($('.sidebar-title').attr('data-original-title') + "计量台账.xlsx", stageTree.children);
  3950. });
  3951. $('#cbr-check-all').click(function () {
  3952. if (this.checked) {
  3953. $('input', '#cbr-pos-list').attr('checked', 'checked');
  3954. } else {
  3955. $('input', '#cbr-pos-list').removeAttr('checked');
  3956. }
  3957. });
  3958. $('#cbr-ok').click(() => {
  3959. const ratio = parseInt($('#cbr-ratio').val());
  3960. if (!ratio) {
  3961. toastr.warning('请输入计量比例');
  3962. return;
  3963. } else if (ratio < 1) {
  3964. toastr.warning('计量比例不可小于1');
  3965. return;
  3966. } else if (ratio > 100) {
  3967. toastr.warning('计量比例不可大于100');
  3968. return;
  3969. }
  3970. const apply2sibling = $('#apply2sibling')[0].checked;
  3971. const posName = _.map($('input:checked', '#cbr-pos-list'), function (x) {return $(x).attr('pos-name')});
  3972. if (posName.length === 0) {
  3973. toastr.warning('请勾选需要按计量比例的计量单元');
  3974. return;
  3975. }
  3976. stageTreeSpreadObj.measureByBatch(posName, ratio, apply2sibling);
  3977. });
  3978. $('body').on('click', '[name=ledger-unlock]', function() {
  3979. $('#cooperation').modal('hide');
  3980. const lid = this.getAttribute('lid');
  3981. if (!lid) return;
  3982. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  3983. if (!p) return;
  3984. $('#unlock-info').html(`${p.node.code} ${p.node.name} 解锁密码<b class="text-danger">*</b>`);
  3985. $('#unlock-pwd').val('').removeClass('is-invalid');
  3986. $('.invalid-feedback', '#unlock').hide();
  3987. $('.alert-warning', '#unlock').hide();
  3988. $('#unlock-ok').attr('lid', lid);
  3989. $('#unlock').modal('show');
  3990. });
  3991. $('#unlock-ok').click(function () {
  3992. const lid = this.getAttribute('lid');
  3993. if (!lid) return;
  3994. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  3995. if (!p) return;
  3996. if (p.pwd === $('#unlock-pwd').val()) {
  3997. const refresh = stageTree.lockNode(p, false);
  3998. // 修改线上
  3999. // postData(window.location.pathname + '/save/cooperation', { type: 'save-pwd', postData: { ledger_id: lid, pwd: $('#unlock-pwd').val() } }, function (result) {
  4000. // stageTree.pwdList = result.cooperationPwd;
  4001. // });
  4002. SpreadJsObj.reloadRowsReadonly(slSpread.getActiveSheet(), refresh);
  4003. stagePosSpreadObj.loadCurPosData();
  4004. $('#unlock').modal('hide');
  4005. reloadCooperationHtml();
  4006. } else {
  4007. $('#unlock-pwd').addClass('is-invalid');
  4008. $('.invalid-feedback', '#unlock').show();
  4009. $('.alert-warning', '#unlock').show();
  4010. }
  4011. });
  4012. $('#cooperationSelect').change(function () {
  4013. reloadCooperationHtml();
  4014. });
  4015. // 确认
  4016. $('body').on('click', '[name=ledger-confirm]', function() {
  4017. const lid = this.getAttribute('lid');
  4018. if (!lid) return;
  4019. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4020. if (!p) return;
  4021. // 修改线上
  4022. postData(window.location.pathname + '/save/cooperation', { type: 'save-confirm', postData: { ledger_id: lid } }, function (result) {
  4023. p.confirm = true;
  4024. p.confirm_time = new Date();
  4025. stageTree.confirmList = result.cooperationConfirm;
  4026. reloadCooperationHtml();
  4027. });
  4028. });
  4029. // 确认
  4030. $('body').on('click', '[name=ledger-unconfirm]', function() {
  4031. const lid = this.getAttribute('lid');
  4032. if (!lid) return;
  4033. const p = stageTree.pwd.find(x => {return x.ledger_id == lid});
  4034. if (!p) return;
  4035. // 修改线上
  4036. postData(window.location.pathname + '/save/cooperation', { type: 'del-confirm', postData: { ledger_id: lid } }, function (result) {
  4037. p.confirm = false;
  4038. p.confirm_time = null;
  4039. stageTree.confirmList = result.cooperationConfirm;
  4040. reloadCooperationHtml();
  4041. });
  4042. });
  4043. });