فهرست منبع

人材机库设置补充分类树模板

zhongzewei 7 سال پیش
والد
کامیت
6b1eba224d

+ 23 - 0
modules/all_models/compleGlj_section.js

@@ -0,0 +1,23 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Zhong
+ * @date 2018/1/2
+ * @version
+ */
+
+import mongoose from 'mongoose';
+
+const Schema = mongoose.Schema;
+const compleGljSection = new Schema({
+    userId: String,
+    compilationId: String,
+    Name: String,
+    ID: String,
+    ParentID: String,
+    NextSiblingID: String,
+});
+
+mongoose.model('complementary_glj_section', compleGljSection, 'complementary_glj_section');

+ 30 - 0
modules/all_models/compleGlj_sectionTemplate.js

@@ -0,0 +1,30 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Zhong
+ * @date 2018/1/2
+ * @version
+ */
+
+/*
+ * 我的补充人材机库章节树模板,一个费用定额有一个模板
+ * 模板的生成目前由手工生成(借助定额库编辑器的章节树编辑)
+ * 新用户第一次进入某费用定额的补充定额库时,拷贝模板给该用户
+ *
+ * */
+
+import mongoose from 'mongoose';
+
+const Schema = mongoose.Schema;
+const compleGljSectionTemp = new Schema({
+    compilationId: String,
+    Name: String,
+    ID: Number,
+    ParentID: Number,
+    NextSiblingID: Number,
+});
+
+mongoose.model('complementary_glj_section_templates', compleGljSectionTemp, 'complementary_glj_section_templates');
+

+ 5 - 5
modules/all_models/comple_section_template.js

@@ -9,11 +9,11 @@
  */
 
 /*
-* 我的补充定额库章节树模板,一个费用定额有一个模板
-* 模板的生成目前由手工生成(借助定额库编辑器的章节树编辑)
-* 新用户第一次进入某费用定额的补充定额库时,拷贝模板给该用户
-*
-* */
+ * 我的补充定额库章节树模板,一个费用定额有一个模板
+ * 模板的生成目前由手工生成(借助定额库编辑器的章节树编辑)
+ * 新用户第一次进入某费用定额的补充定额库时,拷贝模板给该用户
+ *
+ * */
 
 import mongoose from 'mongoose';
 

+ 19 - 0
modules/std_glj_lib/controllers/gljMapController.js

@@ -11,6 +11,25 @@ let callback = function(req, res, err, message, data){
     res.json({error: err, message: message, data: data});
 };
 class GljMapController extends BaseController{
+    //该费用定额下补充人材机分类树模板数据条数
+    async classTemplateCount(req, res) {
+        try {
+            let count = await gljMapDao.classTemplateCount(req.params.compilationId);
+            callback(req, res, 0, 'success', {count});
+        } catch (err) {
+            callback(req, res, 1, err, {count: 0});
+        }
+    }
+    //将该标准人材机库的分类树设置为该费用定额下补充人材机分类树的模板
+    async initClassTemplate(req, res) {
+        try {
+            let data = JSON.parse(req.body.data);
+            await gljMapDao.initClassTemplate(data.gljLibId, data.compilationId);
+            callback(req, res, 0, 'success', null);
+        } catch (err) {
+            callback(req, res, 1, err, null);
+        }
+    }
     async getCompilationList(req, res){
         try{
             let compilationModel = new CompilationModel(), rst = [];

+ 19 - 0
modules/std_glj_lib/models/gljMapModel.js

@@ -8,6 +8,7 @@ const gljClassModel = mongoose.model('std_glj_lib_gljClass');
 const gljClassTemplateModel = mongoose.model('std_glj_lib_gljClassTemplate');
 const rationRepository = mongoose.model('std_ration_lib_map');
 const engLibModel = mongoose.model('engineering_lib');
+const compleGljClassTemp = mongoose.model('complementary_glj_section_templates');
 import moment from "moment";
 import counter from "../../../public/counter/counter";
 import async from "async";
@@ -246,6 +247,24 @@ class GljMapDao extends OprDao{
             }
         });
     }
+    async classTemplateCount (compilationId) {
+        return await compleGljClassTemp.find({compilationId}).count();
+    }
+    async initClassTemplate (gljLibId, compilationId) {
+        let classTempCount = await compleGljClassTemp.find({compilationId}).count();
+        if (classTempCount > 0) {
+            await compleGljClassTemp.remove({compilationId});
+        }
+        let bulks = [];
+        let stdGljClass = await gljClassModel.find({repositoryId: gljLibId});
+        for (let data of stdGljClass) {
+            data._doc.compilationId = compilationId;
+            bulks.push({insertOne: {document: data}});
+        }
+        if (bulks.length > 0) {
+            await compleGljClassTemp.bulkWrite(bulks);
+        }
+    }
 }
 
 export {OprDao, GljMapDao};

