Browse Source

Merge branch 'master' into olym

olym 7 years ago
parent
commit
eeb5c36da3

+ 86 - 0
modules/options/controllers/optionsController.js

@@ -0,0 +1,86 @@
+/**
+ * Created by Zhong on 2017/9/28.
+ */
+
+import BaseController from '../../common/base/base_controller';
+import OptionsDao from '../models/optionsModel';
+import optionsTypes from '../models/optionTypes';
+
+let optionsDao = new OptionsDao();
+class OptionController extends BaseController {
+    //获得所有选项类型的选项
+    async getOptions(req, res){
+        let resJson = {error: null, message: '', data: []};
+        let user_id = req.session.sessionUser.id,
+            compilation_id = req.session.sessionCompilation._id;
+        let defaultOpts = {
+            GENERALOPTS: {
+                rationQuanACToBillsQuan: true,//自动根据清单工程量填写定额工程量
+                rationQuanACToRationUnit: true//自动根据定额单位转换定额工程量
+            }
+        };
+        try{
+            resJson.data = await optionsDao.getOptions(user_id, compilation_id);
+            if(!resJson.data){
+                resJson.data = await optionsDao.saveOptions(user_id, compilation_id, optionsTypes.GENERALOPTS, defaultOpts.GENERALOPTS);
+            }
+        }
+        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{
+            let hasThisOpts = false;
+            for(let i in optionsTypes){
+                if(optionsTypes[i] === optsType){
+                    hasThisOpts = true;
+                    break;
+                }
+            }
+            if(!hasThisOpts) throw '不存在此选项类';
+            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: null, message: '', data: null};
+        let user_id = req.session.sessionUser.id,
+            compilation_id = req.session.sessionCompilation._id,
+            optsType = req.body.optsType,
+            opts = JSON.parse(req.body.opts);
+        try{
+            let hasThisOpts = false;
+            for(let i in optionsTypes){
+                if(optionsTypes[i] == optsType){
+                    hasThisOpts = true;
+                    break;
+                }
+            }
+            if(!hasThisOpts) throw '不存在此选项类';
+            resJson.data = await optionsDao.saveOptions(user_id, compilation_id, optsType, opts);
+        }
+        catch (err){
+            resJson.error = true;
+            resJson.message = '保存失败';
+            resJson.data = null;
+        }
+        res.json(resJson);
+    }
+}
+
+export default OptionController;

+ 13 - 0
modules/options/models/optionTypes.js

@@ -0,0 +1,13 @@
+/**
+ * Created by Zhong on 2017/9/28.
+ */
+
+/*
+* 用户选项设置的选项类型,目前有常规选项
+* */
+
+const optionsTypes = {
+    GENERALOPTS: 'GENERALOPTS'//常规选项:1.自动根据清单工程量填写定额工程量 2.自动根据定额单位转换定额工程量
+};
+
+export default optionsTypes;

+ 38 - 0
modules/options/models/optionsModel.js

@@ -0,0 +1,38 @@
+/**
+ * Created by Zhong on 2017/9/28.
+ */
+
+import optionsModel from '../models/schemas';
+
+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;
+            for(let i = 0, len = opts.length; i < len; i++){
+                if(opts[i].type === optsType){
+                    return opts[i];
+                }
+            }
+        }
+        else return null;
+    }
+
+    async saveOptions(user_id, compilation_id, opsType, opts){
+        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: [{type: opsType, opts: opts}]});
+        }
+        await optionsModel.update({user_id: user_id, compilation_id: compilation_id, 'options.type': opsType}, {$set: {'options.$.opts': opts}});
+        let rst = await optionsModel.find({user_id: user_id, compilation_id: compilation_id});
+        return rst;
+    }
+}
+
+export default OptionsDao;

+ 18 - 0
modules/options/models/schemas.js

@@ -0,0 +1,18 @@
+/**
+ * Created by Zhong on 2017/9/28.
+ */
+import mongoose from 'mongoose';
+
+/*
+* 此选项设置针对绑定用户,对用户该编办下所有项目有效的全局选项
+* */
+let Schema = mongoose.Schema;
+let optionSchema = new Schema({
+    user_id: String,
+    compilation_id: String,
+    options: Array
+}, {versionKey: false});
+
+let optionsModel = mongoose.model('options', optionSchema);
+
+export default optionsModel;

