sub_project_info.js 15 KB

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