material.js 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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. // console.log(select);
  351. // 更新至服务器
  352. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  353. m_tp = result.m_tp;
  354. resetTpTable();
  355. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  356. // 判断如果是更改了编号,名称,单位,月信息价需要跟着改变值
  357. if (months.length > 0 && (col.field === 'code' || col.field === 'name' || col.field === 'unit')) {
  358. monthsList[info.row][col.field] = validText;
  359. SpreadJsObj.reLoadRowData(materialMonthSpread.getActiveSheet(), info.row);
  360. }
  361. }, function () {
  362. select[col.field] = orgValue;
  363. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  364. });
  365. }
  366. },
  367. buttonClicked: function (e, info) {
  368. if (info.sheet.zh_setting) {
  369. const select = SpreadJsObj.getSelectObject(info.sheet);
  370. const col = info.sheet.zh_setting.cols[info.col];
  371. if (materialCol.readOnly.isEdit(select)) {
  372. return;
  373. }
  374. if (col.field === 'is_summary') {
  375. if (info.sheet.isEditing()) {
  376. info.sheet.endEdit(true);
  377. }
  378. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  379. // 更新至服务器
  380. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  381. m_tp = result.m_tp;
  382. resetTpTable();
  383. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  384. }, function () {
  385. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  386. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  387. });
  388. }
  389. }
  390. },
  391. deletePress: function (sheet) {
  392. return;
  393. },
  394. clipboardPasted(e, info) {
  395. const hint = {
  396. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  397. codeEmpty: {type: 'error', msg: '请先输入编号,并且不超过15个字符'},
  398. codeUsed: {type: 'error', msg: '该编号已存在,请重新输入。'},
  399. codeError: {type: 'error', msg: '编号为纯数字时,不能为小数'},
  400. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  401. riskCan: {type: 'error', msg: '只能粘贴0-100的正整数'},
  402. numberCan: {type: 'error', msg: '请粘贴大于0并且小于3位小数的浮点数'},
  403. };
  404. const range = info.cellRange;
  405. const sortData = info.sheet.zh_data || [];
  406. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  407. toastMessageUniq(hint.cellError);
  408. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  409. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  410. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  411. return;
  412. }
  413. if (sortData.length > 0 && range.col + range.colCount > 18) {
  414. toastMessageUniq(hint.cellError);
  415. SpreadJsObj.reLoadSheetHeader(materialSpread.getActiveSheet());
  416. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  417. return;
  418. }
  419. const data = [];
  420. // const rowData = [];
  421. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  422. let bPaste = true;
  423. const curRow = range.row + iRow;
  424. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  425. const materialData = { id: sortData[curRow].id };
  426. const hintRow = range.rowCount > 1 ? curRow : '';
  427. let sameCol = 0;
  428. for (let iCol = 0; iCol < range.colCount; iCol++) {
  429. const curCol = range.col + iCol;
  430. const colSetting = info.sheet.zh_setting.cols[curCol];
  431. if (!colSetting) continue;
  432. let validText = info.sheet.getText(curRow, curCol);
  433. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  434. const orgValue = sortData[curRow][colSetting.field];
  435. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  436. sameCol++;
  437. if (range.colCount === sameCol) {
  438. bPaste = false;
  439. }
  440. continue;
  441. }
  442. if (colSetting.field === 'code' && (validText === '' || validText.length > 15)) {
  443. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  444. bPaste = false;
  445. continue;
  446. }
  447. if (colSetting.field === 'code' && validText.toString().indexOf('.') !== -1) {
  448. toastMessageUniq(getPasteHint(hint.codeError, hintRow));
  449. bPaste = false;
  450. continue;
  451. }
  452. if (colSetting.field === 'code' && _.find(sortData, { code: validText.toString() })) {
  453. toastMessageUniq(getPasteHint(hint.codeUsed, hintRow));
  454. bPaste = false;
  455. continue;
  456. }
  457. if (colSetting.field === 't_type' || colSetting.field === 'm_type') {
  458. continue;
  459. }
  460. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp'
  461. || colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  462. if (isNaN(validText)) {
  463. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  464. bPaste = false;
  465. continue;
  466. }
  467. const num = parseFloat(validText);
  468. if (colSetting.field === 'basic_price' || colSetting.field === 'msg_tp') {
  469. if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
  470. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  471. bPaste = false;
  472. continue;
  473. }
  474. } else if (colSetting.field === 'm_up_risk' || colSetting.field === 'm_down_risk') {
  475. if (validText !== null && (num < 0 || num > 100 || !/^\d+$/.test(num))) {
  476. toastMessageUniq(getPasteHint(hint.riskCan, hintRow));
  477. bPaste = false;
  478. continue;
  479. }
  480. }
  481. }
  482. materialData[colSetting.field] = validText;
  483. sortData[curRow][colSetting.field] = validText;
  484. }
  485. if (materialData.code === '' || materialData.code === null) {
  486. toastMessageUniq(getPasteHint(hint.codeEmpty, hintRow));
  487. bPaste = false;
  488. }
  489. if (bPaste) {
  490. materialData.msg_spread = materialCol.getValue.msg_spread(sortData[curRow]);
  491. materialData.m_spread = materialCol.getValue.m_spread(sortData[curRow]);
  492. materialData.m_tp = materialCol.getValue.m_tp(sortData[curRow]);
  493. data.push(materialData);
  494. // rowData.push(curRow);
  495. } else {
  496. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  497. }
  498. }
  499. if (data.length === 0) {
  500. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  501. return;
  502. }
  503. // console.log(data);
  504. // 更新至服务器
  505. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  506. materialBillsData = result.info;
  507. SpreadJsObj.reLoadSheetData(materialSpread.getActiveSheet());
  508. // for (const row in rowData) {
  509. // materialBillsData.splice(index, 1, result.info[row]);
  510. // SpreadJsObj.reLoadRowData(info.sheet, row);
  511. // }
  512. if (months.length > 0) {
  513. for (const [i,m] of monthsList.entries()) {
  514. m.code = materialBillsData[i].code;
  515. m.name = materialBillsData[i].name;
  516. m.unit = materialBillsData[i].unit;
  517. }
  518. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  519. }
  520. m_tp = result.m_tp;
  521. resetTpTable();
  522. }, function () {
  523. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  524. return;
  525. });
  526. },
  527. setReadOnly: function(readOnly) {
  528. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  529. }
  530. };
  531. materialSpreadObj.refreshActn();
  532. materialSpread.bind(spreadNS.Events.SelectionChanged, materialSpreadObj.selectionChanged);
  533. materialSpread.bind(spreadNS.Events.ClipboardPasted, materialSpreadObj.clipboardPasted);
  534. SpreadJsObj.addDeleteBind(materialSpread, materialSpreadObj.deletePress);
  535. const sheet = materialSpread.getActiveSheet();
  536. sheet.suspendPaint();
  537. // const basic_range = sheet.getRange(-1, 8, -1, 1);
  538. // basic_range.cellType(new DatePickerCellType());
  539. // basic_range.formatter("yyyy-MM-dd");
  540. // const msg_range = sheet.getRange(-1, 10, -1, 1);
  541. // msg_range.cellType(new DatePickerCellType());
  542. // msg_range.formatter("yyyy-MM-dd");
  543. sheet.resumePaint();
  544. const static_cols = [
  545. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 60, formatter: '@', readOnly: true},
  546. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 180, formatter: '@', readOnly: true},
  547. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  548. {title: '平均单价', colSpan: '1', rowSpan: '2', field: 'average_msg_tp', hAlign: 2, width: 60, type: 'Number', readOnly: true, getValue:'getValue.average_msg_tp'},
  549. ];
  550. // 月信息价方法集合
  551. const monthFunGather = {
  552. _setMonthHtml: function() {
  553. let html = '';
  554. let qihtml = '';
  555. for (const m of months) {
  556. html += '<div class="custom-control custom-checkbox mb-2">\n' +
  557. ' <input type="checkbox" name="del_month" value="' + m + '" class="custom-control-input" id="month_' + m + '">\n' +
  558. ' <label class="custom-control-label" for="month_' + m + '">' + m + '月</label>\n' +
  559. ' </div>';
  560. qihtml += parseInt(m.split('-')[1]) + '月,';
  561. }
  562. if (months.length > 0) {
  563. qihtml = '<span class="mx-2 text-muted">/</span>本期月信息价:' + qihtml;
  564. qihtml = qihtml.substring(0, qihtml.length-1);
  565. }
  566. $('#show_month').html(html);
  567. $('#qi-month').html(qihtml);
  568. },
  569. _monthHeaderSet: function() {
  570. const newMonths = [];
  571. for (const m of months) {
  572. const year = m.split('-')[0];
  573. const month = parseInt(m.split('-')[1]);
  574. let one = _.find(newMonths, { 'year': year });
  575. let oneIndex = _.findIndex(newMonths, { 'year': year });
  576. if (one) {
  577. one.month.push(month);
  578. newMonths.splice(oneIndex, 1, one);
  579. } else {
  580. one = {
  581. year: year,
  582. month: [ month ],
  583. };
  584. newMonths.push(one);
  585. }
  586. }
  587. const pushMonth = [];
  588. for(const mo of newMonths) {
  589. for (let i in mo.month) {
  590. i = parseInt(i);
  591. const newCols = {
  592. title: (i === 0 ? mo.year: '') + '|' + mo.month[i] + '月',
  593. colSpan: (i === 0 ? (mo.month.length === 1 ? '0' : mo.month.length) : '') + '|1',
  594. rowSpan: i === 0 ? '1|1' : '|1',
  595. field: mo.year + '-' + (mo.month[i] < 10 ? '0' + mo.month[i] : mo.month[i]),
  596. hAlign: 2, width: 60, type: '@', readOnly: 'readOnly.isEdit'};
  597. pushMonth.push(newCols);
  598. }
  599. }
  600. return pushMonth;
  601. },
  602. monthSheetReset: function () {
  603. const monthCols = monthFunGather._monthHeaderSet();
  604. const newMonthSpreadHeaderCols = static_cols.concat(monthCols);
  605. materialMonthSpreadSetting.cols = newMonthSpreadHeaderCols;
  606. // 表头变化需要重新绘制,不然报错;
  607. materialMonthSpread.getActiveSheet().reset();
  608. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  609. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  610. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  611. monthFunGather._setMonthHtml();
  612. }
  613. }
  614. const materialMonthSpread = SpreadJsObj.createNewSpread($('#material-month-spread')[0]);
  615. const materialMonthSpreadSetting = {
  616. cols: static_cols,
  617. emptyRows: 0,
  618. headRows: 2,
  619. headRowHeight: [25, 25],
  620. defaultRowHeight: 21,
  621. headerFont: '12px 微软雅黑',
  622. font: '12px 微软雅黑',
  623. readOnly: readOnly,
  624. };
  625. if (months.length > 0) {
  626. const monthCols = monthFunGather._monthHeaderSet();
  627. const monthSpreadHeaderCols = static_cols.concat(monthCols);
  628. materialMonthSpreadSetting.cols = monthSpreadHeaderCols;
  629. }
  630. const materialMonthCol = {
  631. getValue: {
  632. average_msg_tp: function (data) {
  633. let msg_tp = 0;
  634. let hadnum = 0;
  635. for (const m of months) {
  636. msg_tp += data[m];
  637. if (data[m] !== null && data[m] !== '' && data[m] !== 0) {
  638. hadnum++;
  639. }
  640. }
  641. const average_tp = hadnum !== 0 ? ZhCalc.round(ZhCalc.div(msg_tp, hadnum), 3) : ZhCalc.round(ZhCalc.div(msg_tp, months.length), 3);
  642. return average_tp;
  643. },
  644. },
  645. readOnly: {
  646. isEdit: function (data) {
  647. return readOnly;
  648. },
  649. },
  650. };
  651. materialMonthSpread.getActiveSheet().frozenColumnCount(4);
  652. materialMonthSpread.getActiveSheet().options.frozenlineColor = '#f1f1f1';
  653. SpreadJsObj.initSpreadSettingEvents(materialMonthSpreadSetting, materialMonthCol);
  654. SpreadJsObj.initSheet(materialMonthSpread.getActiveSheet(), materialMonthSpreadSetting);
  655. SpreadJsObj.loadSheetData(materialMonthSpread.getActiveSheet(), SpreadJsObj.DataType.Data, monthsList);
  656. const materialMonthSpreadObj = {
  657. editEnded: function (e, info) {
  658. if (info.sheet.zh_setting) {
  659. const select = SpreadJsObj.getSelectObject(info.sheet);
  660. const col = info.sheet.zh_setting.cols[info.col];
  661. // 未改变值则不提交
  662. const validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  663. const orgValue = select[col.field];
  664. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  665. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  666. return;
  667. }
  668. // 判断部分值是否输入的是数字判断和数据计算
  669. if (isNaN(validText)) {
  670. toastr.error('不能输入其它非数字类型字符');
  671. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  672. return;
  673. }
  674. const num = parseFloat(validText);
  675. if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
  676. toastr.error('请输入大于0并且小于3位小数的浮点数');
  677. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  678. return;
  679. }
  680. select[col.field] = validText;
  681. // 更新至服务器
  682. postData(window.location.pathname + '/month/save', { type:'update', updateData: { mb_id: select.mb_id, yearmonth: col.field, value: validText } }, function (result) {
  683. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  684. materialBillsData = result.materialBillsData;
  685. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  686. m_tp = result.m_tp;
  687. resetTpTable();
  688. }, function () {
  689. select[col.field] = orgValue;
  690. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  691. });
  692. }
  693. },
  694. deletePress: function (sheet) {
  695. // if (sheet.zh_setting && sheet.zh_data) {
  696. // const sel = sheet.getSelections()[0];
  697. // if (!sel) return;
  698. //
  699. // const col = sheet.zh_setting.cols[sel.col];
  700. // const select = SpreadJsObj.getSelectObject(sheet);
  701. // const orgValue = select[col.field];
  702. // if (sel.colCount > 1 || sel.rowCount > 1) {
  703. // toastr.warning('请勿同时删除多行或多列数据');
  704. // }
  705. // console.log(sel, select, col);
  706. // if (orgValue === null || col.field === 'type' || col.field === 'is_summary') {
  707. // return;
  708. // }
  709. // select[col.field] = null;
  710. // select.calc_num = materialExponentCol.getValue.calc_num(select);
  711. // console.log(select);
  712. // 更新至服务器
  713. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  714. // ex_tp = result.ex_tp;
  715. // ex_expr = result.ex_expr;
  716. // resetExTpTable();
  717. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  718. // materialExponentData.splice(sel.row, 1, select);
  719. // }, function () {
  720. // select[col.field] = orgValue;
  721. // SpreadJsObj.reLoadRowData(sheet, sel.row);
  722. // });
  723. // }
  724. return;
  725. },
  726. clipboardPasted(e, info) {
  727. const hint = {
  728. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  729. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  730. numberCan: {type: 'error', msg: '请粘贴大于0并且小于3位小数的浮点数'},
  731. };
  732. const range = info.cellRange;
  733. const sortData = info.sheet.zh_data || [];
  734. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  735. toastMessageUniq(hint.cellError);
  736. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  737. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  738. return;
  739. }
  740. if (sortData.length > 0 && range.col + range.colCount > 4 + months.length) {
  741. toastMessageUniq(hint.cellError);
  742. SpreadJsObj.reLoadSheetHeader(materialMonthSpread.getActiveSheet());
  743. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  744. return;
  745. }
  746. const data = [];
  747. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  748. let bPaste = true;
  749. const curRow = range.row + iRow;
  750. const materialMonthData = sortData[curRow];
  751. const hintRow = range.rowCount > 1 ? curRow : '';
  752. let sameCol = 0;
  753. for (let iCol = 0; iCol < range.colCount; iCol++) {
  754. const curCol = range.col + iCol;
  755. const colSetting = info.sheet.zh_setting.cols[curCol];
  756. if (!colSetting) continue;
  757. let validText = info.sheet.getText(curRow, curCol);
  758. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  759. const orgValue = sortData[curRow][colSetting.field];
  760. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  761. sameCol++;
  762. if (range.colCount === sameCol) {
  763. bPaste = false;
  764. }
  765. continue;
  766. }
  767. const num = parseFloat(validText);
  768. if (isNaN(validText)) {
  769. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  770. bPaste = false;
  771. continue;
  772. }
  773. if (validText !== null && (num < 0 || !/^\d+(\.\d{1,3})?$/.test(num))) {
  774. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  775. bPaste = false;
  776. continue;
  777. }
  778. materialMonthData[colSetting.field] = validText;
  779. sortData[curRow][colSetting.field] = validText;
  780. }
  781. if (bPaste) {
  782. data.push(materialMonthData);
  783. } else {
  784. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  785. }
  786. }
  787. if (data.length === 0) {
  788. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  789. return;
  790. }
  791. // 更新至服务器
  792. postData(window.location.pathname + '/month/save', { type:'paste', updateData: data }, function (result) {
  793. SpreadJsObj.reLoadSheetData(materialMonthSpread.getActiveSheet());
  794. materialBillsData = result.materialBillsData;
  795. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  796. m_tp = result.m_tp;
  797. resetTpTable();
  798. }, function () {
  799. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  800. return;
  801. });
  802. },
  803. };
  804. materialMonthSpread.bind(spreadNS.Events.ClipboardPasted, materialMonthSpreadObj.clipboardPasted);
  805. SpreadJsObj.addDeleteBind(materialMonthSpread, materialMonthSpreadObj.deletePress);
  806. if (!readOnly) {
  807. $('#add').click(materialSpreadObj.add);
  808. $('#del').click(materialSpreadObj.del);
  809. materialSpread.bind(spreadNS.Events.EditEnded, materialSpreadObj.editEnded);
  810. materialSpread.bind(spreadNS.Events.ButtonClicked, materialSpreadObj.buttonClicked);
  811. materialMonthSpread.bind(spreadNS.Events.EditEnded, materialMonthSpreadObj.editEnded);
  812. // 右键菜单
  813. $.contextMenu({
  814. selector: '#material-spread',
  815. build: function ($trigger, e) {
  816. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialSpread);
  817. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  818. },
  819. items: {
  820. 'create': {
  821. name: '新增材料',
  822. icon: 'fa-sign-in',
  823. callback: function (key, opt) {
  824. materialSpreadObj.add(materialSpread.getActiveSheet());
  825. },
  826. },
  827. 'delete': {
  828. name: '删除材料',
  829. icon: 'fa-remove',
  830. callback: function (key, opt) {
  831. materialSpreadObj.del(materialSpread.getActiveSheet());
  832. },
  833. disabled: function (key, opt) {
  834. const sheet = materialSpread.getActiveSheet();
  835. const select = SpreadJsObj.getSelectObject(sheet);
  836. const sel = sheet.getSelections()[0];
  837. materialSpreadObj.refreshActn(sel.rowCount);
  838. if (!readOnly && select && materialBase.isUsed(select) && sel.rowCount === 1) {
  839. return false;
  840. } else {
  841. return true;
  842. }
  843. }
  844. },
  845. }
  846. });
  847. $('#changeRate').change(function () {
  848. const rate = parseInt($(this).val());
  849. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  850. const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), 2);
  851. const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), 2);
  852. const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), 2);
  853. const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), 2);
  854. $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  855. $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  856. $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  857. $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  858. });
  859. });
  860. $('#expr_select button').on('click', function () {
  861. const code = $(this).text();
  862. // $('#expr').val($('#expr').val() + code);
  863. $('#expr').insertAtCaret(code);
  864. });
  865. const ExprObj = {
  866. _checkExprValid(expr, invalidParam) {
  867. if (!expr) return [true, null];
  868. const param = [];
  869. let num = '', base = '';
  870. for (let i = 0, iLen = expr.length; i < iLen; i++) {
  871. if (/^[\d\.%]+/.test(expr[i])) {
  872. if (base !== '') {
  873. param.push({type: 'base', value: base});
  874. base = '';
  875. }
  876. num = num + expr[i];
  877. } else if (/^[a-z]/.test(expr[i])) {
  878. if (num !== '') {
  879. param.push({type: 'num', value: num});
  880. num = '';
  881. }
  882. base = base + expr[i];
  883. } else if (expr[i] === '(') {
  884. if (num !== '') {
  885. param.push({type: 'num', value: num});
  886. num = '';
  887. }
  888. if (base !== '') {
  889. param.push({type: 'base', value: base});
  890. base = '';
  891. }
  892. param.push({type: 'left', value: '('});
  893. } else if (expr[i] === ')') {
  894. if (num !== '') {
  895. param.push({type: 'num', value: num});
  896. num = '';
  897. }
  898. if (base !== '') {
  899. param.push({type: 'base', value: base});
  900. base = '';
  901. }
  902. param.push({type: 'right', value: ')'});
  903. } else if (/^[\+\-*\/]/.test(expr[i])) {
  904. if (num !== '') {
  905. param.push({type: 'num', value: num});
  906. num = '';
  907. }
  908. if (base !== '') {
  909. param.push({type: 'base', value: base});
  910. base = '';
  911. }
  912. param.push({type: 'calc', value: expr[i]});
  913. } else {
  914. return [false, '输入的表达式含有非法字符: ' + expr[i]];
  915. }
  916. }
  917. if (num !== '') {
  918. param.push({type: 'num', value: num});
  919. num = '';
  920. }
  921. if (base !== '') {
  922. param.push({type: 'base', value: base});
  923. base = '';
  924. }
  925. if (param.length === 0) return true;
  926. if (param.length > 1) {
  927. if (param[0].value === '-') {
  928. param[1].value = '-' + param[1];
  929. }
  930. param.unshift();
  931. }
  932. const iLen = param.length;
  933. let iLeftCount = 0, iRightCount = 0;
  934. for (const [i, p] of param.entries()) {
  935. if (p.type === 'calc') {
  936. if (i === 0 || i === iLen - 1)
  937. return [false, '输入的表达式非法:计算符号' + p.value + '前后应有数字或计算基数'];
  938. }
  939. if (p.type === 'num') {
  940. num = p.value.replace('%', '');
  941. if (p.value.length - num.length > 1)
  942. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  943. num = _.toNumber(num);
  944. if (num === undefined || num === null || _.isNaN(num))
  945. return [false, '输入的表达式非法:' + p.value + '不是一个有效的数字'];
  946. if (i > 0) {
  947. if (param[i - 1].type !== 'calc') {
  948. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  949. } else if (param[i - 1].value === '/' && num === 0) {
  950. return [false, '输入的表达式非法:请勿除0'];
  951. }
  952. }
  953. }
  954. if (p.type === 'base') {
  955. const baseParam = _.find(calcBase, {code: p.value});
  956. if (!baseParam)
  957. return [false, '输入的表达式非法:不存在计算基数' + p.value];
  958. if (invalidParam && invalidParam.indexOf(p.value) >= 0)
  959. return [false, '不可使用计算基数' + p.value];
  960. if (i > 0 && (param[i - 1].type === 'num' || param[i - 1].type === 'right'))
  961. return [false, '输入的表达式非法:' + p.value + '前应有运算符'];
  962. }
  963. if (p.type === 'left') {
  964. iLeftCount += 1;
  965. if (i !== 0 && param[i-1].type !== 'calc')
  966. return [false, '输入的表达式非法:(前应有运算符'];
  967. }
  968. if (p.type === 'right') {
  969. iRightCount += 1;
  970. if (i !== iLen - 1 && param[i+1].type !== 'calc')
  971. return [false, '输入的表达式非法:)后应有运算符'];
  972. if (iRightCount > iLeftCount)
  973. return [false, '输入的表达式非法:")"前无对应的"("'];
  974. }
  975. }
  976. if (iLeftCount > iRightCount)
  977. return [false, '输入的表达式非法:"("后无对应的")"'];
  978. return [true, ''];
  979. },
  980. _checkExpr: function (text) {
  981. if (text) {
  982. const num = _.toNumber(text);
  983. if (num) {
  984. console.log(num);
  985. } else {
  986. const expr = text.replace('=', '').toLowerCase();
  987. const [valid, msg] = this._checkExprValid(expr);
  988. if (!valid) return [valid, msg];
  989. }
  990. }
  991. return [true, ''];
  992. },
  993. };
  994. $('#expr_btn').click(function () {
  995. const expr = $('#expr').val();
  996. // 判断表达式格式
  997. const [valid, msg] = ExprObj._checkExpr(expr);
  998. if (!valid) {
  999. toastr.error(msg);
  1000. return false;
  1001. }
  1002. postData(window.location.pathname + '/save', { type:'expr', id: $('#materialbillsId').val(), expr: expr }, function (result) {
  1003. m_tp = result.m_tp;
  1004. resetTpTable();
  1005. const sheet = materialSpread.getActiveSheet();
  1006. const select = SpreadJsObj.getSelectObject(sheet);
  1007. const index = materialBillsData.indexOf(select);
  1008. materialBillsData.splice(index, 1, result.info);
  1009. SpreadJsObj.reLoadRowData(sheet, index);
  1010. $('#bcyy').modal('hide');
  1011. });
  1012. });
  1013. // 创建月信息价
  1014. $('#make-month').click(function() {
  1015. const yearmonth = $('#months').val();
  1016. const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
  1017. if (result === null) {
  1018. toastr.error('请选择正确的信息价月份');
  1019. return false;
  1020. }
  1021. //判断是否已存在当前月份
  1022. if (months.indexOf(yearmonth) !== -1) {
  1023. toastr.error('调差期已创建过本月的信息价');
  1024. return false;
  1025. }
  1026. postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
  1027. months.push(yearmonth);
  1028. months.sort();
  1029. monthsList = data.monthsList;
  1030. monthFunGather.monthSheetReset();
  1031. // 工料表单价显示也要更新
  1032. materialBillsData = data.materialBillsData;
  1033. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1034. m_tp = data.m_tp;
  1035. resetTpTable();
  1036. $('#add-month').modal('hide');
  1037. });
  1038. });
  1039. // 删除月信息价
  1040. $('#del-month').click(function () {
  1041. const del_month_array = [];
  1042. $("input[name='del_month']:checked").each(function () {
  1043. del_month_array.push($(this).val());
  1044. });
  1045. if (del_month_array.length === 0) {
  1046. toastr.error('请选择要移除的月信息价');
  1047. return false;
  1048. }
  1049. postData(window.location.pathname + '/month/save', { type: 'del', updateData: { del_yearmonth: del_month_array } }, function (data) {
  1050. for (const dm of del_month_array) {
  1051. // _.remove(materialMonthSpreadSetting.cols, function (n) {
  1052. // return n.field === dm;
  1053. // });
  1054. _.remove(months, function (n) {
  1055. return n === dm;
  1056. });
  1057. }
  1058. monthsList = data.monthsList;
  1059. monthFunGather.monthSheetReset();
  1060. // 工料表单价显示也要更新
  1061. materialBillsData = data.materialBillsData;
  1062. SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  1063. m_tp = data.m_tp;
  1064. resetTpTable();
  1065. $('#remove-month').modal('hide');
  1066. });
  1067. });
  1068. } else {
  1069. // SpreadJsObj.forbiddenSpreadContextMenu('#material-spread', materialSpread);
  1070. }
  1071. $.subMenu({
  1072. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1073. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1074. key: 'menu.1.0.0',
  1075. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1076. callback: function (info) {
  1077. if (info.mini) {
  1078. $('.panel-title').addClass('fluid');
  1079. $('#sub-menu').removeClass('panel-sidebar');
  1080. } else {
  1081. $('.panel-title').removeClass('fluid');
  1082. $('#sub-menu').addClass('panel-sidebar');
  1083. }
  1084. autoFlashHeight();
  1085. materialSpread.refresh();
  1086. }
  1087. });
  1088. $.divResizer({
  1089. select: '#right-spr',
  1090. callback: function () {
  1091. materialSpread.refresh();
  1092. materialMonthSpread.refresh();
  1093. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1094. setLocalCache('material_month_' + materialID, width);
  1095. }
  1096. });
  1097. // 展开收起月信息价并浏览器记住本期展开收起
  1098. $('a', '.right-nav').bind('click', function () {
  1099. //const main = $('#main-view'), tool = $('#tools-view');
  1100. const tab = $(this), tabPanel = $(tab.attr('content'));
  1101. if (!tab.hasClass('active')) {
  1102. $('a', '.side-menu').removeClass('active');
  1103. $('.tab-content .tab-select-show').removeClass('active');
  1104. tab.addClass('active');
  1105. tabPanel.addClass('active');
  1106. showSideTools(tab.hasClass('active'));
  1107. if (tab.attr('content') === '#month-tab') {
  1108. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  1109. setLocalCache('material_month_' + materialID, width);
  1110. materialMonthSpread.refresh();
  1111. }
  1112. } else {
  1113. removeLocalCache('material_month_' + materialID);
  1114. tab.removeClass('active');
  1115. tabPanel.removeClass('active');
  1116. showSideTools(tab.hasClass('active'));
  1117. }
  1118. materialSpread.refresh();
  1119. materialMonthSpread.refresh();
  1120. });
  1121. // 根据浏览器记录展开收起
  1122. if (getLocalCache('material_month_' + materialID)) {
  1123. const tab = $('.right-nav a[content="#month-tab"]'), tabPanel = $(tab.attr('content'));
  1124. $('a', '.side-menu').removeClass('active');
  1125. $('.tab-content .tab-select-show').removeClass('active');
  1126. tab.addClass('active');
  1127. tabPanel.addClass('active');
  1128. $('#right-view').width(getLocalCache('material_month_' + materialID) + '%');
  1129. showSideTools(tab.hasClass('active'));
  1130. materialSpread.refresh();
  1131. materialMonthSpread.refresh();
  1132. }
  1133. });