+ 17 - 0
modules/options/routes/routes.js

@@ -0,0 +1,17 @@
+/**
+ * Created by Zhong on 2017/9/28.
+ */
+import express from 'express';
+import OptionsController from '../controllers/optionsController';
+
+let router = express.Router();
+let optionsController = new OptionsController();
+
+module.exports = function (app) {
+    router.post('/getOptions', optionsController.init, optionsController.getOptions);
+    router.post('/getOptionsByType', optionsController.init, optionsController.getOptionsByType);
+    router.post('/saveOptions', optionsController.init, optionsController.saveOptions);
+
+
+    app.use('/options', router);
+};

+ 48 - 1
web/building_saas/main/html/main.html

@@ -40,7 +40,8 @@
                     <a class="nav-link" href="#" aria-expanded="false" data-toggle="modal" data-target="#poj-set"><i class="fa fa-cube"></i> 项目属性</a>
                 </li>
                 <li class="nav-item">
-                    <a class="nav-link" href="#" aria-haspopup="true" aria-expanded="false"><i class="fa fa-sliders"></i> 选项</a>
+                    <a class="nav-link" href="#" aria-expanded="false" data-toggle="modal" data-target="#opts-set"><i class="fa fa-sliders"></i> 选项</a>
+                    <!--<a class="nav-link" href="#" aria-haspopup="true" aria-expanded="false"><i class="fa fa-sliders"></i> 选项</a>-->
                 </li>
                 <li class="nav-item dropdown">
                     <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-wrench"></i> 工具</a>
@@ -491,6 +492,51 @@
             </div>
         </div>
     </div>
+    <!--弹出选项-->
+    <div class="modal fade" id="opts-set" data-backdrop="static">
+        <div class="modal-dialog modal-lg" role="document">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h5 class="modal-title">选项</h5>
+                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                        <span aria-hidden="true">&times;</span>
+                    </button>
+                </div>
+                <div class="modal-body">
+                    <div class="row">
+                        <div class="col-3">
+                            <ul class="nav flex-column nav-pills" role="tablist">
+                                <li class="nav-item"><a class="nav-link active" data-toggle="pill" href="#opts-general" role="tab">常规选项</a></li>
+                            </ul>
+                        </div>
+                        <div class="col-9">
+                            <div class="tab-content">
+                                <!--常规选项-->
+                                <div class="tab-pane fade show active" id="opts-general" role="tabpanel">
+                                    <div class="modal-auto-height">
+                                        <fieldset class="form-group">
+                                            <div class="form-check">
+                                                <label class="form-check-label">
+                                                    <input class="form-check-input" name="opts-general-radios" id="generalOpts1" value="opt1" type="checkbox">
+                                                    自动根据清单工程量填写定额工程量
+                                                </label>
+                                            </div>
+                                            <div class="form-check">
+                                                <label class="form-check-label">
+                                                    <input class="form-check-input" name="opts-general-radios" id="generalOpts2" value="opt2" type="checkbox">
+                                                    自动根据定额单位转换定额工程量
+                                                </label>
+                                            </div>
+                                        </fieldset>
+                                    </div>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
     <!--弹出列设置-->
     <div class="modal fade" id="column" data-backdrop="static">
         <div class="modal-dialog modal-lg" role="document">
@@ -571,6 +617,7 @@
     <script type="text/javascript" src="/web/building_saas/main/js/views/main_tree_col.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/project_info.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/views/project_view.js"></script>
+    <script type="text/javascript" src="/web/building_saas/main/js/views/options_view.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/main_ajax.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/main.js"></script>
     <script type="text/javascript" src="/web/building_saas/main/js/controllers/project_controller.js"></script>

+ 44 - 18
web/building_saas/main/js/calc/bills_calc.js

