Browse Source

造价书右键,自定义批量插入定额

vian 5 years ago
parent
commit
c0e1f6f6ce

+ 4 - 5
modules/main/facade/ration_facade.js

@@ -75,12 +75,11 @@ async function addNewRation(data,compilation) {
 }
 
 async function addMultiRation(datas,compilation) {
-    let rst = [];
-    for(let data of datas){
-        let r = await addNewRation(data,compilation);
-        rst.push(r);
+    const task = [];
+    for (const data of datas) {
+        task.push(addNewRation(data, compilation));
     }
-    return rst;
+    return await Promise.all(task);
 }
 
 async function deleteMultiRation(rations) {//这里是只有删除的情况,删除定额的同时删除定额下挂的其它子项目

+ 11 - 4
public/web/sheet/sheet_common.js

@@ -1554,6 +1554,12 @@ var sheetCommonObj = {
                     input.setSelectionRange(idx, idx);
                 }
             }
+            function handleConfirm() {
+                if (callback) {
+                    callback();
+                }
+                root.$menu.trigger('contextmenu:hide');
+            }
             $(html)
                 .appendTo(this)
                 .on('input', 'input', function () {
@@ -1569,6 +1575,10 @@ var sheetCommonObj = {
                     if (key === 'ArrowUp' || key === 'ArrowDown') {
                         return false;
                     }
+                    if (key === 'Enter') {
+                        handleConfirm();
+                        return false;
+                    }
                     const input = $(this)[0];
                     if (key === 'ArrowLeft') {
                         moveLeft(input, e.shiftKey);
@@ -1580,10 +1590,7 @@ var sheetCommonObj = {
                     if (e.target.tagName === 'INPUT') {
                         return false;
                     }
-                    if (callback) {
-                        callback();
-                    }
-                    root.$menu.trigger('contextmenu:hide');
+                    handleConfirm();
                 });
 
             this.addClass(`context-menu-icon context-menu-icon--fa fa ${icon}`);

+ 37 - 59
web/building_saas/main/js/models/ration.js

@@ -450,9 +450,7 @@ var Ration = {
                 updateBillsOprRation();
             })
         };
-        ration.prototype.addMultiRation = function (items, callback) {
-            debugger;
-            console.log('addMultiRation');
+        ration.prototype.addMultiRation = async function (items) {
             let me = this;
             let project = projectObj.project, sheetController = projectObj.mainController;
             let engineering = projectObj.project.projectInfo.property.engineering;
@@ -502,63 +500,43 @@ var Ration = {
                     }
                     newDatas.push({itemQuery: items[i].itemQuery, newData: newData, defaultLibID: rationLibObj.getDefaultStdRationLibID(), calQuantity: calQuantity, brUpdate: brUpdate, needInstall: needInstall})
                 }
-                let showLoding = true;
-                $.bootstrapLoading.start();
-                //保证由于异步的关系loading界面被隐藏,比如清单指引插入清单定额时,endUpdate中提前隐藏了loading
-                let interval =setInterval(function () {
-                    if(!$.bootstrapLoading.isLoading()&& showLoding){
-                        $.bootstrapLoading.start();
-                        clearInterval(interval);
-                    }
-                    else{
-                        clearInterval(interval);
-                    }
-                }, 100);
-                CommonAjax.post("/ration/addMultiRation",{projectID:me.project.ID(),newDatas: newDatas},function (rstData) {
-                    let newNodes = [];
-                    //更新缓存
-                    for(let data of rstData){
-                        me.datas.push(data.ration);
-                        me.addSubListOfRation(data,false);
-                        //插入树节点
-                        newSource = data.ration;
-                        newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
-                        newNodes.push(newNode);
-                        newNode.source = newSource;
-                        newNode.sourceType = project.Ration.getSourceType();
-                        newNode.data = newSource;
-                        ProjectController.syncDisplayNewNode(sheetController, newNode);
-                        nextID =  project.mainTree.selected.getNextSiblingID();
-                    }
-                    project.projectGLJ.calcQuantity();
-                    for(let data of rstData){
-                        project.ration_glj.addToMainTree(data.ration_gljs);
-                    }
-                    projectObj.mainController.refreshTreeNode(newNodes, false);
-                    if(project.Bills.isFBFX(newNodes[0])) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
-                        project.installation_fee.calcInstallationFee(function (isChange,rations) {
-                            if(isChange){
-                                rations = rations.concat(newNodes);
-                                project.calcProgram.calcNodesAndSave(rations);
-                                itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(rations);
-                            }else {
-                                project.calcProgram.calcNodesAndSave(newNodes);
-                                itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(newNodes);
-                            }
-                        });
-                    }else {
-                        project.calcProgram.calcNodesAndSave(newNodes);
-                        itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(newNodes);
-                    }
-                    updateBillsOprRation();
-
-                        if(callback){
-                            callback();
+                const rstData = await ajaxPost('/ration/addMultiRation', { projectID:me.project.ID(), newDatas });
+                let newNodes = [];
+                //更新缓存
+                for(let data of rstData){
+                    me.datas.push(data.ration);
+                    me.addSubListOfRation(data,false);
+                    //插入树节点
+                    newSource = data.ration;
+                    newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
+                    newNodes.push(newNode);
+                    newNode.source = newSource;
+                    newNode.sourceType = project.Ration.getSourceType();
+                    newNode.data = newSource;
+                    ProjectController.syncDisplayNewNode(sheetController, newNode);
+                    nextID =  project.mainTree.selected.getNextSiblingID();
+                }
+                project.projectGLJ.calcQuantity();
+                for(let data of rstData){
+                    project.ration_glj.addToMainTree(data.ration_gljs);
+                }
+                projectObj.mainController.refreshTreeNode(newNodes, false);
+                if(project.Bills.isFBFX(newNodes[0])) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
+                    project.installation_fee.calcInstallationFee(function (isChange,rations) {
+                        if(isChange){
+                            rations = rations.concat(newNodes);
+                            project.calcProgram.calcNodesAndSave(rations);
+                            itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(rations);
+                        }else {
+                            project.calcProgram.calcNodesAndSave(newNodes);
+                            itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(newNodes);
                         }
-                        showLoding = false;
-                        $.bootstrapLoading.end();
-
-                })
+                    });
+                }else {
+                    project.calcProgram.calcNodesAndSave(newNodes);
+                    itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(newNodes);
+                }
+                updateBillsOprRation();
             }
         };
         ration.prototype.insertVolumePrice = function(type){

+ 12 - 3
web/building_saas/main/js/views/billsElf.js

@@ -920,11 +920,20 @@ const BillsSub = (function() {
     }
     //插入定额
     //@return {void}
-    function insertRations(addRationDatas){
+    async function insertRations(addRationDatas){
         if(addRationDatas.length > 0){
-            projectObj.project.Ration.addMultiRation(addRationDatas, function () {
+            try {
+                $.bootstrapLoading.start();
+                await projectObj.project.Ration.addMultiRation(addRationDatas);
                 projectObj.setActiveCell('quantity', true);
-            });
+            } catch (err) {
+                console.log(err);
+                if (!$('hintBox_form').is(':visible')) {
+                    alert(err);
+                }
+            } finally {
+                $.bootstrapLoading.end();
+            }
         }
     }
     function handleClick(getRationFunc) {

+ 30 - 2
web/building_saas/main/js/views/project_view.js

@@ -1235,6 +1235,33 @@ var projectObj = {
             }
         });
     },
+    // 注册自定义插入定额数量
+    registerFlexibleInsertRatoinMenu: function () {
+        const project = projectObj.project;
+        const insertRationHtml = `<span>插入定额&nbsp;&nbsp;<input id='insert-ration-number' class="menu-input" type="text" value="1" onfocus="this.select()">&nbsp;&nbsp;行</span>`;
+        return sheetCommonObj.registerInputContextMenuItem('insertRation', insertRationHtml, 'fa-sign-in', async function () {
+            try {
+                const number = +$('#insert-ration-number').val();
+                if (!number) {
+                    return;
+                }
+                $.bootstrapLoading.start();
+                const newData = [];
+                for (let i = 0; i < number; i++) {
+                    newData.push({ itemQuery: null, rationType: rationType.ration });
+                }
+                await project.Ration.addMultiRation(newData);
+                projectObj.setActiveCell('quantity', true);
+            } catch (err) {
+                console.log(err);
+                if (!$('hintBox_form').is(':visible')) {
+                    alert(err);
+                }
+            } finally {
+                $.bootstrapLoading.end();
+            }
+        });
+    },
     loadMainSpreadContextMenu: function () {
         var project = this.project, spread = this.mainSpread, controller = this.mainController;
         $.contextMenu({
@@ -1371,6 +1398,7 @@ var projectObj = {
                 },
                 "spr1": '--------',
                 "insertRation": {
+                    type: projectObj.registerFlexibleInsertRatoinMenu(),
                     name: "插入定额",
                     icon: 'fa-sign-in',
                     disabled: function () {
@@ -1382,10 +1410,10 @@ var projectObj = {
                         // 工具栏要加按钮,且不能隐藏。菜单可以隐藏,两者又必须统一,所以启用新规则。怕以后又要改回来,所以保留。 CSL, 2018-01-02
                         return !project.Ration.canAdd(project.mainTree.selected);
                     },
-                    callback: function (key, opt) {
+                    /* callback: function (key, opt) {
                         project.Ration.addNewRation(null,rationType.ration,projectObj.selectColAndFocus,false);
                         // ProjectController.addRation(project, controller, rationType.ration);
-                    }/*,
+                    } *//*,
                      visible: function(key, opt){
                      var selected = project.mainTree.selected;
                      return canInsertRationNode(selected);