Browse Source

引用文件,树结构显示

MaiXinRong 3 tuần trước cách đây
mục cha
commit
c92afd5e75

+ 10 - 18
app/controller/file_controller.js

@@ -309,22 +309,21 @@ module.exports = app => {
                 const accountInfo = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
                 const userPermission = accountInfo !== undefined && accountInfo.permission !== ''
                     ? JSON.parse(accountInfo.permission) : null;
-                const tenderList = await ctx.service.tender.getList('', userPermission, ctx.session.sessionUser.is_admin);
-
-                const result = tenderList;
-                for (const r of result) {
+                const tenders = await ctx.service.tender.getList('', userPermission, ctx.session.sessionUser.is_admin);
+                for (const r of tenders) {
                     r.advance = await ctx.service.advance.getAllDataByCondition({ columns: ['id', 'order', 'type'], where: { tid: r.id }});
                     r.advance.forEach(a => {
                         const type = advanceConst.typeCol.find(x => { return x.type === a.type });
                         if (type) a.type_str = type.name;
                     });
                     r.stage = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 'order'], where: { tid: r.id, status: auditConst.stage.status.checked } });
-                    r.change = await ctx.service.change.getAllDataByCondition({ columns: ['cid', 'code'], where: { tid: r.id, status: auditConst.flow.status.checked } });
+                    r.change = await ctx.service.change.getAllDataByCondition({ columns: ['cid', 'code'], where: { tid: r.id, status: auditConst.flow.status.checked }, orders: [['in_time', 'asc']] });
                     r.change_apply = await ctx.service.changeApply.getAllDataByCondition({ columns: ['id', 'code'], where: { tid: r.id, status: auditConst.flow.status.checked } });
                     r.change_plan = await ctx.service.changePlan.getAllDataByCondition({ columns: ['id', 'code'], where: { tid: r.id, status: auditConst.flow.status.checked } });
                     r.change_project = await ctx.service.changeProject.getAllDataByCondition({ columns: ['id', 'code'], where: { tid: r.id, status: auditConst.flow.status.checked } });
                 }
