瀏覽代碼

编办管理添加工料机库相关

caiaolin 7 年之前
父節點
當前提交
310ecc82a3

+ 36 - 0
modules/common/std/schemas/std_glj_lib_map.js

@@ -0,0 +1,36 @@
+/**
+ * 工料机库数据模型
+ *
+ * @author CaiAoLin
+ * @date 2017/8/16
+ * @version
+ */
+import mongoose from "mongoose";
+
+let Schema = mongoose.Schema;
+let collectionName = 'std_glj_lib_map';
+let modelSchema = {
+    // 显示名称
+    dispName: String,
+    // 类型
+    appType: String,
+    // 是否被删除标记
+    deleted: Boolean,
+    // 自增ID
+    ID: Number,
+    // 创建时间
+    createDate: String,
+    // 创建者
+    creator: String,
+    // 最近一次操作
+    recentOpr: Schema.Types.Mixed,
+    // 编办id
+    compilationId: String,
+    // 编办名称
+    compilationName: String,
+    // 定额库
+    rationLibs: Schema.Types.Mixed
+};
+
+let model = mongoose.model(collectionName, new Schema(modelSchema, {versionKey: false, collection: collectionName}));
+export {model as default, collectionName as collectionName};

+ 55 - 0
modules/common/std/std_glj_lib_map_model.js

@@ -0,0 +1,55 @@
+/**
+ * 工料机库业务逻辑
+ *
+ * @author CaiAoLin
+ * @date 2017/8/16
+ * @version
+ */
+import BaseModel from "../../common/base/base_model";
+import STDGLJLibMapSchema from "./schemas/std_glj_lib_map";
+
+class STDGLJLibMapModel extends BaseModel {
+
+    /**
+     * 构造函数
+     *
+     * @return {void}
+     */
+    constructor() {
+        let parent = super();
+        parent.model = STDGLJLibMapSchema;
+        parent.init();
+    }
+
+    /**
+     * 获取对应的工料机库
+     *
+     * @param {String} compilationId
+     * @return {Promise}
+     */
+    async getGLJLibList(compilationId) {
+        let result = [];
+        let gliLib = await this.findDataByCondition({deleted: false, compilationId: compilationId.toString()}, null, false);
+
+        if (gliLib.length <= 0) {
+            return result;
+        }
+
+        // 整理数据
+        let gljList = [];
+        for(let tmp of gliLib) {
+            let tmpRation = {id: tmp.ID, name: tmp.dispName};
+            if (gljList.length <= 0) {
+                gljList = [tmpRation];
+            } else {
+                gljList.push(tmpRation);
+            }
+        }
+
+        result = gljList;
+        return result;
+    }
+
+}
+
+export default STDGLJLibMapModel;

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

