Browse Source

编办数据新增计算程序标准库

olym 7 years ago
parent
commit
ea08e3d1cf

+ 24 - 0
modules/common/std/schemas/std_calc_program.js

@@ -0,0 +1,24 @@
+/**
+ * 计算程序标准库数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/10/23
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'std_calc_programs';
+let modelSchema = {
+    // 自增id
+    ID: Number,
+    // 所在地
+    region: String,
+    // 标准名称
+    libName: String,
+    // 模板数据
+    templates: Schema.Types.Mixed
+};
+
+let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
+export {model as default, collectionName as collectionName};

+ 50 - 0
modules/common/std/std_calc_program_model.js

@@ -0,0 +1,50 @@
+/**
+ * 计算程序标准库业务模型
+ *
+ * @author CaiAoLin
+ * @date 2017/10/23
+ * @version
+ */
+import BaseModel from "../base/base_model";
+import STDCalcProgramSchema from "./schemas/std_calc_program";
+
+class STDCalcProgramModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = STDCalcProgramSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取计算程序列表
+     *
+     * @return {Promise}
+     */
+    async getProgramList() {
+        let result = [];
+        let field = {ID: 1, libName: 1};
+        let programList = await this.findDataByCondition({ID: {$ne: ''}}, field, false);
+
+        if (programList === null) {
+            return result;
+        }
+        // 整理数据
+        for(let program of programList) {
+            let tmpData = {
+                id: program.ID,
+                name: program.libName
+            };
+            result.push(tmpData);
+        }
+        return result;
+    }
+
+}
+
+export default STDCalcProgramModel;

+ 7 - 0
modules/users/controllers/compilation_controller.js

@@ -16,6 +16,7 @@ import BillsTemplateModel from "../models/bills_template_model";
 import {default as BillsFixedFlagConst, List as BillsFixedFlagList} from "../../common/const/bills_fixed.js";
 import EngineeringLibModel from "../models/engineering_lib_model";
 import STDLabourCoesModel from "../../common/std/std_labour_coes_model";
