change_plan_information.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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: 'code', hAlign: 0, width: 110, formatter: '@', readOnly: 'readOnly.isEdit'},
  173. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 130, formatter: '@', readOnly: 'readOnly.isEdit'},
  174. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: 'readOnly.isEdit', cellType: 'unit', comboItems: changeUnits, comboEdit: true},
  175. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.unit_price'},
  176. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.oamount'},
  177. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.oa_tp'},
  178. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', readOnly: 'readOnly.isEdit', getValue: 'getValue.camount'},
  179. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.ca_tp'},
  180. ],
  181. emptyRows: !readOnly ? 3 : 0,
  182. headRows: 2,
  183. headRowHeight: [25, 25],
  184. defaultRowHeight: 21,
  185. headerFont: '12px 微软雅黑',
  186. font: '12px 微软雅黑',
  187. readOnly: readOnly,
  188. localCache: {
  189. key: 'changes-plan-list-spread',
  190. colWidth: true,
  191. }
  192. };
  193. const changeCol = {
  194. getValue: {
  195. unit_price: function(data) {
  196. return ZhCalc.round(data.unit_price, unitPriceUnit);
  197. },
  198. oa_tp: function (data) {
  199. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  200. },
  201. ca_tp: function (data) {
  202. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  203. },
  204. oamount: function (data) {
  205. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  206. },
  207. camount: function (data) {
  208. return ZhCalc.round(data.camount, findDecimal(data.unit));
  209. },
  210. },
  211. readOnly: {
  212. isEdit: function (data) {
  213. return readOnly;
  214. },
  215. },
  216. };
  217. const changeSpreadObj = {
  218. makeSjsFooter: function () {
  219. // 增加汇总行并设为锁定禁止编辑状态
  220. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  221. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  222. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  223. changeSpreadObj.countSum();
  224. },
  225. countSum: function() {
  226. const rowCount = changeSpreadSheet.getRowCount();
  227. let oSum = 0,
  228. cSum = 0;
  229. for(var i = 0; i < rowCount - 1; i++){
  230. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 5));
  231. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 7));
  232. }
  233. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 5, oSum !== 0 ? oSum : null);
  234. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
  235. },
  236. add: function () {
  237. postData(preUrl + '/list/save', {type: 'add'}, function (result) {
  238. if (result) {
  239. changeList.push(result);
  240. changeSpreadSheet.addRows(changeList.length - 1, 1);
  241. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  242. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  243. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  244. // $('#plan-spread').css('height', `${21*changeList + 100}px`);
  245. }
  246. });
  247. },
  248. batchAdd: function(num) {
  249. postData(preUrl + '/list/save', {type: 'batchadd', num}, function (result) {
  250. if (result) {
  251. changeList = _.concat(changeList, result);
  252. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  253. changeSpreadObj.makeSjsFooter();
  254. }
  255. });
  256. },
  257. del: function () {
  258. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  259. const index = changeList.indexOf(select);
  260. if (index > -1) {
  261. postData(preUrl + '/list/save', {type: 'del', id: select.id}, function (result) {
  262. changeList.splice(index, 1);
  263. changeSpreadSheet.deleteRows(index, 1);
  264. const sel = changeSpreadSheet.getSelections();
  265. changeSpreadSheet.setSelection(0, 0, 1, 1);
  266. changeSpreadObj.countSum();
  267. });
  268. }
  269. },
  270. selectionChanged: function (e, info) {
  271. // const sel = info.sheet.getSelections()[0];
  272. // const col = info.sheet.zh_setting.cols[sel.col];
  273. // // const data = SpreadJsObj.getSelectObject(info.sheet);
  274. // if (col && col.field === 'del_list') {
  275. // changeSpreadObj.del();
  276. // }
  277. },
  278. deletePress: function (sheet) {
  279. return;
  280. },
  281. editEnded: function (e, info) {
  282. if (info.sheet.zh_setting) {
  283. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
  284. const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
  285. const col = info.sheet.zh_setting.cols[info.col];
  286. // 未改变值则不提交
  287. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  288. const orgValue = type === 'update' ? select[col.field] : '';
  289. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  290. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  291. return;
  292. }
  293. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  294. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  295. return;
  296. }
  297. // 判断部分值是否输入的是数字判断和数据计算
  298. if (col.type === 'Number') {
  299. if (isNaN(validText)) {
  300. toastr.error('不能输入其它非数字类型字符');
  301. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  302. return;
  303. }
  304. if (col.field === 'unit_price') {
  305. validText = ZhCalc.round(validText, unitPriceUnit);
  306. } else {
  307. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  308. }
  309. }
  310. if (col.field === 'unit') {
  311. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  312. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  313. }
  314. if(col.field === 'camount') {
  315. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  316. }
  317. select[col.field] = validText;
  318. console.log(select, type);
  319. delete select.waitingLoading;
  320. // 更新至服务器
  321. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  322. if(type === 'update') {
  323. changeList.splice(info.row, 1, select);
  324. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  325. changeSpreadObj.countSum();
  326. } else {
  327. changeList.push(result);
  328. changeSpreadSheet.addRows(changeList.length - 1, 1);
  329. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  330. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  331. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  332. }
  333. }, function () {
  334. select[col.field] = orgValue;
  335. if(col.field === 'camount') {
  336. select.spamount = orgValue;
  337. }
  338. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  339. });
  340. }
  341. },
  342. clipboardPasted(e, info) {
  343. const hint = {
  344. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  345. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  346. };
  347. if (info.sheet.zh_setting) {
  348. const sortData = info.sheet.zh_data || [];
  349. const range = info.cellRange;
  350. const data = [];
  351. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  352. // toastMessageUniq(hint.cellError);
  353. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  354. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  355. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  356. // changeSpreadObj.makeSjsFooter();
  357. // return;
  358. // }
  359. // if (sortData.length > 0 && range.col + range.colCount > 8) {
  360. // toastMessageUniq(hint.cellError);
  361. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  362. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  363. // changeSpreadObj.makeSjsFooter();
  364. // return;
  365. // }
  366. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  367. let bPaste = true;
  368. const curRow = range.row + iRow;
  369. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  370. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  371. const hintRow = range.rowCount > 1 ? curRow : '';
  372. let sameCol = 0;
  373. for (let iCol = 0; iCol < range.colCount; iCol++) {
  374. const curCol = range.col + iCol;
  375. const colSetting = info.sheet.zh_setting.cols[curCol];
  376. if (!colSetting) continue;
  377. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  378. let validText = info.sheet.getText(curRow, curCol);
  379. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  380. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  381. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  382. sameCol++;
  383. if (range.colCount === sameCol) {
  384. bPaste = false;
  385. }
  386. continue;
  387. }
  388. if (colSetting.type === 'Number') {
  389. if (isNaN(validText)) {
  390. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  391. toastMessageUniq(hint.numberExpr);
  392. bPaste = false;
  393. continue;
  394. }
  395. if (colSetting.field === 'unit_price') {
  396. validText = ZhCalc.round(validText, unitPriceUnit);
  397. } else {
  398. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  399. }
  400. }
  401. let unitdecimal = validText;
  402. if (colSetting.field === 'unit') {
  403. //粘贴内容要为下拉列表里所有的单位,不然为空
  404. if (changeUnits.indexOf(validText) === -1) {
  405. unitdecimal = '';
  406. }
  407. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  408. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  409. cLData.spamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  410. }
  411. // sortData[curRow][colSetting.field] = validText;
  412. if (colSetting.type === 'camount') {
  413. cLData.spamount = ZhCalc.round(validText, findDecimal(unitdecimal)) || 0;
  414. }
  415. cLData[colSetting.field] = validText;
  416. }
  417. if (bPaste) {
  418. data.push(cLData);
  419. // rowData.push(curRow);
  420. } else {
  421. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  422. }
  423. }
  424. if (data.length === 0) {
  425. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  426. return;
  427. }
  428. console.log(data);
  429. // 更新至服务器
  430. // postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  431. // changeList = result;
  432. // SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  433. // changeSpreadObj.makeSjsFooter();
  434. // }, function () {
  435. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  436. // return;
  437. // });
  438. }
  439. },
  440. valueChanged(e, info) {
  441. // 防止ctrl+z撤销数据
  442. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  443. },
  444. updateOamount: function () {
  445. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  446. console.log(changeSpreadSheet);
  447. const index = changeList.indexOf(select);
  448. if (index > -1) {
  449. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  450. const source = _.find(dataSource, function (item) {
  451. if (item.b_code === select.code && item.name === select.name) {
  452. if (listRule.rule.length > 0) {
  453. for(const r of listRule.rule) {
  454. if (item[r] !== select[r]) {
  455. return false;
  456. }
  457. }
  458. }
  459. return true;
  460. }
  461. return false;
  462. });
  463. if (source && source.quantity !== select.oamount) {
  464. select.oamount = source.quantity;
  465. delete select.waitingLoading;
  466. console.log(select);
  467. // 更新至服务器
  468. postData(preUrl + '/list/save', { type:'update', updateData: select }, function (result) {
  469. changeList.splice(index, 1, select);
  470. SpreadJsObj.reLoadRowData(changeSpreadSheet, index);
  471. changeSpreadObj.countSum();
  472. }, function () {
  473. SpreadJsObj.reLoadRowData(changeSpreadSheet, index);
  474. });
  475. }
  476. }
  477. },
  478. };
  479. let changeListData;
  480. let gclGatherData;
  481. let dealBillList;
  482. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  483. postData(billUrl + '/defaultBills', {}, function (result) {
  484. gclGatherModel.loadLedgerData(result.bills);
  485. gclGatherModel.loadPosData(result.pos);
  486. gclGatherData = gclGatherModel.gatherGclData();
  487. gclGatherData = _.filter(gclGatherData, function (item) {
  488. return item.leafXmjs && item.leafXmjs.length !== 0;
  489. });
  490. // 数组去重
  491. dealBillList = result.dealBills;
  492. // for (const db of gclGatherData) {
  493. // const exist_index = dealBillList.findIndex(function (item) {
  494. // return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  495. // });
  496. // if (exist_index !== -1) {
  497. // dealBillList.splice(exist_index, 1);
  498. // }
  499. // }
  500. // changeListData = gclGatherData.concat(dealBillList);
  501. changeListData = gclGatherData;
  502. console.log(changeListData, dealBillList);
  503. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  504. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  505. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  506. changeSpreadObj.makeSjsFooter();
  507. });
  508. if (!readOnly) {
  509. $('#add-white-btn').click(changeSpreadObj.add);
  510. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  511. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  512. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  513. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  514. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  515. // 右键菜单
  516. $.contextMenu({
  517. selector: '#plan-spread',
  518. build: function ($trigger, e) {
  519. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  520. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  521. },
  522. items: {
  523. 'updateOamount': {
  524. name: '原设计数量读取',
  525. icon: '',
  526. callback: function (key, opt) {
  527. changeSpreadObj.updateOamount(changeSpreadSheet);
  528. },
  529. disabled: function (key, opt) {
  530. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  531. const sel = changeSpreadSheet.getSelections()[0];
  532. // console.log(select, sel);
  533. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  534. return false;
  535. } else {
  536. return true;
  537. }
  538. }
  539. },
  540. sprDel: '------------',
  541. 'delete': {
  542. name: '删除',
  543. icon: 'fa-remove',
  544. callback: function (key, opt) {
  545. changeSpreadObj.del(changeSpreadSheet);
  546. },
  547. disabled: function (key, opt) {
  548. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  549. const sel = changeSpreadSheet.getSelections()[0];
  550. // console.log(select, sel);
  551. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  552. return false;
  553. } else {
  554. return true;
  555. }
  556. }
  557. },
  558. }
  559. });
  560. $('#shuliangguize').on('show.bs.modal', function () {
  561. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  562. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  563. for(const r of listRule.rule) {
  564. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  565. }
  566. });
  567. // 设置原设计数量读取
  568. $('#setListRule').click(function () {
  569. const rule = [];
  570. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  571. rule.push($(this).val());
  572. });
  573. const newListRule = {
  574. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  575. rule,
  576. };
  577. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  578. listRule = newListRule;
  579. $('#shuliangguize').modal('hide');
  580. });
  581. })
  582. }
  583. });
  584. /**
  585. * 校验文件大小、格式
  586. * @param {Array} files 文件数组
  587. */
  588. function validateFiles(files) {
  589. if (files.length > 10) {
  590. toastr.error('至多同时上传10个文件');
  591. return false
  592. }
  593. return files.every(file => {
  594. if (file.size > 1024 * 1024 * 30) {
  595. toastr.error('文件大小限制为30MB');
  596. return false
  597. }
  598. if (whiteList.indexOf('.' + file.ext) === -1) {
  599. toastr.error('请上传正确的格式文件');
  600. return false
  601. }
  602. return true
  603. })
  604. }
  605. function findDecimal(unit) {
  606. let value = precision.other.value;
  607. const changeUnits = precision;
  608. for (const d in changeUnits) {
  609. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  610. value = changeUnits[d].value;
  611. break;
  612. }
  613. }
  614. return value;
  615. }
  616. const is_numeric = (value) => {
  617. if (typeof(value) === 'object') {
  618. return false;
  619. } else {
  620. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  621. }
  622. };