material.js 55 KB

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