|  | @@ -7,7 +7,169 @@
 | 
	
		
			
				|  |  |   * @date 2020/10/09
 | 
	
		
			
				|  |  |   * @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,
 | 
	
		
			
				|  |  | +            };
 | 
	
		
			
				|  |  | +            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, this_code, this_status, aidList = []) {
 | 
	
		
			
				|  |  | +    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>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
 | 
	
		
			
				|  |  | +    html.push('<td>');
 | 
	
		
			
				|  |  | +    if (!node.cid) {
 | 
	
		
			
				|  |  | +        let auditList = [];
 | 
	
		
			
				|  |  | +        let tender_status = 1;
 | 
	
		
			
				|  |  | +        if(cur_tenderid === node.id) {
 | 
	
		
			
				|  |  | +            html.push(sp_status_list[this_status].name);
 | 
	
		
			
				|  |  | +            auditList = aidList;
 | 
	
		
			
				|  |  | +            tender_status = this_status;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            html.push(sp_status_list[node.shenpiInfo[this_code]].name);
 | 
	
		
			
				|  |  | +            auditList = node.shenpiauditList[this_code];
 | 
	
		
			
				|  |  | +            tender_status = node.shenpiInfo[this_code];
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
 | 
	
		
			
				|  |  | +            const nameList = [];
 | 
	
		
			
				|  |  | +            if(auditList) {
 | 
	
		
			
				|  |  | +                for (const uid of auditList) {
 | 
	
		
			
				|  |  | +                    const user = _.find(accountList, { id: uid });
 | 
	
		
			
				|  |  | +                    nameList.push(user.name);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
 | 
	
		
			
				|  |  | +                'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    html.push('</td>');
 | 
	
		
			
				|  |  | +    html.push('<td>');
 | 
	
		
			
				|  |  | +    if (!node.cid) {
 | 
	
		
			
				|  |  | +        html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    html.push('</td>');
 | 
	
		
			
				|  |  | +    html.push('</tr>');
 | 
	
		
			
				|  |  | +    if (node.children) {
 | 
	
		
			
				|  |  | +        for (const c of node.children) {
 | 
	
		
			
				|  |  | +            html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id, this_code, this_status, aidList));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    return html.join('');
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +// 根据TenderTree数据获取Html代码
 | 
	
		
			
				|  |  | +function getTenderTreeHtml (this_code, this_status, aidList = []) {
 | 
	
		
			
				|  |  | +    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="100">审批流程</th>');
 | 
	
		
			
				|  |  | +        html.push('<th width="40">选择</th>');
 | 
	
		
			
				|  |  | +        html.push('</tr>', '</thead>');
 | 
	
		
			
				|  |  | +        parentId = 0;
 | 
	
		
			
				|  |  | +        for (const t of tenderTree) {
 | 
	
		
			
				|  |  | +            html.push(recursiveGetTenderNodeHtml(t, tenderTree, '', this_code, this_status, aidList));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        html.push('</table>');
 | 
	
		
			
				|  |  | +        return html.join('');
 | 
	
		
			
				|  |  | +    } else {
 | 
	
		
			
				|  |  | +        return EmptyTenderHtml.join('');
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  |  $(document).ready(function () {
 | 
	
		
			
				|  |  |      let timer = null;
 | 
	
		
			
				|  |  |      let oldSearchVal = null;
 | 
	
	
		
			
				|  | @@ -86,8 +248,7 @@ $(document).ready(function () {
 | 
	
		
			
				|  |  |              status: this_status
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          const _self = $(this);
 | 
	
		
			
				|  |  | -        const tenderId = window.location.pathname.split('/')[2];
 | 
	
		
			
				|  |  | -        postData('/tender/' + tenderId + '/shenpi/save', prop, function (data) {
 | 
	
		
			
				|  |  | +        postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
 | 
	
		
			
				|  |  |              if (this_status === sp_status.sqspr) {
 | 
	
		
			
				|  |  |                  _self.parents('.form-group').siblings('.lc-show').html('');
 | 
	
		
			
				|  |  |              } else if (this_status === sp_status.gdspl) {
 | 
	
	
		
			
				|  | @@ -145,8 +306,7 @@ $(document).ready(function () {
 | 
	
		
			
				|  |  |                  type: 'add',
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  |              const _self = $(this);
 | 
	
		
			
				|  |  | -            const tenderId = window.location.pathname.split('/')[2];
 | 
	
		
			
				|  |  | -            postData('/tender/' + tenderId + '/shenpi/audit/save', prop, function (data) {
 | 
	
		
			
				|  |  | +            postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
 | 
	
		
			
				|  |  |                  if (this_status === sp_status.gdspl) {
 | 
	
		
			
				|  |  |                      _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -168,8 +328,7 @@ $(document).ready(function () {
 | 
	
		
			
				|  |  |              type: 'del',
 | 
	
		
			
				|  |  |          };
 | 
	
		
			
				|  |  |          const _self = $(this);
 | 
	
		
			
				|  |  | -        const tenderId = window.location.pathname.split('/')[2];
 | 
	
		
			
				|  |  | -        postData('/tender/' + tenderId + '/shenpi/audit/save', prop, function (data) {
 | 
	
		
			
				|  |  | +        postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
 | 
	
		
			
				|  |  |              if (this_status === sp_status.gdspl) {
 | 
	
		
			
				|  |  |                  const _selflc = _self.parents('.lc-show');
 | 
	
		
			
				|  |  |                  _self.parents('li').remove();
 | 
	
	
		
			
				|  | @@ -257,4 +416,57 @@ $(document).ready(function () {
 | 
	
		
			
				|  |  |              '                                        </li>';
 | 
	
		
			
				|  |  |          return html;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    initTenderTree();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    $('.set-otherTender').on('click', function () {
 | 
	
		
			
				|  |  | +        const this_code = $(this).data('code');
 | 
	
		
			
				|  |  | +        const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
 | 
	
		
			
				|  |  | +        const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
 | 
	
		
			
				|  |  | +        const aidList = [];
 | 
	
		
			
				|  |  | +        for (let i = 0; i < aid_num; i++) {
 | 
	
		
			
				|  |  | +            const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
 | 
	
		
			
				|  |  | +            aidList.push(aid);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        const html = getTenderTreeHtml(this_code, this_status, aidList);
 | 
	
		
			
				|  |  | +        $('#shenpi-name').text($(this).data('name'));
 | 
	
		
			
				|  |  | +        $('#shenpi_code').val(this_code);
 | 
	
		
			
				|  |  | +        $('#shenpi_status').val(this_status);
 | 
	
		
			
				|  |  | +        $('#shenpi_auditors').val(aidList.join(','));
 | 
	
		
			
				|  |  | +        $('#tender-list').html(html);
 | 
	
		
			
				|  |  | +        setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    $('#save-other-shenpi').click(function () {
 | 
	
		
			
				|  |  | +        $(this).attr('disabled', true);
 | 
	
		
			
				|  |  | +        const num = $('#tender-list input:checked').length;
 | 
	
		
			
				|  |  | +        if (num < 2) {
 | 
	
		
			
				|  |  | +            toastr.warning('请选择需要设置审批同步的标段');
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        const data = {
 | 
	
		
			
				|  |  | +            type: 'copy2ot',
 | 
	
		
			
				|  |  | +            status: $('#shenpi_status').val(),
 | 
	
		
			
				|  |  | +            code: $('#shenpi_code').val(),
 | 
	
		
			
				|  |  | +        };
 | 
	
		
			
				|  |  | +        if(data.code !== shenpi_status.gdspl) {
 | 
	
		
			
				|  |  | +            data.aidList = $('#shenpi_auditors').val();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 获取已选中的标段
 | 
	
		
			
				|  |  | +        const tenderList = [];
 | 
	
		
			
				|  |  | +        for (let i = 0; i < num; i++) {
 | 
	
		
			
				|  |  | +            const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
 | 
	
		
			
				|  |  | +            if (tid !== cur_tenderid) {
 | 
	
		
			
				|  |  | +                tenderList.push(tid);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        data.tidList = tenderList.join(',');
 | 
	
		
			
				|  |  | +        postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
 | 
	
		
			
				|  |  | +            toastr.success('设置成功');
 | 
	
		
			
				|  |  | +            setTimeout(function () {
 | 
	
		
			
				|  |  | +                window.location.reload();
 | 
	
		
			
				|  |  | +            }, 1000)
 | 
	
		
			
				|  |  | +        })
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  |  });
 |