|
@@ -0,0 +1,153 @@
|
|
|
+'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) {
|
|
|
+ const html = [];
|
|
|
+ html.push('<tr pid="' + pid + '">');
|
|
|
+ // 名称
|
|
|
+ html.push('<td class="in-' + node.level + '">');
|
|
|
+ if (node.cid) {
|
|
|
+ html.push('<i class="fa fa-folder-o"></i> ', node.name);
|
|
|
+ } else {
|
|
|
+ html.push('<span class="text-muted mr-2">');
|
|
|
+ html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
|
|
|
+ html.push('</span>');
|
|
|
+ //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
|
|
|
+ html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
|
|
|
+ }
|
|
|
+ html.push('</td>');
|
|
|
+ // 创建人
|
|
|
+ html.push('<td>');
|
|
|
+ if (!node.cid) {
|
|
|
+ html.push('<input data-tid="'+ node.id +'" type="radio">');
|
|
|
+ }
|
|
|
+ html.push('</td>');
|
|
|
+ html.push('</tr>');
|
|
|
+ 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('<table class="table table-hover table-bordered">');
|
|
|
+ html.push('<thead>', '<tr>');
|
|
|
+ html.push('<th>名称</th>');
|
|
|
+ html.push('<th width="40">选择</th>');
|
|
|
+ html.push('</tr>', '</thead>');
|
|
|
+ parentId = 0;
|
|
|
+ for (const t of tenderTree) {
|
|
|
+ html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
|
|
|
+ }
|
|
|
+ html.push('</table>');
|
|
|
+ return html.join('');
|
|
|
+ } else {
|
|
|
+ return EmptyTenderHtml.join('');
|
|
|
+ }
|
|
|
+}
|
|
|
+$(document).ready(function () {
|
|
|
+ initTenderTree()
|
|
|
+ $('#copyBtn').click(() => {
|
|
|
+ console.log('1111')
|
|
|
+ const html = getTenderTreeHtml();
|
|
|
+ $('#copyModalContent').html(html)
|
|
|
+ $('#bd-set-8').modal('show')
|
|
|
+ })
|
|
|
+})
|