tender_list_progress.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/10/11
  7. * @version
  8. */
  9. const tenderListSpec = (function(){
  10. function getProgressHtml(total, pre, cur) {
  11. if (total !== 0) {
  12. let preP = ZhCalc.mul(ZhCalc.div(pre, total, 2), 100, 0);
  13. let curP = ZhCalc.mul(ZhCalc.div(cur, total, 2), 100, 0);
  14. let other = Math.max(ZhCalc.sub(ZhCalc.sub(total, pre), cur), 0);
  15. let otherP = Math.max(100 - preP - curP, 0);
  16. const html = '<div class="progress">' +
  17. '<div class="progress-bar bg-success" style="width: ' + preP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="截止上期完成:¥' + (pre || 0) + '">' + preP + '%</div>' +
  18. '<div class="progress-bar bg-info" style="width: ' + curP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="本期完成:¥' + (cur || 0) + '">' + curP + '%</div>' +
  19. '<div class="progress-bar bg-gray" style="width: ' + otherP + '%;" data-placement="bottom" data-toggle="tooltip" data-original-title="未完成:¥' + (other || 0) + '">' + otherP + '%</div>' +
  20. '</div>';
  21. return html;
  22. } else {
  23. return '';
  24. }
  25. }
  26. function getTenderNodeHtml(node, arr, pid) {
  27. const html = [];
  28. html.push('<tr pid="' + pid + '">');
  29. // 名称
  30. html.push('<td width="30%" style="min-width: 300px;" class="in-' + node.level + '">');
  31. if (node.cid) {
  32. html.push('<span onselectstart="return false" style="{-moz-user-select:none}" class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ');
  33. html.push((node.level === 1 ? '<b>' : ''), node.name, (node.level === 1 ? '</b>' : ''));
  34. } else {
  35. html.push('<span class="text-muted mr-2">');
  36. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  37. html.push('</span>');
  38. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  39. html.push('<a href="javascript: void(0)" name="name" id="' + node.id + '">', node.name, '</a>');
  40. }
  41. html.push('</td>');
  42. // 计量进度
  43. html.push('<td style="width: 120px">');
  44. if (!node.cid && node.cur_flow) {
  45. if (node.progress) {
  46. html.push(node.progress.title + ' (' + '<span class="' + node.progress.status_class +'">' + node.progress.status + '</span>' + ')');
  47. } else {
  48. html.push(node.cur_flow.title + ' (' + '<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>' + ')');
  49. }
  50. }
  51. html.push('</td>');
  52. // 当前流程
  53. html.push('<td style="width: 230px">');
  54. if (!node.cid && node.cur_flow) {
  55. const curUser = node.cur_flow instanceof Array && node.cur_flow[0].audit_type && node.cur_flow[0].audit_type !== auditType.key.common
  56. ? transFormToChinese(node.cur_flow[0].audit_order) + '审'
  57. : node.cur_flow instanceof Array ? (node.cur_flow[0].name + (node.cur_flow[0].role ? '-'+node.cur_flow[0].role : '')): (node.cur_flow.name + (node.cur_flow.role ? '-'+node.cur_flow.role : ''));
  58. if (node.stage_status !== undefined) {
  59. html.push(((node.stage_count && node.stage_status === auditConst.stage.status.uncheck) || node.ledger_status === auditConst.ledger.status.uncheck)
  60. ? curUser
  61. : `<a href="#sp-list" data-toggle="modal" data-target="#sp-list" data-type="${node.stage_count ? 'stage' : 'ledger'}" data-tender="${node.id}" data-order="${node.stage_count ? node.stage_count + '' : ''}">${curUser}</a>`
  62. );
  63. html.push(`<span class="${node.progress.status_class} ml-1">${node.progress.status}</span>`);
  64. } else {
  65. html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? '' :
  66. '<a href="#sp-list" data-toggle="modal" data-target="#sp-list" data-type="'+ (node.lastStage ? 'stage' : 'ledger') +'"' +
  67. ' data-tender="'+ node.id +'" data-order="'+ (node.lastStage ? node.lastStage.order : '') +'">');
  68. html.push(curUser);
  69. html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? ' ':
  70. '</a> ');
  71. if (node.cur_flow instanceof Array) {
  72. html.push('<span class="' + node.cur_flow[0].status_class +'">' + node.cur_flow[0].status + '</span>');
  73. } else {
  74. html.push('<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>');
  75. }
  76. }
  77. }
  78. html.push('</td>');
  79. // 上一流程审批时间
  80. html.push('<td style="width: 150px">');
  81. if (!node.cid && node.pre_flow) {
  82. if (node.pre_flow instanceof Array) {
  83. if (node.pre_flow.length > 1) {
  84. html.push(transFormToChinese(node.pre_flow[0].audit_order) + '审' + ' ' + moment(node.pre_flow[0].time).format('YYYY-MM-DD'));
  85. } else {
  86. html.push(node.pre_flow[0].name + ' ' + moment(node.pre_flow[0].time).format('YYYY-MM-DD'));
  87. }
  88. } else {
  89. html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD'));
  90. }
  91. }
  92. html.push('</td>');
  93. // 签约合同价
  94. html.push('<td width="120px" class="text-right">');
  95. html.push(node.contract_price ? node.contract_price : '');
  96. html.push('</td>');
  97. // 总价
  98. html.push('<td width="120px" class="text-right">');
  99. html.push(node.sum_tp ? node.sum_tp : '');
  100. html.push('</td>');
  101. // 截止本期累计完成/本期完成/未完成
  102. html.push('<td width="30%">');
  103. if (node.lastStage || node.stage_count > 0) {
  104. html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));
  105. } else {
  106. html.push('');
  107. }
  108. html.push('</td>');
  109. html.push('</tr>');
  110. return html.join('');
  111. }
  112. function getTenderTreeHeaderHtml() {
  113. const html = [];
  114. const left = $('#sub-menu').css('display') === 'none' ? 56 : 176;
  115. html.push('<table class="table table-hover table-bordered" id="progress-table">')
  116. html.push('<thead style="position: sticky;left:'+ left +'px;top: 0px;">', '<tr>');
  117. // html.push('<thead style="left:56px;top: 34px;">', '<tr>');
  118. html.push('<th style="width: 30%;min-width: 300px" class="text-center">', '标段名称', '</th>');
  119. html.push('<th class="text-center" style="width: 120px">', '计量进度', '</th>');
  120. html.push('<th class="text-center" style="width: 230px">', '当前流程', '</th>');
  121. html.push('<th class="text-center" style="width: 150px">', '上一流程审批时间', '</th>');
  122. html.push('<th class="text-center" style="width: 120px">', '签约合同价', '</th>');
  123. html.push('<th style="width: 120px" class="text-center">', '总价 <i class="fa fa-question-circle text-primary" data-placement="bottom" data-toggle="tooltip" data-original-title="0号台账+截止本期数量变更"></i>', '</th>');
  124. html.push('<th style="width: 30%" class="text-center">', '截止上期完成/本期完成/未完成', '</th>');
  125. html.push('</tr>', '</thead>');
  126. return html.join('');
  127. }
  128. function calculateTender(tender) {
  129. if (tender.stage_tp) {
  130. tender.end_qc_tp = ZhCalc.sum([tender.stage_tp.pre_qc_tp, tender.stage_tp.qc_tp, tender.stage_tp.qc_pc_tp]);
  131. tender.pre_gather_tp = ZhCalc.add(tender.stage_tp.pre_contract_tp, tender.stage_tp.pre_qc_tp);
  132. tender.gather_tp = ZhCalc.sum([tender.stage_tp.contract_tp, tender.stage_tp.qc_tp, tender.stage_tp.pc_tp]);
  133. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  134. } else if (tender.lastStage) {
  135. tender.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_tp]);
  136. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  137. tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]);
  138. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  139. } else {
  140. tender.sum_tp = tender.total_price;
  141. }
  142. }
  143. function calculateParent(node) {
  144. if (node.children && node.cid) {
  145. node.end_qc_tp = 0;
  146. node.pre_gather_tp = 0;
  147. node.gather_tp = 0;
  148. node.sum_tp = 0;
  149. node.lastStage = 0;
  150. node.contract_price = 0;
  151. node.stage_count = 0;
  152. for (const c of node.children) {
  153. calculateParent(c);
  154. node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
  155. node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
  156. node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
  157. node.sum_tp = ZhCalc.add(node.sum_tp, c.sum_tp);
  158. node.lastStage = c.cid
  159. ? Math.max(node.lastStage, c.lastStage)
  160. : (c.lastStage ? Math.max(node.lastStage, c.lastStage.order) : node.lastStage);
  161. node.stage_count = c.cid ? Math.max(node.stage_count, c.stage_count) : (c.stage_count ? Math.max(node.stage_count, c.stage_count): node.stage_count);
  162. node.contract_price = ZhCalc.add(node.contract_price, c.contract_price);
  163. }
  164. }
  165. }
  166. return { getTenderNodeHtml, getTenderTreeHeaderHtml, calculateTender, calculateParent }
  167. })();