material.js 96 KB

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