material.js 74 KB

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