sub_project_info.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. $(document).ready(function() {
  2. const projectTreeObj = (function(setting){
  3. const ProjectTree = createDragTree(setting.treeSetting);
  4. ProjectTree.loadDatas(setting.source);
  5. const TableObj = $(setting.table);
  6. const TableHeaderObj = $(setting.tableHeader);
  7. let tenderTreeShowLevel;
  8. let colSetCache;
  9. const Utils = {
  10. calculateFolder: function(node) {
  11. node.tp_cache = {};
  12. for (const c of node.children) {
  13. if (!c.tp_cache) continue;
  14. for (const prop in c.tp_cache) {
  15. node.tp_cache[prop] = ZhCalc.add(node.tp_cache[prop], c.tp_cache[prop]);
  16. }
  17. }
  18. },
  19. calculateSubProject: function(node) {
  20. node.tp_cache.gather_tp = ZhCalc.sum([node.tp_cache.contract_tp, node.tp_cache.qc_tp, node.tp_cache.pc_tp]);
  21. node.tp_cache.end_contract_tp = ZhCalc.sum([node.tp_cache.pre_contract_tp, node.tp_cache.contract_tp, node.tp_cache.contract_pc_tp]);
  22. node.tp_cache.end_qc_tp = ZhCalc.sum([node.tp_cache.pre_qc_tp, node.tp_cache.qc_tp, node.tp_cache.qc_pc_tp]);
  23. node.tp_cache.end_gather_tp = ZhCalc.add(node.tp_cache.end_contract_tp, node.tp_cache.end_qc_tp);
  24. node.tp_cache.pre_gather_tp = ZhCalc.add(node.tp_cache.pre_contract_tp, node.tp_cache.pre_qc_tp);
  25. node.tp_cache.end_yf_tp = ZhCalc.add(node.tp_cache.pre_yf_tp, node.tp_cache.yf_tp);
  26. node.tp_cache.end_sf_tp = ZhCalc.add(node.tp_cache.pre_sf_tp, node.tp_cache.sf_tp);
  27. node.tp_cache.wf_tp = ZhCalc.sub(node.tp_cache.end_yf_tp, node.tp_cache.end_sf_tp);
  28. },
  29. calculateNode: function(node) {
  30. if (node.children && node.children.length > 0) {
  31. for (const c of node.children) {
  32. this.calculateNode(c);
  33. }
  34. this.calculateFolder(node);
  35. } else {
  36. if (node.is_folder) {
  37. this.calculateFolder(node)
  38. } else {
  39. this.calculateSubProject(node);
  40. }
  41. }
  42. },
  43. calculateAll: function() {
  44. for (const p of ProjectTree.children) {
  45. this.calculateNode(p);
  46. }
  47. },
  48. generateColSetCache: function() {
  49. const result = {};
  50. colSet.forEach(x => {
  51. result[x.field] = { show: x.show, alias: x.alias || x.name };
  52. });
  53. return result;
  54. },
  55. getHeaderHtml: function() {
  56. colSetCache = this.generateColSetCache();
  57. const html = [];
  58. html.push('<tr>');
  59. if (colSetCache.name.show) html.push('<th class="text-center" style="min-width: 300px;">', colSetCache.name.alias, '</th>');
  60. if (colSetCache.contract_price.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.contract_price.alias, '</th>');
  61. if (colSetCache.total_price.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.total_price.alias, '</th>');
  62. if (colSetCache.gather_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.gather_tp.alias, '</th>');
  63. if (colSetCache.end_contract_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_contract_tp.alias, '</th>');
  64. if (colSetCache.end_qc_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_qc_tp.alias, '</th>');
  65. if (colSetCache.end_gather_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_gather_tp.alias, '</th>');
  66. if (colSetCache.pre_gather_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.pre_gather_tp.alias, '</th>');
  67. if (colSetCache.advance_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.advance_tp.alias, '<i class="fa fa-question-circle text-primary" data-placement="bottom" data-toggle="tooltip" data-original-title="预付款流程中截止本期金额"></i>', '</th>');
  68. if (colSetCache.yf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.yf_tp.alias, '</th>');
  69. if (colSetCache.end_yf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_yf_tp.alias, '</th>');
  70. if (colSetCache.sf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.sf_tp.alias, '</th>');
  71. if (colSetCache.end_sf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_sf_tp.alias, '</th>');
  72. if (colSetCache.wf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.wf_tp.alias, '</th>');
  73. html.push('</tr>');
  74. return html.join('');
  75. },
  76. getRowTdHtml: function (node, tree) {
  77. const html = [];
  78. // 名称
  79. if (colSetCache.name.show) {
  80. html.push('<td width="20%" class="in-' + node.tree_level + '">');
  81. if (node.is_folder) {
  82. if (node.children.length > 0) {
  83. html.push('<span onselectstart="return false" style="{-moz-user-select:none}" class="fold-switch mr-1" title="收起" id="'+ node.id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ', node.name);
  84. } else {
  85. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  86. }
  87. } else {
  88. html.push(`<span class="text-muted mr-2">${tree.isLastSibling(node) ? '└' : '├'}</span>`);
  89. html.push(`<a href="/sp/${node.id}/dashboard" name="name" id="${node.id}">`, node.name, '</a>');
  90. }
  91. html.push('</td>');
  92. }
  93. if (colSetCache.contract_price.show) {
  94. html.push('<td style="width: 100px" class="text-right">');
  95. html.push(node.tp_cache.contract_price || '');
  96. html.push('</td>');
  97. }
  98. // 0号台账合同
  99. if (colSetCache.total_price.show) {
  100. html.push('<td style="width: 100px" class="text-right">');
  101. html.push(node.tp_cache.total_price || '');
  102. html.push('</td>');
  103. }
  104. // 本期完成
  105. if (colSetCache.gather_tp.show) {
  106. html.push('<td style="width: 100px" class="text-right">');
  107. html.push(node.tp_cache.gather_tp || '');
  108. html.push('</td>');
  109. }
  110. // 截止本期合同
  111. if (colSetCache.end_contract_tp.show) {
  112. html.push('<td style="width: 100px" class="text-right">');
  113. html.push(node.tp_cache.end_contract_tp || '');
  114. html.push('</td>');
  115. }
  116. // 截止本期变更
  117. if (colSetCache.end_qc_tp.show) {
  118. html.push('<td style="width: 100px" class="text-right">');
  119. html.push(node.end_qc_tp || '');
  120. html.push('</td>');
  121. }
  122. // 截止本期完成
  123. if (colSetCache.end_gather_tp.show) {
  124. html.push('<td style="width: 100px" class="text-right">');
  125. html.push(node.tp_cache.end_gather_tp || '');
  126. html.push('</td>');
  127. }
  128. // 截止上期完成
  129. if (colSetCache.pre_gather_tp.show) {
  130. html.push('<td style="width: 100px" class="text-right">');
  131. html.push(node.pre_gather_tp || '');
  132. html.push('</td>');
  133. }
  134. // 预付款
  135. if (colSetCache.advance_tp.show) {
  136. html.push('<td style="width: 100px" class="text-right">');
  137. html.push(node.tp_cache.advance_tp || '');
  138. html.push('</td>');
  139. }
  140. // 本期应付
  141. if (colSetCache.yf_tp.show) {
  142. html.push('<td style="width: 100px" class="text-right">');
  143. html.push(node.tp_cache.yf_tp || '');
  144. html.push('</td>');
  145. }
  146. // 截止本期应付
  147. if (colSetCache.end_yf_tp.show) {
  148. html.push('<td style="width: 100px" class="text-right">');
  149. html.push(node.tp_cache.end_yf_tp || '');
  150. html.push('</td>');
  151. }
  152. // 本期实付
  153. if (colSetCache.sf_tp.show) {
  154. html.push('<td style="width: 100px" class="text-right">');
  155. html.push(node.tp_cache.sf_tp || '');
  156. html.push('</td>');
  157. }
  158. // 截止本期实付
  159. if (colSetCache.end_sf_tp.show) {
  160. html.push('<td style="width: 100px" class="text-right">');
  161. html.push(node.tp_cache.end_sf_tp || '');
  162. html.push('</td>');
  163. }
  164. // 本期未付
  165. if (colSetCache.wf_tp.show) {
  166. html.push('<td style="width: 100px" class="text-right">');
  167. html.push(node.tp_cache.wf_tp || '');
  168. html.push('</td>');
  169. }
  170. return html.join('');
  171. },
  172. getNodeTrHtml: function (node, tree) {
  173. const html = [];
  174. html.push(`<tr tree_id="${node.id}" draggable="true">`);
  175. html.push(Utils.getRowTdHtml(node, tree));
  176. html.push(`</tr>`);
  177. return html.join('');
  178. },
  179. reloadTable: function () {
  180. this.calculateAll();
  181. TableHeaderObj.html(Utils.getHeaderHtml());
  182. const html = [];
  183. for (const node of ProjectTree.nodes) {
  184. html.push(Utils.getNodeTrHtml(node, ProjectTree));
  185. }
  186. TableObj.html(html.join(''));
  187. },
  188. getSelectNode: function() {
  189. const selectId = $('tr.table-active').attr('tree_id');
  190. return selectId ? ProjectTree.getItems(selectId) : null;
  191. },
  192. getSelectNodeId: function() {
  193. const selectId = $('tr.table-active').attr('tree_id');
  194. return selectId || setting.treeSetting.rootId;
  195. },
  196. refreshTreeTable: function(result) {
  197. ProjectTree.loadDatas(result);
  198. if (ProjectTree.nodes.length > 0 && $('#no-project').length > 0) window.location.reload();
  199. Utils.reloadTable();
  200. },
  201. refreshRow: function(result) {
  202. const refreshData = ProjectTree.loadPostData(result);
  203. if (!refreshData.update) return;
  204. for (const u of refreshData.update) {
  205. $(`tr[tree_id=${u.id}]`).html(Utils.getRowTdHtml(u, ProjectTree));
  206. }
  207. },
  208. expandByLevel: function(level){
  209. ProjectTree.expandByLevel(level);
  210. for (const node of ProjectTree.nodes) {
  211. const tr = $(`tr[tree_id=${node.id}]`);
  212. if (node.expanded) {
  213. $('.fold-switch', tr).html(`<i class="fa fa-minus-square-o"></i>`);
  214. } else {
  215. $('.fold-switch', tr).html(`<i class="fa fa-plus-square-o"></i>`);
  216. }
  217. if (node.visible) {
  218. tr.show();
  219. } else {
  220. tr.hide();
  221. }
  222. }
  223. }
  224. };
  225. Utils.reloadTable();
  226. $('body').on('click', 'tr[tree_id]', function() {
  227. if ($(this).hasClass('table-active')) {
  228. $(this).removeClass('table-active');
  229. } else {
  230. $('tr[tree_id].table-active').removeClass('table-active');
  231. $(this).addClass('table-active');
  232. }
  233. Utils.refreshAddButton();
  234. });
  235. $('body').on('click', '.fold-switch', function() {
  236. const id = this.getAttribute('id');
  237. const node = ProjectTree.getItems(id);
  238. ProjectTree.setExpanded(node, !node.expanded);
  239. const posterity = ProjectTree.getPosterity(node);
  240. if (node.expanded) {
  241. $(this).html(`<i class="fa fa-minus-square-o"></i>`);
  242. } else {
  243. $(this).html(`<i class="fa fa-plus-square-o"></i>`);
  244. }
  245. for (const p of posterity) {
  246. if (p.visible) {
  247. $(`tr[tree_id=${p.id}]`).show();
  248. } else {
  249. $(`tr[tree_id=${p.id}]`).hide();
  250. }
  251. }
  252. });
  253. const getChildrenLevel = function (node) {
  254. let iLevel = node.tree_level || 1;
  255. if (node.children && node.children.length > 0) {
  256. for (const c of node.children) {
  257. iLevel = Math.max(iLevel, getChildrenLevel(c));
  258. }
  259. }
  260. return iLevel;
  261. };
  262. tenderTreeShowLevel = $.cs_showLevel({
  263. selector: '#show-level',
  264. levels: [
  265. {
  266. type: 'sort', count: 5, visible_count: function () {
  267. return ProjectTree.children.map(getChildrenLevel).reduce((x, y) => { return Math.max(x, y); }, 0) - 1;
  268. }
  269. },
  270. {
  271. type: 'last', title: '最底层', visible: function () {
  272. const count = ProjectTree.children.map(getChildrenLevel).reduce((x, y) => { return Math.max(x, y); }, 0) - 1;
  273. return count > 0;
  274. }
  275. },
  276. ],
  277. showLevel: function (tag) {
  278. switch (tag) {
  279. case "1":
  280. case "2":
  281. case "3":
  282. case "4":
  283. case "5":
  284. Utils.expandByLevel(parseInt(tag));
  285. break;
  286. case "last":
  287. Utils.expandByLevel(20);
  288. break;
  289. default: return;
  290. }
  291. }
  292. });
  293. tenderTreeShowLevel.initShowLevel();
  294. tenderTreeShowLevel.refreshMenuVisible();
  295. return { ProjectTree, TableObj, ...Utils };
  296. })({
  297. treeSetting: { id: 'id', pid: 'tree_pid', level: 'tree_level', order: 'tree_order', rootId: '-1' },
  298. source: projectList,
  299. table: '#projectList',
  300. tableHeader: '#projectListHeader',
  301. });
  302. $('#refresh-cache').click(() => {
  303. const spid = [];
  304. for (const p of projectTreeObj.ProjectTree.nodes) {
  305. if (p.is_folder) continue;
  306. spid.push(p.id);
  307. }
  308. postData('/subproj/info/refreshCache', { spid: spid.join(';') }, function(result) {
  309. for (const r of result) {
  310. const project = projectTreeObj.ProjectTree.nodes.find(x => { return x.id === r.id; });
  311. if (!project) continue;
  312. project.tp_cache = r.tp_cache;
  313. }
  314. projectTreeObj.reloadTable();
  315. });
  316. })
  317. });