material.js 96 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  1. 'use strict';
  2. /**
  3. * 材料调差 - 调差工料
  4. *
  5. * @author Mai
  6. * @date 2019/1/16
  7. * @version
  8. */
  9. function loadUpdateMaterials(newMaterial, fields) {
  10. const newMaterials = newMaterial instanceof Array ? newMaterial : [newMaterial];
  11. for (const nm of newMaterials) {
  12. const om = _.find(materialBillsData, {id: nm.id});
  13. for (const prop in nm) {
  14. if (!fields || fields.indexOf(prop) >= 0) {
  15. om[prop] = nm[prop];
  16. }
  17. }
  18. }
  19. }
  20. function DatePickerCellType() {
  21. }
  22. DatePickerCellType.prototype = new GC.Spread.Sheets.CellTypes.Base();
  23. DatePickerCellType.prototype.createEditorElement = function () {
  24. //Create input presenter.
  25. var input = document.createElement("input");
  26. return input;
  27. };
  28. DatePickerCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect) {
  29. //Initialize input editor.
  30. if (editorContext) {
  31. const $editor = $(editorContext);
  32. GC.Spread.Sheets.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
  33. $editor.datepicker({});
  34. $editor.css("position", "absolute");
  35. $editor.attr("gcUIElement", "gcEditingInput");
  36. $(".ui-datepicker").attr("gcUIElement", "gcEditingInput");
  37. }
  38. }
  39. DatePickerCellType.prototype.deactivateEditor = function (editorContext) {
  40. //Remove input editor when end editor status.
  41. if (editorContext) {
  42. var element = editorContext;
  43. // $(element).datepicker().data('datepicker').hide();
  44. // $(element).datepicker().data('datepicker').destroy();
  45. $(element).datepicker("hide");
  46. $(element).datepicker("destroy");
  47. }
  48. GC.Spread.Sheets.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments)
  49. };
  50. DatePickerCellType.prototype.setEditorValue = function (editor, value) {
  51. //Sync value from Cell value to editor value.
  52. // console.log($(editor), value);
  53. $(editor).datepicker("setDate", value);
  54. // $(editor).datepicker().data('datepicker').selectDate(value ? new Date(value) : new Date());
  55. };
  56. DatePickerCellType.prototype.getEditorValue = function (editor, context) {
  57. // console.log($(editor).datepicker().data('datepicker'), context);
  58. //Sync value from editor value to cell value.
  59. // console.log($(editor).datepicker("getDate"));
  60. // return $(editor).datepicker("getDate");
  61. return $(editor).val();
  62. };
  63. DatePickerCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect) {
  64. if (editorContext) {
  65. const $editor = $(editorContext);
  66. $editor.css("width", cellRect.width - 1);
  67. $editor.css("height", cellRect.height - 3);
  68. }
  69. };
  70. function resetTpTable() {
  71. $('#tp_set').find('td').eq(1).text(ZhCalc.round(m_tp, materialDecimal.tp));
  72. $('#tp_set').find('td').eq(2).text(ZhCalc.add(pre_tp, ZhCalc.round(m_tp, materialDecimal.tp)));
  73. if (materialTax) {
  74. $('#tax_rate_set').find('td').eq(1).text(ZhCalc.round(m_tax_tp, materialDecimal.tp));
  75. $('#tax_rate_set').find('td').eq(2).text(ZhCalc.add(m_tax_pre_tp, ZhCalc.round(m_tax_tp, materialDecimal.tp)));
  76. } else {
  77. const rate = $('#rateInput').val();
  78. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  79. const jzbqhs = ZhCalc.add(pre_tp_hs, bqhs);
  80. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  81. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  82. }
  83. if (isStageSelf) {
  84. let html = '';
  85. for (const ms of materialStageData) {
  86. const taxHtml = materialTax ? ' <td class="text-center">' + (ms.m_tax_tp !== null ? ms.m_tax_tp : '') + '</td>\n' : '';
  87. html += '<tr><td>第' + ms.order + '期</td><td class="text-center">' + (ms.m_tp !== null ? ms.m_tp : '') + '</td>\n' +
  88. taxHtml +
  89. ' </tr>';
  90. }
  91. const allTaxHtml = materialTax ? ' <td class="text-center">' + m_tax_tp + '</td>\n' : '';
  92. html += '<tr><td>合计</td><td class="text-center">' + m_tp + '</td>\n' +
  93. allTaxHtml +
  94. ' </tr>';
  95. $('#materialStageTable').html(html);
  96. }
  97. }
  98. function getPasteHint (str, row = '') {
  99. let returnObj = str;
  100. if (row) {
  101. returnObj.msg = '工料第' + (row+1) + '行' + str.msg;
  102. }
  103. return returnObj;
  104. }
  105. const is_numeric = (value) => {
  106. if (typeof(value) === 'object') {
  107. return false;
  108. } else {
  109. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  110. }
  111. };
  112. $(document).ready(() => {
  113. autoFlashHeight();
  114. const materialSpread = SpreadJsObj.createNewSpread($('#material-spread')[0]);
  115. const materialSpreadSetting = {
  116. emptyRows: 0,
  117. headRows: 2,
  118. headRowHeight: [25, 32],
  119. defaultRowHeight: 21,
  120. headerFont: '12px 微软雅黑',
  121. font: '12px 微软雅黑',
  122. readOnly: readOnly,
  123. };
  124. let materialSpreadSettingCols = [
  125. {title: '调差类型', colSpan: '1', rowSpan: '2', field: 't_type', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isUsed', cellType: 'customizeCombo', comboItems: materialType.t_type, cellTypeKey: 1},
  126. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.isUsed'},
  127. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
  128. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: 'readOnly.isEdit'},
  129. {title: '规格', colSpan: '1', rowSpan: '2', field: 'spec', hAlign: 0, width: 150, formatter: '@', readOnly: 'readOnly.isEdit'},
  130. {title: '工料分类', colSpan: '1', rowSpan: '2', field: 'm_type', hAlign: 1, width: 60, readOnly: 'readOnly.isEdit', cellType: 'customizeCombo', comboItems: materialType.m_type, cellTypeKey: 2},
  131. ];
  132. if (materialTax) {
  133. materialSpreadSettingCols.push({title: '税率(%)', colSpan: '1', rowSpan: '2', field: 'm_tax', hAlign: 2, width: 50, type: 'Number', readOnly: editTaxPermission ? 'readOnly.remark' : 'readOnly.isEdit'});
  134. }
  135. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  136. {title: '上涨 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_up_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
  137. {title: '下跌 幅度(%)', colSpan: '1', rowSpan: '2', field: 'm_down_risk', hAlign: 2, width: 50, type: 'Number', readOnly: 'readOnly.isEdit'},
  138. {title: '基准价', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit'},
  139. {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  140. {title: '本期信息价|单价', colSpan: '3|1', rowSpan: '1|1', field: 'msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.msg_tp'},
  141. {title: '|时间', colSpan: '|1', rowSpan: '|1', field: 'msg_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.remark'},
  142. {title: '|单价差', colSpan: '|1', rowSpan: '|1', field: 'msg_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.msg_spread'},]
  143. );
  144. if (materialTax) {
  145. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  146. {title: '本期材料调差|有效价差', colSpan: '4|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
  147. {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
  148. {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
  149. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'm_tax_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tax_tp'},
  150. {title: '截止上期|调差金额', colSpan: '2|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  151. {title: '|调差金额(材料税)', colSpan: '|1', rowSpan: '|1', field: 'tax_pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  152. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
  153. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'}
  154. ])
  155. } else {
  156. materialSpreadSettingCols = _.concat(materialSpreadSettingCols, [
  157. {title: '本期材料调差|有效价差', colSpan: '3|1', rowSpan: '1|1', field: 'm_spread', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue: 'getValue.m_spread'},
  158. {title: '|本期应耗数量', colSpan: '|1', rowSpan: '|1', field: 'quantity', hAlign: 2, width: 90, type: 'Number', readOnly: true},
  159. {title: '|调差金额', colSpan: '|1', rowSpan: '|1', field: 'm_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true, getValue: 'getValue.m_tp'},
  160. {title: '截止上期|调差金额', colSpan: '1|1', rowSpan: '1|1', field: 'pre_tp', hAlign: 2, width: 100, type: 'Number', readOnly: true},
  161. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 50, formatter: '@', cellType: 'ellipsisAutoTip', readOnly: 'readOnly.remark'},
  162. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'}
  163. ])
  164. }
  165. materialSpreadSetting.cols = materialSpreadSettingCols;
  166. const spCol = _.find(materialSpreadSetting.cols, {field: 'quantity'});
  167. spCol.readOnly = true;
  168. spCol.cellType = 'activeImageBtn';
  169. spCol.normalImg = '#ellipsis-icon';
  170. spCol.indent = 5;
  171. spCol.showImage = function (data) {
  172. // return !readOnly && data.t_type === 2 && data.mid === materialID;
  173. return data && data.t_type === 2;
  174. };
  175. materialSpreadSetting.imageClick = function (data) {
  176. if (data.t_type === 2) {
  177. $('#bcyy').modal('show');
  178. $('#materialbillsId').val(data.id);
  179. $('#expr').val(data.expr);
  180. if (!readOnly) {
  181. $('#expr').attr('readOnly', false);
  182. $('#expr_btn').show();
  183. $('#expr_select').show();
  184. } else {
  185. $('#expr').attr('readOnly', true);
  186. $('#expr_btn').hide();
  187. $('#expr_select').hide();
  188. }
  189. }
  190. };
  191. const materialBase = {
  192. isUsed: function (data) {
  193. if (data.t_type === 2) {
  194. return data.mid === materialID;
  195. } else {
  196. const mlInfo = _.find(materialListData, { mb_id: data.id });
  197. return data.mid === materialID && mlInfo === undefined;
  198. }
  199. },
  200. isEdit: function (data) {
  201. // if (data.t_type === 2) {
  202. // return data.mid === materialID;
  203. // } else {
  204. // const mlInfo = _.find(materialListData, { mb_id: data.id });
  205. // return data.mid === materialID && mlInfo === undefined;
  206. // }
  207. return data.mid === materialID;
  208. },
  209. // isStage: function (data) {
  210. // return data.mid === materialID;
  211. // }
  212. }
  213. const materialCol = {
  214. getValue: {
  215. msg_spread: function (data) {
  216. return ZhCalc.round(ZhCalc.sub(data.msg_tp, data.basic_price), materialDecimal.up);
  217. },
  218. m_spread : function (data) {
  219. const msg_spread = materialCol.getValue.msg_spread(data);
  220. const cor = msg_spread >= 0 ? ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_up_risk, 100)) : ZhCalc.mul(data.basic_price, ZhCalc.div(data.m_down_risk, 100));
  221. return Math.abs(msg_spread) > Math.abs(cor) ? (msg_spread > 0 ? ZhCalc.round(ZhCalc.sub(msg_spread, cor), materialDecimal.up) : ZhCalc.round(ZhCalc.add(msg_spread, cor), materialDecimal.up)) : 0;
  222. },
  223. m_tp: function (data) {
  224. return ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  225. },
  226. m_tax_tp: function (data) {
  227. const m_tp = ZhCalc.round(ZhCalc.mul(materialCol.getValue.m_spread(data), data.quantity), materialDecimal.tp);
  228. return data.m_tax ? ZhCalc.round(ZhCalc.mul(m_tp, (1+ZhCalc.div(data.m_tax, 100))), materialDecimal.tp) : m_tp;
  229. }
  230. },
  231. readOnly: {
  232. isEdit: function (data) {
  233. return !(!readOnly && materialBase.isEdit(data));
  234. },
  235. isUsed: function (data) {
  236. return !(!readOnly && materialBase.isUsed(data));
  237. },
  238. remark: function () {
  239. return readOnly;
  240. },
  241. msg_tp: function () {
  242. return !(!readOnly && months.length === 0);
  243. }
  244. },
  245. };
  246. const needUpdateArray = ['quantity', 'expr', 'msg_tp', 'msg_times', 'msg_spread', 'm_spread', 'm_tp', 'm_tax_tp', 'is_summary', 'remark'];
  247. const materialSpreadObj = {
  248. getMaterialBillsData: function () {
  249. if (isStageSelf) {
  250. // 当前选中nav id
  251. const ms_id = $('#myTab').find('.active').data('msid');
  252. const msbList = _.filter(materialStageBillsData, { ms_id });
  253. for (const mb of materialBillsData) {
  254. mb.ms_id = ms_id;
  255. const msbInfo = _.find(msbList, { mb_id: mb.mb_id ? mb.mb_id : mb.id });
  256. if (msbInfo) {
  257. for (const nu of needUpdateArray) {
  258. mb[nu] = msbInfo[nu];
  259. }
  260. }
  261. }
  262. }
  263. return materialBillsData;
  264. },
  265. updateOneMaterialBill: function (data) {
  266. const ms_id = $('#myTab').find('.active').data('msid');
  267. const msbInfo = _.find(materialStageBillsData, { ms_id, mb_id: data.id });
  268. console.log(msbInfo);
  269. data.ms_id = ms_id;
  270. for (const nu of needUpdateArray) {
  271. data[nu] = msbInfo[nu];
  272. }
  273. return data;
  274. },
  275. updateMaterialData: function (datas) {
  276. if (datas.stageData && datas.stageData.length > 0) {
  277. if (datas.stageData.length === materialStageData.length) {
  278. // 全体替换
  279. materialStageData = datas.stageData;
  280. } else {
  281. // 替换对应的stage数据
  282. for (const s of datas.stageData) {
  283. const index = _.findIndex(materialStageData, { id: s.id });
  284. materialStageData.splice(index, 1, s);
  285. }
  286. }
  287. }
  288. if (datas.pushStageBillsData && datas.pushStageBillsData.length > 0) {
  289. materialStageBillsData = _.concat(materialStageBillsData, datas.pushStageBillsData);
  290. }
  291. if (datas.removeStageBillsData && datas.removeStageBillsData.length > 0) {
  292. materialStageBillsData = _.remove(materialStageBillsData, function (item) {
  293. return _.findIndex(datas.removeStageBillsData, { id: item.mb_id }) === -1
  294. })
  295. }
  296. if (datas.stageBillsData && datas.stageBillsData.length > 0) {
  297. if (datas.stageBillsData.length === materialStageBillsData.length) {
  298. // 全体替换
  299. materialStageBillsData = datas.stageBillsData;
  300. } else {
  301. // 替换对应的stage数据
  302. for (const s of datas.stageBillsData) {
  303. const index = _.findIndex(materialStageBillsData, { id: s.id });
  304. materialStageBillsData.splice(index, 1, s);
  305. }
  306. }
  307. }
  308. if (datas.billsData && datas.billsData.length > 0) {
  309. if (datas.billsData.length === materialBillsData.length) {
  310. // 全体替换
  311. materialBillsData = datas.billsData;
  312. materialSpreadObj.getMaterialBillsData();
  313. } else {
  314. for (const b of datas.billsData) {
  315. const index = _.findIndex(materialBillsData, {id: b.id});
  316. materialBillsData.splice(index, 1, b);
  317. materialSpreadObj.updateOneMaterialBill(materialBillsData[index]);
  318. }
  319. }
  320. }
  321. },
  322. materialSheetReset: function (redo = false) {
  323. let newMaterialBillsData = _.cloneDeep(materialBillsData);
  324. if($('#bills0_list').is(':checked')) {
  325. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  326. return item.quantity !== null && item.quantity !== 0;
  327. });
  328. if (redo) {
  329. materialSpread.getActiveSheet().reset();
  330. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  331. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  332. }
  333. }
  334. console.log(newMaterialBillsData);
  335. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  336. materialSpreadObj.refreshActn();
  337. },
  338. refreshActn: function (rowCount = 1) {
  339. const setObjEnable = function (obj, enable) {
  340. if (enable) {
  341. obj.removeClass('disabled');
  342. } else {
  343. obj.addClass('disabled');
  344. }
  345. };
  346. const sheet = materialSpread.getActiveSheet();
  347. const select = SpreadJsObj.getSelectObject(sheet);
  348. const selection = sheet.getSelections();
  349. const sel = selection ? selection[0] : sheet.getSelections()[0];
  350. const row = sel ? sel.row : -1;
  351. const first = materialBillsData[row];
  352. let last = first;
  353. if (sel.rowCount > 1 && first) {
  354. for (let r = 1; r < sel.rowCount; r++) {
  355. const rNode = materialBillsData[sel.row + r];
  356. if (!rNode) break;
  357. last = rNode;
  358. }
  359. }
  360. const preNode = materialBillsData[row - 1];
  361. // 还需判断是否已被调差清单调用
  362. setObjEnable($('#del'), !readOnly && select && materialBase.isUsed(select) && rowCount === 1);
  363. setObjEnable($('#up-move'), !readOnly && first && preNode && materialBillsData.indexOf(last) > 0 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  364. setObjEnable($('#down-move'), !readOnly && first && materialBillsData.indexOf(last) < materialBillsData.length - 1 && sel.row + sel.rowCount <= materialBillsData.length && !$('#bills0_list').is(':checked'));
  365. },
  366. add: function () {
  367. const sheet = materialSpread.getActiveSheet();
  368. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  369. if (result) {
  370. materialBillsData.push(result.info);
  371. if (isStageSelf) {
  372. materialSpreadObj.updateMaterialData(result);
  373. materialSpreadObj.getMaterialBillsData();
  374. }
  375. // sheet.addRows(materialBillsData.length - 1, 1);
  376. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  377. let newMaterialBillsData = materialBillsData;
  378. if($('#bills0_list').is(':checked')) {
  379. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  380. return item.quantity !== null && item.quantity !== 0;
  381. });
  382. }
  383. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  384. // materialSpreadObj.materialSheetReset();
  385. sheet.setSelection(newMaterialBillsData.length - 1, 0, 1, 1);
  386. console.log(sheet);
  387. materialSpreadObj.refreshActn();
  388. // 月信息价需要同时添加空白的list
  389. if (months.length > 0) {
  390. const one_month ={ mb_id: result.info.id, code: '', name: null, origin: null, unit: null, order: result.info.order };
  391. for (const m of months) {
  392. one_month[m] = null;
  393. }
  394. monthsList.push(one_month);
  395. // const newMonthsList = _.filter(monthsList, function (item) {
  396. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  397. // });
  398. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  399. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  400. monthFunGather.monthsListSet();
  401. // materialMonthSpreadObj.monthsListSet();
  402. }
  403. }
  404. });
  405. },
  406. del: function () {
  407. const sheet = materialSpread.getActiveSheet();
  408. const select = SpreadJsObj.getSelectObject(sheet);
  409. const sel = sheet.getSelections();
  410. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  411. m_tp = result.m_tp;
  412. if (materialTax) {
  413. m_tax_tp = result.m_tax_tp;
  414. }
  415. const index = _.findIndex(materialBillsData, { id: select.id });
  416. materialBillsData.splice(index, 1);
  417. if (isStageSelf) {
  418. result.removeStageBillsData = [{ id: select.id }];
  419. materialSpreadObj.updateMaterialData(result);
  420. materialSpreadObj.getMaterialBillsData();
  421. }
  422. let newMaterialBillsData = materialBillsData;
  423. let newIndex = index;
  424. if($('#bills0_list').is(':checked')) {
  425. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  426. return item.quantity !== null && item.quantity !== 0;
  427. });
  428. newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
  429. }
  430. // sheet.deleteRows(newIndex, 1);
  431. // sheet.zh_data.splice(newIndex, 1);
  432. materialSpreadObj.materialSheetReset(true);
  433. resetTpTable();
  434. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  435. sheet.setSelection(newIndex > 0 ? newIndex - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  436. materialSpreadObj.refreshActn();
  437. // 月信息价需要同时删除
  438. if (months.length > 0) {
  439. monthsList.splice(index, 1);
  440. materialMonthSpread.getActiveSheet().deleteRows(newIndex, 1);
  441. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  442. }
  443. });
  444. },
  445. upMove: function () {
  446. if($('#bills0_list').is(':checked')) {
  447. return;
  448. }
  449. const data = {
  450. type: 'changeOrder',
  451. postData: [],
  452. };
  453. const sheet = materialSpread.getActiveSheet();
  454. const selection = sheet.getSelections();
  455. const row = selection[0].row, count = selection[0].rowCount;
  456. const first = sheet.zh_data[row];
  457. if (!first) {
  458. materialSpreadObj.refreshActn();
  459. return false;
  460. }
  461. const pre = sheet.zh_data[row - 1], preUpdate = {id: pre.id};
  462. for (let iRow = 0; iRow < count; iRow++) {
  463. const posData = sheet.zh_data[iRow + row];
  464. if (posData) {
  465. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row - 1].order});
  466. preUpdate.order = posData.order;
  467. }
  468. }
  469. console.log(monthsList);
  470. data.postData.push(preUpdate);
  471. console.log(data);
  472. if (data.postData.length > 0) {
  473. postData(window.location.pathname + '/save', data, function () {
  474. _.forEach(data.postData, function (item) {
  475. const cl = _.find(materialBillsData, { id: item.id });
  476. cl.order = item.order;
  477. });
  478. materialBillsData.sort(function (a, b) {
  479. return a.order - b.order
  480. });
  481. SpreadJsObj.reLoadSheetData(sheet);
  482. const sel = selection[0];
  483. if (sel) {
  484. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  485. }
  486. if (months.length > 0) {
  487. _.forEach(data.postData, function (item) {
  488. const cl = _.find(monthsList, { mb_id: item.id });
  489. cl.order = item.order;
  490. });
  491. monthsList.sort(function (a, b) {
  492. return a.order - b.order
  493. });
  494. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  495. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  496. }
  497. materialSpreadObj.refreshActn();
  498. });
  499. }
  500. },
  501. downMove: function () {
  502. if($('#bills0_list').is(':checked')) {
  503. return;
  504. }
  505. const data = {
  506. type: 'changeOrder',
  507. postData: [],
  508. };
  509. const sheet = materialSpread.getActiveSheet();
  510. const selection = sheet.getSelections();
  511. const row = selection[0].row, count = selection[0].rowCount;
  512. const first = sheet.zh_data[row];
  513. if (!first) {
  514. materialSpreadObj.refreshActn();
  515. return false;
  516. }
  517. const next = sheet.zh_data[row + count], nextUpdate = {id: next.id};
  518. for (let iRow = count - 1; iRow >= 0; iRow--) {
  519. const posData = sheet.zh_data[iRow + row];
  520. if (posData) {
  521. data.postData.push({id: posData.id, order: sheet.zh_data[iRow + row + 1].order});
  522. nextUpdate.order = posData.order;
  523. }
  524. }
  525. data.postData.push(nextUpdate);
  526. console.log(data);
  527. if (data.postData.length > 0) {
  528. postData(window.location.pathname + '/save', data, function () {
  529. _.forEach(data.postData, function (item) {
  530. const cl = _.find(materialBillsData, { id: item.id });
  531. cl.order = item.order;
  532. });
  533. materialBillsData.sort(function (a, b) {
  534. return a.order - b.order
  535. });
  536. SpreadJsObj.reLoadSheetData(sheet);
  537. const sel = selection[0];
  538. if (sel) {
  539. sheet.setSelection(sheet.zh_data.indexOf(first), sel.col, sel.rowCount, sel.colCount);
  540. }
  541. if (months.length > 0) {
  542. _.forEach(data.postData, function (item) {
  543. const cl = _.find(monthsList, { mb_id: item.id });
  544. cl.order = item.order;
  545. });
  546. monthsList.sort(function (a, b) {
  547. return a.order - b.order
  548. });
  549. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  550. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  551. }
  552. materialSpreadObj.refreshActn();
  553. });
  554. }
  555. },
  556. selectionChanged: function (e, info) {
  557. const sel = info.sheet.getSelections()[0];
  558. const col = info.sheet.zh_setting.cols[sel.col];
  559. materialSpreadObj.refreshActn(sel.rowCount);
  560. const data = SpreadJsObj.getSelectObject(info.sheet);
  561. materialSpreadObj.setReadOnly(true);
  562. // console.log(data);
  563. },
  564. editEnded: function (e, info) {
  565. if (info.sheet.zh_setting) {
  566. const select = SpreadJsObj.getSelectObject(info.sheet);
  567. const col = info.sheet.zh_setting.cols[info.col];
  568. if (col.field === 'is_summary') {
  569. return;
  570. }
  571. // 未改变值则不提交
  572. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  573. const orgValue = select[col.field];
  574. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  575. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  576. return;
  577. }
  578. // 判断部分值是否输入的是数字判断和数据计算
  579. if (col.field === 'basic_price') {
  580. if (isNaN(validText)) {
  581. toastr.error('不能输入其它非数字类型字符');
  582. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  583. return;
  584. }
  585. let num = parseFloat(validText);
  586. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  587. if (validText !== null && (num < 0 || !reg.test(num))) {
  588. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  589. validText = ZhCalc.round(num, materialDecimal.up);
  590. }
  591. }
  592. if (col.field === 'msg_tp') {
  593. if (isNaN(validText)) {
  594. toastr.error('不能输入其它非数字类型字符');
  595. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  596. return;
  597. }
  598. const num = parseFloat(validText);
  599. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  600. if (validText !== null && (num < 0 || !reg.test(num))) {
  601. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  602. validText = ZhCalc.round(num, materialDecimal.up);
  603. }
  604. }
  605. if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
  606. // 只能输入正整数
  607. if (isNaN(validText)) {
  608. toastr.error('不能输入其它非数字类型字符');
  609. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  610. return;
  611. }
  612. const num = parseFloat(validText);
  613. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  614. toastr.error('只能输入0-100的正整数');
  615. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  616. return;
  617. }
  618. }
  619. if (col.field === 't_type') {
  620. if (validText === 1) {
  621. select.quantity = null;
  622. select.expr = null;
  623. select.m_tp = null;
  624. }
  625. }
  626. select[col.field] = validText;
  627. select.msg_spread = materialCol.getValue.msg_spread(select);
  628. select.m_spread = materialCol.getValue.m_spread(select);
  629. select.m_tp = materialCol.getValue.m_tp(select);
  630. select.m_tax_tp = materialCol.getValue.m_tax_tp(select);
  631. delete select.waitingLoading;
  632. // console.log(select);
  633. // 更新至服务器
  634. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  635. m_tp = result.m_tp;
  636. if (materialTax) {
  637. m_tax_tp = result.m_tax_tp;
  638. }
  639. if (isStageSelf) {
  640. materialSpreadObj.updateMaterialData(result);
  641. }
  642. resetTpTable();
  643. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  644. // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
  645. if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
  646. const index = _.findIndex(materialBillsData, { id: select.id });
  647. monthsList[index][col.field] = validText;
  648. monthFunGather.monthsListSet();
  649. }
  650. }, function () {
  651. select[col.field] = orgValue;
  652. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  653. });
  654. }
  655. },
  656. buttonClicked: function (e, info) {
  657. if (info.sheet.zh_setting) {
  658. const select = SpreadJsObj.getSelectObject(info.sheet);
  659. const col = info.sheet.zh_setting.cols[info.col];
  660. if (materialCol.readOnly.isEdit(select)) {
  661. return;
  662. }
  663. if (col.field === 'is_summary') {
  664. if (info.sheet.isEditing()) {
  665. info.sheet.endEdit(true);
  666. }
  667. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  668. delete select.waitingLoading;
  669. // 更新至服务器
  670. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  671. m_tp = result.m_tp;
  672. if (materialTax) {
  673. m_tax_tp = result.m_tax_tp;
  674. }
  675. if (isStageSelf) {
  676. materialSpreadObj.updateMaterialData(result);
  677. }
  678. resetTpTable();
  679. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  680. }, function () {
  681. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  682. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  683. });
  684. }
  685. }
  686. },
  687. deletePress: function (sheet) {
  688. return;
  689. },
  690. clipboardPasted(e, info) {
  691. const hint = {
  692. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  693. codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
  694. codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
  695. codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
  696. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  697. riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
  698. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  699. };
  700. const range = info.cellRange;
  701. const sortData = info.sheet.zh_data || [];
  702. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  703. toastMessageUniq(hint.cellError);
  704. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  705. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  706. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  707. return;
  708. }
  709. if (sortData.length > 0 && range.col + range.colCount > 18) {
  710. toastMessageUniq(hint.cellError);
  711. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  712. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  713. return;
  714. }
  715. const data = [];
  716. // const rowData = [];
  717. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  718. let bPaste = true;
  719. const curRow = range.row + iRow;
  720. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  721. const materialData = { id: sortData[curRow].id };
  722. const hintRow = range.rowCount > 1 ? curRow : '';
  723. let sameCol = 0;
  724. for (let iCol = 0; iCol < range.colCount; iCol++) {
  725. const curCol = range.col + iCol;
  726. const colSetting = info.sheet.zh_setting.cols[curCol];
  727. if (!colSetting) continue;
  728. let validText = info.sheet.getText(curRow, curCol);
  729. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  730. const orgValue = sortData[curRow][colSetting.field];
  731. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  732. sameCol++;
  733. if (range.colCount === sameCol) {
  734. bPaste = false;
  735. }
  736. continue;
  737. }
  738. if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
  739. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  740. bPaste = false;
  741. continue;
  742. }
  743. if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
  744. toastMessageUniq(getPasteHint(hint.codeError, hintRow));
  745. bPaste = false;
  746. continue;
  747. }
  748. if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
  749. toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
  750. bPaste = false;
  751. continue;
  752. }
  753. if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
  754. continue;
  755. }
  756. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
  757. || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  758. if (isNaN(validText)) {
  759. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  760. bPaste = false;
  761. continue;
  762. }
  763. const num = parseFloat(validText);
  764. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
  765. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  766. if (validText !== null && (num < 0 || !reg.test(num))) {
  767. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  768. validText = ZhCalc.round(num, materialDecimal.up);
  769. }
  770. } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
  771. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  772. toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
  773. bPaste = false;
  774. continue;
  775. }
  776. }
  777. }
  778. materialData[colSetting.field] = validText;
  779. sortData[curRow][colSetting.field] = validText;
  780. }
  781. if (materialData.code === '' || materialData.code === null) {
  782. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  783. bPaste = false;
  784. }
  785. if (bPaste) {
  786. materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
  787. materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
  788. materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
  789. materialData.m_tax_tp = materialCol.getValue.m_tax_tp(sortData[curRow]);
  790. data.push(materialData);
  791. // rowData.push(curRow);
  792. } else {
  793. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  794. }
  795. }
  796. if (data.length === 0) {
  797. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  798. return;
  799. }
  800. // console.log(data);
  801. // 更新至服务器
  802. postData(window.location.pathname + '/save', { type:'paste', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  803. materialBillsData = result.info;
  804. m_tp = result.m_tp;
  805. if (materialTax) {
  806. m_tax_tp = result.m_tax_tp;
  807. }
  808. if (isStageSelf) {
  809. materialSpreadObj.updateMaterialData(result);
  810. materialSpreadObj.getMaterialBillsData();
  811. }
  812. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  813. materialSpreadObj.materialSheetReset();
  814. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  815. // for (const row in rowData) {
  816. // materialBillsData.splice(index, 1, result.info[row]);
  817. // SpreadJsObj.reLoadRowData(info.sheet, row);
  818. // }
  819. if (months.length > 0) {
  820. for (const [i,m] of monthsList.entries()) {
  821. m.code = materialBillsData[i].code;
  822. m.name = materialBillsData[i].name;
  823. m.unit = materialBillsData[i].unit;
  824. m.origin = materialBillsData[i].origin;
  825. }
  826. // SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  827. monthFunGather.monthsListSet();
  828. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  829. }
  830. resetTpTable();
  831. // materialSpreadObj.refreshActn();
  832. }, function () {
  833. // materialSpreadObj.refreshActn();
  834. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  835. return;
  836. });
  837. },
  838. setReadOnly: function(readOnly) {
  839. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  840. }
  841. };
  842. materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
  843. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  844. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  845. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  846. materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
  847. const sheet = materialSpread.getActiveSheet();
  848. sheet.suspendPaint();
  849. // materialSpreadObj.refreshActn();
  850. // const basic_range = sheet.getRange(-1, 8, -1, 1);
  851. // basic_range.cellType(new DatePickerCellType());
  852. // basic_range.formatter("yyyy-MM-dd");
  853. // const msg_range = sheet.getRange(-1, 10, -1, 1);
  854. // msg_range.cellType(new DatePickerCellType());
  855. // msg_range.formatter("yyyy-MM-dd");
  856. sheet.resumePaint();
  857. const static_cols = [
  858. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
  859. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  860. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  861. {title: '来源地', colSpan: '1', rowSpan: '2', field: 'origin', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  862. {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
  863. ];
  864. // 月信息价方法集合
  865. const monthFunGather = {
  866. _setMonthHtml: function() {
  867. let html = '';
  868. let qihtml = '';
  869. for (const m of months) {
  870. html += '<div class="custom-control custom-checkbox mb-2">\n' +
  871. ' <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
  872. ' <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
  873. ' </div>';
  874. qihtml += parseInt(m.split('-')[1]) + '月,';
  875. }
  876. if (months.length > 0) {
  877. qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
  878. qihtml = qihtml.substring(0, qihtml.length-1);
  879. }
  880. $('#show_month').html(html);
  881. $('#qi-month').html(qihtml);
  882. },
  883. _monthHeaderSet: function() {
  884. const newMonths = [];
  885. for (const m of months) {
  886. const year = m.split('-')[0];
  887. const month = parseInt(m.split('-')[1]);
  888. let one = _.find(newMonths, { 'year': year });
  889. let oneIndex = _.findIndex(newMonths, { 'year': year });
  890. if (one) {
  891. one.month.push(month);
  892. newMonths.splice(oneIndex, 1, one);
  893. } else {
  894. one = {
  895. year: year,
  896. month: [ month ],
  897. };
  898. newMonths.push(one);
  899. }
  900. }
  901. const pushMonth = [];
  902. for(const mo of newMonths) {
  903. for (let i in mo.month) {
  904. i = parseInt(i);
  905. const newCols = {
  906. title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
  907. colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
  908. rowSpan: i === 0 ? '1|1' : '|1',
  909. field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
  910. hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
  911. pushMonth.push(newCols);
  912. }
  913. }
  914. return pushMonth;
  915. },
  916. monthSheetReset: function (ml = monthsList) {
  917. const monthCols = monthFunGather._monthHeaderSet();
  918. const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
  919. materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
  920. // 表头变化需要重新绘制,不然报错;
  921. materialMonthSpread.getActiveSheet().reset();
  922. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  923. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  924. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, ml);
  925. monthFunGather._setMonthHtml();
  926. },
  927. monthsListSet: function (ml = materialBillsData, checked = true) {
  928. if($('#bills0_list').is(':checked') && checked) {
  929. ml = _.filter(materialBillsData, function (item) {
  930. return item.quantity === null || item.quantity === 0;
  931. });
  932. }
  933. const newMonthsList = _.filter(monthsList, function (item) {
  934. return _.findIndex(ml, { code: item.code }) !== -1;
  935. });
  936. monthFunGather.monthSheetReset(newMonthsList);
  937. }
  938. };
  939. const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
  940. const materialMonthSpreadSetting = {
  941. cols: static_cols,
  942. emptyRows: 0,
  943. headRows: 2,
  944. headRowHeight: [25, 25],
  945. defaultRowHeight: 21,
  946. headerFont: '12px 微软雅黑',
  947. font: '12px 微软雅黑',
  948. readOnly: readOnly,
  949. };
  950. if (months.length > 0) {
  951. const monthCols = monthFunGather._monthHeaderSet();
  952. const monthSpreadHeaderCols = static_cols.concat(monthCols);
  953. materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
  954. }
  955. const materialMonthCol = {
  956. getValue: {
  957. average_msg_tp: function (data) {
  958. let msg_tp = 0;
  959. let hadnum = 0;
  960. for (const m of months) {
  961. msg_tp += data[m];
  962. if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
  963. hadnum++;
  964. }
  965. }
  966. const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
  967. return average_tp;
  968. },
  969. },
  970. readOnly: {
  971. isEdit: function (data) {
  972. return readOnly;
  973. },
  974. },
  975. };
  976. materialMonthSpread.getActiveSheet().frozenColumnCount(5);
  977. materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
  978. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  979. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  980. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  981. const materialMonthSpreadObj = {
  982. editEnded: function (e, info) {
  983. if (info.sheet.zh_setting) {
  984. const select = SpreadJsObj.getSelectObject(info.sheet);
  985. const col = info.sheet.zh_setting.cols[info.col];
  986. // 未改变值则不提交
  987. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  988. const orgValue = select[col.field];
  989. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  990. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  991. return;
  992. }
  993. if (col.field === 'origin') {
  994. select[col.field] = validText;
  995. postData(window.location.pathname + '/month/save', { type:'updateOrigin', updateData: { mb_id: select.mb_id, value: validText } }, function (result) {
  996. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  997. materialBillsData = result.materialBillsData;
  998. materialSpreadObj.materialSheetReset();
  999. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1000. }, function () {
  1001. select[col.field] = orgValue;
  1002. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1003. });
  1004. } else {
  1005. // 判断部分值是否输入的是数字判断和数据计算
  1006. if (isNaN(validText)) {
  1007. toastr.error('不能输入其它非数字类型字符');
  1008. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1009. return;
  1010. }
  1011. const num = parseFloat(validText);
  1012. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1013. if (validText !== null && (num < 0 || !reg.test(num))) {
  1014. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  1015. validText = ZhCalc.round(num, materialDecimal.up);
  1016. }
  1017. select[col.field] = validText;
  1018. // 更新至服务器
  1019. postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
  1020. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1021. materialBillsData = result.materialBillsData;
  1022. materialSpreadObj.materialSheetReset();
  1023. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1024. m_tp = result.m_tp;
  1025. if (materialTax) {
  1026. m_tax_tp = result.m_tax_tp;
  1027. }
  1028. resetTpTable();
  1029. }, function () {
  1030. select[col.field] = orgValue;
  1031. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  1032. });
  1033. }
  1034. }
  1035. },
  1036. deletePress: function (sheet) {
  1037. // if (sheet.zh_setting && sheet.zh_data) {
  1038. // const sel = sheet.getSelections()[0];
  1039. // if (!sel) return;
  1040. //
  1041. // const col = sheet.zh_setting.cols[sel.col];
  1042. // const select = SpreadJsObj.getSelectObject(sheet);
  1043. // const orgValue = select[col.field];
  1044. // if (sel.colCount > 1 || sel.rowCount > 1) {
  1045. // toastr.warning('请勿同时删除多行或多列数据');
  1046. // }
  1047. // console.log(sel, select, col);
  1048. // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  1049. // return;
  1050. // }
  1051. // select[col.field] = null;
  1052. // select.calc_num = materialExponentCol.getValue.calc_num(select);
  1053. // console.log(select);
  1054. // 更新至服务器
  1055. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  1056. // ex_tp = result.ex_tp;
  1057. // ex_expr = result.ex_expr;
  1058. // resetExTpTable();
  1059. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1060. // materialExponentData.splice(sel.row, 1, select);
  1061. // }, function () {
  1062. // select[col.field] = orgValue;
  1063. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  1064. // });
  1065. // }
  1066. return;
  1067. },
  1068. clipboardPasted(e, info) {
  1069. const hint = {
  1070. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  1071. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  1072. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  1073. };
  1074. const range = info.cellRange;
  1075. const sortData = info.sheet.zh_data || [];
  1076. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  1077. toastMessageUniq(hint.cellError);
  1078. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1079. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1080. return;
  1081. }
  1082. if (sortData.length > 0 && range.col + range.colCount > 5 + months.length) {
  1083. toastMessageUniq(hint.cellError);
  1084. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1085. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1086. return;
  1087. }
  1088. const data = [];
  1089. let pasteOrigin = false;
  1090. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1091. let bPaste = true;
  1092. const curRow = range.row + iRow;
  1093. const materialMonthData = sortData[curRow];
  1094. const hintRow = range.rowCount > 1 ? curRow : '';
  1095. let sameCol = 0;
  1096. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1097. const curCol = range.col + iCol;
  1098. const colSetting = info.sheet.zh_setting.cols[curCol];
  1099. if (!colSetting) continue;
  1100. let validText = info.sheet.getText(curRow, curCol);
  1101. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1102. const orgValue = sortData[curRow][colSetting.field];
  1103. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1104. sameCol++;
  1105. if (range.colCount === sameCol) {
  1106. bPaste = false;
  1107. }
  1108. continue;
  1109. }
  1110. if (colSetting.field === 'origin') {
  1111. pasteOrigin = true;
  1112. } else {
  1113. const num = parseFloat(validText);
  1114. if (isNaN(validText)) {
  1115. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1116. bPaste = false;
  1117. continue;
  1118. }
  1119. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1120. if (validText !== null && (num < 0 || !reg.test(num))) {
  1121. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1122. validText = ZhCalc.round(num, materialDecimal.up);
  1123. }
  1124. }
  1125. materialMonthData[colSetting.field] = validText;
  1126. sortData[curRow][colSetting.field] = validText;
  1127. }
  1128. if (bPaste) {
  1129. data.push(materialMonthData);
  1130. } else {
  1131. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1132. }
  1133. }
  1134. if (data.length === 0) {
  1135. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1136. return;
  1137. }
  1138. // console.log(data);
  1139. if (pasteOrigin) {
  1140. // 更新至服务器
  1141. postData(window.location.pathname + '/month/save', { type:'pasteOrigin', updateData: data }, function (result) {
  1142. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1143. materialBillsData = result.materialBillsData;
  1144. }, function () {
  1145. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1146. return;
  1147. });
  1148. } else {
  1149. // 更新至服务器
  1150. postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
  1151. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1152. materialBillsData = result.materialBillsData;
  1153. materialSpreadObj.materialSheetReset();
  1154. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1155. m_tp = result.m_tp;
  1156. if (materialTax) {
  1157. m_tax_tp = result.m_tax_tp;
  1158. }
  1159. resetTpTable();
  1160. }, function () {
  1161. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1162. return;
  1163. });
  1164. }
  1165. },
  1166. };
  1167. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1168. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1169. materialSpreadObj.getMaterialBillsData();
  1170. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1171. materialSpreadObj.refreshActn();
  1172. materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
  1173. SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
  1174. materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
  1175. // 期切换
  1176. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  1177. e.preventDefault();
  1178. showWaitingView();
  1179. setTimeout(function () {
  1180. materialSpreadObj.getMaterialBillsData();
  1181. materialSpreadObj.materialSheetReset(true);
  1182. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1183. // 消耗量表格更新
  1184. let html = '';
  1185. calcBase = _.find(calcBaseList, { ms_id: $('#myTab').find('.active').data('msid') }).calcBase;
  1186. for (let iBase = 0; iBase < calcBase.length; iBase++) {
  1187. html += '<tr><td>' + calcBase[iBase].name + '</td><td>' + calcBase[iBase].code + '</td><td>' + calcBase[iBase].value + '</td></tr>';
  1188. }
  1189. $('#calcBase').html(html);
  1190. closeWaitingView();
  1191. }, 1000);
  1192. });
  1193. if (!readOnly || editForAudit) {
  1194. $('#expr_select button').on('click', function () {
  1195. const code = $(this).text();
  1196. // $('#expr').val($('#expr').val() + code);
  1197. $('#expr').insertAtCaret(code);
  1198. });
  1199. const ExprObj = {
  1200. _checkExprValid(expr, invalidParam) {
  1201. if (!expr) return [true, null];
  1202. const param = [];
  1203. let num = '', base = '';
  1204. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1205. if (/^[\d\.%]+/.test(expr[i])) {
  1206. if (base !== '') {
  1207. param.push({type: 'base', value: base});
  1208. base = '';
  1209. }
  1210. num = num + expr[i];
  1211. } else if (/^[a-z]/.test(expr[i])) {
  1212. if (num !== '') {
  1213. param.push({type: 'num', value: num});
  1214. num = '';
  1215. }
  1216. base = base + expr[i];
  1217. } else if (expr[i] === '(') {
  1218. if (num !== '') {
  1219. param.push({type: 'num', value: num});
  1220. num = '';
  1221. }
  1222. if (base !== '') {
  1223. param.push({type: 'base', value: base});
  1224. base = '';
  1225. }
  1226. param.push({type: 'left', value: '('});
  1227. } else if (expr[i] === ')') {
  1228. if (num !== '') {
  1229. param.push({type: 'num', value: num});
  1230. num = '';
  1231. }
  1232. if (base !== '') {
  1233. param.push({type: 'base', value: base});
  1234. base = '';
  1235. }
  1236. param.push({type: 'right', value: ')'});
  1237. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1238. if (num !== '') {
  1239. param.push({type: 'num', value: num});
  1240. num = '';
  1241. }
  1242. if (base !== '') {
  1243. param.push({type: 'base', value: base});
  1244. base = '';
  1245. }
  1246. param.push({type: 'calc', value: expr[i]});
  1247. } else {
  1248. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1249. }
  1250. }
  1251. if (num !== '') {
  1252. param.push({type: 'num', value: num});
  1253. num = '';
  1254. }
  1255. if (base !== '') {
  1256. param.push({type: 'base', value: base});
  1257. base = '';
  1258. }
  1259. if (param.length === 0) return true;
  1260. if (param.length > 1) {
  1261. if (param[0].value === '-') {
  1262. param[1].value = '-' + param[1];
  1263. }
  1264. param.unshift();
  1265. }
  1266. const iLen = param.length;
  1267. let iLeftCount = 0, iRightCount = 0;
  1268. for (const [i, p] of param.entries()) {
  1269. if (p.type === 'calc') {
  1270. if (i === 0 || i === iLen - 1)
  1271. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
  1272. }
  1273. if (p.type === 'num') {
  1274. num = p.value.replace('%', '');
  1275. if (p.value.length - num.length > 1)
  1276. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1277. num = _.toNumber(num);
  1278. if (num === undefined || num === null || _.isNaN(num))
  1279. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1280. if (i > 0) {
  1281. if (param[i - 1].type !== 'calc') {
  1282. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1283. } else if (param[i - 1].value === '/' && num === 0) {
  1284. return [false, '输入的表达式非法:请勿除0'];
  1285. }
  1286. }
  1287. }
  1288. if (p.type === 'base') {
  1289. const baseParam = _.find(calcBase, {code: p.value});
  1290. if (!baseParam)
  1291. return [false, '输入的表达式非法:不存在计算基数' + p.value];
  1292. if (invalidParam && invalidParam.indexOf(p.value) >= 0)
  1293. return [false, '不可使用计算基数' + p.value];
  1294. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1295. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1296. }
  1297. if (p.type === 'left') {
  1298. iLeftCount += 1;
  1299. if (i !== 0 && param[i-1].type !== 'calc')
  1300. return [false, '输入的表达式非法:(前应有运算符'];
  1301. }
  1302. if (p.type === 'right') {
  1303. iRightCount += 1;
  1304. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1305. return [false, '输入的表达式非法:)后应有运算符'];
  1306. if (iRightCount > iLeftCount)
  1307. return [false, '输入的表达式非法:")"前无对应的"("'];
  1308. }
  1309. }
  1310. if (iLeftCount > iRightCount)
  1311. return [false, '输入的表达式非法:"("后无对应的")"'];
  1312. return [true, ''];
  1313. },
  1314. _checkExpr: function (text) {
  1315. if (text) {
  1316. const num = _.toNumber(text);
  1317. if (num) {
  1318. console.log(num);
  1319. } else {
  1320. const expr = text.replace('=', '').toLowerCase();
  1321. const [valid, msg] = this._checkExprValid(expr);
  1322. if (!valid) return [valid, msg];
  1323. }
  1324. }
  1325. return [true, ''];
  1326. },
  1327. };
  1328. $('#expr_btn').click(function () {
  1329. const expr = $('#expr').val();
  1330. // 判断表达式格式
  1331. const [valid, msg] = ExprObj._checkExpr(expr);
  1332. if (!valid) {
  1333. toastr.error(msg);
  1334. return false;
  1335. }
  1336. postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1337. m_tp = result.m_tp;
  1338. if (materialTax) {
  1339. m_tax_tp = result.m_tax_tp;
  1340. }
  1341. const sheet = materialSpread.getActiveSheet();
  1342. const select = SpreadJsObj.getSelectObject(sheet);
  1343. const index = _.findIndex(materialBillsData, { id: select.id });
  1344. let newIndex = index;
  1345. if (isStageSelf) {
  1346. materialSpreadObj.updateMaterialData(result);
  1347. result.info = materialSpreadObj.updateOneMaterialBill(result.info);
  1348. }
  1349. if($('#bills0_list').is(':checked')) {
  1350. const newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1351. return item.quantity !== null && item.quantity !== 0;
  1352. });
  1353. newIndex = _.findIndex(newMaterialBillsData, { id: select.id });
  1354. // newIndex = newMaterialBillsData.indexOf(select);
  1355. newMaterialBillsData.splice(newIndex, 1, result.info);
  1356. sheet.zh_data[newIndex] = result.info;
  1357. }
  1358. materialBillsData.splice(index, 1, result.info);
  1359. sheet.zh_data.splice(newIndex, 1, result.info);
  1360. SpreadJsObj.reLoadRowData(sheet, newIndex);
  1361. resetTpTable();
  1362. $('#bcyy').modal('hide');
  1363. });
  1364. });
  1365. }
  1366. if (!readOnly && !editForAudit) {
  1367. $('#add').click(materialSpreadObj.add);
  1368. $('#del').click(materialSpreadObj.del);
  1369. $('#up-move').click(materialSpreadObj.upMove);
  1370. $('#down-move').click(materialSpreadObj.downMove);
  1371. // 右键菜单
  1372. $.contextMenu({
  1373. selector: '#material-spread',
  1374. build: function ($trigger, e) {
  1375. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1376. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1377. },
  1378. items: {
  1379. 'create': {
  1380. name: '新增材料',
  1381. icon: 'fa-sign-in',
  1382. callback: function (key, opt) {
  1383. materialSpreadObj.add(materialSpread.getActiveSheet());
  1384. },
  1385. },
  1386. 'delete': {
  1387. name: '删除材料',
  1388. icon: 'fa-remove',
  1389. callback: function (key, opt) {
  1390. materialSpreadObj.del(materialSpread.getActiveSheet());
  1391. },
  1392. disabled: function (key, opt) {
  1393. const sheet = materialSpread.getActiveSheet();
  1394. const select = SpreadJsObj.getSelectObject(sheet);
  1395. const sel = sheet.getSelections()[0];
  1396. materialSpreadObj.refreshActn(sel.rowCount);
  1397. if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
  1398. return false;
  1399. } else {
  1400. return true;
  1401. }
  1402. }
  1403. },
  1404. }
  1405. });
  1406. $('.changeRate').click(function () {
  1407. $('#rateInput').val(parseInt($(this).data('value')));
  1408. $('#rateInput').siblings('.dropdown-menu').hide();
  1409. });
  1410. $('#rateInput').click(function () {
  1411. $(this).siblings('.dropdown-menu').show();
  1412. })
  1413. // 回车提交
  1414. $('#rateInput').on('keypress', function () {
  1415. if(window.event.keyCode === 13) {
  1416. $(this).blur();
  1417. }
  1418. });
  1419. $('#rateInput').blur(function () {
  1420. const _self = $(this);
  1421. setTimeout(function () {
  1422. let rate = parseFloat(_self.val());
  1423. if (_.isNaN(rate)) {
  1424. toastr.error('请输入0-100之前的整数值');
  1425. $('#rateInput').val(materialRate);
  1426. return;
  1427. }
  1428. rate = _.round(rate);
  1429. if(rate < 0 || rate > 100) {
  1430. toastr.error('请输入0-100之前的整数值');
  1431. $('#rateInput').val(materialRate);
  1432. return;
  1433. }
  1434. $('#rateInput').siblings('.dropdown-menu').hide();
  1435. console.log(rate, materialRate);
  1436. if (rate !== materialRate) {
  1437. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1438. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1439. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1440. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1441. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1442. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1443. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1444. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1445. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1446. materialRate = rate;
  1447. $('#rateInput').val(rate);
  1448. });
  1449. } else {
  1450. $('#rateInput').val(rate);
  1451. }
  1452. }, 500);
  1453. });
  1454. // $('#changeRate').change(function () {
  1455. // const rate = parseInt($(this).val());
  1456. // postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1457. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1458. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1459. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1460. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1461. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1462. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1463. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1464. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1465. // });
  1466. // });
  1467. // 创建月信息价
  1468. $('#make-month').click(function() {
  1469. const yearmonth = $('#months').val();
  1470. const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
  1471. if (result === null) {
  1472. toastr.error('请选择正确的信息价月份');
  1473. return false;
  1474. }
  1475. //判断是否已存在当前月份
  1476. if (months.indexOf(yearmonth) !== -1) {
  1477. toastr.error('调差期已创建过本月的信息价');
  1478. return false;
  1479. }
  1480. postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
  1481. months.push(yearmonth);
  1482. months.sort();
  1483. monthsList = data.monthsList;
  1484. monthFunGather.monthsListSet();
  1485. // 工料表单价显示也要更新
  1486. materialBillsData = data.materialBillsData;
  1487. materialSpreadObj.materialSheetReset();
  1488. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1489. m_tp = data.m_tp;
  1490. if (materialTax) {
  1491. m_tax_tp = data.m_tax_tp;
  1492. }
  1493. resetTpTable();
  1494. $('#add-month').modal('hide');
  1495. });
  1496. });
  1497. // 删除月信息价
  1498. $('#del-month').click(function () {
  1499. const del_month_array = [];
  1500. $("input[name='del_month']:checked").each(function () {
  1501. del_month_array.push($(this).val());
  1502. });
  1503. if (del_month_array.length === 0) {
  1504. toastr.error('请选择要移除的月信息价');
  1505. return false;
  1506. }
  1507. postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
  1508. for (const dm of del_month_array) {
  1509. // _.remove(materialMonthSpreadSetting.cols, function (n) {
  1510. // return n.field === dm;
  1511. // });
  1512. _.remove(months, function (n) {
  1513. return n === dm;
  1514. });
  1515. }
  1516. monthsList = data.monthsList;
  1517. monthFunGather.monthsListSet();
  1518. // 工料表单价显示也要更新
  1519. materialBillsData = data.materialBillsData;
  1520. materialSpreadObj.materialSheetReset();
  1521. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1522. m_tp = data.m_tp;
  1523. if (materialTax) {
  1524. m_tax_tp = data.m_tax_tp;
  1525. }
  1526. resetTpTable();
  1527. $('#remove-month').modal('hide');
  1528. });
  1529. });
  1530. // 导入功能
  1531. let importFile = null;
  1532. $('#upload-xls-file').change(function () {
  1533. const file = this.files[0];
  1534. importFile = file;
  1535. });
  1536. $('#import-bills-btn').click(function() {
  1537. if (!importFile) {
  1538. toastr.error('请选择excel文件再确定');
  1539. return;
  1540. }
  1541. const ext = importFile.name.toLowerCase().split('.').splice(-1)[0];
  1542. const imgStr = /(xls|xlsx|XLS|XLSX)$/;
  1543. if (!imgStr.test(ext)) {
  1544. toastr.error('请导入正确格式的excel文件。');
  1545. return
  1546. }
  1547. const fileReader = new FileReader();
  1548. fileReader.onload = async function(ev) {
  1549. try{
  1550. const data = ev.target.result;
  1551. let tree = [];
  1552. const includeSpec = $('#xls-spec').is(':checked');
  1553. if (/(xls|xlsx|XLS|XLSX)$/.test(ext)) {
  1554. const workbook = XLSX.read(data, {type: 'binary'}); // 以二进制流方式读取得到整份excel表格对象
  1555. const jsonData = transExcel(XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]], { defval: null }));
  1556. console.log(jsonData);
  1557. if (!(jsonData[0] && jsonData[0].code !== undefined && jsonData[0].code !== null && jsonData[0].unit !== undefined && jsonData[0].name !== undefined &&
  1558. jsonData[0].spec !== undefined && jsonData[0].msg_tp !== undefined && jsonData[0].msg_times !== undefined)) {
  1559. throw 'excel必须按指定格式内容上传';
  1560. }
  1561. // 去重
  1562. tree = _.unionWith(jsonData, function (item1, item2) {
  1563. return item1.code === item2.code && item1.name === item2.name && item1.unit === item2.unit && (!includeSpec || (includeSpec && item1.spec === item2.spec));
  1564. });
  1565. }
  1566. if (tree.length === 0) {
  1567. throw '该excel不存在导入的数据';
  1568. }
  1569. // 判断msg_tp格式,不符合则无法导入,还有excel日期转换问题
  1570. for (const t of tree) {
  1571. t.code = t.code.toString();
  1572. if (t.msg_tp) {
  1573. if (_.isNumber(t.msg_tp)) {
  1574. const num = parseFloat(t.msg_tp);
  1575. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1576. if (num < 0 || !reg.test(num)) {
  1577. t.msg_tp = ZhCalc.round(num, materialDecimal.up);
  1578. }
  1579. } else {
  1580. throw '信息价数据存在非数字字符,无法导入';
  1581. }
  1582. }
  1583. if (_.isNumber(t.msg_times)) {
  1584. t.msg_times = formatDate(t.msg_times, '/');
  1585. }
  1586. t.spec = t.spec === null ? '' : t.spec;
  1587. }
  1588. console.log(tree);
  1589. postData(window.location.pathname + '/save', { type:'export', postData: tree, includeSpec, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  1590. m_tp = result.m_tp;
  1591. if (materialTax) {
  1592. m_tax_tp = result.m_tax_tp;
  1593. }
  1594. materialBillsData = result.billsData;
  1595. if (isStageSelf) {
  1596. materialStageData = result.stageData;
  1597. materialStageBillsData = result.stageBillsData;
  1598. }
  1599. materialSpreadObj.getMaterialBillsData();
  1600. materialSpreadObj.materialSheetReset(true);
  1601. if (months.length > 0) {
  1602. monthsList = result.monthsList;
  1603. monthFunGather.monthsListSet();
  1604. }
  1605. resetTpTable();
  1606. if (result.addNum || result.updateNum) {
  1607. let msg = [];
  1608. if (result.addNum !== undefined && result.addNum !== 0) {
  1609. msg.push('成功导入工料 ' + result.addNum + ' 条');
  1610. }
  1611. if (result.updateNum !== undefined && result.updateNum !== 0) {
  1612. msg.push('成功更新工料 ' + result.updateNum + ' 条');
  1613. }
  1614. toastr.success(msg.length > 1 ? msg.join(',并') : msg[0]);
  1615. } else {
  1616. toastr.warning('不存在可导入的信息价数据');
  1617. }
  1618. $('#import-info').modal('hide');
  1619. });
  1620. } catch (error) {
  1621. console.log(error);
  1622. toastr.error(error);
  1623. return
  1624. }
  1625. };
  1626. // 以二进制方式打开文件
  1627. fileReader.readAsBinaryString(importFile);
  1628. $('#upload-xls-file').val('');
  1629. importFile = null;
  1630. });
  1631. } else {
  1632. // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
  1633. }
  1634. // 筛选调差工料本期应耗数量为0
  1635. $('#bills0_list').click(function () {
  1636. const isCheck = $(this).is(':checked');
  1637. let newMaterialBillsData = materialBillsData;
  1638. if (isCheck) {
  1639. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1640. return item.quantity !== null && item.quantity !== 0;
  1641. });
  1642. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1643. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1644. }
  1645. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1646. monthFunGather.monthsListSet(newMaterialBillsData, false);
  1647. materialSpreadObj.refreshActn();
  1648. });
  1649. let gljLib;
  1650. const gljLibCellDoubleClick = function (e, info) {
  1651. if (readOnly || editForAudit) return;
  1652. const gljSheet = info.sheet;
  1653. if (!gljSheet.zh_setting || !gljSheet.zh_tree) { return; }
  1654. const gljTree = gljSheet.zh_tree;
  1655. const gljNode = gljTree.nodes[info.row];
  1656. const sheet = materialSpread.getActiveSheet();
  1657. const select = SpreadJsObj.getSelectObject(sheet);
  1658. if (!gljNode) return;
  1659. if (gljNode && gljNode.is_leaf === 0) {
  1660. toastr.warning('非最底层项目下,不应添加');
  1661. return;
  1662. }
  1663. postData(window.location.pathname + '/save', { type:'add-glj', postData: gljNode, order: select ? select.order : null }, function (result) {
  1664. if (result) {
  1665. // 比order大的+1
  1666. const maxData = select ? _.filter(materialBillsData, (item) => { return item.order > select.order }) : [];
  1667. _.forEach(maxData, function (item) {
  1668. const cl = _.find(materialBillsData, { id: item.id });
  1669. cl.order = item.order + 1;
  1670. });
  1671. materialBillsData.push(result.info);
  1672. materialBillsData.sort(function (a, b) {
  1673. return a.order - b.order
  1674. });
  1675. console.log(materialBillsData);
  1676. if (isStageSelf) {
  1677. materialSpreadObj.updateMaterialData(result);
  1678. materialSpreadObj.getMaterialBillsData();
  1679. }
  1680. // sheet.addRows(materialBillsData.length - 1, 1);
  1681. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  1682. let newMaterialBillsData = materialBillsData;
  1683. if($('#bills0_list').is(':checked')) {
  1684. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1685. return item.quantity !== null && item.quantity !== 0;
  1686. });
  1687. }
  1688. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1689. // materialSpreadObj.materialSheetReset();
  1690. sheet.setSelection(sheet.zh_data.indexOf(select) + 1, 0, 1, 1);
  1691. materialSpreadObj.refreshActn();
  1692. // 月信息价需要同时添加空白的list
  1693. if (months.length > 0) {
  1694. const one_month ={ mb_id: result.info.id, code: result.info.code, name: result.info.name, origin: result.info.origin, unit: result.info.unit, order: result.info.order };
  1695. for (const m of months) {
  1696. one_month[m] = null;
  1697. }
  1698. _.forEach(maxData, function (item) {
  1699. const cl = _.find(monthsList, { mb_id: item.id });
  1700. cl.order = item.order + 1;
  1701. });
  1702. monthsList.push(one_month);
  1703. monthsList.sort(function (a, b) {
  1704. return a.order - b.order
  1705. });
  1706. console.log(monthsList);
  1707. // const newMonthsList = _.filter(monthsList, function (item) {
  1708. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  1709. // });
  1710. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  1711. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  1712. monthFunGather.monthsListSet();
  1713. // materialMonthSpreadObj.monthsListSet();
  1714. }
  1715. }
  1716. });
  1717. };
  1718. const gljLibSetting = {
  1719. selector: '#material-tab',
  1720. stdType: 'glj',
  1721. libs: gljLists,
  1722. treeSetting: {
  1723. id: 'glj_id',
  1724. pid: 'glj_pid',
  1725. order: 'order',
  1726. level: 'level',
  1727. rootId: -1,
  1728. keys: ['id', 'list_id', 'glj_id'],
  1729. },
  1730. spreadSetting: {
  1731. cols: [
  1732. {title: '编号', field: 'code', hAlign: 0, width: 120, formatter: '@', readOnly: true, cellType: 'tree'},
  1733. {title: '名称', field: 'name', hAlign: 0, width: 150, formatter: '@', readOnly: true},
  1734. {title: '单位', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1735. {title: '参考上涨幅度', field: 'rise_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1736. {title: '参考下跌幅度', field: 'fall_range', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  1737. ],
  1738. treeCol: 0,
  1739. emptyRows: 0,
  1740. headRows: 1,
  1741. headRowHeight: [32],
  1742. defaultRowHeight: 21,
  1743. headerFont: '12px 微软雅黑',
  1744. font: '12px 微软雅黑',
  1745. headColWidth: [30],
  1746. selectedBackColor: '#fffacd',
  1747. },
  1748. spreadClassCss: 'sjs-material',
  1749. cellDoubleClick: gljLibCellDoubleClick,
  1750. page: 'material',
  1751. tid: window.location.pathname.split('/')[2],
  1752. };
  1753. $.subMenu({
  1754. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1755. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1756. key: 'menu.1.0.0',
  1757. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1758. callback: function (info) {
  1759. if (info.mini) {
  1760. $('.panel-title').addClass('fluid');
  1761. $('#sub-menu').removeClass('panel-sidebar');
  1762. } else {
  1763. $('.panel-title').removeClass('fluid');
  1764. $('#sub-menu').addClass('panel-sidebar');
  1765. }
  1766. autoFlashHeight();
  1767. materialSpread.refresh();
  1768. }
  1769. });
  1770. $.divResizer({
  1771. select: '#right-spr',
  1772. callback: function () {
  1773. materialSpread.refresh();
  1774. materialMonthSpread.refresh();
  1775. if (gljLib) gljLib.spread.refresh();
  1776. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1777. setLocalCache('material_month_' + materialID, width);
  1778. }
  1779. });
  1780. $.divResizer({
  1781. select: '#main-resize',
  1782. callback: function () {
  1783. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1784. $(".sp-wrap").height(bcontent-30);
  1785. const height = $('.bcontent-wrap').height();
  1786. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1787. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1788. updateSjsHeight();
  1789. materialSpread.refresh();
  1790. materialMonthSpread.refresh();
  1791. if (gljLib) gljLib.spread.refresh();
  1792. setLocalCache('material_bills_' + materialID, height);
  1793. }
  1794. });
  1795. // 展开收起月信息价并浏览器记住本期展开收起
  1796. $('a', '.right-nav').bind('click', function () {
  1797. //const main = $('#main-view'), tool = $('#tools-view');
  1798. const tab = $(this), tabPanel = $(tab.attr('content'));
  1799. if (!tab.hasClass('active')) {
  1800. $('a', '.side-menu').removeClass('active');
  1801. $('.tab-content .tab-pane').removeClass('active');
  1802. tab.addClass('active');
  1803. tabPanel.addClass('active');
  1804. showSideTools(tab.hasClass('active'));
  1805. if (tab.attr('content') === '#month-tab') {
  1806. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1807. setLocalCache('material_month_' + materialID, width);
  1808. materialMonthSpread.refresh();
  1809. } else if (tab.attr('content') === '#material-tab') {
  1810. if (!gljLib) {
  1811. gljLib = $.gljLib(gljLibSetting);
  1812. }
  1813. updateSjsHeight();
  1814. gljLib.spread.refresh();
  1815. }
  1816. } else {
  1817. removeLocalCache('material_month_' + materialID);
  1818. tab.removeClass('active');
  1819. tabPanel.removeClass('active');
  1820. showSideTools(tab.hasClass('active'));
  1821. }
  1822. materialSpread.refresh();
  1823. // materialMonthSpread.refresh();
  1824. });
  1825. // 根据浏览器记录展开收起
  1826. if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
  1827. const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
  1828. $('a', '.side-menu').removeClass('active');
  1829. $('.tab-content .tab-pane').removeClass('active');
  1830. tab.addClass('active');
  1831. tabPanel.addClass('active');
  1832. $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
  1833. showSideTools(tab.hasClass('active'));
  1834. materialSpread.refresh();
  1835. materialMonthSpread.refresh();
  1836. }
  1837. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1838. if (getLocalCache('material_bills_' + materialID)) {
  1839. $('.bcontent-wrap').height(getLocalCache('material_bills_' + materialID));
  1840. const cHeader = getObjHeight($(".c-header"));
  1841. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1842. $(".sp-wrap").height(bcontent-30);
  1843. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1844. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1845. updateSjsHeight();
  1846. materialSpread.refresh();
  1847. materialMonthSpread.refresh();
  1848. if (gljLib) gljLib.spread.refresh();
  1849. } else {
  1850. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1851. updateSjsHeight();
  1852. materialSpread.refresh();
  1853. materialMonthSpread.refresh();
  1854. if (gljLib) gljLib.spread.refresh();
  1855. }
  1856. function updateSjsHeight() {
  1857. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  1858. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  1859. $('.sjs-material').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar')));
  1860. }
  1861. function getObjHeight(select) {
  1862. return select.length > 0 ? select.height() : 0;
  1863. }
  1864. function formatDate(numb, format) {
  1865. const old = numb - 1;
  1866. const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
  1867. const time = new Date(1900, 0, old, 0, 0, t);
  1868. const year = time.getFullYear();
  1869. const month = time.getMonth() + 1;
  1870. const date = time.getDate();
  1871. return year + format + (month < 10 ? '0' + month : month) + format + (date < 10 ? '0' + date : date);
  1872. }
  1873. function transExcel(results) {
  1874. const mapInfo = {
  1875. '编号': 'code',
  1876. '名称': 'name',
  1877. '单位': 'unit',
  1878. '规格': 'spec',
  1879. '信息价': 'msg_tp',
  1880. '时间': 'msg_times',
  1881. };
  1882. return results.map(zhObj => {
  1883. const enObj = {}
  1884. const zhKeys = Object.keys(zhObj);
  1885. zhKeys.forEach(zhKey => {
  1886. const enKey = mapInfo[zhKey];
  1887. enObj[enKey] = zhObj[zhKey] && _.isString(zhObj[zhKey]) ? _.trim(zhObj[zhKey]) : zhObj[zhKey];
  1888. });
  1889. return enObj
  1890. })
  1891. }
  1892. });