change_approval.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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').submit();
  71. }
  72. } else {
  73. const sdesc = $('#fail-approval').find('textarea').val();
  74. if (sdesc === '') {
  75. toastr.error('审批意见不能为空!');
  76. returnflag = false;
  77. }
  78. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  79. if (type === undefined) {
  80. toastr.error('请选择退回类型!');
  81. returnflag = false;
  82. }
  83. if(returnflag) {
  84. $('input[name="w_code"]').val($('#w_code').val());
  85. $('#fail-approval').submit();
  86. }
  87. }
  88. })
  89. });