|  | @@ -45,6 +45,7 @@ const levelTreeSetting = {
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  const levelNodes =[];
 | 
	
		
			
				|  |  |  const tenderTree = [];
 | 
	
		
			
				|  |  | +let parentId = 0;
 | 
	
		
			
				|  |  |  function createTree() {
 | 
	
		
			
				|  |  |      const zTree = $.fn.zTree.getZTreeObj('treeLevel');
 | 
	
		
			
				|  |  |      if (zTree) {
 | 
	
	
		
			
				|  | @@ -188,7 +189,7 @@ function initTenderTree () {
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | -    function getCategoryNode(category, value, parent) {
 | 
	
		
			
				|  |  | +    function getCategoryNode(category, value, parent, i = null) {
 | 
	
		
			
				|  |  |          const array = parent ?  parent.children : tenderTree;
 | 
	
		
			
				|  |  |          let cate = findCategoryNode(category.id, value, array);
 | 
	
		
			
				|  |  |          if (!cate) {
 | 
	
	
		
			
				|  | @@ -199,19 +200,27 @@ function initTenderTree () {
 | 
	
		
			
				|  |  |                  vid: value,
 | 
	
		
			
				|  |  |                  name: cateValue.value,
 | 
	
		
			
				|  |  |                  children: [],
 | 
	
		
			
				|  |  | -                level: category.level,
 | 
	
		
			
				|  |  | +                level: i ? i : category.level,
 | 
	
		
			
				|  |  | +                sort_id: ++parentId,
 | 
	
		
			
				|  |  |              };
 | 
	
		
			
				|  |  |              array.push(cate);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return cate;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      function loadTenderCategory (tender) {
 | 
	
		
			
				|  |  |          let tenderCategory = null;
 | 
	
		
			
				|  |  | -        for (const lc of levelCategory) {
 | 
	
		
			
				|  |  | +        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;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -220,6 +229,7 @@ function initTenderTree () {
 | 
	
		
			
				|  |  |      tenderTree.splice(0, tenderTree.length);
 | 
	
		
			
				|  |  |      for (const t of tenders) {
 | 
	
		
			
				|  |  |          t.valid = true;
 | 
	
		
			
				|  |  | +        delete t.level;
 | 
	
		
			
				|  |  |          if (t.category && levelCategory.length > 0) {
 | 
	
		
			
				|  |  |              const parent = loadTenderCategory(t);
 | 
	
		
			
				|  |  |              if (parent) {
 | 
	
	
		
			
				|  | @@ -233,13 +243,13 @@ function initTenderTree () {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | -function recursiveGetTenderNodeHtml (node, arr) {
 | 
	
		
			
				|  |  | +function recursiveGetTenderNodeHtml (node, arr, pid) {
 | 
	
		
			
				|  |  |      const html = [];
 | 
	
		
			
				|  |  | -    html.push('<tr>');
 | 
	
		
			
				|  |  | +    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);
 | 
	
		
			
				|  |  | +        html.push('<span class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <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 ? '└' : '├');
 | 
	
	
		
			
				|  | @@ -260,7 +270,7 @@ function recursiveGetTenderNodeHtml (node, arr) {
 | 
	
		
			
				|  |  |      // 管理
 | 
	
		
			
				|  |  |      html.push('<td tid="' + node.id + '">');
 | 
	
		
			
				|  |  |      if (!node.cid) {
 | 
	
		
			
				|  |  | -        html.push('<a href="#javascript: void(0)" name="edit" class="btn btn-outline-primary btn-sm">编辑</a>');
 | 
	
		
			
				|  |  | +        html.push('<a href="javascript: void(0)" name="edit" class="btn btn-outline-primary btn-sm">编辑</a>');
 | 
	
		
			
				|  |  |          if (node.lastStage === null || node.lastStage === undefined) {
 | 
	
		
			
				|  |  |              html.push('<a href="javascript: void(0)" name="del" class="btn btn-outline-danger btn-sm ml-1">删除</a>');
 | 
	
		
			
				|  |  |          } else {
 | 
	
	
		
			
				|  | @@ -271,7 +281,7 @@ function recursiveGetTenderNodeHtml (node, arr) {
 | 
	
		
			
				|  |  |      html.push('</tr>');
 | 
	
		
			
				|  |  |      if (node.children) {
 | 
	
		
			
				|  |  |          for (const c of node.children) {
 | 
	
		
			
				|  |  | -            html.push(recursiveGetTenderNodeHtml(c, node.children));
 | 
	
		
			
				|  |  | +            html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      return html.join('');
 | 
	
	
		
			
				|  | @@ -294,7 +304,7 @@ function getTenderTreeHtml () {
 | 
	
		
			
				|  |  |          html.push('<table class="table table-hover table-bordered">');
 | 
	
		
			
				|  |  |          html.push(getTenderTreeHeaderHtml());
 | 
	
		
			
				|  |  |          for (const t of tenderTree) {
 | 
	
		
			
				|  |  | -            html.push(recursiveGetTenderNodeHtml(t, tenderTree));
 | 
	
		
			
				|  |  | +            html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          html.push('</table>');
 | 
	
		
			
				|  |  |          return html.join('');
 | 
	
	
		
			
				|  | @@ -304,7 +314,7 @@ function getTenderTreeHtml () {
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  function bindTenderUrl() {
 | 
	
		
			
				|  |  |      // 打开标段
 | 
	
		
			
				|  |  | -    $('a[name=name]', '.c-body').bind('click', function () {
 | 
	
		
			
				|  |  | +    $('body').on('click', '.c-body a[name=name]', function () {
 | 
	
		
			
				|  |  |          const tenderId = parseInt($(this).attr('id'));
 | 
	
		
			
				|  |  |          const tender = _.find(tenders, function (t) {
 | 
	
		
			
				|  |  |              return t.id === tenderId;
 | 
	
	
		
			
				|  | @@ -319,7 +329,7 @@ function bindTenderUrl() {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      // 编辑
 | 
	
		
			
				|  |  | -    $('a[name=edit]', '.c-body').on('click', function () {
 | 
	
		
			
				|  |  | +    $('body').on('click', '.c-body a[name=edit]', function () {
 | 
	
		
			
				|  |  |          const tid = parseInt($(this).parent().attr('tid'));
 | 
	
		
			
				|  |  |          const tender = _.find(tenders, {id: tid});
 | 
	
		
			
				|  |  |          $('[name=name]', '#edit-bd').val(tender.name);
 | 
	
	
		
			
				|  | @@ -332,7 +342,7 @@ function bindTenderUrl() {
 | 
	
		
			
				|  |  |          $('#edit-bd').modal('show');
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |      // 删除
 | 
	
		
			
				|  |  | -    $('a[name=del]', '.c-body').bind('click', function () {
 | 
	
		
			
				|  |  | +    $('body').on('click', '.c-body a[name=del]', function () {
 | 
	
		
			
				|  |  |          $('#del-bd-ok').attr('tid', $(this).parent().attr('tid'));
 | 
	
		
			
				|  |  |          $('#del-bd').modal('show');
 | 
	
		
			
				|  |  |      });
 | 
	
	
		
			
				|  | @@ -349,6 +359,8 @@ $(document).ready(() => {
 | 
	
		
			
				|  |  |      initTenderTree();
 | 
	
		
			
				|  |  |      $('.c-body').html(getTenderTreeHtml());
 | 
	
		
			
				|  |  |      bindTenderUrl();
 | 
	
		
			
				|  |  | +    console.log(tenderTree);
 | 
	
		
			
				|  |  | +    console.log(category);
 | 
	
		
			
				|  |  |      // 分类
 | 
	
		
			
				|  |  |      $('#cate-set').on('show.bs.modal', function () {
 | 
	
		
			
				|  |  |          createTree();
 | 
	
	
		
			
				|  | @@ -394,14 +406,18 @@ $(document).ready(() => {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          for (const c of category) {
 | 
	
		
			
				|  |  | -            const cate = {cid: c.id};
 | 
	
		
			
				|  |  |              const cateObj = $('[cate-id=' + c.id + ']', '#add-bd');
 | 
	
		
			
				|  |  | -            if (c.type === categoryType.key.dropDown) {
 | 
	
		
			
				|  |  | +            if (parseInt($('select', cateObj).val()) !== 0) {
 | 
	
		
			
				|  |  | +                const cate = {cid: c.id};
 | 
	
		
			
				|  |  |                  cate.value = parseInt($('select', cateObj).val());
 | 
	
		
			
				|  |  | -            } else if (c.type === categoryType.key.radio) {
 | 
	
		
			
				|  |  | -                cate.value = parseInt($('input:checked', cateObj).val());
 | 
	
		
			
				|  |  | +                data.category.push(cate);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            data.category.push(cate);
 | 
	
		
			
				|  |  | +            // if (c.type === categoryType.key.dropDown) {
 | 
	
		
			
				|  |  | +            //     cate.value = parseInt($('select', cateObj).val());
 | 
	
		
			
				|  |  | +            // } else if (c.type === categoryType.key.radio) {
 | 
	
		
			
				|  |  | +            //     cate.value = parseInt($('input:checked', cateObj).val());
 | 
	
		
			
				|  |  | +            // }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          postData('/list/add', data, function (result) {
 | 
	
		
			
				|  |  |              tenders.push(result);
 | 
	
	
		
			
				|  | @@ -424,14 +440,18 @@ $(document).ready(() => {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          for (const c of category) {
 | 
	
		
			
				|  |  | -            const cate = {cid: c.id};
 | 
	
		
			
				|  |  |              const cateObj = $('[cate-id=' + c.id + ']', '#edit-bd');
 | 
	
		
			
				|  |  | -            if (c.type === categoryType.key.dropDown) {
 | 
	
		
			
				|  |  | +            if (parseInt($('select', cateObj).val()) !== 0) {
 | 
	
		
			
				|  |  | +                const cate = {cid: c.id};
 | 
	
		
			
				|  |  |                  cate.value = parseInt($('select', cateObj).val());
 | 
	
		
			
				|  |  | -            } else if (c.type === categoryType.key.radio) {
 | 
	
		
			
				|  |  | -                cate.value = parseInt($('input:checked', cateObj).val());
 | 
	
		
			
				|  |  | +                data.category.push(cate);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            data.category.push(cate);
 | 
	
		
			
				|  |  | +            // if (c.type === categoryType.key.dropDown) {
 | 
	
		
			
				|  |  | +            //     cate.value = parseInt($('select', cateObj).val());
 | 
	
		
			
				|  |  | +            // } else if (c.type === categoryType.key.radio) {
 | 
	
		
			
				|  |  | +            //     cate.value = parseInt($('input:checked', cateObj).val());
 | 
	
		
			
				|  |  | +            // }
 | 
	
		
			
				|  |  | +            // data.category.push(cate);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          postData('/list/update', data, function (result) {
 | 
	
		
			
				|  |  |              const tender = _.find(tenders, {id: result.id});
 | 
	
	
		
			
				|  | @@ -484,4 +504,52 @@ $(document).ready(() => {
 | 
	
		
			
				|  |  |              $('#del-bd').modal('hide');
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    // 展开和收起
 | 
	
		
			
				|  |  | +    $('body').on('click', '.fold-switch', function () {
 | 
	
		
			
				|  |  | +        if ($(this).children('i').hasClass('fa-minus-square-o')) {
 | 
	
		
			
				|  |  | +            $(this).children('i').removeClass('fa-minus-square-o').addClass('fa-plus-square-o');
 | 
	
		
			
				|  |  | +            $(this).attr('title', '展开');
 | 
	
		
			
				|  |  | +            const cid = $(this).attr('cid');
 | 
	
		
			
				|  |  | +            const node = findTenderTreeNode(parseInt(cid), tenderTree);
 | 
	
		
			
				|  |  | +            doTrStatus(returnItem, 'hide');
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            $(this).children('i').removeClass('fa-plus-square-o').addClass('fa-minus-square-o');
 | 
	
		
			
				|  |  | +            $(this).attr('title', '收起');
 | 
	
		
			
				|  |  | +            const cid = $(this).attr('cid');
 | 
	
		
			
				|  |  | +            const node = findTenderTreeNode(parseInt(cid), tenderTree);
 | 
	
		
			
				|  |  | +            doTrStatus(returnItem, 'show');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  |  });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +function doTrStatus(node, status) {
 | 
	
		
			
				|  |  | +    if (status === 'show') {
 | 
	
		
			
				|  |  | +        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').show();
 | 
	
		
			
				|  |  | +        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '收起');
 | 
	
		
			
				|  |  | +        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-plus-square-o').removeClass('fa-minus-square-o').addClass('fa-minus-square-o');
 | 
	
		
			
				|  |  | +    } else {
 | 
	
		
			
				|  |  | +        $('.c-body').find('tr[pid="'+ node.sort_id +'"]').hide();
 | 
	
		
			
				|  |  | +        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch').attr('title', '展开');
 | 
	
		
			
				|  |  | +        $('.c-body').find('tr[pid="'+ node.sort_id +'"] .fold-switch i').removeClass('fa-minus-square-o').removeClass('fa-plus-square-o').addClass('fa-plus-square-o');
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    // 判断是否还有一层
 | 
	
		
			
				|  |  | +    if (node.children) {
 | 
	
		
			
				|  |  | +        for (const c of node.children) {
 | 
	
		
			
				|  |  | +            doTrStatus(c, status);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +let returnItem;
 | 
	
		
			
				|  |  | +const findTenderTreeNode = function(sortId, tree) {
 | 
	
		
			
				|  |  | +    tree.forEach((item) => {
 | 
	
		
			
				|  |  | +        if (item.sort_id !== undefined && item.sort_id === sortId) {
 | 
	
		
			
				|  |  | +            returnItem = item;
 | 
	
		
			
				|  |  | +            return item;
 | 
	
		
			
				|  |  | +        } else if (item.children && item.children.length > 0) {
 | 
	
		
			
				|  |  | +            findTenderTreeNode(sortId, item.children);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 |