Browse Source

补充定额库,人材机选择页面可选择多个库

vian 5 năm trước cách đây
mục cha
commit
cbd0bb83f8

+ 2 - 3
config/gulpConfig.js

@@ -18,6 +18,8 @@ module.exports = {
         'lib/lodash/lodash.js',
         'public/web/commonAlert.js',
         'public/web/headerOpr.js',
+        'public/common_util.js',
+        'public/common_constants.js',
         'lib/jquery-editable-select/jquery.editable-select.min.js'
     ],
     common_css:[
@@ -56,7 +58,6 @@ module.exports = {
         'web/building_saas/glj/js/socket.io.slim.js',
         'public/web/socket/connection.js',
         'public/billsUtil.js',
-        'public/common_constants.js',
         'web/building_saas/main/js/models/importStdInterfaceBase.js',
         'web/common/components/share/index.js',
         'web/building_saas/pm/js/**/*.js',
@@ -79,10 +80,8 @@ module.exports = {
         // 'test/tmp_data/test_ration_calc/ration_calc_base.js',
         'lib/pinyinjs/pinyin_dict_firstletter.js',
         'lib/pinyinjs/pinyinUtil.js',
-        'public/common_constants.js',
         'web/building_saas/main/js/models/main_consts.js',
         'web/over_write/config/compilation_config.js',
-        'public/web/common_util.js',
         'public/web/encoding_util.js',
         'web/building_saas/glj/js/project_glj.js',
         'web/building_saas/glj/js/composition.js',

+ 16 - 11
modules/complementary_glj_lib/models/gljModel.js

@@ -144,29 +144,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();
+                try {
+                    let stdGljs = stdGljLibId ? await stdGljModel.find({ repositoryId: stdGljLibId }, projection).lean() : [];
                     me.sortToNumber(stdGljs);
                     rst.stdGljs = stdGljs;
                     cb(null);
                 }
-                catch (err){
+                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);
@@ -174,15 +179,15 @@ class GljDao {
                 });
             }
         ], function (err) {
-            if(err){
+            if (err) {
                 callback(err, null);
             }
-            else{
+            else {
                 callback(0, rst);
             }
         })
 
-    };
+    }
 
     async getStdItems (stdGljLibId, projection, callback) {
         try {

+ 52 - 2
modules/ration_glj/controllers/ration_glj_controller.js

@@ -5,7 +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 } = require('../../../public/common_constants');
+const { COMPILATION, COMPLEMENTARY_LIB } = require('../../../public/common_constants');
 
 module.exports={
     createRationGLJ:createRationGLJ,
@@ -102,7 +102,7 @@ async function getGLJDataPaging(req, res) {
     }
 }
 
-async function getGLJData(req, res) {
+/* async function getGLJData(req, res) {
     let result={
         error:0
     }
@@ -125,6 +125,56 @@ async function getGLJData(req, res) {
         result.message = err.message;
         res.json(result);
     }
+} */
+async function getGLJData(req, res) {
+    let result={
+        error:0
+    }
+    try {
+        let libData = null;
+        let { engineerID, gljLibId, isInitial } = req.params;
+        if (gljLibId !== COMPLEMENTARY_LIB) {
+            gljLibId = +gljLibId;
+        }
+        isInitial = JSON.parse(isInitial);
+        if (!gljLibId || isInitial) { // 替换人材机的话,可能存在gljLibID,但是是初始化的操作
+            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;
+                result.message = err.message;
+            }else {
+                //多单价字段
+                if(req.session.sessionCompilation.priceProperties) datas.priceProperties = req.session.sessionCompilation.priceProperties;
+                result.datas = datas;
+                result.datas.libData = libData;
+            }
+            res.json(result);
+        });
+    }catch (err){
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+        res.json(result);
+    }
 }
 
 async function addGLJ(req, res){

+ 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('/getGLJDataPaging', rgController.getGLJDataPaging);
     rgRouter.post('/getGLJDataByCodes',rgController.getGLJDataByCodes);
     rgRouter.post('/addGLJ',rgController.addGLJ);

+ 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;
@@ -521,8 +525,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="height: 435px; overflow: hidden">
                         <div style="width: 100%; height: 100%; overflow: auto">
                             <ul id="selGljTree" class="ztree"></ul>

+ 77 - 29
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,7 +39,7 @@ let gljSelOprObj = {
             delete glj.ID;
         }
     },