@@ -40,7 +40,11 @@ let nodeCalcObj = {
     sumTotalFee: function() {
         let result = 0, child;
         for (child of this.node.children) {
-            result += this.getFee(child.data, this.field.totalFee);
+            let value = this.getFee(child.data, this.field.totalFee);
+            if (Object.prototype.toString.apply(value) === "[object String]") {
+                value = parseFloat(value);
+            }
+            result += value;
         }
         return result;
     },
@@ -48,6 +52,9 @@ let nodeCalcObj = {
         let result = 0, child, qty;
         result = this.sumTotalFee(this.field);
         qty = this.getFee(this.node.data, 'quantity');
+        if (Object.prototype.toString.apply(qty) === "[object String]") {
+            qty = parseFloat(qty);
+        }
         if (qty !== 0) {
             result = result / qty;
         }
@@ -58,11 +65,22 @@ let nodeCalcObj = {
     },
     rationContentUnitFee: function () {
         let result = 0, child, qty = this.getFee(this.node.data, 'quantity');
+        if (Object.prototype.toString.apply(qty) === "[object String]") {
+            qty = parseFloat(qty);
+        }
         if (qty === 0) {
             qty = 1;
         }
         for (child of this.node.children) {
-            result += (this.getFee(child.data, this.field.unitFee) * this.getFee(child.data, 'quantity') / qty).toDecimal(this.digit);
+            let childUnitFee = this.getFee(child.data, this.field.unitFee);
+            if (Object.prototype.toString.apply(childUnitFee) === "[object String]") {
+                childUnitFee = parseFloat(childUnitFee);
+            }
+            let childQuantity = this.getFee(child.data, 'quantity');
+            if (Object.prototype.toString.apply(childQuantity) === "[object String]") {
+                childQuantity = parseFloat(childQuantity);
+            }
+            result += (childUnitFee * childQuantity / qty).toDecimal(this.digit);
         }
         return result;
     }
@@ -220,21 +238,26 @@ class BillsCalcHelper {
     constructor (project, CalcFlag) {
         this.project = project;
         this.CalcFlag = CalcFlag;
-        switch (this.CalcFlag) {
-            case rationContent:
-                this.calcField = rationContentCalcFields;
-                break;
-            case rationPrice:
-                this.calcField = rationPriceCalcFields;
-                break;
-            case rationPriceConverse:
-                this.calcField = rationPriceConverseCalcFields;
-                break;
-            case billsPrice:
-                this.calcField = billsPriceCalcFields;
-                break;
-            default:
-                this.calcField = [];
+        this.calcField = JSON.parse(JSON.stringify(feeType));
+        for (let field of this.calcField) {
+            // unitFeeCalcFlag
+            if (this.calcFlag === rationContent) {
+                field.unitFeeFlag = rationContentUnitFeeFlag;
+            } else if ( this.calcFlag === billsPrice) {
+                field.unitFeeFlag = billsPriceUnitFeeFlag;
+            } else {
+                field.unitFeeFlag = averageQtyUnitFeeFlag;
+            }
+            // totalFeeCalcFlag
+            if (field.type === 'common') {
+                if (this.CalcFlag === rationPriceConverse) {
+                    field.totalFeeFlag = sumTotalFeeFlag;
+                } else {
+                    field.totalFeeFlag = totalFeeFlag;
+                }
+            } else {
+                field.totalFeeFlag = sumTotalFeeFlag;
+            }
         }
         this.InitFields(this.calcField);
     };
@@ -289,7 +312,10 @@ class BillsCalcHelper {
         }
     };
     calcVolumePriceLeaf (node, fields) {
-
+        let total = 0;
+        for (let child of this.node.children) {
+            total += this.getFee(child.data, 'feesIndex.common.totalFee');
+        }
     };
     calcParent (node, fields) {
         nodeCalcObj.node = node;

+ 2 - 10
web/building_saas/main/js/controllers/project_controller.js

@@ -104,18 +104,10 @@ ProjectController = {
         }
     },
     calculateAll: function (project, sheetController, CalcType) {
-        let date0 = new Date();
-        let ration_calc = new RationCalcHelper(project);
-        ration_calc.calculateAll();
-        let date1 = new Date();
-        console.log(date1 - date0);
         let calc = new BillsCalcHelper(project, CalcType);
         calc.calcAll();
-        calc = null;
-        let date2 = new Date();
-        console.log(date2 - date1);
         sheetController.showTreeData();
-        let date3 = new Date();
-        console.log(date3 - date1);
+        project.Bills.updateAll();
+        calc = null;
     }
 }

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

@@ -74,6 +74,10 @@ var Bills = {
                 data.feesIndex = {};
                 if (data.fees) {
                     data.fees.forEach(function (fee) {
+                        fee.unitFee = parseFloat(fee.unitFee);
+                        fee.totalFee = parseFloat(fee.totalFee);
+                        fee.tenderUnitFee = parseFloat(fee.tenderUnitFee);
+                        fee.tenderTotalFee = parseFloat(fee.tenderTotalFee);
                         data.feesIndex[fee.fieldName] = fee;
                     });
                 }
@@ -236,6 +240,25 @@ var Bills = {
             this.project.pushNow('updateBills', this.getSourceType(), updateData);
         };
 
+        bills.prototype.updateAll = function () {
+            let updateData = [];
+            for (let data of this.datas) {
+                let uData = JSON.parse(JSON.stringify(data));
+                delete uData.feesIndex;
+                delete uData.flagsIndex;
+                if (uData.fees) {
+                    for (let fee of uData.fees) {
+                        fee.unitFee = fee.unitFee.toFixed(2);
+                        fee.totalFee = fee.totalFee.toFixed(2);
+                        fee.tenderUnitFee = fee.tenderUnitFee.toFixed(2);
+                        fee.tenderTotalFee = fee.tenderTotalFee.toFixed(2);
+                    }
+                }
+                updateData.push({'updateType': 'ut_update', 'updateData': data});
+            }
+            this.project.pushNow('updateAllBills', this.getSourceType(), updateData);
+        }
+
         return new bills(project);
     }
 };

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

@@ -139,4 +139,4 @@ $('#column').on('hide.bs.modal', function () {
     }
     SheetDataHelper.refreshColumnVisible(projectObj.project.projSetting.mainGridSetting, projectObj.mainSpread.getActiveSheet());
     projectObj.project.pushNow('editColSetting', projectObj.project.projSetting.moduleName, {projectID: projectObj.project.ID(), main_tree_col: projectObj.project.projSetting.main_tree_col});
-})
+});

