change_approval.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. 'use strict';
  2. /**
  3. * 变更令-审批页js
  4. *
  5. * @author EllisRan.
  6. * @date 2018/11/22
  7. * @version
  8. */
  9. $(document).ready(() => {
  10. $('#sp-back input[name="status"]').click(function (e) {
  11. if($(e.target).is('label')){
  12. return;
  13. }
  14. if (parseInt($(this).val()) === 4) {
  15. $('.change-approval-stop').show();
  16. $('.change-approval-back').hide();
  17. } else {
  18. $('.change-approval-stop').hide();
  19. $('.change-approval-back').show();
  20. }
  21. });
  22. // 清单输入监控并更新
  23. $('body').on('valuechange', '.clist input', function (e, previous) {
  24. const amount = $(this).val();
  25. const lid = $(this).parents('tr').data('lid');
  26. const tr = $('#list tr[data-lid="' + lid + '"]').eq(0);
  27. const unitprice = tr.children('td[data-site="5"]').text();
  28. tr.children('.amount_cost').text(amount != '' ?
  29. roundnum(parseFloat(unitprice).mul(parseFloat(amount)),totalPriceUnit) : '');
  30. // 统计总金额
  31. let totalcost = 0;
  32. $('.clist').each(function(){
  33. const utotal = $(this).find('.amount_cost').text();
  34. totalcost = utotal != '' ? parseFloat(totalcost)+parseFloat(utotal) : parseFloat(totalcost);
  35. });
  36. $('.amount_totalcost').eq(1).text(totalcost !== 0 ? roundnum(totalcost, totalPriceUnit) : '');
  37. });
  38. // 选中input所有值
  39. $('body').on('focus', ".clist input", function() {
  40. $(this).select();
  41. });
  42. // 审批提交与判断
  43. $('.approval-btn').on('click', function () {
  44. // 判断审批状态
  45. let returnflag = true;
  46. if ($(this).hasClass('btn-success')) {
  47. const sdesc = $('#success-approval').find('textarea').val();
  48. if (sdesc === '') {
  49. toastr.error('审批意见不能为空!');
  50. returnflag = false;
  51. }
  52. if ($('input[name="p_code"]').val() === '') {
  53. toastr.error('变更令号(批复编号)不能为空!');
  54. returnflag = false;
  55. }
  56. // 判断并提交变更清单表格数据到表单中
  57. const clist = [];
  58. $('.clist input').each(function(k, v){
  59. const value = $(this).val();
  60. const lid = $(this).parents('tr').data('lid');
  61. if (value === '') {
  62. toastr.error('清单第' + (k+1) + '行审批变更数量不能为空');
  63. returnflag = false;
  64. }
  65. clist.push(lid+'_'+value);
  66. });
  67. $('#change-list-approval').val(clist.join(','));
  68. if(returnflag) {
  69. $('input[name="w_code"]').val($('#w_code').val());
  70. $('#success-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  71. $('#success-approval').submit();
  72. }
  73. } else {
  74. const sdesc = $('#fail-approval').find('textarea').val();
  75. if (sdesc === '') {
  76. toastr.error('审批意见不能为空!');
  77. returnflag = false;
  78. }
  79. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  80. if (type === undefined) {
  81. toastr.error('请选择退回类型!');
  82. returnflag = false;
  83. }
  84. if(returnflag) {
  85. $('#fail-approval').find('textarea').val(sdesc.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '));
  86. $('input[name="w_code"]').val($('#w_code').val());
  87. $('#fail-approval').submit();
  88. }
  89. }
  90. })
  91. });