Преглед на файлове

重构定额库部分代码,合并初始化请求

zeweizhong преди 6 години
родител
ревизия
5ad87116bd

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

@@ -24,6 +24,18 @@ import STDGLJListModel from '../../std_glj_lib/models/gljModel';
 let logger = require('../../../logs/log_helper').logger;
 
 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);

+ 1 - 0
modules/ration_repository/models/glj_repository.js

@@ -12,6 +12,7 @@ const gljModel = mongoose.model('std_glj_lib_gljList');
 const gljClassModel = mongoose.model('std_glj_lib_gljClass');
 
 var gljItemDAO = function(){};
+
 gljItemDAO.prototype.getGljTypes = function(gljLibID, callback){
     gljClassModel.find({"repositoryId": gljLibID, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
         if(data.length) callback(false,data);

+ 32 - 3
modules/ration_repository/models/installation.js

@@ -9,14 +9,43 @@ 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}]});
+            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);
+        }
+    }
+    /*async getInstallation(rationRepId, callback){
+        try {
+            let feeItems = await installFeeItemModel.find({rationRepId: rationRepId});
             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}]});
+                    let sections = await installSectionModel.find({ID: {$in: sids}});
                     feeItem._doc.section = sections;
                 }
             }
@@ -25,7 +54,7 @@ class InstallationDao{
         catch(err){
             callback(err, null);
         }
-    }
+    }*/
 
     async updateSection(updateData, callback){
         try{

+ 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.getRationItemsByLib = async function (rationRepId, showHint = null, returnFields = '') {
     let rationLib = await stdRationLibModel.findOne({ID: rationRepId, deleted: false});
     if(!rationLib){

+ 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);

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

@@ -42,6 +42,10 @@ class GljDao  extends OprDao{
         return rst;
     }
 
+    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){
@@ -72,7 +76,9 @@ class GljDao  extends OprDao{
             }
         }
     }
-
+    async getGljItemsSync(gljLibId) {
+         return await gljModel.find({repositoryId: gljLibId}, '-_id', {lean: true});
+    }
     async getGljItemsByRep(repositoryId,callback = null){
         try {
             let rst = await gljModel.find({repositoryId: repositoryId}).lean();

+ 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>
@@ -683,88 +684,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 - 50
web/maintain/ration_repository/js/gljSelect.js

@@ -39,58 +39,24 @@ let gljSelOprObj = {
             delete glj.ID;
         }
     },
-    getSelGljItems: function(stdGljLibId, callback) {
-        $.bootstrapLoading.start();
-        let me = this;
-        $.ajax({
-            type:"POST",
-            url:"/stdGljRepository/api/getGljItems",
-            data:{"repositoryId": stdGljLibId},
-            dataType:"json",
-            cache:false,
-            timeout:240000,
-            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();
-                    }
-                }
-                $.bootstrapLoading.end();
-            },
-            error:function(err){
-                $.bootstrapLoading.end();
-                alert('获取人材机失败');
+    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 - 15
web/maintain/ration_repository/js/ration.js

@@ -95,7 +95,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');
@@ -626,20 +625,6 @@ let rationOprObj = {
         }
         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 - 29
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,36 +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 () {
-           // gljSelOprObj.getGljClassTree(pageOprObj.gljLibId, function () {
-                //gljSelOprObj.getSelGljItems(pageOprObj.gljLibId, 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 - 67
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,38 +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();
-            //自动定位
-            const hash = window.location.hash;
-            const $searchInput = $('#rationSearch');
-            if (hash) {
-                const rationCode = hash.replace('#', '');
-                $searchInput.val(rationCode);
-                me.locateToSection(rationCode);
-            }
-        };
-        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);
@@ -620,7 +597,7 @@ let sectionTreeObj = {
         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);