material.js 57 KB

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