material.js 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  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.round(ZhCalc.add(pre_tp, 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.round(ZhCalc.add(m_tax_pre_tp, 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.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  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 + '</td>\n' : '';
  87. html += '<tr><td>第' + ms.order + '期</td><td class="text-center">' + 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: 'readOnly.remark'});
  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: 50, 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: '@', 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: '@', 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.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', '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.id });
  256. for (const nu of needUpdateArray) {
  257. mb[nu] = msbInfo[nu];
  258. }
  259. }
  260. }
  261. return materialBillsData;
  262. },
  263. updateOneMaterialBill: function (data) {
  264. const ms_id = $('#myTab').find('.active').data('msid');
  265. const msbInfo = _.find(materialStageBillsData, { ms_id, mb_id: data.id });
  266. console.log(msbInfo);
  267. data.ms_id = ms_id;
  268. for (const nu of needUpdateArray) {
  269. data[nu] = msbInfo[nu];
  270. }
  271. return data;
  272. },
  273. updateMaterialData: function (datas) {
  274. if (datas.stageData && datas.stageData.length > 0) {
  275. if (datas.stageData.length === materialStageData.length) {
  276. // 全体替换
  277. materialStageData = datas.stageData;
  278. } else {
  279. // 替换对应的stage数据
  280. for (const s of datas.stageData) {
  281. const index = _.findIndex(materialStageData, { id: s.id });
  282. materialStageData.splice(index, 1, s);
  283. }
  284. }
  285. }
  286. if (datas.pushStageBillsData && datas.pushStageBillsData.length > 0) {
  287. materialStageBillsData = _.concat(materialStageBillsData, datas.pushStageBillsData);
  288. }
  289. if (datas.stageBillsData && datas.stageBillsData.length > 0) {
  290. if (datas.stageBillsData.length === materialStageBillsData.length) {
  291. // 全体替换
  292. materialStageBillsData = datas.stageBillsData;
  293. } else {
  294. // 替换对应的stage数据
  295. for (const s of datas.stageBillsData) {
  296. const index = _.findIndex(materialStageBillsData, { id: s.id });
  297. materialStageBillsData.splice(index, 1, s);
  298. }
  299. }
  300. }
  301. },
  302. materialSheetReset: function () {
  303. let newMaterialBillsData = materialBillsData;
  304. console.log(materialBillsData);
  305. if($('#bills0_list').is(':checked')) {
  306. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  307. return item.quantity !== null && item.quantity !== 0;
  308. });
  309. }
  310. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  311. materialSpreadObj.refreshActn();
  312. },
  313. refreshActn: function (rowCount = 1) {
  314. const setObjEnable = function (obj, enable) {
  315. if (enable) {
  316. obj.removeClass('disabled');
  317. } else {
  318. obj.addClass('disabled');
  319. }
  320. };
  321. const sheet = materialSpread.getActiveSheet();
  322. const select = SpreadJsObj.getSelectObject(sheet);
  323. // 还需判断是否已被调差清单调用
  324. setObjEnable($('#del'), !readOnly && select && materialBase.isUsed(select) && rowCount === 1);
  325. setObjEnable($('#up-move'), !readOnly && select && materialBillsData.indexOf(select) > 0 && !$('#bills0_list').is(':checked'));
  326. setObjEnable($('#down-move'), !readOnly && select && materialBillsData.indexOf(select) < materialBillsData.length - 1 && !$('#bills0_list').is(':checked'));
  327. },
  328. add: function () {
  329. const sheet = materialSpread.getActiveSheet();
  330. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  331. if (result) {
  332. materialBillsData.push(result.info);
  333. if (isStageSelf) {
  334. materialSpreadObj.updateMaterialData(result);
  335. materialSpreadObj.getMaterialBillsData();
  336. }
  337. // sheet.addRows(materialBillsData.length - 1, 1);
  338. // SpreadJsObj.reLoadRowData(sheet, materialBillsData.length - 1);
  339. let newMaterialBillsData = materialBillsData;
  340. if($('#bills0_list').is(':checked')) {
  341. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  342. return item.quantity !== null && item.quantity !== 0;
  343. });
  344. }
  345. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  346. // materialSpreadObj.materialSheetReset();
  347. sheet.setSelection(newMaterialBillsData.length - 1, 0, 1, 1);
  348. materialSpreadObj.refreshActn();
  349. // 月信息价需要同时添加空白的list
  350. if (months.length > 0) {
  351. const one_month ={ mb_id: result.id, code: '', name: null, origin: null, unit: null, order: result.order };
  352. for (const m of months) {
  353. one_month[m] = null;
  354. }
  355. monthsList.push(one_month);
  356. // const newMonthsList = _.filter(monthsList, function (item) {
  357. // return _.findIndex(newMaterialBillsData, { code: item.code }) !== -1;
  358. // });
  359. // materialMonthSpread.getActiveSheet().addRows(newMonthsList.length - 1, 1);
  360. // SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), newMonthsList.length - 1);
  361. monthFunGather.monthsListSet();
  362. // materialMonthSpreadObj.monthsListSet();
  363. }
  364. }
  365. });
  366. },
  367. del: function () {
  368. const sheet = materialSpread.getActiveSheet();
  369. const select = SpreadJsObj.getSelectObject(sheet);
  370. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  371. m_tp = result.m_tp;
  372. if (materialTax) {
  373. m_tax_tp = result.m_tax_tp;
  374. }
  375. const index = materialBillsData.indexOf(select);
  376. let newMaterialBillsData = materialBillsData;
  377. let newIndex = index;
  378. if($('#bills0_list').is(':checked')) {
  379. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  380. return item.quantity !== null && item.quantity !== 0;
  381. });
  382. newIndex = newMaterialBillsData.indexOf(select);
  383. }
  384. materialBillsData.splice(index, 1);
  385. sheet.deleteRows(newIndex, 1);
  386. if (isStageSelf) {
  387. materialSpreadObj.updateMaterialData(result);
  388. materialSpreadObj.getMaterialBillsData();
  389. }
  390. resetTpTable();
  391. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  392. const sel = sheet.getSelections();
  393. sheet.setSelection(newIndex > 0 ? newIndex - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  394. materialSpreadObj.refreshActn();
  395. // 月信息价需要同时删除
  396. if (months.length > 0) {
  397. monthsList.splice(index, 1);
  398. materialMonthSpread.getActiveSheet().deleteRows(newIndex, 1);
  399. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  400. }
  401. });
  402. },
  403. upMove: function () {
  404. if($('#bills0_list').is(':checked')) {
  405. return;
  406. }
  407. const sheet = materialSpread.getActiveSheet();
  408. const cur = SpreadJsObj.getSelectObject(sheet);
  409. const up = materialBillsData[materialBillsData.indexOf(cur) - 1];
  410. const mbIndex = materialBillsData.indexOf(cur);
  411. postData(window.location.pathname + '/save', {type: 'changeOrder', id1: cur.id, id2: up.id}, function () {
  412. const order = cur.order;
  413. cur.order = up.order;
  414. up.order = order;
  415. materialBillsData.sort(function (a, b) {
  416. return a.order - b.order
  417. });
  418. SpreadJsObj.reLoadSheetData(sheet);
  419. const sel = sheet.getSelections();
  420. const index = materialBillsData.indexOf(cur);
  421. sheet.setSelection(index, sel.length > 0 ? sel[0].col : 0, 1, 1);
  422. materialSpreadObj.refreshActn();
  423. if (months.length > 0) {
  424. const monthCur = monthsList[mbIndex];
  425. const monthUp = monthsList[mbIndex - 1];
  426. const monthOrder = monthCur.order;
  427. monthCur.order = monthUp.order;
  428. monthUp.order = monthOrder;
  429. monthsList.sort(function (a, b) {
  430. return a.order - b.order
  431. });
  432. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  433. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  434. }
  435. });
  436. },
  437. downMove: function () {
  438. if($('#bills0_list').is(':checked')) {
  439. return;
  440. }
  441. const sheet = materialSpread.getActiveSheet();
  442. const cur = SpreadJsObj.getSelectObject(sheet);
  443. const down = materialBillsData[materialBillsData.indexOf(cur) + 1];
  444. const mbIndex = materialBillsData.indexOf(cur);
  445. postData(window.location.pathname + '/save', {
  446. type: 'changeOrder',
  447. id1: cur.id,
  448. id2: down.id
  449. }, function () {
  450. const order = cur.order;
  451. cur.order = down.order;
  452. down.order = order;
  453. materialBillsData.sort(function (a, b) {
  454. return a.order - b.order
  455. });
  456. SpreadJsObj.reLoadSheetData(sheet);
  457. const sel = sheet.getSelections();
  458. const index = materialBillsData.indexOf(cur);
  459. sheet.setSelection(index, sel.length > 0 ? sel[0].col : 0, 1, 1);
  460. materialSpreadObj.refreshActn();
  461. if (months.length > 0) {
  462. const monthCur = monthsList[mbIndex];
  463. const monthDown = monthsList[mbIndex + 1];
  464. const monthOrder = monthCur.order;
  465. monthCur.order = monthDown.order;
  466. monthDown.order = monthOrder;
  467. monthsList.sort(function (a, b) {
  468. return a.order - b.order
  469. });
  470. const materialMonthSheet = materialMonthSpread.getActiveSheet();
  471. SpreadJsObj.reLoadSheetData(materialMonthSheet);
  472. }
  473. });
  474. },
  475. selectionChanged: function (e, info) {
  476. const sel = info.sheet.getSelections()[0];
  477. const col = info.sheet.zh_setting.cols[sel.col];
  478. materialSpreadObj.refreshActn(sel.rowCount);
  479. const data = SpreadJsObj.getSelectObject(info.sheet);
  480. materialSpreadObj.setReadOnly(true);
  481. console.log(data);
  482. },
  483. editEnded: function (e, info) {
  484. if (info.sheet.zh_setting) {
  485. const select = SpreadJsObj.getSelectObject(info.sheet);
  486. const col = info.sheet.zh_setting.cols[info.col];
  487. if (col.field === 'is_summary') {
  488. return;
  489. }
  490. // 未改变值则不提交
  491. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  492. const orgValue = select[col.field];
  493. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  494. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  495. return;
  496. }
  497. // 判断部分值是否输入的是数字判断和数据计算
  498. if (col.field === 'basic_price') {
  499. if (isNaN(validText)) {
  500. toastr.error('不能输入其它非数字类型字符');
  501. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  502. return;
  503. }
  504. let num = parseFloat(validText);
  505. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  506. if (validText !== null && (num < 0 || !reg.test(num))) {
  507. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  508. validText = ZhCalc.round(num, materialDecimal.up);
  509. }
  510. }
  511. if (col.field === 'msg_tp') {
  512. if (isNaN(validText)) {
  513. toastr.error('不能输入其它非数字类型字符');
  514. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  515. return;
  516. }
  517. const num = parseFloat(validText);
  518. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  519. if (validText !== null && (num < 0 || !reg.test(num))) {
  520. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  521. validText = ZhCalc.round(num, materialDecimal.up);
  522. }
  523. }
  524. if (col.field === 'm_up_risk' || col.field === 'm_down_risk' || col.field === 'm_tax') {
  525. // 只能输入正整数
  526. if (isNaN(validText)) {
  527. toastr.error('不能输入其它非数字类型字符');
  528. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  529. return;
  530. }
  531. const num = parseFloat(validText);
  532. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  533. toastr.error('只能输入0-100的正整数');
  534. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  535. return;
  536. }
  537. }
  538. if (col.field === 't_type') {
  539. if (validText === 1) {
  540. select.quantity = null;
  541. select.expr = null;
  542. select.m_tp = null;
  543. }
  544. }
  545. select[col.field] = validText;
  546. select.msg_spread = materialCol.getValue.msg_spread(select);
  547. select.m_spread = materialCol.getValue.m_spread(select);
  548. select.m_tp = materialCol.getValue.m_tp(select);
  549. select.m_tax_tp = materialCol.getValue.m_tax_tp(select);
  550. delete select.waitingLoading;
  551. // console.log(select);
  552. // 更新至服务器
  553. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  554. m_tp = result.m_tp;
  555. if (materialTax) {
  556. m_tax_tp = result.m_tax_tp;
  557. }
  558. if (isStageSelf) {
  559. materialSpreadObj.updateMaterialData(result);
  560. }
  561. resetTpTable();
  562. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  563. // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
  564. if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
  565. const index = materialBillsData.indexOf(select);
  566. monthsList[index][col.field] = validText;
  567. monthFunGather.monthsListSet();
  568. }
  569. }, function () {
  570. select[col.field] = orgValue;
  571. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  572. });
  573. }
  574. },
  575. buttonClicked: function (e, info) {
  576. if (info.sheet.zh_setting) {
  577. const select = SpreadJsObj.getSelectObject(info.sheet);
  578. const col = info.sheet.zh_setting.cols[info.col];
  579. if (materialCol.readOnly.isEdit(select)) {
  580. return;
  581. }
  582. if (col.field === 'is_summary') {
  583. if (info.sheet.isEditing()) {
  584. info.sheet.endEdit(true);
  585. }
  586. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  587. delete select.waitingLoading;
  588. // 更新至服务器
  589. postData(window.location.pathname + '/save', { type:'update', updateData: select, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  590. m_tp = result.m_tp;
  591. if (materialTax) {
  592. m_tax_tp = result.m_tax_tp;
  593. }
  594. if (isStageSelf) {
  595. materialSpreadObj.updateMaterialData(result);
  596. }
  597. resetTpTable();
  598. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  599. }, function () {
  600. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  601. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  602. });
  603. }
  604. }
  605. },
  606. deletePress: function (sheet) {
  607. return;
  608. },
  609. clipboardPasted(e, info) {
  610. const hint = {
  611. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  612. codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
  613. codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
  614. codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
  615. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  616. riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
  617. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  618. };
  619. const range = info.cellRange;
  620. const sortData = info.sheet.zh_data || [];
  621. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  622. toastMessageUniq(hint.cellError);
  623. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  624. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  625. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  626. return;
  627. }
  628. if (sortData.length > 0 && range.col + range.colCount > 18) {
  629. toastMessageUniq(hint.cellError);
  630. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  631. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  632. return;
  633. }
  634. const data = [];
  635. // const rowData = [];
  636. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  637. let bPaste = true;
  638. const curRow = range.row + iRow;
  639. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  640. const materialData = { id: sortData[curRow].id };
  641. const hintRow = range.rowCount > 1 ? curRow : '';
  642. let sameCol = 0;
  643. for (let iCol = 0; iCol < range.colCount; iCol++) {
  644. const curCol = range.col + iCol;
  645. const colSetting = info.sheet.zh_setting.cols[curCol];
  646. if (!colSetting) continue;
  647. let validText = info.sheet.getText(curRow, curCol);
  648. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  649. const orgValue = sortData[curRow][colSetting.field];
  650. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  651. sameCol++;
  652. if (range.colCount === sameCol) {
  653. bPaste = false;
  654. }
  655. continue;
  656. }
  657. if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
  658. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  659. bPaste = false;
  660. continue;
  661. }
  662. if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
  663. toastMessageUniq(getPasteHint(hint.codeError, hintRow));
  664. bPaste = false;
  665. continue;
  666. }
  667. if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
  668. toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
  669. bPaste = false;
  670. continue;
  671. }
  672. if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
  673. continue;
  674. }
  675. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
  676. || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  677. if (isNaN(validText)) {
  678. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  679. bPaste = false;
  680. continue;
  681. }
  682. const num = parseFloat(validText);
  683. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
  684. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  685. if (validText !== null && (num < 0 || !reg.test(num))) {
  686. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  687. validText = ZhCalc.round(num, materialDecimal.up);
  688. }
  689. } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk' || colSetting.field === 'm_tax') {
  690. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  691. toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
  692. bPaste = false;
  693. continue;
  694. }
  695. }
  696. }
  697. materialData[colSetting.field] = validText;
  698. sortData[curRow][colSetting.field] = validText;
  699. }
  700. if (materialData.code === '' || materialData.code === null) {
  701. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  702. bPaste = false;
  703. }
  704. if (bPaste) {
  705. materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
  706. materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
  707. materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
  708. materialData.m_tax_tp = materialCol.getValue.m_tax_tp(sortData[curRow]);
  709. data.push(materialData);
  710. // rowData.push(curRow);
  711. } else {
  712. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  713. }
  714. }
  715. if (data.length === 0) {
  716. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  717. return;
  718. }
  719. // console.log(data);
  720. // 更新至服务器
  721. postData(window.location.pathname + '/save', { type:'paste', updateData: data, ms_id: $('#myTab').find('.active').data('msid') || null }, function (result) {
  722. materialBillsData = result.info;
  723. m_tp = result.m_tp;
  724. if (materialTax) {
  725. m_tax_tp = result.m_tax_tp;
  726. }
  727. if (isStageSelf) {
  728. materialSpreadObj.updateMaterialData(result);
  729. materialSpreadObj.getMaterialBillsData();
  730. }
  731. // SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  732. materialSpreadObj.materialSheetReset();
  733. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  734. // for (const row in rowData) {
  735. // materialBillsData.splice(index, 1, result.info[row]);
  736. // SpreadJsObj.reLoadRowData(info.sheet, row);
  737. // }
  738. if (months.length > 0) {
  739. for (const [i,m] of monthsList.entries()) {
  740. m.code = materialBillsData[i].code;
  741. m.name = materialBillsData[i].name;
  742. m.unit = materialBillsData[i].unit;
  743. m.origin = materialBillsData[i].origin;
  744. }
  745. // SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  746. monthFunGather.monthsListSet();
  747. // SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  748. }
  749. resetTpTable();
  750. // materialSpreadObj.refreshActn();
  751. }, function () {
  752. // materialSpreadObj.refreshActn();
  753. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  754. return;
  755. });
  756. },
  757. setReadOnly: function(readOnly) {
  758. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  759. }
  760. };
  761. materialSpreadObj.refreshActn();
  762. materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
  763. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  764. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  765. const sheet = materialSpread.getActiveSheet();
  766. sheet.suspendPaint();
  767. // const basic_range = sheet.getRange(-1, 8, -1, 1);
  768. // basic_range.cellType(new DatePickerCellType());
  769. // basic_range.formatter("yyyy-MM-dd");
  770. // const msg_range = sheet.getRange(-1, 10, -1, 1);
  771. // msg_range.cellType(new DatePickerCellType());
  772. // msg_range.formatter("yyyy-MM-dd");
  773. sheet.resumePaint();
  774. const static_cols = [
  775. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
  776. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 100, formatter: '@', readOnly: true},
  777. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},
  778. {title: '来源地', colSpan: '1', rowSpan: '2', field: 'origin', hAlign: 0, width: 70, formatter: '@', readOnly: 'readOnly.isEdit'},
  779. {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
  780. ];
  781. // 月信息价方法集合
  782. const monthFunGather = {
  783. _setMonthHtml: function() {
  784. let html = '';
  785. let qihtml = '';
  786. for (const m of months) {
  787. html += '<div class="custom-control custom-checkbox mb-2">\n' +
  788. ' <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
  789. ' <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
  790. ' </div>';
  791. qihtml += parseInt(m.split('-')[1]) + '月,';
  792. }
  793. if (months.length > 0) {
  794. qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
  795. qihtml = qihtml.substring(0, qihtml.length-1);
  796. }
  797. $('#show_month').html(html);
  798. $('#qi-month').html(qihtml);
  799. },
  800. _monthHeaderSet: function() {
  801. const newMonths = [];
  802. for (const m of months) {
  803. const year = m.split('-')[0];
  804. const month = parseInt(m.split('-')[1]);
  805. let one = _.find(newMonths, { 'year': year });
  806. let oneIndex = _.findIndex(newMonths, { 'year': year });
  807. if (one) {
  808. one.month.push(month);
  809. newMonths.splice(oneIndex, 1, one);
  810. } else {
  811. one = {
  812. year: year,
  813. month: [ month ],
  814. };
  815. newMonths.push(one);
  816. }
  817. }
  818. const pushMonth = [];
  819. for(const mo of newMonths) {
  820. for (let i in mo.month) {
  821. i = parseInt(i);
  822. const newCols = {
  823. title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
  824. colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
  825. rowSpan: i === 0 ? '1|1' : '|1',
  826. field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
  827. hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
  828. pushMonth.push(newCols);
  829. }
  830. }
  831. return pushMonth;
  832. },
  833. monthSheetReset: function (ml = monthsList) {
  834. const monthCols = monthFunGather._monthHeaderSet();
  835. const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
  836. materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
  837. // 表头变化需要重新绘制,不然报错;
  838. materialMonthSpread.getActiveSheet().reset();
  839. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  840. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  841. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, ml);
  842. monthFunGather._setMonthHtml();
  843. },
  844. monthsListSet: function (ml = materialBillsData, checked = true) {
  845. if($('#bills0_list').is(':checked') && checked) {
  846. ml = _.filter(materialBillsData, function (item) {
  847. return item.quantity === null || item.quantity === 0;
  848. });
  849. }
  850. const newMonthsList = _.filter(monthsList, function (item) {
  851. return _.findIndex(ml, { code: item.code }) !== -1;
  852. });
  853. monthFunGather.monthSheetReset(newMonthsList);
  854. }
  855. };
  856. const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
  857. const materialMonthSpreadSetting = {
  858. cols: static_cols,
  859. emptyRows: 0,
  860. headRows: 2,
  861. headRowHeight: [25, 25],
  862. defaultRowHeight: 21,
  863. headerFont: '12px 微软雅黑',
  864. font: '12px 微软雅黑',
  865. readOnly: readOnly,
  866. };
  867. if (months.length > 0) {
  868. const monthCols = monthFunGather._monthHeaderSet();
  869. const monthSpreadHeaderCols = static_cols.concat(monthCols);
  870. materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
  871. }
  872. const materialMonthCol = {
  873. getValue: {
  874. average_msg_tp: function (data) {
  875. let msg_tp = 0;
  876. let hadnum = 0;
  877. for (const m of months) {
  878. msg_tp += data[m];
  879. if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
  880. hadnum++;
  881. }
  882. }
  883. const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), materialDecimal.up) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), materialDecimal.up);
  884. return average_tp;
  885. },
  886. },
  887. readOnly: {
  888. isEdit: function (data) {
  889. return readOnly;
  890. },
  891. },
  892. };
  893. materialMonthSpread.getActiveSheet().frozenColumnCount(5);
  894. materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
  895. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  896. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  897. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  898. const materialMonthSpreadObj = {
  899. editEnded: function (e, info) {
  900. if (info.sheet.zh_setting) {
  901. const select = SpreadJsObj.getSelectObject(info.sheet);
  902. const col = info.sheet.zh_setting.cols[info.col];
  903. // 未改变值则不提交
  904. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  905. const orgValue = select[col.field];
  906. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  907. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  908. return;
  909. }
  910. if (col.field === 'origin') {
  911. select[col.field] = validText;
  912. postData(window.location.pathname + '/month/save', { type:'updateOrigin', updateData: { mb_id: select.mb_id, value: validText } }, function (result) {
  913. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  914. materialBillsData = result.materialBillsData;
  915. materialSpreadObj.materialSheetReset();
  916. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  917. }, function () {
  918. select[col.field] = orgValue;
  919. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  920. });
  921. } else {
  922. // 判断部分值是否输入的是数字判断和数据计算
  923. if (isNaN(validText)) {
  924. toastr.error('不能输入其它非数字类型字符');
  925. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  926. return;
  927. }
  928. const num = parseFloat(validText);
  929. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  930. if (validText !== null && (num < 0 || !reg.test(num))) {
  931. toastr.warning('已保留'+ materialDecimal.up +'位小数');
  932. validText = ZhCalc.round(num, materialDecimal.up);
  933. }
  934. select[col.field] = validText;
  935. // 更新至服务器
  936. postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
  937. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  938. materialBillsData = result.materialBillsData;
  939. materialSpreadObj.materialSheetReset();
  940. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  941. m_tp = result.m_tp;
  942. if (materialTax) {
  943. m_tax_tp = result.m_tax_tp;
  944. }
  945. resetTpTable();
  946. }, function () {
  947. select[col.field] = orgValue;
  948. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  949. });
  950. }
  951. }
  952. },
  953. deletePress: function (sheet) {
  954. // if (sheet.zh_setting && sheet.zh_data) {
  955. // const sel = sheet.getSelections()[0];
  956. // if (!sel) return;
  957. //
  958. // const col = sheet.zh_setting.cols[sel.col];
  959. // const select = SpreadJsObj.getSelectObject(sheet);
  960. // const orgValue = select[col.field];
  961. // if (sel.colCount > 1 || sel.rowCount > 1) {
  962. // toastr.warning('请勿同时删除多行或多列数据');
  963. // }
  964. // console.log(sel, select, col);
  965. // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  966. // return;
  967. // }
  968. // select[col.field] = null;
  969. // select.calc_num = materialExponentCol.getValue.calc_num(select);
  970. // console.log(select);
  971. // 更新至服务器
  972. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  973. // ex_tp = result.ex_tp;
  974. // ex_expr = result.ex_expr;
  975. // resetExTpTable();
  976. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  977. // materialExponentData.splice(sel.row, 1, select);
  978. // }, function () {
  979. // select[col.field] = orgValue;
  980. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  981. // });
  982. // }
  983. return;
  984. },
  985. clipboardPasted(e, info) {
  986. const hint = {
  987. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  988. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  989. numberCan: {type: 'warning', msg: '已保留'+ materialDecimal.up +'位小数'},
  990. };
  991. const range = info.cellRange;
  992. const sortData = info.sheet.zh_data || [];
  993. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  994. toastMessageUniq(hint.cellError);
  995. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  996. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  997. return;
  998. }
  999. if (sortData.length > 0 && range.col + range.colCount > 5 + months.length) {
  1000. toastMessageUniq(hint.cellError);
  1001. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  1002. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1003. return;
  1004. }
  1005. const data = [];
  1006. let pasteOrigin = false;
  1007. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  1008. let bPaste = true;
  1009. const curRow = range.row + iRow;
  1010. const materialMonthData = sortData[curRow];
  1011. const hintRow = range.rowCount > 1 ? curRow : '';
  1012. let sameCol = 0;
  1013. for (let iCol = 0; iCol < range.colCount; iCol++) {
  1014. const curCol = range.col + iCol;
  1015. const colSetting = info.sheet.zh_setting.cols[curCol];
  1016. if (!colSetting) continue;
  1017. let validText = info.sheet.getText(curRow, curCol);
  1018. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  1019. const orgValue = sortData[curRow][colSetting.field];
  1020. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  1021. sameCol++;
  1022. if (range.colCount === sameCol) {
  1023. bPaste = false;
  1024. }
  1025. continue;
  1026. }
  1027. if (colSetting.field === 'origin') {
  1028. pasteOrigin = true;
  1029. } else {
  1030. const num = parseFloat(validText);
  1031. if (isNaN(validText)) {
  1032. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  1033. bPaste = false;
  1034. continue;
  1035. }
  1036. const reg = materialDecimal.up ? new RegExp("^\\d+(\\.\\d{1,"+ materialDecimal.up +"})?$") : new RegExp("^\\d+?$");
  1037. if (validText !== null && (num < 0 || !reg.test(num))) {
  1038. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  1039. validText = ZhCalc.round(num, materialDecimal.up);
  1040. }
  1041. }
  1042. materialMonthData[colSetting.field] = validText;
  1043. sortData[curRow][colSetting.field] = validText;
  1044. }
  1045. if (bPaste) {
  1046. data.push(materialMonthData);
  1047. } else {
  1048. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  1049. }
  1050. }
  1051. if (data.length === 0) {
  1052. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1053. return;
  1054. }
  1055. // console.log(data);
  1056. if (pasteOrigin) {
  1057. // 更新至服务器
  1058. postData(window.location.pathname + '/month/save', { type:'pasteOrigin', updateData: data }, function (result) {
  1059. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1060. materialBillsData = result.materialBillsData;
  1061. }, function () {
  1062. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1063. return;
  1064. });
  1065. } else {
  1066. // 更新至服务器
  1067. postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
  1068. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  1069. materialBillsData = result.materialBillsData;
  1070. materialSpreadObj.materialSheetReset();
  1071. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1072. m_tp = result.m_tp;
  1073. if (materialTax) {
  1074. m_tax_tp = result.m_tax_tp;
  1075. }
  1076. resetTpTable();
  1077. }, function () {
  1078. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  1079. return;
  1080. });
  1081. }
  1082. },
  1083. };
  1084. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1085. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1086. materialSpreadObj.getMaterialBillsData();
  1087. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1088. materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
  1089. SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
  1090. // 期切换
  1091. $('#myTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  1092. e.preventDefault();
  1093. showWaitingView();
  1094. setTimeout(function () {
  1095. materialSpreadObj.getMaterialBillsData();
  1096. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  1097. // 消耗量表格更新
  1098. let html = '';
  1099. calcBase = _.find(calcBaseList, { ms_id: $('#myTab').find('.active').data('msid') }).calcBase;
  1100. for (let iBase = 0; iBase < calcBase.length; iBase++) {
  1101. html += '<tr><td>' + calcBase[iBase].name + '</td><td>' + calcBase[iBase].code + '</td><td>' + calcBase[iBase].value + '</td></tr>';
  1102. }
  1103. $('#calcBase').html(html);
  1104. closeWaitingView();
  1105. }, 1000);
  1106. });
  1107. if (!readOnly) {
  1108. $('#add').click(materialSpreadObj.add);
  1109. $('#del').click(materialSpreadObj.del);
  1110. $('#up-move').click(materialSpreadObj.upMove);
  1111. $('#down-move').click(materialSpreadObj.downMove);
  1112. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  1113. materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
  1114. materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
  1115. // 右键菜单
  1116. $.contextMenu({
  1117. selector: '#material-spread',
  1118. build: function ($trigger, e) {
  1119. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  1120. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  1121. },
  1122. items: {
  1123. 'create': {
  1124. name: '新增材料',
  1125. icon: 'fa-sign-in',
  1126. callback: function (key, opt) {
  1127. materialSpreadObj.add(materialSpread.getActiveSheet());
  1128. },
  1129. },
  1130. 'delete': {
  1131. name: '删除材料',
  1132. icon: 'fa-remove',
  1133. callback: function (key, opt) {
  1134. materialSpreadObj.del(materialSpread.getActiveSheet());
  1135. },
  1136. disabled: function (key, opt) {
  1137. const sheet = materialSpread.getActiveSheet();
  1138. const select = SpreadJsObj.getSelectObject(sheet);
  1139. const sel = sheet.getSelections()[0];
  1140. materialSpreadObj.refreshActn(sel.rowCount);
  1141. if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
  1142. return false;
  1143. } else {
  1144. return true;
  1145. }
  1146. }
  1147. },
  1148. }
  1149. });
  1150. $('.changeRate').click(function () {
  1151. $('#rateInput').val(parseInt($(this).data('value')));
  1152. $('#rateInput').siblings('.dropdown-menu').hide();
  1153. });
  1154. $('#rateInput').click(function () {
  1155. $(this).siblings('.dropdown-menu').show();
  1156. })
  1157. // 回车提交
  1158. $('#rateInput').on('keypress', function () {
  1159. if(window.event.keyCode === 13) {
  1160. $(this).blur();
  1161. }
  1162. });
  1163. $('#rateInput').blur(function () {
  1164. const _self = $(this);
  1165. setTimeout(function () {
  1166. let rate = parseFloat(_self.val());
  1167. if (_.isNaN(rate)) {
  1168. toastr.error('请输入0-100之前的整数值');
  1169. $('#rateInput').val(materialRate);
  1170. return;
  1171. }
  1172. rate = _.round(rate);
  1173. if(rate < 0 || rate > 100) {
  1174. toastr.error('请输入0-100之前的整数值');
  1175. $('#rateInput').val(materialRate);
  1176. return;
  1177. }
  1178. $('#rateInput').siblings('.dropdown-menu').hide();
  1179. console.log(rate, materialRate);
  1180. if (rate !== materialRate) {
  1181. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1182. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1183. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1184. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1185. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1186. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1187. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1188. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1189. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1190. materialRate = rate;
  1191. $('#rateInput').val(rate);
  1192. });
  1193. } else {
  1194. $('#rateInput').val(rate);
  1195. }
  1196. }, 500);
  1197. });
  1198. // $('#changeRate').change(function () {
  1199. // const rate = parseInt($(this).val());
  1200. // postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  1201. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  1202. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  1203. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  1204. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  1205. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  1206. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  1207. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  1208. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  1209. // });
  1210. // });
  1211. $('#expr_select button').on('click', function () {
  1212. const code = $(this).text();
  1213. // $('#expr').val($('#expr').val() + code);
  1214. $('#expr').insertAtCaret(code);
  1215. });
  1216. const ExprObj = {
  1217. _checkExprValid(expr, invalidParam) {
  1218. if (!expr) return [true, null];
  1219. const param = [];
  1220. let num = '', base = '';
  1221. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  1222. if (/^[\d\.%]+/.test(expr[i])) {
  1223. if (base !== '') {
  1224. param.push({type: 'base', value: base});
  1225. base = '';
  1226. }
  1227. num = num + expr[i];
  1228. } else if (/^[a-z]/.test(expr[i])) {
  1229. if (num !== '') {
  1230. param.push({type: 'num', value: num});
  1231. num = '';
  1232. }
  1233. base = base + expr[i];
  1234. } else if (expr[i] === '(') {
  1235. if (num !== '') {
  1236. param.push({type: 'num', value: num});
  1237. num = '';
  1238. }
  1239. if (base !== '') {
  1240. param.push({type: 'base', value: base});
  1241. base = '';
  1242. }
  1243. param.push({type: 'left', value: '('});
  1244. } else if (expr[i] === ')') {
  1245. if (num !== '') {
  1246. param.push({type: 'num', value: num});
  1247. num = '';
  1248. }
  1249. if (base !== '') {
  1250. param.push({type: 'base', value: base});
  1251. base = '';
  1252. }
  1253. param.push({type: 'right', value: ')'});
  1254. } else if (/^[\+\-*\/]/.test(expr[i])) {
  1255. if (num !== '') {
  1256. param.push({type: 'num', value: num});
  1257. num = '';
  1258. }
  1259. if (base !== '') {
  1260. param.push({type: 'base', value: base});
  1261. base = '';
  1262. }
  1263. param.push({type: 'calc', value: expr[i]});
  1264. } else {
  1265. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  1266. }
  1267. }
  1268. if (num !== '') {
  1269. param.push({type: 'num', value: num});
  1270. num = '';
  1271. }
  1272. if (base !== '') {
  1273. param.push({type: 'base', value: base});
  1274. base = '';
  1275. }
  1276. if (param.length === 0) return true;
  1277. if (param.length > 1) {
  1278. if (param[0].value === '-') {
  1279. param[1].value = '-' + param[1];
  1280. }
  1281. param.unshift();
  1282. }
  1283. const iLen = param.length;
  1284. let iLeftCount = 0, iRightCount = 0;
  1285. for (const [i, p] of param.entries()) {
  1286. if (p.type === 'calc') {
  1287. if (i === 0 || i === iLen - 1)
  1288. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
  1289. }
  1290. if (p.type === 'num') {
  1291. num = p.value.replace('%', '');
  1292. if (p.value.length - num.length > 1)
  1293. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1294. num = _.toNumber(num);
  1295. if (num === undefined || num === null || _.isNaN(num))
  1296. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  1297. if (i > 0) {
  1298. if (param[i - 1].type !== 'calc') {
  1299. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1300. } else if (param[i - 1].value === '/' && num === 0) {
  1301. return [false, '输入的表达式非法:请勿除0'];
  1302. }
  1303. }
  1304. }
  1305. if (p.type === 'base') {
  1306. const baseParam = _.find(calcBase, {code: p.value});
  1307. if (!baseParam)
  1308. return [false, '输入的表达式非法:不存在计算基数' + p.value];
  1309. if (invalidParam && invalidParam.indexOf(p.value) >= 0)
  1310. return [false, '不可使用计算基数' + p.value];
  1311. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  1312. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  1313. }
  1314. if (p.type === 'left') {
  1315. iLeftCount += 1;
  1316. if (i !== 0 && param[i-1].type !== 'calc')
  1317. return [false, '输入的表达式非法:(前应有运算符'];
  1318. }
  1319. if (p.type === 'right') {
  1320. iRightCount += 1;
  1321. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  1322. return [false, '输入的表达式非法:)后应有运算符'];
  1323. if (iRightCount > iLeftCount)
  1324. return [false, '输入的表达式非法:")"前无对应的"("'];
  1325. }
  1326. }
  1327. if (iLeftCount > iRightCount)
  1328. return [false, '输入的表达式非法:"("后无对应的")"'];
  1329. return [true, ''];
  1330. },
  1331. _checkExpr: function (text) {
  1332. if (text) {
  1333. const num = _.toNumber(text);
  1334. if (num) {
  1335. console.log(num);
  1336. } else {
  1337. const expr = text.replace('=', '').toLowerCase();
  1338. const [valid, msg] = this._checkExprValid(expr);
  1339. if (!valid) return [valid, msg];
  1340. }
  1341. }
  1342. return [true, ''];
  1343. },
  1344. };
  1345. $('#expr_btn').click(function () {
  1346. const expr = $('#expr').val();
  1347. // 判断表达式格式
  1348. const [valid, msg] = ExprObj._checkExpr(expr);
  1349. if (!valid) {
  1350. toastr.error(msg);
  1351. return false;
  1352. }
  1353. postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr }, function (result) {
  1354. m_tp = result.m_tp;
  1355. if (materialTax) {
  1356. m_tax_tp = result.m_tax_tp;
  1357. }
  1358. const sheet = materialSpread.getActiveSheet();
  1359. const select = SpreadJsObj.getSelectObject(sheet);
  1360. const index = materialBillsData.indexOf(select);
  1361. console.log(select, index, result.info);
  1362. let newIndex = index;
  1363. if (isStageSelf) {
  1364. materialSpreadObj.updateMaterialData(result);
  1365. result.info = materialSpreadObj.updateOneMaterialBill(result.info);
  1366. console.log(result.info);
  1367. }
  1368. if($('#bills0_list').is(':checked')) {
  1369. const newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1370. return item.quantity !== null && item.quantity !== 0;
  1371. });
  1372. newIndex = newMaterialBillsData.indexOf(select);
  1373. newMaterialBillsData.splice(newIndex, 1, result.info);
  1374. sheet.zh_data[newIndex] = result.info;
  1375. }
  1376. materialBillsData.splice(index, 1, result.info);
  1377. SpreadJsObj.reLoadRowData(sheet, newIndex);
  1378. resetTpTable();
  1379. $('#bcyy').modal('hide');
  1380. });
  1381. });
  1382. // 创建月信息价
  1383. $('#make-month').click(function() {
  1384. const yearmonth = $('#months').val();
  1385. const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
  1386. if (result === null) {
  1387. toastr.error('请选择正确的信息价月份');
  1388. return false;
  1389. }
  1390. //判断是否已存在当前月份
  1391. if (months.indexOf(yearmonth) !== -1) {
  1392. toastr.error('调差期已创建过本月的信息价');
  1393. return false;
  1394. }
  1395. postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
  1396. months.push(yearmonth);
  1397. months.sort();
  1398. monthsList = data.monthsList;
  1399. monthFunGather.monthsListSet();
  1400. // 工料表单价显示也要更新
  1401. materialBillsData = data.materialBillsData;
  1402. materialSpreadObj.materialSheetReset();
  1403. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1404. m_tp = data.m_tp;
  1405. if (materialTax) {
  1406. m_tax_tp = data.m_tax_tp;
  1407. }
  1408. resetTpTable();
  1409. $('#add-month').modal('hide');
  1410. });
  1411. });
  1412. // 删除月信息价
  1413. $('#del-month').click(function () {
  1414. const del_month_array = [];
  1415. $("input[name='del_month']:checked").each(function () {
  1416. del_month_array.push($(this).val());
  1417. });
  1418. if (del_month_array.length === 0) {
  1419. toastr.error('请选择要移除的月信息价');
  1420. return false;
  1421. }
  1422. postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
  1423. for (const dm of del_month_array) {
  1424. // _.remove(materialMonthSpreadSetting.cols, function (n) {
  1425. // return n.field === dm;
  1426. // });
  1427. _.remove(months, function (n) {
  1428. return n === dm;
  1429. });
  1430. }
  1431. monthsList = data.monthsList;
  1432. monthFunGather.monthsListSet();
  1433. // 工料表单价显示也要更新
  1434. materialBillsData = data.materialBillsData;
  1435. materialSpreadObj.materialSheetReset();
  1436. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1437. m_tp = data.m_tp;
  1438. if (materialTax) {
  1439. m_tax_tp = data.m_tax_tp;
  1440. }
  1441. resetTpTable();
  1442. $('#remove-month').modal('hide');
  1443. });
  1444. });
  1445. } else {
  1446. // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
  1447. }
  1448. // 筛选调差工料本期应耗数量为0
  1449. $('#bills0_list').click(function () {
  1450. const isCheck = $(this).is(':checked');
  1451. let newMaterialBillsData = materialBillsData;
  1452. if (isCheck) {
  1453. newMaterialBillsData = _.filter(materialBillsData, function (item) {
  1454. return item.quantity !== null && item.quantity !== 0;
  1455. });
  1456. SpreadJsObj.initSpreadSettingEvents(materialSpreadSetting, materialCol);
  1457. SpreadJsObj.initSheet(materialSpread.getActiveSheet(), materialSpreadSetting);
  1458. }
  1459. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, newMaterialBillsData);
  1460. monthFunGather.monthsListSet(newMaterialBillsData, false);
  1461. materialSpreadObj.refreshActn();
  1462. });
  1463. $.subMenu({
  1464. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1465. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1466. key: 'menu.1.0.0',
  1467. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1468. callback: function (info) {
  1469. if (info.mini) {
  1470. $('.panel-title').addClass('fluid');
  1471. $('#sub-menu').removeClass('panel-sidebar');
  1472. } else {
  1473. $('.panel-title').removeClass('fluid');
  1474. $('#sub-menu').addClass('panel-sidebar');
  1475. }
  1476. autoFlashHeight();
  1477. materialSpread.refresh();
  1478. }
  1479. });
  1480. $.divResizer({
  1481. select: '#right-spr',
  1482. callback: function () {
  1483. materialSpread.refresh();
  1484. materialMonthSpread.refresh();
  1485. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1486. setLocalCache('material_month_' + materialID, width);
  1487. }
  1488. });
  1489. $.divResizer({
  1490. select: '#main-resize',
  1491. callback: function () {
  1492. let bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1493. $(".sp-wrap").height(bcontent-30);
  1494. const height = $('.bcontent-wrap').height();
  1495. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1496. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1497. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  1498. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  1499. materialSpread.refresh();
  1500. materialMonthSpread.refresh();
  1501. setLocalCache('material_bills_' + materialID, height);
  1502. }
  1503. });
  1504. // 展开收起月信息价并浏览器记住本期展开收起
  1505. $('a', '.right-nav').bind('click', function () {
  1506. //const main = $('#main-view'), tool = $('#tools-view');
  1507. const tab = $(this), tabPanel = $(tab.attr('content'));
  1508. if (!tab.hasClass('active')) {
  1509. $('a', '.side-menu').removeClass('active');
  1510. $('.tab-content .tab-select-show').removeClass('active');
  1511. tab.addClass('active');
  1512. tabPanel.addClass('active');
  1513. showSideTools(tab.hasClass('active'));
  1514. if (tab.attr('content') === '#month-tab') {
  1515. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1516. setLocalCache('material_month_' + materialID, width);
  1517. materialMonthSpread.refresh();
  1518. }
  1519. } else {
  1520. removeLocalCache('material_month_' + materialID);
  1521. tab.removeClass('active');
  1522. tabPanel.removeClass('active');
  1523. showSideTools(tab.hasClass('active'));
  1524. }
  1525. materialSpread.refresh();
  1526. materialMonthSpread.refresh();
  1527. });
  1528. // 根据浏览器记录展开收起
  1529. if (getLocalCache('material_month_' + materialID) && !isStageSelf) {
  1530. const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
  1531. $('a', '.side-menu').removeClass('active');
  1532. $('.tab-content .tab-select-show').removeClass('active');
  1533. tab.addClass('active');
  1534. tabPanel.addClass('active');
  1535. $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
  1536. showSideTools(tab.hasClass('active'));
  1537. materialSpread.refresh();
  1538. materialMonthSpread.refresh();
  1539. }
  1540. const cutHeight = isStageSelf ? getObjHeight($('#myTab')) : 0;
  1541. if (getLocalCache('material_bills_' + materialID)) {
  1542. $('.bcontent-wrap').height(getLocalCache('material_bills_' + materialID));
  1543. const cHeader = getObjHeight($(".c-header"));
  1544. const bcontent = $(".bcontent-wrap") ? $(".bcontent-wrap").height() : 0;
  1545. $(".sp-wrap").height(bcontent-30);
  1546. $('.sjs-height-1').height($(window).height()-cHeader-bcontent-90+53);
  1547. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1548. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  1549. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  1550. materialSpread.refresh();
  1551. materialMonthSpread.refresh();
  1552. } else {
  1553. $('.sjs-height-material').height($('.sjs-height-1').height() - cutHeight);
  1554. $('.sjs-height-material-month').height($('.sjs-height-1').height() - getObjHeight($('.sjs-bar-1')));
  1555. $('.material-table-height').height($('.bcontent-wrap').height() - getObjHeight($('.bc-bar')));
  1556. materialSpread.refresh();
  1557. materialMonthSpread.refresh();
  1558. }
  1559. function getObjHeight(select) {
  1560. return select.length > 0 ? select.height() : 0;
  1561. }
  1562. });