stage.js 195 KB

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