material_list.js 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差清单
  4. *
  5. * @author EllisRan
  6. * @date 2019/10/25
  7. * @version
  8. */
  9. function getStageId() {
  10. return window.location.pathname.split('/')[5];
  11. }
  12. function findNotJoinLeafXmj(x, type = '') {
  13. if (type === 'index') {
  14. return notJoinList.findIndex(function (item) {
  15. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  16. });
  17. }
  18. return notJoinList.find(function (item) {
  19. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  20. });
  21. }
  22. function findNotChangeLeafXmj(x, type = '') {
  23. if (type === 'index') {
  24. return notChangeList.findIndex(function (item) {
  25. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  26. });
  27. }
  28. return notChangeList.find(function (item) {
  29. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  30. });
  31. }
  32. function findSelfLeafXmj(x, type = '') {
  33. if (type === 'index') {
  34. return selfList.findIndex(function (item) {
  35. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  36. });
  37. }
  38. return selfList.find(function (item) {
  39. return item.gcl_id === x.gcl_id && item.xmj_id === x.id && (x.mx_id === undefined || (x.mx_id !== undefined && x.mx_id === item.mx_id));
  40. });
  41. }
  42. function getMpSpreadByMBData(id) {
  43. const info = materialBillsData.find(function (item) {
  44. return item.id === parseInt(id);
  45. });
  46. return info ? info.m_spread : 0;
  47. }
  48. function getMaterialListByLeafXmj(gcl_id, xmj_id, mx_id = '') {
  49. const list = [];
  50. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  51. for (const ml of materialListData) {
  52. if (gcl_id === ml.gcl_id && xmj_id === ml.xmj_id && (mx_id === '' || mx_id === ml.mx_id) && (ms_id === null || ms_id === ml.ms_id)) {
  53. list.push(ml);
  54. }
  55. }
  56. return list;
  57. }
  58. function calcOneBQJC(xmj) {
  59. let jiacha = 0;
  60. const notx = findNotJoinLeafXmj(xmj);
  61. if (notx === undefined) {
  62. const list = xmj.mx_id !== undefined ? getMaterialListByLeafXmj(xmj.gcl_id, xmj.id, xmj.mx_id) : getMaterialListByLeafXmj(xmj.gcl_id, xmj.id);
  63. const notx2 = findNotChangeLeafXmj(xmj);
  64. if (notx2 !== undefined) {
  65. for (const l of list) {
  66. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.contract_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  67. }
  68. } else {
  69. for (const l of list) {
  70. jiacha = ZhCalc.add(jiacha, ZhCalc.mul(ZhCalc.mul(xmj.gather_qty, l.quantity), getMpSpreadByMBData(l.mb_id)));
  71. }
  72. }
  73. }
  74. return ZhCalc.round(jiacha, materialDecimal.tp);
  75. }
  76. function getPasteHint (str, row = '') {
  77. let returnObj = str;
  78. if (row) {
  79. returnObj.msg = '清单第' + (row+1) + '行' + (str.msg ? str.msg : str);
  80. }
  81. return returnObj;
  82. }
  83. // 重新计算列表的价差
  84. function calculateJiaCha(data, index) {
  85. // 计算单条的
  86. if (index) {
  87. const gcld = data[index]
  88. let total_jiacha = 0;
  89. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  90. const jiacha = calcOneBQJC(xmj);
  91. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  92. total_jiacha += jiacha;
  93. }
  94. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  95. } else {
  96. for(const gcld of data) {
  97. let total_jiacha = 0;
  98. for (const [index, xmj] of gcld.leafXmjs.entries()) {
  99. const jiacha = calcOneBQJC(xmj);
  100. gcld.leafXmjs[index].jiacha = jiacha !== 0 ? jiacha : null;
  101. total_jiacha += jiacha;
  102. }
  103. gcld.total_jiacha = ZhCalc.round(total_jiacha, materialDecimal.tp)
  104. }
  105. }
  106. }
  107. const is_numeric = (value) => {
  108. if (typeof(value) === 'object') {
  109. return false;
  110. } else {
  111. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  112. }
  113. };
  114. $(document).ready(() => {
  115. function TipCellType()
  116. {
  117. }
  118. TipCellType.prototype = new GC.Spread.Sheets.CellTypes.ColumnHeader();
  119. TipCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
  120. return { x: x, y: y, row: context.row, col: context.col, cellRect: cellRect, sheetArea: context.sheetArea, sheet: context.sheet };
  121. };
  122. TipCellType.prototype.processMouseEnter = function (hitInfo){
  123. if (!this._toolTipElement) {
  124. var div = document.createElement("div");
  125. $(div).css("position", "absolute")
  126. .css("border", "1px #C0C0C0 solid")
  127. .css("box-shadow", "1px 2px 5px rgba(0,0,0,0.4)")
  128. .css("font", "9pt Arial")
  129. .css("background", "#fff")
  130. // .css("color", "#fff")
  131. .css("z-index", "1000")
  132. .css("padding", 5);
  133. this._toolTipElement = div;
  134. }
  135. $(this._toolTipElement).text("单位数量:每一单位清单下所需工料消耗量。")
  136. .css("top", hitInfo.y + 15)
  137. .css("left", hitInfo.x - 15);
  138. $(this._toolTipElement).hide();
  139. // document.body.insertBefore(this._toolTipElement, null);
  140. if (hitInfo.sheet.yn === 4) { // 用于区分上下两个工料关联表
  141. $('#material-self-spread-div').append(this._toolTipElement, null);
  142. } else {
  143. $('#material-spread-div').append(this._toolTipElement, null);
  144. }
  145. $(this._toolTipElement).show("fast");
  146. };
  147. TipCellType.prototype.processMouseLeave = function (hitInfo) {
  148. if (this._toolTipElement) {
  149. // document.body.removeChild(this._toolTipElement);
  150. // $('#material-spread-div').removeChild(this._toolTipElement);
  151. this._toolTipElement.remove();
  152. this._toolTipElement = null;
  153. }
  154. };
  155. autoFlashHeight();
  156. // 清单table
  157. const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  158. const ledgerCols = [
  159. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  160. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  161. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  162. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  163. ];
  164. if (materialQtySource === 1) {
  165. ledgerCols.push({title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
  166. ledgerCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'});
  167. ledgerCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'});
  168. } else if (materialQtySource === 2) {
  169. ledgerCols.push({title: '本期计量数量|合同', colSpan: '1|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
  170. } else if (materialQtySource === 3) {
  171. ledgerCols.push({title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'});
  172. ledgerCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'});
  173. ledgerCols.push({title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 110, type: 'Number'});
  174. ledgerCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number', getValue: 'getValue.gather_qty'});
  175. }
  176. ledgerCols.push({title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'});
  177. ledgerCols.push({title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'});
  178. const ledgerSpreadSetting = {
  179. // cols: [
  180. // {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'b_code', hAlign: 0, width: 90, formatter: '@'},
  181. // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 220, formatter: '@'},
  182. // {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 80, formatter: '@'},
  183. // {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 110, type: 'Number'},
  184. // {title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 110, type: 'Number'},
  185. // {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 110, type: 'Number'},
  186. // {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 110, type: 'Number'},
  187. // {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 110, type: 'Number'},
  188. // {title: '本期完成金额', colSpan: '1', rowSpan: '2', field: 'gather_tp', hAlign: 2, width: 110, type: 'Number'},
  189. // {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'total_jiacha', hAlign:3, width: 110, type: 'Number'}
  190. // ],
  191. emptyRows: 0,
  192. headRows: 2,
  193. headRowHeight: [25, 25],
  194. defaultRowHeight: 21,
  195. headerFont: '12px 微软雅黑',
  196. font: '12px 微软雅黑',
  197. readOnly: true,
  198. };
  199. const ledgerCol = {
  200. getValue: {
  201. gather_qty: function (data) {
  202. if (materialQtySource === 3) {
  203. return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
  204. }
  205. },
  206. }
  207. }
  208. ledgerSpreadSetting.cols = ledgerCols;
  209. // let gclGatherData = gclGatherModel.gatherGclData()
  210. // 获取项目节数据
  211. function loadLeafXmjData(iGclRow) {
  212. const gcl = gclGatherData[iGclRow];
  213. if (gcl) {
  214. for (const [index, xmj] of gcl.leafXmjs.entries()) {
  215. const jiacha = calcOneBQJC(xmj);
  216. gcl.leafXmjs[index].jiacha = jiacha !== 0 ? ZhCalc.round(jiacha, materialDecimal.tp) : null;
  217. }
  218. const leafXmjs = gcl.leafXmjs.filter(item => {
  219. return item.qc_qty || item.contract_qty || item.qc_minus_qty;
  220. });
  221. console.log(leafXmjs);
  222. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, leafXmjs);
  223. // 对清单调差工料table的单位数量进行改变
  224. // materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  225. // SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  226. } else {
  227. SpreadJsObj.loadSheetData(leafXmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  228. }
  229. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  230. }
  231. SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);
  232. SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);
  233. // 项目明细table
  234. const leafXmjSpread = SpreadJsObj.createNewSpread($('#leaf-xmj-spread')[0]);
  235. const leafXmjCols = [
  236. {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  237. {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  238. {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  239. {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  240. {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  241. {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  242. {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  243. ];
  244. if (materialQtySource === 1) {
  245. leafXmjCols.push({title: '本期计量数量|合同', colSpan: '3|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'});
  246. leafXmjCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'});
  247. leafXmjCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'});
  248. } else if (materialQtySource === 2) {
  249. leafXmjCols.push({title: '本期计量数量|合同', colSpan: '1|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 100, type: 'Number'});
  250. } else if (materialQtySource === 3) {
  251. leafXmjCols.push({title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'});
  252. leafXmjCols.push({title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 60, type: 'Number'});
  253. leafXmjCols.push({title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 60, type: 'Number'});
  254. leafXmjCols.push({title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.gather_qty'});
  255. }
  256. leafXmjCols.push({title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'});
  257. const leafXmjSpreadSetting = {
  258. // cols: [
  259. // {title: '项目节|编号', colSpan: '2|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@'},
  260. // {title: '|项目节名称', colSpan: '|1', rowSpan: '|1', field: 'jldy', hAlign: 0, width: 100, formatter: '@'},
  261. // {title: '计量单元|计量单元', colSpan: '2|1', rowSpan: '1|1', field: 'bwmx', hAlign: 0, width: 100, formatter: '@'},
  262. // {title: '|复核数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 0, width: 80, type: 'Number'},
  263. // {title: '部位信息|单位工程', colSpan: '3|1', rowSpan: '1|1', field: 'dwgc', hAlign: 0, width: 100, formatter: '@'},
  264. // {title: '|分部工程', colSpan: '|1', rowSpan: '|1', field: 'fbgc', hAlign: 0, width: 100, formatter: '@'},
  265. // {title: '|分项工程', colSpan: '|1', rowSpan: '|1', field: 'fxgc', hAlign: 0, width: 180, formatter: '@'},
  266. // {title: '本期计量数量|合同', colSpan: '4|1', rowSpan: '1|1', field: 'contract_qty', hAlign: 2, width: 60, type: 'Number'},
  267. // {title: '|数量变更', colSpan: '|1', rowSpan: '|1', field: 'qc_qty', hAlign: 2, width: 80, type: 'Number'},
  268. // {title: '|不计价', colSpan: '|1', rowSpan: '|1', field: 'qc_minus_qty', hAlign: 2, width: 80, type: 'Number'},
  269. // {title: '|小计', colSpan: '|1', rowSpan: '|1', field: 'gather_qty', hAlign: 2, width: 60, type: 'Number'},
  270. // {title: '本期价差', colSpan: '1', rowSpan: '2', field: 'jiacha', hAlign: 2, width: 80, type: 'Number'},
  271. // ],
  272. emptyRows: 0,
  273. headRows: 2,
  274. headRowHeight: [25, 25],
  275. defaultRowHeight: 21,
  276. headerFont: '12px 微软雅黑',
  277. font: '12px 微软雅黑',
  278. readOnly: true,
  279. rowHeader:[
  280. {
  281. rowHeaderType: 'circle',
  282. setting: {
  283. size: 5,
  284. indent: 16,
  285. getColor: function (index, data) {
  286. if (!data) return;
  287. if (_.findIndex(selfList, { gcl_id: data.gcl_id, xmj_id: data.id, mx_id: (data.mx_id ? data.mx_id : '') }) !== -1) {
  288. return '#dc3545';
  289. }
  290. }
  291. },
  292. },
  293. ],
  294. };
  295. leafXmjSpreadSetting.cols = leafXmjCols;
  296. const leafXmjCol = {
  297. getValue: {
  298. gather_qty: function (data) {
  299. if (materialQtySource === 3) {
  300. return ZhCalc.add(data.gather_qty, data.qc_minus_qty);
  301. }
  302. },
  303. }
  304. }
  305. const needUpdateArray = ['quantity', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  306. function getGclList() {
  307. if (gclGatherListData) {
  308. return gclGatherListData;
  309. } else {
  310. const newGclGatherListData = [];
  311. for (const [index,s] of ledgerListData.entries()) {
  312. console.log(index, s);
  313. gclGatherModel.loadLedgerData(ledger, s);
  314. gclGatherModel.loadPosData(pos, posListData[index]);
  315. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  316. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  317. });
  318. newGclGatherListData.push(oneGclGatherData);
  319. }
  320. return newGclGatherListData;
  321. }
  322. }
  323. let first = true;
  324. function setListsData(sid = null, ms_id = null) {
  325. if (first) {
  326. // 加载清单数据 - 暂时统一加载,如有需要,切换成动态加载并缓存
  327. postData(window.location.pathname + '/load', {sid}, async function (result) {
  328. ledger = result.ledger;
  329. curLedgerData = result.curLedgerData;
  330. pos = result.pos;
  331. curPosData = result.curPosData;
  332. materialListData = result.materialListData;
  333. gclList = result.gclList;
  334. notJoinList = result.materialNotJoinListData;
  335. notChangeList = result.materialNotChangeListData;
  336. selfList = result.materialSelfListData;
  337. materialChecklistData = result.materialChecklistData;
  338. if (isStageSelf) {
  339. updateBillsData(ms_id);
  340. const newGclGatherListData = [];
  341. for (const [index, s] of result.ledgerListData.entries()) {
  342. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), s);
  343. gclGatherModel.loadPosData(_.cloneDeep(pos), result.posListData[index]);
  344. const oneGclGatherData = gclGatherModel.gatherGclData().filter(item => {
  345. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  346. });
  347. newGclGatherListData.push(oneGclGatherData);
  348. }
  349. gclGatherListData = newGclGatherListData;
  350. }
  351. // 解析清单汇总数据
  352. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  353. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  354. gclGatherData = gclGatherModel.gatherGclData();
  355. console.log(gclGatherData);
  356. if (openMaterialChecklist) {
  357. const hadBillsidList = _.uniq(_.map(gclList, 'gcl_id'));
  358. console.log(hadBillsidList);
  359. // 判断是否有修订影响到本次数据,并有几率修改清单设置页的值
  360. const pushData = [];
  361. const updateData = [];
  362. for (const hb of hadBillsidList) {
  363. const gcl = _.find(gclGatherData, function (item) {
  364. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: hb}) !== -1;
  365. });
  366. if (gcl) {
  367. const mc = _.find(materialChecklistData, {
  368. b_code: gcl.b_code,
  369. name: gcl.name,
  370. unit: gcl.unit,
  371. unit_price: gcl.unit_price
  372. });
  373. // const newOrder = _.indexOf(gclGatherData, gcl);
  374. // console.log(newOrder);
  375. if (!mc && _.findIndex(pushData, {
  376. b_code: gcl.b_code,
  377. name: gcl.name,
  378. unit: gcl.unit,
  379. unit_price: gcl.unit_price
  380. }) === -1) {
  381. pushData.push({
  382. b_code: gcl.b_code,
  383. name: gcl.name,
  384. unit: gcl.unit,
  385. unit_price: gcl.unit_price,
  386. quantity: (gcl.quantity ? gcl.quantity : null),
  387. total_price: (gcl.total_price ? gcl.total_price : null),
  388. had_bills: 1
  389. });
  390. }
  391. }
  392. }
  393. const removeData = [];
  394. for (const mc of materialChecklistData) {
  395. const gcl = _.find(gclGatherData, {
  396. b_code: mc.b_code,
  397. name: mc.name,
  398. unit: mc.unit,
  399. unit_price: mc.unit_price
  400. });
  401. // 判断是否已不存在工料清单,台账修改过后删除之
  402. if (!gcl) {
  403. removeData.push(mc.id);
  404. } else {
  405. // 更新had_bills值
  406. const updateObj = {id: mc.id};
  407. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  408. const jiaoji = _.intersection(gcl_ids, hadBillsidList);
  409. if (mc.had_bills === 1) {
  410. if (jiaoji.length === 0) {
  411. updateObj.mid = materialID;
  412. updateObj.had_bills = 0;
  413. // updateData.push({ id: mc.id, mid: materialID, had_bills: 0 });
  414. }
  415. } else if (mc.had_bills === 0) {
  416. if (jiaoji.length !== 0) {
  417. updateObj.had_bills = 1;
  418. }
  419. }
  420. // 更新工程量及台账金额
  421. if (mc.quantity !== (gcl.quantity ? gcl.quantity : null)) {
  422. updateObj.quantity = gcl.quantity ? gcl.quantity : null;
  423. updateObj.total_price = gcl.total_price ? gcl.total_price : null;
  424. }
  425. if (!_.isEqual(updateObj, {id: mc.id})) updateData.push(updateObj);
  426. }
  427. }
  428. console.log(pushData, removeData, updateData);
  429. if (pushData.length > 0 || removeData.length > 0 || updateData.length > 0) {
  430. // materialChecklistData = await postDataAsync('/tender/'+ tenderID +'/measure/material/'+ stage_order +'/checklist/save', { type: 'resetChecklist', pushData, removeData, updateData })
  431. }
  432. gclGatherData = gclGatherData.filter(item => {
  433. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  434. });
  435. // 取交集
  436. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  437. gclGatherData = _.filter(gclGatherData, function (item) {
  438. if (_.find(materialChecklistData, {
  439. b_code: item.b_code,
  440. name: item.name,
  441. unit: item.unit,
  442. unit_price: item.unit_price
  443. })) {
  444. return true;
  445. } else {
  446. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  447. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  448. if (jiaoji.length > 0) {
  449. return true;
  450. }
  451. }
  452. });
  453. } else {
  454. gclGatherData = gclGatherData.filter(item => {
  455. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  456. });
  457. }
  458. calculateJiaCha(gclGatherData);
  459. SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  460. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  461. // 加载清单数据
  462. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  463. loadLeafXmjData(0);
  464. loadMaterialData(0);
  465. loadXmjMaterialData(0, 0);
  466. const sheet = materialSpread.getActiveSheet();
  467. sheet.suspendPaint();
  468. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  469. sheet.resumePaint();
  470. const selfSheet = materialSelfSpread.getActiveSheet();
  471. selfSheet.suspendPaint();
  472. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  473. selfSheet.resumePaint();
  474. checkNotJoinMaterialData();
  475. first = false;
  476. // 判断是否需要更新contract_qty、qc_qty和qc_minus_qty
  477. if (!materialIsNewQty && !readOnly) {
  478. let needUpdateList = [];
  479. if (materialListData.length > 0) {
  480. if (isStageSelf) {
  481. for (const msIndex in materialStageData) {
  482. const materialStageList = _.filter(materialListData, { ms_id: materialStageData[msIndex].id });
  483. const gclIdList = _.uniq(_.map(materialListData, 'gcl_id'));
  484. let leafXmjList = [];
  485. for (const id of gclIdList) {
  486. const gcl = _.find(gclGatherListData[msIndex], function (item) {
  487. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
  488. });
  489. if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
  490. }
  491. for (const ml of materialStageList) {
  492. const leafXmjInfo = _.find(leafXmjList, function (item) {
  493. return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
  494. });
  495. if (leafXmjInfo) {
  496. needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
  497. }
  498. }
  499. }
  500. } else {
  501. // 找出所有gcl相同的,方便搜索gclGatherData值
  502. const gclIdList = _.uniq(_.map(materialListData, 'gcl_id'));
  503. let leafXmjList = [];
  504. for (const id of gclIdList) {
  505. const gcl = _.find(gclGatherData, function (item) {
  506. return item.leafXmjs && item.leafXmjs.length > 0 && _.findIndex(item.leafXmjs, {gcl_id: id}) !== -1;
  507. });
  508. if (gcl) leafXmjList = [...leafXmjList, ...gcl.leafXmjs];
  509. }
  510. for (const ml of materialListData) {
  511. const leafXmjInfo = _.find(leafXmjList, function (item) {
  512. return item.gcl_id === ml.gcl_id && item.id === ml.xmj_id && (item.mx_id === undefined || (item.mx_id !== undefined && item.mx_id === ml.mx_id));
  513. });
  514. if (leafXmjInfo) {
  515. needUpdateList.push({ id: ml.id, contract_qty: leafXmjInfo.contract_qty, qc_qty: leafXmjInfo.qc_qty, qc_minus_qty: leafXmjInfo.qc_minus_qty });
  516. }
  517. }
  518. }
  519. }
  520. console.log(needUpdateList);
  521. // postData(window.location.pathname + '/save', needUpdateList, function (result) {
  522. // materialListData2 = result.materialListData;
  523. // });
  524. }
  525. });
  526. } else {
  527. // 解析清单汇总数据
  528. // const ms_id = $('#myTab').find('.active').data('msid');
  529. updateBillsData(ms_id);
  530. const i = _.findIndex(materialStageData, { sid });
  531. gclGatherData = gclGatherListData[i];
  532. if (openMaterialChecklist) {
  533. gclGatherData = gclGatherData.filter(item => {
  534. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  535. });
  536. // 取交集
  537. const selfListGcl = _.uniq(_.map(selfList, 'gcl_id'));
  538. gclGatherData = _.filter(gclGatherData, function (item) {
  539. if (_.find(materialChecklistData, {
  540. b_code: item.b_code,
  541. name: item.name,
  542. unit: item.unit,
  543. unit_price: item.unit_price
  544. })) {
  545. return true;
  546. } else {
  547. const gcl_ids = item.leafXmjs ? _.uniq(_.map(item.leafXmjs, 'gcl_id')) : [];
  548. const jiaoji = _.intersection(gcl_ids, selfListGcl);
  549. if (jiaoji.length > 0) {
  550. return true;
  551. }
  552. }
  553. });
  554. } else {
  555. gclGatherData = gclGatherData.filter(item => {
  556. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  557. });
  558. }
  559. if ($('#show_material_gcl').is(':checked')) {
  560. const hadMaterialGclGatherData = [];
  561. const hadGclIdList = [];
  562. for (const ml of materialListData) {
  563. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  564. hadGclIdList.push(ml.gcl_id);
  565. }
  566. }
  567. for (const gcl of gclGatherData) {
  568. for (const index in gcl.leafXmjs) {
  569. const gcl_id = gcl.leafXmjs[index].gcl_id;
  570. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  571. hadMaterialGclGatherData.push(gcl);
  572. break;
  573. }
  574. }
  575. }
  576. gclGatherData = hadMaterialGclGatherData;
  577. }
  578. console.log(gclGatherData);
  579. calculateJiaCha(gclGatherData);
  580. SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  581. SpreadJsObj.initSheet(leafXmjSpread.getActiveSheet(), leafXmjSpreadSetting);
  582. // 加载清单数据
  583. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  584. loadLeafXmjData(0);
  585. loadMaterialData(0);
  586. loadXmjMaterialData(0, 0);
  587. const sheet = materialSpread.getActiveSheet();
  588. sheet.suspendPaint();
  589. sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  590. sheet.resumePaint();
  591. const selfSheet = materialSelfSpread.getActiveSheet();
  592. selfSheet.suspendPaint();
  593. selfSheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  594. selfSheet.resumePaint();
  595. ledgerSpread.getActiveSheet().setSelection(0, 0, 1, 1);
  596. checkNotJoinMaterialData();
  597. }
  598. }
  599. function updateBillsData(ms_id) {
  600. const msbList = _.filter(materialStageBillsData, { ms_id });
  601. for (const mb of materialBillsData) {
  602. mb.ms_id = ms_id;
  603. const msbInfo = _.find(msbList, { mb_id: mb.id });
  604. for (const nu of needUpdateArray) {
  605. mb[nu] = msbInfo[nu];
  606. }
  607. }
  608. }
  609. setListsData(isStageSelf ? materialStageData[0].sid : null, isStageSelf ? materialStageData[0].id : null);
  610. // 期切换
  611. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  612. e.preventDefault();
  613. const ms_id = $('#myTab').find('.active').data('msid');
  614. const msInfo = _.find(materialStageData, { id: ms_id });
  615. showWaitingView();
  616. setTimeout(function () {
  617. setListsData(msInfo.sid, ms_id);
  618. closeWaitingView();
  619. }, 500);
  620. });
  621. // const leafXmjCol = {
  622. // getValue: {
  623. // jiacha: function (data) {
  624. // let sum = 0;
  625. // const sheet = leafXmjSpread.getActiveSheet();
  626. // const select = SpreadJsObj.getSelectObject(sheet);
  627. // const notx = findNotJoinLeafXmj(select);
  628. // if (notx === undefined) {
  629. // for(const ml of materialList) {
  630. // sum = ZhCalc.round(ZhCalc.add(sum, ZhCalc.mul(ZhCalc.mul(data.gather_qty, ml.quantity), getMpSpreadByMBData(ml.mb_id))), 2);
  631. // }
  632. // }
  633. // return sum !== 0 ? sum : null;
  634. // }
  635. // }
  636. // };
  637. // SpreadJsObj.initSpreadSettingEvents(leafXmjSpreadSetting, leafXmjCol);
  638. // 调差清单工料table
  639. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  640. const materialSpreadSetting = {
  641. cols: [
  642. {title: '清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  643. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  644. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  645. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  646. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  647. ],
  648. emptyRows: 0,
  649. headRows: 2,
  650. headRowHeight: [25, 25],
  651. defaultRowHeight: 21,
  652. headerFont: '12px 微软雅黑',
  653. font: '12px 微软雅黑',
  654. };
  655. const materialBase = {
  656. isEdit: function (data, type = 'normal') {
  657. // 是否本期添加的工料
  658. // return data.order === stage_order && !openMaterialChecklist;
  659. let flag = true;
  660. if (type === 'del' || !editListPermission) {
  661. flag = data.order === stage_order;
  662. }
  663. return flag && !openMaterialChecklist;
  664. }
  665. };
  666. const materialCol = {
  667. readOnly: {
  668. isEdit: function (data) {
  669. // const sheet = leafXmjSpread.getActiveSheet();
  670. // const select = SpreadJsObj.getSelectObject(sheet);
  671. // const notx = findNotJoinLeafXmj(select);
  672. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  673. return !(!readOnly && materialBase.isEdit(data));
  674. },
  675. },
  676. };
  677. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  678. // 获取项目节数据
  679. let materialList = [];
  680. function loadMaterialData(iGclRow) {
  681. const gcl = gclGatherData[iGclRow];
  682. if (gcl && gcl.leafXmjs) {
  683. const gcl_ids = gcl.leafXmjs ? _.uniq(_.map(gcl.leafXmjs, 'gcl_id')) : [];
  684. materialList = [];
  685. const newMaterialList = _.uniqBy(_.filter(gclList, function (m) {
  686. return _.indexOf(gcl_ids, m.gcl_id) !== -1;
  687. }), 'mb_id');
  688. for(const m of newMaterialList) {
  689. const bills = _.find(materialBillsData, { id: m.mb_id });
  690. if(bills) {
  691. m.code = bills.code;
  692. m.name = bills.name;
  693. m.unit = bills.unit;
  694. }
  695. }
  696. console.log(newMaterialList);
  697. materialList = newMaterialList;
  698. // 对清单调差工料table的单位数量进行改变
  699. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  700. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  701. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialList);
  702. } else {
  703. materialSpreadSetting.cols[materialSpreadSetting.cols.length - 2].title = '数量 �';
  704. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  705. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  706. }
  707. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  708. }
  709. // 调差清单工料table
  710. const materialSelfSpread = SpreadJsObj.createNewSpread($('#material-self-spread')[0]);
  711. const materialSelfSpreadSetting = {
  712. cols: [
  713. {title: '明细清单工料含量|编号', colSpan: '5|1', rowSpan: '1|1', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  714. {title: '|名称', colSpan: '|1', rowSpan: '|1', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  715. {title: '|单位', colSpan: '|1', rowSpan: '|1', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  716. {title: '|数量 �', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 80, type: 'Number', readOnly: 'readOnly.isEdit'},
  717. {title: '|计算式', colSpan: '1', rowSpan: '|1', field: 'expr', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isEdit'},
  718. ],
  719. emptyRows: 0,
  720. headRows: 2,
  721. headRowHeight: [25, 25],
  722. defaultRowHeight: 21,
  723. headerFont: '12px 微软雅黑',
  724. font: '12px 微软雅黑',
  725. };
  726. const materialSelfBase = {
  727. isEdit: function (data, type = 'normal') {
  728. // 是否本期添加的工料
  729. // return data.order === stage_order && !openMaterialChecklist;
  730. let flag = true;
  731. if (type === 'del' || !editListPermission) {
  732. flag = data.order === stage_order;
  733. }
  734. return flag;
  735. }
  736. };
  737. const materialSelfCol = {
  738. readOnly: {
  739. isEdit: function (data) {
  740. // const sheet = leafXmjSpread.getActiveSheet();
  741. // const select = SpreadJsObj.getSelectObject(sheet);
  742. // const notx = findNotJoinLeafXmj(select);
  743. // return !(!readOnly && notx === undefined && materialBase.isEdit(data));
  744. return openMaterialSelf && !(!readOnly && materialSelfBase.isEdit(data));
  745. },
  746. },
  747. };
  748. SpreadJsObj.initSpreadSettingEvents(materialSelfSpreadSetting, materialSelfCol);
  749. let materialListSelf = [];
  750. function loadXmjMaterialData(iGclRow, iLXmjRow) {
  751. // 存在单独设置的才展示,不然隐藏
  752. const gcl = gclGatherData[iGclRow];
  753. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  754. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  755. }) : null;
  756. if (leafXmjs) {
  757. const xmj = leafXmjs[iLXmjRow];
  758. console.log(xmj, iLXmjRow);
  759. materialListSelf = [];
  760. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  761. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  762. for (const m of materialListData) {
  763. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined) && (ms_id === null || ms_id === m.ms_id)) {
  764. materialListSelf.push(m);
  765. }
  766. }
  767. $('#material-self-spread-div').addClass('active');
  768. showSelfSideTools(true);
  769. } else {
  770. $('#material-self-spread-div').removeClass('active');
  771. showSelfSideTools(false);
  772. }
  773. // 对清单调差工料table的单位数量进行改变
  774. materialSelfSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '|' + '每' + gcl.unit + '数量 �';
  775. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  776. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialListSelf);
  777. } else {
  778. $('#material-self-spread-div').removeClass('active');
  779. showSelfSideTools(false);
  780. materialSpreadSetting.cols[materialSelfSpreadSetting.cols.length - 2].title = '数量 �';
  781. SpreadJsObj.initSheet(materialSelfSpread.getActiveSheet(), materialSelfSpreadSetting);
  782. SpreadJsObj.loadSheetData(materialSelfSpread.getActiveSheet(), SpreadJsObj.DataType.Data, []);
  783. }
  784. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  785. leafXmjSpread.refresh();
  786. materialSelfSpread.refresh();
  787. }
  788. // SpreadJsObj.locateTreeNode(ledgerSpread.getActiveSheet(), )
  789. // loadLeafXmjData(0);
  790. // loadMaterialData(0, 0);
  791. // const sheet = materialSpread.getActiveSheet();
  792. // sheet.suspendPaint();
  793. // sheet.setCellType(1, 3, new TipCellType(), spreadNS.SheetArea.colHeader);
  794. // sheet.resumePaint();
  795. // 不参与调差数据值变灰, 数量变更不参与调差数据值变黄
  796. function checkNotJoinMaterialData() {
  797. const sheet = ledgerSpread.getActiveSheet();
  798. const select = SpreadJsObj.getSelectObject(sheet);
  799. const index = gclGatherData.indexOf(select);
  800. if (index !== -1) {
  801. const xmj = gclGatherData[index].leafXmjs.filter(item => {
  802. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  803. });
  804. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  805. for (const [iRow,x] of xmj.entries()) {
  806. const notx = findNotJoinLeafXmj(x);
  807. const color = notx === undefined ? '' : '#d6d8db';
  808. // leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color);
  809. const notx2 = findNotChangeLeafXmj(x);
  810. const color2 = notx2 === undefined || materialQtySource === qtySourceValueConst.contract_qty ? color : '#FFE699';
  811. leafXmjSheet.getRange(iRow, -1, 1, -1).backColor(color2);
  812. }
  813. }
  814. }
  815. // checkNotJoinMaterialData();
  816. // 对添加工料表格赋值
  817. function changeMaterialTable(from = 'all') {
  818. $('#materialBills tr').removeClass('table-secondary');
  819. $('#materialBills').find('input').removeAttr('disabled');
  820. $('#materialBills').find('input').prop('checked', false);
  821. const searchList = from === 'self' ? materialListSelf : materialList;
  822. console.log(searchList);
  823. for (const [index, ml] of searchList.entries()) {
  824. const mbIndex = materialBillsData.findIndex(function (item) {
  825. return item.id === ml.mb_id;
  826. });
  827. if (mbIndex !== -1) {
  828. $('#materialBills tr').eq(mbIndex).addClass('table-secondary');
  829. $('#materialBills').find('input').eq(mbIndex).attr('disabled', true);
  830. $('#materialBills').find('input').eq(mbIndex).prop('checked', true);
  831. }
  832. }
  833. }
  834. // 添加调差工料
  835. $('#add_material_bill').click(function () {
  836. // 获取已选工料
  837. $('#materialBills').find('input:disabled').prop('checked', false);
  838. const selectList = $('#materialBills').find('input:checked');
  839. if (selectList.length === 0) {
  840. toastr.warning('请选择调差工料');
  841. $('#materialBills').find('input:disabled').prop('checked', true);
  842. return false;
  843. }
  844. const mb_id = [];
  845. for (let s = 0; s < selectList.length; s++) {
  846. mb_id.push($('#materialBills').find('input:checked').eq(s).val());
  847. }
  848. const type = $('#add_type').val();
  849. if (type === 'all') {
  850. // 获取当前项目节或部位明细id
  851. const sheet = ledgerSpread.getActiveSheet();
  852. const select = SpreadJsObj.getSelectObject(sheet);
  853. const index = gclGatherData.indexOf(select);
  854. const gcl = gclGatherData[index].leafXmjs;
  855. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  856. const datas = [];
  857. for (const xmj of gcl) {
  858. const notx = findNotJoinLeafXmj(xmj);
  859. const notx2 = findNotChangeLeafXmj(xmj);
  860. const data = {
  861. xmj_id: xmj.id,
  862. gcl_id: xmj.gcl_id,
  863. mx_id: xmj.mx_id ? xmj.mx_id : '',
  864. contract_qty: xmj.contract_qty,
  865. qc_qty: xmj.qc_qty,
  866. qc_minus_qty: xmj.qc_minus_qty,
  867. gather_qty: xmj.gather_qty,
  868. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  869. };
  870. if (ms_id) data.ms_id = ms_id;
  871. datas.push(data);
  872. }
  873. if (isStageSelf) {
  874. // 取所有的gclGatherData才行,然后获取下的值
  875. const gclData = gclGatherData[index];
  876. for (const [index, ms] of materialStageData.entries()) {
  877. if (ms.id !== ms_id) {
  878. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  879. if (gclOther) {
  880. const leafXmjs = gclOther.leafXmjs.filter(item => {
  881. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  882. });
  883. // gclOther.leafXmjs.filter(item => item.gather_qty !== null && item.gather_qty !== undefined);
  884. for (const xmj of leafXmjs) {
  885. const notx = findNotJoinLeafXmj(xmj);
  886. const notx2 = findNotChangeLeafXmj(xmj);
  887. const data = {
  888. xmj_id: xmj.id,
  889. gcl_id: xmj.gcl_id,
  890. mx_id: xmj.mx_id ? xmj.mx_id : '',
  891. contract_qty: xmj.contract_qty,
  892. qc_qty: xmj.qc_qty,
  893. qc_minus_qty: xmj.qc_minus_qty,
  894. gather_qty: xmj.gather_qty,
  895. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  896. ms_id: ms.id,
  897. };
  898. datas.push(data);
  899. }
  900. }
  901. }
  902. }
  903. }
  904. console.log(datas, gcl, mb_id);
  905. postData(window.location.pathname + '/save', {type: 'adds', postData: {xmjs: datas, mbIds: mb_id} }, function (result) {
  906. materialListData = result.materialListData;
  907. gclList = result.gclList;
  908. // toastr.success('已成功应用');
  909. calculateJiaCha(gclGatherData);
  910. // const index = gclGatherData.indexOf(ledgerSelect);
  911. loadLeafXmjData(index);
  912. // const xmjSheet = leafXmjSpread.getActiveSheet();
  913. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  914. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  915. loadMaterialData(index);
  916. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  917. $('#addgl').modal('hide');
  918. });
  919. } else if (type === 'self') {
  920. // 获取当前项目节或部位明细id
  921. const sheet = ledgerSpread.getActiveSheet();
  922. const select = SpreadJsObj.getSelectObject(sheet);
  923. const index = gclGatherData.indexOf(select);
  924. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  925. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  926. const gcl = gclGatherData[index].leafXmjs.filter(item => {
  927. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  928. });
  929. const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  930. const xmj = gcl[leafXmjIndex];
  931. const notx = findNotJoinLeafXmj(xmj);
  932. const notx2 = findNotChangeLeafXmj(xmj);
  933. const data = {
  934. xmj_id: xmj.id,
  935. gcl_id: xmj.gcl_id,
  936. mx_id: xmj.mx_id ? xmj.mx_id : '',
  937. mb_id: mb_id,
  938. contract_qty: xmj.contract_qty,
  939. qc_qty: xmj.qc_qty,
  940. qc_minus_qty: xmj.qc_minus_qty,
  941. gather_qty: xmj.gather_qty,
  942. is_join: notx !== undefined ? 0 : notx2 !== undefined ? 2 : 1,
  943. };
  944. console.log(data);
  945. postData(window.location.pathname + '/save', {type: 'add', postData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  946. // 添加到materialList里
  947. materialListData = result;
  948. loadXmjMaterialData(index, leafXmjIndex);
  949. $('#addgl').modal('hide');
  950. });
  951. }
  952. $('#materialBills').find('input:disabled').prop('checked', true);
  953. });
  954. const leafXmjSpreadObj = {
  955. getSelect : function () {
  956. const sheet = ledgerSpread.getActiveSheet();
  957. const select = SpreadJsObj.getSelectObject(sheet);
  958. const index = gclGatherData.indexOf(select);
  959. const leafXmjSheet = leafXmjSpread.getActiveSheet();
  960. const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  961. const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  962. const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  963. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  964. });
  965. const nRow = leafXmjs.indexOf(leafXmjSelect);
  966. const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : (findNotChangeLeafXmj(leafXmjSelect) ? '#FFE699' : '');
  967. return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  968. },
  969. checkJoinMaterial: function (type) {
  970. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  971. const color = type === 'join' ? '' : '#d6d8db';
  972. const data = {
  973. type: type,
  974. select: type === 'join' ? findNotJoinLeafXmj(select) : select,
  975. // gather_qty: select.gather_qty,
  976. ms_id: $('#myTab').find('.active').data('msid') || null,
  977. };
  978. // 添加到
  979. postData(window.location.pathname + '/save', data, function (result) {
  980. if (type === 'join') {
  981. const index = findNotJoinLeafXmj(select, 'index');
  982. notJoinList.splice(index, 1);
  983. } else {
  984. notJoinList.push(result);
  985. const index = findNotChangeLeafXmj(select, 'index');
  986. notChangeList.splice(index, 1);
  987. }
  988. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  989. calculateJiaCha(gclGatherData, iGclRow);
  990. SpreadJsObj.reLoadRowData(sheet, nRow);
  991. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  992. loadMaterialData(iGclRow);
  993. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  994. });
  995. },
  996. checkChangeMaterial: function (type) {
  997. const [iGclRow, iRow, nRow, sheet, select] = leafXmjSpreadObj.getSelect();
  998. const color = type === 'change' ? '' : '#FFE699';
  999. const data = {
  1000. type: type,
  1001. select: type === 'change' ? findNotChangeLeafXmj(select) : select,
  1002. // gather_qty: type === 'change' ? select.gather_qty : select.contract_qty,
  1003. ms_id: $('#myTab').find('.active').data('msid') || null,
  1004. };
  1005. // 添加到
  1006. postData(window.location.pathname + '/save', data, function (result) {
  1007. if (type === 'change') {
  1008. const index = findNotChangeLeafXmj(select, 'index');
  1009. notChangeList.splice(index, 1);
  1010. } else {
  1011. notChangeList.push(result);
  1012. }
  1013. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  1014. calculateJiaCha(gclGatherData, iGclRow);
  1015. SpreadJsObj.reLoadRowData(sheet, nRow);
  1016. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1017. loadMaterialData(iGclRow);
  1018. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1019. });
  1020. },
  1021. checkSelfMaterial: function (type) {
  1022. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  1023. // const color = type === 'self' ? '' : '#d6d8db';
  1024. const data = {
  1025. type: type,
  1026. select: type === 'noself' ? findSelfLeafXmj(select) : select,
  1027. ms_id: $('#myTab').find('.active').data('msid') || null,
  1028. };
  1029. if (type === 'noself') {
  1030. if (isStageSelf) {
  1031. data.select.gather_qty = {};
  1032. const ledgerSheet = ledgerSpread.getActiveSheet();
  1033. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1034. const index = gclGatherData.indexOf(ledgerSelect);
  1035. // 取所有的gclGatherData才行,然后获取下的值
  1036. const gclData = gclGatherData[index];
  1037. for (const [index, ms] of materialStageData.entries()) {
  1038. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1039. let gather_qty = null;
  1040. let contract_qty = null;
  1041. let qc_qty = null;
  1042. let qc_minus_qty = null;
  1043. if (gclOther) {
  1044. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1045. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1046. });
  1047. const oneXmj = _.find(leafXmjs, function (item) {
  1048. return item.gcl_id === select.gcl_id && item.id === select.id && (select.mx_id === undefined || item.mx_id === select.mx_id);
  1049. });
  1050. if (oneXmj) {
  1051. gather_qty = oneXmj.gather_qty;
  1052. contract_qty = oneXmj.contract_qty;
  1053. qc_qty = oneXmj.qc_qty;
  1054. qc_minus_qty = oneXmj.qc_minus_qty ? oneXmj.qc_minus_qty : null;
  1055. }
  1056. }
  1057. data.select.gather_qty['ms_id_' + ms.id] = gather_qty;
  1058. data.select.contract_qty['ms_id_' + ms.id] = contract_qty;
  1059. data.select.qc_qty['ms_id_' + ms.id] = qc_qty;
  1060. data.select.qc_minus_qty['ms_id_' + ms.id] = qc_minus_qty;
  1061. }
  1062. } else {
  1063. data.select.gather_qty = select.gather_qty ? select.gather_qty : null;
  1064. data.select.contract_qty = select.contract_qty ? select.contract_qty : null;
  1065. data.select.qc_qty = select.qc_qty ? select.qc_qty : null;
  1066. data.select.qc_minus_qty = select.qc_minus_qty ? select.qc_minus_qty : null;
  1067. }
  1068. }
  1069. console.log(data);
  1070. // 添加到
  1071. postData(window.location.pathname + '/save', data, function (result) {
  1072. if (type === 'noself') {
  1073. const index = findSelfLeafXmj(select, 'index');
  1074. selfList.splice(index, 1);
  1075. materialListData = result;
  1076. $('#cancel-self').modal('hide');
  1077. } else {
  1078. selfList.push(result.info);
  1079. materialListData = result.materialListData;
  1080. }
  1081. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(select);
  1082. calculateJiaCha(gclGatherData, iGclRow);
  1083. SpreadJsObj.reLoadRowData(sheet, nRow);
  1084. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1085. loadXmjMaterialData(iGclRow, nRow);
  1086. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1087. });
  1088. },
  1089. }
  1090. if (!readOnly) {
  1091. // leafXmj右键功能
  1092. if (!editForAudit) {
  1093. $.contextMenu({
  1094. selector: '#leaf-xmj-spread',
  1095. build: function ($trigger, e) {
  1096. const target = SpreadJsObj.safeRightClickSelection($trigger, e, leafXmjSpread);
  1097. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1098. },
  1099. items: {
  1100. 'stop': {
  1101. name: '当前节点不参与调差',
  1102. icon: 'fa-remove',
  1103. callback: function (key, opt) {
  1104. leafXmjSpreadObj.checkJoinMaterial('notjoin');
  1105. },
  1106. visible: function (key, opt) {
  1107. const sheet = leafXmjSpread.getActiveSheet();
  1108. const select = SpreadJsObj.getSelectObject(sheet);
  1109. const sel = sheet.getSelections()[0];
  1110. if (!select || sel.rowCount !== 1) {
  1111. return false;
  1112. }
  1113. const notx = findNotJoinLeafXmj(select);
  1114. if (!readOnly && select && notx === undefined) {
  1115. return true;
  1116. } else {
  1117. return false;
  1118. }
  1119. }
  1120. },
  1121. 'start': {
  1122. name: '当前节点参与调差',
  1123. icon: 'fa-sign-in',
  1124. callback: function (key, opt) {
  1125. leafXmjSpreadObj.checkJoinMaterial('join');
  1126. },
  1127. visible: function (key, opt) {
  1128. const sheet = leafXmjSpread.getActiveSheet();
  1129. const select = SpreadJsObj.getSelectObject(sheet);
  1130. const sel = sheet.getSelections()[0];
  1131. if (!select || sel.rowCount !== 1) {
  1132. return false;
  1133. }
  1134. const notx = findNotJoinLeafXmj(select);
  1135. if (!readOnly && select && notx === undefined) {
  1136. return false;
  1137. } else {
  1138. return true;
  1139. }
  1140. },
  1141. },
  1142. 'stop2': {
  1143. name: '数量变更不参与调差',
  1144. icon: 'fa-remove',
  1145. callback: function (key, opt) {
  1146. leafXmjSpreadObj.checkChangeMaterial('notchange');
  1147. },
  1148. visible: function (key, opt) {
  1149. const sheet = leafXmjSpread.getActiveSheet();
  1150. const select = SpreadJsObj.getSelectObject(sheet);
  1151. const sel = sheet.getSelections()[0];
  1152. if (!select || sel.rowCount !== 1) {
  1153. return false;
  1154. }
  1155. if (materialQtySource === qtySourceValueConst.contract_qty) {
  1156. return false;
  1157. }
  1158. const notx = findNotJoinLeafXmj(select);
  1159. if (!(!readOnly && select && notx === undefined)) {
  1160. return false;
  1161. }
  1162. const notx2 = findNotChangeLeafXmj(select);
  1163. if (!readOnly && select && notx2 === undefined) {
  1164. return true;
  1165. } else {
  1166. return false;
  1167. }
  1168. }
  1169. },
  1170. 'start2': {
  1171. name: '数量变更参与调差',
  1172. icon: 'fa-sign-in',
  1173. callback: function (key, opt) {
  1174. leafXmjSpreadObj.checkChangeMaterial('change');
  1175. },
  1176. visible: function (key, opt) {
  1177. const sheet = leafXmjSpread.getActiveSheet();
  1178. const select = SpreadJsObj.getSelectObject(sheet);
  1179. const sel = sheet.getSelections()[0];
  1180. if (!select || sel.rowCount !== 1) {
  1181. return false;
  1182. }
  1183. if (materialQtySource === qtySourceValueConst.contract_qty) {
  1184. return false;
  1185. }
  1186. const notx = findNotJoinLeafXmj(select);
  1187. if (!(!readOnly && select && notx === undefined)) {
  1188. return false;
  1189. }
  1190. const notx2 = findNotChangeLeafXmj(select);
  1191. if (!readOnly && select && notx2 === undefined) {
  1192. return false;
  1193. } else {
  1194. return true;
  1195. }
  1196. },
  1197. },
  1198. 'self': {
  1199. name: '单独添加工料',
  1200. icon: 'fa-sign-in',
  1201. callback: function (key, opt) {
  1202. leafXmjSpreadObj.checkSelfMaterial('self');
  1203. },
  1204. visible: function (key, opt) {
  1205. if (!openMaterialSelf) {
  1206. return false;
  1207. }
  1208. const sheet = leafXmjSpread.getActiveSheet();
  1209. const select = SpreadJsObj.getSelectObject(sheet);
  1210. const sel = sheet.getSelections()[0];
  1211. if (!select || sel.rowCount !== 1) {
  1212. return false;
  1213. }
  1214. const notx = findSelfLeafXmj(select);
  1215. if (!readOnly && select && notx === undefined) {
  1216. return true;
  1217. } else {
  1218. return false;
  1219. }
  1220. }
  1221. },
  1222. 'noself': {
  1223. name: '取消单独添加工料',
  1224. icon: 'fa-remove',
  1225. callback: function (key, opt) {
  1226. $('#cancel-self').modal('show');
  1227. // leafXmjSpreadObj.checkSelfMaterial('noself');
  1228. },
  1229. visible: function (key, opt) {
  1230. if (!openMaterialSelf) {
  1231. return false;
  1232. }
  1233. const sheet = leafXmjSpread.getActiveSheet();
  1234. const select = SpreadJsObj.getSelectObject(sheet);
  1235. const sel = sheet.getSelections()[0];
  1236. if (!select || sel.rowCount !== 1) {
  1237. return false;
  1238. }
  1239. const notx = findSelfLeafXmj(select);
  1240. if (!readOnly && select && notx === undefined) {
  1241. return false;
  1242. } else {
  1243. return true;
  1244. }
  1245. },
  1246. disabled: function (key, opt) {
  1247. // const sheet = ledgerSpread.getActiveSheet();
  1248. // const select = SpreadJsObj.getSelectObject(sheet);
  1249. // const index = gclGatherData.indexOf(select);
  1250. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1251. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1252. // const iRow = gclGatherData[index].leafXmjs.indexOf(leafXmjSelect);
  1253. // const leafXmjs = gclGatherData[index].leafXmjs.filter(item => {
  1254. // return item.qc_qty || item.contract_qty
  1255. // });
  1256. // const nRow = leafXmjs.indexOf(leafXmjSelect);
  1257. // const leafXmjColor = findNotJoinLeafXmj(leafXmjSelect) ? '#d6d8db' : '';
  1258. // return [index, iRow, nRow, leafXmjSheet, leafXmjSelect, leafXmjColor];
  1259. const [iGclRow, iRow, nRow, sheet, select, color] = leafXmjSpreadObj.getSelect();
  1260. const gcl = gclGatherData[iGclRow];
  1261. const leafXmjs = gcl && gcl.leafXmjs ? gcl.leafXmjs.filter(item => {
  1262. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1263. }) : null;
  1264. let flag = false;
  1265. if (leafXmjs) {
  1266. const xmj = leafXmjs[nRow];
  1267. if (_.findIndex(selfList, { gcl_id: xmj.gcl_id, xmj_id: xmj.id, mx_id: (xmj.mx_id ? xmj.mx_id : '') }) != -1) {
  1268. for (const m of materialListData) {
  1269. if (m.gcl_id === xmj.gcl_id && m.xmj_id === xmj.id && ((xmj.mx_id !==undefined && m.mx_id === xmj.mx_id) || xmj.mx_id === undefined) && m.order !== stage_order) {
  1270. flag = true;
  1271. break;
  1272. }
  1273. }
  1274. }
  1275. }
  1276. return flag;
  1277. },
  1278. },
  1279. }
  1280. });
  1281. $('#cancelSelfBtn').click(function () {
  1282. leafXmjSpreadObj.checkSelfMaterial('noself');
  1283. });
  1284. }
  1285. // material-spread右键功能
  1286. const materialSpreadObj = {
  1287. del: function () {
  1288. const materialSheet = materialSpread.getActiveSheet();
  1289. const materialSelect = SpreadJsObj.getSelectObject(materialSheet);
  1290. const sheet = ledgerSpread.getActiveSheet();
  1291. const select = SpreadJsObj.getSelectObject(sheet);
  1292. const index = gclGatherData.indexOf(select);
  1293. // const leafXmjSheet = leafXmjSpread.getActiveSheet();
  1294. // const leafXmjSelect = SpreadJsObj.getSelectObject(leafXmjSheet);
  1295. const gcl = gclGatherData[index].leafXmjs;
  1296. // const leafXmjIndex = gcl.indexOf(leafXmjSelect);
  1297. const datas = [];
  1298. for (const xmj of gcl) {
  1299. const data = {
  1300. xmj_id: xmj.id,
  1301. gcl_id: xmj.gcl_id,
  1302. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1303. };
  1304. datas.push(data);
  1305. }
  1306. if (isStageSelf) {
  1307. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1308. // 取所有的gclGatherData才行,然后获取下的值
  1309. const gclData = gclGatherData[index];
  1310. for (const [index, ms] of materialStageData.entries()) {
  1311. if (ms.id !== ms_id) {
  1312. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1313. if (gclOther) {
  1314. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1315. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1316. });
  1317. for (const xmj of leafXmjs) {
  1318. const data = {
  1319. xmj_id: xmj.id,
  1320. gcl_id: xmj.gcl_id,
  1321. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1322. };
  1323. if (_.indexOf(datas, data) === -1) {
  1324. datas.push(data);
  1325. }
  1326. }
  1327. }
  1328. }
  1329. }
  1330. }
  1331. console.log(datas, materialSelect.mb_id);
  1332. postData(window.location.pathname + '/save', {type: 'dels', postData: { xmjs: datas, mb_id: materialSelect.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null}, function (result) {
  1333. materialListData = result.materialListData;
  1334. gclList = result.gclList;
  1335. calculateJiaCha(gclGatherData);
  1336. // const index = gclGatherData.indexOf(ledgerSelect);
  1337. loadLeafXmjData(index);
  1338. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1339. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1340. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1341. loadMaterialData(index);
  1342. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1343. });
  1344. // postData(window.location.pathname + '/save', {type: 'del', id: select.id, mb_id: select.mb_id}, function (result) {
  1345. // const index = materialList.indexOf(select);
  1346. // materialList.splice(index, 1);
  1347. // sheet.deleteRows(index, 1);
  1348. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1349. // const sel = sheet.getSelections();
  1350. // sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1351. // const materialListIndex = materialListData.indexOf(select);
  1352. // materialListData.splice(materialListIndex, 1);
  1353. // const [iGclRow, iRow, lsheet, lselect] = leafXmjSpreadObj.getSelect();
  1354. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1355. // calculateJiaCha(gclGatherData, iGclRow);
  1356. // SpreadJsObj.reLoadRowData(lsheet, iRow);
  1357. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1358. // });
  1359. },
  1360. deletePress: function (sheet) {
  1361. return;
  1362. },
  1363. editStarting: function (e, info) {
  1364. const col = info.sheet.zh_setting.cols[info.col];
  1365. const select = SpreadJsObj.getSelectObject(info.sheet);
  1366. if (col.field === 'quantity') {
  1367. if (select.expr && select.expr !== '') {
  1368. info.sheet.getCell(info.row, info.col).text(select.expr);
  1369. }
  1370. }
  1371. },
  1372. editEnded: function (e, info) {
  1373. if (info.sheet.zh_setting) {
  1374. const select = SpreadJsObj.getSelectObject(info.sheet);
  1375. const col = info.sheet.zh_setting.cols[info.col];
  1376. // 未改变值则不提交
  1377. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1378. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1379. // let orgValue = select[col.field];
  1380. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1381. let orgValue;
  1382. if (col.field === 'quantity') {
  1383. orgValue = validText && validText !== ''
  1384. ? _.toNumber(validText) ? select.quantity : select.expr
  1385. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1386. } else {
  1387. orgValue = select[col.field];
  1388. }
  1389. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1390. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1391. return;
  1392. }
  1393. const exprQuantity = {
  1394. expr: '',
  1395. quantity: 0,
  1396. };
  1397. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1398. if (!valid) {
  1399. toastr.error(msg);
  1400. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1401. return;
  1402. }
  1403. if (isNaN(exprQuantity.quantity)) {
  1404. toastr.error('不能输入其它非数字类型字符');
  1405. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1406. return;
  1407. }
  1408. const num = parseFloat(exprQuantity.quantity);
  1409. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1410. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1411. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1412. // return;
  1413. toastr.warning('已保留6位小数');
  1414. exprQuantity.quantity = ZhCalc.round(num, 6);
  1415. }
  1416. // 更新至服务器
  1417. const ledgerSheet = ledgerSpread.getActiveSheet();
  1418. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1419. const index = gclGatherData.indexOf(ledgerSelect);
  1420. const gcl = gclGatherData[index].leafXmjs;
  1421. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1422. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1423. // const xmjIndex = gcl.indexOf(xmjSelect);
  1424. const datas = [];
  1425. for (const xmj of gcl) {
  1426. const data = {
  1427. xmj_id: xmj.id,
  1428. gcl_id: xmj.gcl_id,
  1429. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1430. };
  1431. datas.push(data);
  1432. }
  1433. if (isStageSelf) {
  1434. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1435. // 取所有的gclGatherData才行,然后获取下的值
  1436. const gclData = gclGatherData[index];
  1437. for (const [index, ms] of materialStageData.entries()) {
  1438. if (ms.id !== ms_id) {
  1439. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1440. if (gclOther) {
  1441. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1442. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1443. });
  1444. for (const xmj of leafXmjs) {
  1445. const data = {
  1446. xmj_id: xmj.id,
  1447. gcl_id: xmj.gcl_id,
  1448. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1449. };
  1450. if (_.indexOf(datas, data) === -1) {
  1451. datas.push(data);
  1452. }
  1453. }
  1454. }
  1455. }
  1456. }
  1457. }
  1458. console.log(exprQuantity, datas, select.mb_id);
  1459. postData(window.location.pathname + '/save', { type:'updates', updateData: { xmjs: datas, expr: exprQuantity.expr, quantity: exprQuantity.quantity, mb_id: select.mb_id }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1460. materialListData = result.materialListData;
  1461. gclList = result.gclList;
  1462. calculateJiaCha(gclGatherData);
  1463. // const index = gclGatherData.indexOf(ledgerSelect);
  1464. loadLeafXmjData(index);
  1465. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1466. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1467. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1468. loadMaterialData(index);
  1469. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1470. materialSpread.getActiveSheet().setSelection(info.row + 1, info.col, 1, 1);
  1471. }, function () {
  1472. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1473. });
  1474. // postData(window.location.pathname + '/save', { type:'update', updateData: { id:select.id, quantity: validText, mb_id: select.mb_id } }, function (result) {
  1475. // const materialListIndex = materialListData.indexOf(select);
  1476. // const index = materialList.indexOf(select);
  1477. // select[col.field] = validText;
  1478. // materialListData.splice(materialListIndex, 1, select);
  1479. // materialList.indexOf(index, 1, select);
  1480. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1481. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1482. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1483. // calculateJiaCha(gclGatherData, iGclRow)
  1484. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1485. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1486. // }, function () {
  1487. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1488. // });
  1489. }
  1490. },
  1491. clipboardPasted(e, info) {
  1492. const hint = {
  1493. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1494. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1495. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1496. };
  1497. const range = info.cellRange;
  1498. const sortData = info.sheet.zh_data || [];
  1499. if (range.row + range.rowCount > sortData.length) {
  1500. toastMessageUniq(hint.cellError);
  1501. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1502. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1503. return;
  1504. }
  1505. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1506. toastMessageUniq(hint.cellError);
  1507. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1508. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1509. return;
  1510. }
  1511. const data = [];
  1512. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1513. let bPaste = true;
  1514. const curRow = range.row + iRow;
  1515. const materialData = { id: sortData[curRow].id, mb_id: sortData[curRow].mb_id };
  1516. const hintRow = range.rowCount > 1 ? curRow : '';
  1517. let sameCol = 0;
  1518. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1519. const curCol = range.col + iCol;
  1520. const colSetting = info.sheet.zh_setting.cols[curCol];
  1521. if (!colSetting) continue;
  1522. // let validText = info.sheet.getText(curRow, curCol);
  1523. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1524. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1525. const orgValue = sortData[curRow][colSetting.field];
  1526. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1527. sameCol++;
  1528. if (range.colCount === sameCol) {
  1529. bPaste = false;
  1530. }
  1531. continue;
  1532. }
  1533. const exprQuantity = {
  1534. expr: '',
  1535. quantity: 0,
  1536. };
  1537. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1538. if (!valid) {
  1539. toastMessageUniq(getPasteHint(msg, hintRow));
  1540. bPaste = false;
  1541. continue;
  1542. }
  1543. if (isNaN(exprQuantity.quantity)) {
  1544. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1545. bPaste = false;
  1546. continue;
  1547. }
  1548. const num = parseFloat(exprQuantity.quantity);
  1549. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1550. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1551. // bPaste = false;
  1552. // continue;
  1553. exprQuantity.quantity = ZhCalc.round(num, 6);
  1554. }
  1555. // materialData[colSetting.field] = validText;
  1556. materialData.expr = exprQuantity.expr;
  1557. materialData.quantity = exprQuantity.quantity;
  1558. }
  1559. if (bPaste) {
  1560. data.push(materialData);
  1561. // rowData.push(curRow);
  1562. } else {
  1563. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1564. }
  1565. }
  1566. if (data.length === 0) {
  1567. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1568. return;
  1569. }
  1570. const ledgerSheet = ledgerSpread.getActiveSheet();
  1571. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  1572. const index = gclGatherData.indexOf(ledgerSelect);
  1573. const gcl = gclGatherData[index].leafXmjs;
  1574. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1575. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1576. // const xmjIndex = gcl.indexOf(xmjSelect);
  1577. const datas = [];
  1578. for (const xmj of gcl) {
  1579. const data2 = {
  1580. xmj_id: xmj.id,
  1581. gcl_id: xmj.gcl_id,
  1582. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1583. };
  1584. datas.push(data2);
  1585. }
  1586. if (isStageSelf) {
  1587. const ms_id = isStageSelf ? parseInt($('#myTab').find('.active').data('msid')) : null;
  1588. // 取所有的gclGatherData才行,然后获取下的值
  1589. const gclData = gclGatherData[index];
  1590. for (const [index, ms] of materialStageData.entries()) {
  1591. if (ms.id !== ms_id) {
  1592. const gclOther = _.find(gclGatherListData[index], { b_code: gclData.b_code, name: gclData.name, unit: gclData.unit, unit_price: gclData.unit_price });
  1593. if (gclOther) {
  1594. const leafXmjs = gclOther.leafXmjs.filter(item => {
  1595. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  1596. });
  1597. for (const xmj of leafXmjs) {
  1598. const data = {
  1599. xmj_id: xmj.id,
  1600. gcl_id: xmj.gcl_id,
  1601. mx_id: xmj.mx_id ? xmj.mx_id : '',
  1602. };
  1603. if (_.indexOf(datas, data) === -1) {
  1604. datas.push(data);
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. console.log(data, datas);
  1612. // 更新至服务器
  1613. postData(window.location.pathname + '/save', { type:'pastes', updateData: { xmjs: datas, pasteData: data }, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1614. materialListData = result.materialListData;
  1615. gclList = result.gclList;
  1616. calculateJiaCha(gclGatherData);
  1617. // const index = gclGatherData.indexOf(ledgerSelect);
  1618. loadLeafXmjData(index);
  1619. // const xmjSheet = leafXmjSpread.getActiveSheet();
  1620. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  1621. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  1622. loadMaterialData(index);
  1623. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  1624. materialSpread.getActiveSheet().setSelection(info.cellRange.row, info.cellRange.col, info.cellRange.rowCount, info.cellRange.colCount);
  1625. }, function () {
  1626. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1627. });
  1628. // postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  1629. // materialListData = result;
  1630. // const [iGclRow, iRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1631. // gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1632. // calculateJiaCha(gclGatherData, iGclRow);
  1633. // SpreadJsObj.reLoadRowData(sheet, iRow);
  1634. // SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1635. // }, function () {
  1636. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1637. // });
  1638. },
  1639. _checkExprValid(expr) {
  1640. if (!expr) return [true, null];
  1641. const param = [];
  1642. let num = '', base = '';
  1643. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1644. if (/^[\d\.%]+/.test(expr[i])) {
  1645. if (base !== '') {
  1646. param.push({type: 'base', value: base});
  1647. base = '';
  1648. }
  1649. num = num + expr[i];
  1650. } else if (expr[i] === '(') {
  1651. if (num !== '') {
  1652. param.push({type: 'num', value: num});
  1653. num = '';
  1654. }
  1655. if (base !== '') {
  1656. param.push({type: 'base', value: base});
  1657. base = '';
  1658. }
  1659. param.push({type: 'left', value: '('});
  1660. } else if (expr[i] === ')') {
  1661. if (num !== '') {
  1662. param.push({type: 'num', value: num});
  1663. num = '';
  1664. }
  1665. if (base !== '') {
  1666. param.push({type: 'base', value: base});
  1667. base = '';
  1668. }
  1669. param.push({type: 'right', value: ')'});
  1670. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1671. if (num !== '') {
  1672. param.push({type: 'num', value: num});
  1673. num = '';
  1674. }
  1675. if (base !== '') {
  1676. param.push({type: 'base', value: base});
  1677. base = '';
  1678. }
  1679. param.push({type: 'calc', value: expr[i]});
  1680. } else {
  1681. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1682. }
  1683. }
  1684. if (num !== '') {
  1685. param.push({type: 'num', value: num});
  1686. num = '';
  1687. }
  1688. if (base !== '') {
  1689. param.push({type: 'base', value: base});
  1690. base = '';
  1691. }
  1692. if (param.length === 0) return true;
  1693. if (param.length > 1) {
  1694. if (param[0].value === '-') {
  1695. param[1].value = '-' + param[1];
  1696. }
  1697. param.unshift();
  1698. }
  1699. const iLen = param.length;
  1700. let iLeftCount = 0, iRightCount = 0;
  1701. for (const [i, p] of param.entries()) {
  1702. if (p.type === 'calc') {
  1703. if (i === 0 || i === iLen - 1)
  1704. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字'];
  1705. }
  1706. if (p.type === 'num') {
  1707. num = p.value.replace('%', '');
  1708. if (p.value.length - num.length > 1)
  1709. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1710. num = _.toNumber(num);
  1711. if (num === undefined || num === null || _.isNaN(num))
  1712. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1713. if (i > 0) {
  1714. if (param[i - 1].type !== 'calc' && param[i - 1].type !== 'left') {
  1715. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1716. } else if (param[i - 1].value === '/' && num === 0) {
  1717. return [false, '输入的表达式非法:请勿除0'];
  1718. }
  1719. }
  1720. }
  1721. if (p.type === 'base') {
  1722. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1723. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1724. }
  1725. if (p.type === 'left') {
  1726. iLeftCount += 1;
  1727. if (i !== 0 && param[i-1].type !== 'calc')
  1728. return [false, '输入的表达式非法:(前应有运算符'];
  1729. }
  1730. if (p.type === 'right') {
  1731. iRightCount += 1;
  1732. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1733. return [false, '输入的表达式非法:)后应有运算符'];
  1734. if (iRightCount > iLeftCount)
  1735. return [false, '输入的表达式非法:")"前无对应的"("'];
  1736. }
  1737. }
  1738. if (iLeftCount > iRightCount)
  1739. return [false, '输入的表达式非法:"("后无对应的")"'];
  1740. return [true, ''];
  1741. },
  1742. _checkExpr: function (text, data) {
  1743. if (text) {
  1744. const num = _.toNumber(text);
  1745. if (num) {
  1746. data.quantity = num;
  1747. data.expr = '';
  1748. } else {
  1749. const expr = $.trim(text).replace('\t', '').replace('=', '').toLowerCase();
  1750. const [valid, msg] = this._checkExprValid(expr);
  1751. if (!valid) return [valid, msg];
  1752. data.expr = expr;
  1753. data.quantity = ZhCalc.calcExpr.calcExprStrRpn(expr.replace('%', '/100'));
  1754. // const ce = new CalcEvalMin();
  1755. // data.quantity = ce.eval(expr);
  1756. // console.log(data.quantity);
  1757. }
  1758. } else {
  1759. data.quantity = 0;
  1760. data.expr = '';
  1761. }
  1762. return [true, ''];
  1763. },
  1764. };
  1765. materialSpread.bind(spreadNS.Events.EditStarting, materialSpreadObj.editStarting);
  1766. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1767. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  1768. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  1769. // material-spread右键功能
  1770. if (openMaterialSelf) {
  1771. const materialSelfSpreadObj = {
  1772. del: function () {
  1773. const sheet = materialSelfSpread.getActiveSheet();
  1774. const select = SpreadJsObj.getSelectObject(sheet);
  1775. console.log(select);
  1776. postData(window.location.pathname + '/save', {
  1777. type: 'del',
  1778. id: select.id,
  1779. mb_id: select.mb_id,
  1780. ms_id: $('#myTab').find('.active').data('msid') || null
  1781. }, function (result) {
  1782. const index = materialListSelf.indexOf(select);
  1783. materialListSelf.splice(index, 1);
  1784. sheet.deleteRows(index, 1);
  1785. SpreadJsObj.reLoadSheetData(materialSelfSpread.getActiveSheet());
  1786. const sel = sheet.getSelections();
  1787. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  1788. const materialListIndex = materialListData.indexOf(select);
  1789. materialListData.splice(materialListIndex, 1);
  1790. const [iGclRow, iRow, nRow, lsheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1791. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1792. calculateJiaCha(gclGatherData, iGclRow);
  1793. SpreadJsObj.reLoadRowData(lsheet, nRow);
  1794. lsheet.getRange(nRow, -1, 1, -1).backColor(color);
  1795. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1796. });
  1797. },
  1798. deletePress: function (sheet) {
  1799. return;
  1800. },
  1801. editStarting: function (e, info) {
  1802. const col = info.sheet.zh_setting.cols[info.col];
  1803. const select = SpreadJsObj.getSelectObject(info.sheet);
  1804. if (col.field === 'quantity') {
  1805. if (select.expr && select.expr !== '') {
  1806. info.sheet.getCell(info.row, info.col).text(select.expr);
  1807. }
  1808. }
  1809. },
  1810. editEnded: function (e, info) {
  1811. if (info.sheet.zh_setting) {
  1812. const select = SpreadJsObj.getSelectObject(info.sheet);
  1813. const col = info.sheet.zh_setting.cols[info.col];
  1814. // 未改变值则不提交
  1815. // const validText = info.editingText ? (typeof(info.editingText) === 'String' ? info.editingText.replace('\n', '') : info.editingText) : null;
  1816. // const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  1817. // let orgValue = select[col.field];
  1818. const validText = info.editingText ? info.editingText.replace('\n', '') : null;
  1819. let orgValue;
  1820. if (col.field === 'quantity') {
  1821. orgValue = validText && validText !== ''
  1822. ? _.toNumber(validText) ? select.quantity : select.expr
  1823. : (select.expr && select.expr !== '') ? select.expr : select.quantity;
  1824. } else {
  1825. orgValue = select[col.field];
  1826. }
  1827. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === '' || validText === null))) {
  1828. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1829. return;
  1830. }
  1831. const exprQuantity = {
  1832. expr: '',
  1833. quantity: 0,
  1834. };
  1835. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1836. if (!valid) {
  1837. toastr.error(msg);
  1838. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1839. return;
  1840. }
  1841. if (isNaN(exprQuantity.quantity)) {
  1842. toastr.error('不能输入其它非数字类型字符');
  1843. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1844. return;
  1845. }
  1846. const num = parseFloat(exprQuantity.quantity);
  1847. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1848. // toastr.error('数量值必须大于0并且小于6位小数的浮点数');
  1849. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1850. // return;
  1851. toastr.warning('已保留6位小数');
  1852. exprQuantity.quantity = ZhCalc.round(num, 6);
  1853. }
  1854. // 更新至服务器
  1855. console.log(exprQuantity, select.mb_id);
  1856. postData(window.location.pathname + '/save', {
  1857. type: 'update',
  1858. updateData: {
  1859. id: select.id,
  1860. expr: exprQuantity.expr,
  1861. quantity: exprQuantity.quantity,
  1862. mb_id: select.mb_id
  1863. },
  1864. ms_id: $('#myTab').find('.active').data('msid') || null
  1865. }, function (result) {
  1866. const materialListIndex = materialListData.indexOf(select);
  1867. const index = materialList.indexOf(select);
  1868. select.quantity = exprQuantity.quantity;
  1869. select.expr = exprQuantity.expr;
  1870. materialListData.splice(materialListIndex, 1, select);
  1871. materialList.indexOf(index, 1, select);
  1872. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1873. const [iGclRow, iRow, nRow, sheet, lselect, color] = leafXmjSpreadObj.getSelect();
  1874. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1875. calculateJiaCha(gclGatherData, iGclRow);
  1876. SpreadJsObj.reLoadRowData(sheet, nRow);
  1877. console.log(lselect, color);
  1878. sheet.getRange(nRow, -1, 1, -1).backColor(color);
  1879. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1880. }, function () {
  1881. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1882. });
  1883. }
  1884. },
  1885. clipboardPasted(e, info) {
  1886. const hint = {
  1887. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1888. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1889. numberCan: {type: 'warning', msg: '已保留6位小数'},
  1890. };
  1891. const range = info.cellRange;
  1892. const sortData = info.sheet.zh_data || [];
  1893. if (range.row + range.rowCount > sortData.length) {
  1894. toastMessageUniq(hint.cellError);
  1895. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1896. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1897. return;
  1898. }
  1899. if (sortData.length > 0 && range.col + range.colCount > 5) {
  1900. toastMessageUniq(hint.cellError);
  1901. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  1902. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1903. return;
  1904. }
  1905. const data = [];
  1906. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1907. let bPaste = true;
  1908. const curRow = range.row + iRow;
  1909. const materialData = {id: sortData[curRow].id, mb_id: sortData[curRow].mb_id};
  1910. const hintRow = range.rowCount > 1 ? curRow : '';
  1911. let sameCol = 0;
  1912. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1913. const curCol = range.col + iCol;
  1914. const colSetting = info.sheet.zh_setting.cols[curCol];
  1915. if (!colSetting) continue;
  1916. // let validText = info.sheet.getText(curRow, curCol);
  1917. // validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1918. const validText = info.sheet.getText(curRow, curCol).replace('\n', '');
  1919. const orgValue = sortData[curRow][colSetting.field];
  1920. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1921. sameCol++;
  1922. if (range.colCount === sameCol) {
  1923. bPaste = false;
  1924. }
  1925. continue;
  1926. }
  1927. const exprQuantity = {
  1928. expr: '',
  1929. quantity: 0,
  1930. };
  1931. const [valid, msg] = materialSpreadObj._checkExpr(validText, exprQuantity);
  1932. if (!valid) {
  1933. toastMessageUniq(getPasteHint(msg, hintRow));
  1934. bPaste = false;
  1935. continue;
  1936. }
  1937. if (isNaN(exprQuantity.quantity)) {
  1938. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1939. bPaste = false;
  1940. continue;
  1941. }
  1942. const num = parseFloat(exprQuantity.quantity);
  1943. if (num < 0 || !/^\d+(\.\d{1,6})?$/.test(num)) {
  1944. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1945. // bPaste = false;
  1946. // continue;
  1947. exprQuantity.quantity = ZhCalc.round(num, 6);
  1948. }
  1949. // materialData[colSetting.field] = validText;
  1950. materialData.expr = exprQuantity.expr;
  1951. materialData.quantity = exprQuantity.quantity;
  1952. }
  1953. if (bPaste) {
  1954. data.push(materialData);
  1955. // rowData.push(curRow);
  1956. } else {
  1957. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1958. }
  1959. }
  1960. if (data.length === 0) {
  1961. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1962. return;
  1963. }
  1964. console.log(data);
  1965. postData(window.location.pathname + '/save', {
  1966. type: 'paste',
  1967. updateData: data,
  1968. ms_id: $('#myTab').find('.active').data('msid') || null
  1969. }, function (result) {
  1970. materialListData = result;
  1971. const [iGclRow, iRow, nRow, sheet, lselect] = leafXmjSpreadObj.getSelect();
  1972. gclGatherData[iGclRow].leafXmjs[iRow].jiacha = calcOneBQJC(lselect);
  1973. calculateJiaCha(gclGatherData, iGclRow);
  1974. SpreadJsObj.reLoadRowData(sheet, nRow);
  1975. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), iGclRow);
  1976. loadXmjMaterialData(iGclRow, nRow);
  1977. }, function () {
  1978. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1979. });
  1980. },
  1981. };
  1982. materialSelfSpread.bind(spreadNS.Events.EditStarting, materialSelfSpreadObj.editStarting);
  1983. materialSelfSpread.bind(spreadNS.Events.EditEnded, materialSelfSpreadObj.editEnded);
  1984. materialSelfSpread.bind(spreadNS.Events.ClipboardPasted, materialSelfSpreadObj.clipboardPasted);
  1985. SpreadJsObj.addDeleteBind(materialSelfSpread, materialSelfSpreadObj.deletePress);
  1986. if (!editForAudit) {
  1987. $.contextMenu({
  1988. selector: '#material-self-spread',
  1989. build: function ($trigger, e) {
  1990. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSelfSpread);
  1991. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1992. },
  1993. items: {
  1994. 'create': {
  1995. name: '添加工料',
  1996. icon: 'fa-sign-in',
  1997. callback: function (key, opt) {
  1998. // 获取已选清单
  1999. changeMaterialTable('self');
  2000. $('#add_type').val('self');
  2001. $('#addgl').modal('show');
  2002. },
  2003. disabled: function (key, opt) {
  2004. const sheet = leafXmjSpread.getActiveSheet();
  2005. const select = SpreadJsObj.getSelectObject(sheet);
  2006. // const notx = findNotJoinLeafXmj(select);
  2007. if (!select) {
  2008. return true;
  2009. }
  2010. // if (!readOnly && notx === undefined) {
  2011. // return false;
  2012. // } else {
  2013. // return true;
  2014. // }
  2015. return readOnly;
  2016. },
  2017. },
  2018. 'delete': {
  2019. name: '删除工料',
  2020. icon: 'fa-remove',
  2021. callback: function (key, opt) {
  2022. materialSelfSpreadObj.del(materialSelfSpread.getActiveSheet());
  2023. },
  2024. disabled: function (key, opt) {
  2025. const sheet = materialSelfSpread.getActiveSheet();
  2026. const select = SpreadJsObj.getSelectObject(sheet);
  2027. if (!select) {
  2028. return true;
  2029. }
  2030. if (!readOnly && select && materialSelfBase.isEdit(select, 'del')) {
  2031. return false;
  2032. } else {
  2033. return true;
  2034. }
  2035. }
  2036. },
  2037. }
  2038. });
  2039. }
  2040. }
  2041. if (!openMaterialChecklist && !editForAudit) {
  2042. $.contextMenu({
  2043. selector: '#material-spread',
  2044. build: function ($trigger, e) {
  2045. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  2046. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  2047. },
  2048. items: {
  2049. 'create': {
  2050. name: '添加工料',
  2051. icon: 'fa-sign-in',
  2052. callback: function (key, opt) {
  2053. // 获取已选清单
  2054. changeMaterialTable();
  2055. $('#add_type').val('all');
  2056. $('#addgl').modal('show');
  2057. },
  2058. disabled: function (key, opt) {
  2059. const sheet = leafXmjSpread.getActiveSheet();
  2060. const select = SpreadJsObj.getSelectObject(sheet);
  2061. // const notx = findNotJoinLeafXmj(select);
  2062. if (!select) {
  2063. return true;
  2064. }
  2065. // if (!readOnly && notx === undefined) {
  2066. // return false;
  2067. // } else {
  2068. // return true;
  2069. // }
  2070. return readOnly;
  2071. }
  2072. },
  2073. 'delete': {
  2074. name: '删除工料',
  2075. icon: 'fa-remove',
  2076. callback: function (key, opt) {
  2077. materialSpreadObj.del(materialSpread.getActiveSheet());
  2078. },
  2079. disabled: function (key, opt) {
  2080. const sheet = materialSpread.getActiveSheet();
  2081. const select = SpreadJsObj.getSelectObject(sheet);
  2082. if (!select) {
  2083. return true;
  2084. }
  2085. if (!readOnly && select && materialBase.isEdit(select, 'del')) {
  2086. return false;
  2087. } else {
  2088. return true;
  2089. }
  2090. }
  2091. },
  2092. }
  2093. });
  2094. }
  2095. }
  2096. // 应用调差工料至其他清单明细
  2097. $('#user_all_material').click(function () {
  2098. const ledgerSheet = ledgerSpread.getActiveSheet();
  2099. const ledgerSelect = SpreadJsObj.getSelectObject(ledgerSheet);
  2100. if (ledgerSelect.leafXmjs.length < 2) {
  2101. toastr.warning('没有需要应用调差工料的其它清单明细');
  2102. return false;
  2103. }
  2104. const xmjSheet = leafXmjSpread.getActiveSheet();
  2105. const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  2106. console.log(ledgerSelect.leafXmjs);
  2107. // 判断需要应用调差工料的清单明细
  2108. const needAddList = [];
  2109. for (const xmj of ledgerSelect.leafXmjs) {
  2110. const notx = findNotJoinLeafXmj(xmj);
  2111. if (notx === undefined && xmjSelect !== xmj && xmj.gather_qty && xmj.jiacha === null && xmjSelect.jiacha !== null) {
  2112. needAddList.push(xmj);
  2113. }
  2114. }
  2115. // if (needAddList.length === 0) {
  2116. // toastr.warning('没有需要应用调差工料的其它清单明细');
  2117. // return false;
  2118. // }
  2119. console.log(needAddList, materialList);
  2120. // 更新至服务器
  2121. postData(window.location.pathname + '/save', { type:'useOther', postData: { addXmj: needAddList, materialBills: materialList } }, function (result) {
  2122. materialListData = result.materialListData;
  2123. gclList = result.gclList;
  2124. toastr.success('已成功应用');
  2125. calculateJiaCha(gclGatherData);
  2126. const index = gclGatherData.indexOf(ledgerSelect);
  2127. loadLeafXmjData(index);
  2128. // const xmjSheet = leafXmjSpread.getActiveSheet();
  2129. // const xmjSelect = SpreadJsObj.getSelectObject(xmjSheet);
  2130. // const xmjIndex = gclGatherData[index].leafXmjs.indexOf(xmjSelect);
  2131. loadMaterialData(index);
  2132. SpreadJsObj.reLoadRowData(ledgerSpread.getActiveSheet(), index);
  2133. });
  2134. });
  2135. // 切换清单行,读取所属项目节数据
  2136. ledgerSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2137. if (info.oldSelections !== undefined) {
  2138. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  2139. if (iNewRow !== iOldRow) {
  2140. loadLeafXmjData(iNewRow);
  2141. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  2142. loadMaterialData(iNewRow);
  2143. loadXmjMaterialData(iNewRow, 0);
  2144. checkNotJoinMaterialData();
  2145. }
  2146. }
  2147. });
  2148. // 切换项目节数据清单明细行,读取单独的清单工料数据
  2149. leafXmjSpread.getActiveSheet().bind(spreadNS.Events.SelectionChanged, function (e, info) {
  2150. if (info.oldSelections !== undefined) {
  2151. const iOldRow = info.oldSelections[0].row, iNewRow = info.newSelections[0].row;
  2152. if (iNewRow !== iOldRow) {
  2153. const sheet = ledgerSpread.getActiveSheet();
  2154. const select = SpreadJsObj.getSelectObject(sheet);
  2155. const index = gclGatherData.indexOf(select);
  2156. loadXmjMaterialData(index, iNewRow);
  2157. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  2158. }
  2159. }
  2160. });
  2161. // 显示有调差工料清单
  2162. $('#show_material_gcl').click(function () {
  2163. if ($(this).is(':checked')) {
  2164. const hadMaterialGclGatherData = [];
  2165. const hadGclIdList = [];
  2166. for (const ml of materialListData) {
  2167. if (hadGclIdList.indexOf(ml.gcl_id) === -1) {
  2168. hadGclIdList.push(ml.gcl_id);
  2169. }
  2170. }
  2171. for (const gcl of gclGatherData) {
  2172. for (const index in gcl.leafXmjs) {
  2173. const gcl_id = gcl.leafXmjs[index].gcl_id;
  2174. if (hadGclIdList.indexOf(gcl_id) !== -1) {
  2175. hadMaterialGclGatherData.push(gcl);
  2176. break;
  2177. }
  2178. }
  2179. }
  2180. gclGatherData = hadMaterialGclGatherData;
  2181. } else {
  2182. if (isStageSelf) {
  2183. const ms_id = parseInt($('#myTab').find('.active').data('msid'));
  2184. updateBillsData(ms_id);
  2185. const i = _.findIndex(materialStageData, { id: ms_id });
  2186. gclGatherData = gclGatherListData[i];
  2187. } else {
  2188. gclGatherModel.loadLedgerData(_.cloneDeep(ledger), curLedgerData);
  2189. gclGatherModel.loadPosData(_.cloneDeep(pos), curPosData);
  2190. gclGatherData = gclGatherModel.gatherGclData().filter(item => {
  2191. return item.qc_qty || item.contract_qty || item.qc_minus_qty
  2192. });
  2193. }
  2194. if (openMaterialChecklist) {
  2195. // 取交集
  2196. gclGatherData = _.filter(gclGatherData, function (item) {
  2197. return _.find(materialChecklistData, { b_code: item.b_code, name: item.name, unit: item.unit, unit_price: item.unit_price });
  2198. });
  2199. }
  2200. }
  2201. calculateJiaCha(gclGatherData);
  2202. SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Data, gclGatherData);
  2203. loadLeafXmjData(0);
  2204. loadMaterialData(0);
  2205. loadXmjMaterialData(0, 0);
  2206. SpreadJsObj.resetTopAndSelect(ledgerSpread.getActiveSheet());
  2207. SpreadJsObj.resetTopAndSelect(leafXmjSpread.getActiveSheet());
  2208. SpreadJsObj.resetTopAndSelect(materialSpread.getActiveSheet());
  2209. SpreadJsObj.resetTopAndSelect(materialSelfSpread.getActiveSheet());
  2210. checkNotJoinMaterialData();
  2211. });
  2212. $.subMenu({
  2213. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  2214. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  2215. key: 'menu.1.0.0',
  2216. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  2217. callback: function (info) {
  2218. if (info.mini) {
  2219. $('.panel-title').addClass('fluid');
  2220. $('#sub-menu').removeClass('panel-sidebar');
  2221. } else {
  2222. $('.panel-title').removeClass('fluid');
  2223. $('#sub-menu').addClass('panel-sidebar');
  2224. }
  2225. autoFlashHeight();
  2226. ledgerSpread.refresh();
  2227. leafXmjSpread.refresh();
  2228. materialSpread.refresh();
  2229. materialSelfSpread.refresh();
  2230. }
  2231. });
  2232. $(window).resize(function () {
  2233. ledgerSpread.refresh();
  2234. leafXmjSpread.refresh();
  2235. materialSpread.refresh();
  2236. materialSelfSpread.refresh();
  2237. });
  2238. $.divResizer({
  2239. select: '#right-spr',
  2240. callback: function () {
  2241. ledgerSpread.refresh();
  2242. // leafXmjSpread.refresh();
  2243. materialSpread.refresh();
  2244. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2245. setLocalCache('material_list_' + materialID, width);
  2246. }
  2247. });
  2248. $.divResizer({
  2249. select: '#right-spr2',
  2250. callback: function () {
  2251. leafXmjSpread.refresh();
  2252. materialSelfSpread.refresh();
  2253. // const width = (($('#right-view2').width()/$('#right-view2').parent('div').width())*100).toFixed();
  2254. // setLocalCache('material_list3_' + materialID, width);
  2255. }
  2256. });
  2257. $.divResizer({
  2258. select: '#main-resize',
  2259. callback: function () {
  2260. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2261. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2262. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2263. $(".sp-wrap").height(bcontent-30);
  2264. materialSpread.refresh();
  2265. ledgerSpread.refresh();
  2266. leafXmjSpread.refresh();
  2267. materialSelfSpread.refresh();
  2268. const height = $('.bcontent-wrap').height();
  2269. setLocalCache('material_list2_' + materialID, height);
  2270. }
  2271. });
  2272. // 展开收起月信息价并浏览器记住本期展开收起
  2273. $('a', '.right-nav').bind('click', function () {
  2274. //const main = $('#main-view'), tool = $('#tools-view');
  2275. const tab = $(this), tabPanel = $(tab.attr('content'));
  2276. if (!tab.hasClass('active')) {
  2277. $('a', '.side-menu').removeClass('active');
  2278. $('.tab-content .tab-select-show').removeClass('active');
  2279. tab.addClass('active');
  2280. tabPanel.addClass('active');
  2281. showSideTools(tab.hasClass('active'));
  2282. if (tab.attr('content') === '#material-tab') {
  2283. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  2284. setLocalCache('material_list_' + materialID, width);
  2285. }
  2286. } else {
  2287. removeLocalCache('material_list_' + materialID);
  2288. tab.removeClass('active');
  2289. tabPanel.removeClass('active');
  2290. showSideTools(tab.hasClass('active'));
  2291. }
  2292. ledgerSpread.refresh();
  2293. // leafXmjSpread.refresh();
  2294. materialSpread.refresh();
  2295. });
  2296. // 根据浏览器记录展开收起
  2297. if (getLocalCache('material_list_' + materialID)) {
  2298. const tab = $('.right-nav a[content="#material-tab"]'), tabPanel = $(tab.attr('content'));
  2299. $('a', '.side-menu').removeClass('active');
  2300. $('.tab-content .tab-select-show').removeClass('active');
  2301. tab.addClass('active');
  2302. tabPanel.addClass('active');
  2303. $('#right-view').css('width', getLocalCache('material_list_' + materialID) + '%');
  2304. showSideTools(tab.hasClass('active'));
  2305. ledgerSpread.refresh();
  2306. // leafXmjSpread.refresh();
  2307. materialSpread.refresh();
  2308. }
  2309. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  2310. if (getLocalCache('material_list2_' + materialID)) {
  2311. $('.bcontent-wrap').height(getLocalCache('material_list2_' + materialID));
  2312. const cHeader = getObjHeight($(".c-header"));
  2313. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  2314. $(".sp-wrap").height(bcontent-30);
  2315. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  2316. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2317. materialSpread.refresh();
  2318. ledgerSpread.refresh();
  2319. leafXmjSpread.refresh();
  2320. materialSelfSpread.refresh();
  2321. } else {
  2322. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  2323. ledgerSpread.refresh();
  2324. }
  2325. function getObjHeight(select) {
  2326. return select.length > 0 ? select.height() : 0;
  2327. }
  2328. const showSelfSideTools = function (show) {
  2329. const left = $('#left-view2'), right = $('#right-view2'), parent = left.parent();
  2330. if (show) {
  2331. right.show();
  2332. autoFlashHeight();
  2333. /**
  2334. * right.show()后, parent被撑开成2倍left.height, 导致parent.width减少了10px
  2335. * 第一次left.width调整后,parent的缩回left.height, 此时parent.width又增加了10px
  2336. * 故需要通过最终的parent.width再计算一次left.width
  2337. *
  2338. * Q: 为什么不通过先计算left.width的宽度,以避免计算两次left.width?
  2339. * A: 右侧工具栏不一定显示,当右侧工具栏显示过一次后,就必须使用parent和right来计算left.width
  2340. *
  2341. */
  2342. //left.css('width', parent.width() - right.outerWidth());
  2343. //left.css('width', parent.width() - right.outerWidth());
  2344. const percent = 100 - right.outerWidth() /parent.width() * 100;
  2345. left.css('width', percent + '%');
  2346. } else {
  2347. // left.css('width', parent.width());
  2348. left.css('width', '100%');
  2349. right.hide();
  2350. }
  2351. };
  2352. });