浏览代码

feat: 清单精灵,定额型项目指引,双击定位到对应定额库下定额

vian 3 年之前
父节点
当前提交
ab496a5097

+ 9 - 0
modules/ration_repository/controllers/search_controller.js

@@ -18,6 +18,15 @@ class SearchController extends BaseController{
             callback(req, res, 1, err, null);
         }
     }
+    async getRationByID (req, res) {
+        try {
+            let data = JSON.parse(req.body.data);
+            let ration = await rationItem.getRationByID(data.ID);
+            callback(req, res, 0, '', ration);
+        } catch (err) {
+            callback(req, res, 1, err, null);
+        }
+    }
     findRation (req, res) {
         var rId = req.body.rationLibId, keyword = req.body.keyword;
         rationItem.findRation(rId, keyword, function (err, message, rst) {

+ 5 - 0
modules/ration_repository/models/ration_item.js

@@ -505,6 +505,11 @@ rationItemDAO.prototype.getRationItem = async function (repId, code) {
     return ration;
 };
 
+rationItemDAO.prototype.getRationByID = async function (ID) {
+    let ration = await rationItemModel.findOne({ ID: +ID }).lean();
+    return ration;
+};
+
 rationItemDAO.prototype.addRationItems = function(rationLibId, lastOpr, sectionId, items,callback){
     if (items && items.length > 0) {
         counter.counterDAO.getIDAfterCount(counter.moduleName.rations, items.length, function(err, result){

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

@@ -87,6 +87,7 @@ module.exports =  function (app) {
     apiRouter.post('/updateSection', installationController.auth, installationController.init, installationController.updateSection);
     apiRouter.post('/batchUpdateInst', installationController.auth, installationController.init, installationController.batchUpdateInst);
 
+    apiRouter.post('/getRationByID', searchController.auth, searchController.init, searchController.getRationByID);
     apiRouter.post('/getRationItem',searchController.auth, searchController.init, searchController.getRationItem);
     apiRouter.post('/findRation', searchController.auth, searchController.init, searchController.findRation);
 

+ 71 - 4
web/maintain/billsGuidance_lib/js/billsGuidance.js

@@ -221,6 +221,9 @@ const billsGuidance = (function () {
             },
             RangeChanged: function (sender, args) {
                 edit(args.sheet, args.changedCells);
+            },
+            CellDoubleClick: function(sender, args) {
+                locateAtRation(args.row);
             }
         }
     };
@@ -356,7 +359,6 @@ const billsGuidance = (function () {
             return;
         }
         const Events = GC.Spread.Sheets.Events;
-        let sheet = workBook.getActiveSheet();
         for(let event in events){
             workBook.bind(Events[event], events[event]);
         }
@@ -386,6 +388,12 @@ const billsGuidance = (function () {
             bindEvent(module.workBook, module.events);
         }
         lockUtil.lockSpreads([module.workBook], locked);
+        if (locked) {
+            // 锁定表格后双击事件失效了,但是需要双击定位,因此重新绑定双击
+            if (module === guideItem) {
+                module.workBook.bind('CellDoubleClick', module.events.CellDoubleClick);
+            }
+        }
     }
     //清空表数据
     //@param {Object}sheet {Array}headers {Number}rowCount @return {void}
@@ -815,7 +823,7 @@ const billsGuidance = (function () {
     }
     //初始化定额条目
     //@param {Number}rationLibId @return {void}
-    function initRationItems(rationLibId){
+    function initRationItems(rationLibId, successCb){
         $.bootstrapLoading.start();
         //获取定额章节树
         let sectionSheet = section.workBook.getActiveSheet();
@@ -841,6 +849,9 @@ const billsGuidance = (function () {
                 ration.datas = rstData;
                 sectionInitSel(0);
                 $.bootstrapLoading.end();
+                if (successCb) {
+                    successCb();
+                }
             }, function () {
                 $.bootstrapLoading.end();
             });
@@ -848,12 +859,16 @@ const billsGuidance = (function () {
             $.bootstrapLoading.end();
         });
     }
+    
+    // 可用的定额库ID
+    const rationLibIDs = [];
     //初始化定额库选择
     //@param {String}compilationId @return {void}
     function initRationLibs(compilationId){
         CommonAjax.post('/rationRepository/api/getRationLibsByCompilation', {compilationId: compilationId}, function (rstData) {
             $('#rationLibSel').empty();
             for(let rationLib of rstData){
+                rationLibIDs.push(+rationLib.ID);
                 let opt = `<option value="${rationLib.ID}">${rationLib.dispName}</option>`;
                 $('#rationLibSel').append(opt);
             }
@@ -865,6 +880,13 @@ const billsGuidance = (function () {
             })
         });
     }
+
+    // 变更定额库
+    function changeRationLib(libID, successCb) {
+        $('#rationLibSel').val(libID);
+        initRationItems(libID, successCb);
+    }
+
     // 设置清单名称文本色
     function setBillsForeColor(billsNodes) {
         const sheet = bills.workBook.getActiveSheet();
@@ -1007,8 +1029,6 @@ const billsGuidance = (function () {
         }
     }
 
-    // 展开收起清单树()
-
     //更新清单备注
     function updateBillsComment(updateData, callback, errCB) {
         CommonAjax.post('/stdBillsEditor/updateBills', updateData, function () {
@@ -1556,6 +1576,53 @@ const billsGuidance = (function () {
             $.bootstrapLoading.end();
         });
     }
+
+    // 双击定位定额
+    async function locateAtRation(row) {
+        const node = bills.tree.selected.guidance.tree.items[row];
+        if (!node || !node.data.rationID) {
+            return;
+        }
+        const rationItem = ration.datas.find(item => item.ID === node.data.rationID);
+        // 当前库没有找到,需要后端查找
+        if (!rationItem) {
+            const findedRation = await ajaxPost('/rationRepository/api/getRationByID',{ ID: node.data.rationID });
+            if (!findedRation || !rationLibIDs.includes(findedRation.rationRepId)) {
+                alert('无法定位此定额,此定额已被删除');
+                return;
+            }
+            changeRationLib(findedRation.rationRepId, () => {
+                located(findedRation.ID, findedRation.sectionId);
+            })
+        } else {
+            located(rationItem.ID, rationItem.sectionId);
+        }
+        function located(rationID, sectionID) {
+            if (!section.tree) {
+                return;
+            }
+            const sectionNode = section.tree.nodes[section.tree.prefix + sectionID];
+            if (!sectionNode) {
+                return;
+            }
+            // 定位到对应章节树
+            const sectionSheet = section.workBook.getActiveSheet();
+            const sectionRow = sectionNode.serialNo();
+            expandSearchNodes(sectionSheet, [sectionNode], section.tree.roots);
+            sectionSheet.setSelection(sectionRow, 0, 1, 1);
+            sectionSheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.center);
+            sectionInitSel(sectionRow);
+    
+            // 定位到对应定额
+            const locatedRationRow = ration.cache.findIndex(item => item.ID === rationID);
+            if (locatedRationRow !== -1) {
+                const rationSheet = ration.workBook.getActiveSheet();
+                rationSheet.setSelection(locatedRationRow, 1, 1, 1);
+                rationSheet.showRow(locatedRationRow, GC.Spread.Sheets.VerticalPosition.center);
+            }
+        }
+    }
+
     //初始化右键菜单
     //@return {void}
     function initContextMenu() {

+ 3 - 2
web/maintain/billsGuidance_lib/js/global.js

@@ -4,9 +4,10 @@ function autoFlashHeight(){
     var topContentHeight = $('#rationSearchResult').is(':visible') ? 0 : $('.top-content').height();
     var toolsBar = $(".toolsbar").height();
     var toolsBarHeightQ = $(".tools-bar-height-q").height();
+    const sideToolsBar = $('.side-tools-bar') ? $('.side-tools-bar').height() : 0;
     $(".content").height($(window).height()-headerHeight);
-    $(".main-side-top").height(($(window).height()-headerHeight) * 0.85);
-    $(".main-side-bottom").height(($(window).height()-headerHeight) * 0.15);
+    $(".main-side-top").height(($(window).height()-headerHeight - sideToolsBar) * 0.85);
+    $(".main-side-bottom").height(($(window).height()-headerHeight - sideToolsBar) * 0.15);
     $('.main-side-bottom').find('textarea').height($('.main-side-bottom').height() - 20);
     $('.main-side-bottom').find('textarea').width($('.main-side-bottom').width() - 25);
     $(".fluid-content").height($(window).height()-headerHeight-1);