|
|
@@ -221,6 +221,83 @@ module.exports = app => {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 按标段自定义分类生成合同列设置的复制目标树
|
|
|
+ * @param {Object} subProject - 当前子项目
|
|
|
+ * @param {Number} currentTenderId - 当前标段id
|
|
|
+ * @returns {Promise<Array>} - 按树顺序排列的分类和标段
|
|
|
+ */
|
|
|
+ async getContractCopyTenderTreeNodes(subProject, currentTenderId) {
|
|
|
+ const category = await this.getAllCategory(subProject);
|
|
|
+ const levelCategory = category.filter(item => item.level && item.level > 0)
|
|
|
+ .sort((a, b) => a.level - b.level);
|
|
|
+ const tenders = await this.ctx.service.tender.getContractList('', null, 1);
|
|
|
+ const root = {
|
|
|
+ id: 'sub-project-root', name: subProject.name, tree_level: 1, is_folder: true, children: [],
|
|
|
+ };
|
|
|
+
|
|
|
+ for (const tender of tenders) {
|
|
|
+ const tenderCategory = Array.isArray(tender.category) ? tender.category : [];
|
|
|
+ let parent = root;
|
|
|
+ let categoryPath = [];
|
|
|
+ for (const [index, item] of levelCategory.entries()) {
|
|
|
+ const selected = tenderCategory.find(value => String(value.cid) === String(item.id));
|
|
|
+ if (selected) {
|
|
|
+ categoryPath.push({ item, valueId: selected.value });
|
|
|
+ } else {
|
|
|
+ if (index === 0) {
|
|
|
+ categoryPath = tenderCategory.map(value => ({
|
|
|
+ item: category.find(cate => String(cate.id) === String(value.cid)), valueId: value.value,
|
|
|
+ })).filter(value => value.item);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (const pathItem of categoryPath) {
|
|
|
+ const categoryValue = pathItem.item.value.find(value => String(value.id) === String(pathItem.valueId));
|
|
|
+ if (!categoryValue) break;
|
|
|
+ let folder = parent.children.find(child => child.is_folder &&
|
|
|
+ String(child.cid) === String(pathItem.item.id) && String(child.vid) === String(pathItem.valueId));
|
|
|
+ if (!folder) {
|
|
|
+ folder = {
|
|
|
+ id: `category-${pathItem.item.id}-${pathItem.valueId}`,
|
|
|
+ cid: pathItem.item.id,
|
|
|
+ vid: pathItem.valueId,
|
|
|
+ name: categoryValue.value,
|
|
|
+ sort: categoryValue.sort,
|
|
|
+ tree_level: parent.tree_level + 1,
|
|
|
+ is_folder: true,
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+ parent.children.push(folder);
|
|
|
+ }
|
|
|
+ parent = folder;
|
|
|
+ }
|
|
|
+ parent.children.push({
|
|
|
+ id: tender.id,
|
|
|
+ name: tender.name,
|
|
|
+ tree_level: parent.tree_level + 1,
|
|
|
+ is_folder: false,
|
|
|
+ current: String(tender.id) === String(currentTenderId),
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ const result = [];
|
|
|
+ const stack = [root];
|
|
|
+ while (stack.length) {
|
|
|
+ const node = stack.pop();
|
|
|
+ result.push(node);
|
|
|
+ if (!node.children) continue;
|
|
|
+ node.children.sort((a, b) => {
|
|
|
+ if (a.is_folder !== b.is_folder) return a.is_folder ? -1 : 1;
|
|
|
+ if (a.is_folder) return Number(a.sort || 0) - Number(b.sort || 0);
|
|
|
+ return a.name.localeCompare(b.name, 'zh-Hans-CN');
|
|
|
+ });
|
|
|
+ for (let index = node.children.length - 1; index >= 0; index--) stack.push(node.children[index]);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return Category;
|