change_information_approval.js 20 KB

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