瀏覽代碼

feat: 土地补偿编辑器

vian 1 年之前
父節點
當前提交
5c5a80f52c

+ 46 - 0
modules/all_models/land.js

@@ -0,0 +1,46 @@
+// 土地补偿
+import mongoose from "mongoose";
+const Schema = mongoose.Schema;
+const collectionName = 'std_land_libs';
+const oprSchema = require('../all_schemas/opr_schema');
+
+const subItem = new Schema({
+    // 土地类型
+    name: String,
+    // 土地补偿标准单价  
+    unitPrice: Number,
+}, { _id: false })
+
+// 地区
+const regionSchema = new Schema({
+    ID: Number,
+    ParentID: Number,
+    // 地区名称
+    name: String,
+    // 地区类型
+    type: Number,
+    // 街道
+    street: String,
+    // 耕地开垦单价
+    unitPrice: Number,
+    subList: { type: [subItem], default: [] },
+}, { _id: false });
+
+const modelSchema = {
+    ID: String,
+    // 标准名称
+    libName: String,
+    //编办ID
+    compilationId: {
+        type: String,
+        index: true
+    },
+    compilationName: String,
+    regions: { type: [regionSchema], default: [] },
+    creator: String,
+    createDate: Number,
+    recentOpr: [oprSchema]
+};
+
+mongoose.model(collectionName, new Schema(modelSchema, { versionKey: false, collection: collectionName }));
+

+ 116 - 0
modules/land_lib/controllers/land_controller.js

@@ -0,0 +1,116 @@
+/**
+ * Created by zhang on 2018/9/10.
+ */
+import BaseController from "../../common/base/base_controller.js";
+import CompilationModel from '../../users/models/compilation_model.js';
+let config = require("../../../config/config.js");
+import landFacade from "../facade/land_facade.js";
+import { checkCompilationPermission } from '../../common/base/base_util.js';
+
+class LandController extends BaseController {
+    async main(request, response) {
+        let compilationModel = new CompilationModel();
+        let compilationList = await compilationModel.getPermissionCompilationList(request, { _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 landLibs = await landFacade.findByCondition(filter, { rates: 0 }, false);
+        const compilationPermission = request.session.managerData.compilationPermission || [];
+        landLibs = landLibs.filter(lib => compilationPermission.includes(lib.compilationId));
+        let randerData = {
+            title: '土地补偿库',
+            userAccount: request.session.managerData.username,
+            userID: request.session.managerData.userID,
+            landLibs,
+            compilationList: compilationList,
+            layout: 'maintain/common/html/layout'
+        };
+        response.render("maintain/land_lib/html/main", randerData);
+    }
+    async addLib(request, response) {
+        try {
+            await landFacade.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 landFacade.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 landFacade.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 landFacade.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 landLib = await landFacade.findByCondition({ 'ID': libID });
+        if (landLib) {
+            checkCompilationPermission(request, response, landLib.compilationId, '/land/main');
+
+            let randerData = {
+                title: '土地补偿库',
+                mainURL: '/land/main',
+                libName: landLib.libName,
+                userAccount: request.session.managerData.username,
+                userID: request.session.managerData.userID,
+                landList: JSON.stringify(landLib.regions),
+                libID: libID,
+                LicenseKey: config.getLicenseKey(process.env.NODE_ENV),
+                layout: 'maintain/common/html/edit_layout'
+            };
+            response.render("maintain/land_lib/html/edit", randerData);
+        } else {
+            response.redirect(request.headers.referer);
+        }
+    }
+}
+
+export default LandController;

+ 50 - 0
modules/land_lib/facade/land_facade.js

@@ -0,0 +1,50 @@
+/**
+ * Created by zhang on 2018/9/10.
+ */
+
+import mongoose from "mongoose";
+
+const uuidV1 = require('uuid/v1');
+let moment = require("moment");
+let landModel = mongoose.model('std_land_libs');
+let compilationModel = mongoose.model("compilation");
+const _ = require('lodash');
+
+let landLib = {
+    findByCondition: async function (conditions, options, single = true) {
+        if (single == true) {
+            return await landModel.findOne(conditions, options);
+        } else {
+            return await landModel.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 }],
+                libName: data.name,
+                compilationId: data.compilationId,
+                compilationName: compilation.name,
+            };
+            newLib.ID = uuidV1();
+            return await landModel.create(newLib);
+        } else {
+            throw new Error("没有找到该编办!");
+        }
+
+    },
+    saveLib: async function (param) {
+        return await landModel.findOneAndUpdate(param.query, param.data, { new: true });
+    },
+    deleteLibByID: async function (ID) {
+        return await landModel.deleteOne({ ID: ID });
+    },
+};
+
+export default landLib

