change_information_approval.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. 'use strict';
  2. /**
  3. * 变更令详细页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. function getPasteHint (str, row = '') {
  10. let returnObj = str;
  11. if (row) {
  12. returnObj.msg = '清单第' + (row+1) + '行' + str.msg;
  13. }
  14. return returnObj;
  15. }
  16. $(document).ready(() => {
  17. const changeSpreadSetting = {
  18. cols: [
  19. {title: '清单编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 80, formatter: '@', readOnly: true},
  20. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  21. {title: '变更部位', colSpan: '1', rowSpan: '2', field: 'bwmx', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  22. {title: '变更详情', colSpan: '1', rowSpan: '2', field: 'detail', hAlign: 0, width: 120, formatter: '@', readOnly: true},
  23. {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 60, formatter: '@', readOnly: true},
  24. {title: '单价', colSpan: '1', rowSpan: '2', field: 'unit_price', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.unit_price', readOnly: true},
  25. {title: '原设计|数量', colSpan: '2|1', rowSpan: '1|1', field: 'oamount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.oamount', readOnly: true},
  26. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'oa_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.oa_tp', readOnly: true},
  27. {title: '申请变更增(+)减(-)|数量', colSpan: '2|1', rowSpan: '1|1', field: 'camount', hAlign: 2, width: 60, type: 'Number', getValue: 'getValue.camount', readOnly: true},
  28. {title: '|金额', colSpan: '|1', rowSpan: '|1', field: 'ca_tp', hAlign: 2, width: 80, type: 'Number', getValue: 'getValue.ca_tp', readOnly: true},
  29. ],
  30. emptyRows: 0,
  31. headRows: 2,
  32. headRowHeight: [25, 25],
  33. defaultRowHeight: 21,
  34. headerFont: '12px 微软雅黑',
  35. font: '12px 微软雅黑',
  36. // readOnly: true,
  37. rowHeader:[
  38. {
  39. rowHeaderType: 'circle',
  40. setting: {
  41. size: 5,
  42. indent: 16,
  43. getColor: function (index, data) {
  44. if (!data) return;
  45. if (_.findIndex(changeLedgerList, { id: data.gcl_id }) !== -1 || _.findIndex(changePosList, { id: data.mx_id }) !== -1) {
  46. return '#dc3545';
  47. }
  48. if(data.lid != 0) return;
  49. return '#007bff';
  50. }
  51. },
  52. },
  53. ],
  54. localCache: {
  55. key: 'changes-spread',
  56. colWidth: true,
  57. }
  58. };
  59. for (const aid of aidList) {
  60. const userinfo = _.find(auditList2, { 'uid': aid });
  61. const newColcount = {
  62. title: userinfo.name + ' 审批|数量',
  63. colSpan: '2|1', rowSpan: '1|1',
  64. field: 'audit_amount_' + aid,
  65. hAlign: 2, width: 60, type: 'Number',
  66. readOnly: aid !== parseInt(accountId)
  67. };
  68. const newColTp = {
  69. title: '|金额',
  70. colSpan: '|1', rowSpan: '|1',
  71. field: 'sa_tp',
  72. hAlign: 2, width: 80, type: 'Number',
  73. readOnly: true
  74. };
  75. changeSpreadSetting.cols.push(newColcount);
  76. changeSpreadSetting.cols.push(newColTp);
  77. }
  78. const changeCol = {
  79. getValue: {
  80. unit_price: function(data) {
  81. return ZhCalc.round(data.unit_price, unitPriceUnit);
  82. },
  83. oa_tp: function (data) {
  84. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.oamount), totalPriceUnit);
  85. },
  86. ca_tp: function (data) {
  87. return ZhCalc.round(ZhCalc.mul(data.unit_price, data.camount), totalPriceUnit);
  88. },
  89. oamount: function (data) {
  90. return ZhCalc.round(data.oamount, findDecimal(data.unit));
  91. },
  92. camount: function (data) {
  93. return ZhCalc.round(data.camount, findDecimal(data.unit));
  94. },
  95. },
  96. };
  97. const changeSpreadObj = {
  98. makeSjsFooter: function () {
  99. // 增加汇总行并设为锁定禁止编辑状态
  100. changeSpreadSheet.addRows(changeSpreadSheet.getRowCount(), 1);
  101. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 0, '合计');
  102. changeSpreadSheet.setStyle(changeSpreadSheet.getRowCount() - 1, -1, style1);
  103. changeSpreadObj.countSum();
  104. },
  105. setAuditValue: function () {
  106. const rowCount = changeSpreadSheet.getRowCount();
  107. // 用户的数据合计
  108. for (const j in aidList) {
  109. for(let i = 0; i <= rowCount - 1; i++){
  110. const data = {
  111. unit_price: changeSpreadSheet.getValue(i, 5),
  112. amount: parseFloat(changeSpreadSheet.getValue(i, 10 + parseInt(j)*2)),
  113. };
  114. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  115. changeSpreadSheet.setValue(i, 11 + j*2, sum !== 0 ? sum : null);
  116. }
  117. }
  118. },
  119. resetXmjSpread: function(data = null) {
  120. const xmj = [];
  121. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  122. if (data.bwmx === data.xmj_jldy) {
  123. data.bwmx = '';
  124. }
  125. xmj.push(data);
  126. }
  127. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  128. },
  129. selectionChanged: function (e, info) {
  130. const data = SpreadJsObj.getSelectObject(info.sheet);
  131. changeSpreadObj.resetXmjSpread(data);
  132. },
  133. setRowValueAndSum: function (data, row, col) {
  134. for (const j in aidList) {
  135. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
  136. changeSpreadSheet.setValue(row, 11 + j*2, sum !== 0 ? sum : null);
  137. }
  138. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
  139. // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
  140. const rowCount = changeSpreadSheet.getRowCount();
  141. // 用户的数据合计
  142. let audit_sum = 0;
  143. for(let i = 0; i < rowCount - 1; i++){
  144. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
  145. }
  146. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
  147. },
  148. countSum: function() {
  149. const rowCount = changeSpreadSheet.getRowCount();
  150. let oSum = 0,
  151. cSum = 0;
  152. for(let i = 0; i < rowCount - 1; i++){
  153. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  154. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  155. }
  156. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  157. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  158. // 用户的数据合计
  159. for (const j in aidList) {
  160. let audit_sum = 0;
  161. for(let i = 0; i < rowCount - 1; i++){
  162. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 11 + j*2));
  163. }
  164. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11 + j*2, audit_sum !== 0 ? audit_sum : null);
  165. }
  166. },
  167. deletePress: function (sheet) {
  168. return;
  169. },
  170. editEnded: function (e, info) {
  171. if (info.sheet.zh_setting) {
  172. const select = SpreadJsObj.getSelectObject(info.sheet);
  173. const col = info.sheet.zh_setting.cols[info.col];
  174. // 未改变值则不提交
  175. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  176. const orgValue = select[col.field];
  177. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  178. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  179. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  180. return;
  181. }
  182. // 判断部分值是否输入的是数字判断和数据计算
  183. if (col.type === 'Number') {
  184. if (isNaN(validText)) {
  185. toastr.error('不能输入其它非数字类型字符');
  186. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  187. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  188. return;
  189. }
  190. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  191. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  192. const usedInfo = _.find(changeUsedData, { id: select.id });
  193. if (usedInfo && validText >= 0 && validText < usedInfo.used_qty) {
  194. toastr.error('清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  195. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  196. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  197. return;
  198. } else if (usedInfo && validText < 0 && validText > usedInfo.used_qty) {
  199. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  200. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  201. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  202. return;
  203. }
  204. }
  205. select[col.field] = validText;
  206. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  207. const data = {
  208. id: select.id,
  209. spamount: select.spamount,
  210. };
  211. console.log(data);
  212. // 更新至服务器
  213. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  214. changeList.splice(info.row, 1, select);
  215. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  216. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  217. }, function () {
  218. select[col.field] = orgValue;
  219. select.spamount = orgValue;
  220. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  221. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  222. });
  223. }
  224. },
  225. clipboardPasted(e, info) {
  226. const hint = {
  227. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  228. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  229. qtyError: {type: 'error', msg: '变更数值必须大于等于已调用值'},
  230. };
  231. const range = info.cellRange;
  232. const sortData = info.sheet.zh_data || [];
  233. // console.log(info, range);
  234. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  235. // toastMessageUniq(hint.cellError);
  236. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  237. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  238. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  239. // changeSpreadObj.setAuditValue();
  240. // changeSpreadObj.makeSjsFooter();
  241. // return;
  242. // }
  243. // if (sortData.length > 0 && range.col + range.colCount > 10) {
  244. // toastMessageUniq(hint.cellError);
  245. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  246. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  247. // changeSpreadObj.setAuditValue();
  248. // changeSpreadObj.makeSjsFooter();
  249. // return;
  250. // }
  251. const data = [];
  252. // const rowData = [];
  253. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  254. let bPaste = true;
  255. const curRow = range.row + iRow;
  256. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  257. const cLData = { id: sortData[curRow].id };
  258. const hintRow = range.rowCount > 1 ? curRow : '';
  259. let sameCol = 0;
  260. for (let iCol = 0; iCol < range.colCount; iCol++) {
  261. const curCol = range.col + iCol;
  262. const colSetting = info.sheet.zh_setting.cols[curCol];
  263. if (!colSetting) continue;
  264. let validText = info.sheet.getText(curRow, curCol);
  265. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  266. const orgValue = sortData[curRow][colSetting.field];
  267. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  268. sameCol++;
  269. if (range.colCount === sameCol) {
  270. bPaste = false;
  271. }
  272. continue;
  273. }
  274. if (colSetting.type === 'Number') {
  275. if (isNaN(validText)) {
  276. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  277. bPaste = false;
  278. continue;
  279. }
  280. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  281. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  282. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  283. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  284. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  285. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  286. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  287. bPaste = false;
  288. continue;
  289. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  290. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  291. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  292. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  293. bPaste = false;
  294. continue;
  295. }
  296. }
  297. // cLData[colSetting.field] = validText;
  298. sortData[curRow][colSetting.field] = validText;
  299. cLData.spamount = validText;
  300. }
  301. if (bPaste) {
  302. data.push(cLData);
  303. // rowData.push(curRow);
  304. } else {
  305. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  306. }
  307. }
  308. if (data.length === 0) {
  309. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  310. return;
  311. }
  312. console.log(data);
  313. // 更新至服务器
  314. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  315. changeList = result;
  316. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  317. changeSpreadObj.setAuditValue();
  318. changeSpreadObj.makeSjsFooter();
  319. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  320. }, function () {
  321. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  322. changeSpreadObj.setAuditValue();
  323. return;
  324. });
  325. },
  326. };
  327. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  328. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  329. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  330. changeSpreadObj.setAuditValue();
  331. changeSpreadObj.makeSjsFooter();
  332. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  333. const userIndex = aidList.indexOf(parseInt(accountId));
  334. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  335. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  336. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  337. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  338. // 审批提交与判断
  339. $('.approval-btn').on('click', function () {
  340. // 判断审批状态
  341. let returnflag = true;
  342. if ($(this).hasClass('btn-success')) {
  343. const sdesc = $('#success-approval').find('textarea').val();
  344. if (sdesc === '') {
  345. toastr.error('审批意见不能为空!');
  346. returnflag = false;
  347. }
  348. if ($('input[name="p_code"]').val() === '') {
  349. toastr.error('变更令号(批复编号)不能为空!');
  350. returnflag = false;
  351. } else if ($('input[name="p_code"]').val() !== undefined) {
  352. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  353. const postData = {
  354. p_code: $('input[name="p_code"]').val(),
  355. };
  356. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  357. }, function (data) {
  358. returnflag = false;
  359. });
  360. }
  361. // 判断并提交变更清单表格数据到表单中
  362. const clist = [];
  363. for(const [i,cl] of changeList.entries()) {
  364. if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') {
  365. toastr.error('清单第' + (i+1) + '行审批变更数量不能为空');
  366. returnflag = false;
  367. } else {
  368. clist.push(cl.id + '_' + cl['audit_amount_' + accountId]);
  369. }
  370. }
  371. $('#change-list-approval').val(clist.join(','));
  372. if(returnflag) {
  373. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  374. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  375. if ($('#warning-text').length) $('#warning-text').remove()
  376. $('#success-approval').submit();
  377. }
  378. } else {
  379. const sdesc = $('#fail-approval').find('textarea').val();
  380. if (sdesc === '') {
  381. toastr.error('审批意见不能为空!');
  382. returnflag = false;
  383. }
  384. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  385. if (type === undefined) {
  386. // toastr.error('请选择退回类型!');
  387. if (!$('#warning-text').length) {
  388. $('#change-back-content').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  389. }
  390. returnflag = false;
  391. }
  392. if(returnflag) {
  393. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  394. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  395. $('#fail-approval').submit();
  396. }
  397. }
  398. })
  399. });
  400. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  401. if (showWaiting) showWaitingView();
  402. $.ajax({
  403. type:"POST",
  404. url: url,
  405. data: {'data': JSON.stringify(data)},
  406. dataType: 'json',
  407. cache: false,
  408. async: false,
  409. timeout: 60000,
  410. beforeSend: function(xhr) {
  411. let csrfToken = Cookies.get('csrfToken_j');
  412. xhr.setRequestHeader('x-csrf-token', csrfToken);
  413. },
  414. success: function(result){
  415. if (result.err === 0) {
  416. if (successCallback) {
  417. successCallback(result.data);
  418. }
  419. } else {
  420. toastr.error(result.msg);
  421. if (errorCallBack) {
  422. errorCallBack(result.msg);
  423. }
  424. }
  425. if (showWaiting) closeWaitingView();
  426. },
  427. error: function(jqXHR, textStatus, errorThrown){
  428. toastr.error('error: ' + textStatus + " " + errorThrown);
  429. if (errorCallBack) {
  430. errorCallBack();
  431. }
  432. if (showWaiting) closeWaitingView();
  433. }
  434. });
  435. };
  436. function auditCheck(i) {
  437. const inlineRadio1 = $('#change-back:checked').val()
  438. const inlineRadio2 = $('#chagne-backnew:checked').val()
  439. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  440. $('textarea[name="sdesc"]').eq(i).val(opinion);
  441. if (i === 1) {
  442. if (!inlineRadio1 && !inlineRadio2) {
  443. if (!$('#warning-text').length) {
  444. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  445. }
  446. return false;
  447. }
  448. if ($('#warning-text').length) $('#warning-text').remove()
  449. }
  450. return true;
  451. }