change_plan_information.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. {title: '审批后变更|数量', colSpan: '2|1', rowSpan: '1|1', field: 'samount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.samount'},
  181. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'sa_tp', hAlign: 2, width: 80, type: 'Number', readOnly: true, getValue: 'getValue.sa_tp'},
  182. ],
  183. emptyRows: !readOnly ? 3 : 0,
  184. headRows: 2,
  185. headRowHeight: [25, 25],
  186. defaultRowHeight: 21,
  187. headerFont: '12px 微软雅黑',
  188. font: '12px 微软雅黑',
  189. readOnly: change.status === auditConst.status.checking ? false : readOnly,
  190. localCache: {
  191. key: 'changes-plan-list-spread',
  192. colWidth: true,
  193. }
  194. };
  195. console.log(changeList, change.listAudits);
  196. if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) {
  197. for (const audit of change.listAudits) {
  198. // const userinfo = _.find(auditList2, { 'aid': aid });
  199. const newColcount = {
  200. title: audit.name + ' 审批|数量',
  201. colSpan: '2|1', rowSpan: '1|1',
  202. field: 'audit_amount_' + audit.aid,
  203. hAlign: 2, width: 60, type: 'Number',
  204. readOnly: !(change.shenpiPower && audit.aid === parseInt(cur_uid))
  205. };
  206. const newColTp = {
  207. title: '|金额',
  208. colSpan: '|1', rowSpan: '|1',
  209. field: 'sa_tp_' + audit.aid,
  210. hAlign: 2, width: 80, type: 'Number',
  211. readOnly: true
  212. };
  213. changeSpreadSetting.cols.push(newColcount);
  214. changeSpreadSetting.cols.push(newColTp);
  215. }
  216. }
  217. const changeCol = {
  218. getValue: {
  219. unit_price: function(data) {
  220. return ZhCalc.round(data.unit_price, unitPriceUnit);
  221. },
  222. oa_tp: function (data) {
  223. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  224. },
  225. ca_tp: function (data) {
  226. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  227. },
  228. oamount: function (data) {
  229. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  230. },
  231. camount: function (data) {
  232. return ZhCalc.round(data.camount, findDecimal(data.unit));
  233. },
  234. samount: function (data) {
  235. return ZhCalc.round(data.samount, findDecimal(data.unit));
  236. },
  237. sa_tp: function (data) {
  238. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.samount), totalPriceUnit);
  239. },
  240. },
  241. readOnly: {
  242. isEdit: function (data) {
  243. return readOnly;
  244. },
  245. },
  246. };
  247. const changeSpreadObj = {
  248. makeSjsFooter: function() {
  249. // 增加汇总行并设为锁定禁止编辑状态
  250. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  251. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  252. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  253. changeSpreadObj.countSum();
  254. },
  255. setAuditValue: function () {
  256. for (const c of changeList) {
  257. for (const audit of change.listAudits) {
  258. c['sa_tp_' + audit.aid] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + audit.aid], c.unit_price), totalPriceUnit);
  259. }
  260. }
  261. },
  262. setRowValueAndSum: function (data, row, col) {
  263. for (const j in change.listAudits) {
  264. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
  265. changeSpreadSheet.setValue(row, 11 + j*2, sum !== 0 ? sum : null);
  266. }
  267. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
  268. // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
  269. const rowCount = changeSpreadSheet.getRowCount();
  270. // 用户的数据合计
  271. let audit_sum = 0;
  272. for(let i = 0; i < rowCount - 1; i++){
  273. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
  274. }
  275. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
  276. },
  277. countSum: function() {
  278. const rowCount = changeSpreadSheet.getRowCount();
  279. let oSum = 0,
  280. cSum = 0,
  281. sSum = 0;
  282. for (let i = 0; i < rowCount - 1; i++) {
  283. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 5));
  284. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 7));
  285. sSum = ZhCalc.add(sSum, changeSpreadSheet.getValue(i, 9));
  286. }
  287. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 5, oSum !== 0 ? oSum : null);
  288. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, cSum !== 0 ? cSum : null);
  289. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, sSum !== 0 ? sSum : null);
  290. // 用户的数据合计
  291. for (const j in change.listAudits) {
  292. let audit_sum = 0;
  293. for(let i = 0; i < rowCount - 1; i++){
  294. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 11 + j*2));
  295. }
  296. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11 + j*2, audit_sum !== 0 ? audit_sum : null);
  297. }
  298. },
  299. deletePress: function (sheet) {
  300. return;
  301. },
  302. showHideAudit: function (show = false) {
  303. const count = changeSpreadSetting.cols.length;
  304. for (let i = 10; i < count; i++) {
  305. changeSpreadSheet.setColumnVisible(i, show, GC.Spread.Sheets.SheetArea.viewport);
  306. }
  307. changeSpreadSheet.setColumnVisible(8, !show, GC.Spread.Sheets.SheetArea.viewport);
  308. changeSpreadSheet.setColumnVisible(9, !show, GC.Spread.Sheets.SheetArea.viewport);
  309. },
  310. valueChanged: function (e, info) {
  311. // 防止ctrl+z撤销数据
  312. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  313. }
  314. };
  315. if (!readOnly) {
  316. changeSpreadObj.del = function (sheet) {
  317. const selection = sheet.getSelections();
  318. const row = selection[0].row, count = selection[0].rowCount;
  319. const sortData = sheet.zh_data;
  320. const ids = [];
  321. for (let iRow = 0; iRow < count; iRow++) {
  322. if (sortData[iRow + row]) {
  323. ids.push(sortData[iRow + row].id);
  324. }
  325. }
  326. if (ids.length > 0) {
  327. postData(preUrl + '/list/save', {type: 'del', ids}, function (result) {
  328. changeList = result;
  329. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  330. changeSpreadObj.makeSjsFooter();
  331. });
  332. }
  333. };
  334. changeSpreadObj.editEnded = function (e, info) {
  335. if (info.sheet.zh_setting) {
  336. const type = SpreadJsObj.getSelectObject(info.sheet) ? 'update' : 'add';
  337. const select = type === 'update' ? SpreadJsObj.getSelectObject(info.sheet) : {unit: ''};
  338. const col = info.sheet.zh_setting.cols[info.col];
  339. // 未改变值则不提交
  340. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  341. const orgValue = type === 'update' ? select[col.field] : '';
  342. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  343. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  344. return;
  345. }
  346. if (col.field === 'oa_tp' || col.field === 'ca_tp') {
  347. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  348. return;
  349. }
  350. // 判断部分值是否输入的是数字判断和数据计算
  351. if (col.type === 'Number') {
  352. if (isNaN(validText)) {
  353. toastr.error('不能输入其它非数字类型字符');
  354. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  355. return;
  356. }
  357. if (col.field === 'unit_price') {
  358. validText = ZhCalc.round(validText, unitPriceUnit);
  359. } else {
  360. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  361. }
  362. }
  363. if (col.field === 'unit') {
  364. select.camount = ZhCalc.round(select.camount, findDecimal(validText)) || 0;
  365. select.oamount = ZhCalc.round(select.oamount, findDecimal(validText)) || 0;
  366. }
  367. if(col.field === 'camount') {
  368. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  369. }
  370. select[col.field] = validText;
  371. console.log(select, type);
  372. delete select.waitingLoading;
  373. // 更新至服务器
  374. postData(preUrl + '/list/save', { type, updateData: select }, function (result) {
  375. if(type === 'update') {
  376. changeList.splice(info.row, 1, select);
  377. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  378. changeSpreadObj.countSum();
  379. } else {
  380. changeList.push(result);
  381. changeSpreadSheet.addRows(changeList.length - 1, 1);
  382. SpreadJsObj.reLoadRowData(changeSpreadSheet, changeList.length - 1);
  383. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  384. changeSpreadSheet.setSelection(changeList.length - 1, 0, 1, 1);
  385. }
  386. }, function () {
  387. select[col.field] = orgValue;
  388. if(col.field === 'camount') {
  389. select.spamount = orgValue;
  390. }
  391. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  392. });
  393. }
  394. };
  395. changeSpreadObj.clipboardPasted = function(e, info, cellRange) {
  396. if (info.sheet.getColumnCount() > info.sheet.zh_setting.cols.length) {
  397. info.sheet.setColumnCount(info.sheet.zh_setting.cols.length);
  398. }
  399. const hint = {
  400. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  401. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  402. };
  403. if (info.sheet.zh_setting) {
  404. const sortData = info.sheet.zh_data || [];
  405. const range = info.cellRange;
  406. const data = [];
  407. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  408. let bPaste = true;
  409. const curRow = range.row + iRow;
  410. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  411. const cLData = curRow >= sortData.length ? {unit: ''} : {id: sortData[curRow].id};
  412. const hintRow = range.rowCount > 1 ? curRow : '';
  413. let sameCol = 0;
  414. for (let iCol = 0; iCol < range.colCount; iCol++) {
  415. const curCol = range.col + iCol;
  416. const colSetting = info.sheet.zh_setting.cols[curCol];
  417. if (!colSetting) continue;
  418. // cLData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
  419. let validText = info.sheet.getText(curRow, curCol);
  420. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : '');
  421. const orgValue = curRow >= sortData.length ? '' : sortData[curRow][colSetting.field];
  422. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  423. sameCol++;
  424. if (range.colCount === sameCol) {
  425. bPaste = false;
  426. }
  427. continue;
  428. }
  429. if (colSetting.type === 'Number') {
  430. if (isNaN(validText)) {
  431. // toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  432. toastMessageUniq(hint.numberExpr);
  433. bPaste = false;
  434. continue;
  435. }
  436. if (colSetting.field === 'unit_price') {
  437. validText = ZhCalc.round(validText, unitPriceUnit);
  438. } else {
  439. validText = ZhCalc.round(validText, findDecimal(cLData.unit)) || 0;
  440. }
  441. }
  442. let unitdecimal = validText;
  443. if (colSetting.field === 'unit') {
  444. //粘贴内容要为下拉列表里所有的单位,不然为空
  445. if (changeUnits.indexOf(validText) === -1) {
  446. unitdecimal = '';
  447. // validText = null;
  448. }
  449. cLData.camount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  450. cLData.oamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].oamount, findDecimal(unitdecimal)) || 0;
  451. cLData.spamount = curRow >= sortData.length ? 0 : ZhCalc.round(sortData[curRow].camount, findDecimal(unitdecimal)) || 0;
  452. }
  453. // sortData[curRow][colSetting.field] = validText;
  454. if (colSetting.field === 'camount') {
  455. cLData.spamount = ZhCalc.round(validText, findDecimal(unitdecimal)) || 0;
  456. }
  457. cLData[colSetting.field] = validText;
  458. }
  459. if (bPaste) {
  460. delete cLData.oa_tp;
  461. delete cLData.ca_tp;
  462. data.push(cLData);
  463. // rowData.push(curRow);
  464. } else {
  465. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  466. }
  467. }
  468. if (data.length === 0) {
  469. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  470. return;
  471. }
  472. console.log(data);
  473. // 更新至服务器
  474. postData(preUrl + '/list/save', { type:'paste', updateData: data }, function (result) {
  475. changeList = result;
  476. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  477. changeSpreadObj.makeSjsFooter();
  478. }, function () {
  479. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  480. return;
  481. });
  482. }
  483. };
  484. changeSpreadObj.updateOamount = function () {
  485. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  486. console.log(changeSpreadSheet);
  487. const index = changeList.indexOf(select);
  488. if (index > -1) {
  489. const dataSource = listRule.source === 1 ? gclGatherData : dealBillList;
  490. const source = _.find(dataSource, function (item) {
  491. if (item.b_code === select.code && item.name === select.name) {
  492. if (listRule.rule.length > 0) {
  493. for(const r of listRule.rule) {
  494. if (item[r] !== select[r]) {
  495. return false;
  496. }
  497. }
  498. }
  499. return true;
  500. }
  501. return false;
  502. });
  503. if (source && source.quantity !== select.oamount) {
  504. select.oamount = source.quantity;
  505. delete select.waitingLoading;
  506. console.log(select);
  507. // 更新至服务器
  508. postData(preUrl + '/list/save', { type:'update', updateData: select }, function (result) {
  509. changeList.splice(index, 1, select);
  510. SpreadJsObj.reLoadRowData(changeSpreadSheet, index);
  511. changeSpreadObj.countSum();
  512. }, function () {
  513. SpreadJsObj.reLoadRowData(changeSpreadSheet, index);
  514. });
  515. }
  516. }
  517. };
  518. // changeSpread.bind(spreadNS.Events.CellChanged, changeSpreadObj.cellChanged);
  519. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  520. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  521. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  522. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  523. // 右键菜单
  524. $.contextMenu({
  525. selector: '#plan-spread',
  526. build: function ($trigger, e) {
  527. const target = SpreadJsObj.safeRightClickSelection($trigger, e, changeSpread);
  528. return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
  529. },
  530. items: {
  531. 'updateOamount': {
  532. name: '原设计数量读取',
  533. icon: '',
  534. callback: function (key, opt) {
  535. changeSpreadObj.updateOamount(changeSpreadSheet);
  536. },
  537. disabled: function (key, opt) {
  538. const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  539. const sel = changeSpreadSheet.getSelections()[0];
  540. // console.log(select, sel);
  541. if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  542. return false;
  543. } else {
  544. return true;
  545. }
  546. }
  547. },
  548. sprDel: '------------',
  549. 'delete': {
  550. name: '删除',
  551. icon: 'fa-remove',
  552. callback: function (key, opt) {
  553. changeSpreadObj.del(changeSpreadSheet);
  554. },
  555. disabled: function (key, opt) {
  556. // const select = SpreadJsObj.getSelectObject(changeSpreadSheet);
  557. if (changeSpreadSheet.zh_data) {
  558. const selection = changeSpreadSheet.getSelections();
  559. return changeSpreadSheet.zh_data.length < selection[0].row + selection[0].rowCount;
  560. } else {
  561. return true;
  562. }
  563. // const sel = changeSpreadSheet.getSelections()[0];
  564. // // console.log(select, sel);
  565. // if (!readOnly && select && sel.row !== changeSpreadSheet.getRowCount() - 1) {
  566. // return false;
  567. // } else {
  568. // return true;
  569. // }
  570. }
  571. },
  572. }
  573. });
  574. $('#shuliangguize').on('show.bs.modal', function () {
  575. $('#shuliangguize input[name="data_source"][value="'+ listRule.source +'"]').prop('checked', true);
  576. $('#shuliangguize input[name="data_rule"]').prop('checked', false);
  577. for(const r of listRule.rule) {
  578. $('#shuliangguize input[name="data_rule"][value="' + r +'"]').prop('checked', true);
  579. }
  580. });
  581. // 设置原设计数量读取
  582. $('#setListRule').click(function () {
  583. const rule = [];
  584. $('#shuliangguize input[name="data_rule"]:checked').each(function () {
  585. rule.push($(this).val());
  586. });
  587. const newListRule = {
  588. source: parseInt($('#shuliangguize input[name="data_source"]:checked').val()),
  589. rule,
  590. };
  591. postData(preUrl + '/list/save', { type: 'list_rule', postData: JSON.stringify(newListRule) }, function (result) {
  592. listRule = newListRule;
  593. $('#shuliangguize').modal('hide');
  594. });
  595. })
  596. }
  597. if (change.shenpiPower) {
  598. changeSpreadObj.editEnded = function (e, info) {
  599. if (info.sheet.zh_setting) {
  600. const select = SpreadJsObj.getSelectObject(info.sheet);
  601. const col = info.sheet.zh_setting.cols[info.col];
  602. // 未改变值则不提交
  603. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  604. const orgValue = select[col.field];
  605. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  606. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  607. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  608. return;
  609. }
  610. // 判断部分值是否输入的是数字判断和数据计算
  611. if (col.type === 'Number') {
  612. if (isNaN(validText)) {
  613. toastr.error('不能输入其它非数字类型字符');
  614. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  615. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  616. return;
  617. }
  618. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  619. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  620. }
  621. select[col.field] = validText;
  622. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  623. const data = {
  624. id: select.id,
  625. spamount: select.spamount,
  626. };
  627. console.log(data);
  628. // 更新至服务器
  629. postData(preUrl + '/list/save', { type:'update', updateData: data }, function (result) {
  630. changeList.splice(info.row, 1, select);
  631. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  632. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  633. }, function () {
  634. select[col.field] = orgValue;
  635. select.spamount = orgValue;
  636. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  637. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  638. });
  639. }
  640. };
  641. changeSpreadObj.clipboardPasted = function(e, info) {
  642. const hint = {
  643. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  644. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  645. };
  646. const range = info.cellRange;
  647. const sortData = info.sheet.zh_data || [];
  648. const data = [];
  649. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  650. let bPaste = true;
  651. const curRow = range.row + iRow;
  652. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  653. const cLData = { id: sortData[curRow].id };
  654. const hintRow = range.rowCount > 1 ? curRow : '';
  655. let sameCol = 0;
  656. for (let iCol = 0; iCol < range.colCount; iCol++) {
  657. const curCol = range.col + iCol;
  658. const colSetting = info.sheet.zh_setting.cols[curCol];
  659. if (!colSetting) continue;
  660. let validText = info.sheet.getText(curRow, curCol);
  661. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  662. const orgValue = sortData[curRow][colSetting.field];
  663. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  664. sameCol++;
  665. if (range.colCount === sameCol) {
  666. bPaste = false;
  667. }
  668. continue;
  669. }
  670. if (colSetting.type === 'Number') {
  671. if (isNaN(validText)) {
  672. toastMessageUniq(hint.numberExpr);
  673. bPaste = false;
  674. continue;
  675. }
  676. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  677. }
  678. // cLData[colSetting.field] = validText;
  679. sortData[curRow][colSetting.field] = validText;
  680. cLData.spamount = validText;
  681. }
  682. if (bPaste) {
  683. data.push(cLData);
  684. // rowData.push(curRow);
  685. } else {
  686. changeSpreadObj.setAuditValue();
  687. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  688. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  689. }
  690. }
  691. if (data.length === 0) {
  692. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  693. return;
  694. }
  695. console.log(data);
  696. // 更新至服务器
  697. postData(preUrl + '/list/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  698. changeList = result;
  699. changeSpreadObj.setAuditValue();
  700. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  701. changeSpreadObj.makeSjsFooter();
  702. }, function () {
  703. changeSpreadObj.setAuditValue();
  704. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  705. return;
  706. });
  707. };
  708. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  709. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  710. changeSpread.bind(spreadNS.Events.ValueChanged, changeSpreadObj.valueChanged);
  711. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  712. }
  713. let changeListData;
  714. let gclGatherData;
  715. let dealBillList;
  716. const billUrl = window.location.pathname.split('/').slice(0, 4).join('/');
  717. postData(billUrl + '/defaultBills', {}, function (result) {
  718. gclGatherModel.loadLedgerData(result.bills);
  719. gclGatherModel.loadPosData(result.pos);
  720. gclGatherData = gclGatherModel.gatherGclData();
  721. gclGatherData = _.filter(gclGatherData, function (item) {
  722. return item.leafXmjs && item.leafXmjs.length !== 0;
  723. });
  724. // 数组去重
  725. dealBillList = result.dealBills;
  726. // for (const db of gclGatherData) {
  727. // const exist_index = dealBillList.findIndex(function (item) {
  728. // return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
  729. // });
  730. // if (exist_index !== -1) {
  731. // dealBillList.splice(exist_index, 1);
  732. // }
  733. // }
  734. // changeListData = gclGatherData.concat(dealBillList);
  735. changeListData = gclGatherData;
  736. console.log(changeListData, dealBillList);
  737. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  738. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  739. if (change.status === auditConst.status.checking || change.status === auditConst.status.checked) changeSpreadObj.setAuditValue();
  740. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  741. changeSpreadObj.makeSjsFooter();
  742. if (change.status === auditConst.status.checked) {
  743. changeSpreadObj.showHideAudit(false);
  744. } else {
  745. changeSpreadObj.showHideAudit(true);
  746. }
  747. });
  748. // 审批流程展示与隐藏
  749. $('#show-table-detail').on('click', function (e) {
  750. if($(e.target).is('label')){
  751. return;
  752. }
  753. changeSpreadObj.showHideAudit($(this).is(':checked'));
  754. });
  755. });
  756. /**
  757. * 校验文件大小、格式
  758. * @param {Array} files 文件数组
  759. */
  760. function validateFiles(files) {
  761. if (files.length > 10) {
  762. toastr.error('至多同时上传10个文件');
  763. return false
  764. }
  765. return files.every(file => {
  766. if (file.size > 1024 * 1024 * 30) {
  767. toastr.error('文件大小限制为30MB');
  768. return false
  769. }
  770. if (whiteList.indexOf('.' + file.ext) === -1) {
  771. toastr.error('请上传正确的格式文件');
  772. return false
  773. }
  774. return true
  775. })
  776. }
  777. function findDecimal(unit) {
  778. let value = precision.other.value;
  779. const changeUnits = precision;
  780. for (const d in changeUnits) {
  781. if (changeUnits[d].unit !== undefined && changeUnits[d].unit === unit) {
  782. value = changeUnits[d].value;
  783. break;
  784. }
  785. }
  786. return value;
  787. }
  788. const is_numeric = (value) => {
  789. if (typeof(value) === 'object') {
  790. return false;
  791. } else {
  792. return !Number.isNaN(Number(value)) && value.toString().trim() !== '';
  793. }
  794. };