Просмотр исходного кода

标准定额库设置补充模板

zhongzewei 7 лет назад
Родитель
Сommit
9d3ac552f0

+ 19 - 0
modules/ration_repository/controllers/ration_section_tree_controller.js

@@ -9,6 +9,25 @@ var callback = function(req,res,err,message, data){
 }
 
 class RationChapterTreeController extends BaseController{
+    //某费用定额下补充定额库章节树模板数据条数
+    async sectionTemplateCount(req, res) {
+        try {
+            let count = await rationChapterTreeData.sectionTemplateCount(req.params.compilationId);
+            callback(req, res, 0, 'success', {count});
+        } catch (err) {
+            callback(req, res, 1, err, {count: 0});
+        }
+    }
+    //将该标准定额库的章节树设置为该费用定额下补充定额章节树的模板
+    async initSectionTemplate(req, res) {
+        try {
+            let data = JSON.parse(req.body.data);
+            await rationChapterTreeData.initSectionTemplate(data.rationLibId, data.compilationId);
+            callback(req, res, 0, 'success', null);
+        } catch (err) {
+            callback(req, res, 1, err, null)
+        }
+    }
     getRationChapterTree(req,res){
         let data = JSON.parse(req.body.data);
         var rationLibId = data.rationLibId;

+ 21 - 0
modules/ration_repository/models/ration_section_tree.js

@@ -8,8 +8,29 @@ let counter = require('../../../public/counter/counter');
 let rationRepositoryDao = require('./repository_map');
 const rationChapterTreeModel = mongoose.model('std_ration_lib_ration_chapter_trees');
 const rationModel = mongoose.model('std_ration_lib_ration_items');
+const compleRationSectionTemp = mongoose.model('complementary_ration_section_templates');
 var rationChapterTreeDAO = function(){};
 
+rationChapterTreeDAO.prototype.sectionTemplateCount = async function (compilationId) {
+    return await compleRationSectionTemp.find({compilationId}).count();
+};
+
+rationChapterTreeDAO.prototype.initSectionTemplate = async function (rationLibId, compilationId) {
+    let sectionTempCount = await compleRationSectionTemp.find({compilationId}).count();
+    if (sectionTempCount > 0) {
+        await compleRationSectionTemp.remove({compilationId});
+    }
+    let bulks = [];
+    let stdRationSection = await rationChapterTreeModel.find({rationRepId: rationLibId});
+    for (let data of stdRationSection) {
+        data._doc.compilationId = compilationId;
+        bulks.push({insertOne: {document: data}});
+    }
+    if (bulks.length > 0) {
+        await compleRationSectionTemp.bulkWrite(bulks);
+    }
+};
+
 rationChapterTreeDAO.prototype.getRationChapterTree = function(rationLibId,callback){
     rationChapterTreeModel.find({"rationRepId": rationLibId, "$or": [{"isDeleted": null}, {"isDeleted": false} ]},function(err,data){
         if(data.length) callback(0,data);

+ 3 - 1
modules/ration_repository/routes/ration_rep_routes.js

@@ -32,8 +32,8 @@ module.exports =  function (app) {
 
     apiRouter.post("/getCompilationList", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getCompilationList);
     apiRouter.post("/getRationLibsByCompilation", rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLibsByCompilation);
-
     apiRouter.post("/getRationLib",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRationLib);
+
     apiRouter.post("/getRationDisplayNames",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getDisPlayRationLibs);
     apiRouter.post("/editRationLibs",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.updateRationRepositoryName);
     apiRouter.post("/addRationRepository",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.addRationRepository);
@@ -41,6 +41,8 @@ module.exports =  function (app) {
     apiRouter.post("/getRealLibName",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getRealLibName);
     apiRouter.post("/getLibIDByName",rationRepositoryController.auth, rationRepositoryController.init, rationRepositoryController.getLibIDByName);
 
+    apiRouter.get('/sectionTemplateCount/:compilationId', rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.sectionTemplateCount);
+    apiRouter.post('/initSectionTemplate', rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.initSectionTemplate);
     apiRouter.post("/getRationTree",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.getRationChapterTree);
     apiRouter.post("/getNewRationTreeID",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.getNewRationTreeID);
     apiRouter.post("/createNewNode",rationChapterTreeController.auth, rationChapterTreeController.init, rationChapterTreeController.createNewNode);

+ 49 - 4
web/maintain/ration_repository/js/main.js

@@ -6,6 +6,8 @@ $(function () {
     let dispNameArr;
     let preDeleteId = null;
     let deleteCount = 0;
+    let selCompilationId,
+        compilationsArr = [];
     $('#del').on('hidden.bs.modal', function () {
         deleteCount = 0;
     });
@@ -124,7 +126,9 @@ $(function () {
         });
 
     });
-    getCompilationList();
+    getCompilationList(function (data) {
+        compilationsArr = data.compilation;
+    });
 
     // 导入原始数据按钮
     let rationRepId = 0;
@@ -216,6 +220,46 @@ $(function () {
         }
         window.location.href = '/rationRepository/api/export?rationRepId=' + id;
     });
+
+    //设置补充定额库章节树模板
+    $("#showArea").on("click", ".set-comple", function () {
+        let id = $(this).data("id");
+        id = parseInt(id);
+        if (isNaN(id) || id <= 0) {
+            return false;
+        }
+        rationRepId = 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/sectionTemplateCount/${selCompilationId}`, function (rstData) {
+            rstData.data.count > 0 ?
+                $('#templateText').text('该费用定额下已有定额章节树模板数据,是否确认覆盖数据?') :
+                $('#templateText').text('确认是否将此库的章节树设置成该费用定额下补充定额章节树模板?');
+            $('#templateA').removeClass('disabled');
+        });
+    });
+    $('#templateA').click(function () {
+        if (rationRepId <= 0 && selCompilationId) {
+            return false;
+        }
+        $.bootstrapLoading.start();
+        CommonAjax.post('api/initSectionTemplate', {rationLibId: rationRepId, compilationId: selCompilationId}, function () {
+            $.bootstrapLoading.end();
+            $('#template').modal('hide');
+        }, function () {
+            $.bootstrapLoading.end();
+            $('#template').modal('hide');
+        });
+    });
 });
 
 function getAllRationLib(callback){
@@ -248,6 +292,7 @@ function getAllRationLib(callback){
                         "<td><a class='btn btn-secondary btn-sm import-source' 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-success btn-sm export' href='javacript:void(0);' data-toggle='modal' data-id='"+ id +"' data-target='#emport' title='导出内部数据'><i class='fa fa-sign-out fa-rotate-270'></i>导出</a> " +
                         "<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>");
                     $("#tempId").attr("id", id);
                 }
@@ -256,13 +301,12 @@ function getAllRationLib(callback){
         }
     });
 }
-function getCompilationList(){
+function getCompilationList(callback){
     $.ajax({
         type: 'post',
         url: 'api/getCompilationList',
         dataType: 'json',
         success: function (result) {
-            console.log(result);
             //addoptions
             for(let i = 0; i < result.data.compilation.length; i++){
                 let $option =  $("<option >"+ result.data.compilation[i].name +"</option>");
@@ -274,7 +318,6 @@ function getCompilationList(){
                 let compilationId = result.data.compilation[0]._id;
                 //console.log(compilationId);
                 let gljLibOps = getGljLibOps(compilationId, result.data.gljLibs);
-                console.log(gljLibOps);
                 for(let i = 0; i < gljLibOps.length; i++){
                     let $option =  $("<option >"+ gljLibOps[i].dispName +"</option>");
                     $option.val(gljLibOps[i].ID);
@@ -292,6 +335,7 @@ function getCompilationList(){
                     $('#gljLibSels').append($option);
                 }
             });
+            callback(result.data);
         }
     });
 }
@@ -336,6 +380,7 @@ function createRationLib(rationObj, dispNamesArr){
                     "<td><a class='btn btn-secondary btn-sm import-source' 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-success btn-sm export' href='javacript:void(0);' data-toggle='modal' data-id='"+ id +"' data-target='#emport' title='导出内部数据'><i class='fa fa-sign-out fa-rotate-270'></i>导出</a> " +
                     "<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>");
                 $("#tempId").attr("id", id);
             }

+ 25 - 1
web/maintain/ration_repository/main.html

@@ -35,7 +35,7 @@
                   <div class="col-md-8">
                     <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="90">操作</th><th width="90">原始数据</th><th width="150">内部数据</th></tr></thead>
+                        <thead><tr><th>定额库名称</th><th width="160">编办</th><th width="160">添加时间</th><th width="90">操作</th><th width="90">原始数据</th><th width="150">内部数据</th><th width="90">补充模板</th></tr></thead>
                         <tbody id="showArea">
                         </tbody>
                       </table>
@@ -229,6 +229,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>