Pārlūkot izejas kodu

Merge branch 'master' of http://smartcost.f3322.net:3000/SmartCost/ConstructionCost

chenshilong 7 gadi atpakaļ
vecāks
revīzija
3e808ded95

+ 59 - 2
modules/options/controllers/optionsController.js

@@ -4,7 +4,7 @@
 
 import BaseController from '../../common/base/base_controller';
 import OptionsDao from '../models/optionsModel';
-import optionsTypes from '../models/optionTypes';
+import optionSetting from '../models/optionTypes';
 
 let optionsDao = new OptionsDao();
 class OptionController extends BaseController {
@@ -13,6 +13,63 @@ class OptionController extends BaseController {
         let resJson = {error: 0, message: '', data: []};
         let user_id = req.session.sessionUser.id,
             compilation_id = req.session.sessionCompilation._id;
+        try{
+            resJson.data = await optionsDao.getOptions(user_id, compilation_id);
+            if(!resJson.data){
+                resJson.data = await optionsDao.saveOptions(user_id, compilation_id, optionSetting);
+            }
+        }
+        catch (err){
+            resJson.error = true;
+            resJson.message = '获取失败';
+            resJson.data = null;
+        }
+        res.json(resJson);
+    }
+    //获得特定选项类型的选项
+    async getOptionsByType(req, res){
+        let resJson = {error: null, message: '', data: null};
+        let user_id = req.session.sessionUser.id,
+            compilation_id = req.session.sessionCompilation._id,
+            optsType = req.body.optsType;
+        try{
+            resJson.data = await optionsDao.getOptionsByType(user_id, compilation_id, optsType);
+        }
+        catch (err){
+            resJson.error = true;
+            resJson.message = '获取失败';
+            resJson.data = null;
+        }
+        res.json(resJson);
+    }
+
+    async saveOptions(req, res){
+        let resJson = {error: 0, message: '', data: null};
+        let data = JSON.parse(req.body.data);
+        let user_id = req.session.sessionUser.id,
+            compilation_id = req.session.sessionCompilation._id,
+            optSetting = data.optSetting;
+        try{
+            resJson.data = await optionsDao.saveOptions(user_id, compilation_id, optSetting);
+        }
+        catch (err){
+            resJson.error = true;
+            resJson.message = '保存失败';
+            resJson.data = null;
+        }
+        res.json(resJson);
+    }
+}
+
+
+
+
+/*class OptionController extends BaseController {
+    //获得所有选项类型的选项
+    async getOptions(req, res){
+        let resJson = {error: 0, message: '', data: []};
+        let user_id = req.session.sessionUser.id,
+            compilation_id = req.session.sessionCompilation._id;
         let defaultOpts = {
             GENERALOPTS: {
                 rationQuanACToBillsQuan: true,//自动根据清单工程量填写定额工程量
@@ -82,6 +139,6 @@ class OptionController extends BaseController {
         }
         res.json(resJson);
     }
-}
+}*/
 
 export default OptionController;

+ 57 - 4
modules/options/models/optionTypes.js

@@ -5,9 +5,62 @@
 /*
 * 用户选项设置的选项类型,目前有常规选项
 * */
