Browse Source

load billsLib & rationLib from engineering of tender

MaiXinRong 8 years ago
parent
commit
c9991608f9

+ 21 - 0
modules/common/helper/mongoose_helper.js

@@ -5,6 +5,8 @@
  * @date 2017/5/22.
  */
 
+import mongoose from "mongoose";
+
 class MongooseHelper {
 
     /**
@@ -31,6 +33,7 @@ class MongooseHelper {
     findOne(conditions, fields = null) {
         let self = this;
         return new Promise(function (resolve, reject) {
+            conditions = self._convertId(conditions);
             self.model.findOne(conditions, fields, function (error, data) {
                 if (error) {
                     reject(null);
@@ -177,6 +180,7 @@ class MongooseHelper {
     update(condition, updateData) {
         let self = this;
         return new Promise(function(resolve, reject) {
+            condition = self._convertId(condition);
             self.model.update(condition, {$set: updateData}, function(error, data) {
                 if (error) {
                     reject(error);
@@ -187,6 +191,23 @@ class MongooseHelper {
         });
     }
 
+    /**
+     * id转换为objectId
+     *
+     * @param {object} condition
+     * @return {object}
+     */
+    _convertId(condition) {
+        // 对于ID的处理
+        if (condition === null || condition._id === undefined) {
+            return condition;
+        }
+        let result = mongoose.Types.ObjectId(condition._id);
+        condition._id = result;
+
+        return condition;
+    }
+
 }
 
 export default MongooseHelper;

+ 7 - 2
modules/pm/controllers/pm_controller.js

@@ -73,9 +73,14 @@ module.exports = {
     },
     getProject: function(req, res){
         let data = JSON.parse(req.body.data);
-        ProjectsData.getUserProject(req.session.sessionUser.ssoId, data.proj_id, function(err, message, data){
+        ProjectsData.getUserProject(req.session.sessionUser.ssoId, data.proj_id, async function(err, message, data){
             if (err === 0) {
-                callback(req, res, err, message, data);
+                let engineeringLibModel = new EngineeringLibModel();
+                let engineeringInfo = await engineeringLibModel.getEngineering(data.property.engineering_id);
+                let strData = JSON.stringify(data);
+                let projInfo = JSON.parse(strData);
+                projInfo.engineeringInfo = engineeringInfo;
+                callback(req, res, err, message, projInfo);
             } else {
                 callback(req, res, err, message, null);
             }

+ 8 - 1
modules/users/models/engineering_lib_model.js

@@ -90,7 +90,14 @@ class EngineeringLibModel extends BaseModel {
             }
         }
         return valuationData;
-    }
+    };
+
+    async getEngineering(engineering_id) {
+        let condition = {_id: engineering_id};
+        let engineering = await this.findDataByCondition(condition);
+
+        return engineering;
+    };
 
 }
 

+ 10 - 10
web/building_saas/main/js/views/std_bills_lib.js

@@ -34,17 +34,17 @@ var billsLibObj = {
         }
     },
     loadStdBillsLib: function () {
-        CommonAjax.post('/stdBillsEditor/getStdBillsLib', {userId: userID}, function (datas) {
-            var i, select = $('#stdBillsLibSelect');
-            select.empty();
-            datas.forEach(function (data) {
-                var option = $('<option>').val(data.billsLibId).text(data.billsLibName);
-                select.append(option);
-            });
-            if (select.children.length !== 0) {
-                billsLibObj.loadStdBills(select.val());
-            }
+        let i, select = $('#stdBillsLibSelect');
+        select.empty();
+
+        let bills_lib = projectInfoObj.projectInfo.engineeringInfo.bill_lib;
+        bills_lib.forEach(function (data) {
+            var option = $('<option>').val(data.id).text(data.name);
+            select.append(option);
         });
+        if (select.children.length !== 0) {
+            billsLibObj.loadStdBills(select.val());
+        }
     },
     loadStdBills: function (stdBillsLibID) {
         var that = this;

+ 9 - 11
web/building_saas/main/js/views/std_ration_lib.js

@@ -27,18 +27,16 @@ var rationLibObj = {
         }
     },
     loadStdRationLibs: function () {
-        CommonAjax.postRationLib('/rationRepository/api/getRationDisplayNames', {user_id: userID}, function (datas) {
-            var select = $('#stdRationLibSelect');
-            select.empty();
-            datas.forEach(function (data) {
-                select.append($('<option>').val(data.ID).text(data.dispName));
-            });
-            if (select[0].options.length !== 0) {
-                rationLibObj.loadStdRation(select.val());
-            }
-        }, function () {
-            $('#stdRationLibSelect').empty();
+        let select = $('#stdRationLibSelect');
+        select.empty();
+
+        let ration_lib = projectInfoObj.projectInfo.engineeringInfo.ration_lib;
+        ration_lib.forEach(function (data) {
+            select.append($('<option>').val(data.id).text(data.name));
         });
+        if (select[0].options.length !== 0) {
+            rationLibObj.loadStdRation(select.val());
+        }
     },
     loadStdRation: function (rationLibID) {
         var that = this;

+ 17 - 0
web/building_saas/pm/js/pm_main.js

@@ -673,6 +673,22 @@ function AddTender() {
     let valuationName = $("#tender-valuation").children("option:selected").text();
     let valuationType = $("input[name='tender_valuation_type']:checked").val();
     let engineering = $("#tender-engineering").val();
+
+    let engineering_id = undefined;
+    let valuationData = valuationType === 'bill' ? JSON.parse(billValuation) : JSON.parse(rationValuation);
+    let engineeringList = [];
+    for(let tmp of valuationData) {
+        if (tmp._id === valuation) {
+            engineeringList = tmp.engineering_list;
+            break;
+        }
+    }
+    for(let tmp of engineeringList) {
+        if (tmp.engineering == engineering) {
+            engineering_id = tmp.engineering_id;
+            break;
+        }
+    }
     let engineeringName = $('#tender-engineering').children("option:selected").text();
 
     let callback = function() {
@@ -687,6 +703,7 @@ function AddTender() {
         valuationType: valuationType,
         valuationName: valuationName,
         engineering: engineering,
+        engineering_id: engineering_id,
         engineeringName: engineeringName
     };
     // 如果选择的是单项工程则新增同级数据