'use strict'; /** * * * @author Mai * @date 2018/10/11 * @version */ const EmptyTenderHtml = [ '
', '

还没有标段数据

', '
' ]; // levelTree - setting const levelTreeSetting = { view: { selectedMulti: false }, data: { simpleData: { idKey: 'lid', pIdKey: 'lpId', rootPId: 0, enable: true, } }, edit: { enable: true, showRemoveBtn: false, showRenameBtn: false, drag: { autoExpandTrigger: true, isCopy: false, isMove: true, prev: false, next: false, inner: true, } }, callback: { beforeDrop: beforeDropNode, onDrop: onDropNode, } }; const levelNodes =[]; const tenderTree = []; let parentId = 0; function createTree() { const zTree = $.fn.zTree.getZTreeObj('treeLevel'); if (zTree) { zTree.destroy(); } $.fn.zTree.init($("#treeLevel"), levelTreeSetting, levelNodes); } function beforeDropNode(treeId, treeNodes, targetNode, moveType, isCopy) { if (targetNode !== null && targetNode.lid !== 1) { const parent = targetNode.getParentNode(); if (parent && parent.lid === 1) { return false; } } for (var i=0,l=treeNodes.length; i= 2) { for (const c of targetNode.children) { if (c.lid !== treeNodes[0].lid) { zTree.moveNode(treeNodes[0], c, 'inner'); } } } } } // 查询方法 function findNode (key, value, arr) { for (const a of arr) { if (a[key] && a[key] === value) { return a; } } } function getPId(level) { if (level !== 1) { const p = findNode('level', level - 1, levelNodes); if (p) { return p.lid } else { return 1; } } else { return 2; } } // 分类数据排序 function sortCategory() { category.sort(function (a, b) { return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id; }); } // 初始化分类树结构数据 function initCategoryLevelNode() { levelNodes.splice(0, levelNodes.length); levelNodes.push( { lid:1, lpId:0, name:"可用类别", open:true, isParent: true, drag: false}, { lid:2, lpId:0, name:"已用类别", open:true, isParent: true, drag: false} ); for (const c of category) { const cate = JSON.parse(JSON.stringify(c)); cate.lid = levelNodes.length + 1; cate.open = true; cate.dropRoot = false; if (!cate.level) { cate.lpId = 1; levelNodes.push(cate); } else { cate.lpId = getPId(cate.level); levelNodes.push(cate); } } } // 新建标段 -- 分类属性选择 function getCategoryHtml() { function getSelectCategoryHtml (cate) { const html = []; html.push('
'); html.push('', cate.name, ''); html.push(''); html.push('
'); return html.join(''); } function getRadioCategoryHtml (cate) { const html = []; html.push('
'); html.push('', cate.name, ''); html.push('
'); for (const iV in cate.value) { const v = cate.value[iV]; html.push('
'); html.push(''); html.push(''); html.push('
'); } html.push('
'); html.push('
'); return html.join(''); } const html = []; for (const c of category) { // if (c.type === categoryType.key.dropDown) { html.push(getSelectCategoryHtml(c)); // } else if (c.type === categoryType.key.radio) { // html.push(getRadioCategoryHtml(c)); // } } return html.join(''); } // 初始化TenderTree数据 function calculateParent(node) { if (node.children && node.cid) { node.total_price = 0; node.gather_tp = 0; node.end_contract_tp = 0; node.end_qc_tp = 0; node.end_gather_tp = 0; node.pre_gather_tp = 0; node.yf_tp = 0; node.end_yf_tp = 0; node.advance_tp = 0; for (const c of node.children) { calculateParent(c); node.total_price = ZhCalc.add(node.total_price, c.total_price); node.gather_tp = ZhCalc.add(node.gather_tp, c.gather_tp); node.end_contract_tp = ZhCalc.add(node.end_contract_tp, c.end_contract_tp); node.end_qc_tp = ZhCalc.add(node.end_qc_tp, c.end_qc_tp); node.end_gather_tp = ZhCalc.add(node.end_gather_tp, c.end_gather_tp); node.pre_gather_tp = ZhCalc.add(node.pre_gather_tp, c.pre_gather_tp); node.yf_tp = ZhCalc.add(node.yf_tp, c.yf_tp); node.end_yf_tp = ZhCalc.add(node.end_yf_tp, c.end_yf_tp); node.advance_tp = ZhCalc.add(node.advance_tp, c.advance_tp); } } } function initTenderTree () { const levelCategory = category.filter(function (c) { return c.level && c.level > 0; }); function findCategoryNode(cid, value, array) { for (const a of array) { if (a.cid === cid && a.vid === value) { return a; } } } function getCategoryNode(category, value, parent, i = null) { const array = parent ? parent.children : tenderTree; let cate = findCategoryNode(category.id, value, array); if (!cate) { const cateValue = findNode('id', value, category.value); if (!cateValue) return null; cate = { cid: category.id, vid: value, name: cateValue.value, children: [], level: i ? i : category.level, sort_id: ++parentId, sort: cateValue.sort, }; array.push(cate); } return cate; } function loadTenderCategory (tender) { let tenderCategory = null; for (const [index, lc] of levelCategory.entries()) { const tenderCate = findNode('cid', lc.id, tender.category); if (tenderCate) { tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory); } else { if (index === 0 && tender.category) { for (const [i,c] of tender.category.entries()) { const cate = findNode('id', c.cid, category); tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1); } } return tenderCategory; } } return tenderCategory; } function calculateTender(tender) { if (tender.lastStage) { tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp); tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp); tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp); tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp); tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp); tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp); tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp); } } tenderTree.splice(0, tenderTree.length); for (const t of tenders) { calculateTender(t); t.valid = true; delete t.level; if (t.category && levelCategory.length > 0) { const parent = loadTenderCategory(t); if (parent) { t.level = parent.level + 1; parent.children.push(t); } else { tenderTree.push(t); } } else { tenderTree.push(t); } } sortTenderTree(); for (const t of tenderTree) { calculateParent(t); } } function recursiveGetTenderNodeHtml (node, arr, pid) { const html = []; html.push(''); // 名称 html.push(''); if (node.cid) { html.push(' ', node.name); } else { html.push(''); html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├'); html.push(''); //html.push('', node[c.field], ''); html.push('', node.name, ''); } html.push(''); // 计量模式 html.push(''); if (node.measure_type) { html.push(node.measure_type === measureType.tz.value ? '0号台账' : '工程量清单'); } html.push(''); // 计量进度 html.push(''); if (!node.cid && node.cur_flow) { html.push(node.cur_flow.title + ' (' + '' + node.cur_flow.status + '' + ')'); } html.push(''); // 当前流程 html.push(''); if (!node.cid && node.cur_flow) { html.push(node.cur_flow.name + ' ' + '' + node.cur_flow.status + ''); } html.push(''); // 上一流程审批时间 html.push(''); if (!node.cid && node.pre_flow) { html.push(node.pre_flow.name + ' ' + moment(node.pre_flow.time).format('YYYY-MM-DD')); } html.push(''); // 0号台账合同 html.push(''); html.push(node.total_price || ''); html.push(''); // 本期完成 html.push(''); html.push(node.gather_tp || ''); html.push(''); // 截止本期合同 html.push(''); html.push(node.end_contract_tp || ''); html.push(''); // 截止本期变更 html.push(''); html.push(node.end_qc_tp || ''); html.push(''); // 截止本期完成 html.push(''); html.push(node.end_gather_tp || ''); html.push(''); // 截止上期完成 html.push(''); html.push(node.pre_gather_tp || ''); html.push(''); // 预付款 html.push(''); html.push(node.advance_tp || ''); html.push(''); // 本期应付 html.push(''); html.push(node.yf_tp || ''); html.push(''); // 截止本期应付 html.push(''); html.push(node.end_yf_tp || ''); html.push(''); html.push(''); if (node.children) { for (const c of node.children) { html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id)); } } return html.join(''); } // 根据TenderTree数据获取Html代码 function getTenderTreeHtml () { if (tenderTree.length > 0) { const html = []; html.push(''); html.push('', ''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push(''); html.push('', ''); parentId = 0; for (const t of tenderTree) { html.push(recursiveGetTenderNodeHtml(t, tenderTree, '')); } html.push('
', '标段名称', '', '计量模式', '', '计量进度', '', '当前流程', '', '上一流程审批时间', '', '0号台账', '', '本期完成', '', '截止本期合同', '', '截止本期变更', '', '截止本期完成', '', '截止上期完成', '', '预付款', '', '', '本期应付', '', '截止本期应付', '
'); return html.join(''); } else { return EmptyTenderHtml.join(''); } } function bindTenderUrl() { $('.c-body').on('click', 'a', function () { const tenderId = parseInt($(this).attr('id')); const tender = _.find(tenders, function (t) { return t.id === tenderId; }); if (!tender) return; if (!tender.measure_type && tender.user_id !== userID) return; if (tender.measure_type) { // window.location.href = '/tender/' + tenderId; window.open('/tender/' + tenderId, '_blank'); } else { for (const a of $('a', '#jlms')) { a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst'); } $('#jlms').modal('show'); } }); } $(document).ready(() => { autoFlashHeight(); sortCategory(); // 初始化分类数据 initCategoryLevelNode(); $('.modal-body', '#add-bd').append(getCategoryHtml()); // 初始化标段树结构 initTenderTree(); $('.c-body').html(getTenderTreeHtml()); bindTenderUrl(); localHideList(); // 分类 $('#cate-set').on('show.bs.modal', function () { createTree(); }); $('#set-cate-ok').click(function () { const data = []; const zTree = $.fn.zTree.getZTreeObj('treeLevel'); for (const c of category) { const node = zTree.getNodeByParam('id', c.id); const parent = node.getParentNode(); if (parent.lid === 1) { data.push({id: c.id, level: 0}); } else { data.push({id: c.id, level: node.getPath().length - 1}); } } postData('/setting/category/level', data, function (rst) { for (const d of data) { const c = findNode('id', d.id, category); c.level = d.level; } sortCategory(); initCategoryLevelNode(); initTenderTree(); $('.c-body').html(getTenderTreeHtml()); localHideList(); $('#cate-set').modal('hide'); }); }); // 新增标段 $('#add-bd-ok').click(function () { const data = { name: cleanSymbols($('[name=name]', '#add-bd').val()), valuation: $('[name=valuation]:checked').val(), category: [], }; if (!data.name || data.name === '') { // TODO 提示用户 return; } for (const c of category) { if (parseInt($('select', '[cate-id=' + c.id + ']').val()) !== 0) { const cate = {cid: c.id}; // if (c.type === categoryType.key.dropDown) { cate.value = parseInt($('select', '[cate-id=' + c.id + ']').val()); // } else if (c.type === categoryType.key.radio) { // cate.value = parseInt($('input:checked', '[cate-id=' + c.id + ']').val()); // } data.category.push(cate); } } $('#hide-all').show(); postData('/list/add', data, function (result) { tenders.push(result); initTenderTree(); $('.c-body').html(getTenderTreeHtml()); bindTenderUrl(); localHideList(); $('#add-bd').modal('hide'); $('[name=name]', '#add-bd').val(''); $('#hide-all').hide(); }); }); });