+ 72 - 0
web/building_saas/main/js/views/options_view.js

@@ -0,0 +1,72 @@
+/**
+ * Created by Zhong on 2017/9/28.
+ */
+let optionsOprObj = {
+    options: null,
+    optionsTypes: {GENERALOPTS: 'GENERALOPTS'},
+    rationQuanACToBillsQuan: $('#generalOpts1'),
+    rationQuanACToRationUnit: $('#generalOpts2'),
+    getOptions: function () {
+        let me = this;
+        $.ajax({
+            type: 'post',
+            url: '/options/getOptions',
+            dataType: 'json',
+            success: function (result) {
+                if(!result.error){
+                   me.options = result.data;
+                    for(let i = 0, len = me.options.length; i < len; i++){
+                        let optsType = me.options[i].type,
+                            opts = me.options[i].opts;
+                        if(optsType === me.optionsTypes.GENERALOPTS){
+                            for(let attr in opts){
+                                me[attr][0].checked = opts[attr];
+                            }
+                        }
+                    }
+                }
+            }
+        });
+    },
+    saveOptions: function (optsType, opts) {
+        $.ajax({
+            type: 'post',
+            url: '/options/saveOptions',
+            data: {optsType: optsType, opts: JSON.stringify(opts)},
+            dataType: 'json',
+            success: function (result) {
+
+            }
+        })
+    },
+    //更新optionsOprObj对象options数据
+    updateOptions: function (options, updateObj) {
+        for(let i = 0, len = options.length; i < len; i++){
+            if(options[i].type === updateObj.type){
+                options[i].opts[updateObj.opt] = updateObj.value;
+                break;
+            }
+        }
+    },
+    getOptsByType: function (options, type) {
+        let rst = null;
+        for(let i = 0, len = options.length; i < len; i++){
+            if(options[i].type === type){
+                rst = options[i].opts;
+            }
+        }
+        return rst;
+    }
+};
+
+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));
+});

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

@@ -133,7 +133,6 @@ let subViewObj = {
             if (node.sourceType === projectObj.project.Bills.getSourceType()) {
                 $('#comments>textarea').val(node.data.comments)
             } else if (node.sourceType === projectObj.project.Ration.getSourceType()) {
-                console.log(node.data);
                 $('#comments>textarea').val(node.data.content);
             }
         }