Selaa lähdekoodia

新增"清单估算指标库"功能

TonyKang 3 vuotta sitten
vanhempi
commit
18b35a9278

+ 35 - 0
modules/all_models/bills_unitprice_feature_lib.js

@@ -0,0 +1,35 @@
+/**
+ * Created by Tony on 2021/9/10.
+ */
+
+//工程特征库
+const mongoose = require('mongoose');
+const Schema = mongoose.Schema;
+const oprSchema = require('../all_schemas/opr_schema');
+const project_feature_lib = new Schema({
+        ID:{type:String,index:true},
+        creator: String,
+        createDate: Number,
+        recentOpr: [oprSchema],
+        name: String,
+        compilationId: String,
+        compilationName: String,
+        feature: {
+            basicKeyOptions: {
+                type: [Schema.Types.Mixed],
+                default: []
+            },
+            basicMappings:{
+                type: [Schema.Types.Mixed],
+                default: []
+            },
+            factorMappings: {
+                type: [Schema.Types.Mixed],
+                default: []
+            }
+        }
+    },
+    {versionKey: false}
+);
+
+mongoose.model("std_bills_unitprice_feature_lib", project_feature_lib,"std_bills_unitprice_feature_lib");

+ 112 - 0
modules/std_bills_unitprice_feature_lib/controllers/bills_unitprice_feature_controller.js

