material_exponent.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. const is_numeric = (value) => {
  2. if (typeof(value) === 'object') {
  3. return false;
  4. } else {
  5. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  6. }
  7. };
  8. function getPasteHint (str, row = '') {
  9. let returnObj = str;
  10. if (row) {
  11. returnObj.msg = '指数清单第' + (row+1) + '行' + str.msg;
  12. }
  13. return returnObj;
  14. }
  15. function resetExTpTable() {
  16. const rate = $('#rateInput').val();
  17. const bqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  18. const jzbqhs = ZhCalc.add(ex_pre_tp_hs, bqhs);
  19. $('#tp_set').find('td').eq(3).text(ZhCalc.round(ex_tp, materialDecimal.tp));
  20. $('#tp_set').find('td').eq(4).text(ZhCalc.add(ex_pre_tp, ZhCalc.round(ex_tp, materialDecimal.tp)));
  21. $('#rate_set').find('td').eq(3).text(bqhs !== 0 ? bqhs : '');
  22. $('#rate_set').find('td').eq(4).text(jzbqhs !== 0 ? jzbqhs : '');
  23. // $('#ex_expr').html(ex_expr);
  24. $('#ex_expr').attr('data-original-title', '本期价差:' + (ex_expr ? ex_expr : ''));
  25. }
  26. $(document).ready(() => {
  27. autoFlashHeight();
  28. const materialExponentSpread = SpreadJsObj.createNewSpread($('#material-exponent-spread')[0]);
  29. const materialExponentSpreadSetting = {
  30. cols: [
  31. {title: '类型', colSpan: '1', rowSpan: '2', field: 'type', hAlign: 1, width: 60, formatter: '@', readOnly: true,cellType: 'customizeCombo', comboItems: materialType.ex_type, cellTypeKey: 1},
  32. {title: '符号', colSpan: '1', rowSpan: '2', field: 'symbol', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
  33. {title: '符号说明', colSpan: '1', rowSpan: '2', field: 'symbol_desc', hAlign: 0, width: 180, formatter: '@', readOnly: 'readOnly.isEdit'},
  34. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit'},
  35. {title: '加权系数', colSpan: '1', rowSpan: '2', field: 'weight_num', hAlign: 2, width: 120, formatter: '@', readOnly: 'readOnly.isConstant'},
  36. {title: '基本价格指数', colSpan: '1', rowSpan: '2', field: 'basic_price', hAlign: 2, width: 120, readOnly: 'readOnly.isEdit'},
  37. {title: '基准时间', colSpan: '1', rowSpan: '2', field: 'basic_times', hAlign: 0, width: 80, formatter: '@', readOnly: 'readOnly.isEdit'},
  38. {title: '现行价格指数', colSpan: '1', rowSpan: '2', field: 'm_price', hAlign: 2, width: 120, type: 'Number', readOnly: 'readOnly.remark'},
  39. {title: '计算值', colSpan: '1', rowSpan: '2', field: 'calc_num', hAlign: 2, width: 80, formatter: '@', readOnly: true},
  40. {title: '备注', colSpan: '1', rowSpan: '2', field: 'remark', hAlign: 0, width: 60, formatter: '@', readOnly: 'readOnly.remark'},
  41. {title: '是否汇总', colSpan: '1', rowSpan: '2', field: 'is_summary', hAlign: 1, width: 60, cellType: 'checkbox', readOnly: 'readOnly.isEdit'},
  42. ],
  43. emptyRows: 0,
  44. headRows: 2,
  45. headRowHeight: [25, 25],
  46. defaultRowHeight: 21,
  47. headerFont: '12px 微软雅黑',
  48. font: '12px 微软雅黑',
  49. readOnly: readOnly,
  50. };
  51. const materialExponentBase = {
  52. isUsed: function (data) {
  53. if (data.type === 2) {
  54. return data.mid === materialID || data.basic_price === null || data.basic_price === 0;
  55. } else {
  56. return false;
  57. }
  58. },
  59. isEdit: function (data) {
  60. return data.mid === materialID && data.type === 2;
  61. },
  62. isConstant: function (data) {
  63. return (materialOrder === 1 && data.type === 1) || (data.mid === materialID && data.type === 2);
  64. }
  65. };
  66. const materialExponentCol = {
  67. getValue: {
  68. calc_num : function (data) {
  69. const calc_num = data.basic_price > 0 ? ZhCalc.mul(data.weight_num, ZhCalc.div(data.m_price, data.basic_price)) : 0;
  70. return calc_num > 0 ? ZhCalc.round(calc_num, 3) : 0;
  71. },
  72. },
  73. readOnly: {
  74. isEdit: function (data) {
  75. return !(!readOnly && materialExponentBase.isEdit(data));
  76. },
  77. isUsed: function (data) {
  78. return !(!readOnly && materialExponentBase.isUsed(data));
  79. },
  80. remark: function (data) {
  81. return !(!readOnly && data.type === 2);
  82. },
  83. isConstant: function (data) {
  84. // return !(!readOnly && materialExponentBase.isConstant(data));
  85. return readOnly;
  86. }
  87. },
  88. };
  89. SpreadJsObj.initSpreadSettingEvents(materialExponentSpreadSetting, materialExponentCol);
  90. SpreadJsObj.initSheet(materialExponentSpread.getActiveSheet(), materialExponentSpreadSetting);
  91. SpreadJsObj.loadSheetData(materialExponentSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialExponentData);
  92. const materialExponentSpreadObj = {
  93. refreshActn: function (rowCount = 1) {
  94. const setObjEnable = function (obj, enable) {
  95. if (enable) {
  96. obj.removeClass('disabled');
  97. } else {
  98. obj.addClass('disabled');
  99. }
  100. };
  101. const sheet = materialExponentSpread.getActiveSheet();
  102. const select = SpreadJsObj.getSelectObject(sheet);
  103. // 还需判断是否已被调差清单调用
  104. setObjEnable($('#del'), !readOnly && select && materialExponentBase.isUsed(select) && rowCount === 1);
  105. },
  106. add: function () {
  107. const sheet = materialExponentSpread.getActiveSheet();
  108. postData(window.location.pathname + '/save', {type: 'add'}, function (result) {
  109. if (result) {
  110. materialExponentData.push(result);
  111. sheet.addRows(materialExponentData.length - 1, 1);
  112. SpreadJsObj.reLoadRowData(sheet, materialExponentData.length - 1);
  113. sheet.setSelection(materialExponentData.length - 1, 0, 1, 1);
  114. materialExponentSpreadObj.refreshActn();
  115. }
  116. });
  117. },
  118. del: function () {
  119. const sheet = materialExponentSpread.getActiveSheet();
  120. const select = SpreadJsObj.getSelectObject(sheet);
  121. postData(window.location.pathname + '/save', {type: 'del', id: select.id}, function (result) {
  122. ex_tp = result.ex_tp;
  123. ex_expr = result.ex_expr;
  124. resetExTpTable();
  125. const index = materialExponentData.indexOf(select);
  126. materialExponentData.splice(index, 1);
  127. sheet.deleteRows(index, 1);
  128. const sel = sheet.getSelections();
  129. sheet.setSelection(index > 0 ? index - 1 : 0, sel.length > 0 ? sel[0].col : 0, 1, 1);
  130. materialExponentSpreadObj.refreshActn();
  131. });
  132. },
  133. selectionChanged: function (e, info) {
  134. const sel = info.sheet.getSelections()[0];
  135. const col = info.sheet.zh_setting.cols[sel.col];
  136. materialExponentSpreadObj.refreshActn(sel.rowCount);
  137. const data = SpreadJsObj.getSelectObject(info.sheet);
  138. materialExponentSpreadObj.setReadOnly(true);
  139. },
  140. editEnded: function (e, info) {
  141. if (info.sheet.zh_setting) {
  142. const select = SpreadJsObj.getSelectObject(info.sheet);
  143. const col = info.sheet.zh_setting.cols[info.col];
  144. if (col.field === 'is_summary') {
  145. return;
  146. }
  147. // 未改变值则不提交
  148. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);
  149. const orgValue = select[col.field];
  150. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  151. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  152. return;
  153. }
  154. // 判断部分值是否输入的是数字判断和数据计算
  155. if (col.field === 'basic_price' || col.field === 'm_price') {
  156. if (isNaN(validText)) {
  157. toastr.error('不能输入其它非数字类型字符');
  158. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  159. return;
  160. }
  161. const num = parseFloat(validText.toPrecision(10));
  162. if (validText !== null && num < 0) {
  163. toastr.error('请输入10位以内有效数字并且小于3位小数的浮点数');
  164. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  165. return;
  166. } else if (validText !== null) {
  167. if(!Number.isInteger(num) && !/^(\d{1,10}\.\d{1,3})?$/.test(num)) {
  168. toastr.warning('已保留3位小数');
  169. } else if (validText.toString().length > 11) {
  170. toastr.warning('已保留10位有效数字');
  171. }
  172. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  173. // return;
  174. validText = ZhCalc.round(num, 3);
  175. }
  176. }
  177. if (col.field === 'weight_num') {
  178. if (isNaN(validText)) {
  179. toastr.error('不能输入其它非数字类型字符');
  180. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  181. return;
  182. }
  183. let num = parseFloat(validText);
  184. if (validText !== null && (num < 0 || num >= 1)) {
  185. toastr.error('请输入0~1范围内并且小于3位小数的浮点数');
  186. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  187. return;
  188. } else if (validText !== null && num > 0 && num < 1 && !/^\d+(\.\d{1,3})?$/.test(num)) {
  189. toastr.warning('已保留3位小数');
  190. validText = ZhCalc.round(num, 3);
  191. num = ZhCalc.round(num, 3);
  192. }
  193. const total_weight = ZhCalc.add(ZhCalc.sub(ZhCalc.sum(_.map(materialExponentData, 'weight_num')), parseFloat(orgValue)), num);
  194. if (total_weight > 1) {
  195. toastr.error('加权系数总和不能大于1');
  196. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  197. return;
  198. }
  199. }
  200. select[col.field] = validText;
  201. select.calc_num = materialExponentCol.getValue.calc_num(select);
  202. delete select.waitingLoading;
  203. // console.log(select);
  204. // 更新至服务器
  205. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  206. ex_tp = result.ex_tp;
  207. ex_expr = result.ex_expr;
  208. resetExTpTable();
  209. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  210. materialExponentData.splice(info.row, 1, select);
  211. }, function () {
  212. select[col.field] = orgValue;
  213. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  214. });
  215. }
  216. },
  217. buttonClicked: function (e, info) {
  218. if (info.sheet.zh_setting) {
  219. const select = SpreadJsObj.getSelectObject(info.sheet);
  220. const col = info.sheet.zh_setting.cols[info.col];
  221. if (col.field === 'weight_num') {
  222. if(materialExponentCol.readOnly.isConstant(select)) {
  223. return;
  224. }
  225. } else {
  226. if(materialExponentCol.readOnly.isEdit(select)) {
  227. return
  228. }
  229. }
  230. if (col.field === 'is_summary') {
  231. if (info.sheet.isEditing()) {
  232. info.sheet.endEdit(true);
  233. }
  234. select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  235. delete select.waitingLoading;
  236. // 更新至服务器
  237. postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  238. ex_tp = result.ex_tp;
  239. ex_expr = result.ex_expr;
  240. resetExTpTable();
  241. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  242. }, function () {
  243. select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  244. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  245. });
  246. }
  247. }
  248. },
  249. deletePress: function (sheet) {
  250. if (!sheet.zh_setting || readOnly || sheet.zh_setting.readOnly) return;
  251. // materialExponentBase.isUsed(select)
  252. if (sheet.zh_setting && sheet.zh_data) {
  253. const sel = sheet.getSelections()[0];
  254. if (!sel) return;
  255. const sortData = sheet.zh_data || [];
  256. const data = [];
  257. for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {
  258. // let bPaste = true;
  259. const exData = sortData[iRow];
  260. const materialExData = { id: sortData[iRow].id };
  261. for (let iCol = 0; iCol < sel.colCount; iCol++) {
  262. const curCol = sel.col + iCol;
  263. const colSetting = sheet.zh_setting.cols[curCol];
  264. if(colSetting.readOnly(exData)) continue;
  265. if (!colSetting) continue;
  266. const orgValue = sortData[iRow][colSetting.field];
  267. if(orgValue === null) {
  268. // bPaste = false;
  269. continue;
  270. }
  271. if (exData.type === materialType.ex_type[0].value && colSetting.field !== 'weight_num') {
  272. // bPaste = false;
  273. continue;
  274. }
  275. if (colSetting.field === 'type' || colSetting.field === 'calc_num' || colSetting.field === 'is_summary'){
  276. // bPaste = false;
  277. continue;
  278. }
  279. materialExData[colSetting.field] = null;
  280. sortData[iRow][colSetting.field] = null;
  281. }
  282. if (exData.type !== materialType.ex_type[0].value) materialExData.calc_num = materialExponentCol.getValue.calc_num(sortData[iRow]);
  283. const arr = Object.keys(materialExData);
  284. if (arr.length !== 1) {
  285. data.push(materialExData);
  286. }
  287. }
  288. if (data.length === 0) {
  289. SpreadJsObj.reLoadSheetData(sheet);
  290. return;
  291. }
  292. // 更新至服务器
  293. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  294. materialExponentData = result.info;
  295. SpreadJsObj.loadSheetData(materialExponentSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialExponentData);
  296. ex_tp = result.ex_tp;
  297. ex_expr = result.ex_expr;
  298. resetExTpTable();
  299. }, function () {
  300. SpreadJsObj.reLoadSheetData(sheet);
  301. return;
  302. });
  303. }
  304. },
  305. clipboardPasted(e, info) {
  306. const hint = {
  307. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  308. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  309. numberCan: {type: 'error', msg: '请粘贴10位以内有效数字并且小于3位小数的浮点数'},
  310. numberCan2: {type: 'error', msg: '请粘贴0~1范围内并且小于3位小数的浮点数'},
  311. numberCan3: {type: 'warning', msg: '已保留3位小数'},
  312. numberCan4: {type: 'warning', msg: '已保留10位有效数字'},
  313. weightNumberCan: {type: 'error', msg: '粘贴的加权系数总和不能大于1'},
  314. };
  315. const range = info.cellRange;
  316. const sortData = info.sheet.zh_data || [];
  317. if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  318. toastMessageUniq(hint.cellError);
  319. // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  320. SpreadJsObj.reLoadSheetHeader(materialExponentSpread.getActiveSheet());
  321. SpreadJsObj.reLoadSheetData(materialExponentSpread.getActiveSheet());
  322. return;
  323. }
  324. if (sortData.length > 0 && range.col + range.colCount > 10) {
  325. toastMessageUniq(hint.cellError);
  326. SpreadJsObj.reLoadSheetHeader(materialExponentSpread.getActiveSheet());
  327. SpreadJsObj.reLoadSheetData(materialExponentSpread.getActiveSheet());
  328. return;
  329. }
  330. const data = [];
  331. // const rowData = [];
  332. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  333. let bPaste = true;
  334. const curRow = range.row + iRow;
  335. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  336. const materialExData = { id: sortData[curRow].id };
  337. const hintRow = range.rowCount > 1 ? curRow : '';
  338. let sameCol = 0;
  339. for (let iCol = 0; iCol < range.colCount; iCol++) {
  340. const curCol = range.col + iCol;
  341. const colSetting = info.sheet.zh_setting.cols[curCol];
  342. if (!colSetting) continue;
  343. let validText = info.sheet.getText(curRow, curCol);
  344. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  345. const orgValue = sortData[curRow][colSetting.field];
  346. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  347. sameCol++;
  348. if (range.colCount === sameCol) {
  349. bPaste = false;
  350. }
  351. continue;
  352. }
  353. if (colSetting.field === 'basic_price' || colSetting.field === 'm_price') {
  354. if (isNaN(validText)) {
  355. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  356. bPaste = false;
  357. continue;
  358. }
  359. const num = parseFloat(validText.toPrecision(10));
  360. if (validText !== null && num < 0) {
  361. toastMessageUniq(getPasteHint(hint.numberCan, hintRow));
  362. bPaste = false;
  363. continue;
  364. } else if (validText !== null) {
  365. if(!Number.isInteger(num) && !/^(\d{1,10}\.\d{1,3})?$/.test(num)) {
  366. toastMessageUniq(getPasteHint(hint.numberCan3, hintRow));
  367. } else if (validText.toString().length > 11) {
  368. toastMessageUniq(getPasteHint(hint.numberCan4, hintRow));
  369. }
  370. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  371. // return;
  372. validText = ZhCalc.round(num, 3);
  373. }
  374. }
  375. if (colSetting.field === 'weight_num') {
  376. if (isNaN(validText)) {
  377. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  378. bPaste = false;
  379. continue;
  380. }
  381. let num = parseFloat(validText);
  382. if (validText !== null && (num < 0 || num >= 1)) {
  383. toastMessageUniq(getPasteHint(hint.numberCan2, hintRow));
  384. bPaste = false;
  385. continue;
  386. } else if (validText !== null && num > 0 && num < 1 && !/^\d+(\.\d{1,3})?$/.test(num)) {
  387. toastMessageUniq(getPasteHint(hint.numberCan3, hintRow));
  388. validText = ZhCalc.round(num, 3);
  389. num = ZhCalc.round(num, 3);
  390. }
  391. const total_weight = ZhCalc.add(ZhCalc.sub(_.sumBy(materialExponentData, 'weight_num'), parseFloat(orgValue)), num);
  392. if (total_weight > 1) {
  393. toastMessageUniq(getPasteHint(hint.weightNumberCan, hintRow));
  394. bPaste = false;
  395. continue;
  396. }
  397. }
  398. materialExData[colSetting.field] = validText;
  399. sortData[curRow][colSetting.field] = validText;
  400. }
  401. if (bPaste) {
  402. materialExData.calc_num = materialExponentCol.getValue.calc_num(sortData[curRow]);
  403. data.push(materialExData);
  404. // rowData.push(curRow);
  405. } else {
  406. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  407. }
  408. }
  409. if (data.length === 0) {
  410. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  411. return;
  412. }
  413. // console.log(data);
  414. // 更新至服务器
  415. postData(window.location.pathname + '/save', { type:'paste', updateData: data }, function (result) {
  416. materialExponentData = result.info;
  417. SpreadJsObj.loadSheetData(materialExponentSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialExponentData);
  418. ex_tp = result.ex_tp;
  419. ex_expr = result.ex_expr;
  420. resetExTpTable();
  421. }, function () {
  422. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  423. return;
  424. });
  425. },
  426. setReadOnly: function(readOnly) {
  427. // SpreadJsObj.resetFieldReadOnly(materialSpread.getActiveSheet(), 'msg_spread', 'm_spread', 'm_tp', 'pre_tp', readOnly);
  428. }
  429. };
  430. materialExponentSpreadObj.refreshActn();
  431. if (!readOnly) {
  432. $('#add').click(materialExponentSpreadObj.add);
  433. $('#del').click(materialExponentSpreadObj.del);
  434. materialExponentSpread.bind(spreadNS.Events.SelectionChanged, materialExponentSpreadObj.selectionChanged);
  435. materialExponentSpread.bind(spreadNS.Events.EditEnded, materialExponentSpreadObj.editEnded);
  436. materialExponentSpread.bind(spreadNS.Events.ButtonClicked, materialExponentSpreadObj.buttonClicked);
  437. materialExponentSpread.bind(spreadNS.Events.ClipboardPasted, materialExponentSpreadObj.clipboardPasted);
  438. if (!editForAudit) {
  439. SpreadJsObj.addDeleteBind(materialExponentSpread, materialExponentSpreadObj.deletePress);
  440. // 右键菜单
  441. $.contextMenu({
  442. selector: '#material-exponent-spread',
  443. build: function ($trigger, e) {
  444. const target = SpreadJsObj.safeRightClickSelection($trigger, e, materialExponentSpread);
  445. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  446. },
  447. items: {
  448. 'create': {
  449. name: '新增',
  450. icon: 'fa-sign-in',
  451. callback: function (key, opt) {
  452. materialExponentSpreadObj.add(materialExponentSpread.getActiveSheet());
  453. },
  454. },
  455. 'delete': {
  456. name: '删除',
  457. icon: 'fa-remove',
  458. callback: function (key, opt) {
  459. materialExponentSpreadObj.del(materialExponentSpread.getActiveSheet());
  460. },
  461. disabled: function (key, opt) {
  462. const sheet = materialExponentSpread.getActiveSheet();
  463. const select = SpreadJsObj.getSelectObject(sheet);
  464. const sel = sheet.getSelections()[0];
  465. materialExponentSpreadObj.refreshActn(sel.rowCount);
  466. if (!readOnly && select && materialExponentBase.isUsed(select) && sel.rowCount === 1) {
  467. return false;
  468. } else {
  469. return true;
  470. }
  471. }
  472. },
  473. }
  474. });
  475. }
  476. // 调差基数选中
  477. $('.calc_select').on('click', function () {
  478. // 如果是选中则清除其余的选中
  479. const code = $(this).val();
  480. for (const calc of ex_calc) {
  481. calc.select = $(this).is(':checked') && code === calc.code ? true : false;
  482. if (!calc.select) {
  483. $('.calc_select[value="'+ calc.code +'"]').prop('checked', false);
  484. }
  485. }
  486. postData(window.location.pathname + '/save', { type:'ex_calc', updateData: ex_calc }, function (result) {
  487. ex_tp = result.ex_tp;
  488. ex_expr = result.ex_expr;
  489. resetExTpTable();
  490. });
  491. });
  492. // 回车提交
  493. $('#calc_zdy').on('keypress', function () {
  494. if(window.event.keyCode === 13) {
  495. $(this).blur();
  496. }
  497. });
  498. // 自定义金额变更并提交
  499. $('#calc_zdy').on('blur', function () {
  500. let newValue = parseFloat($(this).val());
  501. // 判断输入位数,并自动四舍五入
  502. newValue = ZhCalc.round(newValue, materialDecimal.tp);
  503. $('#calc_zdy').val(newValue);
  504. if (isNaN(newValue)) {
  505. toastr.error('请输入正确的金额');
  506. return false;
  507. }
  508. const zdy = _.find(ex_calc, { code: 'zdy' });
  509. if (zdy.value === newValue) {
  510. return;
  511. } else {
  512. zdy.value = newValue;
  513. }
  514. postData(window.location.pathname + '/save', { type:'ex_calc', updateData: ex_calc }, function (result) {
  515. ex_tp = result.ex_tp;
  516. ex_expr = result.ex_expr;
  517. resetExTpTable();
  518. });
  519. });
  520. $('.changeRate').click(function () {
  521. $('#rateInput').val(parseInt($(this).data('value')));
  522. $('#rateInput').siblings('.dropdown-menu').hide();
  523. });
  524. $('#rateInput').click(function () {
  525. $(this).siblings('.dropdown-menu').show();
  526. })
  527. // 回车提交
  528. $('#rateInput').on('keypress', function () {
  529. if(window.event.keyCode === 13) {
  530. $(this).blur();
  531. }
  532. });
  533. $('#rateInput').blur(function () {
  534. const _self = $(this);
  535. setTimeout(function () {
  536. let rate = parseFloat(_self.val());
  537. if (_.isNaN(rate)) {
  538. toastr.error('请输入0-100之前的整数值');
  539. $('#rateInput').val(materialRate);
  540. return;
  541. }
  542. rate = _.round(rate);
  543. if(rate < 0 || rate > 100) {
  544. toastr.error('请输入0-100之前的整数值');
  545. $('#rateInput').val(materialRate);
  546. return;
  547. }
  548. $('#rateInput').siblings('.dropdown-menu').hide();
  549. console.log(rate, materialRate);
  550. if (rate !== materialRate) {
  551. postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  552. const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  553. const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  554. // if (!materialTax) {
  555. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  556. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  557. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  558. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  559. // }
  560. $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  561. $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  562. materialRate = rate;
  563. $('#rateInput').val(rate);
  564. });
  565. } else {
  566. $('#rateInput').val(rate);
  567. }
  568. }, 500);
  569. });
  570. // $('#changeRate').change(function () {
  571. // const rate = parseInt($(this).val());
  572. // postData(window.location.pathname + '/save', { type:'rate', rate: rate }, function (result) {
  573. // const exbqhs = ZhCalc.round(ZhCalc.mul(ex_tp, 1+rate/100), materialDecimal.tp);
  574. // const exjzbqhs = ZhCalc.round(ZhCalc.add(ex_pre_tp_hs, exbqhs), materialDecimal.tp);
  575. // if (!materialTax) {
  576. // const bqhs = ZhCalc.round(ZhCalc.mul(m_tp, 1+rate/100), materialDecimal.tp);
  577. // const jzbqhs = ZhCalc.round(ZhCalc.add(pre_tp_hs, bqhs), materialDecimal.tp);
  578. // $('#rate_set').find('td').eq(1).text(bqhs !== 0 ? bqhs : '');
  579. // $('#rate_set').find('td').eq(2).text(jzbqhs !== 0 ? jzbqhs : '');
  580. // }
  581. // $('#rate_set').find('td').eq(3).text(exbqhs !== 0 ? exbqhs : '');
  582. // $('#rate_set').find('td').eq(4).text(exjzbqhs !== 0 ? exjzbqhs : '');
  583. // });
  584. // });
  585. }
  586. $.divResizer({
  587. select: '#right-spr',
  588. callback: function () {
  589. materialExponentSpread.refresh();
  590. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  591. setLocalCache('material_exponent_' + materialID, width);
  592. }
  593. });
  594. $.divResizer({
  595. select: '#main-resize',
  596. callback: function () {
  597. materialExponentSpread.refresh();
  598. const height = $('#material-exponent-spread').height();
  599. setLocalCache('material_exponent2_' + materialID, height);
  600. }
  601. });
  602. // 展开收起月信息价并浏览器记住本期展开收起
  603. $('a', '.right-nav').bind('click', function () {
  604. //const main = $('#main-view'), tool = $('#tools-view');
  605. const tab = $(this), tabPanel = $(tab.attr('content'));
  606. if (!tab.hasClass('active')) {
  607. $('a', '.side-menu').removeClass('active');
  608. $('.tab-content .tab-select-show').removeClass('active');
  609. tab.addClass('active');
  610. tabPanel.addClass('active');
  611. showSideTools(tab.hasClass('active'));
  612. if (tab.attr('content') === '#base-tab') {
  613. const width = (($('#right-view').width()/$('#right-view').parent('div').width())*100).toFixed();
  614. setLocalCache('material_exponent_' + materialID, width);
  615. }
  616. } else {
  617. removeLocalCache('material_exponent_' + materialID);
  618. tab.removeClass('active');
  619. tabPanel.removeClass('active');
  620. showSideTools(tab.hasClass('active'));
  621. }
  622. materialExponentSpread.refresh();
  623. });
  624. // 根据浏览器记录展开收起
  625. if (getLocalCache('material_exponent_' + materialID)) {
  626. const tab = $('.right-nav a[content="#base-tab"]'), tabPanel = $(tab.attr('content'));
  627. $('a', '.side-menu').removeClass('active');
  628. $('.tab-content .tab-select-show').removeClass('active');
  629. tab.addClass('active');
  630. tabPanel.addClass('active');
  631. $('#right-view').width(getLocalCache('material_exponent_' + materialID) + '%');
  632. showSideTools(tab.hasClass('active'));
  633. materialExponentSpread.refresh();
  634. }
  635. if (getLocalCache('material_exponent2_' + materialID)) {
  636. $('#material-exponent-spread').height(getLocalCache('material_exponent2_' + materialID));
  637. var cHeader = getObjHeight($(".c-header"));
  638. var sjs1 = getObjHeight($('.sjs-height-1'));
  639. $(".bcontent-wrap").height($(window).height()-cHeader-sjs1-90+53);
  640. materialExponentSpread.refresh();
  641. }
  642. function getObjHeight(select) {
  643. return select.length > 0 ? select.height() : 0;
  644. }
  645. $.subMenu({
  646. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  647. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  648. key: 'menu.1.0.0',
  649. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  650. callback: function (info) {
  651. if (info.mini) {
  652. $('.panel-title').addClass('fluid');
  653. $('#sub-menu').removeClass('panel-sidebar');
  654. } else {
  655. $('.panel-title').removeClass('fluid');
  656. $('#sub-menu').addClass('panel-sidebar');
  657. }
  658. autoFlashHeight();
  659. materialExponentSpread.refresh();
  660. }
  661. });
  662. });