tender_list_progress.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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="25%" 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: 8%">');
  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: 8%">');
  54. if (!node.cid && node.cur_flow) {
  55. if (node.id === 4811) console.log(node.cur_flow);
  56. if (node.id === 3866) {
  57. console.log(node);
  58. }
  59. const curUser = node.cur_flow instanceof Array && node.cur_flow[0].audit_type && node.cur_flow[0].audit_type !== auditType.key.common
  60. ? transFormToChinese(node.cur_flow[0].audit_order) + '审'
  61. : 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 : ''));
  62. if (node.stage_status !== undefined) {
  63. html.push(((node.stage_count && node.stage_status === auditConst.stage.status.uncheck) || node.ledger_status === auditConst.ledger.status.uncheck)
  64. ? curUser
  65. : `<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>`
  66. );
  67. html.push(`<span class="${node.progress.status_class} ml-1">${node.progress.status}</span>`);
  68. } else {
  69. html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? '' :
  70. '<a href="#sp-list" data-toggle="modal" data-target="#sp-list" data-type="'+ (node.lastStage ? 'stage' : 'ledger') +'"' +
  71. ' data-tender="'+ node.id +'" data-order="'+ (node.lastStage ? node.lastStage.order : '') +'">');
  72. html.push(curUser);
  73. html.push((node.lastStage && node.lastStage.status === auditConst.stage.status.uncheck) || (!node.lastStage && node.ledger_status === auditConst.ledger.status.uncheck ) ? ' ':
  74. '</a> ');
  75. if (node.cur_flow instanceof Array) {
  76. html.push('<span class="' + node.cur_flow[0].status_class +'">' + node.cur_flow[0].status + '</span>');
  77. } else {
  78. html.push('<span class="' + node.cur_flow.status_class +'">' + node.cur_flow.status + '</span>');
  79. }
  80. }
  81. }
  82. html.push('</td>');
  83. // 上一流程审批时间
  84. html.push('<td style="width: 8%">');
  85. if (!node.cid && node.pre_flow) {
  86. if (node.pre_flow instanceof Array) {
  87. if (node.pre_flow.length > 1) {
  88. html.push(transFormToChinese(node.pre_flow[0].audit_order) + '审' + ' ' + moment(node.pre_flow[0].time).format('YYYY-MM-DD'));
  89. } else {
  90. html.push(node.pre_flow[0].name + ' ' + moment(node.pre_flow[0].time).format('YYYY-MM-DD'));
  91. }
  92. } else {
  93. html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD'));
  94. }
  95. }
  96. html.push('</td>');
  97. // 签约合同价
  98. html.push('<td width="8%" class="text-right">');
  99. html.push(node.contract_price ? node.contract_price : '');
  100. html.push('</td>');
  101. // 总价
  102. html.push('<td width="8%" class="text-right">');
  103. html.push(node.sum_tp ? node.sum_tp : '');
  104. html.push('</td>');
  105. // 截止本期累计完成/本期完成/未完成
  106. html.push('<td>');
  107. if (node.lastStage || node.stage_count > 0) {
  108. html.push(getProgressHtml(node.sum_tp, node.pre_gather_tp, node.gather_tp));
  109. } else {
  110. html.push('');
  111. }
  112. html.push('</td>');
  113. html.push('</tr>');
  114. return html.join('');
  115. }
  116. function getTenderTreeHeaderHtml() {
  117. const html = [];
  118. html.push('<table class="table table-hover table-bordered">');
  119. html.push('<thead style="position: fixed;left:56px;top: 34px;">', '<tr>');
  120. html.push('<th style="width: 25%" class="text-center">', '标段名称', '</th>');
  121. html.push('<th class="text-center" style="width: 8%">', '计量进度', '</th>');
  122. html.push('<th class="text-center" style="width: 8%">', '当前流程', '</th>');
  123. html.push('<th class="text-center" style="width: 8%">', '上一流程审批时间', '</th>');
  124. html.push('<th class="text-center" style="width: 8%">', '签约合同价', '</th>');
  125. html.push('<th style="width: 8%" class="text-center">', '总价 <i class="fa fa-question-circle text-primary" data-placement="bottom" data-toggle="tooltip" data-original-title="0号台账+截止本期数量变更"></i>', '</th>');
  126. html.push('<th style="width: 35%" class="text-center">', '截止上期完成/本期完成/未完成', '</th>');
  127. html.push('</tr>', '</thead>');
  128. return html.join('');
  129. }
  130. function calculateTender(tender) {
  131. if (tender.stage_tp) {
  132. tender.end_qc_tp = ZhCalc.sum([tender.stage_tp.pre_qc_tp, tender.stage_tp.qc_tp, tender.stage_tp.qc_pc_tp]);
  133. tender.pre_gather_tp = ZhCalc.add(tender.stage_tp.pre_contract_tp, tender.stage_tp.pre_qc_tp);
  134. tender.gather_tp = ZhCalc.sum([tender.stage_tp.contract_tp, tender.stage_tp.qc_tp, tender.stage_tp.pc_tp]);
  135. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  136. } else if (tender.lastStage) {
  137. tender.end_qc_tp = ZhCalc.sum([tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp, tender.lastStage.qc_pc_tp]);
  138. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  139. tender.gather_tp = ZhCalc.sum([tender.lastStage.contract_tp, tender.lastStage.qc_tp, tender.lastStage.pc_tp]);
  140. tender.sum_tp = ZhCalc.add(tender.total_price, tender.end_qc_tp);
  141. } else {
  142. tender.sum_tp = tender.total_price;
  143. }
  144. }
  145. function calculateParent(node) {
  146. if (node.children && node.cid) {
  147. node.end_qc_tp = 0;
  148. node.pre_gather_tp = 0;
  149. node.gather_tp = 0;
  150. node.sum_tp = 0;
  151. node.lastStage = 0;
  152. node.contract_price = 0;
  153. node.stage_count = 0;
  154. for (const c of node.children) {
  155. calculateParent(c);
  156. node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp);
  157. node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp);
  158. node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp);
  159. node.sum_tp = ZhCalc.add(node.sum_tp, c.sum_tp);
  160. node.lastStage = c.cid
  161. ? Math.max(node.lastStage, c.lastStage)
  162. : (c.lastStage ? Math.max(node.lastStage, c.lastStage.order) : node.lastStage);
  163. 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);
  164. node.contract_price = ZhCalc.add(node.contract_price, c.contract_price);
  165. }
  166. }
  167. }
  168. return { getTenderNodeHtml, getTenderTreeHeaderHtml, calculateTender, calculateParent }
  169. })();