Browse Source

编办管理新增费率列表

olym 7 years ago
parent
commit
8f807cd88b

+ 56 - 0
modules/common/std/schemas/std_fee_rate_libs.js

@@ -0,0 +1,56 @@
+/**
+ * 费率标准库数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/8/30
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'std_fee_rate_libs';
+
+let optionSchema = new Schema({
+    name:String,
+    value:String,
+    selected:Boolean
+}, {_id: false});
+
+let recordSchema = new Schema({
+    ID:Number,
+    name:String,
+    optionList:[optionSchema]
+}, {_id: false});
+
+let valueMapSchema = new Schema({
+    ID:String,
+    value:Number
+}, {_id: false});
+
+let subFeeRatesSchema = new Schema({
+    recodes :[recordSchema],
+    valueMaps:[valueMapSchema],
+}, {_id: false});
+
+let ratesSchema = new Schema({
+    ID: Number,
+    ParentID: Number,
+    name: String,
+    rate: Number,
+    memo: String,
+    subFeeRate:subFeeRatesSchema
+}, {_id: false});
+
+let modelSchema = {
+    // 自增id
+    ID: String,
+    // 工程所在地
+    region: String,
+    // 标准名称
+    libName: String,
+    // 费率数据
+    rates: [ratesSchema]
+};
+
+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_fee_rate_libs_model.js

@@ -0,0 +1,50 @@
+/**
+ * 费率文件标准库业务逻辑
+ *
+ * @author CaiAoLin
+ * @date 2017/8/30
+ * @version
+ */
+import BaseModel from "../base/base_model";
+import STDFeeRateLibsSchema from "./schemas/std_fee_rate_libs";
+
+class STDFeeRateLibsModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = STDFeeRateLibsSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取费率列表
+     *
+     * @return {Promise}
+     */
+    async getFeeRateList() {
+        let result = [];
+        let field = {ID: 1, libName: 1};
+        let feeRateList = await this.findDataByCondition({ID: {$ne: ''}}, field, false);
+
+        if (feeRateList === null) {
+            return result;
+        }
+        // 整理数据
+        for(let feeRate of feeRateList) {
+            let tmpData = {
+                id: feeRate.ID,
+                name: feeRate.libName
+            };
+            result.push(tmpData);
+        }
+        return result;
+    }
+
+}
+
+export default STDFeeRateLibsModel;

+ 4 - 3
modules/templates/models/bills_template_model.js

