Browse Source

材料替换库主页面相关功能

zhangweicheng 6 years ago
parent
commit
e05c52823c

+ 2 - 2
config/menu.js

@@ -22,12 +22,12 @@ let menuData = {
                 title: '普通用户',
                 url: '/user',
                 name: 'index',
-            },
+            }/*,
             'test-user' : {
                 title: '测试用户',
                 url: '/user/test-user',
                 name: 'test-user',
-            }
+            }*/
         }
     },
     'notify': {

+ 23 - 0
modules/all_models/material_replace_lib.js

@@ -0,0 +1,23 @@
+/**
+ * Created by zhang on 2018/8/22.
+ */
+//材料替换库
+const mongoose = require('mongoose');
+const Schema = mongoose.Schema;
+const oprSchema = require('../all_schemas/opr_schema');
+const material_lib = new Schema({
+        ID:{type:String,index:true},
+        creator: String,
+        createDate: Number,
+        recentOpr: [oprSchema],
+        name: String,
+        compilationId: String,
+        compilationName: String,
+        billsLibId:Number,
+        billsLibName:String,
+        deleted: Boolean
+    },
+    {versionKey: false}
+);
+
+mongoose.model("std_material_replace_lib", material_lib,"std_material_replace_lib");

+ 88 - 0
modules/material_replace_lib/controllers/material_replace_controller.js

@@ -0,0 +1,88 @@
+/**
+ * Created by zhang on 2018/8/22.
+ */
+import BaseController from "../../common/base/base_controller";
+import materialFacade from "../facade/material_replace_facade";
+
+class ReplaceController extends BaseController{
+    /**
+     * 材料替换库页面
+     *
+     * @param {object} request
+     * @param {object} response
+     * @return {void}
+     */
+    async main(request, response) {
+        let materialLibs = await materialFacade.findByCondition({},null,false);
+        let randerData = {
+            title:'材料替换库',
+            userAccount: request.session.managerData.username,
+            userID: request.session.managerData.userID,
+            materialLibs:materialLibs,
+            layout: 'maintain/common/html/layout'
+        };
+        response.render("maintain/material_replace_lib/html/main", randerData);
+    }
+    async findLib(request, response){
+        let result={
+            error:0
+        };
+        try {
+            let data = request.body.data;
+            data = JSON.parse(data);
+            let conditions={};
+            if(data.compilationID) conditions.compilationId = data.compilationID;
+            if(data.billLibID) conditions.billsLibId = data.billLibID;
+            if(data.ID) conditions.ID = data.ID;
+            let resultData = await materialFacade.findByCondition(conditions);
+            result.data=resultData;
+        }catch (err){
+            console.log(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        response.json(result);
+    }
+    async addLib(request, response){
+        try {
+            await materialFacade.addLib(request.body);
+        }catch (error) {
+            console.log(error);
+        }
+        response.redirect(request.headers.referer);
+    }
+    async saveLib(request, response){
+        let result={
+            error:0
+        };
+        try {
+            let data = request.body.data;
+            data = JSON.parse(data);
+            let resultData= await materialFacade.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 materialFacade.deleteLibByID(data.ID);
+            result.data=resultData;
+        }catch (err){
+            console.log(err);
+            result.error=1;
+            result.message = err.message;
+        }
+        response.json(result);
+    }
+}
+
+export default ReplaceController;

+ 52 - 0
modules/material_replace_lib/facade/material_replace_facade.js

@@ -0,0 +1,52 @@
+/**
+ * Created by zhang on 2018/8/22.
+ */
+
+import mongoose from "mongoose";
+const uuidV1 = require('uuid/v1');
+let moment = require("moment");
+let compilationModel = mongoose.model("compilation");
+let materialLibModel = mongoose.model("std_material_replace_lib");
+let StdBillsLib = mongoose.model('std_bills_lib_list');
+
+let materialReplaceLib = {
+    findByCondition:async function(conditions,options,single=true){
+        if(single == true){
+            return await materialLibModel.findOne(conditions,options);
+        }else {
+            return await  materialLibModel.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});
+        //取清单规则信息
+        let billLib = await StdBillsLib.findOne({billsLibId:data.billsLibId});
+        if(compilation && billLib){
+            let newLib = {
+                creator: data.userAccount,
+                createDate: now,
+                recentOpr: [{operator: data.userAccount, operateDate: dateStr}],
+                name: data.name,
+                compilationId: data.compilationId,
+                compilationName: compilation.name,
+                billsLibId:billLib.billsLibId,
+                billsLibName:billLib.billsLibName,
+                deleted: false
+            };
+            newLib.ID = uuidV1();
+            return await materialLibModel.create(newLib);
+        }else {
+            throw  new Error("编办或清单规则有误!");
+        }
+    },
+    saveLib:async function(param) {
+        return await materialLibModel.findOneAndUpdate(param.query,param.data,{new:true});
+    },
+    deleteLibByID:async function(ID){
+        return materialLibModel.deleteOne({ID:ID});
+    }
+}
+export default materialReplaceLib

+ 20 - 0
modules/material_replace_lib/routes/material_replace_router.js

@@ -0,0 +1,20 @@
+/**
+ * Created by zhang on 2018/8/22.
+ */
+
+let express = require("express");
+let repRouter =express.Router();
+import ReplaceController from "../controllers/material_replace_controller";
+let replaceController = new ReplaceController();
+
+module.exports =function (app){
+
+    repRouter.get("/main", replaceController.auth, replaceController.init, replaceController.main);
+    repRouter.post("/findLib", replaceController.auth, replaceController.init, replaceController.findLib);
+    repRouter.post("/add-lib", replaceController.auth, replaceController.init, replaceController.addLib);
+    repRouter.post("/saveLib", replaceController.auth, replaceController.init, replaceController.saveLib);
+    repRouter.post("/deleteLibByID", replaceController.auth, replaceController.init, replaceController.deleteLibByID);
+    app.use("/materialReplace", repRouter);
+};
+
+

+ 68 - 0
modules/users/controllers/user_controller.js

@@ -37,6 +37,8 @@ class UserController extends BaseController {
             compilationString = JSON.stringify(compilationList);
             compilationMap = _.indexBy(compilationList,'_id');
             let condition = userModel.getFilterCondition(request);
+            //设置搜索普通用户:
+            condition.user_type = 'normal';
 
             //获取注册时间
             let regtime = request.query.regtime;
@@ -85,6 +87,72 @@ class UserController extends BaseController {
     }
 
 
+    async testUsers(request,response){
+        let userModel = new UserModel();
+        let total = 0;
+        let pageData = {};
+        let userList = [];
+        let compilationList =[];
+        let compilationString ='';
+        let compilationMap = {};
+        let filter = request.query;
+        try {
+            //获取编办列表
+            let  compilationModel = new CompilationModel();
+            compilationList = await compilationModel.getCompilationList({_id: 1, name: 1, is_release: 1});
+            compilationString = JSON.stringify(compilationList);
+            compilationMap = _.indexBy(compilationList,'_id');
+            let condition = userModel.getFilterCondition(request);
+            //设置搜索普通用户:
+            condition.user_type = 'normal';
+
+            //获取注册时间
+            let regtime = request.query.regtime;
+            if(regtime !== '' && regtime !== undefined){
+                filter.regtimeMsg = userModel.getDayMsg(regtime);
+            }
+
+            //获取注册时间
+            let loginTime = request.query.loginTime;
+            if(loginTime !== '' && loginTime !== undefined){
+                filter.loginMsg = userModel.getDayMsg(loginTime);
+            }
+
+            // 获取用户总数
+            total = await userModel.count(condition);
+
+            // 分页数据
+            let page = request.query.page === undefined ? 1 : request.query.page;
+            pageData = {
+                current: page,
+                total: Math.ceil(total / Config.pageSize),
+                queryData: response.locals.urlQuery
+            };
+
+            // 获取用户列表
+            userList = await userModel.getList(condition, page, Config.pageSize);
+        } catch (error) {
+            console.log(error);
+        }
+
+        // 渲染数据
+        let renderData = {
+            compilationList:compilationList,
+            compilationString:compilationString,
+            compilationMap:compilationMap,
+            adminName:request.session.managerData?request.session.managerData.real_name:'',
+            userList: userList,
+            pages: pageData,
+            total: total,
+            filter: filter,
+            model: userModel,
+            layout: 'users/views/layout/layout',
+            LicenseKey:config.getLicenseKey(process.env.NODE_ENV)
+        };
+        response.render('users/views/user/test_user', renderData);
+    }
+
+
     /**
      * 获取搜索用户json
      *

+ 1 - 1
modules/users/routes/user_route.js

@@ -14,7 +14,7 @@ const userController = new UserController();
 module.exports =function (app) {
     // action定义区域
     router.get('/', userController.auth, userController.init, userController.normalUsers);
-    router.get('/test-user', userController.auth, userController.init, userController.normalUsers);
+    router.get('/test-user', userController.auth, userController.init, userController.testUsers);
     router.get('/search', userController.auth, userController.init, userController.search);
     router.post('/findByID', userController.auth, userController.init, userController.findByID);
     router.post('/getUserList', userController.auth, userController.init, userController.getUserList);

+ 1 - 1
public/web/common_ajax.js

@@ -129,7 +129,7 @@ async function ajaxPost(url, data) {
             cache: false,
             timeout: 50000,
             success: function(result){
-                if (result.error === 0) {
+                if (result.error === 0 ||result.error ===false) {
                     resolve(result.data);
                 } else {
                     alert('error: ' + result.message);

+ 118 - 0
web/maintain/material_replace_lib/html/main.html

@@ -0,0 +1,118 @@
+<div class="main">
+    <div class="content">
+        <div class="container-fluid">
+            <div class="row">
+                <div class="col-md-8">
+                    <div class="warp-p2 mt-3">
+                        <table class="table table-hover table-bordered">
+                            <thead><tr><th>库名称</th><th>清单规则</th><th >费用定额</th><th width="160">添加时间</th><th width="120">操作</th></tr></thead>
+                            <tbody id="showArea">
+                            <% for(let lib of materialLibs){ %>
+                            <tr class="libTr">
+                                <td id="<%= lib.ID%>"><a href="/materialReplace/editMaterial/<%= lib.ID%>"><%= lib.name%></a></td>
+                                <td><%= lib.billsLibName%></td>
+                                <td><%= lib.compilationName%></td>
+                                <td><%= moment(lib.createDate).format('YYYY-MM-DD')%></td>
+                                <td>
+                                    <a style="color: #0275d8" onclick='getMaterialLib("<%= lib.ID%>")' title="编辑"><i class="fa fa-pencil-square-o"></i></a>
+                                    <a style="color: #0275d8" onclick='showDeleteModal("<%= lib.ID%>")' class="text-danger" title="删除"><i class="fa fa-remove"></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="/materialReplace/add-lib" 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="billLibs" name="billsLibId" class="form-control"></select>
+                    </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 type="text/javascript" src="/web/maintain/material_replace_lib/js/material_replace.js"></script>

+ 131 - 0
web/maintain/material_replace_lib/js/material_replace.js

@@ -0,0 +1,131 @@
+/**
+ * Created by zhang on 2018/8/22.
+ */
+$(document).ready(function() {
+    $('#add').on('show.bs.modal', function () {
+        $('#compilationSels').empty();
+        $('#billLibs').empty();
+        getCompilationOptions();
+        getBillsLibOptions();
+
+    });
+
+    // 保存按钮
+    $("#addLibs").click(async function() {
+        let name = $('#name').val();
+        if(name==''){
+            $("#nameError").show();
+            return;
+        }else {
+            let result = await validateLib($('#billLibs').val(),$('#compilationSels').val());
+            if(result == true){//不存在则验证通过
+                $("#addLibs").attr("disabled",true);//防止重复提交
+                $("#addLibForm").submit();
+            }else {
+                alert('清单规则和定额库对应的材料库已存在,请重新选择');
+            }
+        }
+    });
+
+    $("#rename").click(async function() {
+        let libID = $("#libID").val();
+        let name = $('#renameText').val();
+        if(libID!=''){
+            if(name ==''){
+                $("#renameError").show();
+                return;
+            }else {
+                try {
+                    let newMaterial = await ajaxPost("/materialReplace/saveLib",{query:{ID:libID},data:{name:name}});
+                    $("#"+libID).children("a").text(newMaterial.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("/materialReplace/deleteLibByID",{ID:libID});
+                    if(result.ok){
+                        $("#"+libID).parent(".libTr").remove();
+                    }
+                    $("#del").modal('hide');
+                }catch (err){
+                    console.log(err);
+                }
+            }
+        }
+    });
+
+
+})
+
+//检查库是否已经存在,存在则返回false
+async function validateLib(billLibID,compilationID){
+    try {
+        let lib = await ajaxPost("/materialReplace/findLib",{billLibID:billLibID,compilationID:compilationID});
+        return lib?false:true;
+    }catch (err){
+        console.log(err);
+        return false
+    }
+}
+
+//取所有的定额并生成下拉框
+async function getCompilationOptions() {
+    try {
+        let compilations = await ajaxPost("/stdBillsEditor/getCompilationList");
+        for(let com of compilations){
+            let $option =  $("<option >"+ com.name +"</option>");
+            $option.val( com._id);
+            $('#compilationSels').append($option);
+        }
+    }catch (err){
+        console.log(err)
+    }
+}
+
+//取所有的清单规则库并生成下拉框
+async function getBillsLibOptions(){
+    try {
+        let libs = await ajaxPost("/stdBillsEditor/getStdBillsLib");
+        for(let b of libs){
+            let $option =  $("<option >"+ b.billsLibName +"</option>");
+            $option.val( b.billsLibId);
+            $('#billLibs').append($option);
+        }
+    }catch (err){
+        console.log(err)
+    }
+
+}
+
+async function getMaterialLib (ID) {
+    try {
+        let lib = await ajaxPost("/materialReplace/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});
+}

+ 16 - 6
web/users/js/user.js

@@ -31,11 +31,16 @@ async function getUserInfo(ID) {
 }
 
 async function getUserUpgradeInfo(ID){
-    cacheUser  = await ajaxPost("/user/findByID",{ID:ID});
-    refreshUpgradeTabel(cacheUser);
+    try {
+        cacheUser  = await ajaxPost("/user/findByID",{ID:ID});
+        refreshUpgradeTable(cacheUser);
+    }catch (err){
+        console.log(err);
+    }
+
 }
 
-function refreshUpgradeTabel(user) {
+function refreshUpgradeTable(user) {
     let compilationTable = ' <tr><th colspan="2">专业版升级</th></tr>';
     let test = true;
     for(let c of compilationList){
@@ -82,9 +87,14 @@ async function updateUser(compilationID,type) {
             upgradeInfo.isUpgrade = false;
             upgradeInfo.remark = adminName + " "+ moment().format("YYYY-MM-DD") +" 关闭";
         }
-        await ajaxPost("/user/updateUser",{ID:cacheUser._id,updateData:{upgrade_list:upgrade_list}});
-        cacheUser.upgrade_list = upgrade_list;
-        refreshUpgradeTabel(cacheUser);
+        try {
+            await ajaxPost("/user/updateUser",{ID:cacheUser._id,updateData:{upgrade_list:upgrade_list}});
+            cacheUser.upgrade_list = upgrade_list;
+            refreshUpgradeTable(cacheUser);
+        }catch (err){
+            console.log(err);
+        }
+
     }
 
 }

+ 7 - 0
web/users/views/tool/index.html

@@ -62,6 +62,13 @@
                     </h2>
                 </div>
             </div>
+            <div class="col-xs-6 mb-30 ">
+                <div class="c-body">
+                    <h2>材料替换库
+                        <a id="materialReplace" href="/materialReplace/main" target="_blank" class="btn btn-primary pull-right">进入</a>
+                    </h2>
+                </div>
+            </div>
         </div>
     </div>
 </div>

+ 73 - 0
web/users/views/user/test_user.html

@@ -0,0 +1,73 @@
+<%include ../layout/second_menu.html %>
+<div class="panel-content">
+    <div class="panel-title">
+        <div class="title-main">
+            <h2><%= secondMenu[action].title %>
+                <a href="#news-add" data-toggle="modal" data-target="#news-add" class="btn btn-primary btn-sm pull-right">添加用户</a>
+            </h2>
+        </div>
+    </div>
+    <div class="content-wrap">
+        <div class="c-header">
+            <form class="form-inline" method="get" action="">
+                <!--搜索-->
+                <div class="btn-group">
+                    <div class="input-group">
+                        <input type="text" name="keyword" class="form-control input-sm" value="<%= filter.keyword === undefined ? '' : filter.keyword %>" placeholder="手机/邮箱/姓名/公司">
+                        <span class="input-group-btn">
+                        <button class="btn btn-default btn-sm" type="submit">
+                            <i class="glyphicon glyphicon-search"></i>
+                        </button>
+                    </span>
+                    </div>
+                </div>
+            </form>
+            <div class="btn-group">
+
+            </div>
+        </div>
+        <div class="c-body">
+            <table class="table">
+                <thead>
+                <tr>
+                    <th width="350">注册手机/邮箱</th>
+                    <th>姓名</th>
+                    <th>企业名称</th>
+                    <th>企业地区</th>
+                    <th>最近使用版本</th>
+                    <th width="180">最近登录</th>
+                    <th width="180">注册时间</th>
+                    <th>详细</th>
+                </tr>
+                </thead>
+                <tbody>
+                <% userList.forEach(function (user){ %>
+                <tr>
+                    <td><%= user.mobile %> / <%= user.email %></td>
+                    <td><%= user.real_name %></td>
+                    <td><a tabindex="0" role="button" data-toggle="popover" data-trigger="focus" title="更多信息"
+                           data-content="企业类型:<%= model.companyType[user.company_type] %>,企业规模:<%= model.companyScale[user.company_scale] %>"><%= user.company %></a>
+                    </td>
+                    <td><%= model.province[user.province] %></td>
+                    <td><%= compilationMap[user.latest_used]?compilationMap[user.latest_used].name:""%></td>
+                    <td><%= user.latest_login?moment(user.latest_login).format('YYYY-MM-DD HH:mm:ss'):"" %></td>
+                    <td><%= moment(user.create_time).format('YYYY-MM-DD HH:mm:ss') %></td>
+                    <td><a role="button" data-toggle="modal" data-target="#view" onclick='getUserInfo("<%= user._id.toString()%>")'>详细</a></td>
+                </tr>
+                <% }) %>
+                </tbody>
+            </table>
+            <nav aria-label="Page navigation">
+                <%include ../layout/page.html %>
+            </nav>
+        </div>
+    </div>
+</div>
+
+
+
+<script type="text/javascript">
+    let compilationList = JSON.parse('<%- compilationString %>');
+    let adminName = '<%- adminName %>';
+</script>
+<script type="text/javascript" src="/web/users/js/user.js"></script>