Browse Source

getGLJPaging

zhongzewei 6 năm trước cách đây
mục cha
commit
a96ee394dd

+ 33 - 1
modules/complementary_glj_lib/models/gljModel.js

@@ -9,6 +9,11 @@ const compleClassModel = mongoose.model('complementary_glj_section');
 import counter from "../../../public/counter/counter";
 import async from "async";
 import STDGLJLibGLJListModel from "../../common/std/std_glj_lib_glj_list_model";
+const gljType = {
+    stdGLJ: 1,
+    complementaryGLJs: 2
+};
+const limitCount = 50;
 
 class GljDao {
     getGljTypes (gljLibId, callback){
@@ -41,8 +46,35 @@ class GljDao {
         }
     }
 
-    async getGLJPaging ({type, replace, index, search, withinClass}) {
+    getQueryByType ({userID, compilationId, gljLibId, type, classList, search}) {
+        let rst = {
+            model: null,
+            query: {}
+        };
+        if (type === gljType.stdGLJ) {
+            rst.model = stdGljModel;
+            rst.query.repositoryId = gljLibId;
+        } else {
+            rst.model = complementaryGljModel;
+            rst.query.userId = userID;
+            rst.query.compilationId = compilationId;
+        }
+        if (classList.length) {
+            rst.query.gljClass = {$in: classList};
+        }
+        if (search) {
+            rst.query.$or = [{code: {'$regex': search, $options: '$i'}}, {name: {'$regex': search, $options: '$i'}}];
+        }
+        return rst;
+    }
 
+    async getGLJPaging (data) {
+        let queryData = this.getQueryByType(data);
+        let gljs = await queryData.model.find(queryData.query).lean().sort({code: 1}).skip(data.index).limit(limitCount),
+            total = await queryData.model.find(queryData.query).count();
+        return data.type === gljType.stdGLJ
+            ? {stdGljs: gljs, complementaryGljs: [], total: total}
+            : {stdGljs: [], complementaryGljs: gljs, total: total}
     }
 
     //获得用户的补充工料机和用户当前所在编办的标准工料机

+ 14 - 3
modules/ration_glj/controllers/ration_glj_controller.js

@@ -58,16 +58,27 @@ async function getGLJDataByCodes(req,res){
 }
 
 async function getGLJDataPaging(req, res) {
+    let result={
+        error:0
+    };
     let data = JSON.parse(req.body.data);
     try {
-        let gljLibId = await getGLJLibByEngineerID(data.engineerID);
+        let gljLibId = await ration_glj_facade.getGLJLibByEngineerID(data.engineerID);
         let info = {
             gljLibId,
             userID: req.session.sessionUser.id,
             compilationId: req.session.sessionCompilation._id
         };
-    } catch (e) {
-
+        result.datas = await ration_glj_facade.getGLJDataPaging(info, data.condition);
+        if (req.session.sessionCompilation.priceProperties) {
+            result.datas.priceProperties = req.session.sessionCompilation.priceProperties
+        }
+        res.json(result);
+    } catch (err) {
+        logger.err(err);
+        result.error=1;
+        result.message = err.message;
+        res.json(result);
     }
 }
 

+ 6 - 2
modules/ration_glj/facade/ration_glj_facade.js

@@ -8,6 +8,7 @@ module.exports = {
     getQuantityByProjectGLJ: getQuantityByProjectGLJ,
     getLibInfo: getLibInfo,
     getGLJData: getGLJData,
+    getGLJDataPaging: getGLJDataPaging,
     getGLJDataByCodes:getGLJDataByCodes,
     addGLJ: addGLJ,
     deleteGLJ:deleteGLJ,
@@ -540,14 +541,17 @@ async function getGLJLibByEngineerID  (engineerID) {
     return gljLibId
 }
 
-async function getGLJDataPaging(info, data) {
+async function getGLJDataPaging(info, condition) {
     let gljDao = new GljDao();
     let rst = {};
     // 初始化,需要生成分类树和类型数据
-    if (data.init) {
+    if (condition.init) {
         rst.treeData = await gljDao.getMixedTree(info.gljLibId, info.userID, info.compilationId);
         rst.distTypeTree = stdgljutil.getStdGljTypeCacheObj().toArray();
     }
+    let gljData = await gljDao.getGLJPaging({...info, ...condition});
+    Object.assign(rst, gljData);
+    return rst;
 }
 
 function getGLJData(info, callback) {

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

@@ -9,7 +9,7 @@ module.exports = function (app) {
 
     var rgRouter = express.Router();
     rgRouter.get('/getGLJData/:engineerID', rgController.getGLJData);
-    rgRouter.get('/getGLJDataPaging/:engineerID', rgController.getGLJDataPaging);
+    rgRouter.post('/getGLJDataPaging', rgController.getGLJDataPaging);
     rgRouter.post('/getGLJDataByCodes',rgController.getGLJDataByCodes);
     rgRouter.post('/addGLJ',rgController.addGLJ);
     rgRouter.post('/replaceGLJ',rgController.replaceGLJ);

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

@@ -497,10 +497,10 @@ let ration_glj = {
             }
            return node
         };
-        ration_glj.prototype.getGLJDataPaging = function (postData, cb) {
+        ration_glj.prototype.getGLJDataPaging = function (condition, cb) {
             let property = projectObj.project.projectInfo.property;
             let engineerID = property.engineering_id;
-            CommonAjax.post(`/rationGlj/getGLJDataPaging/${engineerID}`, postData, function (data) {
+            CommonAjax.post('/rationGlj/getGLJDataPaging', {engineerID, condition}, function (data) {
                 if(data.datas.priceProperties && data.datas.priceProperties.length > 0){
                     let tem = _.find(data.datas.priceProperties,{region:property.region,taxModel:parseInt(property.taxType)});
                     if(tem){

+ 14 - 10
web/building_saas/main/js/views/glj_view.js

@@ -993,11 +993,11 @@ var gljOprObj = {
             // 初始化
             init: true,
             // 所在部分(标准、补充)
-            type: type.std,
-            // 替换数据
-            replace: {},
+            type: type.stdGLJ,
+            // 替换数据,替换操作下有数据:编码、名称、规格、单位、类型
+            replace: null,
             // 所在分类节点
-            withinClass: [],
+            classList: [],
             // 搜索文本
             search: ''
         };
@@ -1006,13 +1006,17 @@ var gljOprObj = {
         }
         condition.init = false;
         // 标准、补充的选择
-        let radioType = $("input[name='glj']:checked").val();
-        condition.type = type[radioType];
+        if ($('#glj_tree_div').is(':visible')) {
+            let radioType = $("input[name='glj']:checked").val();
+            condition.type = type[radioType];
+        }
         // 选中的分类
-        let selNode = this.treeObj.getNodeByParam('ID', this.gljCurTypeId);
-        // 不为最顶层节点时,才赋值给withinClass
-        if (!selNode || selNode.ParentID !== -1) {
-            condition.withinClass = this.parentNodeIds['_pNodeId_' + this.gljCurTypeId];
+        if (this.treeObj) {
+            let selNode = this.treeObj.getNodeByParam('ID', this.gljCurTypeId);
+            // 不为最顶层节点时,才赋值给withinClass
+            if (!selNode || selNode.ParentID !== -1) {
+                condition.classList = this.parentNodeIds['_pNodeId_' + this.gljCurTypeId];
+            }
         }
         // 搜索文本
         let searchStr = $('#gljSearchKeyword').val().trim();

+ 4 - 0
web/building_saas/main/js/views/glj_view_contextMenu.js

@@ -376,6 +376,10 @@ var gljContextMenu = {
 function getGLJData(actionType) {
     $('#actionType').val(actionType);
     $.bootstrapLoading.start();
+    /*let condition = gljOprObj.getPagingCondition(false, 0);
+    projectObj.project.ration_glj.getGLJDataPaging(condition, function (result) {
+        gljOprObj.treeData =  result.datas.treeData;
+    });*/
     projectObj.project.ration_glj.getGLJData(function (result) {
         console.log(+new Date());
         gljOprObj.treeData =  result.datas.treeData;