+ 2 - 0
modules/std_glj_lib/routes/routes.js

@@ -17,6 +17,8 @@ module.exports = function (app) {
     app.get('/stdGljRepository/main', viewsController.auth, viewsController.init, viewsController.redirectMain);
     app.get('/stdGljRepository/glj', viewsController.auth, viewsController.init, viewsController.redirectGlj);
 
+    router.get('/classTemplateCount/:compilationId', gljMapController.auth, gljMapController.init, gljMapController.classTemplateCount);
+    router.post('/initClassTemplate', gljMapController.auth, gljMapController.init, gljMapController.initClassTemplate);
     router.post('/getCompilationList', gljMapController.auth, gljMapController.init, gljMapController.getCompilationList);
     router.post('/getGljLib', gljMapController.auth, gljMapController.init, gljMapController.getGljLib);
     router.post('/getAllGljLib', gljMapController.auth, gljMapController.init, gljMapController.getAllGljLib);

+ 27 - 3
web/maintain/std_glj_lib/html/main.html

@@ -33,7 +33,7 @@
                   <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="90">操作</th><th width="90">价格数据</th></tr></thead>
+                        <thead><tr><th>人材机库名称</th><th>费用定额</th><th>定额库</th><th width="160">添加时间</th><th width="90">操作</th><th width="90">价格数据</th><th width="90">补充模板</th></tr></thead>
                         <tbody id="showArea">
                       <!--    <tr><td><a href="gongliao.html">XX工料机库</a></td><td>重庆2018</td><td>XXX定额库(重庆2018)</td><td>2017-01-01 </td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>
                           <tr><td><a href="gongliao.html">XX工料机库</a></td><td>重庆2018</td><td></td><td>2017-01-01 </td><td><a href="javacript:void(0);" data-toggle="modal" data-target="#edit" title="编辑"><i class="fa fa-pencil-square-o"></i></a> <a href="javacript:void(0);" data-toggle="modal" data-target="#del" class="text-danger" title="删除"><i class="fa fa-remove"></i></a></td></tr>
@@ -63,7 +63,7 @@
                       <input id="libNameTxt" class="form-control" placeholder="输入人材机库名称" type="text">
                     </div>
                     <div class="form-group">
-                      <label>编办名称</label>
+                      <label>费用定额名称</label>
                       <select id="compilationSels" class="form-control"></select>
                     </div>
                   </form>
@@ -92,7 +92,7 @@
                       <input class="form-control" id="renameText" placeholder="输入人材机库名称" type="text" value="">
                     </div>
                     <div class="form-group">
-                      <label>编办名称</label>
+                      <label>费用定额名称</label>
                       <select id="compilationEdit" class="form-control" disabled><option></option></select>
                     </div>
                   </form>
@@ -153,6 +153,30 @@
             </div>
         </div>
     </div>
+    <!--弹出设置模板-->
+    <div class="modal fade" id="template" 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 id="templateText">确认是否将此库的分类树设置成该费用定额下补充人材机分类树模板?</h5>
+                    <div class="form-group">
+                        <label>费用定额名称</label>
+                        <select id="compilations" class="form-control"></select>
+                    </div>
+                </div>
+                <div class="modal-footer">
+                    <a id="templateA" href="javascript: void(0);" class="btn btn-primary">确认</a>
+                    <button id="templateCancel" type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
+                </div>
+            </div>
+        </div>
+    </div>
     <!-- JS. -->
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/lib/tether/tether.min.js"></script>

+ 45 - 2
web/maintain/std_glj_lib/js/main.js

@@ -7,6 +7,7 @@ $(function () {
     let usedCom;
     let deleteCount = 0;
     let preDeleteId = null;
+    let selCompilationId;
     $('#del').on('hidden.bs.modal', function () {
         deleteCount = 0;
     });
@@ -186,6 +187,45 @@ $(function () {
             $.bootstrapLoading.end();
         }
     });
+    //设置补充人材机库分类树模板
+    $("#showArea").on("click", ".set-comple", function () {
+        let id = $(this).data("id");
+        id = parseInt(id);
+        if (isNaN(id) || id <= 0) {
+            return false;
+        }
+        selLibId = id;
+        $('#templateA').addClass('disabled');
+        $('#template').modal('show');
+        $('#compilations').empty();
+        for (let data of compilationsArr) {
+            let $opt = $(`<option value="${data._id}">${data.name}</option>`);
+            $('#compilations').append($opt);
+        }
+        $('#compilations').change();
+    });
+    $('#compilations').change(function () {
+        selCompilationId = $(this).select().val();
+        CommonAjax.get(`api/classTemplateCount/${selCompilationId}`, function (rstData) {
+            rstData.data.count > 0 ?
+                $('#templateText').text('该费用定额下已有人材机分类树模板数据,是否确认覆盖数据?') :
+                $('#templateText').text('确认是否将此库的分类树设置成该费用定额下补充人材机分类树模板?');
+            $('#templateA').removeClass('disabled');
+        });
+    });
+    $('#templateA').click(function () {
+        if (selLibId <= 0 && selCompilationId) {
+            return false;
+        }
+        $.bootstrapLoading.start();
+        CommonAjax.post('api/initClassTemplate', {gljLibId: selLibId, compilationId: selCompilationId}, function () {
+            $.bootstrapLoading.end();
+            $('#template').modal('hide');
+        }, function () {
+            $.bootstrapLoading.end();
+            $('#template').modal('hide');
+        });
+    });
 });
 
 function getAllGljLib(callback){
@@ -203,6 +243,7 @@ function getAllGljLib(callback){
                     let libName = result.data[i].dispName;
                     let createDate = result.data[i].createDate.split(' ')[0];
                     let compilationName = result.data[i].compilationName;
+                    let compilationId = result.data[i].compilationId;
                     let rationLibs = result.data[i].rationLibs;
                     let rationLibsName = '';
                     for(let j = 0; j < rationLibs.length; j++){
@@ -210,7 +251,7 @@ function getAllGljLib(callback){
                     }
                     dispNames.push(result.data[i].dispName);
                     $("#showArea").append(
-                        "<tr id='tempId'>" +
+                        "<tr id='tempId' data-compilationId='"+ compilationId + "'>" +
                         "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
                         "<td>"+compilationName+" </td>" +
                         "<td>"+rationLibsName+" </td>" +
@@ -219,6 +260,7 @@ function getAllGljLib(callback){
                         "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
                         "<i class='fa fa-remove'></i></a></td>" +
                         "<td><a class='btn btn-secondary btn-sm import-data' href='javacript:void(0);' data-id='"+ id +"' title='导入数据'><i class='fa fa-sign-in fa-rotate-90'></i>导入</a></td>" +
+                        "<td><a class='btn btn-secondary btn-sm set-comple' href='javacript:void(0);' data-id='"+ id +"' title='将分类树设为补充模板数据'><i class='fa fa-sign-in fa-rotate-90'></i>设置</a></td>" +
                         "</tr>");
                     var newHref = "/stdGljRepository/glj?gljLibId="+id;
                     $("#tempId td:first a").attr("href", newHref);
@@ -262,7 +304,7 @@ function createGljLib(gljLibObj, dispNamesArr, usedCom){
                 dispNamesArr.push(libName);
                 usedCom.push(gljLibObj.compilationId);
                 $("#showArea").append(
-                    "<tr id='tempId'>" +
+                    "<tr id='tempId' data-compilationId='"+ gljLibObj.compilationId + "'>" +
                     "<td><a href='/stdGljRepository/glj'>"+libName+"</a></td>" +
                     "<td>"+compilationName+" </td>" +
                     "<td>"+''+" </td>" +
@@ -271,6 +313,7 @@ function createGljLib(gljLibObj, dispNamesArr, usedCom){
                     "<i class='fa fa-pencil-square-o'></i></a> <a href='javascript:void(0);' data-toggle='modal' data-target='#del' class='text-danger' title='删除'>" +
                     "<i class='fa fa-remove'></i></a></td>" +
                     "<td><a class='btn btn-secondary btn-sm import-data' href='javacript:void(0);' data-id='"+ id +"' title='导入数据'><i class='fa fa-sign-in fa-rotate-90'></i>导入</a></td>" +
+                    "<td><a class='btn btn-secondary btn-sm set-comple' href='javacript:void(0);' data-id='"+ id +"' title='将分类树设为补充模板数据'><i class='fa fa-sign-in fa-rotate-90'></i>设置</a></td>" +
                     "</tr>");
                 var newHref = "/stdGljRepository/glj?gljLibId="+id;
                 $("#tempId td:first a").attr("href", newHref);