-
-const optionsTypes = {
-    GENERALOPTS: 'GENERALOPTS'//常规选项:1.自动根据清单工程量填写定额工程量 2.自动根据定额单位转换定额工程量
+const optionSetting = {
+    GENERALOPTS: {
+        rationQuanACToBillsQuan: true,//自动根据清单工程量填写定额工程量
+        rationQuanACToRationUnit: true//自动根据定额单位转换定额工程量
+    },
+    //色彩相关
+    COLOROPTS: {
+        DEFAULT: {
+            backColor: 'White',
+            foreColor: 'Black',
+            stringFont: '15px Arial',
+            numFont: '13px Arial'
+        },
+        DXFY: {
+            backColor: 'default',
+            foreColor: 'default',
+            stringFont: 'bold 15px Arial',
+            numFont: 'bold 13px Arial'
+        },
+        FB: {
+            backColor: '#C1D3E3',
+            foreColor: 'default',
+            stringFont: 'default',
+            numFont: 'default'
+        },
+        UNLEAFBILL: {
+            backColor: '#C1D3E3',
+            foreColor: 'default',
+            stringFont: 'default',
+            numFont: 'default'
+        },
+        FX: {
+            backColor: '#DAE5EE',
+            foreColor: 'default',
+            stringFont: 'default',
+            numFont: 'default'
+        },
+        UNCBBILL: {
+            backColor: '#DAE5EE',
+            foreColor: 'default',
+            stringFont: 'default',
+            numFont: 'default'
+        },
+        CBBILL: {
+            backColor: '#E5F3F2',
+            foreColor: 'default',
+            stringFont: 'default',
+            numFont: 'default'
+        },
+        ZCSB: {
+            backColor: 'default',
+            foreColor: '#4D7BFF',
+            stringFont: 'default',
+            numFont: 'default'
+        }
+    }
 };
 
-export default optionsTypes;
+export default optionSetting;

+ 29 - 1
modules/options/models/optionsModel.js

@@ -12,6 +12,34 @@ class OptionsDao {
     }
 
     async getOptionsByType(user_id, compilation_id, optsType){
+        let rst = await optionsModel.findOne({user_id: user_id, compilation_id: compilation_id});
+        if(rst){
+            return rst.options[optsType] !== undefined && rst.options[optsType] !== null ? rst.options[optsType] : null;
+        }
+    }
+
+    async saveOptions(user_id, compilation_id, optSetting){
+        let optionsData = await optionsModel.find({user_id: user_id, compilation_id: compilation_id});
+        if(optionsData.length === 0){
+            await optionsModel.create({user_id: user_id, compilation_id: compilation_id, options: optSetting});
+        }
+        await optionsModel.update({user_id: user_id, compilation_id: compilation_id}, optSetting);
+        let rst = await optionsModel.find({user_id: user_id, compilation_id: compilation_id});
+        return rst.length > 0 && typeof rst[0].options !== 'undefined' ? rst[0].options : null;
+    }
+}
+
+
+
+
+/*class OptionsDao {
+    async getOptions(user_id, compilation_id){
+        let rst = await optionsModel.find({user_id: user_id, compilation_id: compilation_id});
+        rst = rst.length > 0 && typeof rst[0].options !== 'undefined' ? rst[0].options : null;
+        return rst;
+    }
+
+    async getOptionsByType(user_id, compilation_id, optsType){
         let rst = await optionsModel.find({user_id: user_id, compilation_id: compilation_id});
         if(rst.length > 0){
             let opts = rst[0].options;
@@ -33,6 +61,6 @@ class OptionsDao {
         let rst = await optionsModel.find({user_id: user_id, compilation_id: compilation_id});
         return rst;
     }
-}
+}*/
 
 export default OptionsDao;

+ 10 - 1
modules/options/models/schemas.js

@@ -10,9 +10,18 @@ let Schema = mongoose.Schema;
 let optionSchema = new Schema({
     user_id: String,
     compilation_id: String,
-    options: Array
+    options: {
+        type: Schema.Types.Mixed,
+        default: {}
+    }
 }, {versionKey: false});
 
+/*let optionSchema = new Schema({
+    user_id: String,
+    compilation_id: String,
+    options: Array
+}, {versionKey: false});*/
+
 let optionsModel = mongoose.model('options', optionSchema);
 
 export default optionsModel;

+ 1 - 1
public/web/tree_sheet/tree_sheet_controller.js

@@ -67,6 +67,7 @@ var TREE_SHEET_CONTROLLER = {
                         }
                         that.sheet.deleteRows(sels[0].row, rowCount);
                         that.setTreeSelected(that.tree.items[sels[0].row]);
