change_information_approval.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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_' + aid,
  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. for (const c of changeList) {
  107. for (const j of aidList) {
  108. c['sa_tp_' + j] = ZhCalc.round(ZhCalc.mul(c['audit_amount_' + j], c.unit_price), totalPriceUnit);
  109. }
  110. }
  111. // const rowCount = changeSpreadSheet.getRowCount();
  112. // // 用户的数据合计
  113. // for (const j in aidList) {
  114. // for(let i = 0; i <= rowCount - 1; i++){
  115. // const data = {
  116. // unit_price: changeSpreadSheet.getValue(i, 5),
  117. // amount: parseFloat(changeSpreadSheet.getValue(i, 10 + parseInt(j)*2)),
  118. // };
  119. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.amount), totalPriceUnit);
  120. // changeSpreadSheet.setValue(i, 11 + j*2, sum !== 0 ? sum : null);
  121. // }
  122. // }
  123. },
  124. resetXmjSpread: function(data = null) {
  125. const xmj = [];
  126. if (data && data.lid != 0 && data.xmj_code !== '' && data.xmj_code !== null) {
  127. if (data.bwmx === data.xmj_jldy) {
  128. data.bwmx = '';
  129. }
  130. xmj.push(data);
  131. }
  132. SpreadJsObj.loadSheetData(xmjSpread.getActiveSheet(), SpreadJsObj.DataType.Data, xmj);
  133. },
  134. selectionChanged: function (e, info) {
  135. const data = SpreadJsObj.getSelectObject(info.sheet);
  136. changeSpreadObj.resetXmjSpread(data);
  137. },
  138. setRowValueAndSum: function (data, row, col) {
  139. for (const j in aidList) {
  140. const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, parseFloat(changeSpreadSheet.getValue(row, 10 + parseInt(j)*2))), totalPriceUnit);
  141. changeSpreadSheet.setValue(row, 11 + j*2, sum !== 0 ? sum : null);
  142. }
  143. // const sum = ZhCalc.round(ZhCalc.mul(data.unit_price, data.spamount), totalPriceUnit);
  144. // changeSpreadSheet.setValue(row, col+1, sum !== 0 ? sum : null);
  145. const rowCount = changeSpreadSheet.getRowCount();
  146. // 用户的数据合计
  147. let audit_sum = 0;
  148. for(let i = 0; i < rowCount - 1; i++){
  149. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, col+1));
  150. }
  151. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, col+1, audit_sum !== 0 ? audit_sum : null);
  152. },
  153. countSum: function() {
  154. const rowCount = changeSpreadSheet.getRowCount();
  155. let oSum = 0,
  156. cSum = 0;
  157. for(let i = 0; i < rowCount - 1; i++){
  158. oSum = ZhCalc.add(oSum, changeSpreadSheet.getValue(i, 7));
  159. cSum = ZhCalc.add(cSum, changeSpreadSheet.getValue(i, 9));
  160. }
  161. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 7, oSum !== 0 ? oSum : null);
  162. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 9, cSum !== 0 ? cSum : null);
  163. // 用户的数据合计
  164. for (const j in aidList) {
  165. let audit_sum = 0;
  166. for(let i = 0; i < rowCount - 1; i++){
  167. audit_sum = ZhCalc.add(audit_sum, changeSpreadSheet.getValue(i, 11 + j*2));
  168. }
  169. changeSpreadSheet.setValue(changeSpreadSheet.getRowCount() - 1, 11 + j*2, audit_sum !== 0 ? audit_sum : null);
  170. }
  171. },
  172. deletePress: function (sheet) {
  173. return;
  174. },
  175. editEnded: function (e, info) {
  176. if (info.sheet.zh_setting) {
  177. const select = SpreadJsObj.getSelectObject(info.sheet);
  178. const col = info.sheet.zh_setting.cols[info.col];
  179. // 未改变值则不提交
  180. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  181. const orgValue = select[col.field];
  182. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  183. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  184. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  185. return;
  186. }
  187. // 判断部分值是否输入的是数字判断和数据计算
  188. if (col.type === 'Number') {
  189. if (isNaN(validText)) {
  190. toastr.error('不能输入其它非数字类型字符');
  191. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  192. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  193. return;
  194. }
  195. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  196. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  197. const usedInfo = _.find(changeUsedData, { id: select.id });
  198. 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. } else if (usedInfo && validText < 0 && validText > usedInfo.used_qty) {
  204. toastr.error('清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  205. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  206. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  207. return;
  208. }
  209. }
  210. select[col.field] = validText;
  211. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  212. const data = {
  213. id: select.id,
  214. spamount: select.spamount,
  215. };
  216. console.log(data);
  217. // 更新至服务器
  218. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  219. changeList.splice(info.row, 1, select);
  220. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  221. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  222. }, function () {
  223. select[col.field] = orgValue;
  224. select.spamount = orgValue;
  225. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  226. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  227. });
  228. }
  229. },
  230. clipboardPasted(e, info) {
  231. const hint = {
  232. cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  233. numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  234. qtyError: {type: 'error', msg: '变更数值必须大于等于已调用值'},
  235. };
  236. const range = info.cellRange;
  237. const sortData = info.sheet.zh_data || [];
  238. // console.log(info, range);
  239. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  240. // toastMessageUniq(hint.cellError);
  241. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  242. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  243. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  244. // changeSpreadObj.setAuditValue();
  245. // changeSpreadObj.makeSjsFooter();
  246. // return;
  247. // }
  248. // if (sortData.length > 0 && range.col + range.colCount > 10) {
  249. // toastMessageUniq(hint.cellError);
  250. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  251. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  252. // changeSpreadObj.setAuditValue();
  253. // changeSpreadObj.makeSjsFooter();
  254. // return;
  255. // }
  256. const data = [];
  257. // const rowData = [];
  258. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  259. let bPaste = true;
  260. const curRow = range.row + iRow;
  261. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  262. const cLData = { id: sortData[curRow].id };
  263. const hintRow = range.rowCount > 1 ? curRow : '';
  264. let sameCol = 0;
  265. for (let iCol = 0; iCol < range.colCount; iCol++) {
  266. const curCol = range.col + iCol;
  267. const colSetting = info.sheet.zh_setting.cols[curCol];
  268. if (!colSetting) continue;
  269. let validText = info.sheet.getText(curRow, curCol);
  270. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  271. const orgValue = sortData[curRow][colSetting.field];
  272. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  273. sameCol++;
  274. if (range.colCount === sameCol) {
  275. bPaste = false;
  276. }
  277. continue;
  278. }
  279. if (colSetting.type === 'Number') {
  280. if (isNaN(validText)) {
  281. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  282. bPaste = false;
  283. continue;
  284. }
  285. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  286. // 判断是否 正数必须大于等于限制值,负数必须小于等于限制值,否则无法更改
  287. const usedInfo = _.find(changeUsedData, { id: sortData[curRow].id });
  288. if (usedInfo && usedInfo.used_qty >= 0 && validText < usedInfo.used_qty) {
  289. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须大于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须大于等于已调用值 ' + usedInfo.used_qty);
  290. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  291. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  292. bPaste = false;
  293. continue;
  294. } else if (usedInfo && usedInfo.used_qty < 0 && validText > usedInfo.used_qty) {
  295. toastr.error(hintRow ? '清单' + (hintRow+1) + '行变更数值必须小于等于已调用值 ' + usedInfo.used_qty : '清单变更数值必须小于等于已调用值 ' + usedInfo.used_qty);
  296. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  297. changeSpreadObj.setRowValueAndSum(sortData[curRow], curRow, curCol);
  298. bPaste = false;
  299. continue;
  300. }
  301. }
  302. // cLData[colSetting.field] = validText;
  303. sortData[curRow][colSetting.field] = validText;
  304. cLData.spamount = validText;
  305. }
  306. if (bPaste) {
  307. data.push(cLData);
  308. // rowData.push(curRow);
  309. } else {
  310. // SpreadJsObj.reLoadRowData(info.sheet, curRow);
  311. }
  312. }
  313. if (data.length === 0) {
  314. // SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  315. return;
  316. }
  317. console.log(data);
  318. // 更新至服务器
  319. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  320. changeList = result;
  321. changeSpreadObj.setAuditValue();
  322. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  323. changeSpreadObj.makeSjsFooter();
  324. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  325. }, function () {
  326. changeSpreadObj.setAuditValue();
  327. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  328. return;
  329. });
  330. },
  331. };
  332. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  333. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  334. changeSpreadObj.setAuditValue();
  335. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  336. console.log(changeList);
  337. changeSpreadObj.makeSjsFooter();
  338. changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
  339. const userIndex = aidList.indexOf(parseInt(accountId));
  340. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  341. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  342. changeSpread.bind(spreadNS.Events.SelectionChanged, changeSpreadObj.selectionChanged);
  343. SpreadJsObj.addDeleteBind(changeSpread, changeSpreadObj.deletePress);
  344. // 审批提交与判断
  345. $('.approval-btn').on('click', function () {
  346. // 判断审批状态
  347. let returnflag = true;
  348. if ($(this).hasClass('btn-success')) {
  349. const sdesc = $('#success-approval').find('textarea').val();
  350. if (sdesc === '') {
  351. toastr.error('审批意见不能为空!');
  352. returnflag = false;
  353. }
  354. if ($('input[name="p_code"]').val() === '') {
  355. toastr.error('变更令号(批复编号)不能为空!');
  356. returnflag = false;
  357. } else if ($('input[name="p_code"]').val() !== undefined) {
  358. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  359. const postData = {
  360. p_code: $('input[name="p_code"]').val(),
  361. };
  362. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  363. }, function (data) {
  364. returnflag = false;
  365. });
  366. }
  367. // 判断并提交变更清单表格数据到表单中
  368. const clist = [];
  369. for(const [i,cl] of changeList.entries()) {
  370. if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') {
  371. toastr.error('清单第' + (i+1) + '行审批变更数量不能为空');
  372. returnflag = false;
  373. } else {
  374. clist.push(cl.id + '_' + cl['audit_amount_' + accountId]);
  375. }
  376. }
  377. $('#change-list-approval').val(clist.join(','));
  378. if(returnflag) {
  379. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  380. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  381. if ($('#warning-text').length) $('#warning-text').remove()
  382. $('#success-approval').submit();
  383. }
  384. } else {
  385. const sdesc = $('#fail-approval').find('textarea').val();
  386. if (sdesc === '') {
  387. toastr.error('审批意见不能为空!');
  388. returnflag = false;
  389. }
  390. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  391. if (type === undefined) {
  392. // toastr.error('请选择退回类型!');
  393. if (!$('#warning-text').length) {
  394. $('#change-back-content').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  395. }
  396. returnflag = false;
  397. }
  398. if(returnflag) {
  399. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  400. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  401. $('#fail-approval').submit();
  402. }
  403. }
  404. })
  405. });
  406. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  407. if (showWaiting) showWaitingView();
  408. $.ajax({
  409. type:"POST",
  410. url: url,
  411. data: {'data': JSON.stringify(data)},
  412. dataType: 'json',
  413. cache: false,
  414. async: false,
  415. timeout: 60000,
  416. beforeSend: function(xhr) {
  417. let csrfToken = Cookies.get('csrfToken_j');
  418. xhr.setRequestHeader('x-csrf-token', csrfToken);
  419. },
  420. success: function(result){
  421. if (result.err === 0) {
  422. if (successCallback) {
  423. successCallback(result.data);
  424. }
  425. } else {
  426. toastr.error(result.msg);
  427. if (errorCallBack) {
  428. errorCallBack(result.msg);
  429. }
  430. }
  431. if (showWaiting) closeWaitingView();
  432. },
  433. error: function(jqXHR, textStatus, errorThrown){
  434. toastr.error('error: ' + textStatus + " " + errorThrown);
  435. if (errorCallBack) {
  436. errorCallBack();
  437. }
  438. if (showWaiting) closeWaitingView();
  439. }
  440. });
  441. };
  442. function auditCheck(i) {
  443. const inlineRadio1 = $('#change-back:checked').val()
  444. const inlineRadio2 = $('#chagne-backnew:checked').val()
  445. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  446. $('textarea[name="sdesc"]').eq(i).val(opinion);
  447. if (i === 1) {
  448. if (!inlineRadio1 && !inlineRadio2) {
  449. if (!$('#warning-text').length) {
  450. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  451. }
  452. return false;
  453. }
  454. if ($('#warning-text').length) $('#warning-text').remove()
  455. }
  456. return true;
  457. }