@@ -0,0 +1,112 @@
+/**
+ * Created by Tony on 2021/9/10.
+ */
+
+import BaseController from "../../common/base/base_controller";
+import featureFacade from "../facade/bills_unitprice_feature_facade";
+let config = require("../../../config/config.js");
+import CompilationModel from '../../users/models/compilation_model';
+
+class BillsUnitPriceFeatureController extends BaseController{
+    async main(request, response) {
+        let compilationModel = new CompilationModel();
+        let compilationList = await compilationModel.getCompilationList({_id: 1, name: 1});
+        compilationList.unshift({_id: 'all', name: '所有'});
+        let activeCompilation = compilationList.find(compilation => compilation._id.toString() === request.query.filter);
+        if (activeCompilation) {
+            activeCompilation.active = 'active';
+        } else {
+            compilationList[0].active = 'active'
+        }
+        let filter = request.query.filter ? {compilationId: request.query.filter} : {};
+        let featureLibs = await featureFacade.findByCondition(filter,{feature:0},false);
+        let randerData = {
+            title:'清单估算指标库',
+            userAccount: request.session.managerData.username,
+            userID: request.session.managerData.userID,
+            featureLibs:featureLibs,
+            compilationList: compilationList,
+            layout: 'maintain/common/html/layout'
+        };
+        response.render("maintain/bills_unitprice_feature_lib/html/main", randerData);
+    }
+    async addLib(request, response){
+        try {
+            await featureFacade.addLib(request.body);
+        }catch (error) {
+            console.log(error);
+        }
+        response.redirect(request.headers.referer);
+    }
+    async findLib(request, response){
+        let result={
+            error:0
+        };
+        try {
+            let data = request.body.data;
+            data = JSON.parse(data);
+            let conditions={'ID' : data.ID};
+            let resultData = await featureFacade.findByCondition(conditions);
+            result.data=resultData;
+        }catch (err){
+            console.log(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        response.json(result);
+    }
+    async saveLib(request, response){
+        let result={
+            error:0
+        };
+        try {
+            let data = request.body.data;
+            data = JSON.parse(data);
+            let resultData= await featureFacade.saveLib(data);
+            result.data=resultData;
+        }catch (err){
+            console.log(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        response.json(result);
+    }
+    async deleteLibByID(request,response){
+        let result={
+            error:0
+        };
+        try {
+            let data = request.body.data;
+            data = JSON.parse(data);
+            let resultData= await featureFacade.deleteLibByID(data.ID);
+            result.data=resultData;
+        }catch (err){
+            console.log(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        response.json(result);
+    }
+    async edit(request,response){
+        //先取出替换库信息:
+        let libID = request.params.libID;
+        let featureLib = await featureFacade.findByCondition({'ID':libID});
+        if(featureLib){
+            let randerData = {
+                title:'清单估算指标库',
+                mainURL:'/billsUnitPriceFeature/main',
+                libName:featureLib.name,
+                userAccount: request.session.managerData.username,
+                userID: request.session.managerData.userID,
+                featureList:JSON.stringify(featureLib.feature),
+                libID:libID,
+                LicenseKey:config.getLicenseKey(process.env.NODE_ENV),
+                layout: 'maintain/common/html/edit_layout'
+            };
+            response.render("maintain/bills_unitprice_feature_lib/html/edit", randerData);
+        }else {
+            response.redirect(request.headers.referer);
+        }
+    }
+}
+export default BillsUnitPriceFeatureController;

+ 47 - 0
modules/std_bills_unitprice_feature_lib/facade/bills_unitprice_feature_facade.js

@@ -0,0 +1,47 @@
+/**
+ * Created by Tony on 2021/9/10.
+ */
+
+import mongoose from "mongoose";
+const uuidV1 = require('uuid/v1');
+let moment = require("moment");
+let billsUnitPriceFeatureModel = mongoose.model('std_bills_unitprice_feature_lib');
+let compilationModel = mongoose.model('compilation');
+
+let projectFeatureLib = {
+    findByCondition:async function(conditions,options,single=true){
+        if(single == true){
+            return await billsUnitPriceFeatureModel.findOne(conditions,options);
+        }else {
+            return await  billsUnitPriceFeatureModel.find(conditions,options);
+        }
+    },
+    addLib : async function (data){
+        let now = new Date().getTime();
+        let dateStr = moment(now).format('YYYY-MM-DD HH:mm:ss');
+        //取编办信息
+        let compilation = await compilationModel.findOne({_id:data.compilationId});
+        if(compilation){
+            let newLib = {
+                creator: data.userAccount,
+                createDate: now,
+                recentOpr: [{operator: data.userAccount, operateDate: dateStr}],
+                name: data.name,
+                compilationId: data.compilationId,
+                compilationName: compilation.name,
+            };
+            newLib.ID = uuidV1();
+            return await billsUnitPriceFeatureModel.create(newLib);
+        }else {
+            throw  new Error("没有找到该编办!");
+        }
+    },
+    saveLib:async function(param) {
+        return await billsUnitPriceFeatureModel.findOneAndUpdate(param.query,param.data,{new:true});
+    },
+    deleteLibByID:async function(ID){
+        return await billsUnitPriceFeatureModel.deleteOne({ID:ID});
+    },
+};
+
+export default projectFeatureLib

+ 19 - 0
modules/std_bills_unitprice_feature_lib/routes/bills_unitprice_feature_router.js

@@ -0,0 +1,19 @@
+/**
+ * Created by Tony on 2021/9/10.
+ */
+
+let express = require("express");
+let featureRouter =express.Router();
+import FeatureController from "../controllers/bills_unitprice_feature_controller";
+let featureController = new FeatureController();
+
+module.exports =function (app){
+
+    featureRouter.get("/main", featureController.auth, featureController.init, featureController.main);
+    featureRouter.post("/addLib", featureController.auth, featureController.init, featureController.addLib);
+    featureRouter.post("/findLib", featureController.auth, featureController.init, featureController.findLib);
+    featureRouter.post("/saveLib", featureController.auth, featureController.init, featureController.saveLib);
+    featureRouter.post("/deleteLibByID", featureController.auth, featureController.init, featureController.deleteLibByID);
+    featureRouter.get("/edit/:libID", featureController.auth, featureController.init, featureController.edit);
+    app.use("/billsUnitPriceFeature", featureRouter);
+};

+ 32 - 0
web/maintain/bills_unitprice_feature_lib/html/edit.html

@@ -0,0 +1,32 @@
+<nav class="navbar navbar-toggleable-lg justify-content-between navbar-light p-0 second_header">
+    <ul class="nav nav-tabs" role="tablist">
+        <li class="nav-item">
+            <a class="nav-link active px-3" href="javascript: void(0);">清单估算指标</a>
+        </li>
+    </ul>
+</nav>
+
+<div class="main">
+    <div class="content" >
+        <div class="container-fluid" >
+            <div class=" col-lg-12 p-0">
+                <nav class="navbar sticky-top navbar-toggleable-md navbar-light bg-faded tools-bar">
+                    <div class="collapse navbar-collapse" id="navbarNav">
+                        <div class="tools-btn btn-group align-top">
+                            <a href="javascript:void(0)" class="btn btn-sm lock-btn-control" id="createNormal"><i class="fa fa-list-alt" aria-hidden="true"></i> 生成默认</a>
+                            <a href="javascript:void(0)" class="btn btn-sm lock-btn-control" id="format"><i class="fa fa-list-alt" aria-hidden="true"></i> 校验格式</a>
+                            <a href="javascript:void(0)" class="btn btn-sm lock-btn-control" id="save"><i class="fa fa-floppy-o" aria-hidden="true"></i> 保存</a>
+                        </div>
+                    </div>
+                </nav>
+                <textarea class="form-control lock-text-control" id="featureList" rows="38"></textarea>
+            </div>
+        </div>
+        <input type="hidden" id="libID" value="<%= libID %>">
+        <input type="hidden" id="originalFeature" value="<%= featureList %>">
+    </div>
+</div>
+
+<script type="text/javascript" src="/lib/json/json2.js"></script>
+<script src="/public/web/lock_util.js"></script>
+<script type="text/javascript" src="/web/maintain/bills_unitprice_feature_lib/js/bills_unitprice_feature_edit.js"></script>

+ 150 - 0
web/maintain/bills_unitprice_feature_lib/html/main.html

@@ -0,0 +1,150 @@
+<div class="main">
+    <div class="content">
+        <div class="container-fluid">
+            <div class="row">
+                <div class="col-md-2">
+                    <div class="list-group mt-3">
+                        <% for (let compilation of compilationList) { %>
+                        <% if (compilation._id === 'all') { %>
+                        <a href="/billsUnitPriceFeature/main"
+                           class="list-group-item list-group-item-action <%= compilation.active %>">
+                            所有
+                        </a>
+                        <% } else { %>
+                        <a id="<%= compilation._id %>" href="/billsUnitPriceFeature/main?filter=<%= compilation._id %>"
+                           class="list-group-item list-group-item-action <%= compilation.active %>">
+                            <%= compilation.name %>
+                        </a>
+                        <% }} %>
+                    </div>
+                </div>
+                <div class="col-md-10">
+                    <div class="warp-p2 mt-3">
+                        <table class="table table-hover table-bordered">
+                            <thead>
+                            <tr>
+                                <th>库名称</th>
+                                <th width="160">费用定额</th>
+                                <th width="160">添加时间</th>
+                                <th width="70">操作</th>
+                            </tr>
+                            </thead>
+                            <tbody id="showArea">
+                            <% for(let lib of featureLibs){ %>
+                            <tr class="libTr">
+                                <td id="<%= lib.ID%>"><a
+                                        href="/billsUnitPriceFeature/edit/<%= lib.ID%>?locked=true"><%= lib.name%></a></td>
+                                <td><%= lib.compilationName%></td>
+                                <td><%= moment(lib.createDate).format('YYYY-MM-DD')%></td>
+                                <td>
+                                    <a class="lock-btn-control disabled" href="javascript:void(0);"
+                                       style="color: #0275d8" onclick='getFeatureLib("<%= lib.ID%>")' title="编辑"><i
+                                            class="fa fa-pencil-square-o"></i></a>
+                                    <a class="text-danger lock-btn-control disabled" href="javascript:void(0);"
+                                       onclick='showDeleteModal("<%= lib.ID%>")' title="删除"><i
+                                            class="fa fa-remove"></i></a>
+                                    <a class="lock" data-locked="true" href="javascript:void(0);" title="解锁"><i
+                                            class="fa fa-unlock-alt"></i></a>
+                                </td>
+                            </tr>
+                            <% } %>
+                            </tbody>
+                        </table>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+
+<!--弹出添加-->
+<div class="modal fade" id="add" data-backdrop="static" style="display: none;" aria-hidden="true">
+    <div class="modal-dialog" 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">×</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form id="addLibForm" method="post" action="/billsUnitPriceFeature/addLib"
+                      enctype="application/x-www-form-urlencoded21">
+                    <div class="form-group">
+                        <label>库名称</label>
+                        <input id="name" name="name" class="form-control" placeholder="请输入指标库名称" type="text">
+                        <small class="form-text text-danger" id="nameError" style="display: none">请输入指标库名称。</small>
+                    </div>
+                    <div class="form-group">
+                        <label>编办名称</label>
+                        <select class="form-control" name="compilationId">
+                            <% for (let compilation of compilationList) { %>
+                            <% if (compilation.name !== '所有') { %>
+                            <option value="<%= compilation._id %>"><%= compilation.name %></option>
+                            <% }} %>
+                        </select>
+                    </div>
+                    <input type="hidden" name="userAccount" value="<%= userAccount%>">
+                </form>
+            </div>
+            <div class="modal-footer">
+                <button id="addLibs" class="btn btn-primary">新建</button>
+                <button type="button" id="cancelBtn" class="btn btn-secondary" data-dismiss="modal">取消</button>
+            </div>
+        </div>
+    </div>
+</div>
+
+<!--弹出编辑-->
+<div class="modal fade" id="edit" data-backdrop="static" style="display: none;" aria-hidden="true">
+    <div class="modal-dialog" 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">×</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <form>
+                    <div class="form-group">
+                        <label>清单估算指标库名称</label>
+                        <input id="renameText" class="form-control" placeholder="输入名称" type="text" value="">
+                        <small class="form-text text-danger" id="renameError" style="display: none">请输入名称。</small>
+                        <input id="libID" type="hidden">
+                    </div>
+                </form>
+            </div>
+            <div class="modal-footer">
+                <a id="rename" href="javascript: void(0);" class="btn btn-primary">确定</a>
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+            </div>
+        </div>
+    </div>
+</div>
+
+<!--弹出删除-->
+<div class="modal fade" id="del" data-backdrop="static" style="display: none;" aria-hidden="true">
+    <div class="modal-dialog" 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">×</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                <h5 class="text-danger">删除后无法恢复,确认是否删除?</h5>
+                <input type="hidden" id="libID_del">
+                <input type="hidden" id="delCount">
+            </div>
+            <div class="modal-footer">
+                <a id="delete" href="javascript:void(0);" class="btn btn-danger">确认</a>
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+            </div>
+        </div>
+    </div>
+</div>
+
+<script src="/public/web/lock_util.js"></script>
+<script type="text/javascript" src="/web/maintain/bills_unitprice_feature_lib/js/bills_unitprice_feature.js"></script>

+ 81 - 0
web/maintain/bills_unitprice_feature_lib/js/bills_unitprice_feature.js

@@ -0,0 +1,81 @@
+/**
+ * Created by Tony on 2021/9/10.
+ */
+
+$(document).ready(function() {
+    // 保存按钮
+    $("#addLibs").click(async function() {
+        let name = $('#name').val();
+        if(name==''){
+            $("#nameError").show();
+            return;
+        }else {
+            $("#addLibs").attr("disabled",true);//防止重复提交
+            $("#addLibForm").submit();
+        }
+    });
+
+    $("#rename").click(async function() {
+        let libID = $("#libID").val();
+        let name = $('#renameText').val();
+        if(libID!=''){
+            if(name ==''){
+                $("#renameError").show();
+                return;
+            }else {
+                try {
+                    let newFeature = await ajaxPost("/billsUnitPriceFeature/saveLib",{query:{ID:libID},data:{name:name}});
+                    $("#"+libID).children("a").text(newFeature.name);
+                    $("#edit").modal('hide');
+                }catch(err) {
+                    console.log(err);
+                }
+            }
+        }
+    });
+
+    $("#delete").click(async function() {
+        let libID = $("#libID_del").val();
+        let delCount = parseInt($("#delCount").val());
+        delCount = delCount+1;
+        $("#delCount").val(delCount);
+        if(delCount == 3){
+            if(libID!=""){
+                try {
+                    let result = await ajaxPost("/billsUnitPriceFeature/deleteLibByID",{ID:libID});
+                    if(result.ok){
+                        $("#"+libID).parent(".libTr").remove();
+                    }
+                    $("#del").modal('hide');
+                }catch (err){
+                    console.log(err);
+                }
+            }
+        }
+    });
+    // 锁定、解锁
+    $('.lock').click(function () {
+        lockUtil.handleLockClick($(this));
+    });
+});
+
+async function getFeatureLib (ID) {
+    try {
+        let lib = await ajaxPost("/billsUnitPriceFeature/findLib",{ID:ID});
+        if(lib){
+            $("#renameText").val(lib.name);
+            $("#libID").val(ID);
+            $("#edit").modal({show:true});
+        }else {
+            alert("没有找到材料库");
+        }
+    }catch (err){
+        console.log(err);
+    }
+}
+
+function showDeleteModal(ID){
+    $("#libID_del").val(ID);
+    $("#delCount").val(0);
+    $("#del").modal({show:true});
+}

+ 88 - 0
web/maintain/bills_unitprice_feature_lib/js/bills_unitprice_feature_edit.js

@@ -0,0 +1,88 @@
+/**
+ * Created by Tony on 2021/9/11.
+ */
+
+$(document).ready(function () {
+    const locked = lockUtil.getLocked();
+    lockUtil.lockTools($(document.body), locked);
+    try {
+        let tem = sortJson(JSON.parse($("#originalFeature").val()));
+        $("#featureList").val(JSON.stringify(tem,null,4));
+    }catch (err){
+        console.log(err);
+    }
+
+    $("#format").click( function() {
+        try {
+            let jsonText =  $("#featureList").val();
+            $("#featureList").val(JSON.stringify(JSON.parse(jsonText),null,4));
+        }catch (err){
+            console.log(err);
+            alert("输入的JSON格式有误,请重新输入!");
+        }
+    });
+    $("#save").click(async function() {
+        try {
+            let libID = $("#libID").val();
+            let jsonText =  $("#featureList").val();
+            if(jsonText.indexOf("'")!=-1){
+                alert("输入的格式不能包含 ' 位于:"+jsonText.substr(jsonText.indexOf("'")-15,18));
+                return;
+            }
+            let newFeature = await ajaxPost("/billsUnitPriceFeature/saveLib",{query:{ID:libID},data:{feature:JSON.parse(jsonText)}});
+        }catch (err){
+            console.log(err);
+            alert("保存失败,请查看输入数据");
+        }
+    });
+    $("#createNormal").click(async function() {
+        let projectFeature = {
+            "basicKeyOptions": [
+                { type: "bills", key: "code" },
+                { type: "bills", key: "name" },
+                { type: "bills", key: "unit" }
+            ],
+            "basicMappings": [
+                {
+                    parentBasicKeys: ["2010101", "路基保洁", "路基公里"],
+                    subs: [
+                        {
+                            keys: [ { type: "prjFeature", key: "lanes", value: "双向四车道" } ],
+                            basicValue: 539.00
+                        },
+                        {
+                            keys: [ { type: "prjFeature", key: "lanes", value: "双向六车道" } ],
+                            basicValue: 592.00
+                        },
+                        {
+                            keys: [ { type: "prjFeature", key: "lanes", value: "双向八车道" } ],
+                            basicValue: 618.00
+                        }
+                    ],
+                    defaultBasicValue: 0.00
+                }
+            ],
+            "factorMappings": [
+                {
+                    basicFactorKeys: ["2010101", "路基保洁", "路基公里"],
+                    subs: [
+                        {
+                            keys: [{ type: "prjFeature", key: "trafficFlow", value: "2万以下" }],
+                            basicValue: 0.970
+                        }
+                    ],
+                    defaultFactorValue: 1
+                }
+            ]
+        };
+        try {
+            let jsonText =  JSON.stringify(projectFeature);
+            $("#featureList").val(JSON.stringify(JSON.parse(jsonText),null,4));
+        }catch (err){
+            console.log(err);
+        }
+
+    })
+
+
+});