change_plan_information.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author EllisRan
  6. * @date 2022/01/21
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. $.subMenu({
  11. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  12. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  13. key: 'menu.1.0.0',
  14. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  15. callback: function (info) {
  16. if (info.mini) {
  17. $('.panel-title').addClass('fluid');
  18. $('#sub-menu').removeClass('panel-sidebar');
  19. } else {
  20. $('.panel-title').removeClass('fluid');
  21. $('#sub-menu').addClass('panel-sidebar');
  22. }
  23. autoFlashHeight();
  24. }
  25. });
  26. handleFileList(fileList);
  27. $('#file-ok').click(function () {
  28. const files = Array.from($('#file-modal')[0].files)
  29. const valiData = files.map(v => {
  30. const ext = v.name.substring(v.name.lastIndexOf('.') + 1)
  31. return {
  32. size: v.size,
  33. ext
  34. }
  35. });
  36. if (validateFiles(valiData)) {
  37. if (files.length) {
  38. const formData = new FormData();
  39. files.forEach(file => {
  40. formData.append('name', file.name);
  41. formData.append('size', file.size);
  42. formData.append('file', file);
  43. })
  44. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  45. handleFileList(result);
  46. $('#file-cancel').click();
  47. });
  48. }
  49. }
  50. })
  51. function handleFileList(files = []) {
  52. $('#file-content').empty();
  53. // const { uncheck, checkNo } = auditConst.status
  54. const newFiles = files.map(file => {
  55. let showDel = false;
  56. if (file.uid === cur_uid) {
  57. // if (!curAuditor) {
  58. // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
  59. // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
  60. // } else {
  61. // curAuditor.audit_id === cur_uid && (showDel = true)
  62. // }
  63. if (change.status === auditConst.status.checked) {
  64. showDel = Boolean(file.extra_upload )
  65. } else {
  66. showDel = true
  67. }
  68. }
  69. return {...file, showDel}
  70. })
  71. let html = change.filePermission ? `<tr><td colspan="5"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
  72. newFiles.forEach((file, idx) => {
  73. if (file.showDel) {
  74. html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/plan/${file.cpid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a><a href="javascript: void(0);" class="text-danger file-del" data-id="${file.id}"><i class="fa fa-remove"></i></a></td></tr>`
  75. } else {
  76. html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/plan/${file.cpid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
  77. }
  78. })
  79. $('#file-content').append(html);
  80. }
  81. $('#file-content').on('click', 'a', function () {
  82. if ($(this).hasClass('file-del')) {
  83. const id = $(this).data('id');
  84. postData(preUrl + '/file/delete', {id}, (result) => {
  85. handleFileList(result);
  86. })
  87. }
  88. });
  89. // 回车提交
  90. $('#plan-table input').on('keypress', function () {
  91. if(window.event.keyCode === 13) {
  92. $(this).blur();
  93. }
  94. });
  95. $('#plan-table input').blur(function () {
  96. const val_name = $(this).data('name');
  97. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  98. switch(val_name) {
  99. case 'code':
  100. if(!val) {
  101. toastr.error('方案编号不能为空');
  102. $(this).val(change[val_name]);
  103. return false;
  104. }
  105. break;
  106. case 'name':
  107. if(val && val.length > 100) {
  108. toastr.error('名称超过100个字,请缩减名称');
  109. $(this).val(change[val_name]);
  110. return false;
  111. }
  112. break;
  113. default:
  114. if(val && val.length > 255) {
  115. toastr.error('超出字段范围,请缩减');
  116. $(this).val(change[val_name]);
  117. return false;
  118. }
  119. break;
  120. }
  121. if(change[val_name] !== val) {
  122. const _self = $(this);
  123. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  124. change[val_name] = val;
  125. _self.val(change[val_name]);
  126. if (val_name === 'code') {
  127. $('#change-plan-code').text(change[val_name]);
  128. }
  129. }, function () {
  130. _self.val(change[val_name]);
  131. })
  132. } else {
  133. $(this).val(change[val_name]);
  134. }
  135. });
  136. $('#plan-table textarea').blur(function () {
  137. const val_name = $(this).data('name');
  138. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  139. if(change[val_name] !== val) {
  140. const _self = $(this);
  141. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  142. change[val_name] = val;
  143. _self.val(change[val_name]);
  144. }, function () {
  145. _self.val(change[val_name]);
  146. })
  147. } else {
  148. $(this).val(change[val_name]);
  149. }
  150. });
  151. $('#plan-table select').change(function () {
  152. const val_name = $(this).attr('data-name');
  153. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  154. if(change[val_name] !== val) {
  155. const _self = $(this);
  156. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  157. change[val_name] = val;
  158. _self.val(change[val_name]);
  159. }, function () {
  160. _self.val(change[val_name]);
  161. })
  162. } else {
  163. $(this).val(change[val_name]);
  164. }
  165. });
  166. const changeSpread = SpreadJsObj.createNewSpread($('#plan-spread')[0]);
  167. const changeSpreadSheet = changeSpread.getActiveSheet();
  168. const style1 = new GC.Spread.Sheets.Style();
  169. style1.locked = true;
  170. const changeSpreadSetting = {
  171. cols: [
  172. {title: '新增单价', colSpan: '1', rowSpan: '2', field: 'new_up', hAlign: 1, width: 35, cellType: 'checkbox', readOnly: 'readOnly.isEdit'},
  173. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit'},
  174. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: 'readOnly.isEdit'},
  175. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  176. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  177. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  178. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  179. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.camount'},
  180. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  181. {title: '审批后变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},
  182. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'},
  183. ],
  184. emptyRows: !readOnly ? 3 : 0,
  185. headRows: 2,
  186. headRowHeight: [25, 25],
  187. defaultRowHeight: 21,
  188. headerFont: '12px 微软雅黑',
  189. font: '12px 微软雅黑',
  190. readOnly: change.status === auditConst.status.checking ? false : readOnly,
  191. localCache: {
  192. key: 'changes-plan-list-spread',
  193. colWidth: true,
  194. }
  195. };
  196. console.log(changeList, change.listAudits);
  197. if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) {
  198. for (const audit of change.listAudits) {
  199. // const userinfo = _.find(auditList2, { 'aid': aid });
  200. const newColcount = {
  201. title: audit.name + ' 审批|数量',
  202. colSpan: '2|1', rowSpan: '1|1',
  203. field: 'audit_amount_' + audit.aid,
  204. hAlign: 2, width: 60, type: 'Number',
  205. readOnly: !(change.shenpiPower && audit.aid === parseInt(cur_uid))
  206. };
  207. const newColTp = {
  208. title: '|金额',
  209. colSpan: '|1', rowSpan: '|1',
  210. field: 'sa_tp_' + audit.aid,
  211. hAlign: 2, width: 80, type: 'Number',
  212. readOnly: true
  213. };
  214. changeSpreadSetting.cols.push(newColcount);
  215. changeSpreadSetting.cols.push(newColTp);
  216. }
  217. }
  218. changeSpreadSetting.cols.push({title: '备注1', colSpan: '1', rowSpan: '2', field: 'ex_memo1', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit2'});
  219. changeSpreadSetting.cols.push({title: '备注2', colSpan: '1', rowSpan: '2', field: 'ex_memo2', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit2'});
  220. const changeCol = {
  221. getValue: {
  222. unit_price: function(data) {
  223. return ZhCalc.round(data.unit_price, unitPriceUnit);
  224. },
  225. oa_tp: function (data) {
  226. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.oamount, findDecimal(data.unit))), totalPriceUnit);
  227. },
  228. ca_tp: function (data) {
  229. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.camount, findDecimal(data.unit))), totalPriceUnit);
  230. },
  231. oamount: function (data) {
  232. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  233. },
  234. camount: function (data) {
  235. return ZhCalc.round(data.camount, findDecimal(data.unit));
  236. },
  237. samount: function (data) {
  238. return ZhCalc.round(data.samount, findDecimal(data.unit));
  239. },
  240. sa_tp: function (data) {
  241. return ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), ZhCalc.round(data.samount, findDecimal(data.unit))), totalPriceUnit);
  242. },
  243. },
  244. readOnly: {
  245. isEdit: function (data) {
  246. return readOnly;
  247. },
  248. isEdit2: function (data) {
  249. return change.status === auditConst.status.checked;
  250. },
  251. },
  252. };
  253. const changeSpreadObj = {
  254. makeSjsFooter: function() {
  255. // 增加汇总行并设为锁定禁止编辑状态
  256. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  257. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 1, '合计');
  258. const cellType1 = new GC.Spread.Sheets.CellTypes.Text();
  259. changeSpreadSheet.getCell(changeSpreadSheet.getRowCount() - 1, 0).cellType(cellType1);
  260. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  261. changeSpreadObj.countSum();
  262. },
  263. setAuditValue: function () {
  264. for (const c of changeList) {
  265. for (const audit of change.listAudits) {
  266. c['audit_amount_' + audit.aid] = ZhCalc.round(c['audit_amount_' + audit.aid], findDecimal(c.unit));
  267. c['sa_tp_' + audit.aid] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + audit.aid], ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit);
  268. }
  269. }
  270. },
  271. setRowValueAndSum: function (data, row, col) {
  272. for (const j in change.listAudits) {
  273. const sum = ZhCalc.round(ZhCalc.mul(ZhCalc.round(data.unit_price, unitPriceUnit), parseFloat(changeSpreadSheet.getValue(row, 11 + parseInt(j)*2))), totalPriceUnit);
  274. changeSpreadSheet.setValue(row, 12 + j*2, sum !== 0 ? sum : null);
  275. }
  276. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
  277. // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
  278. const count = changeSpreadSetting.cols.length;
  279. if (col+1 >= count - 2) {
  280. return;
  281. }
  282. const rowCount = changeSpreadSheet.getRowCount();
  283. // 用户的数据合计
  284. let audit_sum = 0;
  285. for(let i = 0; i < rowCount - 1; i++){
  286. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
  287. }
  288. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
  289. },
  290. countSum: function() {
  291. const rowCount = changeSpreadSheet.getRowCount();
  292. let oSum = 0,
  293. cSum = 0,
  294. sSum = 0;
  295. for (let i = 0; i < rowCount - 1; i++) {
  296. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 6));
  297. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 8));
  298. sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, 10));
  299. }
  300. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 6, oSum !== 0 ? oSum : null);
  301. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 8, cSum !== 0 ? cSum : null);
  302. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 10, sSum !== 0 ? sSum : null);
  303. // 用户的数据合计
  304. for (const j in change.listAudits) {
  305. let audit_sum = 0;
  306. for(let i = 0; i < rowCount - 1; i++){
  307. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 12 + j*2));
  308. }
  309. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 12 + j*2, audit_sum !== 0 ? audit_sum : null);
  310. }
  311. },
  312. deletePress: function (sheet) {
  313. return;
  314. },
  315. showHideAudit: function (show = false) {
  316. const count = changeSpreadSetting.cols.length;
  317. for (let i = 11; i < count; i++) {
  318. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  319. }
  320. changeSpreadSheet.setColumnVisible(count - 1, true, GC.Spread.Sheets.SheetArea.viewport);
  321. changeSpreadSheet.setColumnVisible(count - 2, true, GC.Spread.Sheets.SheetArea.viewport);
  322. changeSpreadSheet.setColumnVisible(9, !show, GC.Spread.Sheets.SheetArea.viewport);
  323. changeSpreadSheet.setColumnVisible(10, !show, GC.Spread.Sheets.SheetArea.viewport);
  324. },
  325. valueChanged: function (e, info) {
  326. // 防止ctrl+z撤销数据
  327. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  328. }
  329. };
  330. if (!readOnly) {
  331. changeSpreadObj.add = function () {
  332. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, 1);
  333. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  334. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  335. };
  336. changeSpreadObj.batchAdd = function (num) {
  337. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount() - 1, parseInt(num));
  338. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  339. };
  340. changeSpreadObj.del = function (sheet) {
  341. const selection = sheet.getSelections();
  342. const row = selection[0].row, count = selection[0].rowCount;
  343. const sortData = sheet.zh_data;
  344. const ids = [];
  345. let emptyRowNum = 0;
  346. for (let iRow = 0; iRow < count; iRow++) {
  347. if (sortData[iRow + row]) {
  348. ids.push(sortData[iRow + row].id);
  349. } else {
  350. emptyRowNum++;
  351. }
  352. }
  353. if (ids.length > 0) {
  354. postData(preUrl + '/list/save', {type: 'del', ids}, function (result) {
  355. changeList = result;
  356. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  357. changeSpreadObj.makeSjsFooter();
  358. });
  359. } else if (emptyRowNum > 0) {
  360. changeSpreadSheet.deleteRows(changeList.length, emptyRowNum);
  361. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  362. }
  363. };
  364. changeSpreadObj.editEnded = function (e, info) {
  365. if (info.sheet.zh_setting) {
  366. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
  367. const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
  368. const col = info.sheet.zh_setting.cols[info.col];
  369. if (col.field === 'new_up') {
  370. return;
  371. }
  372. // 未改变值则不提交
  373. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  374. const orgValue = type === 'update' ? select[col.field] : '';
  375. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  376. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  377. return;
  378. }
  379. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  380. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  381. return;
  382. }
  383. // 判断部分值是否输入的是数字判断和数据计算
  384. if (col.type === 'Number') {
  385. if (isNaN(validText)) {
  386. toastr.error('不能输入其它非数字类型字符');
  387. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  388. return;
  389. }
  390. if (col.field === 'unit_price') {
  391. validText = ZhCalc.round(validText, unitPriceUnit);
  392. } else {
  393. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  394. }
  395. }
  396. if (col.field === 'unit') {
  397. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  398. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  399. }
  400. if(col.field === 'camount') {
  401. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  402. }
  403. select[col.field] = validText;
  404. console.log(select, type);
  405. delete select.waitingLoading;
  406. // 更新至服务器
  407. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  408. if(type === 'update') {
  409. changeList.splice(info.row, 1, select);
  410. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  411. changeSpreadObj.countSum();
  412. } else {
  413. changeList.push(result);
  414. changeSpreadSheet.addRows(changeList.length - 1, 1);
  415. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  416. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  417. // changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  418. }
  419. }, function () {
  420. select[col.field] = orgValue;
  421. if(col.field === 'camount') {
  422. select.spamount = orgValue;
  423. }
  424. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  425. });
  426. }
  427. };
  428. changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
  429. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  430. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  431. }
  432. const hint = {
  433. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  434. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  435. };
  436. if (info.sheet.zh_setting) {
  437. const sortData = info.sheet.zh_data || [];
  438. const range = info.cellRange;
  439. const data = [];
  440. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  441. let bPaste = true;
  442. const curRow = range.row + iRow;
  443. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  444. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  445. const hintRow = range.rowCount > 1 ? curRow : '';
  446. let sameCol = 0;
  447. for (let iCol = 0; iCol < range.colCount; iCol++) {
  448. const curCol = range.col + iCol;
  449. const colSetting = info.sheet.zh_setting.cols[curCol];
  450. if (!colSetting) continue;
  451. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  452. let validText = info.sheet.getText(curRow, curCol);
  453. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  454. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  455. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  456. sameCol++;
  457. if (range.colCount === sameCol) {
  458. bPaste = false;
  459. }
  460. continue;
  461. }
  462. if (colSetting.type === 'Number') {
  463. if (isNaN(validText)) {
  464. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  465. toastMessageUniq(hint.numberExpr);
  466. bPaste = false;
  467. continue;
  468. }
  469. if (colSetting.field === 'unit_price') {
  470. validText = ZhCalc.round(validText, unitPriceUnit);
  471. } else {
  472. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  473. }
  474. }
  475. let unitdecimal = validText;
  476. if (colSetting.field === 'unit') {
  477. //粘贴内容要为下拉列表里所有的单位,不然为空
  478. if (changeUnits.indexOf(validText) === -1) {
  479. unitdecimal = '';
  480. // validText = null;
  481. }
  482. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  483. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  484. cLData.spamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  485. }
  486. // sortData[curRow][colSetting.field] = validText;
  487. if (colSetting.field === 'camount') {
  488. cLData.spamount = ZhCalc.round(validText, findDecimal(unitdecimal)) || 0;
  489. }
  490. cLData[colSetting.field] = validText;
  491. }
  492. if (bPaste) {
  493. delete cLData.oa_tp;
  494. delete cLData.ca_tp;
  495. data.push(cLData);
  496. // rowData.push(curRow);
  497. } else {
  498. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  499. }
  500. }
  501. if (data.length === 0) {
  502. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  503. return;
  504. }
  505. console.log(data);
  506. // 更新至服务器
  507. postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  508. changeList = result;
  509. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  510. changeSpreadObj.makeSjsFooter();
  511. }, function () {
  512. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  513. return;
  514. });
  515. }
  516. };
  517. changeSpreadObj.updateOamount = function () {
  518. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  519. const updateList = [];
  520. for (const c of changeList) {
  521. const source = _.find(dataSource, function (item) {
  522. if (((item.b_code && item.b_code === c.code) || (item.code && item.code === c.code)) && item.name === c.name) {
  523. if (listRule.rule.length > 0) {
  524. for(const r of listRule.rule) {
  525. if (item[r] !== c[r]) {
  526. return false;
  527. }
  528. }
  529. }
  530. return true;
  531. }
  532. return false;
  533. });
  534. if (source && source.quantity !== c.oamount) {
  535. updateList.push({ id: c.id, oamount: source.quantity });
  536. }
  537. }
  538. console.log(updateList);
  539. if(updateList.length > 0) {
  540. postData(preUrl + '/list/save', { type:'paste', updateData: updateList }, function (result) {
  541. changeList = result;
  542. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  543. changeSpreadObj.makeSjsFooter();
  544. });
  545. }
  546. };
  547. changeSpreadObj.buttonClicked = function (e, info) {
  548. if (info.sheet.zh_setting) {
  549. const select = SpreadJsObj.getSelectObject(info.sheet);
  550. const col = info.sheet.zh_setting.cols[info.col];
  551. if(!select) {
  552. toastr.error('请添加清单编号再勾选');
  553. if (info.sheet.isEditing()) {
  554. info.sheet.endEdit(true);
  555. }
  556. return;
  557. } else if (col.field === 'new_up') {
  558. if (info.sheet.isEditing()) {
  559. info.sheet.endEdit(true);
  560. }
  561. select.new_up = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  562. postData(preUrl + '/list/save', { type: 'update', updateData: { id: select.id, new_up: select.new_up } }, function (result) {
  563. changeList.splice(info.row, 1, select);
  564. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  565. changeSpreadObj.countSum();
  566. }, function () {
  567. select.new_up = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  568. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  569. });
  570. }
  571. // if (materialCol.readOnly.isEdit(select)) {
  572. // return;
  573. // }
  574. // if (col.field === 'new_up') {
  575. // if (info.sheet.isEditing()) {
  576. // info.sheet.endEdit(true);
  577. // }
  578. // select.is_summary = info.sheet.getValue(info.row, info.col) ? 1 : 0;
  579. // delete select.waitingLoading;
  580. // // 更新至服务器
  581. // postData(window.location.pathname + '/save', { type:'update', updateData: select }, function (result) {
  582. // m_tp = result.m_tp;
  583. // if (materialTax) {
  584. // m_tax_tp = result.m_tax_tp;
  585. // }
  586. // resetTpTable();
  587. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  588. // }, function () {
  589. // select.is_summary = info.sheet.getValue(info.row, info.col) ? 0 : 1;
  590. // SpreadJsObj.reLoadRowData(info.sheet, info.row);
  591. // });
  592. // }
  593. }
  594. };
  595. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  596. changeSpread.bind(spreadNS.Events.ButtonClicked, changeSpreadObj.buttonClicked);
  597. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  598. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  599. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  600. let batchInsertObj;
  601. $.contextMenu.types.batchInsert = function (item, opt, root) {
  602. const self = this;
  603. if ($.isFunction(item.icon)) {
  604. item._icon = item.icon.call(this, this, $t, key, item);
  605. } else {
  606. if (typeof(item.icon) === 'string' && item.icon.substring(0, 3) === 'fa-') {
  607. // to enable font awesome
  608. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '--fa fa ' + item.icon;
  609. } else {
  610. item._icon = root.classNames.icon + ' ' + root.classNames.icon + '-' + item.icon;
  611. }
  612. }
  613. this.addClass(item._icon);
  614. const $obj = $('<div>' + item.name + '<input class="text-right ml-1 mr-1" type="tel" max="100" min="1" value="' + item.value + '" style="width: 30px; height: 18px; padding-right: 4px;">行</div>')
  615. .appendTo(this);
  616. const $input = $obj.find('input');
  617. const event = () => {
  618. if (self.hasClass('context-menu-disabled')) return;
  619. item.batchInsert($input[0], root);
  620. };
  621. $obj.on('click', event).keypress(function (e) {if (e.keyCode === 13) { event(); }});
  622. $input.click((e) => {e.stopPropagation();})
  623. .keyup((e) => {if (e.keyCode === 13) item.batchInsert($input[0], root);})
  624. .on('input', function () {this.value = this.value.replace(/[^\d]/g, '');});
  625. };
  626. // 右键菜单
  627. $.contextMenu({
  628. selector: '#plan-spread',
  629. build: function ($trigger, e) {
  630. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  631. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  632. },
  633. items: {
  634. 'updateOamount': {
  635. name: '原设计数量读取',
  636. icon: '',
  637. callback: function (key, opt) {
  638. changeSpreadObj.updateOamount(changeSpreadSheet);
  639. },
  640. disabled: function (key, opt) {
  641. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  642. // const sel = changeSpreadSheet.getSelections()[0];
  643. // // console.log(select, sel);
  644. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  645. // return false;
  646. // } else {
  647. // return true;
  648. // }
  649. }
  650. },
  651. sprDel: '------------',
  652. 'createAdd': {
  653. name: '添加行',
  654. icon: 'fa-sign-in',
  655. callback: function (key, opt) {
  656. changeSpreadObj.add(changeSpreadSheet);
  657. },
  658. },
  659. 'batchInsert': {
  660. name: '批量添加行',
  661. type: 'batchInsert',
  662. value: '2',
  663. icon: 'fa-sign-in',
  664. batchInsert: function (obj, root) {
  665. if (_.toNumber(obj.value) > _.toNumber(obj.max)) {
  666. obj.value = obj.max;
  667. toastr.warning('批量添加不可多于' + obj.max);
  668. } else if(_.toNumber(obj.value) < _.toNumber(obj.min)) {
  669. obj.value = obj.min;
  670. toastr.warning('批量添加不可少于' + obj.min);
  671. } else {
  672. // treeOperationObj.addNode(ledgerSpread.getActiveSheet(), parseInt(obj.value));
  673. changeSpreadObj.batchAdd(obj.value);
  674. root.$menu.trigger('contextmenu:hide');
  675. }
  676. },
  677. },
  678. 'delete': {
  679. name: '删除',
  680. icon: 'fa-remove',
  681. callback: function (key, opt) {
  682. changeSpreadObj.del(changeSpreadSheet);
  683. },
  684. disabled: function (key, opt) {
  685. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  686. if (changeSpreadSheet.zh_data) {
  687. const selection = changeSpreadSheet.getSelections();
  688. // return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  689. return changeSpreadSheet.getRowCount() - 1 < selection[0].row + selection[0].rowCount;
  690. } else {
  691. return true;
  692. }
  693. // const sel = changeSpreadSheet.getSelections()[0];
  694. // // console.log(select, sel);
  695. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  696. // return false;
  697. // } else {
  698. // return true;
  699. // }
  700. }
  701. },
  702. }
  703. });
  704. $('#shuliangguize').on('show.bs.modal', function () {
  705. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  706. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  707. for(const r of listRule.rule) {
  708. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  709. }
  710. });
  711. // 设置原设计数量读取
  712. $('#setListRule').click(function () {
  713. const rule = [];
  714. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  715. rule.push($(this).val());
  716. });
  717. const newListRule = {
  718. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  719. rule,
  720. };
  721. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  722. listRule = newListRule;
  723. $('#shuliangguize').modal('hide');
  724. });
  725. })
  726. }
  727. if (change.shenpiPower) {
  728. changeSpreadObj.editEnded = function (e, info) {
  729. if (info.sheet.zh_setting) {
  730. const select = SpreadJsObj.getSelectObject(info.sheet);
  731. const col = info.sheet.zh_setting.cols[info.col];
  732. // 未改变值则不提交
  733. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  734. const orgValue = select[col.field];
  735. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  736. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  737. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  738. return;
  739. }
  740. // 判断部分值是否输入的是数字判断和数据计算
  741. if (col.type === 'Number') {
  742. if (isNaN(validText)) {
  743. toastr.error('不能输入其它非数字类型字符');
  744. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  745. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  746. return;
  747. }
  748. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  749. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  750. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  751. }
  752. select[col.field] = validText;
  753. const data = {
  754. id: select.id,
  755. // spamount: select.spamount,
  756. };
  757. if (col.field === 'ex_memo1' || col.field === 'ex_memo2') {
  758. data[col.field] = select[col.field];
  759. } else {
  760. data.spamount = select.spamount;
  761. }
  762. console.log(data);
  763. // 更新至服务器
  764. postData(preUrl + '/list/save', { type:'update', updateData: data }, function (result) {
  765. changeList.splice(info.row, 1, select);
  766. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  767. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  768. }, function () {
  769. select[col.field] = orgValue;
  770. if (col.field !== 'ex_memo1' && col.field !== 'ex_memo2') {
  771. select.spamount = orgValue;
  772. }
  773. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  774. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  775. });
  776. }
  777. };
  778. changeSpreadObj.clipboardPasted = function(e, info) {
  779. const hint = {
  780. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  781. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  782. };
  783. const range = info.cellRange;
  784. const sortData = info.sheet.zh_data || [];
  785. const data = [];
  786. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  787. let bPaste = true;
  788. const curRow = range.row + iRow;
  789. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  790. const cLData = { id: sortData[curRow].id };
  791. const hintRow = range.rowCount > 1 ? curRow : '';
  792. let sameCol = 0;
  793. for (let iCol = 0; iCol < range.colCount; iCol++) {
  794. const curCol = range.col + iCol;
  795. const colSetting = info.sheet.zh_setting.cols[curCol];
  796. if (!colSetting) continue;
  797. let validText = info.sheet.getText(curRow, curCol);
  798. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  799. const orgValue = sortData[curRow][colSetting.field];
  800. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  801. sameCol++;
  802. if (range.colCount === sameCol) {
  803. bPaste = false;
  804. }
  805. continue;
  806. }
  807. if (colSetting.type === 'Number') {
  808. if (isNaN(validText)) {
  809. toastMessageUniq(hint.numberExpr);
  810. bPaste = false;
  811. continue;
  812. }
  813. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  814. }
  815. // cLData[colSetting.field] = validText;
  816. sortData[curRow][colSetting.field] = validText;
  817. cLData.spamount = validText;
  818. }
  819. if (bPaste) {
  820. data.push(cLData);
  821. // rowData.push(curRow);
  822. } else {
  823. changeSpreadObj.setAuditValue();
  824. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  825. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  826. }
  827. }
  828. if (data.length === 0) {
  829. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  830. return;
  831. }
  832. console.log(data);
  833. // 更新至服务器
  834. postData(preUrl + '/list/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  835. changeList = result;
  836. changeSpreadObj.setAuditValue();
  837. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  838. changeSpreadObj.makeSjsFooter();
  839. }, function () {
  840. changeSpreadObj.setAuditValue();
  841. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  842. return;
  843. });
  844. };
  845. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  846. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  847. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  848. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  849. }
  850. let changeListData;
  851. let gclGatherData;
  852. let dealBillList;
  853. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  854. postData(billUrl + '/defaultBills', {}, function (result) {
  855. gclGatherModel.loadLedgerData(result.bills);
  856. gclGatherModel.loadPosData(result.pos);
  857. gclGatherData = gclGatherModel.gatherGclData();
  858. gclGatherData = _.filter(gclGatherData, function (item) {
  859. return item.leafXmjs && item.leafXmjs.length !== 0;
  860. });
  861. // 数组去重
  862. dealBillList = result.dealBills;
  863. changeListData = gclGatherData;
  864. console.log(changeListData, dealBillList);
  865. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  866. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  867. if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) changeSpreadObj.setAuditValue();
  868. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  869. changeSpreadObj.makeSjsFooter();
  870. // 计算最新的变更总额和change的total_price是否一致,不一致则更新
  871. if (change.status !== auditConst.status.checked) {
  872. // let new_tp = 0;
  873. const updateArray = [];
  874. for (const c of changeList) {
  875. const oneUpdate = {};
  876. if (ZhCalc.round(c.spamount, findDecimal(c.unit)) !== c.spamount) oneUpdate.spamount = ZhCalc.round(c.spamount, findDecimal(c.unit));
  877. if (ZhCalc.round(c.oamount, findDecimal(c.unit)) !== c.oamount) oneUpdate.oamount = ZhCalc.round(c.oamount, findDecimal(c.unit));
  878. if (ZhCalc.round(c.camount, findDecimal(c.unit)) !== c.camount) oneUpdate.camount = ZhCalc.round(c.camount, findDecimal(c.unit));
  879. if (ZhCalc.round(c.unit_price, unitPriceUnit) !== c.unit_price) oneUpdate.unit_price = ZhCalc.round(c.unit_price, unitPriceUnit);
  880. const audit_amount = c.audit_amount ? c.audit_amount.split(',') : null;
  881. if (audit_amount) {
  882. for (const i in audit_amount) {
  883. if (ZhCalc.round(parseFloat(audit_amount[i]), findDecimal(c.unit)) !== parseFloat(audit_amount[i])) audit_amount[i] = ZhCalc.round(parseFloat(audit_amount[i]), findDecimal(c.unit));
  884. }
  885. if (c.audit_amount !== audit_amount.join(',')) oneUpdate.audit_amount = audit_amount.join(',');
  886. }
  887. if (!_.isEmpty(oneUpdate)) {
  888. oneUpdate.id = c.id;
  889. updateArray.push(oneUpdate);
  890. }
  891. // new_tp = ZhCalc.add(new_tp, ZhCalc.round(ZhCalc.mul(ZhCalc.round(c.spamount, findDecimal(c.unit)), ZhCalc.round(c.unit_price, unitPriceUnit)), totalPriceUnit));
  892. }
  893. console.log(updateArray);
  894. if (updateArray.length > 0) {
  895. // 更新至服务器
  896. postData(preUrl + '/list/save', { type:'paste', updateData: updateArray }, function (result) {
  897. changeList = result;
  898. if (change.status === auditConst.status.checking) changeSpreadObj.setAuditValue();
  899. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  900. changeSpreadObj.makeSjsFooter();
  901. });
  902. }
  903. // if (change.total_price && change.total_price !== new_tp) {
  904. // postData(preUrl + '/list/save', {type: 'update_tp', updateData: new_tp}, function (result) {
  905. // });
  906. // }
  907. changeSpreadObj.showHideAudit(true);
  908. }
  909. if (change.status === auditConst.status.checked) {
  910. changeSpreadObj.showHideAudit(false);
  911. }
  912. });
  913. // 审批流程展示与隐藏
  914. $('#show-table-detail').on('click', function (e) {
  915. if($(e.target).is('label')){
  916. return;
  917. }
  918. changeSpreadObj.showHideAudit($(this).is(':checked'));
  919. });
  920. });
  921. /**
  922. * 校验文件大小、格式
  923. * @param {Array} files 文件数组
  924. */
  925. function validateFiles(files) {
  926. if (files.length > 10) {
  927. toastr.error('至多同时上传10个文件');
  928. return false
  929. }
  930. return files.every(file => {
  931. if (file.size > 1024 * 1024 * 30) {
  932. toastr.error('文件大小限制为30MB');
  933. return false
  934. }
  935. if (whiteList.indexOf('.' + file.ext) === -1) {
  936. toastr.error('请上传正确的格式文件');
  937. return false
  938. }
  939. return true
  940. })
  941. }
  942. function findDecimal(unit) {
  943. let value = precision.other.value;
  944. const changeUnits = precision;
  945. for (const d in changeUnits) {
  946. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  947. value = changeUnits[d].value;
  948. break;
  949. }
  950. }
  951. return value;
  952. }
  953. const is_numeric = (value) => {
  954. if (typeof(value) === 'object') {
  955. return false;
  956. } else {
  957. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  958. }
  959. };