@@ -48,11 +48,12 @@ class BillsTemplateModel extends BaseModel {
             for (let data of datas) {
                 data.valuationId = valuationId;
                 let condition = {valuationId: valuationId, ID: data.data.ID}, result;
-                if (data.updateType === 'update') {
+                if (data.type === 'update') {
+                    console.log('test');
                     result = await this.db.update(condition, data.data);
-                } else if (data.updateType === 'new') {
+                } else if (data.type === 'new') {
                     result = await this.db.create(data.data);
-                } else if (data.updateType === 'delete') {
+                } else if (data.type === 'delete') {
                     result = await this.db.delete(condition);
                 }
                 if (result === undefined || result.ok ===undefined || !result.ok) {

+ 15 - 6
modules/users/controllers/compilation_controller.js

@@ -10,6 +10,7 @@ import CompilationModel from "../models/compilation_model";
 import STDRationLibMapModel from "../../common/std/std_ration_lib_map_model";
 import STDBillLibListsModel from "../../common/std/std_bills_lib_lists_model";
 import STDGLJLibMapModel from "../../common/std/std_glj_lib_map_model";
+import STDFeeRateLibsModel from "../../common/std/std_fee_rate_libs_model";
 import {default as EngineeringConst, List as EngineeringList} from "../../common/const/engineering";
 import BillsTemplateModel from "../../templates/models/bills_template_model";
 
@@ -118,6 +119,7 @@ class CompilationController extends BaseController {
         let valuationList = {};
         let gljList = [];
         let billsTemplateData = [];
+        let feeRateList = [];
         try {
             let compilationModel = new CompilationModel();
             compilationList = await compilationModel.getCompilationList();
@@ -134,6 +136,10 @@ class CompilationController extends BaseController {
             let stdGLJLibMapModel = new STDGLJLibMapModel();
             gljList = await stdGLJLibMapModel.getGLJLibList(selectedCompilation._id);
 
+            // 获取费率库
+            let stdFeeRateLibsModel = new STDFeeRateLibsModel();
+            feeRateList = await stdFeeRateLibsModel.getFeeRateList();
+
             // 获取对应的计价规则数据
             [valuationData, valuationList] = await compilationModel.getValuation(selectedCompilation._id, valuationId, section);
             if (Object.keys(valuationData).length <= 0) {
@@ -153,6 +159,7 @@ class CompilationController extends BaseController {
             billList: JSON.stringify(billList),
             rationList: JSON.stringify(rationList),
             gljList: JSON.stringify(gljList),
+            feeRateList: JSON.stringify(feeRateList),
             mainTreeCol: JSON.stringify(valuationData.main_tree_col),
             billsTemplateData: JSON.stringify(billsTemplateData),
             engineeringList: EngineeringList,
@@ -375,6 +382,7 @@ class CompilationController extends BaseController {
 
     /**
      * 清单模板,更新数据操作
+     *
      * @param request
      * @param response
      */
@@ -382,15 +390,16 @@ class CompilationController extends BaseController {
         let valuationId = request.params.id;
         let section = request.params.section;
         let data = JSON.parse(request.body.data);
-
+        console.log('hello');
         let billsTemplateModel = new BillsTemplateModel();
         let result = await billsTemplateModel.updateTemplate(valuationId, data);
 
-        if (result) {
-            callback(request, response, 0, '', data);
-        } else {
-            callback(request, response, 1, '更新数据错误', null);
-        }
+        // if (result) {
+        //     callback(request, response, 0, '', data);
+        // } else {
+        //     callback(request, response, 1, '更新数据错误', null);
+        // }
+        response.end('success');
     }
 
 }

+ 27 - 21
modules/users/models/compilation_model.js

@@ -123,6 +123,7 @@ class CompilationModel extends BaseModel {
         updateData[sectionString + ".$.bill_lib"] = data.bill_lib;
         updateData[sectionString + ".$.ration_lib"] = data.ration_lib;
         updateData[sectionString + ".$.glj_lib"] = data.glj_lib;
+        updateData[sectionString + ".$.fee_lib"] = data.fee_lib;
         updateData[sectionString + ".$.name"] = data.name;
         updateData[sectionString + ".$.engineering"] = data.engineering;
         updateData[sectionString + ".$.main_tree_col"] = JSON.parse(data.main_tree_col);
@@ -178,35 +179,40 @@ class CompilationModel extends BaseModel {
         }
         data.engineering = parseInt(data.engineering);
         // 判断标准清单
-        if (data.bill_lib === undefined || data.bill_lib === '') {
-            throw '判断标准清单不能为空';
-        }
-        data.bill_lib = data.bill_lib instanceof Array ? data.bill_lib : [data.bill_lib];
-        for(let tmp in data.bill_lib) {
-            data.bill_lib[tmp] = JSON.parse(data.bill_lib[tmp]);
-        }
+        data.bill_lib = this._validLib(data.bill_lib);
+
         // 判断定额库
-        if (data.ration_lib === undefined || data.ration_lib === '') {
-            throw '判断标准清单不能为空';
-        }
-        data.ration_lib = data.ration_lib instanceof Array ? data.ration_lib : [data.ration_lib];
-        for(let tmp in data.ration_lib) {
-            data.ration_lib[tmp] = JSON.parse(data.ration_lib[tmp]);
-        }
+        data.ration_lib = this._validLib(data.ration_lib);
 
         // 判断工料机库
-        if (data.glj_lib === undefined || data.glj_lib === '') {
-            throw '判断工料机库不能为空';
-        }
-        data.glj_lib = data.glj_lib instanceof Array ? data.glj_lib : [data.glj_lib];
-        for(let tmp in data.glj_lib) {
-            data.glj_lib[tmp] = JSON.parse(data.glj_lib[tmp]);
-        }
+        data.glj_lib = this._validLib(data.glj_lib);
+
+        // 判断费率库
+        data.fee_lib = this._validLib(data.fee_lib);
 
         return data;
     }
 
     /**
+     * 校验库数据
+     *
+     * @param {Object} libData
+     * @return {Object}
+     */
+    _validLib(libData) {
+        let result = [];
+        // 判断费率库
+        if (libData === undefined || libData === '') {
+            throw '判断费率库不能为空';
+        }
+        libData = libData instanceof Array ? libData : [libData];
+        for(let tmp in libData) {
+            result[tmp] = JSON.parse(libData[tmp]);
+        }
+        return result;
+    }
+
+    /**
      * 获取计价规则数据
      *
      * @param {String} compilationId

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

@@ -51,6 +51,11 @@ let childrenSchema = new Schema({
             "headRowHeight":[],
             "cols":[]
         }
+    },
+    // 费率标准库
+    fee_lib: {
+        type: Schema.Types.Mixed,
+        default: []
     }
 });
 let modelSchema = {

+ 65 - 34
web/users/js/compilation.js

@@ -24,15 +24,14 @@ $(document).ready(function() {
     // 新增编办
     $("#add-compilation").click(function() {
         try {
-            let [name, standardBill, rationLib, gljLib, standardBillString, rationLibString, gljLibString] = getAndValidData(model);
-
+            let data = getAndValidData(model);
             let url = '/compilation/add';
             if (model === 'all') {
                 // 新增编办操作
                 $.ajax({
                     url: url,
                     type: 'post',
-                    data: {name: name},
+                    data: {name: data.name},
                     error: function() {
                         isAdding = false;
                     },
@@ -52,22 +51,27 @@ $(document).ready(function() {
             } else {
                 // 新增标准清单/定额库
                 let addLib = {
-                    name: '',
-                    id: ''
+                    name: data[model].name,
+                    id: data[model].id
                 };
-                switch (model) {
-                    case 'bill':
-                        addLib.name = standardBillString;
-                        addLib.id = standardBill;
-                        break;
-                    case 'ration':
-                        addLib.name = rationLibString;
-                        addLib.id = rationLib;
-                        break;
-                    case 'glj':
-                        addLib.name = gljLibString;
-                        addLib.id = gljLib;
-                }
+                // switch (model) {
+                //     case 'bill':
+                //         addLib.name = standardBillString;
+                //         addLib.id = standardBill;
+                //         break;
+                //     case 'ration':
+                //         addLib.name = rationLibString;
+                //         addLib.id = rationLib;
+                //         break;
+                //     case 'glj':
+                //         addLib.name = gljLibString;
+                //         addLib.id = gljLib;
+                //         break;
+                //     case 'fee':
+                //         addLib.name = gljLibString;
+                //         addLib.id = gljLib;
+                //         break;
+                // }
                 // 判断是否有重复的数据
                 if ($("input:hidden[name='"+ model +"_lib'][data-id='"+ addLib.id +"']").length > 0) {
                     alert('重复添加数据!');
@@ -127,34 +131,27 @@ $(document).ready(function() {
     // 添加
     $(".add-compilation").click(function() {
         model = $(this).data('model');
+        $("#addcompilation .modal-body > div").hide();
         switch (model) {
             case 'all':
                 $("#name-area").show();
-                $("#bill-area").hide();
-                $("#ration-area").hide();
-                $("#glj-area").hide();
                 $("#add-compilation-title").text('添加新编办');
                 break;
             case 'bill':
-                $("#name-area").hide();
                 $("#bill-area").show();
-                $("#ration-area").hide();
-                $("#glj-area").hide();
                 $("#add-compilation-title").text('添加标准清单');
                 break;
             case 'ration':
-                $("#name-area").hide();
-                $("#bill-area").hide();
                 $("#ration-area").show();
-                $("#glj-area").hide();
                 $("#add-compilation-title").text('添加定额库');
                 break;
             case 'glj':
-                $("#name-area").hide();
-                $("#bill-area").hide();
-                $("#ration-area").hide();
                 $("#glj-area").show();
                 $("#add-compilation-title").text('添加定额库');
+                break;
+            case 'fee':
+                $("#fee-area").show();
+                $("#add-compilation-title").text('添加费率库');
         }
 
         $("#addcompilation").modal('show');
@@ -168,7 +165,7 @@ $(document).ready(function() {
     });
 
     // 移除操作
-    $(".bill-list, .ration-list").on("click", ".remove-lib", function() {
+    $(".bill-list, .ration-list, .glj-list, .fee-list").on("click", ".remove-lib", function() {
         $(this).parent().remove();
     });
 
@@ -245,6 +242,7 @@ function initCompilation() {
     let billListData = billList === undefined ? [] : JSON.parse(billList);
     let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
     let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
+    let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
 
     if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
         return false;
@@ -280,19 +278,28 @@ function initCompilation() {
     }
     $("select[name='glj_lib']").children("option").first().after(html);
 
+    // 费率库
+    html = '';
+    for(let tmp of feeLibData) {
+        let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
+        html += tmpHtml;
+    }
+    $("select[name='fee_lib']").children("option").first().after(html);
+
 }
 
 /**
  * 校验数据
  *
  * @param {String} model
- * @return {Array}
+ * @return {Object}
  */
 function getAndValidData(model) {
     let name = $("input[name='compilation_name']").val();
     let standardBill = $("select[name='standard_bill']").children("option:selected").val();
     let rationLib = $("select[name='ration_lib']").children("option:selected").val();
     let gljLib = $("select[name='glj_lib']").children("option:selected").val();
+    let feeLib = $("select[name='fee_lib']").children("option:selected").val();
 
     if (name === '' && model === 'all') {
         throw '编办名字不能为空';
@@ -310,11 +317,35 @@ function getAndValidData(model) {
         throw '请选择工料机库';
     }
 
+    if (model === 'fee' && (feeLib === '' || feeLib === 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();
-
-    return [name, standardBill, rationLib, gljLib, standardBillString, rationLibString, gljLibString];
+    let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
+
+    let result = {
+        name: name,
+        standardBill: {
+            id: standardBill,
+            name: standardBillString
+        },
+        ration: {
+            id: rationLib,
+            name: rationLibString
+        },
+        glj: {
+            id: gljLib,
+            name: gljLibString
+        },
+        fee: {
+            id: feeLib,
+            name: feeLibString
+        }
+    };
+    return result;
 }
 
 /**

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

@@ -100,6 +100,23 @@
                             </div>
                             <a href="#" class="btn btn-link btn-sm add-compilation" data-model="glj">添加</a>
                         </div>
+                        <div class="form-group">
+                            <label>费率库</label>
+                            <div class="fee-list">
+                                <% if (valuationData.fee_lib.length > 0) { %>
+                                <% valuationData.fee_lib.forEach(function (fee, index){ %>
+                                <p class="form-control-static">
+                                    <a class="pull-right text-danger remove-lib" data-model="fee" title="移除" data-id="<%= fee.id %>">
+                                        <span class="glyphicon glyphicon-remove"></span>
+                                    </a>
+                                    <input type="hidden" name="fee_lib" data-id="<%= fee.id %>" value="<%= JSON.stringify({id: fee.id, name: fee.name}) %>">
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= fee.name %>
+                                </p>
+                                <% }) %>
+                                <% } %>
+                            </div>
+                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="fee">添加</a>
+                        </div>
                     </div>
                     <div class="col-md-8">
                         <legend>
@@ -123,6 +140,7 @@
     let gljList = '<%- gljList %>';
     let mainTreeCol = '<%- mainTreeCol %>';
     let billsTemplateData = '<%- billsTemplateData %>';
+    let feeRateList = '<%- feeRateList %>';
     let colSpread = null;
     let colEditSpread = null;
 </script>

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

@@ -41,6 +41,16 @@
                         </div>
                     </div>
                 </div>
+                <div class="form-group" id="fee-area">
+                    <label>费率库</label>
+                    <div class="row">
+                        <div class="col-xs-12">
+                            <select class="form-control" name="fee_lib">
+                                <option value="">请选择费率库</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>