MaiXinRong 3 лет назад
Родитель
Сommit
d80f771eca

+ 1 - 1
app/const/report.js

@@ -14,10 +14,10 @@ rptCustomType[JV.NODE_CUS_AUDIT_SELECT] = 1;
 rptCustomType[JV.NODE_CUS_GATHER_SELECT] = 2;
 rptCustomType[JV.NODE_CUS_COMPARE_SELECT] = 3;
 rptCustomType[JV.NODE_CUS_STAGE_SELECT] = 4;
+rptCustomType[JV.NODE_CUS_CHANGE_SELECT] = 5;
 
 const rptDataType = {};
 rptDataType[JV.NODE_CUS_MATERIAL_SELECT] = 1;
-rptDataType[JV.NODE_CUS_CHANGE_SELECT] = 1;
 
 module.exports = {
     rptCustomType,

+ 11 - 2
app/controller/report_controller.js

@@ -197,6 +197,8 @@ module.exports = app => {
                     reportConst.rptCustomType[JV.NODE_CUS_GATHER_SELECT], ctx.tender.id, -1);
                 customSelects.stage_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
                     reportConst.rptCustomType[JV.NODE_CUS_STAGE_SELECT], ctx.tender.id, -1);
+                customSelects.change_select = await ctx.service.rptCustomDefine.getCustomSelectByRpt(cid,
+                    reportConst.rptCustomType[JV.NODE_CUS_CHANGE_SELECT], ctx.tender.id, -1);
                 const dataSelects = {};
                 dataSelects.material_select = await ctx.service.rptCustomDefine.getDataSelectByRpt(cid,
                     reportConst.rptDataType[JV.NODE_CUS_MATERIAL_SELECT]);
@@ -378,10 +380,14 @@ module.exports = app => {
             const customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
                 ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, params.rpt_tpl_id)
                 : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, params.rpt_tpl_id);
+            console.log(customSelect);
 
-            const copyCustomSelect = this.ctx.helper.clone(customSelect);
+            let copyCustomSelect = this.ctx.helper.clone(customSelect);
             if (!params.gather_select && copyCustomSelect) delete copyCustomSelect.gather_select;
             if (!params.stage_select && copyCustomSelect) delete copyCustomSelect.stage_select;
+            if (params.change_select) {
+                copyCustomSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.change_select};
+            }
 
             const pageRst = await getAllPagesCommon(ctx, rptTpl, params, JV.PAGING_OPTION_NORMAL, JV.OUTPUT_TYPE_NORMAL, this.app.baseDir, copyCustomSelect);
             for (const page of pageRst.items) {
@@ -1003,9 +1009,12 @@ async function getMultiRptsCommon(ctx, params, outputType, baseDir) {
         for (let tplIdx = 0; tplIdx < rptTpls.length; tplIdx++) {
             const rptTpl = (rptTpls[tplIdx]._doc) ? rptTpls[tplIdx]._doc : rptTpls[tplIdx];
             rptDataUtil.initialize(rptTpl);
-            const customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
+            let customSelect = rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_AUDIT_SELECT].enable
                 ? await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, params.stage_id, rptTpl.id)
                 : await ctx.service.rptCustomDefine.getCustomDefine(params.tender_id, -1, rptTpl.id);
+            if (rptTpl[JV.NODE_CUSTOM_DEFINE] && rptTpl[JV.NODE_CUSTOM_DEFINE][JV.NODE_CUS_CHANGE_SELECT]) {
+                customSelect = { tid: params.tender_id, rid: params.rpt_tpl_id, sid: -1, change_select: params.customSelect[tplIdx].change_select };
+            }
 
             // 从汇总的rawDataObj中拷贝所需数据表至curRawDataObj,以供后续使用
             const curRawDataObj = {};

+ 24 - 0
app/controller/tender_controller.js

@@ -1361,6 +1361,30 @@ module.exports = app => {
                 ctx.body = this.ajaxErrorBody(err, '保存概况设置失败');
             }
         }
+
+        async loadData(ctx) {
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const filter = data.filter.split(';');
+                const responseData = { err: 0, msg: '', data: {} };
+                for (const f of filter) {
+                    switch (f) {
+                        case 'change':
+                            responseData.data[f] = await ctx.service.change.getAllDataByCondition({
+                                columns: [ 'cid', 'code', 'name' ],
+                                where: { tid: this.ctx.tender.id, valid: 1, status: auditConst.flow.status.checked }
+                            });
+                            break;
+                        default:
+                            throw '未知数据类型';
+                    }
+                }
+                ctx.body = responseData;
+            } catch (err) {
+                ctx.log(err);
+                ctx.ajaxErrorBody(err, '加载数据错误');
+            }
+        }
     }
 
     return TenderController;

+ 10 - 0
app/public/js/global.js