-    getSelGljItems: function(gljData) {
+    /* getSelGljItems: function(gljData) {
         this.stdGljList = gljData.stdGljs;
         //兼容多单价,计算补充定额价格时,套多单价人材机的时候,默认取第一个价格
         for(let sGlj of this.stdGljList){
@@ -61,7 +61,7 @@ let gljSelOprObj = {
                 glj.basePrice = glj.priceProperty && glj.priceProperty[priceField] ? glj.priceProperty[priceField] : 0;
             }
         }
-    },
+    }, */
     initClassTree: function (type, treeData) {
         let me = this;
         if (me.treeObj) {
@@ -81,11 +81,11 @@ let gljSelOprObj = {
             }
         }
     },
-    getGljClassTree: function (mixedTreeData) {
+    /* 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);
@@ -96,7 +96,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;
@@ -162,7 +219,7 @@ let gljSelOprObj = {
         }
     },
     //初始默认radio
-    initRadio: function () {
+    /* initRadio: function () {
         let me = gljSelOprObj;
         $('#gljSearchKeyword').val('');//恢复搜索文本
         me.selectedList = [].concat(rationGLJOprObj.cache['_GLJ_' + rationGLJOprObj.currentRationItem.ID]);
@@ -179,23 +236,17 @@ let gljSelOprObj = {
             //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() != ''){
@@ -204,10 +255,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]);
@@ -220,7 +270,7 @@ let gljSelOprObj = {
         }
     },
     //监听radios选择事件
-    radiosChange: function () {
+    /* radiosChange: function () {
         let me = gljSelOprObj;
         $('.glj-radio').change(function () {
             if($(this).val() === 'stdGljs') {
@@ -230,7 +280,7 @@ let gljSelOprObj = {
             }
             me.filterDatasAndShow();
         });
-    },
+    }, */
 
     getParentCache: function (nodes) {
         let me = gljSelOprObj, rst = [];
@@ -338,15 +388,13 @@ let gljSelTreeOprObj = {
 };
 
 $(document).ready(function () {
-    $('#gljSearchKeyword').change(function () {
-        gljSelOprObj.filterDatasAndShow();
-    });
-    $('#gljSearchKeyword').bind('keypress', function (e) {
-        if(e.keyCode === 13){
-            $(this).blur();
-            return false;
-        }
+    $('#glj-lib-select').change(function () {
+        const gljLibId = $(this).val();
+        gljSelOprObj.initView(gljLibId, false);
     });
+    $('#gljSearchKeyword').on('keyup', _.debounce(function () {
+        gljSelOprObj.filterDatasAndShow();  
+    }, 300));
     $('#selGlj').on('shown.bs.modal', function () {
         if (gljSelOprObj.workBook) {
             gljSelOprObj.workBook.refresh();

+ 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

@@ -127,12 +127,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);

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

@@ -2459,10 +2459,8 @@
     <!--<script type="text/javascript" src="/test/tmp_data/test_ration_calc/ration_calc_base.js"></script>-->
     <script src="/lib/pinyinjs/pinyin_dict_firstletter.js"></script>
     <script src="/lib/pinyinjs/pinyinUtil.js"></script>
-    <script src="/public/common_constants.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/models/main_consts.js"></script>
     <script type="text/javascript" src="/web/over_write/config/compilation_config.js"></script>
-    <script type="text/javascript" src="/public/web/common_util.js"></script>
     <script type="text/javascript" src="/public/web/encoding_util.js"></script>
     <script type="text/javascript" src="/web/building_saas/glj/js/project_glj.js"></script>
     <script type="text/javascript" src="/web/building_saas/glj/js/composition.js"></script>

+ 0 - 1
web/building_saas/pm/html/project-management.html

@@ -947,7 +947,6 @@
 <script src="/web/building_saas/glj/js/socket.io.slim.js"></script>
 <script src="/public/web/socket/connection.js"></script>
 <script src="/public/billsUtil.js"></script>
-<script src="/public/common_constants.js"></script>
 <script src="/web/building_saas/main/js/models/importStdInterfaceBase.js"></script>
 <!-- <script src="/web/building_saas/main/js/models/importStandardInterface.js"></script> -->
 <script src="/web/common/components/share/index.js" ></script>

+ 2 - 0
web/common/html/header.html

@@ -329,5 +329,7 @@
 <script type="text/javascript" src="/lib/lodash/lodash.js"></script>
 <script type="text/javascript" src="/public/web/commonAlert.js"></script>
 <script type="text/javascript" src="/public/web/headerOpr.js"></script>
+<script type="text/javascript" src="/public/common_util.js"></script>
+<script src="/public/common_constants.js"></script>
 <script type="text/javascript" src="/lib/jquery-editable-select/jquery.editable-select.min.js"></script>
 <!-- endinject -->