+ 21 - 0
modules/land_lib/routes/land_routes.js

@@ -0,0 +1,21 @@
+/**
+ * Created by zhang on 2018/9/10.
+ */
+
+let express = require("express");
+let landRouter = express.Router();
+import LandController from "../controllers/land_controller";
+let landController = new LandController();
+
+module.exports = function (app) {
+
+    landRouter.get("/main", landController.auth, landController.init, landController.main);
+    landRouter.post("/addLib", landController.auth, landController.init, landController.addLib);
+    landRouter.post("/findLib", landController.auth, landController.init, landController.findLib);
+    landRouter.post("/saveLib", landController.auth, landController.init, landController.saveLib);
+    landRouter.post("/deleteLibByID", landController.auth, landController.init, landController.deleteLibByID);
+    landRouter.get("/edit/:libID", landController.auth, landController.init, landController.edit);
+
+
+    app.use("/land", landRouter);
+};

+ 36 - 0
web/maintain/land_lib/html/edit.html

@@ -0,0 +1,36 @@
+<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="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="landList" rows="38"></textarea>
+            </div>
+        </div>
+        <input type="hidden" id="libID" value="<%= libID %>">
+        <input type="hidden" id="originalLands" value="<%= landList %>">
+    </div>
+</div>
+
+
+
+<script type="text/javascript">
+
+</script>
+<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/land_lib/js/land_edit.js"></script>

+ 145 - 0
web/maintain/land_lib/html/main.html

@@ -0,0 +1,145 @@
+<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="/land/main"
+                            class="list-group-item list-group-item-action <%= compilation.active %>">
+                            所有
+                        </a>
+                        <% } else { %>
+                        <a id="<%= compilation._id %>" href="/land/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 landLibs){ %>
+                                <tr class="libTr">
+                                    <td id="<%= lib.ID%>"><a
+                                            href="/land/edit/<%= lib.ID%>?locked=true"><%= lib.libName%></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='getLandLib("<%= lib.ID%>")' title="编辑"><i
+                                                class="fa fa-pencil-square-o"></i></a>
+                                        <a class="text-danger lock-btn-control disabled" href="javascript:void(0);"
+                                            style="color: #0275d8" 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="/land/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 id="compilationSels" name="compilationId" class="form-control"></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/land_lib/js/land.js"></script>

+ 86 - 0
web/maintain/land_lib/js/land.js

@@ -0,0 +1,86 @@
+/**
+ * Created by zhang on 2018/9/11.
+ */
+
+$(document).ready(function () {
+    $('#add').on('show.bs.modal', async function () {
+        await initCompilationSelect();
+    });
+
+    // 保存按钮
+    $("#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 newLand = await ajaxPost("/land/saveLib", { query: { ID: libID }, data: { libName: name } });
+                    $("#" + libID).children("a").text(newLand.libName);
+                    $("#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("/land/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 getLandLib(ID) {
+    try {
+        let lib = await ajaxPost("/land/findLib", { ID: ID });
+        if (lib) {
+            $("#renameText").val(lib.libName);
+            $("#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 });
+}

+ 34 - 0
web/maintain/land_lib/js/land_edit.js

@@ -0,0 +1,34 @@
+$(document).ready(function () {
+    const locked = lockUtil.getLocked();
+    lockUtil.lockTools($(document.body), locked);
+    try {
+        let tem = sortJson(JSON.parse($("#originalLands").val()));
+        $("#landList").val(JSON.stringify(tem, null, 4));
+    } catch (err) {
+        console.log(err);
+    }
+
+    $("#format").click(function () {
+        try {
+            let jsonText = $("#landList").val();
+            $("#landList").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 = $("#landList").val();
+            if (jsonText.indexOf("'") != -1) {
+                alert("输入的格式不能包含 ' 位于:" + jsonText.substr(jsonText.indexOf("'") - 15, 18));
+                return;
+            }
+            await ajaxPost("/land/saveLib", { query: { ID: libID }, data: { regions: JSON.parse(jsonText) } });
+        } catch (err) {
+            console.log(err);
+            alert("保存失败,请查看输入数据");
+        }
+    });
+});