Browse Source

Merge branch 'master' into olym

olym 7 years ago
parent
commit
2715900e3c

+ 9 - 8
modules/pm/controllers/pm_controller.js

@@ -40,7 +40,7 @@ module.exports = {
         });
     },
     getProjects: function(req, res){
-        ProjectsData.getUserProjects(req.session.sessionUser.ssoId, function(err, message, projects){
+        ProjectsData.getUserProjects(req.session.sessionUser.ssoId, req.session.sessionCompilation._id, function(err, message, projects){
             if (projects) {
                 callback(req, res, err, message, projects);
             } else {
@@ -50,7 +50,7 @@ module.exports = {
     },
     updateProjects: async function (req, res) {
         let data = JSON.parse(req.body.data);
-        await ProjectsData.updateUserProjects(req.session.sessionUser.ssoId, data.updateData, function (err, message, data) {
+        await ProjectsData.updateUserProjects(req.session.sessionUser.ssoId, req.session.sessionCompilation._id, data.updateData, function (err, message, data) {
             if (err === 0) {
                 callback(req, res, err, message, data);
             } else {
@@ -77,7 +77,7 @@ module.exports = {
     },
     rename: function (req, res) {
         let data = JSON.parse(req.body.data);
-        ProjectsData.rename(req.session.sessionUser.ssoId, data, function (err, message) {
+        ProjectsData.rename(req.session.sessionUser.ssoId, req.session.sessionCompilation._id, data, function (err, message) {
             callback(req, res, err, message, null);
         });
     },
@@ -135,7 +135,7 @@ module.exports = {
         let renderData = {
             userAccount: request.session.userAccount,
             userID: request.session.sessionUser.ssoId,
-            compilationData: sessionCompilation,
+            compilationData: JSON.stringify(sessionCompilation),
             billValuation: JSON.stringify(billValuation),
             rationValuation: JSON.stringify(rationValuation),
             engineeringList: JSON.stringify(engineering.List)
@@ -202,6 +202,7 @@ module.exports = {
 
     getGCDatas: async function(request, response) {
         let userID = request.session.sessionUser.ssoId;
+        let compilatoinId = req.session.sessionCompilation._id;
         let rst = [];
         let _projs = Object.create(null), _engs = Object.create(null), prefix = 'ID_';
         try{
@@ -212,7 +213,7 @@ module.exports = {
                 let gc_uf = gc_unitPriceFiles[i];
                 let theProj = _projs[prefix + gc_uf.root_project_id] || null;
                 if(!theProj){
-                    let tempProj = await ProjectsData.getProjectsByIds([gc_uf.root_project_id]);
+                    let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_uf.root_project_id]);
                     if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
                         theProj = _projs[prefix + gc_uf.root_project_id] = tempProj[0]._doc;
                         buildProj(theProj);
@@ -226,7 +227,7 @@ module.exports = {
                 let gc_ff = gc_feeRateFiles[i];
                 let theProj = _projs[prefix + gc_ff.rootProjectID] || null;
                 if(!theProj){
-                    let tempProj = await ProjectsData.getProjectsByIds([gc_ff.rootProjectID]);
+                    let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_ff.rootProjectID]);
                     if(tempProj.length > 0 && tempProj[0].projType !== projType.folder){
                         theProj = _projs[prefix + gc_ff.rootProjectID] = tempProj[0]._doc;
                         buildProj(theProj);
@@ -241,7 +242,7 @@ module.exports = {
                     let gc_t = gc_tenderFiles[i];
                     let theEng = _engs[prefix + gc_t.ParentID] || null;
                     if(!theEng){
-                        let tempEngs = await ProjectsData.getProjectsByIds([gc_t.ParentID]);
+                        let tempEngs = await ProjectsData.getProjectsByIds(userID, compilatoinId, [gc_t.ParentID]);
                         if(tempEngs.length > 0 && tempEngs[0].projType === projType.engineering){
                             theEng = _engs[prefix + gc_t.ParentID] = tempEngs[0]._doc;
                             theEng.children = [];
@@ -251,7 +252,7 @@ module.exports = {
                         theEng.children.push(gc_t);
                         let theProj = _projs[prefix + theEng.ParentID] || null;
                         if(!theProj){
-                            let tempProj = await ProjectsData.getProjectsByIds([theEng.ParentID]);
+                            let tempProj = await ProjectsData.getProjectsByIds(userID, compilatoinId, [theEng.ParentID]);
                             if(tempProj.length > 0 && tempProj[0].projType === projType.project){
                                 theProj = _projs[prefix + theEng.ParentID] = tempProj[0]._doc;
                                 buildProj(theProj);

+ 11 - 11
modules/pm/models/project_model.js

@@ -30,8 +30,8 @@ let fileType = {
 
 let ProjectsDAO = function(){};
 
-ProjectsDAO.prototype.getUserProjects = function(userId, callback){
-    Projects.find({'$or': [{'userID': userId, 'deleteInfo': null}, {'userID': userId, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id', function(err, templates){
+ProjectsDAO.prototype.getUserProjects = function(userId, compilation, callback){
+    Projects.find({'$or': [{'userID': userId, 'compilation': compilation, 'deleteInfo': null}, {'userID': userId, 'compilation': compilation, 'deleteInfo.deleted': {'$in': [null, false]}}]}, '-_id', function(err, templates){
         if (err) {
             callback(1, 'Error', null);
         } else {
@@ -50,7 +50,7 @@ ProjectsDAO.prototype.getUserProject = function (userId, ProjId, callback) {
     });
 }
 
-ProjectsDAO.prototype.updateUserProjects = async function(userId, datas, callback){
+ProjectsDAO.prototype.updateUserProjects = async function(userId, compilationId, datas, callback){
     let data, project, updateLength = 0, hasError = false, deleteInfo = null, i, newProject;
     let updateAll = function (err) {
             if (!err){
@@ -74,6 +74,7 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, datas, callbac
                 Projects.update({userID: userId, ID: data.updateData.ID}, data.updateData, updateAll);
             } else if (data.updateType === 'new') {
                 data.updateData['userID'] = userId;
+                data.updateData['compilation'] = compilationId;
                 data.updateData['createDateTime'] = new Date();
                 // 如果没有选中单价文件则新增单价文件
                 if (data.updateData.projType === projectType.tender && data.updateData.property !== null &&
@@ -112,7 +113,7 @@ ProjectsDAO.prototype.updateUserProjects = async function(userId, datas, callbac
                 }
                 newProject = new Projects(data.updateData);
                 // 查找同级是否存在同名数据
-                let exist = await this.isExist(data.updateData.name, data.updateData.ParentID);
+                let exist = await this.isExist(userId, compilationId, data.updateData.name, data.updateData.ParentID);
                 if (exist) {
                     callback(1, '同级目录已存在相同名称数据.', null);
                     return;
@@ -270,7 +271,7 @@ ProjectsDAO.prototype.copyUserProjects = function (userId, datas, callback) {
     }
 };
 
-ProjectsDAO.prototype.rename = async function (userId, data, callback){
+ProjectsDAO.prototype.rename = async function (userId, compilationId, data, callback){
     try {
         if (data.id === undefined || data.id === '') {
             throw '数据错误!';
@@ -280,7 +281,7 @@ ProjectsDAO.prototype.rename = async function (userId, data, callback){
         }
         data.newName = data.newName.trim();
         // 查找同级是否存在同名数据
-        let exist = await this.isExist(data.newName, data.parentID);
+        let exist = await this.isExist(userId, compilationId, data.newName, data.parentID);
         if (exist) {
             throw '同级目录已存在相同名称数据';
         }
@@ -333,8 +334,8 @@ ProjectsDAO.prototype.getProject = function (key, callback) {
     }
 };
 
-ProjectsDAO.prototype.getProjectsByIds = async function (ids){
-    return await Projects.find({ID: {$in: ids}});
+ProjectsDAO.prototype.getProjectsByIds = async function (userId, compilationId, ids){
+    return await Projects.find({userID: userId, compilation: compilationId, ID: {$in: ids}});
 };
 
 ProjectsDAO.prototype.getGCFiles = async function (fileType, userID){
@@ -470,12 +471,12 @@ ProjectsDAO.prototype.recGC = async function(userID, datas, callback){
  * @param {Object} data
  * @return {Boolean}
  */
-ProjectsDAO.prototype.isExist = async function(name, parentID) {
+ProjectsDAO.prototype.isExist = async function(userId, compilationId, name, parentID) {
     parentID = parseInt(parentID);
     if (name === '' || isNaN(parentID)) {
         return true;
     }
-    let condition = {ParentID: parentID, name: name, "$or":[{deleteInfo: null}, {"deleteInfo.deleted": false}]};
+    let condition = {userID: userId, compilation: compilationId, ParentID: parentID, name: name, "$or":[{deleteInfo: null}, {"deleteInfo.deleted": false}]};
     let count = await Projects.count(condition);
     return count > 0;
 };
@@ -583,7 +584,6 @@ ProjectsDAO.prototype.changeUnitPriceFileInfo = async function(projectId, change
     return result.ok === 1;
 };
 
-
 module.exports ={
     project: new ProjectsDAO(),
     projType: projectType,

+ 1 - 0
modules/pm/models/project_schema.js

@@ -16,6 +16,7 @@ let ProjectSchema = new Schema({
     "projType": String,
     "recentDateTime": Date,
     "createDateTime": Date,
+    "compilation": String,
     "deleteInfo": deleteSchema,
     'fullFolder': Array,
     "property": {

+ 2 - 2
public/web/rpt_value_define.js

@@ -213,8 +213,8 @@ const JV = {
     LAYOUT_FULFILL: 4,
 
     OUTPUT_ALIGN: {
-        H: ["Left", "Center", "Right"],
-        V: ["Top", "Center", "Bottom"]
+        H: ["left", "center", "right"],
+        V: ["top", "center", "bottom"]
     },
 
     CAL_TYPE:["percentage","abstract"],

+ 12 - 1
web/building_saas/glj/js/project_glj.js

@@ -229,6 +229,7 @@ function init() {
             // 赋值
             jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
             jsonData= filterProjectGLJ(jsonData);
+            jsonData = sortProjectGLJ(jsonData);
             mixRatioConnectData = data.mixRatioConnectData !== undefined ? data.mixRatioConnectData : mixRatioConnectData;
             mixRatioMap = data.mixRatioMap !== undefined ? data.mixRatioMap : mixRatioMap;
             host = data.constData.hostname !== undefined ? data.constData.hostname : '';
@@ -341,7 +342,9 @@ function successTrigger(field, info) {
             break;
     }
     // 重新加载数据到缓存
-    projectObj.project.projectGLJ.loadData();
+    projectObj.project.projectGLJ.loadData(function () {
+        projectObj.project.projectGLJ.loadCacheData();
+    });
 
     // 更新定额工料机
     gljOprObj.refreshView();
@@ -387,3 +390,11 @@ function filterProjectGLJ(jsonData) {
     return jsonData;
 }
 
+function sortProjectGLJ(jsonData) {
+    if (jsonData.length > 0){
+        jsonData = _.sortByAll(jsonData,[function (item) {
+            return item.unit_price.type+"";
+        },'code']);
+    }
+    return jsonData
+}

+ 3 - 2
web/building_saas/glj/js/project_glj_spread.js

@@ -356,10 +356,11 @@ ProjectGLJSpread.prototype.compositionCalculate = function(row) {
                 continue;
             }
             let rowConsumption = consumption[index] === undefined ? 0 : consumption[index];
+            let decimal = getDecimal("glj.unitPrice");
             // 计算价格
-            let rowMarketPrice = (marketPrice * rowConsumption).toDecimal(2);
+            let rowMarketPrice = (marketPrice * rowConsumption).toDecimal(decimal);
             parentMarketPrice[active] = parentMarketPrice[active] === undefined ?
-                rowMarketPrice : (parentMarketPrice[active] + rowMarketPrice).toDecimal(2);
+                rowMarketPrice : (parentMarketPrice[active] + rowMarketPrice).toDecimal(decimal);
 
         }
 

+ 1 - 1
web/building_saas/main/js/models/main_consts.js

@@ -34,7 +34,7 @@ const gljType = {
     COMMERCIAL_MORTAR: 206,
     // ==============材料类型=================
     // ==============机械类型=================
-    // 普通机械
+    // 机械台班
     GENERAL_MACHINE: 301,
     // 机械组成物
     MACHINE_COMPOSITION: 302,

+ 16 - 0
web/building_saas/main/js/models/project_glj.js

@@ -140,6 +140,7 @@ ProjectGLJ.prototype.loadCacheData = function() {
     }
     jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
     jsonData=filterProjectGLJ(jsonData);
+    jsonData = sortProjectGLJ(jsonData);
     projectGLJSheet.setData(jsonData);
     projectGLJSpread.specialColumn(jsonData);
 };
@@ -170,6 +171,8 @@ ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
             me.refreshProjectGLJPrice(data);
             me.refreshRationGLJPrice(glj);
             gljOprObj.showRationGLJSheetData();
+            me.refreshTreeNodePriceIfNeed(glj);
+            
             $.bootstrapLoading.end();
         }
         $.bootstrapLoading.start();
@@ -180,6 +183,18 @@ ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
         gljOprObj.showRationGLJSheetData();
     }
 }
+ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
+    if((data.unit_price.type = gljType.MAIN_MATERIAL||data.type==gljType.EQUIPMENT)&&projectInfoObj.projectInfo.property.displaySetting.disPlayMainMateria==true){
+        var nodes = _.filter(projectObj.project.mainTree.items,function (tem) {
+            if(tem.sourceType==ModuleNames.ration_glj&&tem.data.projectGLJID ==data.id){
+                tem.data.marketUnitFee = data.unit_price.market_price;
+                return true;
+            }
+        })
+        projectObj.mainController.refreshTreeNode(nodes);
+
+    }
+}
 
 ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
     for(let ration_glj of gljOprObj.sheetData){
@@ -209,6 +224,7 @@ ProjectGLJ.prototype.refreshProjectGLJPrice=function(data){
                 glj.unit_price.market_price = d.market_price;
                 this.setAdjustPrice(glj);
                 this.refreshRationGLJPrice(glj);
+                this.refreshTreeNodePriceIfNeed(glj);
             }
         }
     }

+ 16 - 5
web/building_saas/main/js/models/ration_glj.js

@@ -286,20 +286,19 @@ var ration_glj = {
             var callback=function (data) {
                 let initShow = false;//是否需要表格初始化显示
                 if(updateField=='customQuantity'){
-                    console.log(data);
                     me.refreshAfterQuantityUpdate(data,node);
                 }else {
                     var doc = data.doc;
                     for(var key in doc){
                         recode[key] = doc[key];
                     }
-                    console.log(data);
                     if(data.hasOwnProperty('adjustState')){//更新定额调整状态
                         me.updateRationAdjustState(data.adjustState,recode.rationID,node);
                     }
                     if(recode.subList&&recode.subList.length>0){
                         initShow = true;
                     }
+                    node?"":me.refreshTreeNodeIfNeeded(recode);//如果不是在造价书页面直接编辑,则不用刷新
                 }
                 if(initShow==false){//不需要初始化,只需耍新当前显示就可以了
                     gljOprObj.showRationGLJSheetData();
@@ -343,7 +342,7 @@ var ration_glj = {
             })
             if(node){
                 node.data.adjustState=adjustState;
-                nodes.push(node)
+                nodes.push(node);
             }
             if(rnode){
                 nodes.push(rnode);
@@ -382,7 +381,7 @@ var ration_glj = {
               }
               if(glj.hasOwnProperty("compilationId")){
                   ration_glj.from="cpt";
-                  if(glj.code.indexOf('-')!=-1){//这条工料机是用户通过修改称、规格、型号等保存到补充工料机库的
+                  if(glj.code.indexOf('-')!=-1){//这条工料机是用户通过修改称、规格、型号等保存到补充工料机库的
                       ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
                   }
               }
@@ -493,7 +492,13 @@ var ration_glj = {
                 return;
             }
             if(fieldName=="marketUnitFee"){
-
+                var decimal =getDecimal("glj.unitPrice");
+                var newval = number_util.checkNumberValue(value,decimal);
+                if(newval){
+                    fieldName="marketPrice";
+                    projectObj.project.projectGLJ.updatePriceFromRG(node.data,fieldName,newval);
+                    return;
+                }
             }else {
                 if(value!==undefined&&value!==null){
                     if(fieldName=="subType"){
@@ -507,6 +512,12 @@ var ration_glj = {
            // node.data.subType = value;
             projectObj.mainController.refreshTreeNode([node]);
         };
+        ration_glj.prototype.refreshTreeNodeIfNeeded=function (data) {
+            if((data.type == gljType.MAIN_MATERIAL||data.type==gljType.EQUIPMENT)&&projectInfoObj.projectInfo.property.displaySetting.disPlayMainMateria==true){
+                this.transferToNodeData(data);
+                gljOprObj.refreshTreeNode({"type":ModuleNames.ration_glj,"ID":data.ID});
+            }
+        }
         return new ration_glj(project);
     }
 };

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

@@ -559,7 +559,7 @@ var gljOprObj = {
         this.sheet.setRowCount(0);
         //console.log(+new Date())
         //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
-        this.sheetData=_.sortBy(this.sheetData,'type');
+        this.sheetData=sortRationGLJ(this.sheetData);
         this.sumQuantity();//计算总消耗量
         this.addMixRatioToShow();//显示组成物信息
         this.initRationTree(init);
@@ -751,7 +751,7 @@ var gljOprObj = {
         var newval;
         if(updateField=='marketPrice'||updateField=='customQuantity'||updateField=='basePrice'){
             if(args.editingText==null){
-                newval="";
+                updateField=='marketPrice'||updateField=='customQuantity'?newval=0:newval="";
             }else {
                 var decimal = updateField=='customQuantity'?getDecimal("glj.quantity"):getDecimal("glj.unitPrice");
                 newval = number_util.checkNumberValue(args.editingText,decimal);
@@ -954,7 +954,7 @@ var gljOprObj = {
                     selected.data.adjustState=result.adjustState;
                     //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
                     project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
-                    gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData)
+                    gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
                     gljOprObj.showRationGLJSheetData();
                     project.projectGLJ.loadData();
                     projectObj.mainController.refreshTreeNode([selected]);
@@ -1053,7 +1053,6 @@ var gljOprObj = {
             nodes.push(node);
         }
     }
-
     projectObj.mainController.refreshTreeNode(nodes);
 
     },
@@ -1162,7 +1161,11 @@ var gljOprObj = {
             }
         };
         return new TreeNodeCellType()
+    },
+    marketPriceReadOnly:function(node){
+        return node.data.type==gljType.CONCRETE||node.data.type==gljType.MORTAR||node.data.type==gljType.MIX_RATIO||node.data.type==gljType.GENERAL_MACHINE||node.data.isEstimate==1
     }
+
 }
 
 $(function(){
@@ -1295,4 +1298,11 @@ function getFormatter(decimal) {
         pre += "0"
     }
     return pre;
+}
+
+function sortRationGLJ(list) {
+    list= _.sortByAll(list,[function (item) {
+        return item.type+"";
+    },"code"])
+    return list;
 }

+ 3 - 0
web/building_saas/main/js/views/main_tree_col.js

@@ -116,6 +116,9 @@ let MainTreeCol = {
         },
         forQuantity:function (node) {
             return MainTreeCol.readOnly.glj(node)||MainTreeCol.readOnly.billsParent(node)
+        },
+        forMarketPrice:function (node) {
+            return MainTreeCol.readOnly.bills(node)||(MainTreeCol.readOnly.ration(node)&&node.data.type == rationType.ration)||gljOprObj.marketPriceReadOnly(node);
         }
     },
     cellType: {

+ 18 - 2
web/building_saas/main/js/views/project_property_bills_quantity_decimal.js

@@ -248,7 +248,7 @@ let billsDecimalView = {
     },
 
     isValidDecimal: function (v) {
-        return this.isData(v) && !isNaN(v) && parseInt(v) % 1 === 0 && parseInt(v) >= this.default.min && parseInt(v) <= this.default.max;
+        return this.isData(v) && !isNaN(v) && parseInt(v) == v && parseInt(v) >= this.default.min && parseInt(v) <= this.default.max;
     },
 
     hasUnit: function (all, v) {
@@ -260,6 +260,21 @@ let billsDecimalView = {
         return false;
     },
 
+    copyObj: function(obj){
+        let newObj = {};
+        for(let attr in obj){
+            newObj[attr] = obj[attr];
+        }
+        return newObj;
+    },
+
+    initDatas: function (datas) {
+        this.cache = [];
+        for(let i = 0, len = datas.length; i < len; i++){
+            this.cache.push(this.copyObj(datas[i]));
+        }
+    },
+
     rowHasData: function (sheet, row) {
         let v = sheet.getValue(row, 0);
         if(v && v.toString().trim().length > 0) {
@@ -317,7 +332,8 @@ $(document).ready(function () {
     $('#poj-set').on('shown.bs.modal', function (e) {
         //init Spread
         if(billsDecimalView.isDef(billsQuanDecimal.datas)){
-            billsDecimalView.cache = billsDecimalView.cache.concat(billsQuanDecimal.datas);
+            //billsDecimalView.cache = billsDecimalView.cache.concat(billsQuanDecimal.datas);
+            billsDecimalView.initDatas(billsQuanDecimal.datas);
         }
         if(billsDecimalView.cache.length === 0){
             billsDecimalView.cache.push(billsDecimalView.angleDecimal);

+ 1 - 0
web/building_saas/main/js/views/std_bills_lib.js

@@ -156,6 +156,7 @@ var billsLibObj = {
             showBillsRela(stdBillsTree.firstNode());
 
             stdBillsTreeController.bind(TREE_SHEET_CONTROLLER.eventName.treeSelectedChanged, showBillsRela);
+            that.stdBillsSpread.unbind(GC.Spread.Sheets.Events.CellDoubleClick);
             that.stdBillsSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, function (sender, args) {
                 let selectNode = stdBillsTree.items[args.row];
                 if (stdBillsTree.items[args.row].children.length === 0) {

+ 3 - 2
web/building_saas/pm/html/project-management.html

@@ -233,7 +233,7 @@
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
-                <h5 class="modal-title">新建 <i class="fa fa-cubes"></i> 建设项目</h5>
+                <h5 class="modal-title"><i class="fa fa-cubes"></i> 新建建设项目</h5>
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                 </button>
@@ -284,7 +284,7 @@
     <div class="modal-dialog" role="document">
         <div class="modal-content">
             <div class="modal-header">
-                <h5 class="modal-title">新建 <i class="fa fa-sticky-note-o"></i> 单位工程</h5>
+                <h5 class="modal-title"><i class="fa fa-sticky-note-o"></i>新建单位工程</h5>
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                     <span aria-hidden="true">&times;</span>
                 </button>
@@ -522,5 +522,6 @@
     let billValuation = '<%- billValuation %>';
     let rationValuation = '<%- rationValuation %>';
     let engineeringList = '<%- engineeringList %>';
+    let compilationData = JSON.parse('<%- compilationData %>');
 </script>
 </html>

+ 1 - 1
web/building_saas/pm/js/pm_ajax.js

@@ -6,7 +6,7 @@ var GetAllProjectData = function (callback) {
     $.ajax({
         type:"POST",
         url: '/pm/api/getProjects',
-        data: {'data': JSON.stringify({"user_id": userID})},
+        data: {'data': JSON.stringify({"user_id": userID, "compilation": compilationData._id})},
         dataType: 'json',
         cache: false,
         timeout: 50000,

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

@@ -13,7 +13,6 @@ let feeRateData = [];
 let isSaving = false;
 let projectProperty = [];
 let fileDelObj = null;
-let selectedInfo = {project: null, engineering: null};//新建单位工程,建设项目和单项工程下拉选择
 let projectType = {
     folder: 'Folder',
     tender: 'Tender',
@@ -358,10 +357,16 @@ $(document).ready(function() {
 
     // 新增单位工程弹层改变
     $('#add-tender-dialog').on('show.bs.modal', function() {
+        //clear info
+        $('#poj-name-info').hide();
+        $('#eng-name-info').hide();
+        $('#tender-name-info').hide();
+        $('#tender-name').val('');
         //获取建设项目
         let selected = Tree.selected();
         let projs = getProjs(selected);
         setProjOptions(projs);
+       $($("input[name='valuation_type']")[0]).click();
     });
 
     // 新增单位工程
@@ -949,24 +954,41 @@ function existName(name , nodes){
 function getProjs(selected){
     let rst = [];
     let temp;
+    let firstNode;
     if(!selected){
         temp = Tree._root.children;
+        firstNode = temp[0];
     }
     else if(selected.data.projType === projectType.folder){
         temp = selected.children;
+        firstNode = temp[0];
     }
     else if(selected.data.projType === projectType.project){
         temp = selected.parent.children;
+        firstNode = temp[0];
     }
     else if(selected.data.projType === projectType.engineering || selected.data.projType === projectType.tender){
         let proj = selected.parent.data.projType === projectType.project ? selected.parent : selected.parent.parent;
         temp = proj.parent.children;
+        firstNode = proj;
     }
     for(let i = 0, len = temp.length; i < len; i++){
         if(temp[i].data.projType === projectType.project){
             rst.push(temp[i]);
         }
     }
+    //firstNode to first place
+    let index = null;
+    for(let i = 0, len = rst.length; i < len; i++){
+        if(rst[i].data.ID === firstNode.data.ID){
+            index = i;
+            break;
+        }
+    }
+    if(index){
+        rst.splice(index, 1);
+        rst.splice(0, 0, firstNode);
+    }
     return rst;
 }
 
@@ -981,6 +1003,7 @@ function setFileOptions(projID){
     }
     else {
         getUnitFile(projID, function (response) {
+            $("#unit-price").children("option:not(':first')").remove();
             if (response.data.length <= 0) {
                 return false;
             }
@@ -988,17 +1011,16 @@ function setFileOptions(projID){
             for(let tmp of response.data) {
                 unitFileHtml += '<option value="'+ tmp.id +'">'+ tmp.name +'</option>';
             }
-            $("#unit-price").children("option:not(':first')").remove();
             $("#unit-price").children("option").first().after(unitFileHtml);
         });
         // 获取费率文件数据
         getFeeRateFile(projID, function (response) {
-            if (response.data.length <= 0) {
-                return false;
-            }
             let first = $("#tender-fee-rate").children("option").first();
             $("#tender-fee-rate").empty();
             $("#tender-fee-rate").append(first);
+            if (response.data.length <= 0) {
+                return false;
+            }
             for(let tmp of response.data) {
                 let option =  $("<option>").val(tmp.ID).text(tmp.name);
                 $("#tender-fee-rate").append(option);
@@ -1011,12 +1033,8 @@ function setFileOptions(projID){
 function setProjOptions(projs){
     $("#poj-name-list").empty();
     $("#poj-name").val("");
-    selectedInfo.project = null;
     if(projs.length > 0){
         $("#poj-name").val(projs[0].data.name);
-        selectedInfo.project = Object.create(null);
-        selectedInfo.project.ID = projs[0].data.ID;
-        selectedInfo.project.name = projs[0].data.name;
         setFileOptions(projs[0].data.ID);
         setEngOptions(projs[0].data.ID);
         for(let i = 0, len = projs.length; i < len; i++){
@@ -1024,8 +1042,6 @@ function setProjOptions(projs){
             proj.addClass("dropdown-item");
             proj.attr("type", "button");
             proj.click(function () {
-                selectedInfo.project.ID = projs[i].data.ID;
-                selectedInfo.project.name = projs[i].data.name;
                 $("#poj-name").val(projs[i].data.name);
                 setFileOptions(projs[i].data.ID);
                 setEngOptions(projs[i].data.ID);
@@ -1043,21 +1059,33 @@ function setEngOptions(projID){
     let proj = Tree.findNode(projID) || null;
     $("#eng-name-list").empty();
     $("#eng-name").val("");
-    selectedInfo.engineering = null;
     if(proj){
         let engineerings = proj.children;
+        //set selected engineering to first place
+        let selected = Tree.selected();
+        let firstNode = null;
+        if(selected && (selected.data.projType === projectType.engineering || selected.data.projType === projectType.tender)){
+            firstNode = selected.data.projType === projectType.engineering ? selected : selected.parent;
+        }
+        if(firstNode){
+            let index = null;
+            for(let i = 0, len = engineerings.length; i < len; i++){
+                if(firstNode.data.ID === engineerings[i].data.ID){
+                    index = i;
+                }
+            }
+            if(index){
+                engineerings.splice(index, 1);
+                engineerings.splice(0, 0, firstNode);
+            }
+        }
         if(engineerings.length > 0){
             $("#eng-name").val(engineerings[0].data.name);
-            selectedInfo.engineering = Object.create(null);
-            selectedInfo.engineering.ID = engineerings[0].data.ID;
-            selectedInfo.engineering.name = engineerings[0].data.name;
             for(let i = 0, len = engineerings.length; i < len; i++){
                 let eng = $("<button>").val(engineerings[i].data.ID).text(engineerings[i].data.name);
                 eng.addClass("dropdown-item");
                 eng.attr("type", "button");
                 eng.click(function () {
-                    selectedInfo.engineering.ID = engineerings[i].data.ID;
-                    selectedInfo.engineering.name = engineerings[i].data.name;
                     $("#eng-name").val(engineerings[i].data.name);
                 });
                 $("#eng-name-list").append(eng);