');
if (node.children) {
for (const c of node.children) {
html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id));
}
}
return html.join('');
}
function getTenderTreeHeaderHtml() {
const html = [];
html.push('
');
html.push('', '
');
html.push('
', '标段名称', '
');
html.push('
', '创建人', '
');
html.push('
', '创建时间', '
');
html.push('
', '完成期数', '
');
html.push('
', '管理', '
');
html.push('
', '');
return html.join('');
}
// 根据TenderTree数据获取Html代码
function getTenderTreeHtml () {
if (tenderTree.length > 0) {
const html = [];
html.push(getTenderTreeHeaderHtml());
parentId = 0;
for (const t of tenderTree) {
html.push(recursiveGetTenderNodeHtml(t, tenderTree, ''));
}
html.push('
');
return html.join('');
} else {
return EmptyTenderHtml.join('');
}
}
function bindTenderUrl() {
// 打开标段
$('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;
});
if (tender.measure_type) {
window.location.href = '/tender/' + tenderId;
} else {
for (const a of $('a', '#jlms')) {
a.href = '/tender/' + tenderId + '/type?type=' + $(a).attr('mst');
}
$('#jlms').modal('show');
}
});
// 编辑
$('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);
$('input[type=radio]', '#add-bd').prop('checked', false);
$('option[value=0]', '#edit-bd').prop('selected', true);
for (const c of tender.category) {
// $('input[value=' + c.value + ']', '#edit-bd').prop('checked', 'checked');
$('option[value=' + c.value + ']', '#edit-bd').prop('selected', true);
}
$('#edit-bd-ok').attr('tid', tid);
$('#edit-bd').modal('show');
});
// 删除
$('body').on('click', '.c-body a[name=del]', function () {
$('#del-bd-ok').attr('tid', $(this).parent().attr('tid'));
$('#del-bd').modal('show');
});
}
$(document).ready(() => {
autoFlashHeight();
sortCategory();
// 初始化分类数据
initCategoryLevelNode();
$('.modal-body', '#add-bd').append(getCategoryHtml());
$('.modal-body', '#edit-bd').append(getCategoryHtml());
// 初始化标段树结构
initTenderTree();
$('.c-body').html(getTenderTreeHtml());
bindTenderUrl();
localHideList();
// 分类
$('#cate-set').on('show.bs.modal', function () {
createTree();
});
$('#set-cate-ok').click(function () {
const data = [];
const zTree = $.fn.zTree.getZTreeObj('treeLevel');
for (const c of category) {
const node = zTree.getNodeByParam('id', c.id);
const parent = node.getParentNode();
if (parent.lid === 1) {
data.push({id: c.id, level: 0});
} else {
data.push({id: c.id, level: node.getPath().length - 1});
}
}
postData('/setting/category/level', data, function (rst) {
for (const d of data) {
const c = findNode('id', d.id, category);
c.level = d.level;
}
sortCategory();
initCategoryLevelNode();
initTenderTree();
$('.c-body').html(getTenderTreeHtml());
localHideList();
$('#cate-set').modal('hide');
});
});
$('a[name=add]').click(function () {
$('input[type=radio]', '#edit-bd').prop('checked', false);
$('input[type=radio]', '#add-bd').eq(0).prop('checked', true);
});
// 新增标段
$('#add-bd-ok').click(function () {
const data = {
name: $('[name=name]', '#add-bd').val(),
valuation: $('[name=valuation]:checked').val(),
category: [],
};
if (!data.name || data.name === '') {
// TODO 提示用户
return;
}
for (const c of category) {
const cateObj = $('[cate-id=' + c.id + ']', '#add-bd');
if (parseInt($('select', cateObj).val()) !== 0) {
const cate = {cid: c.id};
cate.value = parseInt($('select', cateObj).val());
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);
initTenderTree();
$('.c-body').html(getTenderTreeHtml());
bindTenderUrl();
localHideList();
$('#add-bd').modal('hide');
$('[name=name]', '#add-bd').val('');
});
});
// 编辑标段
$('#edit-bd-ok').click(function () {
const data = {
id: parseInt($(this).attr('tid')),
name: $('[name=name]', '#edit-bd').val(),
category: [],
};
if (!data.name || data.name === '') {
// TODO 提示用户
return;
}
for (const c of category) {
const cateObj = $('[cate-id=' + c.id + ']', '#edit-bd');
if (parseInt($('select', cateObj).val()) !== 0) {
const cate = {cid: c.id};
cate.value = parseInt($('select', cateObj).val());
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});
_.assign(tender, result);
initTenderTree();
$('.c-body').html(getTenderTreeHtml());
bindTenderUrl();
localHideList();
$('#edit-bd').modal('hide');
});
});
// 删除标段
$('#del-bd-ok').click(function () {
const tid = parseInt($(this).attr('tid'));
if (tid >= 0) {
postData('/list/del', [tid], function (result) {
function getCategory(arr, id) {
for (const a of arr) {
if (a.cid) {
const ac = getCategory(a.children, id);
if (ac) {
return ac;
}
} else if (a.id === id) {
return arr;
}
}
return null;
}
for (const rid of result) {
const tr = $('td[tid=' + rid + ']').parent();
const arr = getCategory(tenderTree, rid);
if (arr) {
const a = arr.find(function (x) {
return x.id === rid;
});
if (arr.length > 1 && arr.indexOf(a) === arr.length - 1) {
const span = $('span', tr.prev());
span.text('└');
}
arr.splice(arr.indexOf(a), 1);
}
_.remove(tenders, function (n) {
return n.id === rid;
});
tr.remove();
$('#del-bd').modal('hide');
}
});
} else {
$('#del-bd').modal('hide');
}
});
});