change_apply_information.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. console.log(!$('#addfujian input[name="type"]:checked').val());
  37. if (!$('#addfujian input[name="type"]:checked').val()) {
  38. toastr.error('请选择资料类型');
  39. return false;
  40. }
  41. if (validateFiles(valiData)) {
  42. if (files.length) {
  43. const formData = new FormData();
  44. formData.append('type', $('#addfujian input[name="type"]:checked').val());
  45. files.forEach(file => {
  46. formData.append('name', file.name);
  47. formData.append('size', file.size);
  48. formData.append('file', file);
  49. })
  50. postDataWithFile(preUrl + '/file/upload', formData, function (result) {
  51. handleFileList(result);
  52. $('#file-cancel').click();
  53. });
  54. }
  55. }
  56. })
  57. function handleFileList(files = []) {
  58. $('#file-content').empty();
  59. // const { uncheck, checkNo } = auditConst.status
  60. const newFiles = files.map(file => {
  61. let showDel = false;
  62. if (file.uid === cur_uid) {
  63. // if (!curAuditor) {
  64. // advance.status === uncheck && cur_uid === advance.uid && (showDel = true)
  65. // advance.status === checkNo && cur_uid === advance.uid && (showDel = true)
  66. // } else {
  67. // curAuditor.audit_id === cur_uid && (showDel = true)
  68. // }
  69. if (change.status === auditConst.status.checked) {
  70. showDel = Boolean(file.extra_upload )
  71. } else {
  72. showDel = true
  73. }
  74. }
  75. return {...file, showDel}
  76. })
  77. let html = change.filePermission ? `<tr><td colspan="6"><a href="#addfujian" data-toggle="modal" class="btn btn-primary btn-sm" data-placement="bottom" title="">上传附件</a></td></tr>` : '';
  78. newFiles.forEach((file, idx) => {
  79. if (file.showDel) {
  80. html += `<tr><td>${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/apply/${file.caid}/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>`
  81. } else {
  82. html += `<tr><td width="70">${idx + 1}</td><td><a href="${file.filepath}" target="_blank">${file.filename}</a></td><td>${file.username}</td><td>${file.type ? _.find(fileTypeConst, {key: file.type }).value : ''}</td><td>${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}</td><td><a href="/tender/${file.tid}/change/apply/${file.caid}/information/file/${file.id}/download" class="mr-2"><i class="fa fa-download"></i></a></td></tr>`
  83. }
  84. })
  85. $('#file-content').append(html);
  86. }
  87. $('#file-content').on('click', 'a', function () {
  88. if ($(this).hasClass('file-del')) {
  89. const id = $(this).data('id');
  90. postData(preUrl + '/file/delete', {id}, (result) => {
  91. handleFileList(result);
  92. })
  93. }
  94. });
  95. // 回车提交
  96. $('#apply-table input').on('keypress', function () {
  97. if(window.event.keyCode === 13) {
  98. $(this).blur();
  99. }
  100. });
  101. $('#apply-table input').blur(function () {
  102. const val_name = $(this).data('name');
  103. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  104. switch(val_name) {
  105. case 'code':
  106. if(!val) {
  107. toastr.error('申请编号不能为空');
  108. $(this).val(change[val_name]);
  109. return false;
  110. }
  111. break;
  112. case 'name':
  113. if(val && val.length > 100) {
  114. toastr.error('名称超过100个字,请缩减名称');
  115. $(this).val(change[val_name]);
  116. return false;
  117. }
  118. break;
  119. case 'org_price':
  120. case 'change_price':
  121. case 'crease_price':
  122. val = val ? parseFloat(val) : null;
  123. if(val && !_.isNumber(val)) {
  124. toastr.error('请输入数字');
  125. $(this).val(change[val_name]);
  126. return false;
  127. }
  128. break;
  129. default:
  130. if(val && val.length > 255) {
  131. toastr.error('超出字段范围,请缩减');
  132. $(this).val(change[val_name]);
  133. return false;
  134. }
  135. break;
  136. }
  137. if(change[val_name] !== val) {
  138. const _self = $(this);
  139. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  140. change[val_name] = val;
  141. _self.val(change[val_name]);
  142. if (val_name === 'code') {
  143. $('#change-apply-code').text(change[val_name]);
  144. }
  145. }, function () {
  146. _self.val(change[val_name]);
  147. })
  148. } else {
  149. $(this).val(change[val_name]);
  150. }
  151. });
  152. $('#apply-table textarea').blur(function () {
  153. const val_name = $(this).data('name');
  154. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  155. if(change[val_name] !== val) {
  156. const _self = $(this);
  157. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  158. change[val_name] = val;
  159. _self.val(change[val_name]);
  160. }, function () {
  161. _self.val(change[val_name]);
  162. })
  163. } else {
  164. $(this).val(change[val_name]);
  165. }
  166. });
  167. $('#apply-table select').change(function () {
  168. const val_name = $(this).attr('data-name');
  169. let val = _.trim($(this).val()) !== '' ? _.trim($(this).val()) : null;
  170. if(change[val_name] !== val) {
  171. const _self = $(this);
  172. postData(preUrl + '/save', { name: val_name, val}, function (result) {
  173. change[val_name] = val;
  174. _self.val(change[val_name]);
  175. }, function () {
  176. _self.val(change[val_name]);
  177. })
  178. } else {
  179. $(this).val(change[val_name]);
  180. }
  181. });
  182. const changeSpread = SpreadJsObj.createNewSpread($('#apply-spread')[0]);
  183. const changeSpreadSheet = changeSpread.getActiveSheet();
  184. const style1 = new GC.Spread.Sheets.Style();
  185. style1.locked = true;
  186. const changeSpreadSetting = {
  187. cols: [
  188. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit'},
  189. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: 'readOnly.isEdit'},
  190. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  191. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  192. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  193. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  194. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.camount'},
  195. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  196. ],
  197. emptyRows: !readOnly ? 3 : 0,
  198. headRows: 2,
  199. headRowHeight: [25, 25],
  200. defaultRowHeight: 21,
  201. headerFont: '12px 微软雅黑',
  202. font: '12px 微软雅黑',
  203. readOnly: readOnly,
  204. localCache: {
  205. key: 'changes-apply-list-spread',
  206. colWidth: true,
  207. }
  208. };
  209. console.log(changeList);
  210. const changeCol = {
  211. getValue: {
  212. unit_price: function(data) {
  213. return ZhCalc.round(data.unit_price, unitPriceUnit);
  214. },
  215. oa_tp: function (data) {
  216. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  217. },
  218. ca_tp: function (data) {
  219. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  220. },
  221. oamount: function (data) {
  222. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  223. },
  224. camount: function (data) {
  225. return ZhCalc.round(data.camount, findDecimal(data.unit));
  226. },
  227. },
  228. readOnly: {
  229. isEdit: function (data) {
  230. return readOnly;
  231. },
  232. },
  233. };
  234. const changeSpreadObj = {
  235. makeSjsFooter: function() {
  236. // 增加汇总行并设为锁定禁止编辑状态
  237. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  238. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  239. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  240. changeSpreadObj.countSum();
  241. },
  242. countSum: function() {
  243. const rowCount = changeSpreadSheet.getRowCount();
  244. let oSum = 0,
  245. cSum = 0;
  246. for (let i = 0; i < rowCount - 1; i++) {
  247. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 5));
  248. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 7));
  249. }
  250. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 5, oSum !== 0 ? oSum : null);
  251. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
  252. },
  253. deletePress: function (sheet) {
  254. return;
  255. },
  256. valueChanged: function (e, info) {
  257. // 防止ctrl+z撤销数据
  258. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  259. }
  260. };
  261. if (!readOnly) {
  262. changeSpreadObj.del = function (sheet) {
  263. const selection = sheet.getSelections();
  264. const row = selection[0].row, count = selection[0].rowCount;
  265. const sortData = sheet.zh_data;
  266. const ids = [];
  267. for (let iRow = 0; iRow < count; iRow++) {
  268. if (sortData[iRow + row]) {
  269. ids.push(sortData[iRow + row].id);
  270. }
  271. }
  272. if (ids.length > 0) {
  273. postData(preUrl + '/list/save', {type: 'del', ids}, function (result) {
  274. changeList = result;
  275. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  276. changeSpreadObj.makeSjsFooter();
  277. });
  278. }
  279. };
  280. changeSpreadObj.editEnded = function (e, info) {
  281. if (info.sheet.zh_setting) {
  282. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
  283. const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
  284. const col = info.sheet.zh_setting.cols[info.col];
  285. // 未改变值则不提交
  286. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  287. const orgValue = type === 'update' ? select[col.field] : '';
  288. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  289. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  290. return;
  291. }
  292. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  293. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  294. return;
  295. }
  296. // 判断部分值是否输入的是数字判断和数据计算
  297. if (col.type === 'Number') {
  298. if (isNaN(validText)) {
  299. toastr.error('不能输入其它非数字类型字符');
  300. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  301. return;
  302. }
  303. if (col.field === 'unit_price') {
  304. validText = ZhCalc.round(validText, unitPriceUnit);
  305. } else {
  306. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  307. }
  308. }
  309. if (col.field === 'unit') {
  310. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  311. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  312. }
  313. select[col.field] = validText;
  314. console.log(select, type);
  315. delete select.waitingLoading;
  316. // 更新至服务器
  317. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  318. if(type === 'update') {
  319. changeList.splice(info.row, 1, select);
  320. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  321. changeSpreadObj.countSum();
  322. } else {
  323. changeList.push(result);
  324. changeSpreadSheet.addRows(changeList.length - 1, 1);
  325. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  326. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  327. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  328. }
  329. }, function () {
  330. select[col.field] = orgValue;
  331. if(col.field === 'camount') {
  332. select.spamount = orgValue;
  333. }
  334. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  335. });
  336. }
  337. };
  338. changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
  339. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  340. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  341. }
  342. const hint = {
  343. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  344. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  345. };
  346. if (info.sheet.zh_setting) {
  347. const sortData = info.sheet.zh_data || [];
  348. const range = info.cellRange;
  349. const data = [];
  350. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  351. let bPaste = true;
  352. const curRow = range.row + iRow;
  353. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  354. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  355. const hintRow = range.rowCount > 1 ? curRow : '';
  356. let sameCol = 0;
  357. for (let iCol = 0; iCol < range.colCount; iCol++) {
  358. const curCol = range.col + iCol;
  359. const colSetting = info.sheet.zh_setting.cols[curCol];
  360. if (!colSetting) continue;
  361. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  362. let validText = info.sheet.getText(curRow, curCol);
  363. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  364. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  365. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  366. sameCol++;
  367. if (range.colCount === sameCol) {
  368. bPaste = false;
  369. }
  370. continue;
  371. }
  372. if (colSetting.type === 'Number') {
  373. if (isNaN(validText)) {
  374. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  375. toastMessageUniq(hint.numberExpr);
  376. bPaste = false;
  377. continue;
  378. }
  379. if (colSetting.field === 'unit_price') {
  380. validText = ZhCalc.round(validText, unitPriceUnit);
  381. } else {
  382. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  383. }
  384. }
  385. let unitdecimal = validText;
  386. if (colSetting.field === 'unit') {
  387. //粘贴内容要为下拉列表里所有的单位,不然为空
  388. if (changeUnits.indexOf(validText) === -1) {
  389. unitdecimal = '';
  390. // validText = null;
  391. }
  392. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  393. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  394. }
  395. cLData[colSetting.field] = validText;
  396. }
  397. if (bPaste) {
  398. delete cLData.oa_tp;
  399. delete cLData.ca_tp;
  400. data.push(cLData);
  401. // rowData.push(curRow);
  402. } else {
  403. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  404. }
  405. }
  406. if (data.length === 0) {
  407. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  408. return;
  409. }
  410. console.log(data);
  411. // 更新至服务器
  412. postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  413. changeList = result;
  414. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  415. changeSpreadObj.makeSjsFooter();
  416. }, function () {
  417. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  418. return;
  419. });
  420. }
  421. };
  422. changeSpreadObj.updateOamount = function () {
  423. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  424. console.log(changeSpreadSheet);
  425. const index = changeList.indexOf(select);
  426. if (index > -1) {
  427. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  428. const source = _.find(dataSource, function (item) {
  429. if (item.b_code === select.code && item.name === select.name) {
  430. if (listRule.rule.length > 0) {
  431. for(const r of listRule.rule) {
  432. if (item[r] !== select[r]) {
  433. return false;
  434. }
  435. }
  436. }
  437. return true;
  438. }
  439. return false;
  440. });
  441. if (source && source.quantity !== select.oamount) {
  442. select.oamount = source.quantity;
  443. delete select.waitingLoading;
  444. console.log(select);
  445. // 更新至服务器
  446. postData(preUrl + '/list/save', { type:'update', updateData: select }, function (result) {
  447. changeList.splice(index, 1, select);
  448. SpreadJsObj.reLoadRowData(changeSpreadSheet, index);
  449. changeSpreadObj.countSum();
  450. }, function () {
  451. SpreadJsObj.reLoadRowData(changeSpreadSheet, index);
  452. });
  453. }
  454. }
  455. };
  456. // changeSpread.bind(spreadNS.Events.CellChanged, changeSpreadObj.cellChanged);
  457. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  458. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  459. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  460. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  461. // 右键菜单
  462. $.contextMenu({
  463. selector: '#apply-spread',
  464. build: function ($trigger, e) {
  465. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  466. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  467. },
  468. items: {
  469. 'updateOamount': {
  470. name: '原设计数量读取',
  471. icon: '',
  472. callback: function (key, opt) {
  473. changeSpreadObj.updateOamount(changeSpreadSheet);
  474. },
  475. disabled: function (key, opt) {
  476. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  477. const sel = changeSpreadSheet.getSelections()[0];
  478. // console.log(select, sel);
  479. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  480. return false;
  481. } else {
  482. return true;
  483. }
  484. }
  485. },
  486. sprDel: '------------',
  487. 'delete': {
  488. name: '删除',
  489. icon: 'fa-remove',
  490. callback: function (key, opt) {
  491. changeSpreadObj.del(changeSpreadSheet);
  492. },
  493. disabled: function (key, opt) {
  494. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  495. if (changeSpreadSheet.zh_data) {
  496. const selection = changeSpreadSheet.getSelections();
  497. return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  498. } else {
  499. return true;
  500. }
  501. // const sel = changeSpreadSheet.getSelections()[0];
  502. // // console.log(select, sel);
  503. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  504. // return false;
  505. // } else {
  506. // return true;
  507. // }
  508. }
  509. },
  510. }
  511. });
  512. $('#shuliangguize').on('show.bs.modal', function () {
  513. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  514. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  515. for(const r of listRule.rule) {
  516. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  517. }
  518. });
  519. // 设置原设计数量读取
  520. $('#setListRule').click(function () {
  521. const rule = [];
  522. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  523. rule.push($(this).val());
  524. });
  525. const newListRule = {
  526. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  527. rule,
  528. };
  529. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  530. listRule = newListRule;
  531. $('#shuliangguize').modal('hide');
  532. });
  533. })
  534. }
  535. let changeListData;
  536. let gclGatherData;
  537. let dealBillList;
  538. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  539. postData(billUrl + '/defaultBills', {}, function (result) {
  540. gclGatherModel.loadLedgerData(result.bills);
  541. gclGatherModel.loadPosData(result.pos);
  542. gclGatherData = gclGatherModel.gatherGclData();
  543. gclGatherData = _.filter(gclGatherData, function (item) {
  544. return item.leafXmjs && item.leafXmjs.length !== 0;
  545. });
  546. // 数组去重
  547. dealBillList = result.dealBills;
  548. changeListData = gclGatherData;
  549. console.log(changeListData, dealBillList);
  550. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  551. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  552. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  553. changeSpreadObj.makeSjsFooter();
  554. });
  555. });
  556. /**
  557. * 校验文件大小、格式
  558. * @param {Array} files 文件数组
  559. */
  560. function validateFiles(files) {
  561. if (files.length > 10) {
  562. toastr.error('至多同时上传10个文件');
  563. return false
  564. }
  565. return files.every(file => {
  566. if (file.size > 1024 * 1024 * 30) {
  567. toastr.error('文件大小限制为30MB');
  568. return false
  569. }
  570. if (whiteList.indexOf('.' + file.ext) === -1) {
  571. toastr.error('请上传正确的格式文件');
  572. return false
  573. }
  574. return true
  575. })
  576. }
  577. function findDecimal(unit) {
  578. let value = precision.other.value;
  579. const changeUnits = precision;
  580. for (const d in changeUnits) {
  581. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  582. value = changeUnits[d].value;
  583. break;
  584. }
  585. }
  586. return value;
  587. }
  588. const is_numeric = (value) => {
  589. if (typeof(value) === 'object') {
  590. return false;
  591. } else {
  592. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  593. }
  594. };