@@ -274,6 +274,16 @@ const postData = function (url, data, successCallback, errorCallBack, showWaitin
     });
 };
 
+const postDataAsync = function (url, data, showWaiting = true) {
+    return new Promise(function (resolve, reject) {
+        postData(url, data, result => {
+            resolve(result);
+        }, err => {
+            reject(err);
+        }, showWaiting);
+    });
+};
+
 /**
  * 动态请求数据(压缩数据)
  * @param {String} url - 请求链接

+ 91 - 2
app/public/report/js/rpt_custom.js

@@ -158,6 +158,49 @@ const rptCustomObj = (function () {
         },
     };
 
+    // 变更令选择
+    const sChangeSelect = 'change_select';
+    const changeObj = {
+        changes: null,
+        latestPush: null,
+        loadChanges: async function () {
+            const self = this;
+            const result = await postDataAsync(`/tender/${window.location.pathname.split('/')[2]}/load`, { filter: 'change'});
+            this.changes = result.change;
+            const html = [];
+            for (const c of this.changes) {
+                html.push('<tr>', `<td class="text-center"><input type="checkbox" name="change-select-check" value="${c.cid}"></td>`, `<td>${c.code}</td>`, `<td>${c.name}</td>`, '</tr>');
+            }
+            $('#change-select-list').html(html.join(''));
+            $('[name=change-select-check]').click(function () {
+                const selectChange = $('[name=change-select-check]:checked');
+                const selectHtml = [];
+                for (const sc of selectChange) {
+                    const c = self.changes.find(x => { return x.cid === sc.value });
+                    selectHtml.push(`<tr><td class="text-center">${selectHtml.length + 1}</td><td>${c.code}</td><td>${c.name}</td></tr>`);
+                }
+                $('#change-select-result').html(selectHtml.join(''));
+            });
+        },
+
+        show: async function (title, resolve) {
+            this.latestPush = null;
+            $('#change-select-title').html(title);
+            if (!this.changes) {
+                await this.loadChanges();
+            }
+            if (resolve) {
+                setTimeout(() => { $("#change-select").modal('show'); }, 1000);
+            } else {
+                $('#change-select').modal('show');
+            }
+            $('#change-select-ok').unbind('click');
+            $('#change-select-ok').bind('click', () => {
+                rptCustomObj.resetChangeSelect(resolve);
+            });
+        }
+    };
+
     const getStageFlowSelectHtml = function (select, id) {
         const html = [];
         html.push('<select style="width: 80%" id="' + id + '" sf-title="' + select.title + '">');
@@ -306,6 +349,9 @@ const rptCustomObj = (function () {
             // $("#stage-select").modal('hide');
         });
     };
+    const initChangeSelect = function (gsSetting, rptName, resolve = null) {
+        changeObj.show('选择工程变更' + (rptName ? '-' + rptName : ''), resolve);
+    };
     const init = function (cDefine, sfData, cSelect, rptName, resolve = null) {
         stageFlow = sfData;
         if (cDefine && cDefine[sAuditSelect] && cDefine[sAuditSelect].enable && cDefine[sAuditSelect].setting) {
@@ -327,6 +373,9 @@ const rptCustomObj = (function () {
         } else {
             $('#pnl_stage_select').hide();
         }
+        if (cDefine && cDefine[sChangeSelect] && cDefine[sChangeSelect].enable) {
+            initChangeSelect(cDefine[sChangeSelect].setting, rptName, resolve);
+        }
     };
 
     const reloadReportData = function (result) {
@@ -565,6 +614,32 @@ const rptCustomObj = (function () {
         }
     };
 
+    const resetChangeSelect = function (resolve = null) {
+        const data = {}, hintObj = $('#change-select-hint');
+        if (!resolve) getCommonParams(data);
+        data[sChangeSelect] = [];
+        for (const sc of $('[name=change-select-check]:checked')) {
+            data[sChangeSelect].push(sc.value);
+        }
+        if (data[sChangeSelect].length === 0) {
+            hintObj.html('请至少选择一条变更令').show();
+            return;
+        }
+        if (resolve) {
+            resolve(data);
+        } else {
+            postData('/report/cDefine', data, function (result) {
+                changeObj.latestSelect = data[sChangeSelect];
+                reloadReportData(result);
+                $('#change-select').modal('hide');
+                rptArchiveObj.toggleBtn(true);
+                if (PAGE_SHOW.showArchive) {
+                    rptArchiveObj.showArchivedItem(zTreeOprObj.currentNode);
+                }
+            });
+        }
+    };
+
     const _createTenderTreeForCross = function (tenders, category, rstItems) {
         if (rstItems instanceof Array && rstItems.length === 0) {
             //1. 先确定category方式(‘年份’、‘姓名’、‘类型’)及顺序
@@ -730,6 +805,9 @@ const rptCustomObj = (function () {
             const stage_select = customSelects.stage_select.find(function (x) {
                 return x.id === rptId;
             });
+            const change_select = customSelects.change_select.find(function (x) {
+                return x.id === rptId;
+            });
             if (gather_select && gather_select.custom_define && gather_select.custom_define[sGatherSelect].enable) {
                 if (rptId === currentRptId) {
                     const data = {};
@@ -737,7 +815,7 @@ const rptCustomObj = (function () {
                     params.customSelect.push(data);
                 } else {
                     const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
-                    const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select)
+                    const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', gather_select);
                     params.customSelect.push(select);
                     $('#gather-select').modal('hide');
                 }
@@ -752,6 +830,17 @@ const rptCustomObj = (function () {
                     params.customSelect.push(select);
                     $('#stage-select').modal('hide');
                 }
+            } else if (change_select && change_select.custom_define && change_select.custom_define[sChangeSelect].enable ) {
+                if (rptId === currentRptId && changeObj.latestPush) {
+                    const data = {};
+                    data[sChangeSelect] = changeObj.latestSelect;
+                    params.customSelect.push(data);
+                } else {
+                    const chkNode = chkNodes.find(function (x) { return x.refId === rptId});
+                    const select = await comfirmSelectPromise(chkNode ? chkNode.name : '', change_select);
+                    params.customSelect.push(select);
+                    $('#change-select').modal('hide');
+                }
             } else {
                 params.customSelect.push(null);
             }
@@ -815,7 +904,7 @@ const rptCustomObj = (function () {
 
     return {
         init,
-        resetAuditSelect, resetGatherSelect, resetStageSelect,
+        resetAuditSelect, resetGatherSelect, resetStageSelect, resetChangeSelect,
         initTenderTree,
         initTenderTreeForCross,
         getCustomSelect,

+ 16 - 0
app/public/report/js/rpt_main.js

@@ -297,6 +297,14 @@ let zTreeOprObj = {
                 return;
             }
 
+            const change_select = customSelects.change_select.find(function (x) {
+                return x.id === treeNode.refId;
+            });
+            if (change_select) {
+                rptCustomObj.init(change_select.custom_define, customSelects.stageFlow, change_select);
+                return;
+            }
+
             rptArchiveObj.toggleBtn(true);
             me.requestNormalReport(params);
             me.countChkedRptTpl();
@@ -357,6 +365,14 @@ let zTreeOprObj = {
                 return;
             }
 
+            const change_select = customSelects.change_select.find(function (x) {
+                return x.id === me.currentNode.refId;
+            });
+            if (change_select) {
+                rptCustomObj.init(change_select.custom_define, customSelects.stageFlow, change_select);
+                return;
+            }
+
             me.requestNormalReport(params);
             me.countChkedRptTpl();
             rptCustomObj.showMaterialSelect();

+ 1 - 0
app/router.js

@@ -156,6 +156,7 @@ module.exports = app => {
     app.post('/tender/:id/copy-setting', sessionAuth, tenderCheck, 'tenderController.copyTender');
     app.post('/tender/:id/tourist/audit/save', sessionAuth, tenderCheck, uncheckTenderCheck, 'tenderController.saveTourist');
     app.post('/tender/:id/map/save', sessionAuth, tenderCheck, uncheckTenderCheck, 'tenderController.saveMap');
+    app.post('/tender/:id/load', sessionAuth, tenderCheck, 'tenderController.loadData');
 
     // 预付款
     app.get('/tender/:id/advance/:type', sessionAuth, tenderCheck, 'advanceController.index');

+ 37 - 0
app/view/report/rpt_all_popup.ejs

@@ -443,6 +443,43 @@
         </div>
     </div>
 </div>
+<div class="modal" id="change-select" data-backdrop="static">
+    <div class="modal-dialog modal-lg" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title" id="stage-select-title">请选择变更令</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <div class="row">
+                    <div class="col-6">
+                        <h5>可选变更令 </h5>
+                        <table class="table table-bordered">
+                            <tr class="text-center"><th>选择</th><th>变更令号</th><th>工程名称</th></tr>
+                            <tbody id="change-select-list">
+                            </tbody>
+                        </table>
+                    </div>
+                    <div class="col-6">
+                        <h5>已选变更令 </h5>
+                        <table class="table table-bordered">
+                            <tr class="text-center"><th>序号</th><th>变更令号</th><th>工程名称</th></tr>
+                            <tbody id="change-select-result">
+                            </tbody>
+                        </table>
+                    </div>
+                </div>
+                <div class="alert alert-danger my-2 p-2" id="change-select-hint" style="display: none">我是提示呀</div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
+                <button class="btn btn-sm btn-primary" id="change-select-ok">确定</button>
+            </div>
+        </div>
+    </div>
+</div>
 <!--管理推荐报表-->
 <div class="modal fade" id="man-c" data-backdrop="static">
     <div class="modal-dialog" role="document">