+import STDCalcProgramModel from "../../common/std/std_calc_program_model";
 
 class CompilationController extends BaseController {
 
@@ -185,6 +186,7 @@ class CompilationController extends BaseController {
         let valuationData = {};
         let valuationList = {};
         let artificialCoefficientList = [];
+        let calculationList = [];
         try {
             let compilationModel = new CompilationModel();
             compilationList = await compilationModel.getCompilationList();
@@ -209,6 +211,10 @@ class CompilationController extends BaseController {
             let stdLabourCoesModel = new STDLabourCoesModel();
             artificialCoefficientList = await stdLabourCoesModel.getLabourCoesList();
 
+            // 获取计算程序库
+            let stdCalcProgramModel = new STDCalcProgramModel();
+            calculationList = await stdCalcProgramModel.getProgramList();
+
             // 获取对应的计价规则数据
             [valuationData, valuationList] = await compilationModel.getValuation(selectedCompilation._id, valuationId, section);
             if (Object.keys(valuationData).length <= 0) {
@@ -241,6 +247,7 @@ class CompilationController extends BaseController {
             feeRateList: JSON.stringify(feeRateList),
             billsTemplateData: JSON.stringify(billsTemplateData),
             mainTreeCol: JSON.stringify(libData.main_tree_col),
+            calculationList: JSON.stringify(calculationList),
             layout: 'users/views/layout/layout'
         };
         response.render('users/views/compilation/engineering', renderData);

+ 4 - 0
modules/users/models/engineering_lib_model.js

@@ -151,6 +151,9 @@ class EngineeringLibModel extends BaseModel {
         // 判断人工系数
         data.artificial_lib = this._validLib(data.artificial_lib);
 
+        // 判断计算程序
+        data.program_lib = this._validLib(data.program_lib);
+
         return data;
     }
 
@@ -206,6 +209,7 @@ class EngineeringLibModel extends BaseModel {
                 glj_count: tmp.glj_lib.length,
                 fee_count: tmp.fee_lib.length,
                 artificial_count: tmp.artificial_lib.length,
+                program_count: tmp.program_lib.length,
             };
         }
 

+ 5 - 0
modules/users/models/schemas/engineering_lib.js

@@ -45,6 +45,11 @@ let modelSchema = {
     artificial_lib: {
         type: Schema.Types.Mixed,
         default: []
+    },
+    // 计算程序标准库
+    program_lib: {
+        type: Schema.Types.Mixed,
+        default: []
     }
 };
 let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));

+ 28 - 1
web/users/js/compilation.js

@@ -139,6 +139,10 @@ $(document).ready(function() {
                 $("#artificial-area").show();
                 $("#add-compilation-title").text('添加人工系数');
                 break;
+            case 'program':
+                $("#program-area").show();
+                $("#add-compilation-title").text('添加计算程序');
+                break;
         }
 
         $("#addcompilation").modal('show');
@@ -156,7 +160,7 @@ $(document).ready(function() {
     });
 
     // 移除操作
-    $(".bill-list, .ration-list, .glj-list, .fee-list").on("click", ".remove-lib", function() {
+    $(".bill-list, .ration-list, .glj-list, .fee-list, .artificial-list, .program-list").on("click", ".remove-lib", function() {
         $(this).parent().remove();
     });
 
@@ -235,6 +239,7 @@ function initCompilation() {
     let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
     let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
     let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
+    let programData = programList === undefined ? [] : JSON.parse(programList);
 
     mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
     billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
@@ -295,6 +300,14 @@ function initCompilation() {
     }
     $("select[name='artificial_lib']").children("option").first().after(html);
 
+    // 计算程序标准库
+    html = '';
+    for(let tmp of programData) {
+        let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
+        html += tmpHtml;
+    }
+    $("select[name='program_lib']").children("option").first().after(html);
+
 }
 
 /**
@@ -310,6 +323,7 @@ function getAndValidData(model) {
     let gljLib = $("select[name='glj_lib']").children("option:selected").val();
     let feeLib = $("select[name='fee_lib']").children("option:selected").val();
     let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
+    let programLib = $("select[name='program_lib']").children("option:selected").val();
 
     if (name === '' && model === 'all') {
         throw '编办名字不能为空';
@@ -335,11 +349,16 @@ function getAndValidData(model) {
         throw '请选择费率库';
     }
 
+    if (model === 'program' && (programLib === '' || programLib === undefined)) {
+        throw '请选择计算程序';
+    }
+
     let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
     let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
     let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
     let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
     let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
+    let programString = $("select[name='program_lib']").children("option:selected").text();
 
     let result = {
         name: name,
@@ -362,6 +381,10 @@ function getAndValidData(model) {
         artificial: {
             id: artificialLib,
             name: artificialString
+        },
+        program: {
+            id: programLib,
+            name: programString
         }
     };
     return result;
@@ -405,6 +428,10 @@ function validLib() {
             throw '请添加人工系数';
         }
 
+        if ($("input:hidden[name='program_lib']").length <= 0) {
+            throw '请添加计算程序';
+        }
+
         result = true;
     } catch (error) {
         alert(error);

+ 18 - 0
web/users/views/compilation/engineering.html

@@ -106,6 +106,23 @@
                                 </div>
                                 <a href="#" class="btn btn-link btn-sm add-compilation" data-model="artificial">添加</a>
                             </div>
+                            <div class="form-group col-md-4">
+                                <label>计算程序</label>
+                                <div class="program-list">
+                                    <% if (Object.keys(libData).length > 0 && libData.program_lib.length > 0) { %>
+                                    <% libData.program_lib.forEach(function (program, index){ %>
+                                    <p class="form-control-static">
+                                        <a class="pull-right text-danger remove-lib" data-model="program" title="移除" data-id="<%= program.id %>">
+                                            <span class="glyphicon glyphicon-remove"></span>
+                                        </a>
+                                        <input type="hidden" name="program_lib" data-id="<%= program.id %>" value="<%= JSON.stringify({id: program.id, name: program.name}) %>">
+                                        <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= program.name %>
+                                    </p>
+                                    <% }) %>
+                                    <% } %>
+                                </div>
+                                <a href="#" class="btn btn-link btn-sm add-compilation" data-model="program">添加</a>
+                            </div>
                         </div>
                     </div>
                     <div class="col-md-12">
@@ -131,6 +148,7 @@
     let gljList = '<%- gljList %>';
     let feeRateList = '<%- feeRateList %>';
     let artificialCoefficientList = '<%- artificialCoefficientList %>';
+    let programList = '<%- calculationList %>';
     let mainTreeCol = '<%- mainTreeCol %>';
     let billsTemplateData = '<%- billsTemplateData %>';
     let colSpread = null;

+ 10 - 0
web/users/views/compilation/modal.html

@@ -61,6 +61,16 @@
                         </div>
                     </div>
                 </div>
+                <div class="form-group" id="program-area">
+                    <label>计算程序</label>
+                    <div class="row">
+                        <div class="col-xs-12">
+                            <select class="form-control" name="program_lib">
+                                <option value="">请选择计算程序</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>