浏览代码

1.人材机查找引用
2.重构定额库部分代码,合并初始化请求

zeweizhong 5 年之前
父节点
当前提交
9f8e27228b

+ 12 - 0
modules/ration_repository/controllers/ration_repository_controller.js

@@ -21,6 +21,18 @@ const rationItemModel = mongoose.model('std_ration_lib_ration_items');
 import STDGLJListModel from '../../std_glj_lib/models/gljModel';
 
 class RationRepositoryController extends baseController {
+    // 定额页面初始化数据
+    async prepareInitData(req, res) {
+        try {
+            const data = JSON.parse(req.body.data);
+            const rst = await rationItem.prepareInitData(data.rationRepId);
+            res.json({error: 0, message: 'success', data: rst});
+        } catch (err) {
+            console.log(err);
+            res.json({error: 1, message: 'fail', data: null});
+        }
+    }
+
     async getRationLibsByCompilation(req, res){
         try{
             let data = JSON.parse(req.body.data);

+ 19 - 9
modules/ration_repository/models/installation.js

@@ -9,20 +9,30 @@ const installSectionModel = mongoose.model('std_ration_lib_installationSection')
 class InstallationDao{
     async getInstallation(rationRepId, callback){
         try {
-            let feeItems = await installFeeItemModel.find({rationRepId: rationRepId, $or: [{deleted: false}, {deleted: null}]});
-            for(let feeItem of feeItems){
-                let sids = [];
-                for(let sec of feeItem.section){
-                    sids.push(sec.ID);
-                }
-                if(sids.length > 0){
-                    let sections = await installSectionModel.find({ID: {$in: sids}, $or: [{deleted: false}, {deleted: null}]});
-                    feeItem._doc.section = sections;
+            const feeItems = await installFeeItemModel.find({ rationRepId }).lean();
+            const feeItemMap = {};
+            const sectionIds = [];
+            feeItems.forEach(item => {
+                feeItemMap[item.ID] = item;
+                item.section.forEach(s => sectionIds.push(s.ID));
+                item.section = [];
+            });
+            const sections = await installSectionModel.find({ID: {$in: sectionIds}});
+            sections.forEach(section => {
+                const matchFeeItem = feeItemMap[section.feeItemId];
+                if (matchFeeItem) {
+                    matchFeeItem.section.push(section);
                 }
+            });
+            if (!callback) {
+                return feeItems;
             }
             callback(0, feeItems);
         }
         catch(err){
+            if (!callback) {
+                return [];
+            }
             callback(err, null);
         }
     }

+ 36 - 0
modules/ration_repository/models/ration_item.js

@@ -13,9 +13,45 @@ const stdRationLibModel = mongoose.model('std_ration_lib_map');
 const stdRationSectionModel = mongoose.model('std_ration_lib_ration_chapter_trees');
 const compleRationModel = mongoose.model('complementary_ration_items');
 import STDGLJListModel from '../../std_glj_lib/models/gljModel';
+import InstallationDao from '../models/installation';
+const installationDao = new InstallationDao();
+import GljDao from "../../std_glj_lib/models/gljModel";
+const stdGljDao = new GljDao();
+import stdgljutil  from "../../../public/cache/std_glj_type_util";
 
 var rationItemDAO = function(){};
 
+rationItemDAO.prototype.prepareInitData = async function (rationRepId) {
+    // 定额库
+    const libTask = stdRationLibModel.findOne({ID: rationRepId}, '-_id ID dispName gljLib');
+    // 定额编码
+    const codesTask = rationItemModel.find({rationRepId}, '-_id code', {lean: true});
+    // 定额章节树
+    const sectionTreeTask = stdRationSectionModel.find({rationRepId}, '-_id', {lean: true});
+    // 安装增加费
+    const installationTask = installationDao.getInstallation(rationRepId);
+    const [libInfo, codesArr, sectionTree, installationList] = await Promise.all([libTask, codesTask, sectionTreeTask, installationTask]);
+    const rationsCodes = codesArr.reduce((acc, cur) => {
+        acc.push(cur.code);
+        return acc;
+    }, []);
+    // 人材机分类树
+    const gljLibId = libInfo.gljLib;
+    const gljTreeTask = stdGljDao.getGljTreeSync(gljLibId);
+    const gljTask = stdGljDao.getGljItemsSync(gljLibId);
+    const [gljTree, gljList] = await Promise.all([gljTreeTask, gljTask]);
+    const gljDistTypeList = stdgljutil.getStdGljTypeCacheObj().toArray();
+    return {
+        libInfo,
+        rationsCodes,
+        sectionTree,
+        installationList,
+        gljTree,
+        gljList,
+        gljDistTypeList
+    };
+};
+
 //将消耗量为负的人材机改为正的
 rationItemDAO.prototype.toPositive = async function (rationRepId) {
     let rations = await rationItemModel.find({rationRepId: rationRepId, 'rationGljList.consumeAmt': {$lt: 0}});

+ 1 - 0
modules/ration_repository/routes/ration_rep_routes.js

@@ -30,6 +30,7 @@ module.exports =  function (app) {
     app.get('/rationRepository/coeList', viewsController.auth, viewsController.init, viewsController.redirectCoeList);
     app.get('/rationRepository/installation', viewsController.auth, viewsController.init, viewsController.redirectInstallation);
 
+    apiRouter.post("/prepareInitData", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.prepareInitData);
     apiRouter.post("/getCompilationList", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getCompilationList);
     apiRouter.post("/getRationLibsByCompilation", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLibsByCompilation);
     apiRouter.post("/getRationLib",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLib);

+ 11 - 0
modules/std_glj_lib/controllers/gljController.js

@@ -190,6 +190,17 @@ class GljController extends BaseController{
             res.json({error: 1, message: error, data: null});
         }
     }
+
+    async getReference(req, res) {
+        try {
+            const {repositoryId, gljId} = JSON.parse(req.body.data);
+            const info = await gljDao.getReference(repositoryId, gljId);
+            res.json({error: 0, message: 'success', data: info});
+        } catch (err) {
+            res.json({error: 1, message: String(err), data: null});
+        }
+    }
+
     async importPrice(request, response) {
         let responseData = {
             err: 0,

+ 36 - 1
modules/std_glj_lib/models/gljModel.js

@@ -9,12 +9,39 @@ const gljClassTemplateModel = mongoose.model('std_glj_lib_gljClassTemplate');
 const compilationModel = mongoose.model('compilation');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
 const rationModel = mongoose.model('std_ration_lib_ration_items');
+const complementaryRationModel = mongoose.model('complementary_ration_items');
 import {OprDao} from  "./gljMapModel";
 import moment from "moment";
 import counter from "../../../public/counter/counter";
 import async from "async";
 
 class GljDao  extends OprDao{
+    async getReference(repositoryId, gljId) {
+        const gljLib = await gljMapModel.findOne({ID: repositoryId});
+        const rationLibIds = [];
+        const rationLibNameMapping = {};
+        gljLib.rationLibs.forEach(item => {
+            rationLibIds.push(item.ID);
+            rationLibNameMapping[item.ID] = item.dispName;
+        });
+        const stdRations = await rationModel.find({rationRepId: {$in: rationLibIds}, 'rationGljList.gljId': gljId}, '-_id code rationRepId');
+        const rst = {};
+        const unknownLib = '未知定额库';
+        const complementaryLib = '补充定额库';
+        stdRations.forEach(ration => {
+            const libName = rationLibNameMapping[ration.rationRepId] || unknownLib;
+            if (!rst[libName]) {
+                rst[libName] = [];
+            }
+            rst[libName].push(ration);
+        });
+        const complementaryRations = await complementaryRationModel.find({'rationGljList.gljId': gljId}, '-_id code');
+        if (complementaryRations.length) {
+            rst[complementaryLib] = [];
+        }
+        complementaryRations.forEach(ration => rst[complementaryLib].push({code: ration.code}));
+        return rst;
+    }
     //test
     async deSomething (libID){
         let pClass = await gljClassModel.find({repositoryId: libID, Name: '2013全省材料预算价格'});
@@ -56,7 +83,11 @@ class GljDao  extends OprDao{
         console.log('end');
 
     }
-    //test
+
+    async getGljTreeSync(gljLibId) {
+        return await gljClassModel.find({repositoryId: gljLibId});
+    }
+
     getGljTypes (gljLibId, callback){
         gljClassModel.find({"repositoryId": gljLibId, "$or": [{"isDeleted": null}, {"isDeleted": false}, {deleted: false} ]},
             '-_id', {lean: true}, function(err,data){
@@ -88,6 +119,10 @@ class GljDao  extends OprDao{
         }
     }
 
+    async getGljItemsSync(gljLibId) {
+        return await gljModel.find({repositoryId: gljLibId}, '-_id', {lean: true});
+    }
+
     async getGljItemsByRep(repositoryId,callback = null){
    /*     let me = this;
         if (callback === null) {

+ 2 - 0
modules/std_glj_lib/routes/routes.js

@@ -42,6 +42,8 @@ module.exports = function (app) {
     router.post("/getGljItemsByCodes",gljController.auth, gljController.init, gljController.getGljItemsByCodes);
     router.post("/getGljItemsOccupied",gljController.auth, gljController.init, gljController.getGljItemsOccupied);
     router.post("/isUsed",gljController.auth, gljController.init, gljController.isUsed);//工料机是否被引用
+    // 查找定额引用
+    router.post("/getReference",gljController.auth, gljController.init, gljController.getReference);
     router.post('/importPrice', gljController.auth, gljController.init, gljController.importPrice);
     router.post('/importComponents', gljController.auth, gljController.init, gljController.importComponents);
 

+ 4 - 1
public/web/PerfectLoad.js

@@ -71,7 +71,10 @@ jQuery.bootstrapLoading = {
 
                             });
                         setTimeout(function () {
-                            $('#loadingFocus')[0].focus();
+                            const $loadingFocus = $('#loadingFocus')[0];
+                            if ($loadingFocus) {
+                                $loadingFocus.focus();
+                            }
                         }, 200);
 
                     },

+ 2 - 82
web/maintain/ration_repository/dinge.html

@@ -22,6 +22,7 @@
     </style>
     <script type="text/javascript">
         let priceProperties = JSON.parse('<%- priceProperties %>');
+        let userAccount = '<%=userAccount %>';
         console.log(priceProperties);
     </script>
 </head>
@@ -680,88 +681,7 @@
         <script src="/web/common/js/uploadImg.js"></script>
         <script src="/web/common/js/slideResize.js"></script>
         <script src="/web/maintain/ration_repository/js/ration_template.js"></script>
-        <script type="text/javascript">
-            var exEditor = CodeMirror.fromTextArea(document.getElementById("explanationShow"), {
-                mode: "text/html",
-                lineNumbers: true,
-                theme:"material"
-            });
-            exEditor.setSize('auto','500px');
-            $('#explanationLink').click(function () {
-                setTimeout(function () {
-                    exEditor.refresh();
-                }, 100);
-            });
-            var calcEditor = CodeMirror.fromTextArea(document.getElementById("ruleTextShow"), {
-                mode: 'text/html',
-                lineNumbers: true,
-                theme: 'material'
-            });
-            calcEditor.setSize('auto', '500px');
-            $('#ruleTextLink').click(function () {
-                setTimeout(function () {
-                    calcEditor.refresh();
-                }, 100);
-            });
-
-            let userAccount = '<%=userAccount %>';
-            $(document).ready(function(){
-                rationOprObj.buildSheet($("#rationItemsSheet")[0]);
-                // tabPanel 下有多个Spread时,相互之间不能正确显示。改成一个Spread下多个Sheet。
-                var rdSpread = sheetCommonObj.createSpread($("#rdSpread")[0], 5);
-                rationGLJOprObj.buildSheet(rdSpread.getSheet(0));
-
-                rationAssistOprObj.buildSheet(rdSpread.getSheet(1));
-
-                rationCoeOprObj.buildSheet(rdSpread.getSheet(2));
-                rationInstObj.buildSheet(rdSpread.getSheet(3));
-                RationTemplate.buildSheet(rdSpread.getSheet(4));
-                rationInstObj.getInstallation(parseInt(getQueryString("repository")));
-                pageOprObj.initPage();
-
-                let rdSpreadEscSheets = [];
-                rdSpreadEscSheets.push({sheet: rdSpread.getSheet(0), editStarting: rationGLJOprObj.onEditStarting, editEnded: rationGLJOprObj.onCellEditEnd});
-                rdSpreadEscSheets.push({sheet: rdSpread.getSheet(1), editStarting: rationAssistOprObj.onEditStarting, editEnded: rationAssistOprObj.onEditEnded});
-                rdSpreadEscSheets.push({sheet: rdSpread.getSheet(2), editStarting: rationCoeOprObj.onEditStarting, editEnded: rationCoeOprObj.onEditEnded});
-                rdSpreadEscSheets.push({sheet: rdSpread.getSheet(3), editStarting: rationInstObj.onEditStarting, editEnded: rationInstObj.onEditEnded});
-                rdSpreadEscSheets.push({sheet: rdSpread.getSheet(4), editStarting: null, editEnded: RationTemplate.events.onEditEnded});
-                sheetCommonObj.bindEscKey(rdSpread, rdSpreadEscSheets);
-
-                $("#linkGLJ").click(function(){
-                    rationGLJOprObj.bindRationGljDelOpr();
-                    rdSpread.setActiveSheetIndex(0);
-                });
-
-                $("#linkFZDE").click(function(){
-                    rationAssistOprObj.bindRationAssDel();
-                    rdSpread.setActiveSheetIndex(1);
-                });
-
-                $("#linkFZTJ").click(function(){
-                    rationCoeOprObj.bindRationCoeDel();
-                    rdSpread.setActiveSheetIndex(2);
-                });
-                $("#linkAZZJ").click(function(){
-                    rationInstObj.bindRationInstDel();
-                    rdSpread.setActiveSheetIndex(3);
-                });
-                $("#linkMBGL").click(function(){
-                    RationTemplate.bindRationTempDel();
-                    rdSpread.setActiveSheetIndex(4);
-                });
-                //解决spreadjs sheet初始化没高度宽度
-                $('#modalCon').width($(window).width()*0.5);
-                $('#gljSelTreeDiv').height($(window).height() - 300);
-                $("#gljSelSheet").height($("#gljSelTreeDiv").height()-21.6);
-                $("#gljSelSheet").width($('#modalCon').width() * 0.63);
-                $(window).resize(function () {
-                    $('#modalCon').width($(window).width()*0.5);
-                    $('#gljSelTreeDiv').height($(window).height() - 300);
-                    $("#gljSelSheet").height($("#gljSelTreeDiv").height()-21.6);
-                    $("#gljSelSheet").width($('#modalCon').width()* 0.63);
-                });
-            });
-        </script>
+        <script src="/web/maintain/ration_repository/js/init.js"></script>
     </div>
 </body>
 <script type="text/javascript">

+ 29 - 0
web/maintain/ration_repository/js/explanatory.js

@@ -3,10 +3,39 @@
  */
 //定额章节节点说明、计算规则
 let explanatoryOprObj = {
+    exEditor: null,
+    calcEditor: null,
     preTreeNode: null,
     currentTreeNode: null,//定额章节树节点
     currentExplanation: null,
     currentRuleText: null,
+    // 初始化说明、计算规则编辑器
+    initEditor: function () {
+        const exEditor = CodeMirror.fromTextArea(document.getElementById("explanationShow"), {
+            mode: "text/html",
+            lineNumbers: true,
+            theme:"material"
+        });
+        exEditor.setSize('auto','500px');
+        $('#explanationLink').click(function () {
+            setTimeout(function () {
+                exEditor.refresh();
+            }, 100);
+        });
+        this.exEditor = exEditor;
+        const calcEditor = CodeMirror.fromTextArea(document.getElementById("ruleTextShow"), {
+            mode: 'text/html',
+            lineNumbers: true,
+            theme: 'material'
+        });
+        calcEditor.setSize('auto', '500px');
+        $('#ruleTextLink').click(function () {
+            setTimeout(function () {
+                calcEditor.refresh();
+            }, 100);
+        });
+        this.calcEditor = calcEditor;
+    },
     setAttribute: function (preNode, currentNode, explanation, ruleText) {
         let me = explanatoryOprObj;
         me.preTreeNode = preNode;

+ 16 - 47
web/maintain/ration_repository/js/gljSelect.js

@@ -39,55 +39,24 @@ let gljSelOprObj = {
             delete glj.ID;
         }
     },
-    getSelGljItems: function(stdGljLibId, callback) {
-        let me = this;
-        $.ajax({
-            type:"POST",
-            url:"/stdGljRepository/api/getGljItems",
-            data:{"repositoryId": stdGljLibId},
-            dataType:"json",
-            cache:false,
-            timeout:20000,
-            success:function(result){
-                if(!result.error) {
-                    if(priceProperties && priceProperties.length > 0){
-                        let priceField = priceProperties[0].price.dataCode;
-                        for(let glj of result.data){
-                            glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
-                        }
-                    }
-                    me.stdGljList = result.data;
-                    me.switchToGljId(me.stdGljList);
-                    me.sortGlj(me.stdGljList);
-                    if(callback){
-                        callback();
-                    }
-                }
-            },
-            error:function(err){
-                alert(err.responseJSON.error);
+    initGljList: function(gljList) {
+        if(priceProperties && priceProperties.length){
+            const priceField = priceProperties[0].price.dataCode;
+            for(let glj of gljList){
+                glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
             }
-        });
+        }
+        this.stdGljList = gljList;
+        this.switchToGljId(this.stdGljList);
+        this.sortGlj(this.stdGljList);
     },
-    getGljClassTree: function (gljLibId, callback) {
-        let me = this;
-        let url = '/stdGljRepository/api/getGljTree';
-        let postData = {gljLibId: gljLibId};
-        let sucFunc = function (rstData) {
-            zTreeHelper.createTree(rstData, gljSelTreeOprObj.setting, "selGljTree", gljSelOprObj);
-            let rootNode = gljSelOprObj.treeObj.getNodes()[0];
-            if(rootNode && rootNode.isParent && rootNode.isFirstNode){
-                gljSelOprObj.rootNode = rootNode;
-            }
-            gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
-            if(callback){
-                callback();
-            }
-        };
-        let errFunc = function () {
-
-        };
-        CommonAjax.post(url, postData, sucFunc, errFunc);
+    initGljClassTree: function (gljTree) {
+        zTreeHelper.createTree(gljTree, gljSelTreeOprObj.setting, "selGljTree", gljSelOprObj);
+        const rootNode = gljSelOprObj.treeObj.getNodes()[0];
+        if(rootNode && rootNode.isParent && rootNode.isFirstNode){
+            gljSelOprObj.rootNode = rootNode;
+        }
+        gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
     },
     buildSheet: function (container) {
         let me = gljSelOprObj;

+ 88 - 0
web/maintain/ration_repository/js/init.js

@@ -0,0 +1,88 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Zhong
+ * @date 2019/10/30
+ * @version
+ */
+
+const initialization = (() => {
+    function initData() {
+        const rationRepId = +getQueryString('repository');
+        $.bootstrapLoading.start();
+        CommonAjax.post('/rationRepository/api/prepareInitData', { rationRepId }, rstData => {
+            pageOprObj.initPage(rstData.libInfo);
+            rationOprObj.buildSheet($("#rationItemsSheet")[0]);
+            // tabPanel 下有多个Spread时,相互之间不能正确显示。改成一个Spread下多个Sheet。
+            const rdSpread = sheetCommonObj.createSpread($("#rdSpread")[0], 5);
+            rationGLJOprObj.buildSheet(rdSpread.getSheet(0));
+            rationAssistOprObj.buildSheet(rdSpread.getSheet(1));
+            rationCoeOprObj.buildSheet(rdSpread.getSheet(2));
+            rationInstObj.buildSheet(rdSpread.getSheet(3));
+            RationTemplate.buildSheet(rdSpread.getSheet(4));
+
+            const rdSpreadEscSheets = [];
+            rdSpreadEscSheets.push({sheet: rdSpread.getSheet(0), editStarting: rationGLJOprObj.onEditStarting, editEnded: rationGLJOprObj.onCellEditEnd});
+            rdSpreadEscSheets.push({sheet: rdSpread.getSheet(1), editStarting: rationAssistOprObj.onEditStarting, editEnded: rationAssistOprObj.onEditEnded});
+            rdSpreadEscSheets.push({sheet: rdSpread.getSheet(2), editStarting: rationCoeOprObj.onEditStarting, editEnded: rationCoeOprObj.onEditEnded});
+            rdSpreadEscSheets.push({sheet: rdSpread.getSheet(3), editStarting: rationInstObj.onEditStarting, editEnded: rationInstObj.onEditEnded});
+            rdSpreadEscSheets.push({sheet: rdSpread.getSheet(4), editStarting: null, editEnded: RationTemplate.events.onEditEnded});
+            sheetCommonObj.bindEscKey(rdSpread, rdSpreadEscSheets);
+
+            // 初始化定额章节树
+            sectionTreeObj.initSectionTree(rstData.sectionTree);
+            // 初始化人材机类型
+            rationGLJOprObj.initGljDistType(rstData.gljDistTypeList);
+            // 初始化人材机分类树
+            gljSelOprObj.initGljClassTree(rstData.gljTree);
+            // 初始化人材机
+            gljSelOprObj.initGljList(rstData.gljList);
+            // 初始化安装增加费
+            rationInstObj.initInstallation(rstData.installationList);
+            //初始化已使用的定额编码
+            rationOprObj.rationsCodes = rstData.rationsCodes;
+
+            $("#linkGLJ").click(function(){
+                rationGLJOprObj.bindRationGljDelOpr();
+                rdSpread.setActiveSheetIndex(0);
+            });
+
+            $("#linkFZDE").click(function(){
+                rationAssistOprObj.bindRationAssDel();
+                rdSpread.setActiveSheetIndex(1);
+            });
+            $("#linkFZTJ").click(function(){
+                rationCoeOprObj.bindRationCoeDel();
+                rdSpread.setActiveSheetIndex(2);
+            });
+            $("#linkAZZJ").click(function(){
+                rationInstObj.bindRationInstDel();
+                rdSpread.setActiveSheetIndex(3);
+            });
+            $("#linkMBGL").click(function(){
+                RationTemplate.bindRationTempDel();
+                rdSpread.setActiveSheetIndex(4);
+            });
+            //解决spreadjs sheet初始化没高度宽度
+            $('#modalCon').width($(window).width()*0.5);
+            $('#gljSelTreeDiv').height($(window).height() - 300);
+            $("#gljSelSheet").height($("#gljSelTreeDiv").height()-21.6);
+            $("#gljSelSheet").width($('#modalCon').width() * 0.63);
+            $(window).resize(function () {
+                $('#modalCon').width($(window).width()*0.5);
+                $('#gljSelTreeDiv').height($(window).height() - 300);
+                $("#gljSelSheet").height($("#gljSelTreeDiv").height()-21.6);
+                $("#gljSelSheet").width($('#modalCon').width()* 0.63);
+            });
+            $.bootstrapLoading.end();
+        }, () => $.bootstrapLoading.end());
+    }
+    
+    $(document).ready(() => {
+        // 初始化编辑
+        explanatoryOprObj.initEditor();
+        initData();
+    });
+})();

+ 0 - 22
web/maintain/ration_repository/js/ration.js

@@ -92,7 +92,6 @@ let rationOprObj = {
         let me = rationOprObj;
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
         sheetCommonObj.bindEscKey(me.workBook, [{sheet: me.workBook.getSheet(0), editStarting: me.onCellEditStart, editEnded: me.onCellEditEnd}]);
-        me.getRationsCodes(rationRepId);
         me.onContextmenuOpr();
         me.rationDelOpr();
         me.setCombo(me.workBook.getSheet(0), 'dynamic');
@@ -612,27 +611,6 @@ let rationOprObj = {
         obj.machinePrice = 0;
         obj.basePrice = 0;
     },
-    isValidUnit: function (rationObj, validUnits) {
-        let rst = true;
-        if(typeof rationObj.unit !== 'undefined' && rationObj.unit && validUnits.indexOf(rationObj.unit) === -1){//无效
-            rst = false;
-        }
-        return rst;
-    },
-    getRationsCodes: function (repId) {
-        let me = rationOprObj;
-        $.ajax({
-            type: 'post',
-            url: 'api/getRationsCodes',
-            data: {data: JSON.stringify({repId: repId})},
-            dataType: 'json',
-            success: function (result) {
-                if(!result.error){
-                    me.rationsCodes = result.data;
-                }
-            }
-        })
-    },
     mixUpdateRequest: function(updateArr, addArr, removeIds, callback) {
         let me = rationOprObj;
         me.saveInString(updateArr);

+ 11 - 25
web/maintain/ration_repository/js/ration_glj.js

@@ -25,7 +25,6 @@ var rationGLJOprObj = {
         }
     },
     getDistTypeTree: function (gljDistType) {
-        let me = this;
         let distType;
         let distTypeTree = {
             prefix : 'gljDistType',
@@ -61,32 +60,19 @@ var rationGLJOprObj = {
         });
         return distTypeTree;
     },
-    getGljDistType: function (callback) {
-        let me = this;
-        $.ajax({
-            type: 'post',
-            url: "api/getGljDistType",
-            dataType: 'json',
-            success: function (result) {
-                if(!result.error && callback){
-                    me.distTypeTree = me.getDistTypeTree(result.data);
-                    callback();
-                }
-            }
-        })
+    initGljDistType: function (gljDistTypeList) {
+        this.distTypeTree = this.getDistTypeTree(gljDistTypeList);
+
     },
     buildSheet: function(sheet) {
-        var me = this;
-        me.sheet = sheet;
-        me.getGljDistType(function () {
-            sheetCommonObj.initSheet(me.sheet, me.setting, 30);
-            me.onContextmenuOpr();
-            me.bindRationGljDelOpr();
-            me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
-            me.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
-            me.sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.onEditStarting);
-            me.sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onCellEditEnd);
-        });
+        this.sheet = sheet;
+        sheetCommonObj.initSheet(this.sheet, this.setting, 30);
+        this.onContextmenuOpr();
+        this.bindRationGljDelOpr();
+        this.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, this.onClipboardPasting);
+        this.sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, this.onClipboardPasted);
+        this.sheet.bind(GC.Spread.Sheets.Events.EditStarting, this.onEditStarting);
+        this.sheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onCellEditEnd);
     },
     bindRationGljDelOpr: function () {
         let me = rationGLJOprObj, spreadBook = me.sheet.getParent();

+ 11 - 17
web/maintain/ration_repository/js/ration_installation.js

@@ -45,23 +45,17 @@ let rationInstObj = {
     isDef: function (v) {
         return v !== undefined && v !== null;
     },
-    getInstallation: function (rationRepId, callback) {
-        let me = this;
-        CommonAjax.post('/rationRepository/api/getInstallation', {rationRepId: rationRepId}, function (rstData) {
-            //建立name - ID 映射, ID - name 映射
-            me.feeItem = {};
-            me.IDMapping = {feeItem: {}, section: {}};
-            for(let feeItem of rstData){
-                me.feeItem[feeItem.feeItem] = {ID: feeItem.ID, section: {}};
-                me.IDMapping['feeItem'][feeItem.ID] = feeItem.feeItem;
-                for(let section of feeItem.section){
-                    me.feeItem[feeItem.feeItem]['section'][section.name] = section.ID;
-                    me.IDMapping['section'][section.ID] = section.name;
-                }
-            }
-            if(callback){
-                callback(rstData);
-            }
+    initInstallation: function (installationList) {
+        //建立name - ID 映射, ID - name 映射
+        this.feeItem = {};
+        this.IDMapping = {feeItem: {}, section: {}};
+        installationList.forEach(item => {
+            this.feeItem[item.feeItem] = {ID: item.ID, section: {}};
+            this.IDMapping.feeItem[item.ID] = item.feeItem;
+            item.section.forEach(section => {
+                this.feeItem[item.feeItem].section[section.name] = section.ID;
+                this.IDMapping.section[section.ID] = section.name;
+            });
         });
     },
     getFeeItemCombo: function () {

+ 44 - 59
web/maintain/ration_repository/js/section_tree.js

@@ -8,42 +8,27 @@ let pageOprObj = {
     rationLibName : null,
     rationLibId : null,
     gljLibId: null,
-    initPage : function() {
-        let me = this, rationLibId = getQueryString("repository");
-        me.getRationLibInfo(rationLibId, function (rstData) {
-            if(rstData.length > 0){
-                me.rationLibName = rstData[0].dispName;
-                me.gljLibId = rstData[0].gljLib;
-                if(!me.gljLibId || typeof me.gljLibId === 'undefined' || me.gljLibId == -1){
-                    alert("没有引用人材机库!");
-                    window.location.href = "/rationRepository/main";
-                }
-                if (me.rationLibName) {
-                    var html = $("#rationname")[0].outerHTML;
-                    html = html.replace("XXX定额库", me.rationLibName);
-                    $("#rationname")[0].outerHTML = html;
-                    me.rationLibId = rationLibId;
-                    sectionTreeObj.getSectionTree(rationLibId);
-                    //job
-                    jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
-                    $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
-                    $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
-                    jobContentOprObj.bindAllEvents($('#txtareaAll'));
-                    //fz
-                    annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
-                    $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
-                    $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
-                    annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
-                }
-                gljSelOprObj.getGljClassTree(pageOprObj.gljLibId, function () {
-                    gljSelOprObj.getSelGljItems(pageOprObj.gljLibId, function () {})});
-            }
-        });
+    initPage : function(libInfo) {
+        this.rationLibId = libInfo.ID;
+        this.gljLibId = libInfo.gljLib;
+        this.rationLibName = libInfo.dispName;
+        $('#rationname').html(`<a href="main">定额库</a><i class="fa fa-angle-right fa-fw"></i>${this.rationLibName}`);
+        if (!this.gljLibId || this.gljLibId === -1) {
+            alert('没有引用人材机库');
+            setTimeout(() => window.location.href = '/rationRepository/main', 2000);
+        }
+        //job
+        jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);
+        $('#addConBtn').click(jobContentOprObj.bindAddConBtn());
+        $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());
+        jobContentOprObj.bindAllEvents($('#txtareaAll'));
+        //fz
+        annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);
+        $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
+        $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
+        annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
     },
-    getRationLibInfo: function (rationLibId, callback) {
-        CommonAjax.post('api/getRationLib', {libId: rationLibId}, callback);
-    }
-}
+};
 
 let sectionTreeObj = {
     cache: null,//ref to tree.items
@@ -243,29 +228,30 @@ let sectionTreeObj = {
             sheetCommonObj.setColumnWidthByRate($('#sectionSpread').width() - 65, this.workBook, [{rateWidth: IDRate}, {rateWidth: nameRate}]);
         }
     },
-    getSectionTree: function (repId) {
-        let me = sectionTreeObj;
-        let url = 'api/getRationTree';
-        let postData = {rationLibId: repId};
-        let sucFunc = function (rstData) {
-            //init
-            me.buildSheet();
-            me.initTree(rstData);
-            me.cache = me.tree.items;
-            me.bindBtn();
-            me.initController(me.tree, me.sheet, me.setting.sheet);
-            me.controller.showTreeData();
-            me.sheet.setFormatter(-1, 0, '@');
-            me.initSelection(me.tree.selected);
-            explanatoryOprObj.bindEvents(exEditor, calcEditor);
-            me.loadRateWidth();
-        };
-        let errFunc = function () {
-
-        };
-        CommonAjax.post(url, postData, sucFunc, errFunc);
+    initSectionTree: function (sectionTree) {
+        //init
+        this.buildSheet();
+        this.initTree(sectionTree);
+        this.cache = this.tree.items;
+        this.bindBtn();
+        this.initController(this.tree, this.sheet, this.setting.sheet);
+        this.controller.showTreeData();
+        this.sheet.setFormatter(-1, 0, '@');
+        this.initSelection(this.tree.selected);
+        explanatoryOprObj.bindEvents(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor);
+        this.loadRateWidth();
+        this.autoLocate();
+    },
+    //自动定位
+    autoLocate: function () {
+        const hash = window.location.hash;
+        const $searchInput = $('#rationSearch');
+        if (hash) {
+            const rationCode = hash.replace('#', '');
+            $searchInput.val(rationCode);
+            this.locateToSection(rationCode);
+        }
     },
-    
     initTree: function (datas) {
         this.tree = idTree.createNew(this.setting.tree);
         this.tree.loadDatas(datas);
@@ -610,8 +596,7 @@ let sectionTreeObj = {
     initTools: function (node) {
         if(this.isDef(node)){
             explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);
-            //explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));
-            explanatoryOprObj.showText(exEditor, calcEditor, node.data.explanation, node.data.ruleText);
+            explanatoryOprObj.showText(explanatoryOprObj.exEditor, explanatoryOprObj.calcEditor, node.data.explanation, node.data.ruleText);
             //job
             jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.ALL;
             jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);

+ 26 - 0
web/maintain/std_glj_lib/css/main.css

@@ -276,4 +276,30 @@ body {
 .modal-fixed-height {
     height:400px;
     overflow-y:auto;
+}
+.reset *{
+    margin: 0;
+    padding: 0;
+}
+.info-list {
+    max-height: 300px;
+    overflow: auto;
+}
+.info-list .list-title{
+    font-weight: bold;
+}
+.info-list li{
+    list-style: none;
+    display: flex;
+}
+.info-list li:hover{
+    background-color: #eee;
+}
+.info-list li span {
+    flex: 1;
+}
+.info-list li a {
+    float: right;
+    width: 30px;
+    text-decoration: none;
 }

+ 16 - 0
web/maintain/std_glj_lib/html/gongliao.html

@@ -189,6 +189,22 @@
             </div>
         </div>
     </div>
+    <div class="modal fade" id="info" data-backdrop="static" style="display: none;" aria-hidden="true">
+        <div class="modal-dialog" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">查找引用</h5>
+                    <button type="button"  class="close typeClose" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">×</span>
+                    </button>
+                </div>
+                <div class="modal-body reset">
+                    <ul id="infoBody" class="info-list">
+                    </ul>
+                </div>
+            </div>
+        </div>
+    </div>
     <!-- JS. -->
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/lib/jquery-contextmenu/jquery.contextMenu.min.js"></script>

+ 44 - 2
web/maintain/std_glj_lib/js/glj.js

@@ -1050,7 +1050,7 @@ let repositoryGljObj = {
                     return {
                         callback: function(){},
                         items: {
-                            "delete": {
+                            delete: {
                                 name: "删除",
                                 disabled: function () {
                                     return !(me.currentCache && me.currentCache[target.row]);
@@ -1060,7 +1060,19 @@ let repositoryGljObj = {
                                     let curSel = _.cloneDeep(sheet.getSelections()[0]);
                                     curSel.colCount = me.setting.header.length;
                                     me.delGljs([curSel]);
-                                }}
+                                }
+                            },
+                            getReference: {
+                                name: '查找引用',
+                                disabled: function () {
+                                    return !(me.currentCache && me.currentCache[target.row]);
+                                },
+                                icon: 'fa-search',
+                                callback: function () {
+                                    const glj = me.currentCache[target.row];
+                                    me.getReference(glj);
+                                }
+                            },
                         }
                     };
                 }
@@ -1070,6 +1082,36 @@ let repositoryGljObj = {
             }
         });
     },
+    getReference: function (glj) {
+        const $info = $('#info');
+        const $infoBody = $('#infoBody');
+        $.bootstrapLoading.start();
+        CommonAjax.post('/stdGljRepository/api/getReference', {repositoryId: glj.repositoryId, gljId: glj.ID}, function (info) {
+            const htmlArr = [];
+            if (!info || !Object.keys(info).length) {
+                htmlArr.push('<li>无引用数据</li>');
+            }
+            for (let libName in info) {
+                htmlArr.push(`<li class="list-title">${libName}</li>`);
+                const rations = info[libName];
+                const rationList = rations.map(ration => {
+                    if (ration.rationRepId) {
+                        return `<li>
+                                    <span>${ration.code}</span>
+                                    <a target="_blank" href="/rationRepository/ration?repository=${ration.rationRepId}#${ration.code}">定位</a>
+                                </li>`;
+                    }
+                    return `<li><span>${ration.code}</span></li>`;
+                });
+                htmlArr.push(...rationList);
+            }
+            $infoBody.html(htmlArr.join(''));
+            $info.modal('show');
+            $.bootstrapLoading.end();
+        }, function () {
+            $.bootstrapLoading.end();
+        });
+    },
     validUpdateObj: function (pasteObj, rowIdx) {
         let rst = {updateGlj: [], updateBasePrcArr: []}, backUpObj = {},
             me = repositoryGljObj,