change_information_approval.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. editEnded: function (e, info) {
  126. if (info.sheet.zh_setting) {
  127. const select = SpreadJsObj.getSelectObject(info.sheet);
  128. const col = info.sheet.zh_setting.cols[info.col];
  129. // 未改变值则不提交
  130. let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : '');
  131. const orgValue = select[col.field];
  132. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  133. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  134. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  135. return;
  136. }
  137. // 判断部分值是否输入的是数字判断和数据计算
  138. if (col.type === 'Number') {
  139. if (isNaN(validText)) {
  140. toastr.error('不能输入其它非数字类型字符');
  141. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  142. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  143. return;
  144. }
  145. validText = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  146. }
  147. select[col.field] = validText;
  148. select.spamount = ZhCalc.round(validText, findDecimal(select.unit)) || 0;
  149. console.log(select);
  150. const data = {
  151. id: select.id,
  152. spamount: select.spamount,
  153. };
  154. console.log(data);
  155. // 更新至服务器
  156. postData(window.location.pathname + '/save', { type:'update', updateData: data }, function (result) {
  157. changeList.splice(info.row, 1, select);
  158. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  159. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  160. }, function () {
  161. select[col.field] = orgValue;
  162. select.spamount = orgValue;
  163. SpreadJsObj.reLoadRowData(info.sheet, info.row);
  164. changeSpreadObj.setRowValueAndSum(select, info.row, info.col);
  165. });
  166. }
  167. },
  168. clipboardPasted(e, info) {
  169. // const hint = {
  170. // cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},
  171. // numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},
  172. // };
  173. const range = info.cellRange;
  174. const sortData = info.sheet.zh_data || [];
  175. // console.log(info, range);
  176. // if (info.cellRange.row + info.cellRange.rowCount > sortData.length) {
  177. // toastMessageUniq(hint.cellError);
  178. // // SpreadJsObj.loadSheetData(materialSpread.getActiveSheet(), SpreadJsObj.DataType.Data, materialBillsData);
  179. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  180. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  181. // changeSpreadObj.setAuditValue();
  182. // changeSpreadObj.makeSjsFooter();
  183. // return;
  184. // }
  185. // if (sortData.length > 0 && range.col + range.colCount > 10) {
  186. // toastMessageUniq(hint.cellError);
  187. // SpreadJsObj.reLoadSheetHeader(changeSpreadSheet);
  188. // SpreadJsObj.reLoadSheetData(changeSpreadSheet);
  189. // changeSpreadObj.setAuditValue();
  190. // changeSpreadObj.makeSjsFooter();
  191. // return;
  192. // }
  193. const data = [];
  194. // const rowData = [];
  195. for (let iRow = 0; iRow < range.rowCount; iRow++) {
  196. let bPaste = true;
  197. const curRow = range.row + iRow;
  198. // const materialData = JSON.parse(JSON.stringify(sortData[curRow]));
  199. const cLData = { id: sortData[curRow].id };
  200. const hintRow = range.rowCount > 1 ? curRow : '';
  201. let sameCol = 0;
  202. for (let iCol = 0; iCol < range.colCount; iCol++) {
  203. const curCol = range.col + iCol;
  204. const colSetting = info.sheet.zh_setting.cols[curCol];
  205. if (!colSetting) continue;
  206. let validText = info.sheet.getText(curRow, curCol);
  207. validText = is_numeric(validText) ? parseFloat(validText) : (validText ? trimInvalidChar(validText) : null);
  208. const orgValue = sortData[curRow][colSetting.field];
  209. if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {
  210. sameCol++;
  211. if (range.colCount === sameCol) {
  212. bPaste = false;
  213. }
  214. continue;
  215. }
  216. if (colSetting.type === 'Number') {
  217. if (isNaN(validText)) {
  218. toastMessageUniq(getPasteHint(hint.numberExpr, hintRow));
  219. bPaste = false;
  220. continue;
  221. }
  222. validText = ZhCalc.round(validText, findDecimal(sortData[curRow].unit)) || 0;
  223. }
  224. // cLData[colSetting.field] = validText;
  225. sortData[curRow][colSetting.field] = validText;
  226. cLData.spamount = validText;
  227. }
  228. if (bPaste) {
  229. data.push(cLData);
  230. // rowData.push(curRow);
  231. } else {
  232. SpreadJsObj.reLoadRowData(info.sheet, curRow);
  233. }
  234. }
  235. if (data.length === 0) {
  236. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  237. return;
  238. }
  239. console.log(data);
  240. // 更新至服务器
  241. postData(window.location.pathname + '/save', { type:'paste_amount_rows', updateData: data }, function (result) {
  242. changeList = result;
  243. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  244. changeSpreadObj.setAuditValue();
  245. changeSpreadObj.makeSjsFooter();
  246. }, function () {
  247. SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);
  248. changeSpreadObj.setAuditValue();
  249. return;
  250. });
  251. },
  252. };
  253. SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
  254. SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
  255. SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
  256. changeSpreadObj.setAuditValue();
  257. changeSpreadObj.makeSjsFooter();
  258. const userIndex = aidList.indexOf(parseInt(accountId));
  259. changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
  260. changeSpread.bind(spreadNS.Events.ClipboardPasted, changeSpreadObj.clipboardPasted);
  261. // 审批提交与判断
  262. $('.approval-btn').on('click', function () {
  263. // 判断审批状态
  264. let returnflag = true;
  265. if ($(this).hasClass('btn-success')) {
  266. const sdesc = $('#success-approval').find('textarea').val();
  267. if (sdesc === '') {
  268. toastr.error('审批意见不能为空!');
  269. returnflag = false;
  270. }
  271. if ($('input[name="p_code"]').val() === '') {
  272. toastr.error('变更令号(批复编号)不能为空!');
  273. returnflag = false;
  274. } else if ($('input[name="p_code"]').val() !== undefined) {
  275. $('input[name="p_code"]').val($.trim($('input[name="p_code"]').val()));
  276. const postData = {
  277. p_code: $('input[name="p_code"]').val(),
  278. };
  279. postDataWithAsync('/tender/' + $('#tenderId').val() + '/change/' + $('#changeId').val() + '/check/codeRepeat',postData, function (result) {
  280. }, function (data) {
  281. returnflag = false;
  282. });
  283. }
  284. // 判断并提交变更清单表格数据到表单中
  285. const clist = [];
  286. for(const [i,cl] of changeList.entries()) {
  287. if (cl['audit_amount_' + accountId] === null || cl['audit_amount_' + accountId] === '') {
  288. toastr.error('清单第' + (i+1) + '行审批变更数量不能为空');
  289. returnflag = false;
  290. } else {
  291. clist.push(cl.id + '_' + cl['audit_amount_' + accountId]);
  292. }
  293. }
  294. $('#change-list-approval').val(clist.join(','));
  295. if(returnflag) {
  296. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  297. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  298. if ($('#warning-text').length) $('#warning-text').remove()
  299. $('#success-approval').submit();
  300. }
  301. } else {
  302. const sdesc = $('#fail-approval').find('textarea').val();
  303. if (sdesc === '') {
  304. toastr.error('审批意见不能为空!');
  305. returnflag = false;
  306. }
  307. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  308. if (type === undefined) {
  309. // toastr.error('请选择退回类型!');
  310. if (!$('#warning-text').length) {
  311. $('#change-back-content').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  312. }
  313. returnflag = false;
  314. }
  315. if(returnflag) {
  316. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  317. $('input[name="w_code"]').val($.trim($('#w_code').val()));
  318. $('#fail-approval').submit();
  319. }
  320. }
  321. })
  322. });
  323. const postDataWithAsync = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  324. if (showWaiting) showWaitingView();
  325. $.ajax({
  326. type:"POST",
  327. url: url,
  328. data: {'data': JSON.stringify(data)},
  329. dataType: 'json',
  330. cache: false,
  331. async: false,
  332. timeout: 60000,
  333. beforeSend: function(xhr) {
  334. let csrfToken = Cookies.get('csrfToken');
  335. xhr.setRequestHeader('x-csrf-token', csrfToken);
  336. },
  337. success: function(result){
  338. if (result.err === 0) {
  339. if (successCallback) {
  340. successCallback(result.data);
  341. }
  342. } else {
  343. toastr.error(result.msg);
  344. if (errorCallBack) {
  345. errorCallBack(result.msg);
  346. }
  347. }
  348. if (showWaiting) closeWaitingView();
  349. },
  350. error: function(jqXHR, textStatus, errorThrown){
  351. toastr.error('error: ' + textStatus + " " + errorThrown);
  352. if (errorCallBack) {
  353. errorCallBack();
  354. }
  355. if (showWaiting) closeWaitingView();
  356. }
  357. });
  358. };
  359. function auditCheck(i) {
  360. const inlineRadio1 = $('#change-back:checked').val()
  361. const inlineRadio2 = $('#chagne-backnew:checked').val()
  362. const opinion = $('textarea[name="sdesc"]').eq(i).val().replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
  363. $('textarea[name="sdesc"]').eq(i).val(opinion);
  364. if (i === 1) {
  365. if (!inlineRadio1 && !inlineRadio2) {
  366. if (!$('#warning-text').length) {
  367. $('#reject-process').prepend('<p id="warning-text" style="color: red; margin: 0;">请选择退回流程</p>');
  368. }
  369. return false;
  370. }
  371. if ($('#warning-text').length) $('#warning-text').remove()
  372. }
  373. return true;
  374. }