'use strict'; /** * * @author LanJianRong * @date 2020/11/13 * @version */ const tenderTree = []; let parentId = 0; // 查询方法 function findNode (key, value, arr) { for (const a of arr) { if (a[key] && a[key] === value) { return a; } } } // 初始化TenderTree数据 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); } } } function recursiveGetTenderNodeHtml (node, arr, pid) { // console.log(node, tender) if (node.id === tender.id) return '' if (node.user_id && parseInt(node.user_id) !== cur_uid) return '' 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.cid) { // html.push(' '+ (node.copy_id === tender.copy_id ? 'checked' : '') + '/>'); html.push(``); } 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('', ''); parentId = 0; for (const t of tenderTree) { html.push(recursiveGetTenderNodeHtml(t, tenderTree, '')); } html.push('
名称选择
'); return html.join(''); } else { return EmptyTenderHtml.join(''); } } $(document).ready(function () { initTenderTree(); const html = getTenderTreeHtml(); $('#copyModalContent').html(html); // $('#copyBtn').click(() => { // const html = getTenderTreeHtml(); // $('#copyModalContent').html(html); // $('#bd-set-8').modal('show'); // }); // // $('#copyModalContent').on('click', 'input[type="radio"]', function() { // $('#copyModalContent tbody').children().each(function () { // $(this).find('input:radio').prop("checked", false); // }) // $(this).prop("checked", true); // }); // // $('#setting-custom').on('click', '.custom-checkbox', function () { // const isChecked = $(this).find('input').prop("checked"); // $(this).find('input').prop("checked", !isChecked); // }) // $('#copy_comfirm_btn').click(function() { // const type = [] // $('#setting-custom').find('input:checked').each(function() { // type.push($(this).data('type')) // }) // if (!type.length) { // return toastr.error('请勾选需要拷贝的属性') // } // const id = $('#copyModalContent').find('input:checked').data('tid'); // if (id) { // postData(window.location.pathname + '/copy-setting', { id, type }, function() { // window.location.reload() // }) // } // }); })