Sfoglia il codice sorgente

定额库编辑器,子目换算窗口,新增查找引用功能

zeweizhong 5 anni fa
parent
commit
a9ec7cf3c3

+ 10 - 0
modules/ration_repository/controllers/coe_controller.js

@@ -8,6 +8,16 @@ var callback = function(req,res,err,message, data){
 }
 
 class CoeListController extends BaseController{
+    async getCoeReference(req, res) {
+        try {
+            const { rationRepId, coeID } = JSON.parse(req.body.data);
+            const rst = await coeList.getCoeReference(rationRepId, coeID);
+            res.json({ error: 0, message: 'success', data: rst });
+        } catch (err) {
+            res.json({ error: 1, message: err.message, data: null });
+        }
+    }
+
     getCoeList(req,res){
         coeList.getCoesByLibID(req.body.libID, function(err,data){
             callback(req, res, err, 'Get coes', data);

+ 6 - 1
modules/ration_repository/models/coe.js

@@ -5,11 +5,16 @@
 //modiyied by zhong on 2017/9/21
 const mongoose = require('mongoose');
 const coeListModel = mongoose.model('std_ration_lib_coe_list');
-let counter = require('../../../public/counter/counter');
+const counter = require('../../../public/counter/counter');
+const rationModel = mongoose.model('std_ration_lib_ration_items');
 import async from 'async';
 
 let coeListDAO = function(){};
 
+coeListDAO.prototype.getCoeReference = async function (rationRepId, coeID) {
+    return await rationModel.find({rationRepId, 'rationCoeList.ID': coeID}, '-_id code').sort({code: 1});
+};
+
 coeListDAO.prototype.getCoe = function (data, callback) {
     coeListModel.findOne({
             "libID": data.libID,

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

@@ -74,6 +74,7 @@ module.exports =  function (app) {
     apiRouter.post("/getGljItemsByIds",repositoryGljController.auth, gljController.init, gljController.getGljItemsByIds);
     apiRouter.post("/getGljItemsByCodes",repositoryGljController.auth, gljController.init, gljController.getGljItemsByCodes);
 
+    apiRouter.post("/getCoeReference",coeListController.auth, coeListController.init, coeListController.getCoeReference);
     apiRouter.post("/getCoeList",coeListController.auth, coeListController.init, coeListController.getCoeList);
     apiRouter.post("/saveCoeList",coeListController.auth, coeListController.init, coeListController.saveCoeList);
     apiRouter.post("/getCoeItemsByIDs",coeListController.auth, coeListController.init, coeListController.getCoeItemsByIDs);

+ 26 - 0
web/maintain/ration_repository/css/main.css

@@ -294,6 +294,32 @@ div.resize-x{
     cursor: w-resize;
     float: left;
 }
+.reset *{
+    margin: 0;
+    padding: 0;
+}
+.info-list {
+    max-height: 300px;
+    overflow: auto;
+}
+.info-list .list-title{
+    font-weight: bold;
+}
+.info-list li{
+    list-style: none;
+    display: flex;
+}
+.info-list li:hover{
+    background-color: #eee;
+}
+.info-list li span {
+    flex: 1;
+}
+.info-list li a {
+    float: right;
+    width: 30px;
+    text-decoration: none;
+}
 .disabled {
     pointer-events: none;
     opacity: .65;

+ 17 - 0
web/maintain/ration_repository/dinge.html

@@ -562,6 +562,23 @@
                 </div>
             </div>
         </div>
+        <!--查找引用-->
+        <div class="modal fade" id="info" 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 typeClose" data-dismiss="modal" aria-label="Close">
+                            <span aria-hidden="true">×</span>
+                        </button>
+                    </div>
+                    <div class="modal-body reset">
+                        <ul id="infoBody" class="info-list">
+                        </ul>
+                    </div>
+                </div>
+            </div>
+        </div>
         <%include ../../common/html/uploadImg.html %>
         <!--弹出html填写帮助-->
         <!--弹出html填写帮助-->

+ 80 - 16
web/maintain/ration_repository/js/coe.js

@@ -230,31 +230,35 @@ let coeOprObj = {
         me.workSheet = me.workBook.getSheet(0);
         me.workSheet.options.isProtected = true;
         me.onDelOpr(me.workBook, me.setting);
+        me.initContextMenu();
         me.workSheet.bind(GC.Spread.Sheets.Events.SelectionChanged, me.onSelectionChanged);
         me.workSheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
         me.workBook.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
     },
     onSelectionChanged: function (sender, info) {
-        let me = coeOprObj, that = gljAdjOprObj;
         if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){
-            let row = info.newSelections[0].row;
-            if(row < me.currentCoeList.length){
-                me.currentCoe = me.currentCoeList[row];
-                that.currentGljAdjList = me.currentCoe.coes;
-                that.buildDynamicComboBox(that.workSheet);
-            }
-            else{
-                me.currentCoe = null;
-                that.currentGljAdjList = [];
-                that.buildBaseCell(that.workSheet);
-            }
-            //refresh & show coes
-            sheetCommonObj.cleanSheet(that.workSheet, that.setting, -1);
-            me.workBook.focus(true);
-            that.show(that.currentGljAdjList);
+            const row = info.newSelections[0].row;
+            coeOprObj.coeSelInit(row);
         }
     },
+    coeSelInit: function (row) {
+        const me = coeOprObj;
+        const adj = gljAdjOprObj;
+        if(row < me.currentCoeList.length){
+            me.currentCoe = me.currentCoeList[row];
+            adj.currentGljAdjList = me.currentCoe.coes;
+            adj.buildDynamicComboBox(adj.workSheet);
+        } else{
+            me.currentCoe = null;
+            adj.currentGljAdjList = [];
+            adj.buildBaseCell(adj.workSheet);
+        }
+        //refresh & show coes
+        sheetCommonObj.cleanSheet(adj.workSheet, adj.setting, -1);
+        me.workBook.focus(true);
+        adj.show(adj.currentGljAdjList);
+    },
     onEditEnded: function (sender, args) {
         let me = coeOprObj, addArr = [], updateArr = [], dataCode = me.setting.header[args.col].dataCode;
         if(args.editingText && args.editingText.toString().trim().length > 0){
@@ -411,6 +415,66 @@ let coeOprObj = {
         workBook.commandManager().setShortcutKey(null, GC.Spread.Commands.Key.del, false, false, false, false);
         workBook.commandManager().setShortcutKey('coeListDel', GC.Spread.Commands.Key.del, false, false, false, false);
     },
+    initContextMenu: function () {
+        const me = this;
+        $.contextMenu({
+            selector: '#mainSpread',
+            build: function($triggerElement, e){
+                //控制允许右键菜单在哪个位置出现
+                const target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
+                const sheet = me.workBook.getSheet(0);
+                if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
+                    if(typeof target.row !== 'undefined'){
+                        //控制按钮是否可用
+                        sheet.setActiveCell(target.row, target.col);
+                        me.coeSelInit(target.row);
+                    }
+                    return {
+                        callback: function(){},
+                        items: {
+                            getReference: {
+                                name: '查找引用',
+                                disabled: function () {
+                                    return !me.currentCoeList || !me.currentCoeList[target.row];
+                                },
+                                icon: 'fa-search',
+                                callback: function () {
+                                    const coe = me.currentCoeList[target.row];
+                                    me.getReference(coe.ID);
+                                }
+                            },
+                        }
+                    };
+                }
+                else{
+                    return false;
+                }
+            }
+        });
+    },
+    getReference: function (coeID) {
+        const $info = $('#info');
+        const $infoBody = $('#infoBody');
+        $.bootstrapLoading.start();
+        CommonAjax.post('/rationRepository/api/getCoeReference', { rationRepId: pageOprObj.rationLibId, coeID }, function (info) {
+            let htmlArr = [];
+            if (!info || !info.length) {
+                htmlArr.push('<li>无引用数据</li>');
+            } else {
+                htmlArr = info.map(ration => {
+                    return `<li>
+                             <span>${ration.code}</span>
+                             <a data-dismiss="modal" href="javascript:;" onclick="sectionTreeObj.locateToSection('${ration.code}')">定位</a>
+                        </li>`;
+                });
+            }
+            $infoBody.html(htmlArr.join(''));
+            $info.modal('show');
+            $.bootstrapLoading.end();
+        }, function () {
+            $.bootstrapLoading.end();
+        });
+    },
     //粘贴的数据,编号唯一化,去除编号重复的项
     makeUniqItems: function (items) {
         let rst = [];

+ 10 - 10
web/maintain/ration_repository/js/section_tree.js

@@ -246,10 +246,8 @@ let sectionTreeObj = {
     //自动定位
     autoLocate: function () {
         const hash = window.location.hash;
-        const $searchInput = $('#rationSearch');
         if (hash) {
             const rationCode = hash.replace('#', '');
-            $searchInput.val(rationCode);
             this.locateToSection(rationCode);
         }
     },
@@ -665,7 +663,9 @@ let sectionTreeObj = {
     },
     //根据定额定位至章节树
     locateToSection: function (rationCode) {
-        let me = this;
+        const me = this;
+        const $seach = $('#rationSearch');
+        $seach.val(rationCode);
         //去后台搜索该定额
         CommonAjax.post('/rationRepository/api/getRationItem', {rationLibId: pageOprObj.rationLibId, code: rationCode}, function (rstData) {
             if (!rstData) {
@@ -673,21 +673,21 @@ let sectionTreeObj = {
                 return;
             }
             //定位至相关章节
-            let sectionId = rstData.sectionId;
+            const sectionId = rstData.sectionId;
             if (!sectionId) {
                 return;
             }
-            let sectionNode = me.tree.nodes[`id_${sectionId}`];
+            const sectionNode = me.tree.nodes[`id_${sectionId}`];
             if (!sectionNode) {
                 return;
             }
-            let sectionRow = sectionNode.serialNo();
+            const sectionRow = sectionNode.serialNo();
             me.sheet.setActiveCell(sectionRow, 1);
             me.sheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.top);
-            let doAfterGetRation = function (rations) {
-                let findRation = _.find(rations, {code: rationCode}),
-                    rIdx = rations.indexOf(findRation),
-                    rationSheet = rationOprObj.workBook.getActiveSheet();
+            const doAfterGetRation = function (rations) {
+                const findRation = _.find(rations, {code: rationCode});
+                const rIdx = rations.indexOf(findRation);
+                const rationSheet = rationOprObj.workBook.getActiveSheet();
                 rationSheet.setActiveCell(rIdx, 0);
                 rationOprObj.rationSelInit(rIdx, true);
                 rationOprObj.workBook.getActiveSheet().showRow(rIdx, GC.Spread.Sheets.VerticalPosition.top);