change_information_approval.js 18 KB

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