stage.js 196 KB

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