123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- $(document).ready(function() {
- const projectTreeObj = (function(setting){
- const ProjectTree = createDragTree(setting.treeSetting);
- ProjectTree.loadDatas(setting.source);
- const TableObj = $(setting.table);
- const TableHeaderObj = $(setting.tableHeader);
- let tenderTreeShowLevel;
- let colSetCache;
- const Utils = {
- calculateFolder: function(node) {
- node.tp_cache = {};
- for (const c of node.children) {
- if (!c.tp_cache) continue;
- for (const prop in c.tp_cache) {
- node.tp_cache[prop] = ZhCalc.add(node.tp_cache[prop], c.tp_cache[prop]);
- }
- }
- },
- calculateSubProject: function(node) {
- node.tp_cache.gather_tp = ZhCalc.sum([node.tp_cache.contract_tp, node.tp_cache.qc_tp, node.tp_cache.pc_tp]);
- 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]);
- 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]);
- node.tp_cache.end_gather_tp = ZhCalc.add(node.tp_cache.end_contract_tp, node.tp_cache.end_qc_tp);
- node.tp_cache.pre_gather_tp = ZhCalc.add(node.tp_cache.pre_contract_tp, node.tp_cache.pre_qc_tp);
- node.tp_cache.end_yf_tp = ZhCalc.add(node.tp_cache.pre_yf_tp, node.tp_cache.yf_tp);
- node.tp_cache.end_sf_tp = ZhCalc.add(node.tp_cache.pre_sf_tp, node.tp_cache.sf_tp);
- node.tp_cache.wf_tp = ZhCalc.sub(node.tp_cache.end_yf_tp, node.tp_cache.end_sf_tp);
- },
- calculateNode: function(node) {
- if (node.children && node.children.length > 0) {
- for (const c of node.children) {
- this.calculateNode(c);
- }
- this.calculateFolder(node);
- } else {
- if (node.is_folder) {
- this.calculateFolder(node)
- } else {
- this.calculateSubProject(node);
- }
- }
- },
- calculateAll: function() {
- for (const p of ProjectTree.children) {
- this.calculateNode(p);
- }
- },
- generateColSetCache: function() {
- const result = {};
- colSet.forEach(x => {
- result[x.field] = { show: x.show, alias: x.alias || x.name };
- });
- return result;
- },
- getHeaderHtml: function() {
- colSetCache = this.generateColSetCache();
- const html = [];
- html.push('<tr>');
- if (colSetCache.name.show) html.push('<th class="text-center" style="min-width: 300px;">', colSetCache.name.alias, '</th>');
- if (colSetCache.contract_price.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.contract_price.alias, '</th>');
- if (colSetCache.total_price.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.total_price.alias, '</th>');
- if (colSetCache.gather_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.gather_tp.alias, '</th>');
- if (colSetCache.end_contract_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_contract_tp.alias, '</th>');
- if (colSetCache.end_qc_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_qc_tp.alias, '</th>');
- if (colSetCache.end_gather_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_gather_tp.alias, '</th>');
- if (colSetCache.pre_gather_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.pre_gather_tp.alias, '</th>');
- 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>');
- if (colSetCache.yf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.yf_tp.alias, '</th>');
- if (colSetCache.end_yf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_yf_tp.alias, '</th>');
- if (colSetCache.sf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.sf_tp.alias, '</th>');
- if (colSetCache.end_sf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.end_sf_tp.alias, '</th>');
- if (colSetCache.wf_tp.show) html.push('<th class="text-center" style="width: 100px">', colSetCache.wf_tp.alias, '</th>');
- html.push('</tr>');
- return html.join('');
- },
- getRowTdHtml: function (node, tree) {
- const html = [];
- // 名称
- if (colSetCache.name.show) {
- html.push('<td width="20%" class="in-' + node.tree_level + '">');
- if (node.is_folder) {
- if (node.children.length > 0) {
- 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);
- } else {
- html.push('<i class="fa fa-folder-o"></i> ', node.name);
- }
- } else {
- html.push(`<span class="text-muted mr-2">${tree.isLastSibling(node) ? '└' : '├'}</span>`);
- html.push(`<a href="/sp/${node.id}/dashboard" name="name" id="${node.id}">`, node.name, '</a>');
- }
- html.push('</td>');
- }
- if (colSetCache.contract_price.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.contract_price || '');
- html.push('</td>');
- }
- // 0号台账合同
- if (colSetCache.total_price.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.total_price || '');
- html.push('</td>');
- }
- // 本期完成
- if (colSetCache.gather_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.gather_tp || '');
- html.push('</td>');
- }
- // 截止本期合同
- if (colSetCache.end_contract_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.end_contract_tp || '');
- html.push('</td>');
- }
- // 截止本期变更
- if (colSetCache.end_qc_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.end_qc_tp || '');
- html.push('</td>');
- }
- // 截止本期完成
- if (colSetCache.end_gather_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.end_gather_tp || '');
- html.push('</td>');
- }
- // 截止上期完成
- if (colSetCache.pre_gather_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.pre_gather_tp || '');
- html.push('</td>');
- }
- // 预付款
- if (colSetCache.advance_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.advance_tp || '');
- html.push('</td>');
- }
- // 本期应付
- if (colSetCache.yf_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.yf_tp || '');
- html.push('</td>');
- }
- // 截止本期应付
- if (colSetCache.end_yf_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.end_yf_tp || '');
- html.push('</td>');
- }
- // 本期实付
- if (colSetCache.sf_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.sf_tp || '');
- html.push('</td>');
- }
- // 截止本期实付
- if (colSetCache.end_sf_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.end_sf_tp || '');
- html.push('</td>');
- }
- // 本期未付
- if (colSetCache.wf_tp.show) {
- html.push('<td style="width: 100px" class="text-right">');
- html.push(node.tp_cache.wf_tp || '');
- html.push('</td>');
- }
- return html.join('');
- },
- getNodeTrHtml: function (node, tree) {
- const html = [];
- html.push(`<tr tree_id="${node.id}" draggable="true">`);
- html.push(Utils.getRowTdHtml(node, tree));
- html.push(`</tr>`);
- return html.join('');
- },
- reloadTable: function () {
- this.calculateAll();
- TableHeaderObj.html(Utils.getHeaderHtml());
- const html = [];
- for (const node of ProjectTree.nodes) {
- html.push(Utils.getNodeTrHtml(node, ProjectTree));
- }
- TableObj.html(html.join(''));
- },
- getSelectNode: function() {
- const selectId = $('tr.table-active').attr('tree_id');
- return selectId ? ProjectTree.getItems(selectId) : null;
- },
- getSelectNodeId: function() {
- const selectId = $('tr.table-active').attr('tree_id');
- return selectId || setting.treeSetting.rootId;
- },
- refreshTreeTable: function(result) {
- ProjectTree.loadDatas(result);
- if (ProjectTree.nodes.length > 0 && $('#no-project').length > 0) window.location.reload();
- Utils.reloadTable();
- },
- refreshRow: function(result) {
- const refreshData = ProjectTree.loadPostData(result);
- if (!refreshData.update) return;
- for (const u of refreshData.update) {
- $(`tr[tree_id=${u.id}]`).html(Utils.getRowTdHtml(u, ProjectTree));
- }
- },
- expandByLevel: function(level){
- ProjectTree.expandByLevel(level);
- for (const node of ProjectTree.nodes) {
- const tr = $(`tr[tree_id=${node.id}]`);
- if (node.expanded) {
- $('.fold-switch', tr).html(`<i class="fa fa-minus-square-o"></i>`);
- } else {
- $('.fold-switch', tr).html(`<i class="fa fa-plus-square-o"></i>`);
- }
- if (node.visible) {
- tr.show();
- } else {
- tr.hide();
- }
- }
- }
- };
- Utils.reloadTable();
- $('body').on('click', 'tr[tree_id]', function() {
- if ($(this).hasClass('table-active')) {
- $(this).removeClass('table-active');
- } else {
- $('tr[tree_id].table-active').removeClass('table-active');
- $(this).addClass('table-active');
- }
- Utils.refreshAddButton();
- });
- $('body').on('click', '.fold-switch', function() {
- const id = this.getAttribute('id');
- const node = ProjectTree.getItems(id);
- ProjectTree.setExpanded(node, !node.expanded);
- const posterity = ProjectTree.getPosterity(node);
- if (node.expanded) {
- $(this).html(`<i class="fa fa-minus-square-o"></i>`);
- } else {
- $(this).html(`<i class="fa fa-plus-square-o"></i>`);
- }
- for (const p of posterity) {
- if (p.visible) {
- $(`tr[tree_id=${p.id}]`).show();
- } else {
- $(`tr[tree_id=${p.id}]`).hide();
- }
- }
- });
- const getChildrenLevel = function (node) {
- let iLevel = node.tree_level || 1;
- if (node.children && node.children.length > 0) {
- for (const c of node.children) {
- iLevel = Math.max(iLevel, getChildrenLevel(c));
- }
- }
- return iLevel;
- };
- tenderTreeShowLevel = $.cs_showLevel({
- selector: '#show-level',
- levels: [
- {
- type: 'sort', count: 5, visible_count: function () {
- return ProjectTree.children.map(getChildrenLevel).reduce((x, y) => { return Math.max(x, y); }, 0) - 1;
- }
- },
- {
- type: 'last', title: '最底层', visible: function () {
- const count = ProjectTree.children.map(getChildrenLevel).reduce((x, y) => { return Math.max(x, y); }, 0) - 1;
- return count > 0;
- }
- },
- ],
- showLevel: function (tag) {
- switch (tag) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- Utils.expandByLevel(parseInt(tag));
- break;
- case "last":
- Utils.expandByLevel(20);
- break;
- default: return;
- }
- }
- });
- tenderTreeShowLevel.initShowLevel();
- tenderTreeShowLevel.refreshMenuVisible();
- return { ProjectTree, TableObj, ...Utils };
- })({
- treeSetting: { id: 'id', pid: 'tree_pid', level: 'tree_level', order: 'tree_order', rootId: '-1' },
- source: projectList,
- table: '#projectList',
- tableHeader: '#projectListHeader',
- });
- $('#refresh-cache').click(() => {
- const spid = [];
- for (const p of projectTreeObj.ProjectTree.nodes) {
- if (p.is_folder) continue;
- spid.push(p.id);
- }
- postData('/subproj/info/refreshCache', { spid: spid.join(';') }, function(result) {
- for (const r of result) {
- const project = projectTreeObj.ProjectTree.nodes.find(x => { return x.id === r.id; });
- if (!project) continue;
- project.tp_cache = r.tp_cache;
- }
- projectTreeObj.reloadTable();
- });
- })
- });
|