Sfoglia il codice sorgente

人材机查找引用

zeweizhong 6 anni fa
parent
commit
28c1f18d46

+ 11 - 0
modules/std_glj_lib/controllers/gljController.js

@@ -201,6 +201,17 @@ class GljController extends BaseController{
             res.json({error: 1, message: error, data: null});
         }
     }
+
+    async getReference(req, res) {
+        try {
+            const {repositoryId, gljId} = JSON.parse(req.body.data);
+            const info = await gljDao.getReference(repositoryId, gljId);
+            res.json({error: 0, message: 'success', data: info});
+        } catch (err) {
+            res.json({error: 1, message: 'fail', data: null});
+        }
+    }
+
     async importPrice(request, response) {
         let responseData = {
             err: 0,

+ 28 - 0
modules/std_glj_lib/models/gljModel.js

@@ -8,12 +8,40 @@ const gljClassModel = mongoose.model('std_glj_lib_gljClass');
 const compilationModel = mongoose.model('compilation');
 const scMathUtil = require('../../../public/scMathUtil').getUtil();
 const rationModel = mongoose.model('std_ration_lib_ration_items');
+const complementaryRationModel = mongoose.model('complementary_ration_items');
 import {OprDao} from  "./gljMapModel";
 import moment from "moment";
 import counter from "../../../public/counter/counter";
 import async from "async";
 
 class GljDao  extends OprDao{
+    async getReference(repositoryId, gljId) {
+        const gljLib = await gljMapModel.findOne({ID: repositoryId});
+        const rationLibIds = [];
+        const rationLibNameMapping = {};
+        gljLib.rationLibs.forEach(item => {
+            rationLibIds.push(item.ID);
+            rationLibNameMapping[item.ID] = item.dispName;
+        });
+        const stdRations = await rationModel.find({rationRepId: {$in: rationLibIds}, 'rationGljList.gljId': gljId}, '-_id code rationRepId');
+        const rst = {};
+        const unknownLib = '未知定额库';
+        const complementaryLib = '补充定额库';
+        stdRations.forEach(ration => {
+            const libName = rationLibNameMapping[ration.rationRepId] || unknownLib;
+            if (!rst[libName]) {
+                rst[libName] = [];
+            }
+            rst[libName].push(ration);
+        });
+        const complementaryRations = await complementaryRationModel.find({'rationGljList.gljId': gljId}, '-_id code');
+        if (complementaryRations.length) {
+            rst[complementaryLib] = [];
+        }
+        complementaryRations.forEach(ration => rst[complementaryLib].push({code: ration.code}));
+        return rst;
+    }
+
     getGljTypes (gljLibId, callback){
         gljClassModel.find({"repositoryId": gljLibId, "$or": [{"isDeleted": null}, {"isDeleted": false}, {deleted: false} ]},
             '-_id', {lean: true}, function(err,data){

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

@@ -42,6 +42,7 @@ module.exports = function (app) {
     router.post("/getGljItemsByCodes",gljController.auth, gljController.init, gljController.getGljItemsByCodes);
     router.post("/getGljItemsOccupied",gljController.auth, gljController.init, gljController.getGljItemsOccupied);
     router.post("/isUsed",gljController.auth, gljController.init, gljController.isUsed);//工料机是否被引用
+    router.post("/getReference",gljController.auth, gljController.init, gljController.getReference);
     router.post('/importPrice', gljController.auth, gljController.init, gljController.importPrice);
     router.post('/importComponents', gljController.auth, gljController.init, gljController.importComponents);
 

+ 12 - 0
web/maintain/ration_repository/js/section_tree.js

@@ -259,9 +259,18 @@ let sectionTreeObj = {
             me.initSelection(me.tree.selected);
             explanatoryOprObj.bindEvents(exEditor, calcEditor);
             me.loadRateWidth();
+            //自动定位
+            const hash = window.location.hash;
+            const $searchInput = $('#rationSearch');
+            if (hash) {
+                const rationCode = hash.replace('#', '');
+                $searchInput.val(rationCode);
+                me.locateToSection(rationCode);
+            }
         };
         let errFunc = function () {
 
+
         };
         CommonAjax.post(url, postData, sucFunc, errFunc);
     },
@@ -678,6 +687,7 @@ let sectionTreeObj = {
     locateToSection: function (rationCode) {
         let me = this;
         //去后台搜索该定额
+        $.bootstrapLoading.start();
         CommonAjax.post('/rationRepository/api/getRationItem', {rationLibId: pageOprObj.rationLibId, code: rationCode}, function (rstData) {
             if (!rstData) {
                 alert(`不存在定额${rationCode}`);
@@ -695,6 +705,7 @@ let sectionTreeObj = {
             let sectionRow = sectionNode.serialNo();
             me.sheet.setActiveCell(sectionRow, 1);
             me.sheet.showRow(sectionRow, GC.Spread.Sheets.VerticalPosition.top);
+            $.bootstrapLoading.end();
             let doAfterGetRation = function (rations) {
                 let findRation = _.find(rations, {code: rationCode}),
                     rIdx = rations.indexOf(findRation),
@@ -705,6 +716,7 @@ let sectionTreeObj = {
             };
             me.initSelection(sectionNode, doAfterGetRation);
         }, function () {
+            $.bootstrapLoading.end();
         });
     }
 };

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

@@ -276,4 +276,30 @@ body {
 .modal-fixed-height {
     height:400px;
     overflow-y:auto;
+}
+.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;
 }

+ 16 - 0
web/maintain/std_glj_lib/html/gongliao.html

@@ -189,6 +189,22 @@
             </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>
     <!-- JS. -->
     <script src="/lib/jquery/jquery.min.js"></script>
     <script src="/lib/jquery-contextmenu/jquery.contextMenu.min.js"></script>

+ 44 - 2
web/maintain/std_glj_lib/js/glj.js

@@ -1100,7 +1100,7 @@ let repositoryGljObj = {
                     return {
                         callback: function(){},
                         items: {
-                            "delete": {
+                            delete: {
                                 name: "删除",
                                 disabled: function () {
                                     return !(me.currentCache && me.currentCache[target.row]);
@@ -1110,7 +1110,19 @@ let repositoryGljObj = {
                                     let curSel = _.cloneDeep(sheet.getSelections()[0]);
                                     curSel.colCount = me.setting.header.length;
                                     me.delGljs([curSel]);
-                                }}
+                                }
+                            },
+                            getReference: {
+                                name: '查找引用',
+                                disabled: function () {
+                                    return !(me.currentCache && me.currentCache[target.row]);
+                                },
+                                icon: 'fa-search',
+                                callback: function () {
+                                    const glj = me.currentCache[target.row];
+                                    me.getReference(glj);
+                                }
+                            },
                         }
                     };
                 }
@@ -1120,6 +1132,36 @@ let repositoryGljObj = {
             }
         });
     },
+    getReference: function (glj) {
+        const $info = $('#info');
+        const $infoBody = $('#infoBody');
+        $.bootstrapLoading.start();
+        CommonAjax.post('/stdGljRepository/api/getReference', {repositoryId: glj.repositoryId, gljId: glj.ID}, function (info) {
+            const htmlArr = [];
+            if (!info || !Object.keys(info).length) {
+                htmlArr.push('<li>无引用数据</li>');
+            }
+            for (let libName in info) {
+                htmlArr.push(`<li class="list-title">${libName}</li>`);
+                const rations = info[libName];
+                const rationList = rations.map(ration => {
+                    if (ration.rationRepId) {
+                        return `<li>
+                                    <span>${ration.code}</span>
+                                    <a target="_blank" href="/rationRepository/ration?repository=${ration.rationRepId}#${ration.code}">定位</a>
+                                </li>`;
+                    }
+                    return `<li><span>${ration.code}</span></li>`;
+                });
+                htmlArr.push(...rationList);
+            }
+            $infoBody.html(htmlArr.join(''));
+            $info.modal('show');
+            $.bootstrapLoading.end();
+        }, function () {
+            $.bootstrapLoading.end();
+        });
+    },
     validUpdateObj: function (pasteObj, rowIdx) {
         let rst = {updateGlj: [], updateBasePrcArr: []}, backUpObj = {},
             me = repositoryGljObj,