change_information_approval.js 20 KB

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