Quellcode durchsuchen

一对一克隆。

chenshilong vor 6 Jahren
Ursprung
Commit
7b060ff4cb

+ 33 - 16
web/building_saas/main/js/views/block_lib.js

@@ -132,18 +132,14 @@ var blockLibObj = {
     loadDetailDatas: function (node){
         let me = this;
         if (node.data.type == 2){
-            let sourceNode = node.data.sourceNode;
-            let rations = sourceNode.children;
-            let rationDatas = [];
-            for (let r of rations){
-                rationDatas.push(r.data);
-            };
-            sheetCommonObj.showData(me.billSheet, me.billSetting, [sourceNode.data]);
-            me.changeBillText(sourceNode.data);
-            let rCount = (rationDatas.length > 0) ? rationDatas.length : 1;
+            let bill = node.data.datas[0];
+            let rations = bill.children;
+            sheetCommonObj.showData(me.billSheet, me.billSetting, [bill]);
+            me.changeBillText(bill);
+            let rCount = (rations.length > 0) ? rations.length : 1;
             me.rationSheet.setRowCount(rCount, GC.Spread.Sheets.SheetArea.viewport);
-            sheetCommonObj.showData(me.rationSheet, me.rationSetting, rationDatas);
-            me.changeRationText(rationDatas);
+            sheetCommonObj.showData(me.rationSheet, me.rationSetting, rations);
+            me.changeRationText(rations);
         }
         else{
             sheetCommonObj.cleanSheet(me.billSheet, me.billSetting, 1);
@@ -349,7 +345,7 @@ var blockLibObj = {
         };
         return new TreeCell();
     },
-    newNode: function (nodeType, nodeName, categoryID, sourceNode){     // 1 分类(只用前两个参数)  2 块文件
+    newNode: function (nodeType, nodeName, categoryID, source){     // 1 分类(只用前两个参数)  2 块文件
         let tree = blockLibObj.mainTree;
         let pID = -1, nID = -1;
         let select = tree.selected;
@@ -372,8 +368,14 @@ var blockLibObj = {
         let newNode = tree.insert(pID, nID);
         newNode.data.type = nodeType;
         newNode.data.name = nodeName;
-        if (nodeType == 2)
-            newNode.data.sourceNode = sourceNode;
+        if (nodeType == 2){
+            newNode.data.compilationID = source.compilationID;
+            newNode.data.copyTime = source.copyTime;
+            newNode.data.firstNodeType = source.firstNodeType;
+            newNode.data.isFBFX = source.isFBFX;
+            newNode.data.datas = source.datas;
+        }
+
         tree.selected = newNode;
 
         let sheet = blockLibObj.mainSheet;
@@ -458,7 +460,7 @@ var blockLibObj = {
                         return me.curIsBlock();
                     },
                     callback: function (key, opt) {
-
+                        me.oneToOneClone();
                     }
                 },
                 "oneToMoreClone": {
@@ -521,8 +523,23 @@ var blockLibObj = {
         me.mainTree.selected = me.mainTree.items[me.mainSheet.getActiveRowIndex()];
     },
     onCellDoubleClick: function (sender, args) {
+        blockLibObj.oneToOneClone();
+    },
+    oneToOneClone: function () {
         let me = blockLibObj;
-        //
+        let projectNode = projectObj.project.mainTree.selected;
+        if (!calcTools.isLeafBill(projectNode)) return;
+
+        let block = me.mainTree.selected.data;
+        // 这里再次封装成伟城的块文件格式,可直接使用伟城的“粘贴块”接口。前提:当前块文件的全部数据已从后台取到前台。
+        let vBlock_WC = {
+            compilationID: block.compilationID,
+            copyTime: block.copyTime,
+            firstNodeType: 1,   // 强制改成1。这里跟粘贴块有区别,忽略叶子清单层,直接从定额开始,即始终强制在叶子清单下插入定额。
+            isFBFX: block.isFBFX,
+            datas: block.datas[0].children    // rations
+        };
+        BlockController.confirmPaste(vBlock_WC, projectNode, 'sub');
     }
 };
 

+ 13 - 1
web/building_saas/main/js/views/project_view.js

@@ -2900,7 +2900,19 @@ $(function () {
                 if (node.data.name == undefined || node.data.name == '') return;  // 清单名称为空,不生成块模板文件
                 let name = node.data.code + ' ' + node.data.name + ' ' + node.data.unit;
                 name = name.replace(/^\s+|\s+$/g, "");    // 只去两头空格
-                blockLibObj.newNode(2, name, categoryID, node);
+
+                // 封装成伟城的块文件格式,直接调用伟城接口(定额这里的业务太多太庞杂,不要再重做一遍,尽量共用,维护代价小)
+                // 块文件要构建自己的树结构,所以也有自己的一部分数据。两种结构揉合在一起,显得有点杂乱,但利大于弊。
+                let block_WC = {
+                    compilationID: projectInfoObj.projectInfo.compilation,
+                    firstNodeType: node.data.type,
+                    isFBFX: projectObj.project.Bills.isFBFX(node),
+                    copyTime: +new Date(),
+                    datas: []
+                };
+                let ration_glj_Map = _.groupBy(projectObj.project.ration_glj.datas, 'rationID');
+                block_WC.datas.push(BlockController.getNodeDatas(node, ration_glj_Map));
+                blockLibObj.newNode(2, name, categoryID, block_WC);
             };
 
             function createRecursion(node){