-                ctx.body = {err: 0, msg: '', data: result };
+                const category = await this.ctx.service.category.getAllCategory(ctx.subProject);
+                ctx.body = {err: 0, msg: '', data: { category, tenders, selfCategoryLevel: this.ctx.subProject.permission.self_category_level} };
             } catch (error) {
                 ctx.helper.log(error);
                 ctx.body = this.ajaxErrorBody(error, '加载标段信息失败');
@@ -341,14 +340,8 @@ module.exports = app => {
                 case 'att':
                     return await this.ctx.service.stageAtt.getAllDataByCondition({ where: { tid: data.tender_id, sid: stage.order }, order: [['id', 'desc']]});
                 case 'dealPay':
-                    const dpFiles = [];
-                    await this.ctx.service.stage.doCheckStage(stage, this.ctx.session.sessionUser.is_admin);
-                    const stagePays = await this.ctx.service.stagePay.getAllDataByCondition({ where: { sid: stage.id, stimes: stage.curTimes, sorder: stage.curOrder } });
-                    stagePays.forEach(x => {
-                        x.attachment = x.attachment ? JSON.parse(x.attachment) : [];
-                        if (x.attachment.length > 0) imFiles.push(...x.attachment);
-                    });
-                    return dpFiles;
+                    const payAtt = await this.ctx.service.payAtt.getStageData({ sid: stage.id });
+                    return payAtt;
                 case 'stageIm':
                     const imFiles = [];
                     const stageIm = await this.ctx.service.stageDetailAtt.getAllDataByCondition({ where: { sid: stage.id} });
@@ -377,17 +370,17 @@ module.exports = app => {
         }
         async _loadChangePlanAtt(data) {
             if (!data.selectId) throw '参数错误';
-            const result = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { cpid: data.selectId }, order: [['id', 'desc']]});
+            const result = await this.ctx.service.changePlanAtt.getAllDataByCondition({ where: { cpid: data.selectId }, order: [['id', 'desc']]});
             return result;
         }
         async _loadChangeProjectAtt(data) {
             if (!data.selectId) throw '参数错误';
-            const result = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { cpid: data.selectId }, order: [['id', 'desc']]});
+            const result = await this.ctx.service.changeProjectAtt.getAllDataByCondition({ where: { cpid: data.selectId }, order: [['id', 'desc']]});
             return result;
         }
         async _loadChangeApplyAtt(data) {
             if (!data.selectId) throw '参数错误';
-            const result = await this.ctx.service.changeAtt.getAllDataByCondition({ where: { caid: data.selectId }, order: [['id', 'desc']]});
+            const result = await this.ctx.service.changeApplyAtt.getAllDataByCondition({ where: { caid: data.selectId }, order: [['id', 'desc']]});
             return result;
         }
         async loadRelaFiles(ctx) {
@@ -497,7 +490,6 @@ module.exports = app => {
             try {
                 const id = ctx.query.id;
                 await ctx.service.filingTemplateList.delete(id);
-                console.log(ctx.request.headers.referer, id);
                 if (ctx.request.headers.referer.indexOf(id) > 0) {
                     ctx.redirect('/file/template');
                 } else {

+ 66 - 50
app/public/js/file_detail.js

@@ -990,31 +990,40 @@ $(document).ready(function() {
         clearFileSelect() {
             if (!this.tenderTree) return;
 
-            const nodes = this.tenderTree.getNodes();
-            nodes.forEach(node => {
-                const x = node.source_node;
-                x.selectFiles = [];
-                if (x.att) x.att.forEach(la => { la.checked = false });
-                if (x.advance) {
-                    x.advance.forEach(a => {
-                        if (a.files) a.files.forEach(aa => { aa.checked = false });
-                    });
-                }
-                if (x.stage) {
-                    x.stage.forEach(s => {
-                        if (s.att) s.att.forEach(sa => { sa.checked = false });
-                    })
-                }
-            });
+            const tenderTree = this.tenderTree;
+            const recursiveFun = function(nodes) {
+                if (!nodes || nodes.length === 0) return;
+
+                nodes.forEach(node => {
+                    const x = node.source_node;
+                    if (x.tid) {
+                        x.selectFiles = [];
+                        if (x.att) x.att.forEach(la => { la.checked = false });
+                        if (x.advance) {
+                            x.advance.forEach(a => {
+                                if (a.files) a.files.forEach(aa => { aa.checked = false });
+                            });
+                        }
+                        if (x.stage) {
+                            x.stage.forEach(s => {
+                                if (s.att) s.att.forEach(sa => { sa.checked = false });
+                            })
+                        }
+                    } else {
+                        recursiveFun(tenderTree.getNodesByParam('tree_pid', node.id, node));
+                    }
+                });
+            };
+            recursiveFun(this.tenderTree.getNodes());
         }
         refreshSelectHint(){
-            if (this.curTender) {
+            if (this.curTender && this.curTender.source_node.tid) {
                 $('#cur-tender-hint').html(`当前标段,已选${this.curTender.source_node.selectFiles.length}文件`);
             } else {
                 $('#cur-tender-hint').html('');
             }
-            const nodes = this.tenderTree.getNodes();
-            const selectTenders = nodes.filter(x => { return x.source_node.selectFiles.length > 0; });
+            const nodes = this.tenderTree.transformToArray(this.tenderTree.getNodes());
+            const selectTenders = nodes.filter(x => { return x.tid && x.source_node.selectFiles.length > 0; });
             if (selectTenders.length > 0) {
                 const count = selectTenders.reduce((rst, x) => { return rst + x.source_node.selectFiles.length; }, 0);
                 $('#rela-file-hint').html(`已选择${selectTenders.length}个标段,共${count}个文件`);
@@ -1038,11 +1047,17 @@ $(document).ready(function() {
         async showRelaFile(){
             $('#rela-filing-hint').html(`当前目录:${filingObj.getCurFilingFullPath()}`);
             if (!this.tenderTree) {
-                const tenders = await postDataAsync('file/rela/tender', {});
-                const sortNodes = tenders.map(x => {
-                    return { id: x.id, tree_pid: -1, name: x.name, source_node: x, icon: '/public/css/ztree/img/diy/11.png' };
+                const data = await postDataAsync('file/rela/tender', {});
+                const tenderPathTree = Tender2Tree.convert(data.category, data.tenders, null, null, function(node, source) {
+                    _.assign(node, source);
+                }, data.selfCategoryLevel);
+                const sortNodes = tenderPathTree.nodes.map(x => {
+                    const data = { id: x.tmt_id, tree_pid: x.tmt_pid, name: x.name, source_node: x };
+                    if (x.tid) data.icon = '/public/css/ztree/img/diy/11.png';
+                    return data;
                 });
                 this.tenderTree = this.filingTree = $.fn.zTree.init($('#rela-tender'), this.treeSetting, sortNodes);
+                this.tenderTree.expandAll(true);
             }
             this.clearFileSelect();
             this.refreshSelectHint();
@@ -1082,7 +1097,7 @@ $(document).ready(function() {
         }
         refreshTenderFileSubType() {
             const type = this.tenderFileType.find(x => { return x.value === this.rfType.type});
-            if (type.subType && type.subType.length > 0) {
+            if (type && type.subType && type.subType.length > 0) {
                 this.rfType.sub_type = type.subType[0].value;
                 const html= [];
                 for (const tfst of type.subType) {
@@ -1102,18 +1117,6 @@ $(document).ready(function() {
         }
         refreshSelects(tender) {
             this.tenderFileType = [];
-            this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
-            if (tender.stage && tender.stage.length > 0) {
-                const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
-                this.tenderFileType.push({
-                    value: 'stage', text: '计量期',
-                    subType: [
-                        { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
-                        { value: 'dealPay', text: '合同支付', stage: JSON.parse(JSON.stringify(stages)) },
-                        { value: 'stageIm', text: '中间计量', stage: JSON.parse(JSON.stringify(stages)) },
-                    ],
-                });
-            }
             if (tender.advance && tender.advance.length > 0) {
                 const advanceType = [];
                 tender.advance.forEach(x => {
@@ -1128,6 +1131,18 @@ $(document).ready(function() {
                     value: 'advance', text: '预付款', subType: advanceType
                 });
             }
+            if (tender.tid) this.tenderFileType.push({ value: 'ledger', text: '台账附件' });
+            if (tender.stage && tender.stage.length > 0) {
+                const stages = tender.stage.map(x => { return {value: x.id, text: `第${x.order}期`}; });
+                this.tenderFileType.push({
+                    value: 'stage', text: '计量期',
+                    subType: [
+                        { value: 'att', text: '计量附件', stage: JSON.parse(JSON.stringify(stages)) },
+                        { value: 'dealPay', text: '合同支付', stage: JSON.parse(JSON.stringify(stages)) },
+                        { value: 'stageIm', text: '中间计量', stage: JSON.parse(JSON.stringify(stages)) },
+                    ],
+                });
+            }
             if (tender.change && tender.change.length > 0) {
                 const selects = [];
                 tender.change.forEach(x => {
@@ -1138,25 +1153,25 @@ $(document).ready(function() {
             if (tender.change_plan && tender.change_plan.length > 0) {
                 const selects = [];
                 tender.change_plan.forEach(x => {
-                    selects.push({ value: x.cpid, text: x.code })
+                    selects.push({ value: x.id, text: x.code })
                 });
                 this.tenderFileType.push({ value: 'change_plan', text: '变更方案', select: selects });
             }
-            if (tender.change_project && tender.change_project.length > 0) {
-                const selects = [];
-                tender.change_project.forEach(x => {
-                    selects.push({ value: x.cid, text: x.code })
-                });
-                this.tenderFileType.push({ value: 'change_project', text: '变更立项', select: selects });
-            }
             if (tender.change_apply && tender.change_apply.length > 0) {
                 const selects = [];
                 tender.change_apply.forEach(x => {
-                    selects.push({ value: x.cid, text: x.code })
+                    selects.push({ value: x.id, text: x.code })
                 });
                 this.tenderFileType.push({ value: 'change_apply', text: '变更申请', select: selects });
             }
-            this.rfType = { type: this.tenderFileType[0].value };
+            if (tender.change_project && tender.change_project.length > 0) {
+                const selects = [];
+                tender.change_project.forEach(x => {
+                    selects.push({ value: x.id, text: x.code })
+                });
+                this.tenderFileType.push({ value: 'change_project', text: '变更立项', select: selects });
+            }
+            this.rfType = { type: tender.tid ? this.tenderFileType[0].value : '' };
             this.refreshTenderFileType();
             this.refreshTenderFileSubType();
             this.refreshTenderFileStage();
@@ -1259,7 +1274,7 @@ $(document).ready(function() {
         async _loadChangePlanFile() {
             const rfType = this.rfType;
             const change = this.curTender.source_node.change_plan.find(x => {
-                return x.id === rfType.selectId;
+                return x.id == rfType.selectId;
             });
             if (!change) {
                 this.curFiles = [];
@@ -1271,7 +1286,7 @@ $(document).ready(function() {
         async _loadChangeProjectFile() {
             const rfType = this.rfType;
             const change = this.curTender.source_node.change_project.find(x => {
-                return x.id === rfType.selectId;
+                return x.id == rfType.selectId;
             });
             if (!change) {
                 this.curFiles = [];
@@ -1283,7 +1298,7 @@ $(document).ready(function() {
         async _loadChangeApplyFile() {
             const rfType = this.rfType;
             const change = this.curTender.source_node.change_apply.find(x => {
-                return x.id === rfType.selectId;
+                return x.id == rfType.selectId;
             });
             if (!change) {
                 this.curFiles = [];
@@ -1301,6 +1316,7 @@ $(document).ready(function() {
                 case 'change_plan': await this._loadChangePlanFile(); break;
                 case 'change_project': await this._loadChangeProjectFile(); break;
                 case 'change_apply': await this._loadChangeApplyFile(); break;
+                default: this.curFiles = [];
             }
             this.initFilesId(this.curFiles);
         }
@@ -1313,9 +1329,9 @@ $(document).ready(function() {
         }
         getSelectRelaFile() {
             const data = [];
-            const nodes = this.tenderTree.getNodes();
+            const nodes = this.tenderTree.transformToArray(this.tenderTree.getNodes());
             nodes.forEach(node => {
-                if (node.source_node.selectFiles.length === 0) return;
+                if (!node.source_node.selectFiles || node.source_node.selectFiles.length === 0) return;
 
                 node.source_node.selectFiles.forEach(x => {
                     data.push({

+ 1 - 1
app/service/filing_template.js

@@ -256,7 +256,7 @@ module.exports = app => {
                 insertData.push({
                     id: this.uuid.v4(), temp_id: templateId, add_user_id: this.ctx.session.sessionUser.accountId,
                     tree_pid: parent ? parent.id : rootId, tree_level: parent ? parent.tree_level + 1 : 1, tree_order: d.tree_order,
-                    name: d.name, file_company: node.file_company, tips: d.tips, filing_type: d.filing_type, is_fixed: parent ? d.is_fixed : 1, org_id: d.id,
+                    name: d.name, file_company: d.file_company, tips: d.tips, filing_type: d.filing_type, is_fixed: parent ? d.is_fixed : 1, org_id: d.id,
                 });
             }
             insertData.forEach(x => { delete x.org_id; });