Browse Source

feat: 清单精灵编辑器,清单右键“配置材料”移至工具栏。弹出的窗口,新增一个表格,显示当前清单下引用的定额下的所有材料,方便双击添加为配置材料

vian 3 years ago
parent
commit
d8fa1ba4b5

+ 1 - 1
modules/std_billsGuidance_lib/controllers/libController.js

@@ -113,7 +113,7 @@ class BillsGuideLibController extends BaseController{
             callback(req, res, 0, '', materials);
         }
         catch(err){
-            callback(req, res, 1, err, []);
+            callback(req, res, 1, err, null);
         }
     }
 

+ 27 - 2
modules/std_billsGuidance_lib/facade/facades.js

@@ -415,13 +415,38 @@ async function updateItems(updateDatas) {
 
 // 获取清单材料数据
 async function getBillMaterials(libID, billID) {
+    // 指引下已有定额人材机
+    let allGljList = [];
+    const rationItems = await billsGuideItemsModel.find({ libID, billsID: billID, rationID: { $ne: null } }, '-_id rationID').lean();
+    if (rationItems.length) {
+        const rationIDs = rationItems.map(item => item.rationID);
+        const rations = await stdRationModel.find({ ID: { $in: rationIDs } }, '-_id rationGljList');
+        const gljIDs = [];
+        rations.forEach(ration => {
+            if (ration.rationGljList && ration.rationGljList.length) {
+                gljIDs.push(...ration.rationGljList.map(rGlj => rGlj.gljId));
+            }
+        });
+        if (gljIDs.length) {
+            allGljList = await gljModel.find({ ID: { $in: [...new Set(gljIDs)] } }, '-_id ID code name specs').lean();
+        }
+    }
+    // 清单材料
+    let billMaterials = [];
     const billMaterial = await billMaterialModel.findOne({ libID, billID }).lean();
     if (!billMaterial || !billMaterial.materials) {
-        return [];
+        return {
+            billMaterials, 
+            allGljList
+        };
     }
     const gljIDs = billMaterial.materials.map(m => m.gljID);
     const gljList = await gljModel.find({ ID: { $in: gljIDs } }, '-_id ID code name specs').lean();
-    return gljList.map(glj => ({ gljID: glj.ID, code: glj.code, name: glj.name, specs: glj.specs }));
+    billMaterials = gljList.map(glj => ({ gljID: glj.ID, code: glj.code, name: glj.name, specs: glj.specs }));
+    return {
+        billMaterials, 
+        allGljList
+    }
 }
 
 // 编辑清单材料数据,返回清单材料数据

+ 10 - 5
web/maintain/billsGuidance_lib/html/zhiyin.html

@@ -62,13 +62,14 @@
                     <div class="main-side p-0" id="leftContent" style="width: 33%">
                         <div class="side-tools-bar" >
                             <div style="display: flex; align-items: center; height: 36px;">
-                                <a id="expandToSecond" href="javascript:void(0);" class="btn btn-sm" data-toggle="tooltip" data-placement="bottom" title="收起"><i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起</a>
-                                <div class="input-group col-5 pl-0">
+                                <a id="expandToSecond" href="javascript:void(0);" class="btn btn-sm"><i class="fa fa-minus-square-o" aria-hidden="true"></i> 收起</a>
+                                <div class="input-group col-5 pl-0" style="padding-right: 0">
                                     <input id="searchBillText" type="text" class="form-control form-control-sm" placeholder="搜索清单">
                                     <span class="input-group-btn">
                                     <button id="searchBillBtn" class="btn btn-secondary btn-sm" type="button"><i class="fa fa-search" aria-hidden="true"></i></button>
                                 </span>
                                 </div>
+                                <a id="editMaterial" href="javascript:void(0);" class="btn btn-sm"><i class="fa fa-edit" aria-hidden="true"></i> 配置材料</a>
                             </div>
                             <div id="searchBillsResult" style="display: none;">
                                 <div style="display: flex; align-items: center; height: 36px;">
@@ -198,8 +199,8 @@
     </div>
     <!-- 配置材料 -->
     <div class="modal fade" id="bill-material-modal" data-backdrop="static" style="display: none;" aria-hidden="true">
-        <div class="modal-dialog" role="document">
-            <div class="modal-content" style="width: 520px">
+        <div class="modal-dialog" role="document" style="transform: translateX(-45%);">
+            <div class="modal-content" style="width: 900px">
                 <div class="modal-header">
                     <h5 class="modal-title">配置材料</h5>
                     <button type="button"  class="close" data-dismiss="modal" aria-label="Close">
@@ -207,7 +208,11 @@
                     </button>
                 </div>
                 <div class="modal-body">
-                    <div id="bill-material-spread" style="height: 400px;"></div>
+                    <div style="display: flex;">
+                        <div id="bill-material-spread" style="width: 50%; height: 400px;"></div>
+                        <div id="bill-material-helper-spread" style="width: 50%; height: 400px;"></div>
+                    </div>
+                    
                 </div>
                 <div class="modal-footer">
                     <button type="button" class="btn btn-secondary"  data-dismiss="modal">关闭</button>

+ 51 - 9
web/maintain/billsGuidance_lib/js/billsGuidance.js

@@ -395,15 +395,16 @@ const billsGuidance = (function () {
     };
 
     /* 清单材料表 */
+    const materialHeaders =  [
+        {name: '材料编码', dataCode: 'code', width: 90, vAlign: 'center', hAlign: 'left', formatter: '@'},
+        {name: '材料名称', dataCode: 'name', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'},
+        {name: '规格', dataCode: 'specs', width: 130, vAlign: 'center', hAlign: 'left', formatter: '@'}
+    ];
     const billMaterial = {
         dom: $('#bill-material-spread'),
         workBook: null,
         cache: [],
-        headers: [
-            {name: '材料编码', dataCode: 'code', width: 110, vAlign: 'center', hAlign: 'left', formatter: '@'},
-            {name: '材料名称', dataCode: 'name', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'},
-            {name: '规格', dataCode: 'specs', width: 150, vAlign: 'center', hAlign: 'left', formatter: '@'}
-        ],
+        headers: materialHeaders,
         events: {
             EditEnded: function (sender, args) {
                 editMaterials(args.sheet, [{row: args.row, col: args.col}]);
@@ -414,6 +415,29 @@ const billsGuidance = (function () {
         }
     }
 
+    /* 清单辅助材料录入表 */
+    const billMaterialHelper = {
+        dom: $('#bill-material-helper-spread'),
+        workBook: null,
+        cache: [],
+        headers: materialHeaders,
+        events: {
+            // 双击添加到清单材料表
+            CellDoubleClick: function (sender, args) {
+                // 模拟清单材料表编辑(共用同一个接口)
+                if (!billMaterialHelper.cache[args.row]) {
+                    return;
+                }
+                const code = billMaterialHelper.cache[args.row].code;
+                const row = billMaterial.cache.length;
+                const targetSheet = billMaterial.workBook.getSheet(0);
+                targetSheet.setValue(row, 0, code);
+                const changedCells = [{ row, col: 0 }];
+                editMaterials(billMaterial.workBook.getSheet(0), changedCells);
+            }
+        }
+    }
+
     // 显示清单材料数据
     function showBillMaterialData(sheet, headers, datas, emptyRow = 0){
         let fuc = function () {
@@ -440,14 +464,20 @@ const billsGuidance = (function () {
         billMaterial.cache = [];
         try {
             $.bootstrapLoading.start();
-            billMaterial.cache = await ajaxPost('/billsGuidance/api/getBillMaterials', { libID, billID: bills.tree.selected.data.ID });
+            const { billMaterials, allGljList } = await ajaxPost('/billsGuidance/api/getBillMaterials', { libID, billID: bills.tree.selected.data.ID });
+            billMaterial.cache = billMaterials;
+            console.log(allGljList);
             sortByCode(billMaterial.cache);
+            billMaterialHelper.cache = allGljList
+            sortByCode(billMaterialHelper.cache);
         } catch (error) {
             $('#alert-info').text(error.message);
             $('#alert').modal('show');
         } finally {
             showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
             billMaterial.workBook.getSheet(0).showRow(0, GC.Spread.Sheets.VerticalPosition.top);
+            showBillMaterialData(billMaterialHelper.workBook.getSheet(0), billMaterialHelper.headers, billMaterialHelper.cache);
+            billMaterialHelper.workBook.getSheet(0).showRow(0, GC.Spread.Sheets.VerticalPosition.top);
             $.bootstrapLoading.end();
         }
     }
@@ -580,6 +610,9 @@ const billsGuidance = (function () {
                 sheet.getRange(-1, 1, -1, -1).locked(true);
                 sheet.getRange(-1, 2, -1, -1).locked(true);
             }
+            else if (module === billMaterialHelper) {
+                sheet.options.isProtected = true;
+            }
             setOptions(module.workBook, options);
             buildHeader(module.workBook.getActiveSheet(), module.headers);
             bindEvent(module.workBook, module.events);
@@ -619,6 +652,7 @@ const billsGuidance = (function () {
         cleanData(guideSheet, guideItem.headers, -1);
         let node = bills.tree.items[row];
         if(!node){
+            $('#editMaterial').addClass('disabled');
             return;
         }
         const billSheet = bills.workBook.getActiveSheet();
@@ -628,6 +662,7 @@ const billsGuidance = (function () {
             setBgColor(billSheet, oldSel.row, orgNode && orgNode.isSearch ? searchBgColor : 'white');
         }
         bills.tree.selected = node;
+        $('#editMaterial').removeClass('disabled');
         //显示备注
         $('.main-side-bottom').find('textarea').val(node.data.comment ? node.data.comment : '');
         if(!node.guidance.tree){
@@ -2238,7 +2273,8 @@ const billsGuidance = (function () {
             showBillMaterialData(billMaterial.workBook.getSheet(0), billMaterial.headers, billMaterial.cache, 30);
         });
         $("#bill-material-modal").on('shown.bs.modal', function () {
-            if (billMaterial.workBook) {
+            if (billMaterial.workBook && billMaterialHelper.workBook) {
+                billMaterialHelper.workBook.refresh();
                 billMaterial.workBook.refresh();
                 getBillMaterials();
             }
@@ -2304,6 +2340,12 @@ const billsGuidance = (function () {
                 TREE_SHEET_HELPER.refreshNodesVisible(tree.roots, itemSheet, true);
             });
         });
+        // 配置材料
+        $('#editMaterial').click(function () {
+            if (bills && bills.tree && bills.tree.selected) {
+                $('#bill-material-modal').modal('show');
+            }
+        });
         // 插入选中定额
         $('#insertRation').click(function () {
             let checkedRows = getCheckedRationRows();
@@ -2535,14 +2577,14 @@ const billsGuidance = (function () {
     //初始化视图
     //@param {void} @return {void}
     function initViews(){
-        let modules = [bills, guideItem, section, ration, billMaterial];
+        let modules = [bills, guideItem, section, ration, billMaterial, billMaterialHelper];
         initWorkBooks(modules);
         lockUtil.lockTools($(document.body), locked);
         getLibWithBills(libID);
         initDomEvents();
         initContextMenu();
         initRationContextMenu();
-        initBillsContextMenu();
+        //initBillsContextMenu();
         initSlideSize();
     }