tender_copy_setting.js 6.9 KB

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