+                        that.sheet.setSelection(sels[0].row,sels[0].col,1,sels[0].colCount);
                     });
                     cbTools.refreshFormulaNodes();
                 }
@@ -96,7 +97,6 @@ var TREE_SHEET_CONTROLLER = {
                     cbTools.refreshFormulaNodes();
                 }
             }
-
         };
         controller.prototype.upLevel = function () {
             var that = this;

+ 3 - 3
public/web/tree_sheet/tree_sheet_helper.js

@@ -105,9 +105,9 @@ var TREE_SHEET_HELPER = {
         nodes.forEach(function (node) {
             let iRow = node.serialNo();
             let nodeStyle = projectObj.getNodeColorStyle(node);
-            //test
-            sheet.setStyle(iRow, -1, nodeStyle);
-            //test
+            if(nodeStyle){
+                sheet.setStyle(iRow, -1, nodeStyle);
+            }
             setting.cols.forEach(function (colSetting, iCol) {
                 var cell = sheet.getCell(iRow, iCol, GC.Spread.Sheets.SheetArea.viewport);
                 let boldFontStyle = projectObj.getBoldFontStyle(node, colSetting);

+ 0 - 3
web/building_saas/main/js/models/bills.js

@@ -519,9 +519,6 @@ var Bills = {
                     project.ration_glj.updataOrdelete(selected.source);
                 }
                 if(parent){
-                    if(parent.children.length==0&&parent.data.feesIndex&&parent.data.feesIndex.common){
-                        parent.data.feesIndex.common.unitFee = 0;
-                    }
                     projectObj.converseCalculateBills(parent);
                 }else { //删除的是大项费用要重新计算工程造价节点
                     project.Bills.calcEngineeringCostNode(controller);

+ 8 - 1
web/building_saas/main/js/views/main_tree_col.js

@@ -149,7 +149,14 @@ let MainTreeCol = {
             return MainTreeCol.readOnly.non_bills(node) || MainTreeCol.readOnly.billsParent(node) || MainTreeCol.readOnly.leafBillsWithDetail(node)
         },
         forQuantity: function (node) {
-            return MainTreeCol.readOnly.glj(node) || MainTreeCol.readOnly.billsParent(node)
+            if(node.sourceType === projectObj.project.Bills.getSourceType()){
+                if(node.data.type==billType.DXFY||node.data.type==billType.FB||(node.data.type==billType.BILL&&MainTreeCol.readOnly.billsParent(node))){//大项费用、分部、清单父项行,工程量只读。
+                    return true;
+                }
+            }else if(MainTreeCol.readOnly.glj(node)){
+                return true;
+            }
+            return false;
         },
         forMarketPrice: function (node) {
             return MainTreeCol.readOnly.bills(node) ||

+ 61 - 1
web/building_saas/main/js/views/options_view.js

@@ -3,6 +3,66 @@
  */
 let optionsOprObj = {
     options: null,
+    optionsTypes: {GENERALOPTS: 'GENERALOPTS', COLOROPTS: 'COLOROPTS'},
+    rationQuanACToBillsQuan: $('#generalOpts1'),
+    rationQuanACToRationUnit: $('#generalOpts2'),
+    getOptions: function () {
+        let me = this;
+        CommonAjax.post('/options/getOptions', [], function (rstData) {
+            me.options = rstData;
+            let gOpts = me.options[me.optionsTypes.GENERALOPTS];
+            if(isDef(gOpts)){
+                for(let attr in gOpts){
+                    me[attr][0].checked = gOpts[attr];
+                }
+            }
+        });
+    },
+    saveOptions: function (type, opts) {
+        let optSettingType = 'options.' + type;
+        let postData = Object.create(null);
+        postData[optSettingType] = opts;
+        CommonAjax.post('/options/saveOptions', {optSetting: postData});
+    },
+    //更新optionsOprObj对象options数据
+    updateOptions: function (options, updateObj) {
+        if(isDef(options[updateObj.type])){
+            options[updateObj.type][updateObj.opt] = updateObj.value;
+        }
+    },
+    getOptsByType: function (options, type) {
+        return isDef(options[type]) ? options[type] : null;
+    },
+    getOption: function (type, optionName) {
+        if(!isDef(optionName)){
+            return isDef(this.options[type]) ? this.options[type] : null;
+        }
+        else {
+            return isDef(this.options[type][optionName])
+                ? this.options[type][optionName]
+                    : optionName === this.optionsTypes.GENERALOPTS
+                    ? true
+                : null;
+        }
+    }
+};
+
+optionsOprObj.getOptions();
+optionsOprObj.rationQuanACToBillsQuan.click(function () {
+    let value = this.checked;
+    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToBillsQuan', value: value});
+    optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
+});
+optionsOprObj.rationQuanACToRationUnit.click(function () {
+    let value = this.checked;
+    optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: value});
+    optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
+});
+
+
+
+/*let optionsOprObj = {
+    options: null,
     optionsTypes: {GENERALOPTS: 'GENERALOPTS'},
     rationQuanACToBillsQuan: $('#generalOpts1'),
     rationQuanACToRationUnit: $('#generalOpts2'),
@@ -58,4 +118,4 @@ optionsOprObj.rationQuanACToRationUnit.click(function () {
     let value = this.checked;
     optionsOprObj.updateOptions(optionsOprObj.options, {type: optionsOprObj.optionsTypes.GENERALOPTS, opt: 'rationQuanACToRationUnit', value: value});
     optionsOprObj.saveOptions(optionsOprObj.optionsTypes.GENERALOPTS, optionsOprObj.getOptsByType(optionsOprObj.options, optionsOprObj.optionsTypes.GENERALOPTS));
-});
+});*/

+ 125 - 44
web/building_saas/main/js/views/project_view.js

@@ -41,37 +41,89 @@ var projectObj = {
             }
         };
         let selected = tree.selected, that = projectObj;
+
         let canUpLevel = function (node) {
-            if (selected && selected.depth() > 1 && selected.canUpLevel()) {
-                if (selected.sourceType === that.project.Bills.getSourceType()) {
-                    return (!selected.nextSibling) || (selected.children.length === 0) || (selected.source.children.length > 0);
-                } else {
+            if(!node){
+                return false;
+            }
+            if(node.depth()<=1){//焦点行是树结构的第一/二层节点,灰显。
+                return false;
+            }
+            if(node.sourceType !== that.project.Bills.getSourceType()){//焦点行是定额/量价/工料机,灰显。
+                return false;
+            }else {
+                if(node.data.type == billType.FX){//是分项,灰显。
                     return false;
                 }
-            } else {
-                return false;
+                if(node.data.type == billType.FB&&node.nextSibling&&node.children.length>0){//焦点行是分部有后兄弟,有子项.
+                     if(node.children[0].data.type==billType.FX){ //焦点行子项是分项
+                         return false;
+                     }
+                }
+                if(node.data.type == billType.BILL &&node.nextSibling){//焦点行是清单有后兄弟
+                    if(node.data.calcBase&&node.data.calcBase!=""){//有基数计算
+                        return false;
+                    }
+                    if(node.children.length>0&&node.children[0].sourceType !== that.project.Bills.getSourceType()){//有子项,并且子项不是清单
+                        return false;
+                    }
+                }
             }
+            return true;
         };
         let canDownLevel = function (node) {
-            if (selected && selected.depth() > 0 && selected.canDownLevel()) {
-                if (selected.sourceType === that.project.Bills.getSourceType()) {
-                    return (selected.preSibling.children.length === 0) || (selected.preSibling.source.children.length > 0);
-                } else {
+            if(!node){
+                return false;
+            }
+            if(node.depth()==0){//焦点行是树结构的第一层节点,灰显。
+                return false;
+            }
+            if(node.sourceType !== that.project.Bills.getSourceType()) {//焦点行是定额/量价/工料机,灰显。
+                return false;
+            }else {
+                if(node.data.type == billType.FX){//是分项,灰显。
                     return false;
                 }
-            } else {
-                return false;
+                if(!node.preSibling){//无前兄弟,灰显
+                    return false;
+                }else if(node.preSibling.data.calcBase&&node.preSibling.data.calcBase!=""){//前兄弟有基数计算
+                    return false
+                }
+                if(node.preSibling.children.length>0){//前兄弟有子项,子项是分项,灰显。
+                    if(node.data.type==billType.FB&&node.preSibling.children[0].data.type==billType.FX){//焦点行是分部前兄弟有子项,子项是分项,灰显。
+                        return false;
+                    }
+                    if(node.data.type==billType.BILL&&node.preSibling.children[0].sourceType !== that.project.Bills.getSourceType()){//焦点行是清单,子项不是清单
+                        return false
+                    }
+                }
             }
+            return true;
         };
-
-
-
+        let canUpMove = function (node) {
+            if(node&&node.preSibling){//有前兄弟
+                if(node.sourceType==that.project.Bills.getSourceType()&&node.data.type == billType.DXFY&&node.data.isAdd!==1){
+                    return false;
+                }
+                return true
+            }
+            return false
+        };
+        let canDownMove = function (node) {
+            if(node&&node.nextSibling){
+                if(node.sourceType==that.project.Bills.getSourceType()&&node.data.type == billType.DXFY&&node.data.isAdd!==1){
+                    return false;
+                }
+                return true;
+            }
+            return false
+        };
+        
         setButtonValid(ifCanDelete(), $('#delete'));
         setButtonValid(canUpLevel(selected), $('#upLevel'));
         setButtonValid(canDownLevel(selected), $('#downLevel'));
-        setButtonValid(selected && (selected.depth() > 0) && selected.canUpMove(), $('#upMove'));
-        setButtonValid(selected && (selected.depth() > 0) && selected.canDownMove(), $('#downMove'));
-
+        setButtonValid(canUpMove(selected) , $('#upMove'));
+        setButtonValid(canDownMove(selected), $('#downMove'));
     },
     checkCommonField: function (editingText, colSetting) {
         let value;
@@ -471,6 +523,7 @@ var projectObj = {
                 that.loadFocusLocation();
                 let endTime = +new Date();
                 console.log("加载完成-----"+endTime);
+                console.log(`时间——${endTime - startTime}`);
             }
             else {
 
@@ -801,63 +854,90 @@ var projectObj = {
         };
  },
 
- //根据节点获取行style(颜色、字体加粗)
-    getNodeColorStyle: function (node) {
-        let type, backColor = null, foreColor = null;
+    //根据节点获取行style(颜色、字体加粗)
+    getNodeColorStyle: function (node, colSetting) {
+        let colorSetting = optionsOprObj.getOption(optionsOprObj.optionsTypes.COLOROPTS);
+        let mapping = {DEFAULT: 'DEFAULT', DXFY: 'DXFY', FB: 'FB', UNLEAFBILL: 'UNLEAFBILL',
+            FX: 'FX', UNCBBILL: 'UNCBBILL', CBBILL: 'CBBILL', ZCSB: 'ZCSB'};
+        let styleMap = null;
+        //中文字段名,由于同一节点中,中文字体大小和数字字体大小不同
+        let stringFields = [
+            'code',
+            'subType',
+            'name',
+            'unit',
+            'itemCharacterText',
+            'jobContentText',
+            'adjustState',
+            'calcBase',
+            'programID',
+            'ruleText'
+        ];
         if(!isDef(node)){
             return null;
         }
         //清单大类
         if(node.sourceType === this.project.Bills.getSourceType()){
+            //大项费用
+            if(node.data.type === billType.DXFY){
+                styleMap = mapping.DXFY;
+            }
             //分部
             if(node.data.type === billType.FB){
-                type = 1;
+                styleMap = mapping.FB;
             }
             //分项
             else if(node.data.type === billType.FX){
-                type = 2;
+                styleMap = mapping.FX;
             }
             //清单
             else if(node.data.type === billType.BILL){
                 //非叶子节点的清单
                 if(node.source.children.length > 0){
-                    type = 1;
+                    styleMap = mapping.UNLEAFBILL;
                 }
                 //未使用基数计算的叶子节点的清单
                 else if(node.source.children.length === 0 && (!isDef(node.data.calcBase) || node.data.calcBase === '')){
-                    type = 2;
+                    styleMap = mapping.UNCBBILL;
                 }
                 //使用基数计算的叶子节点的清单
                 else if(node.source.children.length === 0 && isDef(node.data.calcBase && node.data.calcBaseValue !== '')){
-                    type = 3;
+                    styleMap = mapping.CBBILL;
                 }
             }
         }
         //定额下的主材、设备
         else if(node.sourceType === this.project.ration_glj.getSourceType()){
-            type = 4;
+            styleMap = mapping.ZCSB;
         }
-        switch (type){
-            //case 0: font = 'bold 13px "Arial"'; break;
-            case 1: backColor = '#c1d3e3'; break;
-            case 2: backColor = '#dae5ee'; break;
-            case 3: backColor = '#e5f3f2';  break;
-            case 4: foreColor = '#4D7BFF';   break;
+        else {
+            styleMap = mapping.DEFAULT;
         }
-        if(!backColor && !foreColor){
+        let styleSetting = colorSetting[styleMap];
+        let defaultSetting = colorSetting[mapping.DEFAULT];
+        if(!isDef(styleSetting)){
             return null;
         }
         let style = new GC.Spread.Sheets.Style();
-        if(foreColor){
-            style.foreColor = foreColor;
-        }
-        if(backColor){
-            style.backColor = backColor;
-            style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
-            style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
-            style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
-            style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
+        //设置style属性
+        for(let attr in styleSetting){
+            if(attr !== 'stringFont' && attr !== 'numFont'){
+                style[attr] = styleSetting[attr] === 'default' || !isDef(styleSetting[attr]) ? defaultSetting[attr] : styleSetting[attr];
+            }
+            //暂时不开放字体设置,开放的话只能每个单元格进入此方法
+           /* else {
+                if(stringFields.indexOf(colSetting.data.field) > 0){
+                    style.font = styleSetting.stringFont === 'default' || !isDef(styleSetting.stringFont) ? defaultSetting.stringFont : styleSetting.stringFont;
+                }
+                else {
+                    style.font = styleSetting.numFont === 'default' || !isDef(styleSetting.numFont) ? defaultSetting.numFont : styleSetting.numFont;
+                }
+            }*/
         }
+        style.borderLeft = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
+        style.borderTop = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
+        style.borderRight = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
+        style.borderBottom = new GC.Spread.Sheets.LineBorder("#D4D4D4", GC.Spread.Sheets.LineStyle.thin);
         return style;
     },
     //大项费用则字体加粗,String 15px, Number 13px
@@ -887,6 +967,7 @@ var projectObj = {
         }
         return style;
     }
+    
 };
 // 点击合计框中的复制
 $("body").on("click", "#total-tips a", function() {
@@ -926,7 +1007,7 @@ $('#upLevel').click(function () {
     if (selected && selected.sourceType === project.Bills.getSourceType()) {
         project.Bills.upLevelBills(selected.source);
         controller.upLevel();
-        projectObj.converseCalculateBills(orgParent);
+        projectObj.project.calcProgram.calcBillsAndSave([selected,orgParent]);
     }
 });
 $('#downLevel').click(function () {