tender_copy_setting.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. 'use strict';
  2. /**
  3. *
  4. * @author LanJianRong
  5. * @date 2020/11/13
  6. * @version
  7. */
  8. const tenderTree = [];
  9. let parentId = 0;
  10. // 查询方法
  11. function findNode (key, value, arr) {
  12. for (const a of arr) {
  13. if (a[key] && a[key] === value) {
  14. return a;
  15. }
  16. }
  17. }
  18. // 初始化TenderTree数据
  19. function initTenderTree () {
  20. const levelCategory = category.filter(function (c) {
  21. return c.level && c.level > 0;
  22. });
  23. function findCategoryNode(cid, value, array) {
  24. for (const a of array) {
  25. if (a.cid === cid && a.vid === value) {
  26. return a;
  27. }
  28. }
  29. }
  30. function getCategoryNode(category, value, parent, i = null) {
  31. const array = parent ? parent.children : tenderTree;
  32. let cate = findCategoryNode(category.id, value, array);
  33. if (!cate) {
  34. const cateValue = findNode('id', value, category.value);
  35. if (!cateValue) return null;
  36. cate = {
  37. cid: category.id,
  38. vid: value,
  39. name: cateValue.value,
  40. children: [],
  41. level: i ? i : category.level,
  42. sort_id: ++parentId,
  43. sort: cateValue.sort,
  44. };
  45. array.push(cate);
  46. }
  47. return cate;
  48. }
  49. function loadTenderCategory (tender) {
  50. let tenderCategory = null;
  51. for (const [index,lc] of levelCategory.entries()) {
  52. const tenderCate = findNode('cid', lc.id, tender.category);
  53. if (tenderCate) {
  54. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  55. } else {
  56. if (index === 0 && tender.category) {
  57. for (const [i,c] of tender.category.entries()) {
  58. const cate = findNode('id', c.cid, category);
  59. tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  60. }
  61. }
  62. return tenderCategory;
  63. }
  64. }
  65. return tenderCategory;
  66. }
  67. function calculateTender(tender) {
  68. if (tender.lastStage) {
  69. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  70. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  71. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  72. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  73. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  74. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  75. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  76. }
  77. }
  78. tenderTree.splice(0, tenderTree.length);
  79. for (const t of tenders) {
  80. calculateTender(t);
  81. t.valid = true;
  82. delete t.level;
  83. if (t.category && levelCategory.length > 0) {
  84. const parent = loadTenderCategory(t);
  85. if (parent) {
  86. t.level = parent.level + 1;
  87. parent.children.push(t);
  88. } else {
  89. tenderTree.push(t);
  90. }
  91. } else {
  92. tenderTree.push(t);
  93. }
  94. }
  95. }
  96. function recursiveGetTenderNodeHtml (node, arr, pid) {
  97. if (node.id === tender.id) return ''
  98. const html = [];
  99. html.push('<tr pid="' + pid + '">');
  100. // 名称
  101. html.push('<td class="in-' + node.level + '">');
  102. if (node.cid) {
  103. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  104. } else {
  105. html.push('<span class="text-muted mr-2">');
  106. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  107. html.push('</span>');
  108. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  109. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  110. }
  111. html.push('</td>');
  112. // 创建人
  113. html.push('<td>');
  114. if (!node.cid) {
  115. // html.push('<input data-tid="'+ node.id +'" type="radio"> '+ (node.copy_id === tender.copy_id ? 'checked' : '') + '/>');
  116. html.push(`<input data-tid=${node.id} type="radio" ${node.id === tender.copy_id ? 'checked' : ''}>`);
  117. }
  118. html.push('</td>');
  119. html.push('</tr>');
  120. if (node.children) {
  121. for (const c of node.children) {
  122. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
  123. }
  124. }
  125. return html.join('');
  126. }
  127. // 根据TenderTree数据获取Html代码
  128. function getTenderTreeHtml () {
  129. if (tenderTree.length > 0) {
  130. const html = [];
  131. html.push('<table class="table table-hover table-bordered">');
  132. html.push('<thead>', '<tr>');
  133. html.push('<th>名称</th>');
  134. html.push('<th width="40">选择</th>');
  135. html.push('</tr>', '</thead>');
  136. parentId = 0;
  137. for (const t of tenderTree) {
  138. html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
  139. }
  140. html.push('</table>');
  141. return html.join('');
  142. } else {
  143. return EmptyTenderHtml.join('');
  144. }
  145. }
  146. $(document).ready(function () {
  147. initTenderTree()
  148. $('#copyBtn').click(() => {
  149. const html = getTenderTreeHtml();
  150. $('#copyModalContent').html(html);
  151. $('#bd-set-8').modal('show');
  152. });
  153. $('#copyModalContent').on('click', 'input[type="radio"]', function() {
  154. $('#copyModalContent tbody').children().each(function () {
  155. $(this).find('input:radio').prop("checked", false);
  156. })
  157. $(this).prop("checked", true);
  158. });
  159. $('#setting-custom').on('click', '.custom-checkbox', function () {
  160. const isChecked = $(this).find('input').prop("checked");
  161. $(this).find('input').prop("checked", !isChecked);
  162. })
  163. $('#copy_comfirm_btn').click(function() {
  164. const type = []
  165. $('#setting-custom').find('input:checked').each(function() {
  166. type.push($(this).data('type'))
  167. })
  168. if (!type.length) {
  169. return toastr.error('请勾选需要拷贝的属性')
  170. }
  171. const id = $('#copyModalContent').find('input:checked').data('tid');
  172. if (id) {
  173. postData(window.location.pathname + '/copy-setting', { id, type }, function() {
  174. window.location.reload()
  175. })
  176. }
  177. });
  178. })