@@ -9,6 +9,7 @@ import BaseController from "../../common/base/base_controller";
 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 {default as EngineeringConst, List as EngineeringList} from "../../common/const/engineering";
 
 class CompilationController extends BaseController {
@@ -114,6 +115,7 @@ class CompilationController extends BaseController {
         let compilationList = [];
         let valuationData = {};
         let valuationList = {};
+        let gljList = [];
         try {
             let compilationModel = new CompilationModel();
             compilationList = await compilationModel.getCompilationList();
@@ -126,6 +128,10 @@ class CompilationController extends BaseController {
             let stdRationLibMapModel = new STDRationLibMapModel();
             rationList = await stdRationLibMapModel.getRationLib(selectedCompilation._id);
 
+            // 获取工料机库
+            let stdGLJLibMapModel = new STDGLJLibMapModel();
+            gljList = await stdGLJLibMapModel.getGLJLibList(selectedCompilation._id);
+
             // 获取对应的计价规则数据
             [valuationData, valuationList] = await compilationModel.getValuation(selectedCompilation._id, valuationId, section);
             if (Object.keys(valuationData).length <= 0) {
@@ -140,6 +146,7 @@ class CompilationController extends BaseController {
             compilationList: compilationList,
             billList: JSON.stringify(billList),
             rationList: JSON.stringify(rationList),
+            gljList: JSON.stringify(gljList),
             engineeringList: EngineeringList,
             selectedCompilation: selectedCompilation,
             valuationData: valuationData,

+ 11 - 1
modules/users/models/compilation_model.js

@@ -122,6 +122,7 @@ class CompilationModel extends BaseModel {
         let updateData = {};
         updateData[sectionString + ".$.bill_lib"] = data.bill_lib;
         updateData[sectionString + ".$.ration_lib"] = data.ration_lib;
+        updateData[sectionString + ".$.glj_lib"] = data.glj_lib;
         updateData[sectionString + ".$.name"] = data.name;
         updateData[sectionString + ".$.engineering"] = data.engineering;
 
@@ -183,7 +184,7 @@ class CompilationModel extends BaseModel {
         for(let tmp in data.bill_lib) {
             data.bill_lib[tmp] = JSON.parse(data.bill_lib[tmp]);
         }
-        // 判断定额清单
+        // 判断定额
         if (data.ration_lib === undefined || data.ration_lib === '') {
             throw '判断标准清单不能为空';
         }
@@ -192,6 +193,15 @@ class CompilationModel extends BaseModel {
             data.ration_lib[tmp] = JSON.parse(data.ration_lib[tmp]);
         }
 
+        // 判断工料机库
+        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]);
+        }
+
         return data;
     }
 

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

@@ -27,6 +27,11 @@ let childrenSchema = new Schema({
         type: Schema.Types.Mixed,
         default: []
     },
+    // 工料机库
+    glj_lib: {
+        type: Schema.Types.Mixed,
+        default: []
+    },
     // 是否启用
     enable: {
         type: Boolean,

+ 30 - 3
web/users/js/compilation.js

@@ -24,7 +24,7 @@ $(document).ready(function() {
     // 新增编办
     $("#add-compilation").click(function() {
         try {
-            let [name, standardBill, rationLib, standardBillString, rationLibString] = getAndValidData(model);
+            let [name, standardBill, rationLib, gljLib, standardBillString, rationLibString, gljLibString] = getAndValidData(model);
 
             let url = '/compilation/add';
             if (model === 'all') {
@@ -64,6 +64,9 @@ $(document).ready(function() {
                         addLib.name = rationLibString;
                         addLib.id = rationLib;
                         break;
+                    case 'glj':
+                        addLib.name = gljLibString;
+                        addLib.id = gljLib;
                 }
                 // 判断是否有重复的数据
                 if ($("input:hidden[name='"+ model +"_lib'][data-id='"+ addLib.id +"']").length > 0) {
@@ -129,20 +132,29 @@ $(document).ready(function() {
                 $("#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('添加定额库');
         }
 
         $("#addcompilation").modal('show');
@@ -232,8 +244,9 @@ $(document).ready(function() {
 function initCompilation() {
     let billListData = billList === undefined ? [] : JSON.parse(billList);
     let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
+    let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
 
-    if (billListData.length <= 0 || rationLibData.length <= 0) {
+    if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
         return false;
     }
     // 标准清单
@@ -252,6 +265,14 @@ function initCompilation() {
     }
     $("select[name='ration_lib']").children("option").first().after(html);
 
+    // 工料机库
+    html = '';
+    for(let tmp of gljLibData) {
+        let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
+        html += tmpHtml;
+    }
+    $("select[name='glj_lib']").children("option").first().after(html);
+
 }
 
 /**
@@ -264,6 +285,7 @@ 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();
 
     if (name === '' && model === 'all') {
         throw '编办名字不能为空';
@@ -277,10 +299,15 @@ function getAndValidData(model) {
         throw '请选择定额库';
     }
 
+    if (model === 'glj' && (gljLib === '' || gljLib === 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, standardBillString, rationLibString];
+    return [name, standardBill, rationLib, gljLib, standardBillString, rationLibString, gljLibString];
 }
 
 /**

+ 22 - 4
web/users/views/compilation/add.html

@@ -53,13 +53,13 @@
                             <label>标准清单</label>
                             <div class="bill-list">
                                 <% if (valuationData.bill_lib.length > 0) { %>
-                                <% valuationData.bill_lib.forEach(function (bill){ %>
+                                <% valuationData.bill_lib.forEach(function (bill, index){ %>
                                 <p class="form-control-static">
                                     <a class="pull-right text-danger remove-lib" data-model="bill" title="移除">
                                         <span class="glyphicon glyphicon-remove"></span>
                                     </a>
                                     <input type="hidden" name="bill_lib" data-id="<%= bill.id %>" value="<%= JSON.stringify({id: bill.id, name: bill.name}) %>">
-                                    <%= bill.name %>
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= bill.name %>
                                 </p>
                                 <% }) %>
                                 <% } %>
@@ -70,19 +70,36 @@
                             <label>定额库</label>
                             <div class="ration-list">
                                 <% if (valuationData.ration_lib.length > 0) { %>
-                                <% valuationData.ration_lib.forEach(function (ration){ %>
+                                <% valuationData.ration_lib.forEach(function (ration, index){ %>
                                 <p class="form-control-static">
                                     <a class="pull-right text-danger remove-lib" data-model="ration" title="移除" data-id="<%= ration.id %>">
                                         <span class="glyphicon glyphicon-remove"></span>
                                     </a>
                                     <input type="hidden" name="ration_lib" data-id="<%= ration.id %>" value="<%= JSON.stringify({id: ration.id, name: ration.name}) %>">
-                                    <%= ration.name %>
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= ration.name %>
                                 </p>
                                 <% }) %>
                                 <% } %>
                             </div>
                             <a href="#" class="btn btn-link btn-sm add-compilation" data-model="ration">添加</a>
                         </div>
+                        <div class="form-group">
+                            <label>工料机库</label>
+                            <div class="glj-list">
+                                <% if (valuationData.glj_lib.length > 0) { %>
+                                <% valuationData.glj_lib.forEach(function (glj, index){ %>
+                                <p class="form-control-static">
+                                    <a class="pull-right text-danger remove-lib" data-model="glj" title="移除" data-id="<%= glj.id %>">
+                                        <span class="glyphicon glyphicon-remove"></span>
+                                    </a>
+                                    <input type="hidden" name="glj_lib" data-id="<%= glj.id %>" value="<%= JSON.stringify({id: glj.id, name: glj.name}) %>">
+                                    <% if (index === 0) {%><i class="glyphicon glyphicon-flag"></i>&nbsp;<% } %><%= glj.name %>
+                                </p>
+                                <% }) %>
+                                <% } %>
+                            </div>
+                            <a href="#" class="btn btn-link btn-sm add-compilation" data-model="glj">添加</a>
+                        </div>
                     </div>
                     <div class="col-md-8">
                         <legend>造价书列设置<a href="javascript:void(0)" data-toggle="modal" data-target="#set-column" class="btn btn-primary btn-sm pull-right">设置</a></legend>
@@ -100,6 +117,7 @@
 <script type="text/javascript">
     let billList = '<%- billList %>';
     let rationList = '<%- rationList %>';
+    let gljList = '<%- gljList %>';
 </script>
 <script type="text/javascript" src="/web/users/js/compilation.js"></script>
 <%include ../compilation/modal.html %>

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

@@ -31,6 +31,16 @@
                         </div>
                     </div>
                 </div>
+                <div class="form-group" id="glj-area">
+                    <label>工料机库</label>
+                    <div class="row">
+                        <div class="col-xs-12">
+                            <select class="form-control" name="glj_lib">
+                                <option value="">请选择工料机库</option>
+                            </select>
+                        </div>
+                    </div>
+                </div>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>