| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 | 
							- '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('<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"> '+ (node.copy_id === tender.copy_id ? 'checked' : '') + '/>');
 
-         html.push(`<input data-tid=${node.id} type="radio" ${node.id === tender.copy_id ? 'checked' : ''}>`);
 
-     }
 
-     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(() => {
 
-         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()
 
-             })
 
-         }
 
-     });
 
- })
 
 
  |