check_data_modal.ejs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!--上报审批 自检-->
  2. <div class="modal fade" id="check" data-backdrop="static">
  3. <div class="modal-dialog" role="document">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <h5 class="modal-title">上报审批</h5>
  7. </div>
  8. <div class="modal-body">
  9. <h5>数据计算中,完成后会自动进入审批流程设置。</h5>
  10. <div class="progress">
  11. <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. <!--上报审批 自检 计算错误-->
  18. <div class="modal fade" id="check-error-hint" data-backdrop="static">
  19. <div class="modal-dialog" role="document">
  20. <div class="modal-content">
  21. <div class="modal-header">
  22. <h5 class="modal-title">上报审批</h5>
  23. </div>
  24. <div class="modal-body">
  25. <div class="alert alert-danger" role="alert">
  26. 部分清单存在问题,请前往错误列表进行查看,并进行修改。
  27. </div>
  28. </div>
  29. <div class="modal-footer">
  30. <button type="button" class="btn btn-sm btn-primary" data-dismiss="modal" id="show-error-list">查看错误列表</button>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. <script>
  36. /**
  37. *
  38. * @param setting
  39. * {
  40. * loadUrl,
  41. * loadData,
  42. * checkFun,
  43. * errorList
  44. * }
  45. */
  46. const DataChecker = function (setting) {
  47. let progressInterval;
  48. $('#show-error-list').click(function () {
  49. $('#check').modal('hide');
  50. setting.errorList.show();
  51. });
  52. const loadCheckData = function () {
  53. const promise = new Promise(function (resolve, reject) {
  54. postData(setting.loadUrl, setting.loadData, function (result) {
  55. resolve(result);
  56. });
  57. });
  58. return promise;
  59. }
  60. const progress = function (percent) {
  61. $('.progress-bar').attr('aria-valuenow', percent).width(percent + '%').html(percent + '%');
  62. }
  63. const fakeProgresTo = function (percent) {
  64. const processObj = $('.progress-bar');
  65. let count = 0;
  66. progressInterval = setInterval(function () {
  67. const pos = parseInt(processObj.attr('aria-valuenow'));
  68. if (pos < 10) { // 1
  69. processObj.attr('aria-valuenow', pos + 2);
  70. processObj.width((pos + 2) + '%');
  71. } else if (pos < 20) { // 2
  72. processObj.attr('aria-valuenow', pos + 1);
  73. processObj.width((pos + 1) + '%');
  74. } else if (pos < 30) { // 4
  75. count += 1;
  76. if (count % 2 === 0) {
  77. processObj.attr('aria-valuenow', pos + 1);
  78. processObj.width((pos + 1) + '%');
  79. }
  80. } else if (pos < 40) { // 10
  81. count += 1;
  82. if (count % 5 === 0) {
  83. processObj.attr('aria-valuenow', pos + 1);
  84. processObj.width((pos + 1) + '%');
  85. }
  86. } else if (pos < 45) { // 15
  87. count += 1;
  88. if (count % 15 === 0) {
  89. processObj.attr('aria-valuenow', pos + 1);
  90. processObj.width((pos + 1) + '%');
  91. }
  92. } else if (pos < 50) { // 20
  93. count += 1;
  94. if (count % 40 === 0) {
  95. processObj.attr('aria-valuenow', pos + 1);
  96. processObj.width((pos + 1) + '%');
  97. }
  98. }
  99. }, 100);
  100. }
  101. const stopFakeProgress = function (percent) {
  102. clearInterval(progressInterval);
  103. progress(percent);
  104. }
  105. const addProgress = function (percent) {
  106. const oldPercent = parseInt($('.progress-bar').attr('aria-valuenow'));
  107. progress(oldPercent + parseInt(percent/2));
  108. }
  109. const checkAndPost = async function (postUrl, postForm) {
  110. progress(0);
  111. $('#check').modal('show');
  112. fakeProgresTo(50);
  113. const lastestData = await loadCheckData();
  114. stopFakeProgress(50);
  115. const result = setting.checkFun(lastestData, addProgress);
  116. progress(100);
  117. setTimeout(function () {
  118. if (result && result.length > 0) {
  119. $('#check-error-hint').modal('show');
  120. setting.errorList.loadErrorData(result);
  121. } else {
  122. setting.errorList.clearErrorData();
  123. postDataWithFile(postUrl, postForm, function () {
  124. window.location.reload();
  125. });
  126. }
  127. }, 1000);
  128. }
  129. return {checkAndPost};
  130. }
  131. </script>