Browse Source

阶段进度,初始化相关

MaiXinRong 5 months ago
parent
commit
c189d5717e
1 changed files with 25 additions and 4 deletions
  1. 25 4
      app/service/sub_proj_progress.js

+ 25 - 4
app/service/sub_proj_progress.js

@@ -50,11 +50,32 @@ module.exports = app => {
         async init(subProj) {
             if (!subProj) throw '阶段进度数据错误';
 
+            const budgetStd = subProj.std_id ? await this.ctx.service.budgetStd.getDataById(subProj.std_id) : null;
+            const template_id = budgetStd ? budgetStd.progress_template_id.split(',')[0] : '';
+
             const insertData = [];
-            for (const b of defaultData) {
-                const bills = JSON.parse(JSON.stringify(b));
-                this._getDefaultData(bills, subProj.id);
-                insertData.push(bills);
+            if (template_id) {
+                const templateData = await this.ctx.service.tenderNodeTemplate.getData(template_id);
+                for (const tmp of templateData) {
+                    const bills = {
+                        code: tmp.code || '',
+                        name: tmp.name || '',
+                        tree_id: tmp.template_id,
+                        tree_pid: tmp.pid,
+                        tree_level: tmp.level,
+                        tree_order: tmp.order,
+                        tree_full_path: tmp.full_path,
+                        tree_is_leaf: tmp.is_leaf,
+                    };
+                    this._getDefaultData(bills, subProj.id);
+                    insertData.push(bills);
+                }
+            } else {
+                for (const b of defaultData) {
+                    const bills = JSON.parse(JSON.stringify(b));
+                    this._getDefaultData(bills, subProj.id);
+                    insertData.push(bills);
+                }
             }
 
             const operate = await this.db.insert(this.tableName, insertData);