Ver código fonte

重构定额人材机选择页面,可调用多个库

vian 5 anos atrás
pai
commit
3c50534d02

+ 28 - 19
modules/complementary_glj_lib/models/gljModel.js

@@ -51,29 +51,34 @@ class GljDao {
     }
 
     //获得用户的补充工料机和用户当前所在编办的标准工料机
-    async getGljItems (stdGljLibId, userId, compilationId, projection, callback){
+    async getGljItems(stdGljLibId, userId, compilationId, projection, callback) {
         let me = this;
-        let rst = {stdGljs: [], complementaryGljs: []};
+        let rst = { stdGljs: [], complementaryGljs: [] };
         //批量获取异步
         async.parallel([
-           async function (cb) {
-               try{
-                   let stdGljs = await stdGljModel.find({repositoryId: stdGljLibId}, projection).lean();
-                   me.sortToNumber(stdGljs);
-                   rst.stdGljs = stdGljs;
-                   cb(null);
-               }
-               catch (err){
-                   cb(err);
-               }
+            async function (cb) {
+                try {
+                    let stdGljs = stdGljLibId ? await stdGljModel.find({ repositoryId: stdGljLibId }, projection).lean() : [];
+                    me.sortToNumber(stdGljs);
+                    rst.stdGljs = stdGljs;
+                    cb(null);
+                }
+                catch (err) {
+                    cb(err);
+                }
 
             },
             function (cb) {
-                complementaryGljModel.find({userId: userId, compilationId: compilationId}, '-_id', {lean: true}, function (err, complementaryGljs) {
-                    if(err){
+                if (!userId || !compilationId) {
+                    rst.complementaryGljs = [];
+                    cb(null);
+                    return;
+                }
+                complementaryGljModel.find({ userId: userId, compilationId: compilationId }, '-_id', { lean: true }, function (err, complementaryGljs) {
+                    if (err) {
                         cb(err);
                     }
-                    else{
+                    else {
                         me.sortToNumber(complementaryGljs);
                         rst.complementaryGljs = complementaryGljs;
                         cb(null);
@@ -81,10 +86,10 @@ class GljDao {
                 });
             }
         ], function (err) {
-            if(err){
+            if (err) {
                 callback(err, null);
             }
-            else{
+            else {
                 callback(0, rst);
             }
         })
@@ -313,8 +318,12 @@ class GljDao {
 
     async getMixedTree(gljLibId, userId, compilationId){
         let rst = {std: [], comple: []};
-        rst.std = await gljClassModel.find({repositoryId: gljLibId}).lean();
-        rst.comple = await compleClassModel.find({userId: userId, compilationId: compilationId}).lean();
+        if (gljLibId) {
+            rst.std = await gljClassModel.find({repositoryId: gljLibId}).lean();
+        }
+        if (userId && compilationId) {
+            rst.comple = await compleClassModel.find({userId: userId, compilationId: compilationId}).lean();
+        }
         return rst;
     }
 }

+ 53 - 1
modules/ration_glj/controllers/ration_glj_controller.js

@@ -5,6 +5,7 @@ let mongoose = require("mongoose")
 let ration_glj_facade = require('../facade/ration_glj_facade')
 import EngineeringLibModel from "../../users/models/engineering_lib_model";
 let logger = require("../../../logs/log_helper").logger;
+const { COMPLEMENTARY_LIB, COMPILATION } = require ('../../../public/common_constants');
 
 module.exports={
     createRationGLJ:createRationGLJ,
@@ -64,7 +65,33 @@ async function getGLJData(req, res) {
         error:0
     }
     try {
-        let info = await ration_glj_facade.getLibInfo(req);
+        let libData = null;
+        let { engineerID, gljLibId, isInitial } = req.params;
+        if (gljLibId !== COMPLEMENTARY_LIB) {
+            gljLibId = +gljLibId;
+        }
+        isInitial = JSON.parse(isInitial);
+        if (!gljLibId || isInitial) { // 替换人材机的话,可能存在gljLibID,但是是初始化的操作
+            console.log(COMPILATION);
+            libData = engineerID === COMPILATION 
+            ? await ration_glj_facade.getLibOptionsForCompilation(req.session.sessionCompilation._id)
+            : await ration_glj_facade.getLibOptions(engineerID);
+            libData.push({ name: '补充人材机', gljLibId: COMPLEMENTARY_LIB });
+            if (gljLibId) { // 替换人材机初始化会触发此条件
+                const orgDefalutLib = libData.find(lib => lib.isDefault);
+                const newDefaultLib = libData.find(lib => lib.gljLibId === +gljLibId);
+                if (orgDefalutLib && newDefaultLib) {
+                    orgDefalutLib.isDefault = false;
+                    newDefaultLib.isDefault = true;
+                }
+            }
+        }
+        if (!gljLibId && libData) {
+            gljLibId = (libData.find(lib => lib.isDefault) || {}).gljLibId;
+        }
+        const info = gljLibId === COMPLEMENTARY_LIB 
+            ? { gljLibId: null, userID: req.session.sessionUser.id, compilationId: req.session.sessionCompilation._id }
+            : { gljLibId, userID: null, compilationId: null };
         ration_glj_facade.getGLJData(info,function (err,datas) {
             if(err){
                 result.error=1;
@@ -73,6 +100,7 @@ async function getGLJData(req, res) {
                 //多单价字段
                 if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
                 result.datas = datas;
+                result.datas.libData = libData;
             }
             res.json(result);
         });
@@ -83,6 +111,30 @@ async function getGLJData(req, res) {
         res.json(result);
     }
 }
+/* async function getGLJData(req, res) {
+    let result={
+        error:0
+    }
+    try {
+        let info = await ration_glj_facade.getLibInfo(req);
+        ration_glj_facade.getGLJData(info,function (err,datas) {
+            if(err){
+                result.error=1;
+                result.message = err.message;
+            }else {
+                //多单价字段
+                if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
+                result.datas = datas;
+            }
+            res.json(result);
+        });
+    }catch (err){
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+        res.json(result);
+    }
+} */
 
 async function addGLJ(req, res){
     let result={

+ 64 - 0
modules/ration_glj/facade/ration_glj_facade.js

@@ -8,6 +8,8 @@ module.exports = {//先 exports再require 防止循环引用
     deleteByRation: deleteByRation,
     getQuantityByProjectGLJ: getQuantityByProjectGLJ,
     getLibInfo: getLibInfo,
+    getLibOptions,
+    getLibOptionsForCompilation,
     getGLJData: getGLJData,
     getGLJDataByCodes:getGLJDataByCodes,
     addGLJ: addGLJ,
@@ -57,6 +59,9 @@ const stdGljModel = mongoose.model('std_glj_lib_gljList');
 const gljClassModel = mongoose.model('std_glj_lib_gljClass');
 const projectDao = require('../../pm/models/project_model').project;
 const compleClassModel = mongoose.model('complementary_glj_section');
+const stdRationLibModel = mongoose.model('std_ration_lib_map');
+const compilationModel = mongoose.model('compilation');
+const engineeringModel = mongoose.model('engineering_lib');
 let gljUtil = require('../../../public/gljUtil');
 
 
@@ -548,6 +553,65 @@ async function getGLJLibByEngineerID  (engineerID) {
     return gljLibId
 }
 
+// 获取人材机选择页面,可选的定额库-人材机库映射选项
+async function getLibOptions(engineerID) {
+    // 找到工程专业绑定的定额库,再获取这些定额库引用的人材机库
+    const engineeringLibModel = new EngineeringLibModel();
+    const engineeringInfo = await engineeringLibModel.findDataByCondition({ _id: engineerID });
+    const rationLibs = engineeringInfo.ration_lib;
+    const rationLibIDs = rationLibs.map(lib => lib.id);
+    const rationLibData = await stdRationLibModel.find({ ID: { $in: rationLibIDs } }, 'ID gljLib').lean();
+    const rst = [];
+    rationLibs.forEach(lib => {
+        rationLibData.forEach(stdLib => {
+            if (+lib.id === +stdLib.ID) {
+                lib.gljLibId = stdLib.gljLib;
+                rst.push(lib);
+            }
+        });
+    });
+    return rst;
+}
+
+// 获取人材机选择库页面,可选的定额库为费用定额下,所有工程专业的定额库(需要去重)
+async function getLibOptionsForCompilation(compilationId) {
+    const compilation = await compilationModel.findOne({ _id: mongoose.Types.ObjectId(compilationId) }, 'ration_valuation bill_valuation');
+    const valuationIDs = [];
+    if (compilation.ration_valuation[0] && compilation.ration_valuation[0].enable) {
+        valuationIDs.push(compilation.ration_valuation[0].id);
+    }
+    if (compilation.bill_valuation[0] && compilation.bill_valuation[0].enable) {
+        valuationIDs.push(compilation.bill_valuation[0].id);
+    }
+    const engineeringLibs = await engineeringModel.find({ valuationID: { $in: valuationIDs }, visible: true }, 'ration_lib');
+    const rationLibs = [];
+    const rationLibIDs = [];
+    let hasDefalut = false;
+    engineeringLibs.forEach(lib => {
+        lib.ration_lib.forEach(rLib => {
+            if (!rationLibIDs.includes(rLib.id)) {
+                rationLibIDs.push(rLib.id);
+                rationLibs.push({
+                    isDefault: hasDefalut ? false: rLib.isDefault,
+                    name: rLib.name,
+                    id: rLib.id
+                });
+                if (rLib.isDefault) {
+                    hasDefalut = true;
+                }
+            }
+        });
+    });
+    const stdRationLibs = await stdRationLibModel.find({ ID: { $in: rationLibIDs } }, 'ID gljLib').lean();
+    rationLibs.forEach(lib => {
+        stdRationLibs.forEach(stdLib => {
+            if (+lib.id === +stdLib.ID) {
+                lib.gljLibId = stdLib.gljLib;
+            }
+        });
+    });
+    return rationLibs;
+}
 
 function getGLJData(info, callback) {
     let gljDao = new GljDao();

+ 1 - 1
modules/ration_glj/routes/ration_glj_route.js

@@ -8,7 +8,7 @@ let rgController = require('../controllers/ration_glj_controller');
 module.exports = function (app) {
 
     var rgRouter = express.Router();
-    rgRouter.get('/getGLJData/:engineerID', rgController.getGLJData);
+    rgRouter.get('/getGLJData/:engineerID/:gljLibId/:isInitial', rgController.getGLJData);
     rgRouter.post('/getGLJDataByCodes',rgController.getGLJDataByCodes);
     rgRouter.post('/addGLJ',rgController.addGLJ);
     rgRouter.post('/replaceGLJ',rgController.replaceGLJ);

+ 9 - 1
public/common_constants.js

@@ -77,7 +77,15 @@
         REPAIR_MAINTENANCE_FEE: 33,
     };
 
+    // 补充人材机库
+    const COMPLEMENTARY_LIB = 'complementaryLib';
+
+    // 费用定额
+    const COMPILATION = 'compilation';
+
     return {
-        fixedFlag
+        fixedFlag,
+        COMPLEMENTARY_LIB,
+        COMPILATION,
     };
 })

+ 10 - 2
web/building_saas/complementary_ration_lib/html/dinge.html

@@ -18,6 +18,10 @@
     <link rel="shortcut icon" href="/web/building_saas/css/favicon.ico">
     <link rel="icon" type="image/gif" href="/web/building_saas/css/animated_favicon1.gif">
     <style type="text/css">
+        .form-control-inline {
+            display: inline-block !important;
+            width: 80% !important;
+        }
         div.resize-y{
             height: 5px;
             background: #efefef;
@@ -520,8 +524,12 @@
             <div class="modal-body" style="padding-left: 0; padding-right: 3px; margin-left: 0;">
                 <div style="width: 36%; float: left;">
                     &nbsp;
-                    <input type="radio" class="glj-radio" name="glj" value="stdGljs">标准&nbsp;&nbsp;
-                    <input type="radio" class="glj-radio" name="glj" value="complementaryGljs">补充&nbsp;&nbsp;
+                    <select class="form-control  form-control-sm form-control-inline" id="glj-lib-select">
+                        <option value="1">1</option>
+                        <option value="2">2</option>
+                    </select>
+<!--                     <input type="radio" class="glj-radio" name="glj" value="stdGljs">标准&nbsp;&nbsp;
+                    <input type="radio" class="glj-radio" name="glj" value="complementaryGljs">补充&nbsp;&nbsp; -->
                     <div  class="modal-auto-height" id="gljSelTreeDiv" style="overflow: hidden">
                         <div style="width: 100%; height: 100%; overflow: auto">
                             <ul id="selGljTree" class="ztree"></ul>

+ 67 - 84
web/building_saas/complementary_ration_lib/js/gljSelect.js

@@ -3,10 +3,10 @@
  */
 
 let gljSelOprObj = {
+    distTypeTree: null,
     parentNodeIds: {},
     treeObj:null,
     rootNode: null,//分类树根节点
-    radiosSelected: null,//allGljs, stdGljs, complementaryGljs
     workBook: null,
     selectedList: [],//选中的工料机
     setting: {
@@ -39,23 +39,6 @@ let gljSelOprObj = {
             delete glj.ID;
         }
     },
-    getSelGljItems: function(gljData) {
-        this.stdGljList = gljData.stdGljs;
-        //兼容多单价,计算补充定额价格时,套多单价人材机的时候,默认取第一个价格
-        for(let sGlj of this.stdGljList){
-            if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined'){
-                sGlj.basePrice = sGlj.priceProperty.price1;
-            }
-        }
-        this.complementaryGljList = gljData.complementaryGljs;
-        this.switchToGljId(this.stdGljList);
-        this.switchToGljId(this.complementaryGljList);
-        this.setProp('type', 'std', this.stdGljList);
-        this.setProp('type', 'complementary', this.complementaryGljList);
-        this.sortGlj(this.stdGljList);
-        this.sortGlj(this.complementaryGljList);
-        gljAdjOprObj.gljList = this.stdGljList.concat(this.complementaryGljList);
-    },
     initClassTree: function (type, treeData) {
         let me = this;
         if (me.treeObj) {
@@ -75,28 +58,6 @@ let gljSelOprObj = {
             }
         }
     },
-    getGljClassTree: function (gljLibId, callback) {
-        let me = this;
-        let url = '/complementartGlj/api/getMixedTree';
-        let postData = {gljLibId: gljLibId};
-        let sucFunc = function (rstData) {
-            me.treeData = rstData;
-            me.initClassTree('std', me.treeData.std);
-            gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
-            if(callback){
-                callback();
-            }
-        };
-        let errFunc = function () {
-
-        };
-        CommonAjax.post(url, postData, sucFunc, errFunc);
-    },
-    getGljClassTree: function (mixedTreeData) {
-        this.treeData = mixedTreeData;
-        this.initClassTree('std', this.treeData.std);
-        gljSelOprObj.buildSheet($('#gljSelSheet')[0]);
-    },
     buildSheet: function (container) {
         let me = gljSelOprObj;
         me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
@@ -107,7 +68,64 @@ let gljSelOprObj = {
         me.workBook.getSheet(0).bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.workBook.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClicked);//复选框点击事件
         me.bindBtnOpr($('#gljSelY'));
-        me.radiosChange();
+    },
+    setGLJItems: function(stdGLJs, complementaryGLJs) {
+        this.stdGljList = stdGLJs;
+        //兼容多单价,计算补充定额价格时,套多单价人材机的时候,默认取第一个价格
+        for(let sGlj of this.stdGljList){
+            if(sGlj.priceProperty && typeof sGlj.priceProperty.price1 !== 'undefined'){
+                sGlj.basePrice = sGlj.priceProperty.price1;
+            }
+        }
+        this.complementaryGljList = complementaryGLJs;
+        this.switchToGljId(this.stdGljList);
+        this.switchToGljId(this.complementaryGljList);
+        this.setProp('type', 'std', this.stdGljList);
+        this.setProp('type', 'complementary', this.complementaryGljList);
+        this.sortGlj(this.stdGljList);
+        this.sortGlj(this.complementaryGljList);
+    },
+    initLibOptions: function (libData) {
+        const html = libData.reduce((acc, lib) => acc += `<option ${lib.isDefault ? 'selected="selected"' : ''} value="${lib.gljLibId}">${lib.name}</option>`, '');
+        $('#glj-lib-select').html(html);
+    },
+    // 初始化选择页面
+    initView: async function (gljLibId, isInitial) {
+        try {
+            $.bootstrapLoading.start();
+            const { libData, treeData, distTypeTree, stdGLJ, complementaryGLJs } = await this.getViewData(gljLibId);
+            if (isInitial) {
+                this.initLibOptions(libData);
+                $('#gljSearchKeyword').val('');
+                setTimeout(() => $('#selGlj').modal('show'), 200);
+            }
+            if (!this.workBook) {
+                this.buildSheet($('#gljSelSheet')[0]);
+            }
+            this.distTypeTree = distTypeTree;
+            this.setGLJItems(stdGLJ, complementaryGLJs);
+            this.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
+            this.showGljList = [];
+            this.setShowGljList(this.stdGljList, true);
+            if (treeData.std.length) {
+                this.initClassTree('std', treeData.std);
+            } else if (treeData.comple.length) {
+                this.initClassTree('comple', treeData.comple);
+            } else {
+                throw '没有有效的分类树。';
+            }
+            this.filterDatasAndShow();
+        } catch (err) {
+            console.log(err);
+            alert(err);
+        } finally {
+            $.bootstrapLoading.end();
+        }
+    },
+    getViewData: async function (gljLibId) {
+        const url = `/rationGlj/getGLJData/${commonConstants.COMPILATION}/${gljLibId}/true`;
+        const data = await ajaxGet(url);
+        return data.datas;
     },
     onClipboardPasting: function (sender, args) {
         args.cancel = true;
@@ -172,41 +190,16 @@ let gljSelOprObj = {
             me.showGljList.push(gljList[i]);
         }
     },
-    //初始默认radio
-    initRadio: function () {
-        let me = gljSelOprObj;
-        $('#gljSearchKeyword').val('');//恢复搜索文本
-        me.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
-        //默认radio所有工料机
-        if(typeof $("input[name='glj']:checked")[0] !== 'undefined'){
-            $("input[name='glj']:checked")[0].checked = false;
-        }
-        $("input[value = 'stdGljs']")[0].checked = true;
-        me.radiosSelected = 'stdGljs';
-        //初始为标准工料机
-        me.showGljList = [];
-        if(me.radiosSelected === 'stdGljs'){
-            me.setShowGljList(me.stdGljList, true);
-            //me.setShowGljList(me.complementaryGljList, true);
-            me.sortGlj(me.showGljList);
-        }
-    },
     filterDatasAndShow: function () {
+        const gljLib = $('#glj-lib-select').val();
         let me = gljSelOprObj;
-        let val = $("input[name='glj']:checked").val();
-        me.radiosSelected = val;
         //选择改变,数据重新筛选显示
         me.showGljList = [];
-        if(me.radiosSelected === 'allGljs'){
-            me.setShowGljList(me.stdGljList);
+        if (gljLib === commonConstants.COMPLEMENTARY_LIB) {
             me.setShowGljList(me.complementaryGljList);
-        }
-        else if(me.radiosSelected === 'stdGljs'){
+        } else {
             me.setShowGljList(me.stdGljList);
         }
-        else if(me.radiosSelected === 'complementaryGljs'){
-            me.setShowGljList(me.complementaryGljList);
-        }
         //搜索匹配
         let searchStr = $('#gljSearchKeyword').val();
         if(searchStr && searchStr.trim() != ''){
@@ -215,10 +208,9 @@ let gljSelOprObj = {
                 return reg.test(data.code) || reg.test(data.name);
             });
         }
-        me.sortGlj(me.showGljList);
+        //me.sortGlj(me.showGljList);
         //重新显示
         me.showGljItems(me.showGljList, me.gljCurTypeId);
-        //切换radio后更新cache
         if (me.currentOprParent = 1) {
             if(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]){
                 me.currentCache = me.getParentCache(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]);
@@ -230,19 +222,6 @@ let gljSelOprObj = {
             me.currentCache = me.getCache();
         }
     },
-    //监听radios选择事件
-    radiosChange: function () {
-        let me = gljSelOprObj;
-        $('.glj-radio').change(function () {
-            if($(this).val() === 'stdGljs') {
-                me.initClassTree('std', me.treeData.std);
-            } else {
-                me.initClassTree('comple', me.treeData.comple);
-            }
-            me.filterDatasAndShow();
-        });
-    },
-
     getParentCache: function (nodes) {
         let me = gljSelOprObj, rst = [];
         for(let i = 0; i < me.showGljList.length; i++){
@@ -349,6 +328,10 @@ let gljSelTreeOprObj = {
 };
 
 $(document).ready(function () {
+    $('#glj-lib-select').change(function () {
+        const gljLibId = $(this).val();
+        gljSelOprObj.initView(gljLibId, false);
+    });
     $('#gljSearchKeyword').change(function () {
         gljSelOprObj.filterDatasAndShow();
     });

+ 1 - 0
web/building_saas/complementary_ration_lib/js/init.js

@@ -40,6 +40,7 @@ const initialization = (() => {
                 rdSpreadEscSheets.push({sheet: rdSpread.getSheet(2), editStarting: rationCoeOprObj.onEditStarting, editEnded: rationCoeOprObj.onEditEnded});
                 rdSpreadEscSheets.push({sheet: rdSpread.getSheet(3), editStarting: rationInstObj.onEditStarting, editEnded: rationInstObj.onEditEnded});
                 sheetCommonObj.bindEscKey(rdSpread, rdSpreadEscSheets);
+                gljAdjOprObj.gljList = data.mixedGLJData.stdGljs.concat(data.mixedGLJData.complementaryGljs);
                 pageOprObj.initPage();
 
                 $("#linkGLJ").click(function(){

+ 1 - 6
web/building_saas/complementary_ration_lib/js/ration_glj.js

@@ -113,12 +113,7 @@ var rationGLJOprObj = {
                         items: {
                             "add": {
                                 name: "添加工料机", disabled: addDis, icon: "fa-plus", callback: function (key, opt) {
-                                    //默认radio所有工料机
-                                    gljSelOprObj.initRadio();
-                                    gljSelOprObj.gljCurTypeId = null;
-                                    gljSelOprObj.initClassTree('std', gljSelOprObj.treeData.std);
-                                    //弹出窗口
-                                    $('#selGlj').modal('show');
+                                    gljSelOprObj.initView(0, true);
                                 }
                             },
                             "delete": {

+ 0 - 2
web/building_saas/complementary_ration_lib/js/section_tree.js

@@ -20,8 +20,6 @@ let pageOprObj = {
         $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());
         $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());
         annotationOprObj.bindAllEvents($('#fzTxtareaAll'));
-        gljSelOprObj.getGljClassTree(this.mixedTreeData);
-        gljSelOprObj.getSelGljItems(this.mixedGLJData);
     },
     getRationLibInfo: function (rationLibId, callback) {
         CommonAjax.post('api/getRationLib', {rationRepId: rationLibId}, callback);

+ 4 - 0
web/building_saas/css/custom.css

@@ -431,4 +431,8 @@ input.text-right{
 .poj-list {
     height: 1000px; 
     background: #f7f7f9;
+}
+.form-control-inline {
+    display: inline-block !important;
+    width: 80% !important;
 }

+ 4 - 2
web/building_saas/main/html/main.html

@@ -1069,8 +1069,10 @@
                 <div class="modal-body" style="padding-left: 0; padding-right: 3px; margin-left: 0;">
                         <div style="width: 32%; float: left;">
                             &nbsp;
-                            <input type="radio" class="glj-radio" name="glj" value="stdGLJ">标准&nbsp;&nbsp;
-                            <input type="radio" class="glj-radio" name="glj" value="complementaryGLJs">补充&nbsp;&nbsp;
+                            <select class="form-control  form-control-sm form-control-inline" id="glj-lib-select">
+                            </select>
+ <!--                            <input type="radio" class="glj-radio" name="glj" value="stdGLJ">标准&nbsp;&nbsp;
+                            <input type="radio" class="glj-radio" name="glj" value="complementaryGLJs">补充&nbsp;&nbsp; -->
                             <div  class="modal-auto-height" id="componentTreeDiv" style=" height: 435px; overflow: hidden;">
                                 <!--<div class="print-list">-->
                                 <div style="width: 100%; height: 100%; overflow: auto">

+ 3 - 3
web/building_saas/main/js/models/ration_glj.js

@@ -538,10 +538,10 @@ let ration_glj = {
             }
             return node
         };
-        ration_glj.prototype.getGLJData = function (cb) {
+        ration_glj.prototype.getGLJData = function (url, cb) {
             let property = projectObj.project.projectInfo.property;
-            let engineerID = property.engineering_id;
-            CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
+            //let engineerID = property.engineering_id;
+            CommonAjax.get(url, function (data) {
                 //编办中有多单价设置
                 if(data.datas.priceProperties && data.datas.priceProperties.length > 0){
                     let tem = _.find(data.datas.priceProperties,{region:property.region,taxModel:parseInt(property.taxType)});

+ 13 - 76
web/building_saas/main/js/views/glj_view.js

@@ -998,12 +998,10 @@ var gljOprObj = {
     },
     filterLibGLJSheetData: function () {
         let me = this;
-        let val = $("input[name='glj']:checked").val();
-        if (val == 'allGljs') {
-            me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
-        } else {
-            me.gljLibSheetData = me[val];
-        }
+        const selectLibID = $('#glj-lib-select').val();
+        me.gljLibSheetData = selectLibID === commonConstants.COMPLEMENTARY_LIB
+            ? me.complementaryGLJs
+            : me.stdGLJ;
         if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
             me.filterLibGLJByType();
         }else if($('#actionType').val() == 'addMix'){
@@ -1432,7 +1430,10 @@ var gljOprObj = {
         let zTree = $.fn.zTree.getZTreeObj("gljTree");
         let node = null;
         if (ID) node = zTree.getNodesByParam('ID', ID, null)[0];
-        if (!node) node = zTree.getNodeByTId('gljTree_1');
+        if (!node) {
+            node = zTree.getNodeByTId('gljTree_1');
+            ID = node.ID;
+        }
         zTree.selectNode(node);
         gljOprObj.gljCurTypeId = ID;
         gljOprObj.filterLibGLJSheetData();
@@ -1537,72 +1538,7 @@ var gljOprObj = {
 
 $(function () {
     $('#glj_tree_div').on('shown.bs.modal', function (e) {
-        if (gljOprObj.gljLibSpresd == undefined) {
-            gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
-            sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
-            gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
-            gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
-            gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
-            gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
-            gljOprObj.gljLibSheet.options.isProtected = true;
-            gljOprObj.gljLibSheet.name('glj_lib');
-        }
-        gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
-        let gljClass = 0, selectMap = {};
-        if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert' || $('#actionType').val() == 'insertEquipment') {//插入,添加
-            gljOprObj.GLJSelection = [];
-        } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
-            let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
-            let connect_key = gljOprObj.getIndex(selected, gljKeyArray);
-            gljOprObj.GLJSelection = [connect_key];
-            selectMap[connect_key] = true;
-            gljOprObj.filterLibGLJByType();
-        }else if($('#actionType').val() =='addMix'){//添加组成物
-            gljOprObj.GLJSelection = [];
-            projectGljObject.filterLibGLJForMixRatio();
-            /*selections = projectGljObject.mixRatioData;  添加组成物的时候先不选中
-             gljOprObj.GLJSelection = [];
-             for(let s of selections){
-             let s_key = gljOprObj.getIndex(s, gljKeyArray);
-             selectMap[s_key] = true;
-             gljOprObj.GLJSelection.push(s_key);
-             }*/
-        }
-        for(let item of gljOprObj.gljLibSheetData){
-            let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
-            if(selectMap[item_key]){
-                item.select = 1 ;
-                gljClass = item.gljClass;
-            }
-        }
-        //替换,焦点定位至当前选中人材机
-        if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
-            gljOprObj.locateZTree(gljClass);
-            let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
-            let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
-            gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
-            gljOprObj.gljLibSheet.setActiveCell(index, 0);
-            gljOprObj.initSelection({row: index});
-            gljOprObj.gljLibSpresd.focus(true);
-        } else if ($('#actionType').val() === 'insertEquipment') {//右键插入设备,人材机选择窗口,应默认固定到分类"养护管理设备"。
-            let locateClass = gljOprObj.treeData.std.find(function (stdClass) {
-                return stdClass.Name === '养护管理设备';
-            });
-            if (locateClass) {
-                gljClass = locateClass.ID;
-                gljOprObj.locateZTree(gljClass);
-                gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
-                gljOprObj.gljLibSheet.setActiveCell(0, 0);
-                gljOprObj.initSelection({row: 0});
-            }
-        } else if ($('#actionType').val() === 'add') {
-            gljOprObj.locateZTree(null);
-            gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
-            gljOprObj.gljLibSheet.setActiveCell(0, 0);
-            gljOprObj.initSelection({row: 0});
-        } else {
-            gljOprObj.showLibGLJSheetData();
-        }
+        gljContextMenu.initGLJSelectView();
     });
 
     $('#mreplace_next_div').on('shown.bs.modal', function (e) {
@@ -1629,11 +1565,12 @@ $(function () {
                 gljOprObj.initClassTree('comple', gljOprObj.treeData.comple, true);
             }
             gljOprObj.initSelection({row: 0});
-            //gljOprObj.gljLibSheetData = gljOprObj[val];
-            /*gljOprObj.filterLibGLJSheetData();
-             gljOprObj.showLibGLJSheetData();*/
         }
     });
+    // 更改选择库
+    $('#glj-lib-select').change(function () {
+        getGLJData('change', false);
+    })
     /*    //工料机搜索
      $('#gljSearchKeyword').change(function () {
      gljOprObj.filterLibGLJSheetData();

+ 113 - 18
web/building_saas/main/js/views/glj_view_contextMenu.js

@@ -370,13 +370,101 @@ var gljContextMenu = {
         }
         //controller.setTreeSelected(controller.tree.items[target.row]);
         return target.hitTestType === GC.Spread.Sheets.SheetArea.viewport || target.hitTestType === GC.Spread.Sheets.SheetArea.rowHeader;
+    },
+    initGLJSelectView: function () {
+        if (gljOprObj.gljLibSpresd == undefined) {
+            gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
+            sheetCommonObj.spreadDefaultStyle(gljOprObj.gljLibSpresd);
+            gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
+            gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
+            gljOprObj.gljLibSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, gljOprObj.onSelectionChanged);
+            gljOprObj.gljLibSheet.setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
+            gljOprObj.gljLibSheet.options.isProtected = true;
+            gljOprObj.gljLibSheet.name('glj_lib');
+        }
+        gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
+        let gljClass = 0, selectMap = {};
+        if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert' || $('#actionType').val() == 'insertEquipment') {//插入,添加
+            gljOprObj.GLJSelection = [];
+        } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
+            let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
+            let connect_key = gljOprObj.getIndex(selected, gljKeyArray);
+            gljOprObj.GLJSelection = [connect_key];
+            selectMap[connect_key] = true;
+            gljOprObj.filterLibGLJByType();
+        }else if($('#actionType').val() =='addMix'){//添加组成物
+            gljOprObj.GLJSelection = [];
+            projectGljObject.filterLibGLJForMixRatio();
+        }
+        for(let item of gljOprObj.gljLibSheetData){
+            let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
+            if(selectMap[item_key]){
+                item.select = 1 ;
+                gljClass = item.gljClass;
+            }
+        }
+        //替换,焦点定位至当前选中人材机
+        if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){
+            gljOprObj.locateZTree(gljClass);
+            let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
+            let index = _.findIndex(gljOprObj.gljLibSheetData, {code: selected.code});
+            gljOprObj.gljLibSheet.showRow(index, GC.Spread.Sheets.VerticalPosition.center);
+            gljOprObj.gljLibSheet.setActiveCell(index, 0);
+            gljOprObj.initSelection({row: index});
+            gljOprObj.gljLibSpresd.focus(true);
+        } else if ($('#actionType').val() === 'insertEquipment') {//右键插入设备,人材机选择窗口,应默认固定到分类"养护管理设备"。
+            let locateClass = gljOprObj.treeData.std.find(function (stdClass) {
+                return stdClass.Name === '养护管理设备';
+            });
+            if (locateClass) {
+                gljClass = locateClass.ID;
+                gljOprObj.locateZTree(gljClass);
+                gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
+                gljOprObj.gljLibSheet.setActiveCell(0, 0);
+                gljOprObj.initSelection({row: 0});
+            }
+        } else if ($('#actionType').val() === 'add') {
+            gljOprObj.locateZTree(null);
+            gljOprObj.gljLibSheet.showRow(0, GC.Spread.Sheets.VerticalPosition.top);
+            gljOprObj.gljLibSheet.setActiveCell(0, 0);
+            gljOprObj.initSelection({row: 0});
+        } else {
+            gljOprObj.showLibGLJSheetData();
+        }
+    }
+}
+
+function initLibOptions(libData) {
+    const html = libData.reduce((acc, lib) => acc += `<option ${lib.isDefault ? 'selected="selected"' : ''} value="${lib.gljLibId}">${lib.name}</option>`, '');
+    $('#glj-lib-select').html(html);
+}
+
+function getActionUrl(actionType) {
+    const rootUrl = `/rationGlj/getGLJData/${projectObj.project.projectInfo.property.engineering_id}`
+    switch (actionType) {
+        case 'add':
+        case 'addMix':
+        case 'insertEquipment':
+            return `${rootUrl}/0/true`;
+        case 'replace':
+        case 'm_replace':
+            const selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
+            const gljLibId = selected.repositoryId || commonConstants.COMPLEMENTARY_LIB;
+            return `${rootUrl}/${gljLibId}/true`;
+        case 'change': // 更改选择库
+            const selectGLJLibID = $('#glj-lib-select').val();
+            return `${rootUrl}/${selectGLJLibID}/false`;
     }
 }
 
-function getGLJData(actionType) {
+function getGLJData(actionType, isInitial = true) {
+    const url = getActionUrl(actionType);
+    if (actionType === 'change') {
+        actionType = $('#actionType').val();
+    }
     $('#actionType').val(actionType);
     $.bootstrapLoading.start();
-    projectObj.project.ration_glj.getGLJData(function (result) {
+    projectObj.project.ration_glj.getGLJData(url, function (result) {
         // 目前只有浙江2015需要特殊处理处理
         if (gljOprObj.sortSelectViewGLJ) {
             gljOprObj.sortSelectViewGLJ(result.datas.stdGLJ);
@@ -385,9 +473,6 @@ function getGLJData(actionType) {
             result.datas.stdGLJ = _.sortBy(result.datas.stdGLJ, 'code');
             result.datas.complementaryGLJs = _.sortBy(result.datas.complementaryGLJs, 'code');
         }
-        gljOprObj.treeData = result.datas.treeData;
-        //zTreeHelper.createTree(result.datas.treeData, gljOprObj.gljTreeSetting, "gljTree", gljOprObj);
-        gljOprObj.initClassTree('std', gljOprObj.treeData.std);
         gljOprObj.stdGLJ=result.datas.stdGLJ;
         gljOprObj.complementaryGLJs=result.datas.complementaryGLJs;
         for(let compleGlj of gljOprObj.complementaryGLJs){
@@ -397,20 +482,30 @@ function getGLJData(actionType) {
         gljOprObj.AllRecode=gljOprObj.stdGLJ.concat(gljOprObj.complementaryGLJs);
         //gljOprObj.AllRecode=gljOprObj.stdGLJ;
         gljOprObj.distTypeTree=gljOprObj.getComboData(result.datas.distTypeTree);
-        $('#modalCon').width($(window).width()*0.5);
-        $("input[name='glj']").get(0).checked=true;
-        $.bootstrapLoading.end();
-        if(actionType == "m_replace"){
-            $('#glj_selected_conf').hide();
-            $('#replace_next_btn').show();
-        }else {
-            $('#glj_selected_conf').show();
-            $('#replace_next_btn').hide();
+        gljOprObj.treeData = result.datas.treeData;
+        if (gljOprObj.treeData.std.length) {
+            gljOprObj.initClassTree('std', gljOprObj.treeData.std, !isInitial);
+        } else if (gljOprObj.treeData.comple.length) {
+            gljOprObj.initClassTree('comple', gljOprObj.treeData.comple, !isInitial);
         }
-        $("#glj_tree_div").modal({show:true});
-        setTimeout(function(){
-            gljOprObj.gljLibSpresd?gljOprObj.gljLibSpresd.refresh():'';
-        }, 200);
+        if (isInitial) {
+            initLibOptions(result.datas.libData);
+            $('#modalCon').width($(window).width()*0.5);
+            if(actionType == "m_replace"){
+                $('#glj_selected_conf').hide();
+                $('#replace_next_btn').show();
+            }else {
+                $('#glj_selected_conf').show();
+                $('#replace_next_btn').hide();
+            }
+            $("#glj_tree_div").modal({show:true});
+            setTimeout(function(){
+                gljOprObj.gljLibSpresd?gljOprObj.gljLibSpresd.refresh():'';
+            }, 200);
+        } else {
+            gljContextMenu.initGLJSelectView();
+        }
+        $.bootstrapLoading.end();
     })
 }