change_approval.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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="4"]').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. // 审批提交与判断
  39. $('.approval-btn').on('click', function () {
  40. // 判断审批状态
  41. let returnflag = true;
  42. if ($(this).hasClass('btn-success')) {
  43. const sdesc = $('#success-approval').find('textarea').val();
  44. if (sdesc === '') {
  45. toastr.error('审批意见不能为空!');
  46. returnflag = false;
  47. }
  48. if ($('#w_code').val() === '') {
  49. toastr.error('批复文号不能为空!');
  50. returnflag = false;
  51. } else {
  52. $('input[name="w_code"]').val($('#w_code').val());
  53. }
  54. // 判断并提交变更清单表格数据到表单中
  55. const clist = [];
  56. $('.clist input').each(function(k, v){
  57. const value = $(this).val();
  58. const lid = $(this).parents('tr').data('lid');
  59. if (value === '') {
  60. toastr.error('清单第' + (k+1) + '行审批变更数量不能为空');
  61. returnflag = false;
  62. }
  63. clist.push(lid+'_'+value);
  64. });
  65. $('#change-list-approval').val(clist.join(','));
  66. if(returnflag) {
  67. $('#success-approval').submit();
  68. }
  69. } else {
  70. const sdesc = $('#fail-approval').find('textarea').val();
  71. if (sdesc === '') {
  72. toastr.error('审批意见不能为空!');
  73. returnflag = false;
  74. }
  75. const type = $('#fail-approval').find('input[name="status"]:checked').val();
  76. if (type === undefined) {
  77. toastr.error('请选择退回类型!');
  78. returnflag = false;
  79. }
  80. if(returnflag) {
  81. $('#fail-approval').submit();
  82. }
  83. }
  84. })
  85. });